mirror of
https://github.com/GPUOpen-LibrariesAndSDKs/D3D12MemoryAllocator.git
synced 2024-11-21 11:50:03 +00:00
Fixed Allocator::CalculateStats for committed allocations in custom pools
Added test for it.
This commit is contained in:
parent
d647ce1202
commit
cb0376a32e
@ -2800,6 +2800,7 @@ public:
|
||||
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 @@ void PoolPimpl::CalculateStats(StatInfo& outStats)
|
||||
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 @@ void AllocatorPimpl::CalculateStats(Stats& outStats)
|
||||
}
|
||||
|
||||
// Process deafult pools.
|
||||
|
||||
if(SupportsResourceHeapTier2())
|
||||
{
|
||||
for(size_t heapTypeIndex = 0; heapTypeIndex < STANDARD_HEAP_TYPE_COUNT; ++heapTypeIndex)
|
||||
@ -5478,7 +5487,7 @@ void AllocatorPimpl::CalculateStats(Stats& outStats)
|
||||
PoolList& poolList = m_Pools[heapTypeIndex];
|
||||
for(PoolPimpl* pool = poolList.Front(); pool != NULL; pool = poolList.GetNext(pool))
|
||||
{
|
||||
pool->GetBlockVector()->AddStats(outStats);
|
||||
pool->AddStats(outStats);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -809,6 +809,13 @@ static void TestStandardCustomCommittedPlaced(const TestContext& ctx)
|
||||
|
||||
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 @@ static void TestStandardCustomCommittedPlaced(const TestContext& ctx)
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user