Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -826,8 +826,12 @@ namespace gpgmm { namespace d3d12 {
allocationDescriptor.HeapType, heapFlags, resourceInfo.SizeInBytes, &newResourceDesc,
clearValue, initialResourceState, &committedResource, &resourceHeap));

mInfo.UsedMemoryUsage += resourceHeap->GetSize();
// Using committed resources will create a tightly allocated resource allocations.
// This means the block and heap size should be equal (modulo driver padding).
const uint64_t allocationSize = resourceHeap->GetSize();
mInfo.UsedMemoryUsage += allocationSize;
mInfo.UsedMemoryCount++;
mInfo.UsedBlockUsage += allocationSize;

*resourceAllocationOut = new ResourceAllocation{mResidencyManager.Get(),
/*allocator*/ this,
Expand Down Expand Up @@ -1017,8 +1021,11 @@ namespace gpgmm { namespace d3d12 {

std::lock_guard<std::mutex> lock(mMutex);

mInfo.UsedMemoryUsage -= allocation->GetSize();
const uint64_t allocationSize = allocation->GetSize();
mInfo.UsedMemoryUsage -= allocationSize;
mInfo.UsedMemoryCount--;
mInfo.UsedBlockUsage -= allocationSize;

SafeRelease(allocation);
}

Expand Down
4 changes: 4 additions & 0 deletions src/tests/end2end/D3D12ResourceAllocatorTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,10 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferAlwaysCommitted) {
Heap* resourceHeap = ToBackend(allocation->GetMemory());
ASSERT_NE(resourceHeap, nullptr);
ASSERT_EQ(resourceHeap->GetHeap(), nullptr);

// Commited resources must use all the memory allocated.
EXPECT_EQ(allocator->GetInfo().UsedMemoryUsage, kDefaultPreferredResourceHeapSize);
EXPECT_EQ(allocator->GetInfo().UsedBlockUsage, allocator->GetInfo().UsedMemoryUsage);
}

TEST_F(D3D12ResourceAllocatorTests, CreateBufferNeverAllocate) {
Expand Down