MCPcopy Create free account
hub / github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator / TestDebugMargin

Function TestDebugMargin

src/Tests.cpp:3975–4067  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3973#endif
3974
3975static void TestDebugMargin()
3976{
3977 if(VMA_DEBUG_MARGIN == 0)
3978 {
3979 return;
3980 }
3981
3982 wprintf(L"Test VMA_DEBUG_MARGIN = %u\n", (uint32_t)VMA_DEBUG_MARGIN);
3983
3984 VkBufferCreateInfo bufInfo = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO };
3985 bufInfo.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
3986 bufInfo.size = 256; // Doesn't matter
3987
3988 VmaAllocationCreateInfo allocCreateInfo = {};
3989 allocCreateInfo.usage = VMA_MEMORY_USAGE_AUTO_PREFER_HOST;
3990 allocCreateInfo.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT;
3991
3992 VmaPoolCreateInfo poolCreateInfo = {};
3993 TEST(vmaFindMemoryTypeIndexForBufferInfo(
3994 g_hAllocator, &bufInfo, &allocCreateInfo, &poolCreateInfo.memoryTypeIndex) == VK_SUCCESS);
3995
3996 for(size_t algorithmIndex = 0; algorithmIndex < 2; ++algorithmIndex)
3997 {
3998 switch(algorithmIndex)
3999 {
4000 case 0: poolCreateInfo.flags = 0; break;
4001 case 1: poolCreateInfo.flags = VMA_POOL_CREATE_LINEAR_ALGORITHM_BIT; break;
4002 default: assert(0);
4003 }
4004 VmaPool pool = VK_NULL_HANDLE;
4005 TEST(vmaCreatePool(g_hAllocator, &poolCreateInfo, &pool) == VK_SUCCESS && pool);
4006
4007 allocCreateInfo.pool = pool;
4008
4009 // Create few buffers of different size.
4010 const size_t BUF_COUNT = 10;
4011 BufferInfo buffers[BUF_COUNT];
4012 VmaAllocationInfo allocInfo[BUF_COUNT];
4013 for(size_t allocIndex = 0; allocIndex < 10; ++allocIndex)
4014 {
4015 const bool isLast = allocIndex == BUF_COUNT - 1;
4016 bufInfo.size = (VkDeviceSize)(allocIndex + 1) * 256;
4017 // Last one will be mapped.
4018 allocCreateInfo.flags = isLast ? VMA_ALLOCATION_CREATE_MAPPED_BIT : 0;
4019
4020 VkResult res = vmaCreateBuffer(g_hAllocator, &bufInfo, &allocCreateInfo, &buffers[allocIndex].Buffer, &buffers[allocIndex].Allocation, &allocInfo[allocIndex]);
4021 TEST(res == VK_SUCCESS);
4022
4023 if(isLast)
4024 {
4025 // Fill with data.
4026 TEST(allocInfo[allocIndex].pMappedData != nullptr);
4027 // Uncomment this "+ 1" to overwrite past end of allocation and check corruption detection.
4028 memset(allocInfo[allocIndex].pMappedData, 0xFF, bufInfo.size /* + 1 */);
4029 }
4030 }
4031
4032 // Check if their offsets preserve margin between them.

Callers 1

TestFunction · 0.85

Calls 9

TESTEnum · 0.85
vmaCreatePoolFunction · 0.85
vmaCreateBufferFunction · 0.85
vmaCheckCorruptionFunction · 0.85
vmaBuildStatsStringFunction · 0.85
vmaFreeStatsStringFunction · 0.85
vmaDestroyBufferFunction · 0.85
vmaDestroyPoolFunction · 0.85

Tested by

no test coverage detected