From e28a4b33bb95682e7ccddea00e99ea553a80f3da Mon Sep 17 00:00:00 2001 From: "Bernhart, Bryan" Date: Thu, 12 Jan 2023 12:29:19 -0800 Subject: [PATCH] Minor refactor to prepare for release. --- src/gpgmm/common/BuddyBlockAllocator.h | 1 + src/gpgmm/common/BuddyMemoryAllocator.h | 1 + src/gpgmm/common/ConditionalMemoryAllocator.h | 1 + src/gpgmm/common/DedicatedMemoryAllocator.h | 1 + src/gpgmm/common/Memory.h | 1 + src/gpgmm/common/PooledMemoryAllocator.h | 1 + src/gpgmm/common/SegmentedMemoryAllocator.h | 1 + src/gpgmm/common/SlabBlockAllocator.h | 1 + src/gpgmm/common/SlabMemoryAllocator.h | 2 ++ src/gpgmm/d3d12/DebugResourceAllocatorD3D12.h | 5 +++-- src/gpgmm/d3d12/HeapD3D12.h | 4 +++- src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp | 9 +++------ src/gpgmm/d3d12/ResourceAllocatorD3D12.h | 7 ++++--- src/gpgmm/d3d12/ResourceHeapAllocatorD3D12.cpp | 6 ++++-- src/gpgmm/d3d12/ResourceHeapAllocatorD3D12.h | 1 + 15 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/gpgmm/common/BuddyBlockAllocator.h b/src/gpgmm/common/BuddyBlockAllocator.h index f82f1e3a7..82f98346a 100644 --- a/src/gpgmm/common/BuddyBlockAllocator.h +++ b/src/gpgmm/common/BuddyBlockAllocator.h @@ -49,6 +49,7 @@ namespace gpgmm { uint64_t ComputeTotalNumOfFreeBlocksForTesting() const; private: + // ObjectBase interface const char* GetTypename() const override; uint32_t ComputeLevelFromBlockSize(uint64_t blockSize) const; diff --git a/src/gpgmm/common/BuddyMemoryAllocator.h b/src/gpgmm/common/BuddyMemoryAllocator.h index 763a0c90c..ecb9b28ee 100644 --- a/src/gpgmm/common/BuddyMemoryAllocator.h +++ b/src/gpgmm/common/BuddyMemoryAllocator.h @@ -52,6 +52,7 @@ namespace gpgmm { MemoryAllocatorStats GetStats() const override; private: + // ObjectBase interface const char* GetTypename() const override; uint64_t GetMemoryIndex(uint64_t offset) const; diff --git a/src/gpgmm/common/ConditionalMemoryAllocator.h b/src/gpgmm/common/ConditionalMemoryAllocator.h index e18c48a6f..43662d18e 100644 --- a/src/gpgmm/common/ConditionalMemoryAllocator.h +++ b/src/gpgmm/common/ConditionalMemoryAllocator.h @@ -40,6 +40,7 @@ namespace gpgmm { MemoryAllocator* GetSecondAllocatorForTesting() const; private: + // ObjectBase interface const char* GetTypename() const override; std::unique_ptr mFirstAllocator; diff --git a/src/gpgmm/common/DedicatedMemoryAllocator.h b/src/gpgmm/common/DedicatedMemoryAllocator.h index 984203265..6248a8c58 100644 --- a/src/gpgmm/common/DedicatedMemoryAllocator.h +++ b/src/gpgmm/common/DedicatedMemoryAllocator.h @@ -36,6 +36,7 @@ namespace gpgmm { MemoryAllocatorStats GetStats() const override; private: + // ObjectBase interface const char* GetTypename() const override; }; diff --git a/src/gpgmm/common/Memory.h b/src/gpgmm/common/Memory.h index de11d0716..d9517d36a 100644 --- a/src/gpgmm/common/Memory.h +++ b/src/gpgmm/common/Memory.h @@ -37,6 +37,7 @@ namespace gpgmm { bool RemoveSubAllocationRef(); private: + // ObjectBase interface const char* GetTypename() const override; RefCounted mSubAllocationRefs; diff --git a/src/gpgmm/common/PooledMemoryAllocator.h b/src/gpgmm/common/PooledMemoryAllocator.h index 8454dad69..2db088905 100644 --- a/src/gpgmm/common/PooledMemoryAllocator.h +++ b/src/gpgmm/common/PooledMemoryAllocator.h @@ -38,6 +38,7 @@ namespace gpgmm { uint64_t GetMemoryAlignment() const override; private: + // ObjectBase interface const char* GetTypename() const override; std::unique_ptr mPool; diff --git a/src/gpgmm/common/SegmentedMemoryAllocator.h b/src/gpgmm/common/SegmentedMemoryAllocator.h index dbdb3f1a1..98df17a49 100644 --- a/src/gpgmm/common/SegmentedMemoryAllocator.h +++ b/src/gpgmm/common/SegmentedMemoryAllocator.h @@ -48,6 +48,7 @@ namespace gpgmm { uint64_t GetSegmentSizeForTesting() const; private: + // ObjectBase interface const char* GetTypename() const override; MemorySegment* GetOrCreateFreeSegment(uint64_t memorySize); diff --git a/src/gpgmm/common/SlabBlockAllocator.h b/src/gpgmm/common/SlabBlockAllocator.h index 4988a2748..70723adcf 100644 --- a/src/gpgmm/common/SlabBlockAllocator.h +++ b/src/gpgmm/common/SlabBlockAllocator.h @@ -53,6 +53,7 @@ namespace gpgmm { uint64_t GetBlockCount() const; private: + // ObjectBase interface const char* GetTypename() const override; struct BlockList { diff --git a/src/gpgmm/common/SlabMemoryAllocator.h b/src/gpgmm/common/SlabMemoryAllocator.h index 2c783ea1f..a9badb77d 100644 --- a/src/gpgmm/common/SlabMemoryAllocator.h +++ b/src/gpgmm/common/SlabMemoryAllocator.h @@ -62,6 +62,7 @@ namespace gpgmm { MemoryAllocatorStats GetStats() const override; private: + // ObjectBase interface const char* GetTypename() const override; uint64_t ComputeSlabSize(uint64_t requestSize, @@ -130,6 +131,7 @@ namespace gpgmm { uint64_t GetMemorySize() const override; private: + // ObjectBase interface const char* GetTypename() const override; class SlabAllocatorCacheEntry : public NonCopyable { diff --git a/src/gpgmm/d3d12/DebugResourceAllocatorD3D12.h b/src/gpgmm/d3d12/DebugResourceAllocatorD3D12.h index 070c5068b..f6a3177c0 100644 --- a/src/gpgmm/d3d12/DebugResourceAllocatorD3D12.h +++ b/src/gpgmm/d3d12/DebugResourceAllocatorD3D12.h @@ -34,10 +34,11 @@ namespace gpgmm::d3d12 { void ReleaseLiveAllocationsForTesting(); private: - void DeallocateMemory(std::unique_ptr allocation) override; - + // ObjectBase interface const char* GetTypename() const override; + void DeallocateMemory(std::unique_ptr allocation) override; + class ResourceAllocationEntry { public: explicit ResourceAllocationEntry(ResourceAllocation* allocation); // For lookup diff --git a/src/gpgmm/d3d12/HeapD3D12.h b/src/gpgmm/d3d12/HeapD3D12.h index 06b2ea152..59fb2a339 100644 --- a/src/gpgmm/d3d12/HeapD3D12.h +++ b/src/gpgmm/d3d12/HeapD3D12.h @@ -59,8 +59,10 @@ namespace gpgmm::d3d12 { const HEAP_DESC& descriptor, bool isResidencyDisabled); - HRESULT SetDebugNameImpl(LPCWSTR name) override; + // ObjectBase interface const char* GetTypename() const override; + + HRESULT SetDebugNameImpl(LPCWSTR name) override; DXGI_MEMORY_SEGMENT_GROUP GetMemorySegmentGroup() const; // The residency manager must know the last fence value that any portion of the pageable was diff --git a/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp b/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp index 49a615cb0..23456962c 100644 --- a/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp +++ b/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp @@ -1255,7 +1255,7 @@ namespace gpgmm::d3d12 { (allocationDescriptor.Flags & ALLOCATION_FLAG_DISABLE_RESIDENCY) ? nullptr : mResidencyManager.Get(), - ImportResourceCallbackContext::CreateHeap, + ImportResourceCallbackContext::GetHeap, &importResourceCallbackContext, &resourceHeap)); const uint64_t& allocationSize = resourceInfo.SizeInBytes; @@ -1481,12 +1481,9 @@ namespace gpgmm::d3d12 { } // static - HRESULT ImportResourceCallbackContext::CreateHeap(void* pContext, + HRESULT ImportResourceCallbackContext::GetHeap(void* pContext, ID3D12Pageable** ppPageableOut) { - ImportResourceCallbackContext* importResourceCallbackContext = - static_cast(pContext); - - return importResourceCallbackContext->GetHeap(ppPageableOut); + return static_cast(pContext)->GetHeap(ppPageableOut); } HRESULT ImportResourceCallbackContext::GetHeap(ID3D12Pageable** ppPageableOut) { diff --git a/src/gpgmm/d3d12/ResourceAllocatorD3D12.h b/src/gpgmm/d3d12/ResourceAllocatorD3D12.h index 9e5b8305e..b7b939628 100644 --- a/src/gpgmm/d3d12/ResourceAllocatorD3D12.h +++ b/src/gpgmm/d3d12/ResourceAllocatorD3D12.h @@ -38,7 +38,7 @@ namespace gpgmm::d3d12 { class ImportResourceCallbackContext { public: ImportResourceCallbackContext(ComPtr resource); - static HRESULT CreateHeap(void* pContext, ID3D12Pageable** ppPageableOut); + static HRESULT GetHeap(void* pContext, ID3D12Pageable** ppPageableOut); private: HRESULT GetHeap(ID3D12Pageable** ppPageableOut); @@ -101,12 +101,13 @@ namespace gpgmm::d3d12 { DEFINE_IUNKNOWNIMPL_OVERRIDES() - const char* GetTypename() const override; - private: friend BufferAllocator; friend ResourceAllocation; + // ObjectBase interface + const char* GetTypename() const override; + HRESULT CreateResourceInternal(const ALLOCATION_DESC& allocationDescriptor, const D3D12_RESOURCE_DESC& resourceDescriptor, D3D12_RESOURCE_STATES initialResourceState, diff --git a/src/gpgmm/d3d12/ResourceHeapAllocatorD3D12.cpp b/src/gpgmm/d3d12/ResourceHeapAllocatorD3D12.cpp index 7d7f780a7..00ea98d36 100644 --- a/src/gpgmm/d3d12/ResourceHeapAllocatorD3D12.cpp +++ b/src/gpgmm/d3d12/ResourceHeapAllocatorD3D12.cpp @@ -26,6 +26,8 @@ namespace gpgmm::d3d12 { + static const wchar_t* kResourceHeapDebugName = L"GPGMM Resource Heap"; + ResourceHeapAllocator::ResourceHeapAllocator(ResidencyManager* residencyManager, ID3D12Device* device, D3D12_HEAP_PROPERTIES heapProperties, @@ -51,8 +53,8 @@ namespace gpgmm::d3d12 { // alignment to avoid wasting bytes. // https://docs.microsoft.com/en-us/windows/win32/api/d3d12/ns-d3d12-d3d12_HEAP_INFO resourceHeapDesc.SizeInBytes = AlignTo(request.SizeInBytes, request.Alignment); - resourceHeapDesc.Alignment = request.Alignment; - resourceHeapDesc.DebugName = L"Resource heap"; + resourceHeapDesc.Alignment = request.Alignment; + resourceHeapDesc.DebugName = kResourceHeapDebugName; const bool isResidencyEnabled = (mResidencyManager != nullptr); resourceHeapDesc.Flags |= GetHeapFlags(mHeapFlags, isResidencyEnabled); diff --git a/src/gpgmm/d3d12/ResourceHeapAllocatorD3D12.h b/src/gpgmm/d3d12/ResourceHeapAllocatorD3D12.h index 2ebd67c09..fcbfd68ec 100644 --- a/src/gpgmm/d3d12/ResourceHeapAllocatorD3D12.h +++ b/src/gpgmm/d3d12/ResourceHeapAllocatorD3D12.h @@ -50,6 +50,7 @@ namespace gpgmm::d3d12 { void DeallocateMemory(std::unique_ptr allocation) override; private: + // ObjectBase interface const char* GetTypename() const override; ResidencyManager* const mResidencyManager;