From 9a091e8ccba58e67c07c4a8e6a56d5bfe5ab1291 Mon Sep 17 00:00:00 2001 From: Adam Sawicki Date: Thu, 28 Oct 2021 15:00:24 +0200 Subject: [PATCH] Implemented vmaCalculateVirtualBlockStats --- include/vk_mem_alloc.h | 9 ++++++++- src/Tests.cpp | 14 +++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/include/vk_mem_alloc.h b/include/vk_mem_alloc.h index 53da44e..25f72a5 100644 --- a/include/vk_mem_alloc.h +++ b/include/vk_mem_alloc.h @@ -6891,6 +6891,10 @@ public: { m_Metadata->SetAllocationUserData(offset, userData); } + void CalculateStats(VmaStatInfo& outStatInfo) const + { + m_Metadata->CalcAllocationStatInfo(outStatInfo); + } private: VmaBlockMetadata* m_Metadata; @@ -18403,7 +18407,10 @@ VMA_CALL_PRE void VMA_CALL_POST vmaSetVirtualAllocationUserData(VmaVirtualBlock VMA_CALL_PRE void VMA_CALL_POST vmaCalculateVirtualBlockStats(VmaVirtualBlock VMA_NOT_NULL virtualBlock, VmaStatInfo* VMA_NOT_NULL pStatInfo) { - VMA_ASSERT(0 && "TODO implement"); + VMA_ASSERT(virtualBlock != VK_NULL_HANDLE && pStatInfo != VMA_NULL); + VMA_DEBUG_LOG("vmaCalculateVirtualBlockStats"); + VMA_DEBUG_GLOBAL_MUTEX_LOCK; + virtualBlock->CalculateStats(*pStatInfo); } VMA_CALL_PRE void VMA_CALL_POST vmaBuildVirtualBlockStatsString(VmaVirtualBlock VMA_NOT_NULL virtualBlock, diff --git a/src/Tests.cpp b/src/Tests.cpp index def6c9f..2c85b76 100644 --- a/src/Tests.cpp +++ b/src/Tests.cpp @@ -2747,16 +2747,16 @@ static void TestVirtualBlocks() TEST(alloc2Offset < blockSize); TEST(alloc2Offset + 4 * MEGABYTE <= alloc0Offset || alloc0Offset + 8 * MEGABYTE <= alloc2Offset); // Check if they don't overlap. -#if 0 // # Calculate statistics - StatInfo statInfo = {}; - block->CalculateStats(&statInfo); - CHECK_BOOL(statInfo.AllocationCount == 2); - CHECK_BOOL(statInfo.BlockCount == 1); - CHECK_BOOL(statInfo.UsedBytes == blockSize); - CHECK_BOOL(statInfo.UnusedBytes + statInfo.UsedBytes == blockSize); + VmaStatInfo statInfo = {}; + vmaCalculateVirtualBlockStats(block, &statInfo); + TEST(statInfo.allocationCount == 2); + TEST(statInfo.blockCount == 1); + TEST(statInfo.usedBytes == blockSize); + TEST(statInfo.unusedBytes + statInfo.usedBytes == blockSize); +#if 0 // # Generate JSON dump WCHAR* json = nullptr;