| 4858 | } |
| 4859 | |
| 4860 | static void BenchmarkAlgorithmsCase(FILE* file, |
| 4861 | uint32_t algorithm, |
| 4862 | bool empty, |
| 4863 | VmaAllocationCreateFlags allocStrategy, |
| 4864 | FREE_ORDER freeOrder) |
| 4865 | { |
| 4866 | RandomNumberGenerator rand{16223}; |
| 4867 | |
| 4868 | const VkDeviceSize bufSizeMin = 32; |
| 4869 | const VkDeviceSize bufSizeMax = 1024; |
| 4870 | const size_t maxBufCapacity = 10000; |
| 4871 | const uint32_t iterationCount = 10; |
| 4872 | |
| 4873 | VkBufferCreateInfo sampleBufCreateInfo = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO }; |
| 4874 | sampleBufCreateInfo.size = bufSizeMax; |
| 4875 | sampleBufCreateInfo.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT; |
| 4876 | |
| 4877 | VmaAllocationCreateInfo sampleAllocCreateInfo = {}; |
| 4878 | sampleAllocCreateInfo.usage = VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE; |
| 4879 | |
| 4880 | VmaPoolCreateInfo poolCreateInfo = {}; |
| 4881 | VkResult res = vmaFindMemoryTypeIndexForBufferInfo(g_hAllocator, &sampleBufCreateInfo, &sampleAllocCreateInfo, &poolCreateInfo.memoryTypeIndex); |
| 4882 | TEST(res == VK_SUCCESS); |
| 4883 | |
| 4884 | poolCreateInfo.blockSize = bufSizeMax * maxBufCapacity; |
| 4885 | poolCreateInfo.flags = VMA_POOL_CREATE_IGNORE_BUFFER_IMAGE_GRANULARITY_BIT;//TODO remove this |
| 4886 | poolCreateInfo.flags |= algorithm; |
| 4887 | poolCreateInfo.minBlockCount = poolCreateInfo.maxBlockCount = 1; |
| 4888 | |
| 4889 | VmaPool pool = nullptr; |
| 4890 | res = vmaCreatePool(g_hAllocator, &poolCreateInfo, &pool); |
| 4891 | TEST(res == VK_SUCCESS); |
| 4892 | |
| 4893 | // Buffer created just to get memory requirements. Never bound to any memory. |
| 4894 | VkBuffer dummyBuffer = VK_NULL_HANDLE; |
| 4895 | res = vkCreateBuffer(g_hDevice, &sampleBufCreateInfo, g_Allocs, &dummyBuffer); |
| 4896 | TEST(res == VK_SUCCESS && dummyBuffer); |
| 4897 | |
| 4898 | VkMemoryRequirements memReq = {}; |
| 4899 | vkGetBufferMemoryRequirements(g_hDevice, dummyBuffer, &memReq); |
| 4900 | |
| 4901 | vkDestroyBuffer(g_hDevice, dummyBuffer, g_Allocs); |
| 4902 | |
| 4903 | VmaAllocationCreateInfo allocCreateInfo = {}; |
| 4904 | allocCreateInfo.pool = pool; |
| 4905 | allocCreateInfo.flags = allocStrategy; |
| 4906 | |
| 4907 | VmaAllocation alloc; |
| 4908 | std::vector<VmaAllocation> baseAllocations; |
| 4909 | |
| 4910 | if(!empty) |
| 4911 | { |
| 4912 | // Make allocations up to 1/3 of pool size. |
| 4913 | VkDeviceSize totalSize = 0; |
| 4914 | while(totalSize < poolCreateInfo.blockSize / 3) |
| 4915 | { |
| 4916 | // This test intentionally allows sizes that are aligned to 4 or 16 bytes. |
| 4917 | // This is theoretically allowed and already uncovered one bug. |
no test coverage detected