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

Function TestAllocationWithAlignment

src/Tests.cpp:6143–6288  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6141}
6142
6143static void TestAllocationWithAlignment()
6144{
6145 wprintf(L"Test allocation with alignment\n");
6146
6147 static const VkDeviceSize BUFFER_SIZE = 4 * KILOBYTE;
6148 static const VkDeviceSize MIN_ALIGNMENT = 64 * KILOBYTE;
6149
6150 VkBufferCreateInfo bufCreateInfo = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO };
6151 bufCreateInfo.size = BUFFER_SIZE;
6152 bufCreateInfo.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
6153
6154 VkResult res;
6155
6156 // 1. Using vmaAllocateMemory with VmaAllocationCreateInfo::minAlignment
6157 {
6158 VkBuffer buffers[2] = {};
6159 VkMemoryRequirements memReq[2] = {};
6160 VmaAllocation allocations[2] = {};
6161 VmaAllocationInfo allocInfo[2] = {};
6162
6163 for(uint32_t i = 0; i < 2; ++i)
6164 {
6165 res = vkCreateBuffer(g_hDevice, &bufCreateInfo, g_Allocs, &buffers[i]);
6166 TEST(res == VK_SUCCESS && buffers[i] != VK_NULL_HANDLE);
6167 vkGetBufferMemoryRequirements(g_hDevice, buffers[i], &memReq[i]);
6168 }
6169
6170 VmaAllocationCreateInfo allocCreateInfo = {};
6171 allocCreateInfo.minAlignment = MIN_ALIGNMENT;
6172
6173 for(uint32_t i = 0; i < 2; ++i)
6174 {
6175 res = vmaAllocateMemory(g_hAllocator, &memReq[i], &allocCreateInfo, &allocations[i], &allocInfo[i]);
6176 TEST(res == VK_SUCCESS && allocations[i] != VK_NULL_HANDLE);
6177 TEST(allocInfo[i].offset % MIN_ALIGNMENT == 0); // !!!
6178 }
6179
6180 for(uint32_t i = 0; i < 2; ++i)
6181 {
6182 res = vmaBindBufferMemory(g_hAllocator, allocations[i], buffers[i]);
6183 TEST(res == VK_SUCCESS);
6184 }
6185
6186 for(uint32_t i = 0; i < 2; ++i)
6187 {
6188 vkDestroyBuffer(g_hDevice, buffers[i], g_Allocs);
6189 vmaFreeMemory(g_hAllocator, allocations[i]);
6190 }
6191 }
6192
6193 // 2. Using vmaCreateBuffer with VmaAllocationCreateInfo::minAlignment
6194 {
6195 VkBuffer buffers[2] = {};
6196 VmaAllocation allocations[2] = {};
6197 VmaAllocationInfo allocInfo[2] = {};
6198
6199 VmaAllocationCreateInfo allocCreateInfo = {};
6200 allocCreateInfo.minAlignment = MIN_ALIGNMENT;

Callers 1

TestFunction · 0.85

Calls 10

TESTEnum · 0.85
vmaAllocateMemoryFunction · 0.85
vmaBindBufferMemoryFunction · 0.85
vmaFreeMemoryFunction · 0.85
vmaCreateBufferFunction · 0.85
vmaDestroyBufferFunction · 0.85
vmaCreatePoolFunction · 0.85
vmaDestroyPoolFunction · 0.85

Tested by

no test coverage detected