| 6655 | } |
| 6656 | |
| 6657 | static void TestStatistics() |
| 6658 | { |
| 6659 | wprintf(L"Testing statistics...\n"); |
| 6660 | |
| 6661 | constexpr VkDeviceSize BUF_SIZE = 10ull * 1024 * 1024; |
| 6662 | constexpr uint32_t BUF_COUNT = 4; |
| 6663 | constexpr VkDeviceSize PREALLOCATED_BLOCK_SIZE = BUF_SIZE * (BUF_COUNT + 1); |
| 6664 | |
| 6665 | const VkPhysicalDeviceMemoryProperties* memProps = {}; |
| 6666 | vmaGetMemoryProperties(g_hAllocator, &memProps); |
| 6667 | |
| 6668 | /* |
| 6669 | Test 0: VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT. |
| 6670 | Test 1: normal allocations. |
| 6671 | Test 2: allocations in a custom pool. |
| 6672 | Test 3: allocations in a custom pool, DEDICATED_MEMORY. |
| 6673 | Test 4: allocations in a custom pool with preallocated memory. |
| 6674 | */ |
| 6675 | uint32_t memTypeIndex = UINT32_MAX; |
| 6676 | for(uint32_t testIndex = 0; testIndex < 5; ++testIndex) |
| 6677 | { |
| 6678 | vmaSetCurrentFrameIndex(g_hAllocator, ++g_FrameIndex); |
| 6679 | |
| 6680 | VmaBudget budgetBeg[VK_MAX_MEMORY_HEAPS] = {}; |
| 6681 | vmaGetHeapBudgets(g_hAllocator, budgetBeg); |
| 6682 | VmaTotalStatistics statsBeg = {}; |
| 6683 | vmaCalculateStatistics(g_hAllocator, &statsBeg); |
| 6684 | |
| 6685 | for(uint32_t i = 0; i < memProps->memoryHeapCount; ++i) |
| 6686 | { |
| 6687 | TEST(budgetBeg[i].budget > 0); |
| 6688 | TEST(budgetBeg[i].budget <= memProps->memoryHeaps[i].size); |
| 6689 | TEST(budgetBeg[i].statistics.allocationBytes <= budgetBeg[i].statistics.blockBytes); |
| 6690 | } |
| 6691 | |
| 6692 | // Create pool. |
| 6693 | const bool usePool = testIndex >= 2; |
| 6694 | const bool useDedicated = testIndex == 0 || testIndex == 3; |
| 6695 | const bool usePreallocated = testIndex == 4; |
| 6696 | VmaPool pool = VK_NULL_HANDLE; |
| 6697 | if(usePool) |
| 6698 | { |
| 6699 | assert(memTypeIndex != UINT32_MAX); |
| 6700 | VmaPoolCreateInfo poolCreateInfo = {}; |
| 6701 | poolCreateInfo.memoryTypeIndex = memTypeIndex; |
| 6702 | if(usePreallocated) |
| 6703 | { |
| 6704 | poolCreateInfo.blockSize = PREALLOCATED_BLOCK_SIZE; |
| 6705 | poolCreateInfo.minBlockCount = poolCreateInfo.maxBlockCount = 1; |
| 6706 | } |
| 6707 | TEST(vmaCreatePool(g_hAllocator, &poolCreateInfo, &pool) == VK_SUCCESS); |
| 6708 | } |
| 6709 | |
| 6710 | VmaStatistics poolStatsBeg = {}; |
| 6711 | VmaDetailedStatistics detailedPoolStatsBeg = {}; |
| 6712 | if(usePool) |
| 6713 | { |
| 6714 | vmaGetPoolStatistics(g_hAllocator, pool, &poolStatsBeg); |
no test coverage detected