diff --git a/src/gpgmm/BUILD.gn b/src/gpgmm/BUILD.gn index 35efd1b2..03459f30 100644 --- a/src/gpgmm/BUILD.gn +++ b/src/gpgmm/BUILD.gn @@ -120,8 +120,6 @@ source_set("gpgmm_sources") { "d3d12/D3D12Platform.h", "d3d12/DebugObjectD3D12.cpp", "d3d12/DebugObjectD3D12.h", - "d3d12/DebugResourceAllocatorD3D12.cpp", - "d3d12/DebugResourceAllocatorD3D12.h", "d3d12/ErrorD3D12.cpp", "d3d12/ErrorD3D12.h", "d3d12/FenceD3D12.cpp", @@ -137,6 +135,8 @@ source_set("gpgmm_sources") { "d3d12/ResidencyManagerD3D12.h", "d3d12/ResourceAllocationD3D12.cpp", "d3d12/ResourceAllocationD3D12.h", + "d3d12/ResourceAllocationTrackingAllocatorD3D12.cpp", + "d3d12/ResourceAllocationTrackingAllocatorD3D12.h", "d3d12/ResourceAllocatorD3D12.cpp", "d3d12/ResourceAllocatorD3D12.h", "d3d12/ResourceHeapAllocatorD3D12.cpp", diff --git a/src/gpgmm/CMakeLists.txt b/src/gpgmm/CMakeLists.txt index e41b482f..6ade789c 100644 --- a/src/gpgmm/CMakeLists.txt +++ b/src/gpgmm/CMakeLists.txt @@ -59,8 +59,8 @@ if (GPGMM_ENABLE_D3D12) "d3d12/BufferAllocatorD3D12.h" "d3d12/DebugObjectD3D12.cpp" "d3d12/DebugObjectD3D12.h" - "d3d12/DebugResourceAllocatorD3D12.cpp" - "d3d12/DebugResourceAllocatorD3D12.h" + "d3d12/ResourceAllocationTrackingAllocatorD3D12.cpp" + "d3d12/ResourceAllocationTrackingAllocatorD3D12.h" "d3d12/CapsD3D12.cpp" "d3d12/CapsD3D12.h" "d3d12/ErrorD3D12.cpp" diff --git a/src/gpgmm/d3d12/ResourceAllocationD3D12.h b/src/gpgmm/d3d12/ResourceAllocationD3D12.h index d21dd27c..34ad4b36 100644 --- a/src/gpgmm/d3d12/ResourceAllocationD3D12.h +++ b/src/gpgmm/d3d12/ResourceAllocationD3D12.h @@ -23,7 +23,7 @@ namespace gpgmm::d3d12 { - class DebugResourceAllocator; + class ResourceAllocationTrackingAllocator; class ResidencyManager; class ResourceAllocator; class ResidencyHeap; @@ -67,8 +67,8 @@ namespace gpgmm::d3d12 { MemoryBlock* block, ComPtr resource); - // Only DebugResourceAllocator may inject itself to ensure |this| cannot leak. - friend DebugResourceAllocator; + // Only ResourceAllocationTrackingAllocator may inject itself to ensure |this| cannot leak. + friend ResourceAllocationTrackingAllocator; void SetDebugAllocator(MemoryAllocator* allocator); HRESULT SetDebugNameImpl(LPCWSTR name) override; diff --git a/src/gpgmm/d3d12/DebugResourceAllocatorD3D12.cpp b/src/gpgmm/d3d12/ResourceAllocationTrackingAllocatorD3D12.cpp similarity index 72% rename from src/gpgmm/d3d12/DebugResourceAllocatorD3D12.cpp rename to src/gpgmm/d3d12/ResourceAllocationTrackingAllocatorD3D12.cpp index d146fa22..38b85c2a 100644 --- a/src/gpgmm/d3d12/DebugResourceAllocatorD3D12.cpp +++ b/src/gpgmm/d3d12/ResourceAllocationTrackingAllocatorD3D12.cpp @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "gpgmm/d3d12/DebugResourceAllocatorD3D12.h" +#include "gpgmm/d3d12/ResourceAllocationTrackingAllocatorD3D12.h" #include "gpgmm/common/EventMessage.h" #include "gpgmm/d3d12/BackendD3D12.h" @@ -23,30 +23,32 @@ namespace gpgmm::d3d12 { - DebugResourceAllocator::ResourceAllocationEntry::ResourceAllocationEntry( + ResourceAllocationTrackingAllocator::ResourceAllocationEntry::ResourceAllocationEntry( ResourceAllocation* allocation) : mAllocation(allocation) { } - DebugResourceAllocator::ResourceAllocationEntry::ResourceAllocationEntry( + ResourceAllocationTrackingAllocator::ResourceAllocationEntry::ResourceAllocationEntry( ResourceAllocation* allocation, MemoryAllocator* allocator) : mAllocation(allocation), mAllocator(allocator) { } - MemoryAllocator* DebugResourceAllocator::ResourceAllocationEntry::GetAllocator() const { + MemoryAllocator* ResourceAllocationTrackingAllocator::ResourceAllocationEntry::GetAllocator() + const { return mAllocator; } - ResourceAllocation* DebugResourceAllocator::ResourceAllocationEntry::GetAllocation() const { + ResourceAllocation* + ResourceAllocationTrackingAllocator::ResourceAllocationEntry::GetAllocation() const { return mAllocation; } - size_t DebugResourceAllocator::ResourceAllocationEntry::GetKey() const { + size_t ResourceAllocationTrackingAllocator::ResourceAllocationEntry::GetKey() const { return reinterpret_cast(mAllocation); } - void DebugResourceAllocator::ReportLiveAllocations() const { + void ResourceAllocationTrackingAllocator::ReportLiveAllocations() const { std::lock_guard lock(mMutex); for (auto allocationEntry : mLiveAllocations) { const ResourceAllocation* allocation = allocationEntry->GetValue().GetAllocation(); @@ -55,7 +57,7 @@ namespace gpgmm::d3d12 { } } - void DebugResourceAllocator::ReleaseLiveAllocationsForTesting() { + void ResourceAllocationTrackingAllocator::ReleaseLiveAllocationsForTesting() { std::lock_guard lock(mMutex); for (auto allocationEntry : mLiveAllocations) { allocationEntry->GetValue().GetAllocator()->DeallocateMemory( @@ -65,7 +67,7 @@ namespace gpgmm::d3d12 { mLiveAllocations.clear(); } - void DebugResourceAllocator::AddLiveAllocation(ResourceAllocation* allocation) { + void ResourceAllocationTrackingAllocator::TrackAllocation(ResourceAllocation* allocation) { std::lock_guard lock(mMutex); mLiveAllocations.GetOrCreate( @@ -75,11 +77,12 @@ namespace gpgmm::d3d12 { allocation->SetDebugAllocator(this); } - void DebugResourceAllocator::DeallocateMemory(std::unique_ptr allocation) { + void ResourceAllocationTrackingAllocator::DeallocateMemory( + std::unique_ptr allocation) { std::lock_guard lock(mMutex); // KeepAlive must be false so |mLiveAllocations| cache will shrink by 1 entry once |entry| - // falls out of scope below since AddLiveAllocation() adds one (and only one) ref. + // falls out of scope below since TrackAllocation() adds one (and only one) ref. auto entry = mLiveAllocations.GetOrCreate( ResourceAllocationEntry(ToBackend(allocation.get())), false); diff --git a/src/gpgmm/d3d12/DebugResourceAllocatorD3D12.h b/src/gpgmm/d3d12/ResourceAllocationTrackingAllocatorD3D12.h similarity index 74% rename from src/gpgmm/d3d12/DebugResourceAllocatorD3D12.h rename to src/gpgmm/d3d12/ResourceAllocationTrackingAllocatorD3D12.h index 54754151..dc194f5c 100644 --- a/src/gpgmm/d3d12/DebugResourceAllocatorD3D12.h +++ b/src/gpgmm/d3d12/ResourceAllocationTrackingAllocatorD3D12.h @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef GPGMM_D3D12_DEBUGRESOURCEALLOCATORD3D12_H_ -#define GPGMM_D3D12_DEBUGRESOURCEALLOCATORD3D12_H_ +#ifndef GPGMM_D3D12_RESOURCEALLOCATIONTRACKINGALLOCATORD3D12_H_ +#define GPGMM_D3D12_RESOURCEALLOCATIONTRACKINGALLOCATORD3D12_H_ #include "gpgmm/common/MemoryAllocator.h" #include "gpgmm/common/MemoryCache.h" @@ -22,14 +22,14 @@ namespace gpgmm::d3d12 { class ResourceAllocation; - // DebugResourceAllocator tracks "live" allocations so they can be reported if leaked. - // A "live" allocation means the allocation was created (allocated) but not released + // ResourceAllocationTrackingAllocator tracks "live" allocations so they can be reported if + // leaked. A "live" allocation means the allocation was created (allocated) but not released // (de-allocated). - class DebugResourceAllocator final : public MemoryAllocator { + class ResourceAllocationTrackingAllocator final : public MemoryAllocator { public: - DebugResourceAllocator() = default; + ResourceAllocationTrackingAllocator() = default; - void AddLiveAllocation(ResourceAllocation* allocation); + void TrackAllocation(ResourceAllocation* allocation); void ReportLiveAllocations() const; void ReleaseLiveAllocationsForTesting(); @@ -58,4 +58,4 @@ namespace gpgmm::d3d12 { } // namespace gpgmm::d3d12 -#endif // GPGMM_D3D12_DEBUGRESOURCEALLOCATORD3D12_H_ +#endif // GPGMM_D3D12_RESOURCEALLOCATIONTRACKINGALLOCATORD3D12_H_ diff --git a/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp b/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp index e2ff9696..937b2438 100644 --- a/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp +++ b/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp @@ -26,13 +26,13 @@ #include "gpgmm/d3d12/BackendD3D12.h" #include "gpgmm/d3d12/BufferAllocatorD3D12.h" #include "gpgmm/d3d12/CapsD3D12.h" -#include "gpgmm/d3d12/DebugResourceAllocatorD3D12.h" #include "gpgmm/d3d12/ErrorD3D12.h" #include "gpgmm/d3d12/JSONSerializerD3D12.h" #include "gpgmm/d3d12/LogD3D12.h" #include "gpgmm/d3d12/ResidencyHeapD3D12.h" #include "gpgmm/d3d12/ResidencyManagerD3D12.h" #include "gpgmm/d3d12/ResourceAllocationD3D12.h" +#include "gpgmm/d3d12/ResourceAllocationTrackingAllocatorD3D12.h" #include "gpgmm/d3d12/ResourceHeapAllocatorD3D12.h" #include "gpgmm/d3d12/ResourceSizeD3D12.h" #include "gpgmm/d3d12/UtilsD3D12.h" @@ -600,7 +600,7 @@ namespace gpgmm::d3d12 { GPGMM_TRACE_EVENT_OBJECT_NEW(this); if (descriptor.Flags & RESOURCE_ALLOCATOR_FLAG_NEVER_LEAK) { - mDebugAllocator = std::make_unique(); + mTrackingAllocator = std::make_unique(); } const bool isUMA = @@ -813,9 +813,9 @@ namespace gpgmm::d3d12 { // Give the debug allocator the first chance to report allocation leaks. // If allocation leak exists, report then release them immediately to prevent another leak // check from re-reporting the leaked allocation. - if (mDebugAllocator) { - mDebugAllocator->ReportLiveAllocations(); - mDebugAllocator->ReleaseLiveAllocationsForTesting(); + if (mTrackingAllocator) { + mTrackingAllocator->ReportLiveAllocations(); + mTrackingAllocator->ReleaseLiveAllocationsForTesting(); } // Destroy allocators in the reverse order they were created so we can record delete events @@ -956,10 +956,10 @@ namespace gpgmm::d3d12 { ASSERT(allocation->GetResource() != nullptr); - if (GPGMM_UNLIKELY(mDebugAllocator)) { + if (GPGMM_UNLIKELY(mTrackingAllocator)) { GPGMM_RETURN_IF_FAILED(allocation->SetDebugName(allocationDescriptor.DebugName), mDevice); - mDebugAllocator->AddLiveAllocation(static_cast(allocation.Get())); + mTrackingAllocator->TrackAllocation(static_cast(allocation.Get())); } // Update the current usage counters. diff --git a/src/gpgmm/d3d12/ResourceAllocatorD3D12.h b/src/gpgmm/d3d12/ResourceAllocatorD3D12.h index ea2786c1..a52cf17e 100644 --- a/src/gpgmm/d3d12/ResourceAllocatorD3D12.h +++ b/src/gpgmm/d3d12/ResourceAllocatorD3D12.h @@ -31,7 +31,7 @@ namespace gpgmm::d3d12 { class BufferAllocator; class Caps; class ResidencyHeap; - class DebugResourceAllocator; + class ResourceAllocationTrackingAllocator; class ResidencyManager; class ResourceAllocation; @@ -179,7 +179,7 @@ namespace gpgmm::d3d12 { std::array, kNumOfResourceHeapTypes> mSmallBufferAllocatorOfType; - std::unique_ptr mDebugAllocator; + std::unique_ptr mTrackingAllocator; }; } // namespace gpgmm::d3d12