Fixed Allocator::CalculateStats for committed allocations in custom pools
Added test for it.
diff --git a/src/D3D12MemAlloc.cpp b/src/D3D12MemAlloc.cpp
index 9fc000a..b50c193 100644
--- a/src/D3D12MemAlloc.cpp
+++ b/src/D3D12MemAlloc.cpp
@@ -2800,6 +2800,7 @@
CommittedAllocationList* GetCommittedAllocationList() { return SupportsCommittedAllocations() ? &m_CommittedAllocations : NULL; }
void CalculateStats(StatInfo& outStats);
+ void AddStats(Stats& inoutStats);
void SetName(LPCWSTR Name);
LPCWSTR GetName() const { return m_Name; }
@@ -4444,6 +4445,15 @@
PostProcessStatInfo(outStats);
}
+void PoolPimpl::AddStats(Stats& inoutStats)
+{
+ StatInfo poolStatInfo = {};
+ CalculateStats(poolStatInfo);
+
+ AddStatInfo(inoutStats.Total, poolStatInfo);
+ AddStatInfo(inoutStats.HeapType[HeapTypeToIndex(m_Desc.HeapProperties.Type)], poolStatInfo);
+}
+
void PoolPimpl::SetName(LPCWSTR Name)
{
FreeName();
@@ -5448,7 +5458,6 @@
}
// Process deafult pools.
-
if(SupportsResourceHeapTier2())
{
for(size_t heapTypeIndex = 0; heapTypeIndex < STANDARD_HEAP_TYPE_COUNT; ++heapTypeIndex)
@@ -5478,7 +5487,7 @@
PoolList& poolList = m_Pools[heapTypeIndex];
for(PoolPimpl* pool = poolList.Front(); pool != NULL; pool = poolList.GetNext(pool))
{
- pool->GetBlockVector()->AddStats(outStats);
+ pool->AddStats(outStats);
}
}
diff --git a/src/Tests.cpp b/src/Tests.cpp
index fbca62a..8374feb 100644
--- a/src/Tests.cpp
+++ b/src/Tests.cpp
@@ -809,6 +809,13 @@
std::vector<AllocationUniquePtr> allocations;
+ D3D12MA::Stats statsBeg = {};
+ D3D12MA::StatInfo poolStatInfoBeg = {};
+ ctx.allocator->CalculateStats(&statsBeg);
+ pool->CalculateStats(&poolStatInfoBeg);
+
+ size_t poolAllocCount = 0;
+
D3D12_RESOURCE_DESC resDesc = {};
FillResourceDescForBuffer(resDesc, bufferSize);
@@ -839,13 +846,30 @@
D3D12_RESOURCE_STATE_COMMON,
NULL, // pOptimizedClearValue
&allocPtr, IID_NULL, NULL);
+ CHECK_BOOL(SUCCEEDED(hr) == (allocPtr != NULL));
if(allocPtr)
+ {
allocations.push_back(AllocationUniquePtr{allocPtr});
+ if(useCustomPool)
+ ++poolAllocCount;
+ }
bool expectSuccess = !neverAllocate; // NEVER_ALLOCATE should always fail with COMMITTED.
CHECK_BOOL(expectSuccess == SUCCEEDED(hr));
}
}
+
+ D3D12MA::Stats statsEnd = {};
+ D3D12MA::StatInfo poolStatInfoEnd = {};
+ ctx.allocator->CalculateStats(&statsEnd);
+ pool->CalculateStats(&poolStatInfoEnd);
+
+ CHECK_BOOL(statsEnd.Total.AllocationCount == statsBeg.Total.AllocationCount + allocations.size());
+ CHECK_BOOL(statsEnd.Total.UsedBytes >= statsBeg.Total.UsedBytes + allocations.size() * bufferSize);
+ CHECK_BOOL(statsEnd.HeapType[0].AllocationCount == statsBeg.HeapType[0].AllocationCount + allocations.size());
+ CHECK_BOOL(statsEnd.HeapType[0].UsedBytes >= statsBeg.HeapType[0].UsedBytes + allocations.size() * bufferSize);
+ CHECK_BOOL(poolStatInfoEnd.AllocationCount == poolStatInfoBeg.AllocationCount + poolAllocCount);
+ CHECK_BOOL(poolStatInfoEnd.UsedBytes >= poolStatInfoBeg.UsedBytes + poolAllocCount * bufferSize);
}
static void TestAliasingMemory(const TestContext& ctx)