From 8f950827b8126fb83675952515eee477319ab859 Mon Sep 17 00:00:00 2001 From: "Bernhart, Bryan" Date: Thu, 2 Mar 2023 09:48:21 -0800 Subject: [PATCH] Make all public DX objects inherit DebugObject. --- include/gpgmm_d3d12.h | 4 ++-- src/gpgmm/d3d12/DebugObjectD3D12.cpp | 5 +++++ src/gpgmm/d3d12/DebugObjectD3D12.h | 4 +++- src/gpgmm/d3d12/HeapD3D12.h | 1 - src/gpgmm/d3d12/ResidencyManagerD3D12.cpp | 8 ++++++++ src/gpgmm/d3d12/ResidencyManagerD3D12.h | 9 +++++++-- src/gpgmm/d3d12/ResourceAllocationD3D12.h | 2 -- src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp | 8 ++++++++ src/gpgmm/d3d12/ResourceAllocatorD3D12.h | 8 ++++++-- src/mvi/gpgmm_d3d12.cpp | 16 ++++++++++++++++ src/mvi/gpgmm_d3d12.h | 8 ++++++++ 11 files changed, 63 insertions(+), 10 deletions(-) diff --git a/include/gpgmm_d3d12.h b/include/gpgmm_d3d12.h index 6600f293c..d4e9d1bd3 100644 --- a/include/gpgmm_d3d12.h +++ b/include/gpgmm_d3d12.h @@ -444,7 +444,7 @@ namespace gpgmm::d3d12 { Internally, the ResidencyManager keeps the application in-budget by calling ID3D12Device::Evict and ID3D12Device::MakeResident to page-out or page-in heaps, respectively. **/ - GPGMM_INTERFACE IResidencyManager : public IUnknown { + GPGMM_INTERFACE IResidencyManager : public IDebugObject { public: /** \brief Locks the specified heap. @@ -1095,7 +1095,7 @@ namespace gpgmm::d3d12 { budget. And similarly, a smaller Heap allows for finer grained residency but could increase overall memory usage for allocation. **/ - GPGMM_INTERFACE IResourceAllocator : public IUnknown { + GPGMM_INTERFACE IResourceAllocator : public IDebugObject { public: /** \brief Allocates memory and creates a D3D12 resource using it. diff --git a/src/gpgmm/d3d12/DebugObjectD3D12.cpp b/src/gpgmm/d3d12/DebugObjectD3D12.cpp index be40d53f1..1336d5e34 100644 --- a/src/gpgmm/d3d12/DebugObjectD3D12.cpp +++ b/src/gpgmm/d3d12/DebugObjectD3D12.cpp @@ -31,4 +31,9 @@ namespace gpgmm::d3d12 { return SetDebugNameImpl(Name); } + HRESULT DebugObject::SetDebugNameImpl(LPCWSTR name) { + mDebugName = name; + return S_OK; + } + } // namespace gpgmm::d3d12 diff --git a/src/gpgmm/d3d12/DebugObjectD3D12.h b/src/gpgmm/d3d12/DebugObjectD3D12.h index 51f19cad1..5cd9fa246 100644 --- a/src/gpgmm/d3d12/DebugObjectD3D12.h +++ b/src/gpgmm/d3d12/DebugObjectD3D12.h @@ -29,9 +29,11 @@ namespace gpgmm::d3d12 { LPCWSTR GetDebugName() const; HRESULT SetDebugName(LPCWSTR Name); + DEFINE_UNKNOWN_OVERRIDES() + protected: // Derived classes should override to associate the name with the containing ID3D12Object. - virtual HRESULT SetDebugNameImpl(LPCWSTR name) = 0; + virtual HRESULT SetDebugNameImpl(LPCWSTR name); private: std::wstring mDebugName; diff --git a/src/gpgmm/d3d12/HeapD3D12.h b/src/gpgmm/d3d12/HeapD3D12.h index f9b9ae74a..2c41319ea 100644 --- a/src/gpgmm/d3d12/HeapD3D12.h +++ b/src/gpgmm/d3d12/HeapD3D12.h @@ -18,7 +18,6 @@ #include "gpgmm/common/Memory.h" #include "gpgmm/d3d12/DebugObjectD3D12.h" -#include "gpgmm/d3d12/UnknownD3D12.h" #include "gpgmm/utils/Limits.h" #include "gpgmm/utils/LinkedList.h" diff --git a/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp b/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp index 2b3ce2173..cb68786ea 100644 --- a/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp +++ b/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp @@ -1033,4 +1033,12 @@ namespace gpgmm::d3d12 { return S_OK; } + LPCWSTR ResidencyManager::GetDebugName() const { + return DebugObject::GetDebugName(); + } + + HRESULT ResidencyManager::SetDebugName(LPCWSTR Name) { + return DebugObject::SetDebugNameImpl(Name); + } + } // namespace gpgmm::d3d12 diff --git a/src/gpgmm/d3d12/ResidencyManagerD3D12.h b/src/gpgmm/d3d12/ResidencyManagerD3D12.h index 28c58e16b..0f4234228 100644 --- a/src/gpgmm/d3d12/ResidencyManagerD3D12.h +++ b/src/gpgmm/d3d12/ResidencyManagerD3D12.h @@ -17,7 +17,7 @@ #define GPGMM_D3D12_RESIDENCYMANAGERD3D12_H_ #include "gpgmm/common/Object.h" -#include "gpgmm/d3d12/UnknownD3D12.h" +#include "gpgmm/d3d12/DebugObjectD3D12.h" #include "gpgmm/utils/EnumFlags.h" #include "gpgmm/utils/LinkedList.h" @@ -40,7 +40,7 @@ namespace gpgmm::d3d12 { class ResourceAllocator; class ResourceHeapAllocator; - class ResidencyManager final : public Unknown, public IResidencyManager, ObjectBase { + class ResidencyManager final : public DebugObject, public IResidencyManager, public ObjectBase { public: static HRESULT CreateResidencyManager(const RESIDENCY_DESC& descriptor, IResidencyManager** ppResidencyManagerOut); @@ -92,8 +92,13 @@ namespace gpgmm::d3d12 { bool IsUMA() const; + // ObjectBase interface const char* GetTypename() const override; + // IDebugObject interface + LPCWSTR GetDebugName() const override; + HRESULT SetDebugName(LPCWSTR Name) override; + using LRUCache = LinkedList; struct VideoMemorySegment { diff --git a/src/gpgmm/d3d12/ResourceAllocationD3D12.h b/src/gpgmm/d3d12/ResourceAllocationD3D12.h index 447c1546b..4c6d439f3 100644 --- a/src/gpgmm/d3d12/ResourceAllocationD3D12.h +++ b/src/gpgmm/d3d12/ResourceAllocationD3D12.h @@ -18,8 +18,6 @@ #include "gpgmm/common/MemoryAllocation.h" #include "gpgmm/d3d12/DebugObjectD3D12.h" -#include "gpgmm/d3d12/UnknownD3D12.h" -#include "gpgmm/d3d12/d3d12_platform.h" #include diff --git a/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp b/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp index f248b5125..ba2cd3685 100644 --- a/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp +++ b/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp @@ -1638,6 +1638,14 @@ namespace gpgmm::d3d12 { return E_INVALIDARG; } + LPCWSTR ResourceAllocator::GetDebugName() const { + return DebugObject::GetDebugName(); + } + + HRESULT ResourceAllocator::SetDebugName(LPCWSTR Name) { + return DebugObject::SetDebugNameImpl(Name); + } + ImportResourceCallbackContext::ImportResourceCallbackContext(ID3D12Resource* resource) : mResource(resource) { } diff --git a/src/gpgmm/d3d12/ResourceAllocatorD3D12.h b/src/gpgmm/d3d12/ResourceAllocatorD3D12.h index 17bde2433..d9eb217c7 100644 --- a/src/gpgmm/d3d12/ResourceAllocatorD3D12.h +++ b/src/gpgmm/d3d12/ResourceAllocatorD3D12.h @@ -17,7 +17,7 @@ #define GPGMM_D3D12_RESOURCEALLOCATORD3D12_H_ #include "gpgmm/common/MemoryAllocator.h" -#include "gpgmm/d3d12/UnknownD3D12.h" +#include "gpgmm/d3d12/DebugObjectD3D12.h" #include "gpgmm/utils/EnumFlags.h" #include @@ -35,7 +35,7 @@ namespace gpgmm::d3d12 { class ResidencyManager; class ResourceAllocation; - class ResourceAllocator final : public Unknown, + class ResourceAllocator final : public DebugObject, public IResourceAllocator, public MemoryAllocator { public: @@ -73,6 +73,10 @@ namespace gpgmm::d3d12 { // ObjectBase interface const char* GetTypename() const override; + // IDebugObject interface + LPCWSTR GetDebugName() const override; + HRESULT SetDebugName(LPCWSTR Name) override; + HRESULT CreateResourceInternal(const ALLOCATION_DESC& allocationDescriptor, const D3D12_RESOURCE_DESC& resourceDescriptor, D3D12_RESOURCE_STATES initialResourceState, diff --git a/src/mvi/gpgmm_d3d12.cpp b/src/mvi/gpgmm_d3d12.cpp index d855edbb9..21a32251f 100644 --- a/src/mvi/gpgmm_d3d12.cpp +++ b/src/mvi/gpgmm_d3d12.cpp @@ -219,6 +219,14 @@ namespace gpgmm::d3d12 { return Unknown::Release(); } + LPCWSTR ResidencyManager::GetDebugName() const { + return L""; + } + + HRESULT ResidencyManager::SetDebugName(LPCWSTR Name) { + return S_OK; + } + // ResourceAllocation void ResourceAllocation::DeleteThis() { @@ -419,6 +427,14 @@ namespace gpgmm::d3d12 { return Unknown::Release(); } + LPCWSTR ResourceAllocator::GetDebugName() const { + return L""; + } + + HRESULT ResourceAllocator::SetDebugName(LPCWSTR Name) { + return S_OK; + } + CreateCommittedResourceCallbackContext::CreateCommittedResourceCallbackContext( ID3D12Device* device, ALLOCATION_DESC allocationDescriptor, diff --git a/src/mvi/gpgmm_d3d12.h b/src/mvi/gpgmm_d3d12.h index 90f9fb8be..37d3693c8 100644 --- a/src/mvi/gpgmm_d3d12.h +++ b/src/mvi/gpgmm_d3d12.h @@ -130,6 +130,10 @@ namespace gpgmm::d3d12 { ULONG STDMETHODCALLTYPE AddRef() override; ULONG STDMETHODCALLTYPE Release() override; + // IDebugObject interface + LPCWSTR GetDebugName() const override; + HRESULT SetDebugName(LPCWSTR Name) override; + private: ResidencyManager(const RESIDENCY_DESC& descriptor); @@ -228,6 +232,10 @@ namespace gpgmm::d3d12 { ULONG STDMETHODCALLTYPE AddRef() override; ULONG STDMETHODCALLTYPE Release() override; + // IDebugObject interface + LPCWSTR GetDebugName() const override; + HRESULT SetDebugName(LPCWSTR Name) override; + private: ResourceAllocator(const ALLOCATOR_DESC& descriptor, ResidencyManager* pResidencyManager);