| 6141 | } |
| 6142 | |
| 6143 | static 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; |
no test coverage detected