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

Function TestStatistics

src/Tests.cpp:6657–6901  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6655}
6656
6657static 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);

Callers 1

TestFunction · 0.85

Calls 13

vmaGetMemoryPropertiesFunction · 0.85
vmaSetCurrentFrameIndexFunction · 0.85
vmaGetHeapBudgetsFunction · 0.85
vmaCalculateStatisticsFunction · 0.85
TESTEnum · 0.85
vmaCreatePoolFunction · 0.85
vmaGetPoolStatisticsFunction · 0.85
vmaCreateBufferFunction · 0.85
MemoryTypeToHeapFunction · 0.85
vmaDestroyBufferFunction · 0.85
vmaDestroyPoolFunction · 0.85

Tested by

no test coverage detected