diff --git a/src/gpgmm/d3d12/ResidencyHeapD3D12.cpp b/src/gpgmm/d3d12/ResidencyHeapD3D12.cpp index 95ca4082..a1095314 100644 --- a/src/gpgmm/d3d12/ResidencyHeapD3D12.cpp +++ b/src/gpgmm/d3d12/ResidencyHeapD3D12.cpp @@ -306,16 +306,20 @@ namespace gpgmm::d3d12 { } } - ResidencyHeap::~ResidencyHeap() { - if (mResidencyManager == nullptr) { - return; - } - + void ResidencyHeap::DeleteThis() { if (IsResidencyLocked() && GPGMM_UNSUCCESSFUL(Unlock())) { DebugLog(MessageId::kUnknown, this) << "Heap was locked for residency while being destroyed."; } + Unknown::DeleteThis(); + } + + ResidencyHeap::~ResidencyHeap() { + if (mResidencyManager == nullptr) { + return; + } + // When a heap is destroyed, it no longer resides in resident memory, so we must evict // it from the residency cache. If this heap is not manually removed from the residency // cache, the ResidencyManager will attempt to use it after it has been deallocated. diff --git a/src/gpgmm/d3d12/ResidencyHeapD3D12.h b/src/gpgmm/d3d12/ResidencyHeapD3D12.h index efea297e..966a343b 100644 --- a/src/gpgmm/d3d12/ResidencyHeapD3D12.h +++ b/src/gpgmm/d3d12/ResidencyHeapD3D12.h @@ -71,6 +71,9 @@ namespace gpgmm::d3d12 { const RESIDENCY_HEAP_DESC& descriptor, bool isResidencyDisabled); + // Unknown interface + void DeleteThis() override; + // ObjectBase interface DEFINE_OBJECT_BASE_OVERRIDES(IHeap) diff --git a/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp b/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp index 971bae42..c3aa39f5 100644 --- a/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp +++ b/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp @@ -181,10 +181,13 @@ namespace gpgmm::d3d12 { ASSERT(mAdapter != nullptr); } - ResidencyManager::~ResidencyManager() { - GPGMM_TRACE_EVENT_OBJECT_DESTROY(this); + void ResidencyManager::DeleteThis() { StopBudgetNotificationUpdates(); + Unknown::DeleteThis(); + } + ResidencyManager::~ResidencyManager() { + GPGMM_TRACE_EVENT_OBJECT_DESTROY(this); if (mFlushEventBuffersOnDestruct) { FlushEventTraceToDisk(); } diff --git a/src/gpgmm/d3d12/ResidencyManagerD3D12.h b/src/gpgmm/d3d12/ResidencyManagerD3D12.h index c7730a73..bd30a1e0 100644 --- a/src/gpgmm/d3d12/ResidencyManagerD3D12.h +++ b/src/gpgmm/d3d12/ResidencyManagerD3D12.h @@ -84,6 +84,9 @@ namespace gpgmm::d3d12 { IDXGIAdapter3* pAdapter, std::unique_ptr caps); + // Unknown interface + void DeleteThis() override; + HRESULT EvictInternal(uint64_t bytesToEvict, const DXGI_MEMORY_SEGMENT_GROUP& heapSegment, uint64_t* bytesEvictedOut = nullptr); diff --git a/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp b/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp index b419d1e4..b162f3ea 100644 --- a/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp +++ b/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp @@ -832,9 +832,7 @@ namespace gpgmm::d3d12 { /*allowSlabPrefetch*/ false, std::move(pooledOrNonPooledAllocator)); } - ResourceAllocator::~ResourceAllocator() { - GPGMM_TRACE_EVENT_OBJECT_DESTROY(this); - + void ResourceAllocator::DeleteThis() { // 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. @@ -870,6 +868,11 @@ namespace gpgmm::d3d12 { #endif mResidencyManager = nullptr; + Unknown::DeleteThis(); + } + + ResourceAllocator::~ResourceAllocator() { + GPGMM_TRACE_EVENT_OBJECT_DESTROY(this); if (mFlushEventBuffersOnDestruct) { FlushEventTraceToDisk(); } diff --git a/src/gpgmm/d3d12/ResourceAllocatorD3D12.h b/src/gpgmm/d3d12/ResourceAllocatorD3D12.h index b75f2a34..4c24e2aa 100644 --- a/src/gpgmm/d3d12/ResourceAllocatorD3D12.h +++ b/src/gpgmm/d3d12/ResourceAllocatorD3D12.h @@ -83,6 +83,8 @@ namespace gpgmm::d3d12 { ResidencyManager* pResidencyManager, std::unique_ptr caps); + void DeleteThis() override; + template MaybeError TryAllocateResource(MemoryAllocatorBase* allocator, const MemoryAllocationRequest& request,