From 2715b6edcb5428f0b17f254eab49cb9442b0e9b3 Mon Sep 17 00:00:00 2001 From: "Bernhart, Bryan" Date: Mon, 17 Apr 2023 11:34:16 -0700 Subject: [PATCH] Refactor the D3D12 API. --- README.md | 8 +- docs/DESIGN.md | 2 +- include/gpgmm_d3d12.h | 148 ++++++++-------- include/gpgmm_vk.h | 2 +- src/fuzzers/D3D12Fuzzer.cpp | 4 +- src/fuzzers/D3D12Fuzzer.h | 2 +- src/fuzzers/D3D12ResidencyManagerFuzzer.cpp | 6 +- src/fuzzers/D3D12ResourceAllocatorFuzzer.cpp | 2 +- src/gpgmm/BUILD.gn | 4 +- src/gpgmm/CMakeLists.txt | 4 +- src/gpgmm/d3d12/BufferAllocatorD3D12.cpp | 4 +- src/gpgmm/d3d12/JSONSerializerD3D12.cpp | 12 +- src/gpgmm/d3d12/JSONSerializerD3D12.h | 10 +- .../{HeapD3D12.cpp => ResidencyHeapD3D12.cpp} | 102 +++++------ .../{HeapD3D12.h => ResidencyHeapD3D12.h} | 33 ++-- src/gpgmm/d3d12/ResidencyListD3D12.cpp | 7 +- src/gpgmm/d3d12/ResidencyListD3D12.h | 6 +- src/gpgmm/d3d12/ResidencyManagerD3D12.cpp | 56 +++--- src/gpgmm/d3d12/ResidencyManagerD3D12.h | 21 +-- src/gpgmm/d3d12/ResourceAllocationD3D12.cpp | 8 +- src/gpgmm/d3d12/ResourceAllocationD3D12.h | 6 +- src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp | 160 +++++++++--------- src/gpgmm/d3d12/ResourceAllocatorD3D12.h | 16 +- .../d3d12/ResourceHeapAllocatorD3D12.cpp | 16 +- src/mvi/gpgmm_d3d12.cpp | 95 ++++++----- src/mvi/gpgmm_d3d12.h | 47 ++--- src/samples/D3D12Sample.cpp | 2 +- src/tests/D3D12Test.cpp | 8 +- src/tests/D3D12Test.h | 8 +- .../D3D12MemoryTraceReplay.cpp | 65 +++---- .../end2end/D3D12ResidencyManagerTests.cpp | 132 +++++++-------- .../end2end/D3D12ResourceAllocatorTests.cpp | 117 +++++++------ 32 files changed, 571 insertions(+), 542 deletions(-) rename src/gpgmm/d3d12/{HeapD3D12.cpp => ResidencyHeapD3D12.cpp} (68%) rename src/gpgmm/d3d12/{HeapD3D12.h => ResidencyHeapD3D12.h} (69%) diff --git a/README.md b/README.md index 932992957..fd4873c86 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ First create an allocator then create allocations from it: ```cpp #include -gpgmm::d3d12::ALLOCATOR_DESC allocatorDesc = {}; +gpgmm::d3d12::RESOURCE_ALLOCATOR_DESC allocatorDesc = {}; ComPtr residency; // Optional ComPtr allocator; @@ -58,13 +58,13 @@ list->Reset(); Residency also works for non-resources too: ```cpp -gpgmm::d3d12::HEAP_DESC shaderVisibleHeap = {}; +gpgmm::d3d12::RESIDENCY_HEAP_DESC shaderVisibleHeap = {}; shaderVisibleHeap.SizeInBytes = kHeapSize; shaderVisibleHeap.HeapSegment = DXGI_MEMORY_SEGMENT_GROUP_LOCAL; -ComPtr descriptorHeap; +ComPtr descriptorHeap; CreateHeapContext createHeapContext(heapDesc); -gpgmm::d3d12::CreateHeap(shaderVisibleHeap, residencyManager, +gpgmm::d3d12::CreateResidencyHeap(shaderVisibleHeap, residencyManager, createHeapContext, &CreateHeapContext::CreateHeapCallbackWrapper, &descriptorHeap); diff --git a/docs/DESIGN.md b/docs/DESIGN.md index 6f5b0eb85..9bff80f81 100644 --- a/docs/DESIGN.md +++ b/docs/DESIGN.md @@ -147,7 +147,7 @@ sequenceDiagram GPGMM->>GPGMM: Pool-allocate Note over GPGMM: No heaps in pool. activate D3D12 - GPGMM->>D3D12: CreateHeap + GPGMM->>D3D12: CreateResidencyHeap D3D12-->>GPGMM: new Heap Note over GPGMM: Track Heap for residency. GPGMM->>D3D12: CreatePlacedResource diff --git a/include/gpgmm_d3d12.h b/include/gpgmm_d3d12.h index d763aa2ff..790024a84 100644 --- a/include/gpgmm_d3d12.h +++ b/include/gpgmm_d3d12.h @@ -62,7 +62,7 @@ namespace gpgmm::d3d12 { virtual HRESULT SetDebugName(LPCWSTR Name) = 0; }; - /** \enum RESIDENCY_STATUS + /** \enum RESIDENCY_HEAP_STATUS D3D12 allows heaps to be explicitly created resident or not. This means the expected residency status of the heap cannot be solely determined by checking for the existence in a @@ -75,27 +75,27 @@ namespace gpgmm::d3d12 { D3D12, it will immediately become currently resident. If the heap becomes locked, it will stay currently resident until it is evicted, then back to pending residency. */ - enum RESIDENCY_STATUS { + enum RESIDENCY_HEAP_STATUS { /** \brief Heap residency status is not known and cannot be made resident. Heap must become locked to be managed for residency. */ - RESIDENCY_STATUS_UNKNOWN = 0, + RESIDENCY_HEAP_STATUS_UNKNOWN = 0, /** \brief Heap is about to be made resident. Heap must be previously locked, evicted, or currently resident at creation. */ - RESIDENCY_STATUS_PENDING_RESIDENCY = 1, + RESIDENCY_HEAP_STATUS_PENDING = 1, /** \brief Heap was made resident and can be evicted. Heaps that stay locked will always be currently resident. */ - RESIDENCY_STATUS_CURRENT_RESIDENT = 2, + RESIDENCY_HEAP_STATUS_CURRENT = 2, }; - /** \struct HEAP_INFO + /** \struct RESIDENCY_HEAP_INFO Additional information about the heap. */ - struct HEAP_INFO { + struct RESIDENCY_HEAP_INFO { /** \brief Created size, in bytes, of the heap. Must be non-zero. SizeInBytes is always a multiple of the alignment. @@ -118,23 +118,23 @@ namespace gpgmm::d3d12 { /** \brief Check if the heap was made resident or not. */ - RESIDENCY_STATUS Status; + RESIDENCY_HEAP_STATUS Status; }; - /** \enum HEAP_FLAGS + /** \enum RESIDENCY_HEAP_FLAGS Specify creation options to configure the heap. */ - enum HEAP_FLAGS { + enum RESIDENCY_HEAP_FLAGS { /** \brief Disables all option flags. */ - HEAP_FLAG_NONE = 0x0, + RESIDENCY_HEAP_FLAG_NONE = 0x0, /** \brief Requires the heap to be created in budget. This flags ensures there is enough budget to exist for the heap or E_OUTOFMEMORY. */ - HEAP_FLAG_ALWAYS_IN_BUDGET = 0x1, + RESIDENCY_HEAP_FLAG_ALWAYS_IN_BUDGET = 0x1, /** \brief Requires the heap to be tracked for residency. @@ -142,15 +142,15 @@ namespace gpgmm::d3d12 { creation. The flag only has effect when the heap's residency status cannot be determined. */ - HEAP_FLAG_ALWAYS_IN_RESIDENCY = 0x2, + RESIDENCY_HEAP_FLAG_ALWAYS_RESIDENT = 0x2, }; - DEFINE_ENUM_FLAG_OPERATORS(HEAP_FLAGS) + DEFINE_ENUM_FLAG_OPERATORS(RESIDENCY_HEAP_FLAGS) - /** \struct HEAP_DESC + /** \struct RESIDENCY_HEAP_DESC Specifies creation options for a residency managed heap. */ - struct HEAP_DESC { + struct RESIDENCY_HEAP_DESC { /** \brief Created size of the heap, in bytes. Must be non-zero. SizeInBytes is always a multiple of the alignment. @@ -171,9 +171,9 @@ namespace gpgmm::d3d12 { /** \brief Specifies heaps options. - Optional parameter. By default, no flags are specified or HEAP_FLAG_NONE. + Optional parameter. By default, no flags are specified or RESIDENCY_HEAP_FLAG_NONE. */ - HEAP_FLAGS Flags; + RESIDENCY_HEAP_FLAGS Flags; /** \brief Debug name associated with the heap. @@ -198,12 +198,12 @@ namespace gpgmm::d3d12 { node is removed from the cache when it is evicted from video memory due to budget constraints, or when the memory is released. */ - GPGMM_INTERFACE IHeap : public IDebugObject { + GPGMM_INTERFACE IResidencyHeap : public IDebugObject { /** \brief Returns information about this heap. - \return A HEAP_INFO struct containing the information. + \return A RESIDENCY_HEAP_INFO struct containing the information. */ - virtual HEAP_INFO GetInfo() const = 0; + virtual RESIDENCY_HEAP_INFO GetInfo() const = 0; }; /** \brief Create a heap managed by GPGMM. @@ -212,19 +212,19 @@ namespace gpgmm::d3d12 { purposes. A heap managed by GPGMM represents either a 1) committed resource backed by implicit D3D12 heap OR 2) an explicit D3D12 heap used with placed resources. - @param descriptor A reference to HEAP_DESC structure that describes the heap. + @param descriptor A reference to RESIDENCY_HEAP_DESC structure that describes the heap. @param pResidencyManager A pointer to the ResidencyManager used to manage this heap. @param createHeapFn A callback function which creates a ID3D12Pageable derived type. @param pCreateHeapContext A pointer to a class designed to implement the actual heap creation function and store any necessary variables. - @param[out] ppHeapOut Pointer to a memory block that receives a pointer to the + @param[out] ppResidencyHeapOut Pointer to a memory block that receives a pointer to the heap. Example call showing the usage of createHeapFn and pCreateHeapContext: \code - CreateHeap(descriptor, pResidencyManager, CallbackContext:CallbackWrapper, - reinterpret_cast(callbackContext), ppHeapOut); + CreateResidencyHeap(descriptor, pResidencyManager, CallbackContext:CallbackWrapper, + reinterpret_cast(callbackContext), ppResidencyHeapOut); \endcode Example Callback Context Class: @@ -233,7 +233,7 @@ namespace gpgmm::d3d12 { class CallbackContext { public: CallbackContext(); - CreateHeap(void *context, ID3D12Pageable** ppPageableOut); + CreateResidencyHeap(void *context, ID3D12Pageable** ppPageableOut); static CallbackWrapper(ID3D12Pageable** ppPageableOut); private: (Declare variables needed for heap creation here) @@ -245,15 +245,15 @@ namespace gpgmm::d3d12 { \code HRESULT CallbackContext:CallbackWrapper(void* context, ID3D12Pageable** ppPageableOut) { CallbackContext* callbackContext = reinterpret_cast(context); - return callbackContext->CreateHeap(ppPageableOut); + return callbackContext->CreateResidencyHeap(ppPageableOut); } \endcode */ - GPGMM_EXPORT HRESULT CreateHeap(const HEAP_DESC& descriptor, - IResidencyManager* const pResidencyManager, - CreateHeapFn createHeapFn, - void* pCreateHeapContext, - IHeap** ppHeapOut); + GPGMM_EXPORT HRESULT CreateResidencyHeap(const RESIDENCY_HEAP_DESC& descriptor, + IResidencyManager* const pResidencyManager, + CreateHeapFn createHeapFn, + void* pCreateHeapContext, + IResidencyHeap** ppResidencyHeapOut); /** \brief Represents a list of heaps which will be "made resident" upon executing a command-list. @@ -274,7 +274,7 @@ namespace gpgmm::d3d12 { \return Returns S_OK if successfull. */ - virtual HRESULT Add(IHeap * pHeap) = 0; + virtual HRESULT Add(IResidencyHeap * pHeap) = 0; /** \brief Resets a residency list to its initial state as if a new residenct list was created. @@ -375,10 +375,10 @@ namespace gpgmm::d3d12 { */ GPGMM_EXPORT HRESULT CreateResidencyList(IResidencyList** ppResidencyListOut); - /** \enum RESIDENCY_FLAGS + /** \enum RESIDENCY_MANAGER_FLAGS Specify options to configure the residency manager. */ - enum RESIDENCY_FLAGS { + enum RESIDENCY_MANAGER_FLAGS { /** \brief Disables all option flags. */ @@ -409,17 +409,17 @@ namespace gpgmm::d3d12 { RESIDENCY_FLAG_ALWAYS_IN_BUDGET = 0x4, }; - DEFINE_ENUM_FLAG_OPERATORS(RESIDENCY_FLAGS) + DEFINE_ENUM_FLAG_OPERATORS(RESIDENCY_MANAGER_FLAGS) - /** \struct RESIDENCY_DESC + /** \struct RESIDENCY_MANAGER_DESC Specify parameters when creating a residency manager. */ - struct RESIDENCY_DESC { + struct RESIDENCY_MANAGER_DESC { /** \brief Specifies residency options. Optional parameter. By default, no flags are specified or RESIDENCY_FLAG_NONE. */ - RESIDENCY_FLAGS Flags; + RESIDENCY_MANAGER_FLAGS Flags; /** \brief Minimum severity level to record messages. @@ -553,7 +553,7 @@ namespace gpgmm::d3d12 { @param pHeap A pointer to the heap being locked. */ - virtual HRESULT LockHeap(IHeap * pHeap) = 0; + virtual HRESULT LockHeap(IResidencyHeap * pHeap) = 0; /** \brief Unlocks the specified heap. @@ -561,7 +561,7 @@ namespace gpgmm::d3d12 { @param pHeap A pointer to the heap being unlocked. */ - virtual HRESULT UnlockHeap(IHeap * pHeap) = 0; + virtual HRESULT UnlockHeap(IResidencyHeap * pHeap) = 0; /** \brief Execute command lists using residency managed heaps or E_OUTOFMEMORY. @@ -613,9 +613,10 @@ namespace gpgmm::d3d12 { CURRENT_RESIDENT/PENDING, respectively. @param pHeap A pointer to the heap being updated. - @param state The RESIDENCY_STATUS enum of the new status. + @param state The RESIDENCY_HEAP_STATUS enum of the new status. */ - virtual HRESULT SetResidencyState(IHeap * pHeap, const RESIDENCY_STATUS& state) = 0; + virtual HRESULT SetResidencyStatus(IResidencyHeap * pHeap, + const RESIDENCY_HEAP_STATUS& state) = 0; /** \brief Query the current residency usage. @@ -630,7 +631,7 @@ namespace gpgmm::d3d12 { /** \brief Create residency residency manager to manage video memory. - @param descriptor A reference to RESIDENCY_DESC structure that describes the residency + @param descriptor A reference to RESIDENCY_MANAGER_DESC structure that describes the residency manager. @param pDevice device used by this allocator. Required parameter. Use CreateDevice get the device. @@ -641,7 +642,7 @@ namespace gpgmm::d3d12 { actually create the residency Manager. If NULL is passed and residency manager creating would succeed, S_FALSE is returned. */ - GPGMM_EXPORT HRESULT CreateResidencyManager(const RESIDENCY_DESC& descriptor, + GPGMM_EXPORT HRESULT CreateResidencyManager(const RESIDENCY_MANAGER_DESC& descriptor, ID3D12Device* pDevice, IDXGIAdapter3* pAdapter, IResidencyManager** ppResidencyManagerOut); @@ -737,13 +738,13 @@ namespace gpgmm::d3d12 { \return A pointer to the Heap used by this resource allocation. */ - virtual IHeap* GetMemory() const = 0; + virtual IResidencyHeap* GetMemory() const = 0; }; - /** \enum ALLOCATOR_FLAGS + /** \enum RESOURCE_ALLOCATOR_FLAGS Specify creation options for allocator. */ - enum ALLOCATOR_FLAGS { + enum RESOURCE_ALLOCATOR_FLAGS { /** \brief Disables all option flags. */ @@ -755,19 +756,20 @@ namespace gpgmm::d3d12 { for large static resources. Otherwise, this is mostly used for debugging and testing purposes. */ - ALLOCATOR_FLAG_ALWAYS_COMMITTED = 0x1, + RESOURCE_ALLOCATOR_FLAG_ALWAYS_COMMITTED = 0x1, /** \brief Requires resource allocation to be created within budget. - Always use HEAP_FLAG_ALWAYS_IN_BUDGET to resource heaps created by this resource allocator. + Always use RESIDENCY_HEAP_FLAG_ALWAYS_IN_BUDGET to resource heaps created by this resource + allocator. */ - ALLOCATOR_FLAG_ALWAYS_IN_BUDGET = 0x2, + RESOURCE_ALLOCATOR_FLAG_ALWAYS_IN_BUDGET = 0x2, /** \brief Disables pre-fetching of GPU memory. Should be only used for debugging and testing purposes. */ - ALLOCATOR_FLAG_DISABLE_MEMORY_PREFETCH = 0x4, + RESOURCE_ALLOCATOR_FLAG_DISABLE_PREFETCH = 0x4, /** \brief Disables recycling of GPU memory. @@ -778,7 +780,7 @@ namespace gpgmm::d3d12 { minimal possible GPU memory footprint, avoiding out-of-memory, or debugging possible corruption of heaps. */ - ALLOCATOR_FLAG_ALWAYS_ON_DEMAND = 0x8, + RESOURCE_ALLOCATOR_FLAG_ALWAYS_ON_DEMAND = 0x8, /** \brief Disables using D3D12_HEAP_TYPE_CUSTOM-equivalent upload heap everywhere on UMA GPUs. @@ -786,14 +788,14 @@ namespace gpgmm::d3d12 { Used to workaround issues when custom heaps are not being recongized as expected or driver bugs related to using a single memory pool. */ - ALLOCATOR_FLAG_DISABLE_UNIFIED_MEMORY = 0x10, + RESOURCE_ALLOCATOR_FLAG_DISABLE_UNIFIED_MEMORY = 0x10, /** \brief Report leaks of resource allocations. Used to track outstanding allocations made with this allocator. When the allocator is about to be released, it will report details on any leaked allocations as log messages. */ - ALLOCATOR_FLAG_NEVER_LEAK_MEMORY = 0x20, + RESOURCE_ALLOCATOR_FLAG_NEVER_LEAK = 0x20, /** \brief Requires resource allocation to be created resident. @@ -802,10 +804,10 @@ namespace gpgmm::d3d12 { operations at resource creation, and instead, reverts back to the default behavior of D3D12 of always making heaps implicitly resident on creation. */ - ALLOCATOR_FLAG_ALWAYS_RESIDENT = 0x40, + RESOURCE_ALLOCATOR_FLAG_ALWAYS_RESIDENT = 0x40, }; - DEFINE_ENUM_FLAG_OPERATORS(ALLOCATOR_FLAGS) + DEFINE_ENUM_FLAG_OPERATORS(RESOURCE_ALLOCATOR_FLAGS) /** \enum ALLOCATOR_ALGORITHM Specify the algorithms used for allocation. @@ -857,7 +859,7 @@ namespace gpgmm::d3d12 { Fixed-size pool limits recycling to resource heaps equal to PreferredResourceHeapSize. A PreferredResourceHeapSize of zero is effectively - equivelent to ALLOCATOR_FLAG_ALWAYS_ON_DEMAND. + equivelent to RESOURCE_ALLOCATOR_FLAG_ALWAYS_ON_DEMAND. */ ALLOCATOR_ALGORITHM_FIXED_POOL = 3, @@ -874,24 +876,24 @@ namespace gpgmm::d3d12 { A dedicated allocation allocates exactly what is needed for the resource and nothing more. Internally, dedicated allocations are "placed resources" which allows the heap to be - recycled by GPGMM. Otherwise, ALLOCATOR_FLAG_ALWAYS_COMMITTED is equivelent to a "dedicated - allocation" but without heaps being recycled by GPGMM. + recycled by GPGMM. Otherwise, RESOURCE_ALLOCATOR_FLAG_ALWAYS_COMMITTED is equivelent to a + "dedicated allocation" but without heaps being recycled by GPGMM. Dedicated allocation allocates/deallocates in O(1) time using O(N * pageSize) space. */ ALLOCATOR_ALGORITHM_DEDICATED = 5, }; - /** \struct ALLOCATOR_DESC + /** \struct RESOURCE_ALLOCATOR_DESC Specify parameters for creating allocators. */ - struct ALLOCATOR_DESC { + struct RESOURCE_ALLOCATOR_DESC { /** \brief Specifies allocator options. For example, whether the allocator can reuse memory, or resources should be resident upon creation. */ - ALLOCATOR_FLAGS Flags; + RESOURCE_ALLOCATOR_FLAGS Flags; /** \brief Minimum severity level to record messages. @@ -1012,7 +1014,7 @@ namespace gpgmm::d3d12 { The created resource must use an existing resource heap or E_OUTOFMEMORY. Effectively disables creating standalone allocations whose memory cannot be reused. */ - ALLOCATION_FLAG_NEVER_ALLOCATE_MEMORY = 0x1, + ALLOCATION_FLAG_NEVER_ALLOCATE_HEAP = 0x1, /** \brief Sub-allocate a resource allocation within the same resource. @@ -1036,7 +1038,7 @@ namespace gpgmm::d3d12 { When this flag is used, the created resource will always be allocated with it's own resource heap. */ - ALLOCATION_FLAG_NEVER_SUBALLOCATE_MEMORY = 0x4, + ALLOCATION_FLAG_NEVER_SUBALLOCATE_HEAP = 0x4, /** \brief Prefetch memory for the next resource allocation. @@ -1045,9 +1047,9 @@ namespace gpgmm::d3d12 { trigger prefetching based on heurstics. Prefetching enables more performance when allocating for contiguous allocations or many resources of the same size. - Should not be used with ALLOCATION_FLAG_NEVER_ALLOCATE_MEMORY. + Should not be used with ALLOCATION_FLAG_NEVER_ALLOCATE_HEAP. */ - ALLOCATION_FLAG_ALWAYS_PREFETCH_MEMORY = 0x8, + ALLOCATION_FLAG_ALWAYS_PREFETCH_HEAP = 0x8, /** \brief Cache the request size. @@ -1064,7 +1066,7 @@ namespace gpgmm::d3d12 { as well as frequent CPU reads would beneifit from D3D12_HEAP_TYPE_READBACK since the CPU properties are always write-combined. - If ALLOCATOR_FLAG_DISABLE_UNIFIED_MEMORY was specified, heap type was + If RESOURCE_ALLOCATOR_FLAG_DISABLE_UNIFIED_MEMORY was specified, heap type was D3D12_HEAP_TYPE_READBACK, or the adapter is not cache-coherent UMA, this flag has no effect. */ ALLOCATION_FLAG_ALWAYS_ATTRIBUTE_HEAPS = 0x20, @@ -1125,7 +1127,7 @@ namespace gpgmm::d3d12 { /** \brief Additional heap flags that the resource requires. By default, GPGMM infers the required heap flags based on the required - fields in the D3D12_RESOURCE_DESC, ALLOCATOR_DESC and ALLOCATION_DESC. + fields in the D3D12_RESOURCE_DESC, RESOURCE_ALLOCATOR_DESC and ALLOCATION_DESC. But if additional heap flags are required, they can also be specified. It is recommended to only specify D3D12_HEAP_FLAG_NONE since not all @@ -1343,7 +1345,7 @@ namespace gpgmm::d3d12 { Residency requires at-least DXGI version 1.4. - @param allocatorDescriptor A reference to ALLOCATOR_DESC structure that describes the + @param allocatorDescriptor A reference to RESOURCE_ALLOCATOR_DESC structure that describes the allocator. @param pDevice device used by this allocator. Required parameter. Use CreateDevice get the device. @@ -1356,7 +1358,7 @@ namespace gpgmm::d3d12 { residency manager. If NULL is passed, the allocator will be created without using residency. */ - GPGMM_EXPORT HRESULT CreateResourceAllocator(const ALLOCATOR_DESC& allocatorDescriptor, + GPGMM_EXPORT HRESULT CreateResourceAllocator(const RESOURCE_ALLOCATOR_DESC& allocatorDescriptor, ID3D12Device* pDevice, IDXGIAdapter* pAdapter, IResourceAllocator** ppResourceAllocatorOut, @@ -1364,7 +1366,7 @@ namespace gpgmm::d3d12 { /** \brief Create a resource allocator using a specified residency manager. - @param allocatorDescriptor A reference to ALLOCATOR_DESC structure that describes the + @param allocatorDescriptor A reference to RESOURCE_ALLOCATOR_DESC structure that describes the allocator. @param pDevice device used by this allocator. Required parameter. Use CreateDevice get the device. @@ -1376,7 +1378,7 @@ namespace gpgmm::d3d12 { resource allocator. Pass NULL to test if allocator creation would succeed, but not actually create the allocator. */ - GPGMM_EXPORT HRESULT CreateResourceAllocator(const ALLOCATOR_DESC& allocatorDescriptor, + GPGMM_EXPORT HRESULT CreateResourceAllocator(const RESOURCE_ALLOCATOR_DESC& allocatorDescriptor, ID3D12Device* pDevice, IDXGIAdapter* pAdapter, IResidencyManager* pResidencyManager, diff --git a/include/gpgmm_vk.h b/include/gpgmm_vk.h index 63cc9fcf7..a82c340d3 100644 --- a/include/gpgmm_vk.h +++ b/include/gpgmm_vk.h @@ -260,7 +260,7 @@ namespace gpgmm::vk { when the current allocation requested is completed. By default, GPGMM will automatically trigger prefetching based on heurstics. Prefetching enables more performance when allocating for large contiguous allocations. Should not be used with - ALLOCATION_FLAG_NEVER_ALLOCATE_MEMORY. + GP_ALLOCATION_CREATE_NEVER_ALLOCATE_MEMORY. */ GP_ALLOCATION_CREATE_ALWAYS_PREFETCH_MEMORY = 0x8, }; diff --git a/src/fuzzers/D3D12Fuzzer.cpp b/src/fuzzers/D3D12Fuzzer.cpp index c8ea4c581..64ed4475d 100644 --- a/src/fuzzers/D3D12Fuzzer.cpp +++ b/src/fuzzers/D3D12Fuzzer.cpp @@ -20,10 +20,10 @@ uint64_t UInt8ToUInt64(const uint8_t* src) { return dst; } -HRESULT CreateResourceAllocatorDesc(gpgmm::d3d12::ALLOCATOR_DESC* pAllocatorDesc, +HRESULT CreateResourceAllocatorDesc(gpgmm::d3d12::RESOURCE_ALLOCATOR_DESC* pAllocatorDesc, ID3D12Device** ppDeviceOut, IDXGIAdapter3** ppAdapterOut) { - gpgmm::d3d12::ALLOCATOR_DESC allocatorDescOut = {}; + gpgmm::d3d12::RESOURCE_ALLOCATOR_DESC allocatorDescOut = {}; // Populate the device if (FAILED(D3D12CreateDevice(nullptr, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(ppDeviceOut)))) { diff --git a/src/fuzzers/D3D12Fuzzer.h b/src/fuzzers/D3D12Fuzzer.h index c9daeb32e..21e153ba8 100644 --- a/src/fuzzers/D3D12Fuzzer.h +++ b/src/fuzzers/D3D12Fuzzer.h @@ -23,7 +23,7 @@ using Microsoft::WRL::ComPtr; uint64_t UInt8ToUInt64(const uint8_t* src); -HRESULT CreateResourceAllocatorDesc(gpgmm::d3d12::ALLOCATOR_DESC* allocatorDesc, +HRESULT CreateResourceAllocatorDesc(gpgmm::d3d12::RESOURCE_ALLOCATOR_DESC* allocatorDesc, ID3D12Device** ppDeviceOut, IDXGIAdapter3** ppAdapterOut); diff --git a/src/fuzzers/D3D12ResidencyManagerFuzzer.cpp b/src/fuzzers/D3D12ResidencyManagerFuzzer.cpp index bbc166a29..0d391682c 100644 --- a/src/fuzzers/D3D12ResidencyManagerFuzzer.cpp +++ b/src/fuzzers/D3D12ResidencyManagerFuzzer.cpp @@ -50,19 +50,19 @@ namespace { } // namespace extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) { - gpgmm::d3d12::ALLOCATOR_DESC allocatorDesc = {}; + gpgmm::d3d12::RESOURCE_ALLOCATOR_DESC allocatorDesc = {}; if (FAILED(CreateResourceAllocatorDesc(&allocatorDesc, &gDevice, &gAdapter))) { return 0; } - allocatorDesc.Flags |= gpgmm::d3d12::ALLOCATOR_FLAG_ALWAYS_IN_BUDGET; + allocatorDesc.Flags |= gpgmm::d3d12::RESOURCE_ALLOCATOR_FLAG_ALWAYS_IN_BUDGET; ComPtr adapter3; if (FAILED(gAdapter->QueryInterface(IID_PPV_ARGS(&adapter3)))) { return 0; } - gpgmm::d3d12::RESIDENCY_DESC residencyDesc = {}; + gpgmm::d3d12::RESIDENCY_MANAGER_DESC residencyDesc = {}; residencyDesc.MinLogLevel = D3D12_MESSAGE_SEVERITY_MESSAGE; // Create ResidencyManager diff --git a/src/fuzzers/D3D12ResourceAllocatorFuzzer.cpp b/src/fuzzers/D3D12ResourceAllocatorFuzzer.cpp index 0feef6392..31bfc1e6c 100644 --- a/src/fuzzers/D3D12ResourceAllocatorFuzzer.cpp +++ b/src/fuzzers/D3D12ResourceAllocatorFuzzer.cpp @@ -28,7 +28,7 @@ namespace { } // namespace extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) { - gpgmm::d3d12::ALLOCATOR_DESC allocatorDesc = {}; + gpgmm::d3d12::RESOURCE_ALLOCATOR_DESC allocatorDesc = {}; if (FAILED(CreateResourceAllocatorDesc(&allocatorDesc, &gDevice, &gAdapter))) { return 0; } diff --git a/src/gpgmm/BUILD.gn b/src/gpgmm/BUILD.gn index 9f9a0821b..35efd1b28 100644 --- a/src/gpgmm/BUILD.gn +++ b/src/gpgmm/BUILD.gn @@ -126,11 +126,11 @@ source_set("gpgmm_sources") { "d3d12/ErrorD3D12.h", "d3d12/FenceD3D12.cpp", "d3d12/FenceD3D12.h", - "d3d12/HeapD3D12.cpp", - "d3d12/HeapD3D12.h", "d3d12/JSONSerializerD3D12.cpp", "d3d12/JSONSerializerD3D12.h", "d3d12/LogD3D12.h", + "d3d12/ResidencyHeapD3D12.cpp", + "d3d12/ResidencyHeapD3D12.h", "d3d12/ResidencyListD3D12.cpp", "d3d12/ResidencyListD3D12.h", "d3d12/ResidencyManagerD3D12.cpp", diff --git a/src/gpgmm/CMakeLists.txt b/src/gpgmm/CMakeLists.txt index b20dc33f2..e41b482fa 100644 --- a/src/gpgmm/CMakeLists.txt +++ b/src/gpgmm/CMakeLists.txt @@ -67,8 +67,8 @@ if (GPGMM_ENABLE_D3D12) "d3d12/ErrorD3D12.h" "d3d12/FenceD3D12.cpp" "d3d12/FenceD3D12.h" - "d3d12/HeapD3D12.cpp" - "d3d12/HeapD3D12.h" + "d3d12/ResidencyHeapD3D12.cpp" + "d3d12/ResidencyHeapD3D12.h" "d3d12/JSONSerializerD3D12.cpp" "d3d12/JSONSerializerD3D12.h" "d3d12/LogD3D12.h" diff --git a/src/gpgmm/d3d12/BufferAllocatorD3D12.cpp b/src/gpgmm/d3d12/BufferAllocatorD3D12.cpp index 458c7d97a..5c09197a3 100644 --- a/src/gpgmm/d3d12/BufferAllocatorD3D12.cpp +++ b/src/gpgmm/d3d12/BufferAllocatorD3D12.cpp @@ -17,7 +17,7 @@ #include "gpgmm/common/EventMessage.h" #include "gpgmm/common/TraceEvent.h" #include "gpgmm/d3d12/BackendD3D12.h" -#include "gpgmm/d3d12/HeapD3D12.h" +#include "gpgmm/d3d12/ResidencyHeapD3D12.h" #include "gpgmm/d3d12/ResourceAllocationD3D12.h" #include "gpgmm/d3d12/ResourceAllocatorD3D12.h" #include "gpgmm/utils/Math.h" @@ -65,7 +65,7 @@ namespace gpgmm::d3d12 { resourceDescriptor.Flags = mResourceFlags; // Optimized clear is not supported for buffers. - ComPtr resourceHeap; + ComPtr resourceHeap; HRESULT hr = mResourceAllocator->CreateCommittedResource( mHeapProperties, mHeapFlags, info, &resourceDescriptor, /*pOptimizedClearValue*/ nullptr, mInitialResourceState, /*resourceOut*/ nullptr, diff --git a/src/gpgmm/d3d12/JSONSerializerD3D12.cpp b/src/gpgmm/d3d12/JSONSerializerD3D12.cpp index bfe8e9329..7f565a0d5 100644 --- a/src/gpgmm/d3d12/JSONSerializerD3D12.cpp +++ b/src/gpgmm/d3d12/JSONSerializerD3D12.cpp @@ -15,7 +15,7 @@ #include "gpgmm/d3d12/JSONSerializerD3D12.h" #include "gpgmm/common/TraceEvent.h" -#include "gpgmm/d3d12/HeapD3D12.h" +#include "gpgmm/d3d12/ResidencyHeapD3D12.h" #include "gpgmm/d3d12/ResidencyListD3D12.h" #include "gpgmm/d3d12/ResidencyManagerD3D12.h" #include "gpgmm/d3d12/ResourceAllocationD3D12.h" @@ -31,7 +31,7 @@ namespace gpgmm::d3d12 { } // static - JSONDict JSONSerializer::Serialize(const ALLOCATOR_DESC& desc) { + JSONDict JSONSerializer::Serialize(const RESOURCE_ALLOCATOR_DESC& desc) { JSONDict dict; dict.AddItem("Flags", desc.Flags); dict.AddItem("MinLogLevel", desc.MinLogLevel); @@ -158,7 +158,7 @@ namespace gpgmm::d3d12 { } // static - JSONDict JSONSerializer::Serialize(const HEAP_DESC& desc) { + JSONDict JSONSerializer::Serialize(const RESIDENCY_HEAP_DESC& desc) { JSONDict dict; dict.AddItem("SizeInBytes", desc.SizeInBytes); dict.AddItem("Alignment", desc.Alignment); @@ -171,7 +171,7 @@ namespace gpgmm::d3d12 { } // static - JSONDict JSONSerializer::Serialize(const HEAP_INFO& info) { + JSONDict JSONSerializer::Serialize(const RESIDENCY_HEAP_INFO& info) { JSONDict dict; dict.AddItem("SizeInBytes", info.SizeInBytes); dict.AddItem("Alignment", info.Alignment); @@ -230,7 +230,7 @@ namespace gpgmm::d3d12 { JSONDict residencyListDict; JSONArray heapArray; ResidencyList* residencyList = static_cast(desc.ResidencyLists[i]); - for (Heap* heap : *residencyList) { + for (ResidencyHeap* heap : *residencyList) { heapArray.AddItem(gpgmm::JSONSerializer::Serialize(heap)); } if (!heapArray.IsEmpty()) { @@ -248,7 +248,7 @@ namespace gpgmm::d3d12 { } // static - JSONDict JSONSerializer::Serialize(const RESIDENCY_DESC& desc) { + JSONDict JSONSerializer::Serialize(const RESIDENCY_MANAGER_DESC& desc) { JSONDict dict; dict.AddItem("MinLogLevel", desc.MinLogLevel); dict.AddItem("MinRecordLevel", desc.MinRecordLevel); diff --git a/src/gpgmm/d3d12/JSONSerializerD3D12.h b/src/gpgmm/d3d12/JSONSerializerD3D12.h index 2a727d27c..376600f94 100644 --- a/src/gpgmm/d3d12/JSONSerializerD3D12.h +++ b/src/gpgmm/d3d12/JSONSerializerD3D12.h @@ -32,7 +32,7 @@ namespace gpgmm::d3d12 { }; struct CREATE_HEAP_DESC { - const HEAP_DESC& HeapDescriptor; + const RESIDENCY_HEAP_DESC& HeapDescriptor; ID3D12Pageable* Pageable; }; @@ -44,17 +44,17 @@ namespace gpgmm::d3d12 { class JSONSerializer final : public gpgmm::JSONSerializer { public: static JSONDict Serialize(); - static JSONDict Serialize(const ALLOCATOR_DESC& desc); + static JSONDict Serialize(const RESOURCE_ALLOCATOR_DESC& desc); static JSONDict Serialize(const CREATE_RESOURCE_DESC& desc); static JSONDict Serialize(const ALLOCATION_DESC& desc); static JSONDict Serialize(const D3D12_RESOURCE_DESC& desc); static JSONDict Serialize(const CREATE_HEAP_DESC& desc); - static JSONDict Serialize(const HEAP_DESC& desc); - static JSONDict Serialize(const HEAP_INFO& info); + static JSONDict Serialize(const RESIDENCY_HEAP_DESC& desc); + static JSONDict Serialize(const RESIDENCY_HEAP_INFO& info); static JSONDict Serialize(const RESOURCE_ALLOCATION_DESC& desc); static JSONDict Serialize(const RESOURCE_ALLOCATION_INFO& info); static JSONDict Serialize(const EXECUTE_COMMAND_LISTS_DESC& desc); - static JSONDict Serialize(const RESIDENCY_DESC& desc); + static JSONDict Serialize(const RESIDENCY_MANAGER_DESC& desc); static JSONDict Serialize(const RECORD_OPTIONS& desc); private: diff --git a/src/gpgmm/d3d12/HeapD3D12.cpp b/src/gpgmm/d3d12/ResidencyHeapD3D12.cpp similarity index 68% rename from src/gpgmm/d3d12/HeapD3D12.cpp rename to src/gpgmm/d3d12/ResidencyHeapD3D12.cpp index 0e1216eb3..0fef0b5ec 100644 --- a/src/gpgmm/d3d12/HeapD3D12.cpp +++ b/src/gpgmm/d3d12/ResidencyHeapD3D12.cpp @@ -13,7 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "gpgmm/d3d12/HeapD3D12.h" +#include "gpgmm/d3d12/ResidencyHeapD3D12.h" #include "gpgmm/common/SizeClass.h" #include "gpgmm/common/TraceEvent.h" @@ -47,29 +47,29 @@ namespace gpgmm::d3d12 { } } // namespace - HEAP_FLAGS GetHeapFlags(D3D12_HEAP_FLAGS heapFlags, bool alwaysCreatedInBudget) { + RESIDENCY_HEAP_FLAGS GetHeapFlags(D3D12_HEAP_FLAGS heapFlags, bool alwaysCreatedInBudget) { if (alwaysCreatedInBudget) { - return HEAP_FLAG_ALWAYS_IN_BUDGET | HEAP_FLAG_ALWAYS_IN_RESIDENCY; + return RESIDENCY_HEAP_FLAG_ALWAYS_IN_BUDGET | RESIDENCY_HEAP_FLAG_ALWAYS_RESIDENT; } - return HEAP_FLAG_ALWAYS_IN_RESIDENCY; + return RESIDENCY_HEAP_FLAG_ALWAYS_RESIDENT; } - HRESULT CreateHeap(const HEAP_DESC& descriptor, - IResidencyManager* const pResidencyManager, - CreateHeapFn createHeapFn, - void* pCreateHeapContext, - IHeap** ppHeapOut) { - return Heap::CreateHeap(descriptor, pResidencyManager, createHeapFn, pCreateHeapContext, - ppHeapOut); + HRESULT CreateResidencyHeap(const RESIDENCY_HEAP_DESC& descriptor, + IResidencyManager* const pResidencyManager, + CreateHeapFn createHeapFn, + void* pCreateHeapContext, + IResidencyHeap** ppResidencyHeapOut) { + return ResidencyHeap::CreateResidencyHeap(descriptor, pResidencyManager, createHeapFn, + pCreateHeapContext, ppResidencyHeapOut); } // static - HRESULT Heap::CreateHeap(const HEAP_DESC& descriptor, - IResidencyManager* const pResidencyManager, - CreateHeapFn createHeapFn, - void* pCreateHeapContext, - IHeap** ppHeapOut) { + HRESULT ResidencyHeap::CreateResidencyHeap(const RESIDENCY_HEAP_DESC& descriptor, + IResidencyManager* const pResidencyManager, + CreateHeapFn createHeapFn, + void* pCreateHeapContext, + IResidencyHeap** ppResidencyHeapOut) { GPGMM_RETURN_IF_NULLPTR(pCreateHeapContext); const bool isResidencyDisabled = (pResidencyManager == nullptr); @@ -77,7 +77,7 @@ namespace gpgmm::d3d12 { ResidencyManager* residencyManager = static_cast(pResidencyManager); // Ensure enough budget exists before creating the heap to avoid an out-of-memory error. - if (!isResidencyDisabled && (descriptor.Flags & HEAP_FLAG_ALWAYS_IN_BUDGET)) { + if (!isResidencyDisabled && (descriptor.Flags & RESIDENCY_HEAP_FLAG_ALWAYS_IN_BUDGET)) { uint64_t bytesEvicted = descriptor.SizeInBytes; GPGMM_RETURN_IF_FAILED( residencyManager->EvictInternal(descriptor.SizeInBytes, descriptor.HeapSegment, @@ -95,7 +95,7 @@ namespace gpgmm::d3d12 { (currentVideoInfo.Budget > currentVideoInfo.CurrentUsage) ? currentVideoInfo.Budget - currentVideoInfo.CurrentUsage : 0) - << " MBs) and HEAP_FLAG_ALWAYS_IN_BUDGET was specified."; + << " MBs) and RESIDENCY_HEAP_FLAG_ALWAYS_IN_BUDGET was specified."; } return E_OUTOFMEMORY; } @@ -108,10 +108,11 @@ namespace gpgmm::d3d12 { // Pageable-based type is required for residency-managed heaps. GPGMM_RETURN_IF_NULLPTR(pageable); - GPGMM_TRACE_EVENT_OBJECT_CALL("Heap.CreateHeap", + GPGMM_TRACE_EVENT_OBJECT_CALL("Heap.CreateResidencyHeap", (CREATE_HEAP_DESC{descriptor, pageable.Get()})); - std::unique_ptr heap(new Heap(pageable, descriptor, isResidencyDisabled)); + std::unique_ptr heap( + new ResidencyHeap(pageable, descriptor, isResidencyDisabled)); if (!isResidencyDisabled) { // Check if the underlying memory was implicitly made resident. @@ -120,15 +121,15 @@ namespace gpgmm::d3d12 { // Resource heaps created without the "create not resident" flag are always // resident. if (!(resourceHeapFlags & D3D12_HEAP_FLAG_CREATE_NOT_RESIDENT)) { - heap->mState = RESIDENCY_STATUS_CURRENT_RESIDENT; + heap->mState = RESIDENCY_HEAP_STATUS_CURRENT; } else { - heap->mState = RESIDENCY_STATUS_PENDING_RESIDENCY; + heap->mState = RESIDENCY_HEAP_STATUS_PENDING; } } // Heap created not resident requires no budget to be created. - if (heap->mState == RESIDENCY_STATUS_PENDING_RESIDENCY && - (descriptor.Flags & HEAP_FLAG_ALWAYS_IN_BUDGET)) { + if (heap->mState == RESIDENCY_HEAP_STATUS_PENDING && + (descriptor.Flags & RESIDENCY_HEAP_FLAG_ALWAYS_IN_BUDGET)) { ErrorLog(heap.get(), MessageId::kInvalidArgument) << "Creating a heap always in budget cannot be used with " "D3D12_HEAP_FLAG_CREATE_NOT_RESIDENT."; @@ -139,22 +140,23 @@ namespace gpgmm::d3d12 { // should be always inserted in the residency cache. For other heap types (eg. // descriptor heap), they must be manually locked and unlocked to be inserted into the // residency cache. - if (heap->mState != RESIDENCY_STATUS_UNKNOWN) { + if (heap->mState != RESIDENCY_HEAP_STATUS_UNKNOWN) { GPGMM_RETURN_IF_FAILED(residencyManager->InsertHeap(heap.get()), GetDevice(pageable.Get())); } else { - if (descriptor.Flags & HEAP_FLAG_ALWAYS_IN_RESIDENCY) { + if (descriptor.Flags & RESIDENCY_HEAP_FLAG_ALWAYS_RESIDENT) { GPGMM_RETURN_IF_FAILED(residencyManager->LockHeap(heap.get()), GetDevice(pageable.Get())); GPGMM_RETURN_IF_FAILED(residencyManager->UnlockHeap(heap.get()), GetDevice(pageable.Get())); - ASSERT(heap->mState == RESIDENCY_STATUS_CURRENT_RESIDENT); + ASSERT(heap->mState == RESIDENCY_HEAP_STATUS_CURRENT); } } } else { - if (descriptor.Flags & HEAP_FLAG_ALWAYS_IN_RESIDENCY) { + if (descriptor.Flags & RESIDENCY_HEAP_FLAG_ALWAYS_RESIDENT) { WarnLog(heap.get(), MessageId::kInvalidArgument) - << "HEAP_FLAG_ALWAYS_IN_RESIDENCY was specified but had no effect becauase " + << "RESIDENCY_HEAP_FLAG_ALWAYS_RESIDENT was specified but had no effect " + "becauase " "residency management is " "not being used."; } @@ -167,29 +169,29 @@ namespace gpgmm::d3d12 { << "Created heap, Size=" << heap->GetInfo().SizeInBytes << ", ID3D12Pageable=" << ToHexStr(heap->mPageable.Get()); - if (ppHeapOut != nullptr) { - *ppHeapOut = heap.release(); + if (ppResidencyHeapOut != nullptr) { + *ppResidencyHeapOut = heap.release(); } return S_OK; } - Heap::Heap(ComPtr pageable, - const HEAP_DESC& descriptor, - bool isResidencyDisabled) + ResidencyHeap::ResidencyHeap(ComPtr pageable, + const RESIDENCY_HEAP_DESC& descriptor, + bool isResidencyDisabled) : MemoryBase(descriptor.SizeInBytes, descriptor.Alignment), mPageable(std::move(pageable)), mHeapSegment(descriptor.HeapSegment), mResidencyLock(0), mIsResidencyDisabled(isResidencyDisabled), - mState(RESIDENCY_STATUS_UNKNOWN) { + mState(RESIDENCY_HEAP_STATUS_UNKNOWN) { ASSERT(mPageable != nullptr); if (!mIsResidencyDisabled) { GPGMM_TRACE_EVENT_OBJECT_NEW(this); } } - Heap::~Heap() { + ResidencyHeap::~ResidencyHeap() { if (mIsResidencyDisabled) { return; } @@ -204,59 +206,59 @@ namespace gpgmm::d3d12 { GPGMM_TRACE_EVENT_OBJECT_DESTROY(this); } - uint64_t Heap::GetLastUsedFenceValue() const { + uint64_t ResidencyHeap::GetLastUsedFenceValue() const { return mLastUsedFenceValue; } - void Heap::SetLastUsedFenceValue(uint64_t fenceValue) { + void ResidencyHeap::SetLastUsedFenceValue(uint64_t fenceValue) { mLastUsedFenceValue = fenceValue; } - DXGI_MEMORY_SEGMENT_GROUP Heap::GetHeapSegment() const { + DXGI_MEMORY_SEGMENT_GROUP ResidencyHeap::GetHeapSegment() const { return mHeapSegment; } - void Heap::AddResidencyLockRef() { + void ResidencyHeap::AddResidencyLockRef() { mResidencyLock.Ref(); } - void Heap::ReleaseResidencyLock() { + void ResidencyHeap::ReleaseResidencyLock() { mResidencyLock.Unref(); } - bool Heap::IsResidencyLocked() const { + bool ResidencyHeap::IsResidencyLocked() const { return mResidencyLock.GetRefCount() > 0; } - HEAP_INFO Heap::GetInfo() const { + RESIDENCY_HEAP_INFO ResidencyHeap::GetInfo() const { return {GetSize(), GetAlignment(), IsResidencyLocked(), IsInList(), mState}; } - HRESULT Heap::SetDebugNameImpl(LPCWSTR name) { + HRESULT ResidencyHeap::SetDebugNameImpl(LPCWSTR name) { return SetDebugObjectName(mPageable.Get(), name); } - HRESULT STDMETHODCALLTYPE Heap::QueryInterface(REFIID riid, void** ppvObject) { + HRESULT STDMETHODCALLTYPE ResidencyHeap::QueryInterface(REFIID riid, void** ppvObject) { return mPageable->QueryInterface(riid, ppvObject); } - ULONG STDMETHODCALLTYPE Heap::AddRef() { + ULONG STDMETHODCALLTYPE ResidencyHeap::AddRef() { return Unknown::AddRef(); } - ULONG STDMETHODCALLTYPE Heap::Release() { + ULONG STDMETHODCALLTYPE ResidencyHeap::Release() { return Unknown::Release(); } - void Heap::SetResidencyState(RESIDENCY_STATUS newStatus) { + void ResidencyHeap::SetResidencyStatus(RESIDENCY_HEAP_STATUS newStatus) { mState = newStatus; } - LPCWSTR Heap::GetDebugName() const { + LPCWSTR ResidencyHeap::GetDebugName() const { return DebugObject::GetDebugName(); } - HRESULT Heap::SetDebugName(LPCWSTR Name) { + HRESULT ResidencyHeap::SetDebugName(LPCWSTR Name) { return DebugObject::SetDebugName(Name); } diff --git a/src/gpgmm/d3d12/HeapD3D12.h b/src/gpgmm/d3d12/ResidencyHeapD3D12.h similarity index 69% rename from src/gpgmm/d3d12/HeapD3D12.h rename to src/gpgmm/d3d12/ResidencyHeapD3D12.h index b0093a4e0..631477f3c 100644 --- a/src/gpgmm/d3d12/HeapD3D12.h +++ b/src/gpgmm/d3d12/ResidencyHeapD3D12.h @@ -27,20 +27,23 @@ namespace gpgmm::d3d12 { class ResidencyManager; - HEAP_FLAGS GetHeapFlags(D3D12_HEAP_FLAGS heapFlags, bool alwaysCreatedInBudget); + RESIDENCY_HEAP_FLAGS GetHeapFlags(D3D12_HEAP_FLAGS heapFlags, bool alwaysCreatedInBudget); - class Heap final : public MemoryBase, public DebugObject, public LinkNode, public IHeap { + class ResidencyHeap final : public MemoryBase, + public DebugObject, + public LinkNode, + public IResidencyHeap { public: - static HRESULT CreateHeap(const HEAP_DESC& descriptor, - IResidencyManager* const pResidencyManager, - CreateHeapFn createHeapFn, - void* pCreateHeapContext, - IHeap** ppHeapOut); + static HRESULT CreateResidencyHeap(const RESIDENCY_HEAP_DESC& descriptor, + IResidencyManager* const pResidencyManager, + CreateHeapFn createHeapFn, + void* pCreateHeapContext, + IResidencyHeap** ppResidencyHeapOut); - ~Heap() override; + ~ResidencyHeap() override; - // IHeap interface - HEAP_INFO GetInfo() const override; + // IResidencyHeap interface + RESIDENCY_HEAP_INFO GetInfo() const override; // IUnknown interface HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject) override; @@ -54,9 +57,9 @@ namespace gpgmm::d3d12 { private: friend ResidencyManager; - Heap(ComPtr pageable, - const HEAP_DESC& descriptor, - bool isResidencyDisabled); + ResidencyHeap(ComPtr pageable, + const RESIDENCY_HEAP_DESC& descriptor, + bool isResidencyDisabled); // ObjectBase interface DEFINE_OBJECT_BASE_OVERRIDES(IHeap) @@ -70,7 +73,7 @@ namespace gpgmm::d3d12 { uint64_t GetLastUsedFenceValue() const; void SetLastUsedFenceValue(uint64_t fenceValue); - void SetResidencyState(RESIDENCY_STATUS newStatus); + void SetResidencyStatus(RESIDENCY_HEAP_STATUS newStatus); bool IsResidencyLocked() const; @@ -86,7 +89,7 @@ namespace gpgmm::d3d12 { DXGI_MEMORY_SEGMENT_GROUP mHeapSegment; RefCounted mResidencyLock; bool mIsResidencyDisabled; - RESIDENCY_STATUS mState; + RESIDENCY_HEAP_STATUS mState; }; } // namespace gpgmm::d3d12 diff --git a/src/gpgmm/d3d12/ResidencyListD3D12.cpp b/src/gpgmm/d3d12/ResidencyListD3D12.cpp index 2dc4374b5..3f2253fe9 100644 --- a/src/gpgmm/d3d12/ResidencyListD3D12.cpp +++ b/src/gpgmm/d3d12/ResidencyListD3D12.cpp @@ -15,7 +15,7 @@ #include "gpgmm/d3d12/ResidencyListD3D12.h" #include "gpgmm/common/TraceEvent.h" -#include "gpgmm/d3d12/HeapD3D12.h" +#include "gpgmm/d3d12/ResidencyHeapD3D12.h" namespace gpgmm::d3d12 { @@ -34,13 +34,12 @@ namespace gpgmm::d3d12 { GPGMM_TRACE_EVENT_OBJECT_DESTROY(this); } - HRESULT ResidencyList::Add(IHeap* pHeap) { + HRESULT ResidencyList::Add(IResidencyHeap* pHeap) { if (pHeap == nullptr) { return E_INVALIDARG; } - Heap* heap = static_cast(pHeap); - mList.push_back(heap); + mList.push_back(static_cast(pHeap)); return S_OK; } diff --git a/src/gpgmm/d3d12/ResidencyListD3D12.h b/src/gpgmm/d3d12/ResidencyListD3D12.h index c9d2bfbd5..1caa59319 100644 --- a/src/gpgmm/d3d12/ResidencyListD3D12.h +++ b/src/gpgmm/d3d12/ResidencyListD3D12.h @@ -24,7 +24,7 @@ namespace gpgmm::d3d12 { - class Heap; + class ResidencyHeap; class JSONSerializer; class ResidencyManager; @@ -33,7 +33,7 @@ namespace gpgmm::d3d12 { ResidencyList(); ~ResidencyList() override; - HRESULT Add(IHeap* pHeap) override; + HRESULT Add(IResidencyHeap* pHeap) override; HRESULT Reset() override; DEFINE_UNKNOWN_OVERRIDES() @@ -42,7 +42,7 @@ namespace gpgmm::d3d12 { friend JSONSerializer; friend ResidencyManager; - using UnderlyingType = std::vector; + using UnderlyingType = std::vector; UnderlyingType::const_iterator begin() const; UnderlyingType::const_iterator end() const; diff --git a/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp b/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp index 2051bc77e..2882f1119 100644 --- a/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp +++ b/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp @@ -22,9 +22,9 @@ #include "gpgmm/d3d12/CapsD3D12.h" #include "gpgmm/d3d12/ErrorD3D12.h" #include "gpgmm/d3d12/FenceD3D12.h" -#include "gpgmm/d3d12/HeapD3D12.h" #include "gpgmm/d3d12/JSONSerializerD3D12.h" #include "gpgmm/d3d12/LogD3D12.h" +#include "gpgmm/d3d12/ResidencyHeapD3D12.h" #include "gpgmm/d3d12/ResidencyListD3D12.h" #include "gpgmm/d3d12/UtilsD3D12.h" #include "gpgmm/utils/Math.h" @@ -161,7 +161,7 @@ namespace gpgmm::d3d12 { std::shared_ptr mEvent; }; - HRESULT CreateResidencyManager(const RESIDENCY_DESC& descriptor, + HRESULT CreateResidencyManager(const RESIDENCY_MANAGER_DESC& descriptor, ID3D12Device* pDevice, IDXGIAdapter3* pAdapter, IResidencyManager** ppResidencyManagerOut) { @@ -170,7 +170,7 @@ namespace gpgmm::d3d12 { } // static - HRESULT ResidencyManager::CreateResidencyManager(const RESIDENCY_DESC& descriptor, + HRESULT ResidencyManager::CreateResidencyManager(const RESIDENCY_MANAGER_DESC& descriptor, ID3D12Device* pDevice, IDXGIAdapter3* pAdapter, IResidencyManager** ppResidencyManagerOut) { @@ -273,7 +273,7 @@ namespace gpgmm::d3d12 { return S_OK; } - ResidencyManager::ResidencyManager(const RESIDENCY_DESC& descriptor, + ResidencyManager::ResidencyManager(const RESIDENCY_MANAGER_DESC& descriptor, ID3D12Device* pDevice, IDXGIAdapter3* pAdapter, std::unique_ptr caps) @@ -310,12 +310,12 @@ namespace gpgmm::d3d12 { } // Increments number of locks on a heap to ensure the heap remains resident. - HRESULT ResidencyManager::LockHeap(IHeap* pHeap) { + HRESULT ResidencyManager::LockHeap(IResidencyHeap* pHeap) { GPGMM_RETURN_IF_NULLPTR(pHeap); std::lock_guard lock(mMutex); - Heap* heap = static_cast(pHeap); + ResidencyHeap* heap = static_cast(pHeap); ASSERT(heap != nullptr); if (!heap->IsInList() && !heap->IsResidencyLocked()) { @@ -324,7 +324,7 @@ namespace gpgmm::d3d12 { GPGMM_RETURN_IF_FAILED( MakeResident(heap->GetHeapSegment(), heap->GetSize(), 1, pageable.GetAddressOf()), mDevice); - heap->SetResidencyState(RESIDENCY_STATUS_CURRENT_RESIDENT); + heap->SetResidencyStatus(RESIDENCY_HEAP_STATUS_CURRENT); // Untracked heaps, created not resident, are not already attributed toward residency // usage because they are not in the residency cache. @@ -338,7 +338,7 @@ namespace gpgmm::d3d12 { // Untracked heaps, previously made resident, are not attributed toward residency usage // because they will be removed from the residency cache. - if (heap->mState == RESIDENCY_STATUS_CURRENT_RESIDENT) { + if (heap->mState == RESIDENCY_HEAP_STATUS_CURRENT) { mStats.CurrentHeapCount++; mStats.CurrentHeapUsage += heap->GetSize(); } @@ -351,11 +351,11 @@ namespace gpgmm::d3d12 { // Decrements number of locks on a heap. When the number of locks becomes zero, the heap is // inserted into the LRU cache and becomes eligible for eviction. - HRESULT ResidencyManager::UnlockHeap(IHeap* pHeap) { + HRESULT ResidencyManager::UnlockHeap(IResidencyHeap* pHeap) { GPGMM_RETURN_IF_NULLPTR(pHeap); std::lock_guard lock(mMutex); - Heap* heap = static_cast(pHeap); + ResidencyHeap* heap = static_cast(pHeap); ASSERT(heap != nullptr); // If the heap was never locked, nothing further should be done. @@ -389,7 +389,7 @@ namespace gpgmm::d3d12 { return S_OK; } - HRESULT ResidencyManager::InsertHeap(Heap* pHeap) { + HRESULT ResidencyManager::InsertHeap(ResidencyHeap* pHeap) { std::lock_guard lock(mMutex); return InsertHeapInternal(pHeap); } @@ -399,7 +399,7 @@ namespace gpgmm::d3d12 { // is implicitly made resident will cause the residency manager to view the allocation as // non-resident and call MakeResident - which will make D3D12's internal residency refcount on // the allocation out of sync with Dawn. - HRESULT ResidencyManager::InsertHeapInternal(Heap* heap) { + HRESULT ResidencyManager::InsertHeapInternal(ResidencyHeap* heap) { if (heap == nullptr) { return E_INVALIDARG; } @@ -561,7 +561,8 @@ namespace gpgmm::d3d12 { << "There is not enough memory to page-out to get below the budget. This " "likely means there are more external than internal heaps that cannot " "be " - "evicted because they are unmanaged by GPGMM. Consider using CreateHeap " + "evicted because they are unmanaged by GPGMM. Consider using " + "CreateResidencyHeap " "to import them: " << GPGMM_BYTES_TO_MB(pVideoMemoryInfo->CurrentUsage) << " vs " << GPGMM_BYTES_TO_MB(mStats.CurrentHeapUsage) << " MBs."; @@ -665,7 +666,7 @@ namespace gpgmm::d3d12 { break; } - Heap* heap = cache->head()->value(); + ResidencyHeap* heap = cache->head()->value(); const uint64_t lastUsedFenceValue = heap->GetLastUsedFenceValue(); // If the next candidate for eviction was inserted into the cache during the current @@ -681,7 +682,7 @@ namespace gpgmm::d3d12 { GPGMM_RETURN_IF_FAILED(mResidencyFence->WaitFor(lastUsedFenceValue), mDevice); heap->RemoveFromList(); - heap->SetResidencyState(RESIDENCY_STATUS_PENDING_RESIDENCY); + heap->SetResidencyStatus(RESIDENCY_HEAP_STATUS_PENDING); bytesEvicted += heap->GetSize(); @@ -746,8 +747,8 @@ namespace gpgmm::d3d12 { uint64_t localSizeToMakeResident = 0; uint64_t nonLocalSizeToMakeResident = 0; - std::vector heapsToMakeResident; - for (Heap* heap : *residencyList) { + std::vector heapsToMakeResident; + for (ResidencyHeap* heap : *residencyList) { // Heaps that are locked resident are not tracked in the LRU cache. if (heap->IsResidencyLocked()) { continue; @@ -791,7 +792,7 @@ namespace gpgmm::d3d12 { // If the heap should be already resident, calling MakeResident again will be redundant. // Tell the developer the heap wasn't properly tracked by the residency manager. - if (heap->GetInfo().Status == RESIDENCY_STATUS_UNKNOWN) { + if (heap->GetInfo().Status == RESIDENCY_HEAP_STATUS_UNKNOWN) { DebugLog(this, MessageId::kBadOperation) << "Residency state could not be determined for the heap (Heap=" << ToHexStr(heap) @@ -818,8 +819,8 @@ namespace gpgmm::d3d12 { // Once MakeResident succeeds, we must assume the heaps are resident since D3D12 provides // no way of knowing for certain. - for (Heap* heap : heapsToMakeResident) { - heap->SetResidencyState(RESIDENCY_STATUS_CURRENT_RESIDENT); + for (ResidencyHeap* heap : heapsToMakeResident) { + heap->SetResidencyStatus(RESIDENCY_HEAP_STATUS_CURRENT); } GPGMM_TRACE_EVENT_METRIC( @@ -920,14 +921,14 @@ namespace gpgmm::d3d12 { RESIDENCY_MANAGER_STATS result = mStats; for (const auto& entry : mLocalVideoMemorySegment.cache) { - if (entry.value()->GetInfo().Status == RESIDENCY_STATUS_CURRENT_RESIDENT) { + if (entry.value()->GetInfo().Status == RESIDENCY_HEAP_STATUS_CURRENT) { result.CurrentHeapUsage += entry.value()->GetSize(); result.CurrentHeapCount++; } } for (const auto& entry : mNonLocalVideoMemorySegment.cache) { - if (entry.value()->GetInfo().Status == RESIDENCY_STATUS_CURRENT_RESIDENT) { + if (entry.value()->GetInfo().Status == RESIDENCY_HEAP_STATUS_CURRENT) { result.CurrentHeapUsage += entry.value()->GetSize(); result.CurrentHeapCount++; } @@ -995,10 +996,11 @@ namespace gpgmm::d3d12 { } } - HRESULT ResidencyManager::SetResidencyState(IHeap* pHeap, const RESIDENCY_STATUS& state) { + HRESULT ResidencyManager::SetResidencyStatus(IResidencyHeap* pHeap, + const RESIDENCY_HEAP_STATUS& state) { GPGMM_RETURN_IF_NULLPTR(pHeap); - Heap* heap = static_cast(pHeap); + ResidencyHeap* heap = static_cast(pHeap); if (heap->GetInfo().IsLocked) { ErrorLog(this, MessageId::kBadOperation) << "Heap residency cannot be updated because it was locked. " @@ -1006,8 +1008,8 @@ namespace gpgmm::d3d12 { return E_FAIL; } - const RESIDENCY_STATUS oldState = heap->GetInfo().Status; - if (state == RESIDENCY_STATUS_UNKNOWN && oldState != RESIDENCY_STATUS_UNKNOWN) { + const RESIDENCY_HEAP_STATUS oldState = heap->GetInfo().Status; + if (state == RESIDENCY_HEAP_STATUS_UNKNOWN && oldState != RESIDENCY_HEAP_STATUS_UNKNOWN) { ErrorLog(this, MessageId::kBadOperation) << "Heap residency cannot be unknown when previously known by the " "residency manager. " @@ -1015,7 +1017,7 @@ namespace gpgmm::d3d12 { return E_FAIL; } - heap->SetResidencyState(state); + heap->SetResidencyStatus(state); return S_OK; } diff --git a/src/gpgmm/d3d12/ResidencyManagerD3D12.h b/src/gpgmm/d3d12/ResidencyManagerD3D12.h index b5061f11f..a069f811c 100644 --- a/src/gpgmm/d3d12/ResidencyManagerD3D12.h +++ b/src/gpgmm/d3d12/ResidencyManagerD3D12.h @@ -36,13 +36,13 @@ namespace gpgmm::d3d12 { class BudgetUpdateEvent; class Caps; class Fence; - class Heap; + class ResidencyHeap; class ResourceAllocator; class ResourceHeapAllocator; class ResidencyManager final : public DebugObject, public IResidencyManager, public ObjectBase { public: - static HRESULT CreateResidencyManager(const RESIDENCY_DESC& descriptor, + static HRESULT CreateResidencyManager(const RESIDENCY_MANAGER_DESC& descriptor, ID3D12Device* pDevice, IDXGIAdapter3* pAdapter, IResidencyManager** ppResidencyManagerOut); @@ -50,8 +50,8 @@ namespace gpgmm::d3d12 { ~ResidencyManager() override; // IResidencyManager interface - HRESULT LockHeap(IHeap* pHeap) override; - HRESULT UnlockHeap(IHeap* pHeap) override; + HRESULT LockHeap(IResidencyHeap* pHeap) override; + HRESULT UnlockHeap(IResidencyHeap* pHeap) override; HRESULT ExecuteCommandLists(ID3D12CommandQueue* pQueue, ID3D12CommandList* const* ppCommandLists, IResidencyList* const* ppResidencyLists, @@ -63,7 +63,8 @@ namespace gpgmm::d3d12 { HRESULT QueryVideoMemoryInfo(const DXGI_MEMORY_SEGMENT_GROUP& heapSegment, DXGI_QUERY_VIDEO_MEMORY_INFO* pVideoMemoryInfoOut) override; - HRESULT SetResidencyState(IHeap* pHeap, const RESIDENCY_STATUS& state) override; + HRESULT SetResidencyStatus(IResidencyHeap* pHeap, + const RESIDENCY_HEAP_STATUS& state) override; HRESULT QueryStats(RESIDENCY_MANAGER_STATS* pResidencyManagerStats) override; @@ -74,11 +75,11 @@ namespace gpgmm::d3d12 { HRESULT SetDebugName(LPCWSTR Name) override; private: - friend Heap; + friend ResidencyHeap; friend ResourceAllocator; friend ResourceHeapAllocator; - ResidencyManager(const RESIDENCY_DESC& descriptor, + ResidencyManager(const RESIDENCY_MANAGER_DESC& descriptor, ID3D12Device* pDevice, IDXGIAdapter3* pAdapter, std::unique_ptr caps); @@ -87,9 +88,9 @@ namespace gpgmm::d3d12 { const DXGI_MEMORY_SEGMENT_GROUP& heapSegment, uint64_t* bytesEvictedOut = nullptr); - HRESULT InsertHeap(Heap* heap); + HRESULT InsertHeap(ResidencyHeap* heap); - HRESULT InsertHeapInternal(Heap* heap); + HRESULT InsertHeapInternal(ResidencyHeap* heap); HRESULT QueryStatsInternal(RESIDENCY_MANAGER_STATS* pResidencyManagerStats); @@ -101,7 +102,7 @@ namespace gpgmm::d3d12 { // ObjectBase interface DEFINE_OBJECT_BASE_OVERRIDES(IResidencyManager) - using LRUCache = LinkedList; + using LRUCache = LinkedList; struct VideoMemorySegment { LRUCache cache = {}; diff --git a/src/gpgmm/d3d12/ResourceAllocationD3D12.cpp b/src/gpgmm/d3d12/ResourceAllocationD3D12.cpp index 2d7423494..1c5997012 100644 --- a/src/gpgmm/d3d12/ResourceAllocationD3D12.cpp +++ b/src/gpgmm/d3d12/ResourceAllocationD3D12.cpp @@ -19,9 +19,9 @@ #include "gpgmm/common/MemoryAllocator.h" #include "gpgmm/d3d12/BackendD3D12.h" #include "gpgmm/d3d12/ErrorD3D12.h" -#include "gpgmm/d3d12/HeapD3D12.h" #include "gpgmm/d3d12/JSONSerializerD3D12.h" #include "gpgmm/d3d12/LogD3D12.h" +#include "gpgmm/d3d12/ResidencyHeapD3D12.h" #include "gpgmm/d3d12/ResidencyListD3D12.h" #include "gpgmm/d3d12/ResidencyManagerD3D12.h" #include "gpgmm/d3d12/UtilsD3D12.h" @@ -45,7 +45,7 @@ namespace gpgmm::d3d12 { ResourceAllocation::ResourceAllocation(const RESOURCE_ALLOCATION_DESC& desc, ResidencyManager* residencyManager, MemoryAllocator* allocator, - Heap* resourceHeap, + ResidencyHeap* resourceHeap, MemoryBlock* block, ComPtr resource) : MemoryAllocation(allocator, @@ -151,8 +151,8 @@ namespace gpgmm::d3d12 { return {GetSize(), GetAlignment(), static_cast(GetMethod())}; } - IHeap* ResourceAllocation::GetMemory() const { - return static_cast(MemoryAllocation::GetMemory()); + IResidencyHeap* ResourceAllocation::GetMemory() const { + return static_cast(MemoryAllocation::GetMemory()); } void ResourceAllocation::SetDebugAllocator(MemoryAllocator* allocator) { diff --git a/src/gpgmm/d3d12/ResourceAllocationD3D12.h b/src/gpgmm/d3d12/ResourceAllocationD3D12.h index 2180d24da..d21dd27c4 100644 --- a/src/gpgmm/d3d12/ResourceAllocationD3D12.h +++ b/src/gpgmm/d3d12/ResourceAllocationD3D12.h @@ -26,7 +26,7 @@ namespace gpgmm::d3d12 { class DebugResourceAllocator; class ResidencyManager; class ResourceAllocator; - class Heap; + class ResidencyHeap; struct RESOURCE_ALLOCATION_DESC { uint64_t SizeInBytes; @@ -49,7 +49,7 @@ namespace gpgmm::d3d12 { D3D12_GPU_VIRTUAL_ADDRESS GetGPUVirtualAddress() const override; uint64_t GetOffsetFromResource() const override; RESOURCE_ALLOCATION_INFO GetInfo() const override; - IHeap* GetMemory() const override; + IResidencyHeap* GetMemory() const override; DEFINE_UNKNOWN_OVERRIDES() @@ -63,7 +63,7 @@ namespace gpgmm::d3d12 { ResourceAllocation(const RESOURCE_ALLOCATION_DESC& desc, ResidencyManager* residencyManager, MemoryAllocator* allocator, - Heap* resourceHeap, + ResidencyHeap* resourceHeap, MemoryBlock* block, ComPtr resource); diff --git a/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp b/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp index b7776d498..e2ff96965 100644 --- a/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp +++ b/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp @@ -28,9 +28,9 @@ #include "gpgmm/d3d12/CapsD3D12.h" #include "gpgmm/d3d12/DebugResourceAllocatorD3D12.h" #include "gpgmm/d3d12/ErrorD3D12.h" -#include "gpgmm/d3d12/HeapD3D12.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/ResourceHeapAllocatorD3D12.h" @@ -242,7 +242,7 @@ namespace gpgmm::d3d12 { // RAII wrapper to lock/unlock heap from the residency cache. class ScopedResidencyLock final { public: - ScopedResidencyLock(ResidencyManager* const residencyManager, Heap* const heap) + ScopedResidencyLock(ResidencyManager* const residencyManager, ResidencyHeap* const heap) : mResidencyManager(residencyManager), mHeap(heap) { ASSERT(heap != nullptr); if (mResidencyManager != nullptr) { @@ -258,7 +258,7 @@ namespace gpgmm::d3d12 { private: ResidencyManager* const mResidencyManager; - Heap* const mHeap; + ResidencyHeap* const mHeap; }; // Combines AllocatorMemory and Create*Resource into a single call. @@ -348,7 +348,7 @@ namespace gpgmm::d3d12 { const D3D12_CLEAR_VALUE* clearValue, D3D12_RESOURCE_STATES initialResourceState); - static HRESULT CreateHeap(void* pContext, ID3D12Pageable** ppPageableOut); + static HRESULT CreateResidencyHeap(void* pContext, ID3D12Pageable** ppPageableOut); private: HRESULT CreateCommittedResource(ID3D12Pageable** ppPageableOut); @@ -363,7 +363,7 @@ namespace gpgmm::d3d12 { } // namespace - HRESULT CreateResourceAllocator(const ALLOCATOR_DESC& allocatorDescriptor, + HRESULT CreateResourceAllocator(const RESOURCE_ALLOCATOR_DESC& allocatorDescriptor, ID3D12Device* pDevice, IDXGIAdapter* pAdapter, IResourceAllocator** ppResourceAllocatorOut, @@ -372,7 +372,7 @@ namespace gpgmm::d3d12 { allocatorDescriptor, pDevice, pAdapter, ppResourceAllocatorOut, ppResidencyManagerOut); } - HRESULT CreateResourceAllocator(const ALLOCATOR_DESC& allocatorDescriptor, + HRESULT CreateResourceAllocator(const RESOURCE_ALLOCATOR_DESC& allocatorDescriptor, ID3D12Device* pDevice, IDXGIAdapter* pAdapter, IResidencyManager* pResidencyManager, @@ -382,11 +382,12 @@ namespace gpgmm::d3d12 { } // static - HRESULT ResourceAllocator::CreateResourceAllocator(const ALLOCATOR_DESC& allocatorDescriptor, - ID3D12Device* pDevice, - IDXGIAdapter* pAdapter, - IResourceAllocator** ppResourceAllocatorOut, - IResidencyManager** ppResidencyManagerOut) { + HRESULT ResourceAllocator::CreateResourceAllocator( + const RESOURCE_ALLOCATOR_DESC& allocatorDescriptor, + ID3D12Device* pDevice, + IDXGIAdapter* pAdapter, + IResourceAllocator** ppResourceAllocatorOut, + IResidencyManager** ppResidencyManagerOut) { GPGMM_RETURN_IF_NULLPTR(pDevice); ComPtr residencyManager; @@ -396,11 +397,11 @@ namespace gpgmm::d3d12 { GPGMM_RETURN_IF_FAILED(pAdapter->QueryInterface(IID_PPV_ARGS(&adapter3)), pDevice); } - RESIDENCY_DESC residencyDesc = {}; + RESIDENCY_MANAGER_DESC residencyDesc = {}; residencyDesc.MinLogLevel = allocatorDescriptor.MinLogLevel; residencyDesc.RecordOptions = allocatorDescriptor.RecordOptions; - if (allocatorDescriptor.Flags & ALLOCATOR_FLAG_ALWAYS_IN_BUDGET) { + if (allocatorDescriptor.Flags & RESOURCE_ALLOCATOR_FLAG_ALWAYS_IN_BUDGET) { residencyDesc.Flags |= RESIDENCY_FLAG_ALWAYS_IN_BUDGET; } @@ -427,7 +428,7 @@ namespace gpgmm::d3d12 { // static HRESULT ResourceAllocator::CreateResourceAllocator( - const ALLOCATOR_DESC& allocatorDescriptor, + const RESOURCE_ALLOCATOR_DESC& allocatorDescriptor, ID3D12Device* pDevice, IDXGIAdapter* pAdapter, IResidencyManager* pResidencyManager, @@ -466,15 +467,16 @@ namespace gpgmm::d3d12 { "resources of different categories from sharing the same heap."; } - if (allocatorDescriptor.Flags & ALLOCATOR_FLAG_ALWAYS_IN_BUDGET && !pResidencyManager) { + if (allocatorDescriptor.Flags & RESOURCE_ALLOCATOR_FLAG_ALWAYS_IN_BUDGET && + !pResidencyManager) { WarnLog(MessageId::kInvalidArgument, true) - << "ALLOCATOR_FLAG_ALWAYS_IN_BUDGET has no effect when residency " + << "RESOURCE_ALLOCATOR_FLAG_ALWAYS_IN_BUDGET has no effect when residency " "management does not exist. This is probably not what the " "developer intended to do. Please consider creating a residency " "manager with this resource allocator before using this flag."; } - ALLOCATOR_DESC newDescriptor = allocatorDescriptor; + RESOURCE_ALLOCATOR_DESC newDescriptor = allocatorDescriptor; newDescriptor.ResourceHeapGrowthFactor = (allocatorDescriptor.ResourceHeapGrowthFactor >= 1.0) ? allocatorDescriptor.ResourceHeapGrowthFactor @@ -491,20 +493,20 @@ namespace gpgmm::d3d12 { // By default, UMA is allowed to use a single heap type. Unless it is explicitly disabled or // unsupported by the device. - if (!(allocatorDescriptor.Flags & ALLOCATOR_FLAG_DISABLE_UNIFIED_MEMORY) && + if (!(allocatorDescriptor.Flags & RESOURCE_ALLOCATOR_FLAG_DISABLE_UNIFIED_MEMORY) && !caps->IsAdapterCacheCoherentUMA()) { DebugLog(MessageId::kInvalidArgument, true) - << "ALLOCATOR_FLAG_DISABLE_UNIFIED_MEMORY was not requested but enabled " + << "RESOURCE_ALLOCATOR_FLAG_DISABLE_UNIFIED_MEMORY was not requested but enabled " "anyway because the device did not support cache-coherent UMA."; - newDescriptor.Flags |= ALLOCATOR_FLAG_DISABLE_UNIFIED_MEMORY; + newDescriptor.Flags |= RESOURCE_ALLOCATOR_FLAG_DISABLE_UNIFIED_MEMORY; } - if (!(allocatorDescriptor.Flags & ALLOCATOR_FLAG_ALWAYS_RESIDENT) && + if (!(allocatorDescriptor.Flags & RESOURCE_ALLOCATOR_FLAG_ALWAYS_RESIDENT) && !caps->IsCreateHeapNotResidentSupported()) { DebugLog(MessageId::kInvalidArgument, true) - << "ALLOCATOR_FLAG_ALWAYS_RESIDENT was not requested but enabled " + << "RESOURCE_ALLOCATOR_FLAG_ALWAYS_RESIDENT was not requested but enabled " "anyway because the device did not support creation of non-resident heaps."; - newDescriptor.Flags |= ALLOCATOR_FLAG_ALWAYS_RESIDENT; + newDescriptor.Flags |= RESOURCE_ALLOCATOR_FLAG_ALWAYS_RESIDENT; } // Resource heap tier is required but user didn't specify one. @@ -577,7 +579,7 @@ namespace gpgmm::d3d12 { return S_OK; } - ResourceAllocator::ResourceAllocator(const ALLOCATOR_DESC& descriptor, + ResourceAllocator::ResourceAllocator(const RESOURCE_ALLOCATOR_DESC& descriptor, ID3D12Device* pDevice, ResidencyManager* pResidencyManager, std::unique_ptr caps) @@ -585,19 +587,19 @@ namespace gpgmm::d3d12 { mResidencyManager(pResidencyManager), mCaps(std::move(caps)), mResourceHeapTier(descriptor.ResourceHeapTier), - mIsAlwaysCommitted(descriptor.Flags & ALLOCATOR_FLAG_ALWAYS_COMMITTED), - mIsAlwaysCreatedInBudget(descriptor.Flags & ALLOCATOR_FLAG_ALWAYS_IN_BUDGET), + mIsAlwaysCommitted(descriptor.Flags & RESOURCE_ALLOCATOR_FLAG_ALWAYS_COMMITTED), + mIsAlwaysCreatedInBudget(descriptor.Flags & RESOURCE_ALLOCATOR_FLAG_ALWAYS_IN_BUDGET), mFlushEventBuffersOnDestruct(descriptor.RecordOptions.EventScope & RECORD_SCOPE_PER_INSTANCE), mUseDetailedTimingEvents(descriptor.RecordOptions.UseDetailedTimingEvents), - mIsCustomHeapsDisabled(descriptor.Flags & ALLOCATOR_FLAG_DISABLE_UNIFIED_MEMORY), - mIsAlwaysCreateResident(descriptor.Flags & ALLOCATOR_FLAG_ALWAYS_RESIDENT), + mIsCustomHeapsDisabled(descriptor.Flags & RESOURCE_ALLOCATOR_FLAG_DISABLE_UNIFIED_MEMORY), + mIsAlwaysCreateResident(descriptor.Flags & RESOURCE_ALLOCATOR_FLAG_ALWAYS_RESIDENT), mMaxResourceHeapSize(descriptor.MaxResourceHeapSize) { ASSERT(mDevice != nullptr); GPGMM_TRACE_EVENT_OBJECT_NEW(this); - if (descriptor.Flags & ALLOCATOR_FLAG_NEVER_LEAK_MEMORY) { + if (descriptor.Flags & RESOURCE_ALLOCATOR_FLAG_NEVER_LEAK) { mDebugAllocator = std::make_unique(); } @@ -631,7 +633,7 @@ namespace gpgmm::d3d12 { // Dedicated allocators are used when sub-allocation cannot but heaps could still be // recycled. - ALLOCATOR_DESC dedicatedDescriptor = descriptor; + RESOURCE_ALLOCATOR_DESC dedicatedDescriptor = descriptor; dedicatedDescriptor.SubAllocationAlgorithm = ALLOCATOR_ALGORITHM_DEDICATED; mDedicatedResourceAllocatorOfType[resourceHeapTypeIndex] = CreateResourceAllocator( @@ -754,7 +756,7 @@ namespace gpgmm::d3d12 { } std::unique_ptr ResourceAllocator::CreateResourceAllocator( - const ALLOCATOR_DESC& descriptor, + const RESOURCE_ALLOCATOR_DESC& descriptor, D3D12_HEAP_FLAGS heapFlags, const D3D12_HEAP_PROPERTIES& heapProperties, uint64_t heapAlignment) { @@ -766,19 +768,21 @@ namespace gpgmm::d3d12 { const uint64_t heapSize = std::max(heapAlignment, AlignTo(descriptor.PreferredResourceHeapSize, heapAlignment)); - std::unique_ptr pooledOrNonPooledAllocator = CreatePoolAllocator( - descriptor.PoolAlgorithm, heapSize, heapAlignment, - (descriptor.Flags & ALLOCATOR_FLAG_ALWAYS_ON_DEMAND), std::move(resourceHeapAllocator)); - - return CreateSubAllocator( - descriptor.SubAllocationAlgorithm, heapSize, heapAlignment, - descriptor.ResourceHeapFragmentationLimit, descriptor.ResourceHeapGrowthFactor, - /*allowSlabPrefetch*/ !(descriptor.Flags & ALLOCATOR_FLAG_DISABLE_MEMORY_PREFETCH), - std::move(pooledOrNonPooledAllocator)); + std::unique_ptr pooledOrNonPooledAllocator = + CreatePoolAllocator(descriptor.PoolAlgorithm, heapSize, heapAlignment, + (descriptor.Flags & RESOURCE_ALLOCATOR_FLAG_ALWAYS_ON_DEMAND), + std::move(resourceHeapAllocator)); + + return CreateSubAllocator(descriptor.SubAllocationAlgorithm, heapSize, heapAlignment, + descriptor.ResourceHeapFragmentationLimit, + descriptor.ResourceHeapGrowthFactor, + /*allowSlabPrefetch*/ + !(descriptor.Flags & RESOURCE_ALLOCATOR_FLAG_DISABLE_PREFETCH), + std::move(pooledOrNonPooledAllocator)); } std::unique_ptr ResourceAllocator::CreateSmallBufferAllocator( - const ALLOCATOR_DESC& descriptor, + const RESOURCE_ALLOCATOR_DESC& descriptor, D3D12_HEAP_FLAGS heapFlags, const D3D12_HEAP_PROPERTIES& heapProperties, uint64_t heapAlignment, @@ -789,7 +793,7 @@ namespace gpgmm::d3d12 { std::unique_ptr pooledOrNonPooledAllocator = CreatePoolAllocator(descriptor.PoolAlgorithm, heapAlignment, heapAlignment, - (descriptor.Flags & ALLOCATOR_FLAG_ALWAYS_ON_DEMAND), + (descriptor.Flags & RESOURCE_ALLOCATOR_FLAG_ALWAYS_ON_DEMAND), std::move(smallBufferOnlyAllocator)); const uint64_t heapSize = @@ -1046,7 +1050,8 @@ namespace gpgmm::d3d12 { D3D12_HEAP_FLAGS heapFlags = GetHeapFlags(resourceHeapType, IsCreateHeapNotResident()); if (!HasAllFlags(heapFlags, allocationDescriptor.ExtraRequiredHeapFlags)) { WarnLog(this, MessageId::kPerformanceWarning) - << "ALLOCATOR_FLAG_ALWAYS_COMMITTED was not requested but enabled anyway because " + << "RESOURCE_ALLOCATOR_FLAG_ALWAYS_COMMITTED was not requested but enabled anyway " + "because " "the required heap flags were incompatible with resource heap type (" << std::to_string(allocationDescriptor.ExtraRequiredHeapFlags) << " vs " << std::to_string(heapFlags) + ")."; @@ -1058,8 +1063,7 @@ namespace gpgmm::d3d12 { isAlwaysCommitted = true; } - bool neverSubAllocate = - allocationDescriptor.Flags & ALLOCATION_FLAG_NEVER_SUBALLOCATE_MEMORY; + bool neverSubAllocate = allocationDescriptor.Flags & ALLOCATION_FLAG_NEVER_SUBALLOCATE_HEAP; const bool isMSAA = resourceDescriptor.SampleDesc.Count > 1; @@ -1078,10 +1082,9 @@ namespace gpgmm::d3d12 { request.SizeInBytes = (newResourceDesc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER) ? newResourceDesc.Width : resourceInfo.SizeInBytes; - request.NeverAllocate = - (allocationDescriptor.Flags & ALLOCATION_FLAG_NEVER_ALLOCATE_MEMORY); + request.NeverAllocate = (allocationDescriptor.Flags & ALLOCATION_FLAG_NEVER_ALLOCATE_HEAP); request.AlwaysPrefetch = - (allocationDescriptor.Flags & ALLOCATION_FLAG_ALWAYS_PREFETCH_MEMORY); + (allocationDescriptor.Flags & ALLOCATION_FLAG_ALWAYS_PREFETCH_HEAP); request.AlwaysCacheSize = (allocationDescriptor.Flags & ALLOCATION_FLAG_ALWAYS_CACHE_SIZE); request.AvailableForAllocation = mMaxResourceHeapSize; @@ -1184,7 +1187,8 @@ namespace gpgmm::d3d12 { // Committed resource implicitly creates a resource heap which can be // used for sub-allocation. ComPtr committedResource; - Heap* resourceHeap = static_cast(subAllocation.GetMemory()); + ResidencyHeap* resourceHeap = + static_cast(subAllocation.GetMemory()); GPGMM_RETURN_IF_FAILED( resourceHeap->QueryInterface(IID_PPV_ARGS(&committedResource)), mDevice); @@ -1222,7 +1226,8 @@ namespace gpgmm::d3d12 { // Each allocation maps to a disjoint (physical) address range so no physical // memory is can be aliased or will overlap. ComPtr placedResource; - Heap* resourceHeap = static_cast(subAllocation.GetMemory()); + ResidencyHeap* resourceHeap = + static_cast(subAllocation.GetMemory()); GPGMM_RETURN_IF_FAILED( CreatePlacedResource(resourceHeap, subAllocation.GetOffset(), &newResourceDesc, clearValue, initialResourceState, @@ -1264,7 +1269,8 @@ namespace gpgmm::d3d12 { GPGMM_RETURN_IF_SUCCEEDED_OR_FATAL( TryAllocateResource(allocator, request, [&](const auto& allocation) -> HRESULT { - Heap* resourceHeap = static_cast(allocation.GetMemory()); + ResidencyHeap* resourceHeap = + static_cast(allocation.GetMemory()); ComPtr placedResource; GPGMM_RETURN_IF_FAILED( CreatePlacedResource(resourceHeap, allocation.GetOffset(), &newResourceDesc, @@ -1319,7 +1325,7 @@ namespace gpgmm::d3d12 { } ComPtr committedResource; - ComPtr resourceHeap; + ComPtr resourceHeap; GPGMM_RETURN_IF_FAILED( CreateCommittedResource(heapProperties, heapFlags, resourceInfo, &newResourceDesc, clearValue, initialResourceState, &committedResource, @@ -1397,7 +1403,7 @@ namespace gpgmm::d3d12 { const ALLOCATION_FLAGS allowMask = (ALLOCATION_FLAG_NEVER_RESIDENT & ALLOCATION_FLAG_ALWAYS_ATTRIBUTE_HEAPS & - ALLOCATION_FLAG_NEVER_ALLOCATE_MEMORY); + ALLOCATION_FLAG_NEVER_ALLOCATE_HEAP); if (allocationDescriptor.Flags & ~allowMask) { ErrorLog(MessageId::kInvalidArgument) << "Unable to import a resource when using allocation flags which modify memory."; @@ -1409,21 +1415,21 @@ namespace gpgmm::d3d12 { return S_FALSE; } - HEAP_DESC resourceHeapDesc = {}; + RESIDENCY_HEAP_DESC resourceHeapDesc = {}; resourceHeapDesc.SizeInBytes = resourceInfo.SizeInBytes; resourceHeapDesc.Alignment = resourceInfo.Alignment; ImportResourceCallbackContext importResourceCallbackContext(pCommittedResource); - ComPtr resourceHeap; - GPGMM_RETURN_IF_FAILED( - Heap::CreateHeap(resourceHeapDesc, - (allocationDescriptor.Flags & ALLOCATION_FLAG_NEVER_RESIDENT) - ? nullptr - : mResidencyManager.Get(), - ImportResourceCallbackContext::GetHeap, &importResourceCallbackContext, - &resourceHeap), - mDevice); + ComPtr resourceHeap; + GPGMM_RETURN_IF_FAILED(ResidencyHeap::CreateResidencyHeap( + resourceHeapDesc, + (allocationDescriptor.Flags & ALLOCATION_FLAG_NEVER_RESIDENT) + ? nullptr + : mResidencyManager.Get(), + ImportResourceCallbackContext::GetHeap, + &importResourceCallbackContext, &resourceHeap), + mDevice); const uint64_t& allocationSize = resourceInfo.SizeInBytes; mStats.UsedMemoryUsage += allocationSize; @@ -1435,14 +1441,14 @@ namespace gpgmm::d3d12 { allocationDesc.SizeInBytes = allocationSize; allocationDesc.Method = ALLOCATION_METHOD_STANDALONE; - *ppResourceAllocationOut = new ResourceAllocation(allocationDesc, nullptr, this, - static_cast(resourceHeap.Detach()), - nullptr, pCommittedResource); + *ppResourceAllocationOut = new ResourceAllocation( + allocationDesc, nullptr, this, static_cast(resourceHeap.Detach()), + nullptr, pCommittedResource); return S_OK; } - HRESULT ResourceAllocator::CreatePlacedResource(Heap* const resourceHeap, + HRESULT ResourceAllocator::CreatePlacedResource(ResidencyHeap* const resourceHeap, uint64_t resourceOffset, const D3D12_RESOURCE_DESC* resourceDescriptor, const D3D12_CLEAR_VALUE* clearValue, @@ -1479,11 +1485,11 @@ namespace gpgmm::d3d12 { const D3D12_CLEAR_VALUE* clearValue, D3D12_RESOURCE_STATES initialResourceState, ID3D12Resource** commitedResourceOut, - Heap** resourceHeapOut) { + ResidencyHeap** resourceHeapOut) { GPGMM_TRACE_EVENT_DURATION(TraceEventCategory::kDefault, "ResourceAllocator.CreateCommittedResource"); - HEAP_DESC resourceHeapDesc = {}; + RESIDENCY_HEAP_DESC resourceHeapDesc = {}; resourceHeapDesc.SizeInBytes = info.SizeInBytes; resourceHeapDesc.Alignment = info.Alignment; resourceHeapDesc.DebugName = L"Resource heap (committed)"; @@ -1495,14 +1501,15 @@ namespace gpgmm::d3d12 { } // Since residency is per heap, every committed resource is wrapped in a heap object. - ComPtr resourceHeap; + ComPtr resourceHeap; CreateCommittedResourceCallbackContext callbackContext(mDevice, &heapProperties, heapFlags, resourceDescriptor, clearValue, initialResourceState); - GPGMM_RETURN_IF_FAILED(Heap::CreateHeap(resourceHeapDesc, mResidencyManager.Get(), - CreateCommittedResourceCallbackContext::CreateHeap, - &callbackContext, &resourceHeap), + GPGMM_RETURN_IF_FAILED(ResidencyHeap::CreateResidencyHeap( + resourceHeapDesc, mResidencyManager.Get(), + CreateCommittedResourceCallbackContext::CreateResidencyHeap, + &callbackContext, &resourceHeap), mDevice); if (commitedResourceOut != nullptr) { @@ -1513,7 +1520,7 @@ namespace gpgmm::d3d12 { } if (resourceHeapOut != nullptr) { - *resourceHeapOut = static_cast(resourceHeap.Detach()); + *resourceHeapOut = static_cast(resourceHeap.Detach()); } return S_OK; @@ -1726,8 +1733,9 @@ namespace gpgmm::d3d12 { } // static - HRESULT CreateCommittedResourceCallbackContext::CreateHeap(void* pContext, - ID3D12Pageable** ppPageableOut) { + HRESULT CreateCommittedResourceCallbackContext::CreateResidencyHeap( + void* pContext, + ID3D12Pageable** ppPageableOut) { CreateCommittedResourceCallbackContext* createCommittedResourceCallbackContext = static_cast(pContext); diff --git a/src/gpgmm/d3d12/ResourceAllocatorD3D12.h b/src/gpgmm/d3d12/ResourceAllocatorD3D12.h index c44bd648c..ea2786c14 100644 --- a/src/gpgmm/d3d12/ResourceAllocatorD3D12.h +++ b/src/gpgmm/d3d12/ResourceAllocatorD3D12.h @@ -30,7 +30,7 @@ namespace gpgmm::d3d12 { class BufferAllocator; class Caps; - class Heap; + class ResidencyHeap; class DebugResourceAllocator; class ResidencyManager; class ResourceAllocation; @@ -39,13 +39,13 @@ namespace gpgmm::d3d12 { public IResourceAllocator, public MemoryAllocator { public: - static HRESULT CreateResourceAllocator(const ALLOCATOR_DESC& allocatorDescriptor, + static HRESULT CreateResourceAllocator(const RESOURCE_ALLOCATOR_DESC& allocatorDescriptor, ID3D12Device* pDevice, IDXGIAdapter* pAdapter, IResourceAllocator** ppResourceAllocatorOut, IResidencyManager** ppResidencyManagerOut); - static HRESULT CreateResourceAllocator(const ALLOCATOR_DESC& allocatorDescriptor, + static HRESULT CreateResourceAllocator(const RESOURCE_ALLOCATOR_DESC& allocatorDescriptor, ID3D12Device* pDevice, IDXGIAdapter* pAdapter, IResidencyManager* pResidencyManager, @@ -87,19 +87,19 @@ namespace gpgmm::d3d12 { const D3D12_CLEAR_VALUE* clearValue, IResourceAllocation** ppResourceAllocationOut); - ResourceAllocator(const ALLOCATOR_DESC& descriptor, + ResourceAllocator(const RESOURCE_ALLOCATOR_DESC& descriptor, ID3D12Device* pDevice, ResidencyManager* pResidencyManager, std::unique_ptr caps); std::unique_ptr CreateResourceAllocator( - const ALLOCATOR_DESC& descriptor, + const RESOURCE_ALLOCATOR_DESC& descriptor, D3D12_HEAP_FLAGS heapFlags, const D3D12_HEAP_PROPERTIES& heapProperties, uint64_t heapAlignment); std::unique_ptr CreateSmallBufferAllocator( - const ALLOCATOR_DESC& descriptor, + const RESOURCE_ALLOCATOR_DESC& descriptor, D3D12_HEAP_FLAGS heapFlags, const D3D12_HEAP_PROPERTIES& heapProperties, uint64_t heapAlignment, @@ -121,7 +121,7 @@ namespace gpgmm::d3d12 { bool isPrefetchAllowed, std::unique_ptr underlyingAllocator); - HRESULT CreatePlacedResource(Heap* const resourceHeap, + HRESULT CreatePlacedResource(ResidencyHeap* const resourceHeap, uint64_t resourceOffset, const D3D12_RESOURCE_DESC* resourceDescriptor, const D3D12_CLEAR_VALUE* clearValue, @@ -135,7 +135,7 @@ namespace gpgmm::d3d12 { const D3D12_CLEAR_VALUE* clearValue, D3D12_RESOURCE_STATES initialResourceState, ID3D12Resource** commitedResourceOut, - Heap** resourceHeapOut); + ResidencyHeap** resourceHeapOut); HRESULT ReportLiveDeviceObjects() const; diff --git a/src/gpgmm/d3d12/ResourceHeapAllocatorD3D12.cpp b/src/gpgmm/d3d12/ResourceHeapAllocatorD3D12.cpp index dc9b2dced..7808c06f1 100644 --- a/src/gpgmm/d3d12/ResourceHeapAllocatorD3D12.cpp +++ b/src/gpgmm/d3d12/ResourceHeapAllocatorD3D12.cpp @@ -19,7 +19,7 @@ #include "gpgmm/common/SizeClass.h" #include "gpgmm/d3d12/BackendD3D12.h" #include "gpgmm/d3d12/ErrorD3D12.h" -#include "gpgmm/d3d12/HeapD3D12.h" +#include "gpgmm/d3d12/ResidencyHeapD3D12.h" #include "gpgmm/d3d12/ResidencyManagerD3D12.h" #include "gpgmm/d3d12/UtilsD3D12.h" #include "gpgmm/utils/Limits.h" @@ -50,7 +50,7 @@ namespace gpgmm::d3d12 { return {}; } - HEAP_DESC resourceHeapDesc = {}; + RESIDENCY_HEAP_DESC resourceHeapDesc = {}; // D3D12 requests (but not requires) the heap size be always a multiple of // alignment to avoid wasting bytes. // https://docs.microsoft.com/en-us/windows/win32/api/d3d12/ns-d3d12-d3d12_HEAP_INFO @@ -72,10 +72,10 @@ namespace gpgmm::d3d12 { heapDesc.Flags = mHeapFlags; CreateResourceHeapCallbackContext createResourceHeapCallbackContext(mDevice, &heapDesc); - ComPtr resourceHeap; - HRESULT hr = Heap::CreateHeap(resourceHeapDesc, mResidencyManager, - CreateResourceHeapCallbackContext::CreateHeap, - &createResourceHeapCallbackContext, &resourceHeap); + ComPtr resourceHeap; + HRESULT hr = ResidencyHeap::CreateResidencyHeap( + resourceHeapDesc, mResidencyManager, CreateResourceHeapCallbackContext::CreateHeap, + &createResourceHeapCallbackContext, &resourceHeap); if (FAILED(hr)) { return {static_cast(hr)}; } @@ -83,8 +83,8 @@ namespace gpgmm::d3d12 { mStats.UsedMemoryUsage += resourceHeapDesc.SizeInBytes; mStats.UsedMemoryCount++; - return std::make_unique(this, static_cast(resourceHeap.Detach()), - request.SizeInBytes); + return std::make_unique( + this, static_cast(resourceHeap.Detach()), request.SizeInBytes); } void ResourceHeapAllocator::DeallocateMemory(std::unique_ptr allocation) { diff --git a/src/mvi/gpgmm_d3d12.cpp b/src/mvi/gpgmm_d3d12.cpp index 28eafb73b..0f904b08e 100644 --- a/src/mvi/gpgmm_d3d12.cpp +++ b/src/mvi/gpgmm_d3d12.cpp @@ -71,48 +71,49 @@ namespace gpgmm::d3d12 { // Heap // static - HRESULT Heap::CreateHeap(const HEAP_DESC& descriptor, - IResidencyManager* const pResidencyManager, - CreateHeapFn createHeapFn, - void* context, - IHeap** ppHeapOut) { + HRESULT ResidencyHeap::CreateResidencyHeap(const RESIDENCY_HEAP_DESC& descriptor, + IResidencyManager* const pResidencyManager, + CreateHeapFn createHeapFn, + void* context, + IResidencyHeap** ppResidencyHeapOut) { Microsoft::WRL::ComPtr pageable; GPGMM_RETURN_IF_FAILED(createHeapFn(context, &pageable)); - if (ppHeapOut != nullptr) { - *ppHeapOut = new Heap(pageable, descriptor, (pResidencyManager == nullptr)); + if (ppResidencyHeapOut != nullptr) { + *ppResidencyHeapOut = + new ResidencyHeap(pageable, descriptor, (pResidencyManager == nullptr)); } return S_OK; } - Heap::Heap(Microsoft::WRL::ComPtr pageable, - const HEAP_DESC& descriptor, - bool isResidencyDisabled) + ResidencyHeap::ResidencyHeap(Microsoft::WRL::ComPtr pageable, + const RESIDENCY_HEAP_DESC& descriptor, + bool isResidencyDisabled) : MemoryBase(descriptor.SizeInBytes, descriptor.Alignment), mPageable(std::move(pageable)) { } - HEAP_INFO Heap::GetInfo() const { - return {GetSize(), GetAlignment(), false, false, RESIDENCY_STATUS_UNKNOWN}; + RESIDENCY_HEAP_INFO ResidencyHeap::GetInfo() const { + return {GetSize(), GetAlignment(), false, false, RESIDENCY_HEAP_STATUS_UNKNOWN}; } - HRESULT STDMETHODCALLTYPE Heap::QueryInterface(REFIID riid, void** ppvObject) { + HRESULT STDMETHODCALLTYPE ResidencyHeap::QueryInterface(REFIID riid, void** ppvObject) { return mPageable->QueryInterface(riid, ppvObject); } - ULONG STDMETHODCALLTYPE Heap::AddRef() { + ULONG STDMETHODCALLTYPE ResidencyHeap::AddRef() { return Unknown::AddRef(); } - ULONG STDMETHODCALLTYPE Heap::Release() { + ULONG STDMETHODCALLTYPE ResidencyHeap::Release() { return Unknown::Release(); } - LPCWSTR Heap::GetDebugName() const { + LPCWSTR ResidencyHeap::GetDebugName() const { return nullptr; } - HRESULT Heap::SetDebugName(LPCWSTR Name) { + HRESULT ResidencyHeap::SetDebugName(LPCWSTR Name) { return E_NOTIMPL; } @@ -127,7 +128,7 @@ namespace gpgmm::d3d12 { ResidencyList::ResidencyList() = default; - HRESULT ResidencyList::Add(IHeap* pHeap) { + HRESULT ResidencyList::Add(IResidencyHeap* pHeap) { return S_OK; } @@ -149,7 +150,7 @@ namespace gpgmm::d3d12 { // ResidencyManager - HRESULT CreateResidencyManager(const RESIDENCY_DESC& descriptor, + HRESULT CreateResidencyManager(const RESIDENCY_MANAGER_DESC& descriptor, ID3D12Device* pDevice, IDXGIAdapter3* pAdapter, IResidencyManager** ppResidencyManagerOut) { @@ -158,7 +159,7 @@ namespace gpgmm::d3d12 { } // static - HRESULT ResidencyManager::CreateResidencyManager(const RESIDENCY_DESC& descriptor, + HRESULT ResidencyManager::CreateResidencyManager(const RESIDENCY_MANAGER_DESC& descriptor, ID3D12Device* pDevice, IDXGIAdapter3* pAdapter, IResidencyManager** ppResidencyManagerOut) { @@ -171,11 +172,11 @@ namespace gpgmm::d3d12 { ResidencyManager::~ResidencyManager() = default; - HRESULT ResidencyManager::LockHeap(IHeap* pHeap) { + HRESULT ResidencyManager::LockHeap(IResidencyHeap* pHeap) { return S_OK; } - HRESULT ResidencyManager::UnlockHeap(IHeap* pHeap) { + HRESULT ResidencyManager::UnlockHeap(IResidencyHeap* pHeap) { return S_OK; } @@ -200,7 +201,8 @@ namespace gpgmm::d3d12 { return S_OK; } - HRESULT ResidencyManager::SetResidencyState(IHeap* pHeap, const RESIDENCY_STATUS& state) { + HRESULT ResidencyManager::SetResidencyStatus(IResidencyHeap* pHeap, + const RESIDENCY_HEAP_STATUS& state) { return S_OK; } @@ -208,7 +210,7 @@ namespace gpgmm::d3d12 { return E_NOTIMPL; } - ResidencyManager::ResidencyManager(const RESIDENCY_DESC& descriptor, + ResidencyManager::ResidencyManager(const RESIDENCY_MANAGER_DESC& descriptor, ID3D12Device* pDevice, IDXGIAdapter3* pAdapter) : mDevice(pDevice), mAdapter(pAdapter) { @@ -266,12 +268,12 @@ namespace gpgmm::d3d12 { return {GetSize(), GetAlignment()}; } - IHeap* ResourceAllocation::GetMemory() const { - return static_cast(MemoryAllocation::GetMemory()); + IResidencyHeap* ResourceAllocation::GetMemory() const { + return static_cast(MemoryAllocation::GetMemory()); } ResourceAllocation::ResourceAllocation(MemoryAllocator* allocator, - Heap* resourceHeap, + ResidencyHeap* resourceHeap, Microsoft::WRL::ComPtr resource) : MemoryAllocation(allocator, resourceHeap), mResource(std::move(resource)) { } @@ -298,7 +300,7 @@ namespace gpgmm::d3d12 { // ResourceAllocator - HRESULT CreateResourceAllocator(const ALLOCATOR_DESC& allocatorDescriptor, + HRESULT CreateResourceAllocator(const RESOURCE_ALLOCATOR_DESC& allocatorDescriptor, ID3D12Device* pDevice, IDXGIAdapter* pAdapter, IResourceAllocator** ppResourceAllocatorOut, @@ -308,18 +310,19 @@ namespace gpgmm::d3d12 { } // static - HRESULT ResourceAllocator::CreateResourceAllocator(const ALLOCATOR_DESC& allocatorDescriptor, - ID3D12Device* pDevice, - IDXGIAdapter* pAdapter, - IResourceAllocator** ppResourceAllocatorOut, - IResidencyManager** ppResidencyManagerOut) { + HRESULT ResourceAllocator::CreateResourceAllocator( + const RESOURCE_ALLOCATOR_DESC& allocatorDescriptor, + ID3D12Device* pDevice, + IDXGIAdapter* pAdapter, + IResourceAllocator** ppResourceAllocatorOut, + IResidencyManager** ppResidencyManagerOut) { if (pDevice == nullptr) { return E_INVALIDARG; } Microsoft::WRL::ComPtr residencyManager; if (ppResidencyManagerOut != nullptr) { - RESIDENCY_DESC residencyDesc = {}; + RESIDENCY_MANAGER_DESC residencyDesc = {}; Microsoft::WRL::ComPtr adapter3; if (pAdapter != nullptr) { @@ -347,7 +350,7 @@ namespace gpgmm::d3d12 { // static HRESULT ResourceAllocator::CreateResourceAllocator( - const ALLOCATOR_DESC& allocatorDescriptor, + const RESOURCE_ALLOCATOR_DESC& allocatorDescriptor, ID3D12Device* pDevice, IDXGIAdapter* pAdapter, IResidencyManager* pResidencyManager, @@ -365,13 +368,13 @@ namespace gpgmm::d3d12 { D3D12_RESOURCE_STATES initialResourceState, const D3D12_CLEAR_VALUE* pClearValue, IResourceAllocation** ppResourceAllocationOut) { - IHeap* resourceHeap = nullptr; + IResidencyHeap* resourceHeap = nullptr; Microsoft::WRL::ComPtr committedResource; const D3D12_RESOURCE_ALLOCATION_INFO resourceInfo = mDevice->GetResourceAllocationInfo(0, 1, &resourceDescriptor); - HEAP_DESC resourceHeapDesc = {}; + RESIDENCY_HEAP_DESC resourceHeapDesc = {}; resourceHeapDesc.SizeInBytes = resourceInfo.SizeInBytes; resourceHeapDesc.Alignment = resourceInfo.Alignment; @@ -379,12 +382,13 @@ namespace gpgmm::d3d12 { mDevice.Get(), allocationDescriptor, committedResource, &resourceDescriptor, pClearValue, initialResourceState); - GPGMM_RETURN_IF_FAILED(Heap::CreateHeap(resourceHeapDesc, mResidencyManager.Get(), - CreateCommittedResourceCallbackContext::CreateHeap, - &callbackContext, &resourceHeap)); + GPGMM_RETURN_IF_FAILED(ResidencyHeap::CreateResidencyHeap( + resourceHeapDesc, mResidencyManager.Get(), + CreateCommittedResourceCallbackContext::CreateResidencyHeap, &callbackContext, + &resourceHeap)); - *ppResourceAllocationOut = new ResourceAllocation(this, static_cast(resourceHeap), - std::move(committedResource)); + *ppResourceAllocationOut = new ResourceAllocation( + this, static_cast(resourceHeap), std::move(committedResource)); return S_OK; } @@ -409,7 +413,7 @@ namespace gpgmm::d3d12 { return E_INVALIDARG; // Unsupported } - ResourceAllocator::ResourceAllocator(const ALLOCATOR_DESC& descriptor, + ResourceAllocator::ResourceAllocator(const RESOURCE_ALLOCATOR_DESC& descriptor, ID3D12Device* pDevice, ResidencyManager* pResidencyManager) : mDevice(pDevice), mResidencyManager(pResidencyManager) { @@ -468,8 +472,9 @@ namespace gpgmm::d3d12 { return S_OK; } - HRESULT CreateCommittedResourceCallbackContext::CreateHeap(void* context, - ID3D12Pageable** ppPageableOut) { + HRESULT CreateCommittedResourceCallbackContext::CreateResidencyHeap( + void* context, + ID3D12Pageable** ppPageableOut) { CreateCommittedResourceCallbackContext* createCommittedResourceCallbackContext = static_cast(context); diff --git a/src/mvi/gpgmm_d3d12.h b/src/mvi/gpgmm_d3d12.h index 249659346..bdf74cbcd 100644 --- a/src/mvi/gpgmm_d3d12.h +++ b/src/mvi/gpgmm_d3d12.h @@ -62,16 +62,16 @@ namespace gpgmm::d3d12 { GPGMM_REFCOUNT_TYPE mRefCount; }; - class Heap final : public MemoryBase, public Unknown, public IHeap { + class ResidencyHeap final : public MemoryBase, public Unknown, public IResidencyHeap { public: - static HRESULT CreateHeap(const HEAP_DESC& descriptor, - IResidencyManager* const pResidencyManager, - CreateHeapFn createHeapFn, - void* context, - IHeap** ppHeapOut); + static HRESULT CreateResidencyHeap(const RESIDENCY_HEAP_DESC& descriptor, + IResidencyManager* const pResidencyManager, + CreateHeapFn createHeapFn, + void* context, + IResidencyHeap** ppResidencyHeapOut); - // IHeap interface - HEAP_INFO GetInfo() const override; + // IResidencyHeap interface + RESIDENCY_HEAP_INFO GetInfo() const override; // IUnknown interface HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject) override; @@ -83,9 +83,9 @@ namespace gpgmm::d3d12 { HRESULT SetDebugName(LPCWSTR Name) override; private: - Heap(Microsoft::WRL::ComPtr pageable, - const HEAP_DESC& descriptor, - bool isResidencyDisabled); + ResidencyHeap(Microsoft::WRL::ComPtr pageable, + const RESIDENCY_HEAP_DESC& descriptor, + bool isResidencyDisabled); Microsoft::WRL::ComPtr mPageable; }; @@ -94,7 +94,7 @@ namespace gpgmm::d3d12 { public: ResidencyList(); - HRESULT Add(IHeap* pHeap) override; + HRESULT Add(IResidencyHeap* pHeap) override; HRESULT Reset() override; // IUnknown interface @@ -105,7 +105,7 @@ namespace gpgmm::d3d12 { class ResidencyManager final : public Unknown, public IResidencyManager { public: - static HRESULT CreateResidencyManager(const RESIDENCY_DESC& descriptor, + static HRESULT CreateResidencyManager(const RESIDENCY_MANAGER_DESC& descriptor, ID3D12Device* pDevice, IDXGIAdapter3* pAdapter, IResidencyManager** ppResidencyManagerOut); @@ -113,8 +113,8 @@ namespace gpgmm::d3d12 { ~ResidencyManager() override; // IResidencyManager interface - HRESULT LockHeap(IHeap* pHeap) override; - HRESULT UnlockHeap(IHeap* pHeap) override; + HRESULT LockHeap(IResidencyHeap* pHeap) override; + HRESULT UnlockHeap(IResidencyHeap* pHeap) override; HRESULT ExecuteCommandLists(ID3D12CommandQueue* pQueue, ID3D12CommandList* const* ppCommandLists, IResidencyList* const* ppResidencyLists, @@ -124,7 +124,8 @@ namespace gpgmm::d3d12 { uint64_t* pCurrentReservationOut = nullptr) override; HRESULT QueryVideoMemoryInfo(const DXGI_MEMORY_SEGMENT_GROUP& heapSegment, DXGI_QUERY_VIDEO_MEMORY_INFO* pVideoMemoryInfoOut) override; - HRESULT SetResidencyState(IHeap* pHeap, const RESIDENCY_STATUS& state) override; + HRESULT SetResidencyStatus(IResidencyHeap* pHeap, + const RESIDENCY_HEAP_STATUS& state) override; HRESULT QueryStats(RESIDENCY_MANAGER_STATS* pResidencyManagerStats) override; // IUnknown interface @@ -137,7 +138,7 @@ namespace gpgmm::d3d12 { HRESULT SetDebugName(LPCWSTR Name) override; private: - ResidencyManager(const RESIDENCY_DESC& descriptor, + ResidencyManager(const RESIDENCY_MANAGER_DESC& descriptor, ID3D12Device* pDevice, IDXGIAdapter3* pAdapter); @@ -160,7 +161,7 @@ namespace gpgmm::d3d12 { D3D12_GPU_VIRTUAL_ADDRESS GetGPUVirtualAddress() const override; uint64_t GetOffsetFromResource() const override; RESOURCE_ALLOCATION_INFO GetInfo() const override; - IHeap* GetMemory() const override; + IResidencyHeap* GetMemory() const override; // IUnknown interface HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject) override; @@ -175,7 +176,7 @@ namespace gpgmm::d3d12 { friend ResourceAllocator; ResourceAllocation(MemoryAllocator* allocator, - Heap* resourceHeap, + ResidencyHeap* resourceHeap, Microsoft::WRL::ComPtr resource); void DeleteThis() override; @@ -191,7 +192,7 @@ namespace gpgmm::d3d12 { const D3D12_RESOURCE_DESC* resourceDescriptor, const D3D12_CLEAR_VALUE* clearValue, D3D12_RESOURCE_STATES initialResourceState); - static HRESULT CreateHeap(void* context, ID3D12Pageable** ppPageableOut); + static HRESULT CreateResidencyHeap(void* context, ID3D12Pageable** ppPageableOut); private: HRESULT CreateCommittedResource(ID3D12Pageable** ppPageableOut); @@ -208,13 +209,13 @@ namespace gpgmm::d3d12 { public Unknown, public IResourceAllocator { public: - static HRESULT CreateResourceAllocator(const ALLOCATOR_DESC& allocatorDescriptor, + static HRESULT CreateResourceAllocator(const RESOURCE_ALLOCATOR_DESC& allocatorDescriptor, ID3D12Device* pDevice, IDXGIAdapter* pAdapter, IResourceAllocator** ppResourceAllocatorOut, IResidencyManager** ppResidencyManagerOut); - static HRESULT CreateResourceAllocator(const ALLOCATOR_DESC& allocatorDescriptor, + static HRESULT CreateResourceAllocator(const RESOURCE_ALLOCATOR_DESC& allocatorDescriptor, ID3D12Device* pDevice, IDXGIAdapter* pAdapter, IResidencyManager* pResidencyManager, @@ -245,7 +246,7 @@ namespace gpgmm::d3d12 { HRESULT SetDebugName(LPCWSTR Name) override; private: - ResourceAllocator(const ALLOCATOR_DESC& descriptor, + ResourceAllocator(const RESOURCE_ALLOCATOR_DESC& descriptor, ID3D12Device* pDevice, ResidencyManager* pResidencyManager); diff --git a/src/samples/D3D12Sample.cpp b/src/samples/D3D12Sample.cpp index 7fc6f8545..feeab849f 100644 --- a/src/samples/D3D12Sample.cpp +++ b/src/samples/D3D12Sample.cpp @@ -56,7 +56,7 @@ HRESULT Init() { return hr; } - gpgmm::d3d12::ALLOCATOR_DESC desc = {}; + gpgmm::d3d12::RESOURCE_ALLOCATOR_DESC desc = {}; desc.ResourceHeapTier = options.ResourceHeapTier; Microsoft::WRL::ComPtr resourceAllocator; diff --git a/src/tests/D3D12Test.cpp b/src/tests/D3D12Test.cpp index 2bc609c1b..4a8c3c182 100644 --- a/src/tests/D3D12Test.cpp +++ b/src/tests/D3D12Test.cpp @@ -126,8 +126,8 @@ namespace gpgmm::d3d12 { GPGMMTestBase::TearDown(); } - ALLOCATOR_DESC D3D12TestBase::CreateBasicAllocatorDesc() const { - ALLOCATOR_DESC desc = {}; + RESOURCE_ALLOCATOR_DESC D3D12TestBase::CreateBasicAllocatorDesc() const { + RESOURCE_ALLOCATOR_DESC desc = {}; desc.ResourceHeapTier = mCaps->GetMaxResourceHeapTierSupported(); desc.MinLogLevel = GetMessageSeverity(GetLogLevel()); @@ -141,8 +141,8 @@ namespace gpgmm::d3d12 { return desc; } - RESIDENCY_DESC D3D12TestBase::CreateBasicResidencyDesc() const { - RESIDENCY_DESC desc = {}; + RESIDENCY_MANAGER_DESC D3D12TestBase::CreateBasicResidencyDesc() const { + RESIDENCY_MANAGER_DESC desc = {}; desc.MinLogLevel = GetMessageSeverity(GetLogLevel()); if (IsDumpEventsEnabled()) { diff --git a/src/tests/D3D12Test.h b/src/tests/D3D12Test.h index 4ffbc39dc..54b7c1b99 100644 --- a/src/tests/D3D12Test.h +++ b/src/tests/D3D12Test.h @@ -33,8 +33,8 @@ namespace gpgmm::d3d12 { - struct ALLOCATOR_DESC; - struct RESIDENCY_DESC; + struct RESOURCE_ALLOCATOR_DESC; + struct RESIDENCY_MANAGER_DESC; class Caps; @@ -52,8 +52,8 @@ namespace gpgmm::d3d12 { void SetUp(); void TearDown(); - RESIDENCY_DESC CreateBasicResidencyDesc() const; - ALLOCATOR_DESC CreateBasicAllocatorDesc() const; + RESIDENCY_MANAGER_DESC CreateBasicResidencyDesc() const; + RESOURCE_ALLOCATOR_DESC CreateBasicAllocatorDesc() const; static D3D12_RESOURCE_DESC CreateBasicBufferDesc(uint64_t width, uint64_t alignment = 0); diff --git a/src/tests/capture_replay_tests/D3D12MemoryTraceReplay.cpp b/src/tests/capture_replay_tests/D3D12MemoryTraceReplay.cpp index e30a4c93b..12469f857 100644 --- a/src/tests/capture_replay_tests/D3D12MemoryTraceReplay.cpp +++ b/src/tests/capture_replay_tests/D3D12MemoryTraceReplay.cpp @@ -86,10 +86,12 @@ namespace { return resourceDesc; } - ALLOCATOR_DESC ConvertAndApplyToAllocatorDesc(const Json::Value& allocatorDescJson, - const ALLOCATOR_DESC& allocatorDesc) { - ALLOCATOR_DESC newAllocatorDesc = allocatorDesc; - newAllocatorDesc.Flags |= static_cast(allocatorDescJson["Flags"].asInt()); + RESOURCE_ALLOCATOR_DESC ConvertAndApplyToAllocatorDesc( + const Json::Value& allocatorDescJson, + const RESOURCE_ALLOCATOR_DESC& allocatorDesc) { + RESOURCE_ALLOCATOR_DESC newAllocatorDesc = allocatorDesc; + newAllocatorDesc.Flags |= + static_cast(allocatorDescJson["Flags"].asInt()); newAllocatorDesc.ResourceHeapTier = static_cast(allocatorDescJson["ResourceHeapTier"].asInt()); newAllocatorDesc.SubAllocationAlgorithm = @@ -106,10 +108,12 @@ namespace { return newAllocatorDesc; } - RESIDENCY_DESC ConvertAndApplyToResidencyDesc(const Json::Value& residencyDescJson, - const RESIDENCY_DESC& residencyDesc) { - RESIDENCY_DESC newResidencyDesc = residencyDesc; - newResidencyDesc.Flags |= static_cast(residencyDescJson["Flags"].asInt()); + RESIDENCY_MANAGER_DESC ConvertAndApplyToResidencyDesc( + const Json::Value& residencyDescJson, + const RESIDENCY_MANAGER_DESC& residencyDesc) { + RESIDENCY_MANAGER_DESC newResidencyDesc = residencyDesc; + newResidencyDesc.Flags |= + static_cast(residencyDescJson["Flags"].asInt()); newResidencyDesc.MaxPctOfVideoMemoryToBudget = residencyDescJson["MaxPctOfVideoMemoryToBudget"].asFloat(); newResidencyDesc.MinPctOfBudgetToReserve = @@ -130,11 +134,12 @@ namespace { return heapProperties; } - HEAP_DESC ConvertAndApplyToHeapDesc(const Json::Value& heapJson, const HEAP_DESC& heapDesc) { - HEAP_DESC newHeapDesc = heapDesc; + RESIDENCY_HEAP_DESC ConvertAndApplyToHeapDesc(const Json::Value& heapJson, + const RESIDENCY_HEAP_DESC& heapDesc) { + RESIDENCY_HEAP_DESC newHeapDesc = heapDesc; newHeapDesc.SizeInBytes = heapJson["SizeInBytes"].asUInt64(); newHeapDesc.Alignment = heapJson["Alignment"].asUInt64(); - newHeapDesc.Flags = static_cast(heapJson["Flags"].asInt()); + newHeapDesc.Flags = static_cast(heapJson["Flags"].asInt()); return newHeapDesc; } @@ -158,12 +163,12 @@ class D3D12MemoryTraceReplay : public D3D12TestBase, public CaptureReplayTestWit using InstanceID = std::string; ComPtr CurrentAllocationWithoutID; - ComPtr CurrentHeapWithoutID; + ComPtr CurrentHeapWithoutID; std::unordered_map> CreatedAllocatorsToID; std::unordered_map> CreatedResidencyManagersToID; std::unordered_map> CreatedAllocationsToID; - std::unordered_map> CreatedHeapsToID; + std::unordered_map> CreatedHeapsToID; InstanceID currentAllocatorID; InstanceID currentResidencyID; @@ -185,7 +190,7 @@ class D3D12MemoryTraceReplay : public D3D12TestBase, public CaptureReplayTestWit const Json::Value& traceEvents = root["traceEvents"]; ASSERT_TRUE(!traceEvents.empty()); - ALLOCATOR_DESC baseAllocatorDesc = CreateBasicAllocatorDesc(); + RESOURCE_ALLOCATOR_DESC baseAllocatorDesc = CreateBasicAllocatorDesc(); // Captures never store recording options, they must be always specified. baseAllocatorDesc.RecordOptions.Flags |= @@ -200,10 +205,10 @@ class D3D12MemoryTraceReplay : public D3D12TestBase, public CaptureReplayTestWit } if (!envParams.IsPrefetchAllowed) { - baseAllocatorDesc.Flags |= ALLOCATOR_FLAG_DISABLE_MEMORY_PREFETCH; + baseAllocatorDesc.Flags |= RESOURCE_ALLOCATOR_FLAG_DISABLE_PREFETCH; } - RESIDENCY_DESC baseResidencyDesc = CreateBasicResidencyDesc(); + RESIDENCY_MANAGER_DESC baseResidencyDesc = CreateBasicResidencyDesc(); baseResidencyDesc.RecordOptions = baseAllocatorDesc.RecordOptions; for (Json::Value::ArrayIndex eventIndex = 0; eventIndex < traceEvents.size(); @@ -309,11 +314,11 @@ class D3D12MemoryTraceReplay : public D3D12TestBase, public CaptureReplayTestWit ASSERT_NE(resourceAllocator, nullptr); if (envParams.IsNeverAllocate) { - allocationDescriptor.Flags |= ALLOCATION_FLAG_NEVER_ALLOCATE_MEMORY; + allocationDescriptor.Flags |= ALLOCATION_FLAG_NEVER_ALLOCATE_HEAP; } if (envParams.IsSuballocationDisabled) { - allocationDescriptor.Flags |= ALLOCATION_FLAG_NEVER_SUBALLOCATE_MEMORY; + allocationDescriptor.Flags |= ALLOCATION_FLAG_NEVER_SUBALLOCATE_HEAP; } HRESULT hr = resourceAllocator->CreateResource( @@ -394,7 +399,7 @@ class D3D12MemoryTraceReplay : public D3D12TestBase, public CaptureReplayTestWit GPGMM_SKIP_TEST_IF(!envParams.IsIgnoreCapsMismatchEnabled); } - RESIDENCY_DESC newResidencyDesc = baseResidencyDesc; + RESIDENCY_MANAGER_DESC newResidencyDesc = baseResidencyDesc; newResidencyDesc = ConvertAndApplyToResidencyDesc(snapshot, newResidencyDesc); @@ -456,7 +461,7 @@ class D3D12MemoryTraceReplay : public D3D12TestBase, public CaptureReplayTestWit GPGMM_SKIP_TEST_IF(!envParams.IsIgnoreCapsMismatchEnabled); } - ALLOCATOR_DESC allocatorDescOfProfile = baseAllocatorDesc; + RESOURCE_ALLOCATOR_DESC allocatorDescOfProfile = baseAllocatorDesc; // Apply profile (if specified). if (envParams.AllocatorProfile == AllocatorProfile::ALLOCATOR_PROFILE_CAPTURED) { @@ -468,7 +473,8 @@ class D3D12MemoryTraceReplay : public D3D12TestBase, public CaptureReplayTestWit allocatorDescOfProfile.ResourceHeapFragmentationLimit = 1.0f; } else if (envParams.AllocatorProfile == AllocatorProfile::ALLOCATOR_PROFILE_LOW_MEMORY) { - allocatorDescOfProfile.Flags |= ALLOCATOR_FLAG_ALWAYS_ON_DEMAND; + allocatorDescOfProfile.Flags |= + RESOURCE_ALLOCATOR_FLAG_ALWAYS_ON_DEMAND; allocatorDescOfProfile.ResourceHeapFragmentationLimit = 0.125; // 1/8th of 4MB } @@ -511,7 +517,7 @@ class D3D12MemoryTraceReplay : public D3D12TestBase, public CaptureReplayTestWit default: break; } - } else if (event["name"].asString() == "Heap.CreateHeap") { + } else if (event["name"].asString() == "Heap.CreateResidencyHeap") { switch (*event["ph"].asCString()) { case TRACE_EVENT_PHASE_INSTANT: { const Json::Value& args = event["args"]; @@ -529,7 +535,7 @@ class D3D12MemoryTraceReplay : public D3D12TestBase, public CaptureReplayTestWit const D3D12_HEAP_PROPERTIES heapProperties = ConvertToD3D12HeapProperties(args["Heap"]["Properties"]); - HEAP_DESC resourceHeapDesc = {}; + RESIDENCY_HEAP_DESC resourceHeapDesc = {}; resourceHeapDesc.HeapSegment = GetHeapSegment( heapProperties.MemoryPoolPreference, mCaps->IsAdapterUMA()); resourceHeapDesc = @@ -553,10 +559,11 @@ class D3D12MemoryTraceReplay : public D3D12TestBase, public CaptureReplayTestWit CreateResourceHeapCallbackContext createHeapContext(mDevice.Get(), &heapDesc); - ComPtr resourceHeap; - ASSERT_SUCCEEDED(CreateHeap(resourceHeapDesc, residencyManager, - CreateResourceHeapCallbackContext::CreateHeap, - &createHeapContext, &resourceHeap)); + ComPtr resourceHeap; + ASSERT_SUCCEEDED( + CreateResidencyHeap(resourceHeapDesc, residencyManager, + CreateResourceHeapCallbackContext::CreateHeap, + &createHeapContext, &resourceHeap)); playbackContext.CurrentHeapWithoutID = std::move(resourceHeap); @@ -569,7 +576,7 @@ class D3D12MemoryTraceReplay : public D3D12TestBase, public CaptureReplayTestWit default: break; } - } else if (event["name"].asString() == "IHeap") { + } else if (event["name"].asString() == "IResidencyHeap") { switch (*event["ph"].asCString()) { case TRACE_EVENT_PHASE_CREATE_OBJECT: { if (playbackContext.CurrentHeapWithoutID == nullptr) { @@ -592,7 +599,7 @@ class D3D12MemoryTraceReplay : public D3D12TestBase, public CaptureReplayTestWit continue; } - IHeap* heap = it->second.Get(); + IResidencyHeap* heap = it->second.Get(); ASSERT_NE(heap, nullptr); mCapturedMemoryStats.CurrentUsage -= heap->GetInfo().SizeInBytes; diff --git a/src/tests/end2end/D3D12ResidencyManagerTests.cpp b/src/tests/end2end/D3D12ResidencyManagerTests.cpp index d00c7c35d..b25109f24 100644 --- a/src/tests/end2end/D3D12ResidencyManagerTests.cpp +++ b/src/tests/end2end/D3D12ResidencyManagerTests.cpp @@ -39,14 +39,14 @@ class D3D12ResidencyManagerTests : public D3D12TestBase, public ::testing::Test // Configures allocator for testing residency in a controlled and predictable // fashion. - ALLOCATOR_DESC CreateBasicAllocatorDesc() const { - ALLOCATOR_DESC desc = D3D12TestBase::CreateBasicAllocatorDesc(); + RESOURCE_ALLOCATOR_DESC CreateBasicAllocatorDesc() const { + RESOURCE_ALLOCATOR_DESC desc = D3D12TestBase::CreateBasicAllocatorDesc(); // Disable pre-fetching since it will could cause over-committment unpredictably. - desc.Flags |= gpgmm::d3d12::ALLOCATOR_FLAG_DISABLE_MEMORY_PREFETCH; + desc.Flags |= gpgmm::d3d12::RESOURCE_ALLOCATOR_FLAG_DISABLE_PREFETCH; // Require MakeResident/Evict occur near CreateResource, for debugging purposes. - desc.Flags |= gpgmm::d3d12::ALLOCATOR_FLAG_ALWAYS_IN_BUDGET; + desc.Flags |= gpgmm::d3d12::RESOURCE_ALLOCATOR_FLAG_ALWAYS_IN_BUDGET; // Disable memory growth so older heap being paged out are the same size as newer heaps // being paged-in, and the test expectation based on these sizes is easy to determine. @@ -57,8 +57,8 @@ class D3D12ResidencyManagerTests : public D3D12TestBase, public ::testing::Test // Configures residency manager for testing residency in a controlled and predictable // fashion. - RESIDENCY_DESC CreateBasicResidencyDesc(uint64_t budget) const { - RESIDENCY_DESC residencyDesc = D3D12TestBase::CreateBasicResidencyDesc(); + RESIDENCY_MANAGER_DESC CreateBasicResidencyDesc(uint64_t budget) const { + RESIDENCY_MANAGER_DESC residencyDesc = D3D12TestBase::CreateBasicResidencyDesc(); // Disable automatic budget updates, since it occurs uncontrollably by the OS. residencyDesc.Flags |= RESIDENCY_FLAG_DISABLE_BUDGET_UPDATES_ON_WORKER_THREAD; @@ -84,7 +84,7 @@ class D3D12ResidencyManagerTests : public D3D12TestBase, public ::testing::Test bool IsResident(IResourceAllocation* pAllocation) const { ASSERT(pAllocation != nullptr); - return pAllocation->GetMemory()->GetInfo().Status == RESIDENCY_STATUS_CURRENT_RESIDENT; + return pAllocation->GetMemory()->GetInfo().Status == RESIDENCY_HEAP_STATUS_CURRENT; } class CreateDescHeapCallbackContext { @@ -92,14 +92,14 @@ class D3D12ResidencyManagerTests : public D3D12TestBase, public ::testing::Test CreateDescHeapCallbackContext(ID3D12Device* device, D3D12_DESCRIPTOR_HEAP_DESC descHeapDesc) : mDevice(device), mDescHeapDesc(descHeapDesc) { } - static HRESULT CreateHeap(void* pContext, ID3D12Pageable** ppPageableOut) { + static HRESULT CreateResidencyHeap(void* pContext, ID3D12Pageable** ppPageableOut) { CreateDescHeapCallbackContext* createDescHeapCallbackContext = static_cast(pContext); - return createDescHeapCallbackContext->CreateHeap(ppPageableOut); + return createDescHeapCallbackContext->CreateResidencyHeap(ppPageableOut); } private: - HRESULT CreateHeap(ID3D12Pageable** ppPageableOut) { + HRESULT CreateResidencyHeap(ID3D12Pageable** ppPageableOut) { ComPtr heap; if (FAILED(mDevice->CreateDescriptorHeap(&mDescHeapDesc, IID_PPV_ARGS(&heap)))) { return E_FAIL; @@ -141,10 +141,10 @@ TEST_F(D3D12ResidencyManagerTests, CreateResourceHeapNotResident) { D3D12_HEAP_PROPERTIES heapProperties = {}; heapProperties.Type = D3D12_HEAP_TYPE_DEFAULT; - HEAP_DESC resourceHeapAlwaysInBudgetDesc = {}; + RESIDENCY_HEAP_DESC resourceHeapAlwaysInBudgetDesc = {}; resourceHeapAlwaysInBudgetDesc.SizeInBytes = kHeapSize; resourceHeapAlwaysInBudgetDesc.HeapSegment = DXGI_MEMORY_SEGMENT_GROUP_LOCAL; - resourceHeapAlwaysInBudgetDesc.Flags |= HEAP_FLAG_ALWAYS_IN_BUDGET; + resourceHeapAlwaysInBudgetDesc.Flags |= RESIDENCY_HEAP_FLAG_ALWAYS_IN_BUDGET; D3D12_HEAP_DESC heapDesc = {}; heapDesc.Properties = heapProperties; @@ -154,9 +154,9 @@ TEST_F(D3D12ResidencyManagerTests, CreateResourceHeapNotResident) { CreateResourceHeapCallbackContext createHeapContext(mDevice.Get(), &heapDesc); - ASSERT_SUCCEEDED(CreateHeap(resourceHeapAlwaysInBudgetDesc, residencyManager.Get(), - CreateResourceHeapCallbackContext::CreateHeap, &createHeapContext, - nullptr)); + ASSERT_SUCCEEDED(CreateResidencyHeap(resourceHeapAlwaysInBudgetDesc, residencyManager.Get(), + CreateResourceHeapCallbackContext::CreateHeap, + &createHeapContext, nullptr)); } TEST_F(D3D12ResidencyManagerTests, CreateResourceHeap) { @@ -179,37 +179,37 @@ TEST_F(D3D12ResidencyManagerTests, CreateResourceHeap) { CreateResourceHeapCallbackContext createHeapContext(mDevice.Get(), &heapDesc); BadCreateHeapCallbackContext badCreateHeapCallbackContext; - HEAP_DESC resourceHeapDesc = {}; + RESIDENCY_HEAP_DESC resourceHeapDesc = {}; resourceHeapDesc.SizeInBytes = kHeapSize; resourceHeapDesc.HeapSegment = DXGI_MEMORY_SEGMENT_GROUP_LOCAL; - ASSERT_FAILED(CreateHeap(resourceHeapDesc, residencyManager.Get(), - BadCreateHeapCallbackContext::CreateHeap, - &badCreateHeapCallbackContext, nullptr)); + ASSERT_FAILED(CreateResidencyHeap(resourceHeapDesc, residencyManager.Get(), + BadCreateHeapCallbackContext::CreateHeap, + &badCreateHeapCallbackContext, nullptr)); - ASSERT_SUCCEEDED(CreateHeap(resourceHeapDesc, residencyManager.Get(), - CreateResourceHeapCallbackContext::CreateHeap, &createHeapContext, - nullptr)); + ASSERT_SUCCEEDED(CreateResidencyHeap(resourceHeapDesc, residencyManager.Get(), + CreateResourceHeapCallbackContext::CreateHeap, + &createHeapContext, nullptr)); // Create a resource heap without residency. - ComPtr resourceHeap; - ASSERT_SUCCEEDED(CreateHeap(resourceHeapDesc, nullptr, - CreateResourceHeapCallbackContext::CreateHeap, &createHeapContext, - &resourceHeap)); + ComPtr resourceHeap; + ASSERT_SUCCEEDED(CreateResidencyHeap(resourceHeapDesc, nullptr, + CreateResourceHeapCallbackContext::CreateHeap, + &createHeapContext, &resourceHeap)); // Ensure the unmanaged resource heap state is always unknown. Even though D3D12 implicitly // creates heaps as resident, untrack resource heaps would never transition out from - // RESIDENCY_STATUS_CURRENT_RESIDENT and must be left RESIDENCY_STATUS_UNKNOWN. - EXPECT_EQ(resourceHeap->GetInfo().Status, gpgmm::d3d12::RESIDENCY_STATUS_UNKNOWN); + // RESIDENCY_HEAP_STATUS_CURRENT and must be left RESIDENCY_HEAP_STATUS_UNKNOWN. + EXPECT_EQ(resourceHeap->GetInfo().Status, gpgmm::d3d12::RESIDENCY_HEAP_STATUS_UNKNOWN); EXPECT_EQ(resourceHeap->GetInfo().IsLocked, false); // Create a resource heap with residency. - ASSERT_SUCCEEDED(CreateHeap(resourceHeapDesc, residencyManager.Get(), - CreateResourceHeapCallbackContext::CreateHeap, &createHeapContext, - &resourceHeap)); + ASSERT_SUCCEEDED(CreateResidencyHeap(resourceHeapDesc, residencyManager.Get(), + CreateResourceHeapCallbackContext::CreateHeap, + &createHeapContext, &resourceHeap)); ASSERT_NE(resourceHeap, nullptr); - EXPECT_EQ(resourceHeap->GetInfo().Status, gpgmm::d3d12::RESIDENCY_STATUS_CURRENT_RESIDENT); + EXPECT_EQ(resourceHeap->GetInfo().Status, gpgmm::d3d12::RESIDENCY_HEAP_STATUS_CURRENT); EXPECT_EQ(resourceHeap->GetInfo().IsLocked, false); // Residency status of resource heap types is always known. @@ -222,7 +222,7 @@ TEST_F(D3D12ResidencyManagerTests, CreateResourceHeap) { ASSERT_SUCCEEDED(residencyManager->LockHeap(resourceHeap.Get())); - EXPECT_EQ(resourceHeap->GetInfo().Status, gpgmm::d3d12::RESIDENCY_STATUS_CURRENT_RESIDENT); + EXPECT_EQ(resourceHeap->GetInfo().Status, gpgmm::d3d12::RESIDENCY_HEAP_STATUS_CURRENT); EXPECT_EQ(resourceHeap->GetInfo().IsLocked, true); EXPECT_EQ(GetStats(residencyManager).CurrentHeapUsage, resourceHeapDesc.SizeInBytes); @@ -230,7 +230,7 @@ TEST_F(D3D12ResidencyManagerTests, CreateResourceHeap) { ASSERT_SUCCEEDED(residencyManager->UnlockHeap(resourceHeap.Get())); - EXPECT_EQ(resourceHeap->GetInfo().Status, gpgmm::d3d12::RESIDENCY_STATUS_CURRENT_RESIDENT); + EXPECT_EQ(resourceHeap->GetInfo().Status, gpgmm::d3d12::RESIDENCY_HEAP_STATUS_CURRENT); EXPECT_EQ(resourceHeap->GetInfo().IsLocked, false); // Unlocking a heap does not evict it, the memory usage should not change. @@ -250,19 +250,19 @@ TEST_F(D3D12ResidencyManagerTests, CreateDescriptorHeap) { heapDesc.NumDescriptors = 1; heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE; - HEAP_DESC descriptorHeapDesc = {}; + RESIDENCY_HEAP_DESC descriptorHeapDesc = {}; descriptorHeapDesc.SizeInBytes = heapDesc.NumDescriptors * mDevice->GetDescriptorHandleIncrementSize(heapDesc.Type); descriptorHeapDesc.HeapSegment = DXGI_MEMORY_SEGMENT_GROUP_LOCAL; CreateDescHeapCallbackContext createDescHeapCallbackContext(mDevice.Get(), heapDesc); - ComPtr descriptorHeap; - ASSERT_SUCCEEDED(CreateHeap(descriptorHeapDesc, residencyManager.Get(), - CreateDescHeapCallbackContext::CreateHeap, - &createDescHeapCallbackContext, &descriptorHeap)); + ComPtr descriptorHeap; + ASSERT_SUCCEEDED(CreateResidencyHeap(descriptorHeapDesc, residencyManager.Get(), + CreateDescHeapCallbackContext::CreateResidencyHeap, + &createDescHeapCallbackContext, &descriptorHeap)); - EXPECT_EQ(descriptorHeap->GetInfo().Status, gpgmm::d3d12::RESIDENCY_STATUS_UNKNOWN); + EXPECT_EQ(descriptorHeap->GetInfo().Status, gpgmm::d3d12::RESIDENCY_HEAP_STATUS_UNKNOWN); EXPECT_EQ(descriptorHeap->GetInfo().IsLocked, false); ComPtr heap; @@ -276,7 +276,7 @@ TEST_F(D3D12ResidencyManagerTests, CreateDescriptorHeap) { ASSERT_SUCCEEDED(residencyManager->LockHeap(descriptorHeap.Get())); - EXPECT_EQ(descriptorHeap->GetInfo().Status, gpgmm::d3d12::RESIDENCY_STATUS_CURRENT_RESIDENT); + EXPECT_EQ(descriptorHeap->GetInfo().Status, gpgmm::d3d12::RESIDENCY_HEAP_STATUS_CURRENT); EXPECT_EQ(descriptorHeap->GetInfo().IsLocked, true); EXPECT_EQ(GetStats(residencyManager).CurrentHeapUsage, descriptorHeapDesc.SizeInBytes); @@ -284,7 +284,7 @@ TEST_F(D3D12ResidencyManagerTests, CreateDescriptorHeap) { ASSERT_SUCCEEDED(residencyManager->UnlockHeap(descriptorHeap.Get())); - EXPECT_EQ(descriptorHeap->GetInfo().Status, gpgmm::d3d12::RESIDENCY_STATUS_CURRENT_RESIDENT); + EXPECT_EQ(descriptorHeap->GetInfo().Status, gpgmm::d3d12::RESIDENCY_HEAP_STATUS_CURRENT); EXPECT_EQ(descriptorHeap->GetInfo().IsLocked, false); // Unlocking a heap does not evict it, the memory usage should not change. @@ -304,20 +304,20 @@ TEST_F(D3D12ResidencyManagerTests, CreateDescriptorHeapAlwaysResident) { heapDesc.NumDescriptors = 1; heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE; - HEAP_DESC descriptorHeapDesc = {}; + RESIDENCY_HEAP_DESC descriptorHeapDesc = {}; descriptorHeapDesc.SizeInBytes = heapDesc.NumDescriptors * mDevice->GetDescriptorHandleIncrementSize(heapDesc.Type); descriptorHeapDesc.HeapSegment = DXGI_MEMORY_SEGMENT_GROUP_LOCAL; - descriptorHeapDesc.Flags |= HEAP_FLAG_ALWAYS_IN_RESIDENCY; + descriptorHeapDesc.Flags |= RESIDENCY_HEAP_FLAG_ALWAYS_RESIDENT; CreateDescHeapCallbackContext createDescHeapCallbackContext(mDevice.Get(), heapDesc); - ComPtr descriptorHeap; - ASSERT_SUCCEEDED(CreateHeap(descriptorHeapDesc, residencyManager.Get(), - CreateDescHeapCallbackContext::CreateHeap, - &createDescHeapCallbackContext, &descriptorHeap)); + ComPtr descriptorHeap; + ASSERT_SUCCEEDED(CreateResidencyHeap(descriptorHeapDesc, residencyManager.Get(), + CreateDescHeapCallbackContext::CreateResidencyHeap, + &createDescHeapCallbackContext, &descriptorHeap)); - EXPECT_EQ(descriptorHeap->GetInfo().Status, gpgmm::d3d12::RESIDENCY_STATUS_CURRENT_RESIDENT); + EXPECT_EQ(descriptorHeap->GetInfo().Status, gpgmm::d3d12::RESIDENCY_HEAP_STATUS_CURRENT); EXPECT_EQ(descriptorHeap->GetInfo().IsLocked, false); } @@ -338,7 +338,7 @@ TEST_F(D3D12ResidencyManagerTests, CreateResidencyList) { { ComPtr list; ASSERT_SUCCEEDED(CreateResidencyList(&list)); - IHeap* invalid = nullptr; + IResidencyHeap* invalid = nullptr; ASSERT_FAILED(list->Add(invalid)); } @@ -398,7 +398,7 @@ TEST_F(D3D12ResidencyManagerTests, CreateResidencyManager) { // Create allocator with residency, seperately, but no adapter should fail. { - ALLOCATOR_DESC allocatorDesc = CreateBasicAllocatorDesc(); + RESOURCE_ALLOCATOR_DESC allocatorDesc = CreateBasicAllocatorDesc(); ComPtr residencyManager; ComPtr resourceAllocator; @@ -463,7 +463,7 @@ TEST_F(D3D12ResidencyManagerTests, CreateResidencyManagerNoLeak) { // Keeps allocating until it reaches the restricted budget then over-commits to ensure older heaps // will evicted. TEST_F(D3D12ResidencyManagerTests, OverBudget) { - RESIDENCY_DESC residencyDesc = CreateBasicResidencyDesc(kDefaultBudget); + RESIDENCY_MANAGER_DESC residencyDesc = CreateBasicResidencyDesc(kDefaultBudget); ComPtr residencyManager; ASSERT_SUCCEEDED( @@ -528,7 +528,7 @@ TEST_F(D3D12ResidencyManagerTests, OverBudget) { // Keeps allocating until it goes over the OS provided budget. TEST_F(D3D12ResidencyManagerTests, OverBudgetAsync) { constexpr uint64_t kBudgetIsDeterminedByOS = 0; - RESIDENCY_DESC residencyDesc = CreateBasicResidencyDesc(kBudgetIsDeterminedByOS); + RESIDENCY_MANAGER_DESC residencyDesc = CreateBasicResidencyDesc(kBudgetIsDeterminedByOS); residencyDesc.Flags ^= RESIDENCY_FLAG_DISABLE_BUDGET_UPDATES_ON_WORKER_THREAD; ComPtr residencyManager; @@ -572,13 +572,13 @@ TEST_F(D3D12ResidencyManagerTests, OverBudgetAsync) { // Keeps allocating until it reaches the restricted budget then over-commits to ensure new heaps // will not keep increasing in size. TEST_F(D3D12ResidencyManagerTests, OverBudgetDisablesGrowth) { - RESIDENCY_DESC residencyDesc = CreateBasicResidencyDesc(kDefaultBudget); + RESIDENCY_MANAGER_DESC residencyDesc = CreateBasicResidencyDesc(kDefaultBudget); ComPtr residencyManager; ASSERT_SUCCEEDED( CreateResidencyManager(residencyDesc, mDevice.Get(), mAdapter.Get(), &residencyManager)); - ALLOCATOR_DESC allocatorDesc = CreateBasicAllocatorDesc(); + RESOURCE_ALLOCATOR_DESC allocatorDesc = CreateBasicAllocatorDesc(); allocatorDesc.ResourceHeapGrowthFactor = 2; ComPtr resourceAllocator; @@ -587,7 +587,7 @@ TEST_F(D3D12ResidencyManagerTests, OverBudgetDisablesGrowth) { &resourceAllocator)); std::vector> allocations = {}; - std::vector resourceHeaps = {}; + std::vector resourceHeaps = {}; constexpr uint64_t kBufferMemorySize = GPGMM_MB_TO_BYTES(1); const D3D12_RESOURCE_DESC bufferDesc = CreateBasicBufferDesc(kBufferMemorySize); @@ -619,7 +619,7 @@ TEST_F(D3D12ResidencyManagerTests, OverBudgetDisablesGrowth) { // Keeps allocating until it reaches the restricted budget then over-commits to ensure locked heaps // will never be evicted. TEST_F(D3D12ResidencyManagerTests, OverBudgetWithLockedHeaps) { - RESIDENCY_DESC residencyDesc = CreateBasicResidencyDesc(kDefaultBudget); + RESIDENCY_MANAGER_DESC residencyDesc = CreateBasicResidencyDesc(kDefaultBudget); ComPtr residencyManager; ASSERT_SUCCEEDED( @@ -659,8 +659,8 @@ TEST_F(D3D12ResidencyManagerTests, OverBudgetWithLockedHeaps) { return; } - // Since locked heaps are ineligable for eviction and HEAP_FLAG_ALWAYS_IN_BUDGET is true, - // CreateResource should always fail since there is not enough budget. + // Since locked heaps are ineligable for eviction and RESIDENCY_HEAP_FLAG_ALWAYS_IN_BUDGET is + // true, CreateResource should always fail since there is not enough budget. ASSERT_FAILED(resourceAllocator->CreateResource(bufferAllocationDesc, bufferDesc, D3D12_RESOURCE_STATE_COMMON, nullptr, nullptr)); @@ -695,7 +695,7 @@ TEST_F(D3D12ResidencyManagerTests, OverBudgetExecuteCommandList) { ComPtr allocation; ASSERT_SUCCEEDED(resourceAllocator->CreateResource( {}, bufferDesc, D3D12_RESOURCE_STATE_COMMON, nullptr, &allocation)); - EXPECT_EQ(allocation->GetMemory()->GetInfo().Status, RESIDENCY_STATUS_CURRENT_RESIDENT); + EXPECT_EQ(allocation->GetMemory()->GetInfo().Status, RESIDENCY_HEAP_STATUS_CURRENT); firstSetOfHeaps.push_back(std::move(allocation)); } @@ -705,7 +705,7 @@ TEST_F(D3D12ResidencyManagerTests, OverBudgetExecuteCommandList) { ComPtr allocation; ASSERT_SUCCEEDED(resourceAllocator->CreateResource( {}, bufferDesc, D3D12_RESOURCE_STATE_COMMON, nullptr, &allocation)); - EXPECT_EQ(allocation->GetMemory()->GetInfo().Status, RESIDENCY_STATUS_CURRENT_RESIDENT); + EXPECT_EQ(allocation->GetMemory()->GetInfo().Status, RESIDENCY_HEAP_STATUS_CURRENT); secondSetOfHeaps.push_back(std::move(allocation)); } @@ -745,12 +745,12 @@ TEST_F(D3D12ResidencyManagerTests, OverBudgetExecuteCommandList) { // Everything below the budget should now be resident. for (auto& allocation : firstSetOfHeaps) { - EXPECT_EQ(allocation->GetMemory()->GetInfo().Status, RESIDENCY_STATUS_CURRENT_RESIDENT); + EXPECT_EQ(allocation->GetMemory()->GetInfo().Status, RESIDENCY_HEAP_STATUS_CURRENT); } // Everything above the budget should now be evicted. for (auto& allocation : secondSetOfHeaps) { - EXPECT_EQ(allocation->GetMemory()->GetInfo().Status, RESIDENCY_STATUS_PENDING_RESIDENCY); + EXPECT_EQ(allocation->GetMemory()->GetInfo().Status, RESIDENCY_HEAP_STATUS_PENDING); } // Page-in the second set of heaps using ExecuteCommandLists (and page-out the first set). @@ -770,17 +770,17 @@ TEST_F(D3D12ResidencyManagerTests, OverBudgetExecuteCommandList) { // Everything below the budget should now be evicted. for (auto& allocation : firstSetOfHeaps) { - EXPECT_EQ(allocation->GetMemory()->GetInfo().Status, RESIDENCY_STATUS_PENDING_RESIDENCY); + EXPECT_EQ(allocation->GetMemory()->GetInfo().Status, RESIDENCY_HEAP_STATUS_PENDING); } // Everything above the budget should now be resident. for (auto& allocation : secondSetOfHeaps) { - EXPECT_EQ(allocation->GetMemory()->GetInfo().Status, RESIDENCY_STATUS_CURRENT_RESIDENT); + EXPECT_EQ(allocation->GetMemory()->GetInfo().Status, RESIDENCY_HEAP_STATUS_CURRENT); } } TEST_F(D3D12ResidencyManagerTests, OverBudgetImported) { - RESIDENCY_DESC residencyDesc = CreateBasicResidencyDesc(kDefaultBudget); + RESIDENCY_MANAGER_DESC residencyDesc = CreateBasicResidencyDesc(kDefaultBudget); ComPtr residencyManager; ASSERT_SUCCEEDED( diff --git a/src/tests/end2end/D3D12ResourceAllocatorTests.cpp b/src/tests/end2end/D3D12ResourceAllocatorTests.cpp index 1d32d44cf..f8f7f366e 100644 --- a/src/tests/end2end/D3D12ResourceAllocatorTests.cpp +++ b/src/tests/end2end/D3D12ResourceAllocatorTests.cpp @@ -62,15 +62,15 @@ class D3D12ResourceAllocatorTests : public D3D12TestBase, public ::testing::Test // Configures allocator for testing allocation in a controlled and predictable // fashion. - ALLOCATOR_DESC CreateBasicAllocatorDesc() const { - ALLOCATOR_DESC desc = D3D12TestBase::CreateBasicAllocatorDesc(); + RESOURCE_ALLOCATOR_DESC CreateBasicAllocatorDesc() const { + RESOURCE_ALLOCATOR_DESC desc = D3D12TestBase::CreateBasicAllocatorDesc(); // Pre-fetching is enabled by default. However for testing purposes, pre-fetching changes // expectations that check GPU memory usage and needs to be tested in isolation. - desc.Flags |= ALLOCATOR_FLAG_DISABLE_MEMORY_PREFETCH; + desc.Flags |= RESOURCE_ALLOCATOR_FLAG_DISABLE_PREFETCH; // Make sure leak detection is always enabled. - desc.Flags |= gpgmm::d3d12::ALLOCATOR_FLAG_NEVER_LEAK_MEMORY; + desc.Flags |= gpgmm::d3d12::RESOURCE_ALLOCATOR_FLAG_NEVER_LEAK; return desc; } @@ -100,7 +100,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateResourceAllocator) { // Creating an allocator without a device should always fail. { - ALLOCATOR_DESC desc = CreateBasicAllocatorDesc(); + RESOURCE_ALLOCATOR_DESC desc = CreateBasicAllocatorDesc(); ComPtr resourceAllocator; EXPECT_FAILED( @@ -119,7 +119,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateResourceAllocator) { // Creating an allocator with the wrong resource heap tier should always fail. { // Tier 3 doesn't exist in D3D12. - ALLOCATOR_DESC desc = CreateBasicAllocatorDesc(); + RESOURCE_ALLOCATOR_DESC desc = CreateBasicAllocatorDesc(); desc.ResourceHeapTier = static_cast(D3D12_RESOURCE_HEAP_TIER_2 + 1); @@ -149,7 +149,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateResourceAllocator) { // Creating a new allocator with a preferred resource heap size larger then the max resource // heap size should always fail. { - ALLOCATOR_DESC desc = CreateBasicAllocatorDesc(); + RESOURCE_ALLOCATOR_DESC desc = CreateBasicAllocatorDesc(); desc.PreferredResourceHeapSize = kBufferOf4MBAllocationSize; desc.MaxResourceHeapSize = kBufferOf4MBAllocationSize / 2; @@ -190,7 +190,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferNoLeak) { // Exceeding the max resource heap size should always fail. TEST_F(D3D12ResourceAllocatorTests, CreateBufferAndTextureInSameHeap) { - ALLOCATOR_DESC allocatorDesc = CreateBasicAllocatorDesc(); + RESOURCE_ALLOCATOR_DESC allocatorDesc = CreateBasicAllocatorDesc(); // Heaps of only the same size can be reused between resource types. allocatorDesc.PreferredResourceHeapSize = kBufferOf4MBAllocationSize; @@ -225,7 +225,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferAndTextureInSameHeap) { // Exceeding the max resource heap size should always fail. TEST_F(D3D12ResourceAllocatorTests, CreateBufferAndTextureInSeperateHeap) { - ALLOCATOR_DESC allocatorDesc = CreateBasicAllocatorDesc(); + RESOURCE_ALLOCATOR_DESC allocatorDesc = CreateBasicAllocatorDesc(); allocatorDesc.ResourceHeapTier = D3D12_RESOURCE_HEAP_TIER_1; // Heaps of only the same size can be reused between resource types. @@ -281,7 +281,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferOversized) { } TEST_F(D3D12ResourceAllocatorTests, CreateBufferSubAllocated) { - ALLOCATOR_DESC allocatorDesc = CreateBasicAllocatorDesc(); + RESOURCE_ALLOCATOR_DESC allocatorDesc = CreateBasicAllocatorDesc(); // Ensure the underlying memory size is large enough so all buffer allocation can fit. allocatorDesc.PreferredResourceHeapSize = GPGMM_MB_TO_BYTES(64); @@ -292,7 +292,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferSubAllocated) { // ALLOCATOR_ALGORITHM_BUDDY_SYSTEM { - ALLOCATOR_DESC newAllocatorDesc = allocatorDesc; + RESOURCE_ALLOCATOR_DESC newAllocatorDesc = allocatorDesc; newAllocatorDesc.SubAllocationAlgorithm = ALLOCATOR_ALGORITHM_BUDDY_SYSTEM; ComPtr resourceAllocator; @@ -311,7 +311,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferSubAllocated) { // ALLOCATOR_ALGORITHM_BUDDY_SYSTEM + ALLOCATOR_ALGORITHM_FIXED_POOL { - ALLOCATOR_DESC newAllocatorDesc = allocatorDesc; + RESOURCE_ALLOCATOR_DESC newAllocatorDesc = allocatorDesc; newAllocatorDesc.SubAllocationAlgorithm = ALLOCATOR_ALGORITHM_BUDDY_SYSTEM; newAllocatorDesc.PoolAlgorithm = ALLOCATOR_ALGORITHM_FIXED_POOL; @@ -331,7 +331,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferSubAllocated) { // ALLOCATOR_ALGORITHM_BUDDY_SYSTEM + ALLOCATOR_ALGORITHM_SEGMENTED_POOL { - ALLOCATOR_DESC newAllocatorDesc = allocatorDesc; + RESOURCE_ALLOCATOR_DESC newAllocatorDesc = allocatorDesc; newAllocatorDesc.SubAllocationAlgorithm = ALLOCATOR_ALGORITHM_BUDDY_SYSTEM; newAllocatorDesc.PoolAlgorithm = ALLOCATOR_ALGORITHM_SEGMENTED_POOL; @@ -351,7 +351,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferSubAllocated) { // ALLOCATOR_ALGORITHM_SLAB { - ALLOCATOR_DESC newAllocatorDesc = allocatorDesc; + RESOURCE_ALLOCATOR_DESC newAllocatorDesc = allocatorDesc; newAllocatorDesc.SubAllocationAlgorithm = ALLOCATOR_ALGORITHM_SLAB; ComPtr resourceAllocator; @@ -370,7 +370,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferSubAllocated) { // ALLOCATOR_ALGORITHM_SLAB + ALLOCATOR_ALGORITHM_FIXED_POOL { - ALLOCATOR_DESC newAllocatorDesc = allocatorDesc; + RESOURCE_ALLOCATOR_DESC newAllocatorDesc = allocatorDesc; newAllocatorDesc.SubAllocationAlgorithm = ALLOCATOR_ALGORITHM_SLAB; newAllocatorDesc.PoolAlgorithm = ALLOCATOR_ALGORITHM_FIXED_POOL; @@ -390,7 +390,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferSubAllocated) { // ALLOCATOR_ALGORITHM_SLAB + ALLOCATOR_ALGORITHM_SEGMENTED_POOL { - ALLOCATOR_DESC newAllocatorDesc = allocatorDesc; + RESOURCE_ALLOCATOR_DESC newAllocatorDesc = allocatorDesc; newAllocatorDesc.SubAllocationAlgorithm = ALLOCATOR_ALGORITHM_SLAB; newAllocatorDesc.PoolAlgorithm = ALLOCATOR_ALGORITHM_SEGMENTED_POOL; @@ -410,8 +410,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferSubAllocated) { // No sub-allocation algorithm. { - ALLOCATOR_DESC newAllocatorDesc = allocatorDesc; - newAllocatorDesc.Flags |= ALLOCATOR_FLAG_ALWAYS_COMMITTED; + RESOURCE_ALLOCATOR_DESC newAllocatorDesc = allocatorDesc; + newAllocatorDesc.Flags |= RESOURCE_ALLOCATOR_FLAG_ALWAYS_COMMITTED; ComPtr resourceAllocator; ASSERT_SUCCEEDED(CreateResourceAllocator(newAllocatorDesc, mDevice.Get(), mAdapter.Get(), @@ -429,7 +429,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferSubAllocated) { // ALLOCATOR_ALGORITHM_DEDICATED { - ALLOCATOR_DESC newAllocatorDesc = allocatorDesc; + RESOURCE_ALLOCATOR_DESC newAllocatorDesc = allocatorDesc; newAllocatorDesc.SubAllocationAlgorithm = ALLOCATOR_ALGORITHM_DEDICATED; ComPtr resourceAllocator; @@ -448,11 +448,11 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferSubAllocated) { } TEST_F(D3D12ResourceAllocatorTests, CreateBufferWithPreferredHeapSize) { - ALLOCATOR_DESC allocatorDesc = CreateBasicAllocatorDesc(); + RESOURCE_ALLOCATOR_DESC allocatorDesc = CreateBasicAllocatorDesc(); // ALLOCATOR_ALGORITHM_SLAB { - ALLOCATOR_DESC newAllocatorDesc = allocatorDesc; + RESOURCE_ALLOCATOR_DESC newAllocatorDesc = allocatorDesc; newAllocatorDesc.SubAllocationAlgorithm = ALLOCATOR_ALGORITHM_SLAB; newAllocatorDesc.PreferredResourceHeapSize = GPGMM_MB_TO_BYTES(12); @@ -472,7 +472,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferWithPreferredHeapSize) { // ALLOCATOR_ALGORITHM_BUDDY_SYSTEM { - ALLOCATOR_DESC newAllocatorDesc = allocatorDesc; + RESOURCE_ALLOCATOR_DESC newAllocatorDesc = allocatorDesc; newAllocatorDesc.SubAllocationAlgorithm = ALLOCATOR_ALGORITHM_BUDDY_SYSTEM; newAllocatorDesc.PreferredResourceHeapSize = GPGMM_MB_TO_BYTES(12); @@ -492,7 +492,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferWithPreferredHeapSize) { // ALLOCATOR_ALGORITHM_DEDICATED { - ALLOCATOR_DESC newAllocatorDesc = allocatorDesc; + RESOURCE_ALLOCATOR_DESC newAllocatorDesc = allocatorDesc; newAllocatorDesc.SubAllocationAlgorithm = ALLOCATOR_ALGORITHM_DEDICATED; newAllocatorDesc.PreferredResourceHeapSize = GPGMM_MB_TO_BYTES(12); @@ -637,7 +637,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBuffer) { D3D12_RESOURCE_STATE_COMMON, nullptr, &allocation)); ASSERT_NE(allocation, nullptr); - ComPtr heap = allocation->GetMemory(); + ComPtr heap = allocation->GetMemory(); ASSERT_NE(heap, nullptr); ComPtr d3dHeap; @@ -695,7 +695,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBuffer) { // Create a buffer that exceeds the max size should always fail. { - ALLOCATOR_DESC allocatorDesc = CreateBasicAllocatorDesc(); + RESOURCE_ALLOCATOR_DESC allocatorDesc = CreateBasicAllocatorDesc(); allocatorDesc.MaxResourceHeapSize = kBufferOf4MBAllocationSize; ComPtr resourceAllocatorLimitedTo4MB; @@ -758,8 +758,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferUMA) { } TEST_F(D3D12ResourceAllocatorTests, CreateBufferDisableUMA) { - ALLOCATOR_DESC allocatorDesc = CreateBasicAllocatorDesc(); - allocatorDesc.Flags |= ALLOCATOR_FLAG_DISABLE_UNIFIED_MEMORY; + RESOURCE_ALLOCATOR_DESC allocatorDesc = CreateBasicAllocatorDesc(); + allocatorDesc.Flags |= RESOURCE_ALLOCATOR_FLAG_DISABLE_UNIFIED_MEMORY; ComPtr resourceAllocator; ASSERT_SUCCEEDED(CreateResourceAllocator(allocatorDesc, mDevice.Get(), mAdapter.Get(), @@ -828,8 +828,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateSmallTexture) { } { - ALLOCATOR_DESC allocatorDesc = CreateBasicAllocatorDesc(); - allocatorDesc.Flags = ALLOCATOR_FLAG_ALWAYS_ON_DEMAND; + RESOURCE_ALLOCATOR_DESC allocatorDesc = CreateBasicAllocatorDesc(); + allocatorDesc.Flags = RESOURCE_ALLOCATOR_FLAG_ALWAYS_ON_DEMAND; allocatorDesc.SubAllocationAlgorithm = ALLOCATOR_ALGORITHM_DEDICATED; ComPtr resourceAllocator; @@ -938,8 +938,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferInvalid) { } TEST_F(D3D12ResourceAllocatorTests, CreateBufferAlwaysCommitted) { - ALLOCATOR_DESC desc = CreateBasicAllocatorDesc(); - desc.Flags = ALLOCATOR_FLAG_ALWAYS_COMMITTED; + RESOURCE_ALLOCATOR_DESC desc = CreateBasicAllocatorDesc(); + desc.Flags = RESOURCE_ALLOCATOR_FLAG_ALWAYS_COMMITTED; ComPtr resourceAllocator; ASSERT_SUCCEEDED( @@ -957,7 +957,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferAlwaysCommitted) { EXPECT_EQ(allocation->GetInfo().SizeInBytes, kBufferOf4MBAllocationSize); // Commmitted resources cannot be backed by a D3D12 heap. - ComPtr resourceHeap = allocation->GetMemory(); + ComPtr resourceHeap = allocation->GetMemory(); ASSERT_NE(resourceHeap, nullptr); EXPECT_NE(allocation->GetResource(), nullptr); @@ -986,7 +986,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferNeverAllocate) { // Check we can't reuse memory if CreateResource was never called previously. ALLOCATION_DESC allocationDesc = {}; - allocationDesc.Flags = ALLOCATION_FLAG_NEVER_ALLOCATE_MEMORY; + allocationDesc.Flags = ALLOCATION_FLAG_NEVER_ALLOCATE_HEAP; allocationDesc.HeapType = D3D12_HEAP_TYPE_DEFAULT; ComPtr allocation; @@ -1008,7 +1008,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferNeverAllocate) { allocationA.Reset(); // Re-check that the same resource heap is used once CreateResource gets called. - allocationDesc.Flags = ALLOCATION_FLAG_NEVER_ALLOCATE_MEMORY; + allocationDesc.Flags = ALLOCATION_FLAG_NEVER_ALLOCATE_HEAP; ComPtr allocationB; ASSERT_SUCCEEDED( resourceAllocator->CreateResource(allocationDesc, CreateBasicBufferDesc(bufferSize), @@ -1302,7 +1302,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferNeverSubAllocated) { ALLOCATION_DESC allocationDesc = {}; allocationDesc.HeapType = D3D12_HEAP_TYPE_UPLOAD; - allocationDesc.Flags = ALLOCATION_FLAG_NEVER_SUBALLOCATE_MEMORY; + allocationDesc.Flags = ALLOCATION_FLAG_NEVER_SUBALLOCATE_HEAP; ComPtr subAllocation; ASSERT_SUCCEEDED(resourceAllocator->CreateResource( @@ -1314,8 +1314,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferNeverSubAllocated) { } TEST_F(D3D12ResourceAllocatorTests, CreateBufferNeverPooled) { - ALLOCATOR_DESC allocatorDesc = CreateBasicAllocatorDesc(); - allocatorDesc.Flags |= ALLOCATOR_FLAG_ALWAYS_ON_DEMAND; + RESOURCE_ALLOCATOR_DESC allocatorDesc = CreateBasicAllocatorDesc(); + allocatorDesc.Flags |= RESOURCE_ALLOCATOR_FLAG_ALWAYS_ON_DEMAND; ComPtr resourceAllocator; ASSERT_SUCCEEDED(CreateResourceAllocator(allocatorDesc, mDevice.Get(), mAdapter.Get(), @@ -1340,7 +1340,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferNeverPooled) { // Check the first buffer of size A cannot be from recycled memory. { ALLOCATION_DESC allocationDesc = baseAllocationDesc; - allocationDesc.Flags = ALLOCATION_FLAG_NEVER_ALLOCATE_MEMORY; + allocationDesc.Flags = ALLOCATION_FLAG_NEVER_ALLOCATE_HEAP; ComPtr allocation; ASSERT_FAILED(resourceAllocator->CreateResource( @@ -1361,7 +1361,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferNeverPooled) { // Check the second buffer of size B cannot be from recycled memory. { ALLOCATION_DESC allocationDesc = baseAllocationDesc; - allocationDesc.Flags = ALLOCATION_FLAG_NEVER_ALLOCATE_MEMORY; + allocationDesc.Flags = ALLOCATION_FLAG_NEVER_ALLOCATE_HEAP; ComPtr allocation; ASSERT_FAILED(resourceAllocator->CreateResource( @@ -1373,7 +1373,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferNeverPooled) { TEST_F(D3D12ResourceAllocatorTests, CreateBufferPooled) { constexpr uint64_t bufferSize = kBufferOf4MBAllocationSize; - ALLOCATOR_DESC allocatorDesc = CreateBasicAllocatorDesc(); + RESOURCE_ALLOCATOR_DESC allocatorDesc = CreateBasicAllocatorDesc(); ComPtr poolAllocator; ASSERT_SUCCEEDED(CreateResourceAllocator(allocatorDesc, mDevice.Get(), mAdapter.Get(), @@ -1382,7 +1382,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferPooled) { // Only standalone allocations can be pool-allocated. ALLOCATION_DESC standaloneAllocationDesc = {}; - standaloneAllocationDesc.Flags = ALLOCATION_FLAG_NEVER_SUBALLOCATE_MEMORY; + standaloneAllocationDesc.Flags = ALLOCATION_FLAG_NEVER_SUBALLOCATE_HEAP; standaloneAllocationDesc.HeapType = D3D12_HEAP_TYPE_UPLOAD; // Create buffer of size A with it's own resource heap that will be returned to the pool. @@ -1411,7 +1411,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferPooled) { { ALLOCATION_DESC reusePoolOnlyDesc = standaloneAllocationDesc; reusePoolOnlyDesc.Flags = - standaloneAllocationDesc.Flags | ALLOCATION_FLAG_NEVER_ALLOCATE_MEMORY; + standaloneAllocationDesc.Flags | ALLOCATION_FLAG_NEVER_ALLOCATE_HEAP; ComPtr allocation; ASSERT_SUCCEEDED( poolAllocator->CreateResource(reusePoolOnlyDesc, CreateBasicBufferDesc(bufferSize), @@ -1425,7 +1425,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferPooled) { { ALLOCATION_DESC reusePoolOnlyDesc = standaloneAllocationDesc; reusePoolOnlyDesc.Flags = - standaloneAllocationDesc.Flags | ALLOCATION_FLAG_NEVER_ALLOCATE_MEMORY; + standaloneAllocationDesc.Flags | ALLOCATION_FLAG_NEVER_ALLOCATE_HEAP; ComPtr allocation; ASSERT_SUCCEEDED( poolAllocator->CreateResource(reusePoolOnlyDesc, CreateBasicBufferDesc(bufferSize / 2), @@ -1448,7 +1448,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferPooled) { { ALLOCATION_DESC reusePoolOnlyDesc = standaloneAllocationDesc; reusePoolOnlyDesc.Flags = - standaloneAllocationDesc.Flags | ALLOCATION_FLAG_NEVER_ALLOCATE_MEMORY; + standaloneAllocationDesc.Flags | ALLOCATION_FLAG_NEVER_ALLOCATE_HEAP; ComPtr allocation; ASSERT_FAILED( poolAllocator->CreateResource(reusePoolOnlyDesc, CreateBasicBufferDesc(bufferSize), @@ -1459,7 +1459,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferPooled) { { ALLOCATION_DESC reusePoolOnlyDesc = standaloneAllocationDesc; reusePoolOnlyDesc.Flags = - standaloneAllocationDesc.Flags | ALLOCATION_FLAG_NEVER_ALLOCATE_MEMORY; + standaloneAllocationDesc.Flags | ALLOCATION_FLAG_NEVER_ALLOCATE_HEAP; ComPtr allocation; ASSERT_FAILED( poolAllocator->CreateResource(reusePoolOnlyDesc, CreateBasicBufferDesc(bufferSize / 2), @@ -1468,7 +1468,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferPooled) { // Creating a new allocator using a misaligned max resource size for pooling should succeed. { - ALLOCATOR_DESC desc = CreateBasicAllocatorDesc(); + RESOURCE_ALLOCATOR_DESC desc = CreateBasicAllocatorDesc(); ComPtr resourceAllocator; ASSERT_SUCCEEDED(CreateResourceAllocator(desc, mDevice.Get(), mAdapter.Get(), @@ -1495,7 +1495,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferStats) { ASSERT_NE(resourceAllocator, nullptr); ALLOCATION_DESC standaloneAllocationDesc = {}; - standaloneAllocationDesc.Flags = ALLOCATION_FLAG_NEVER_SUBALLOCATE_MEMORY; + standaloneAllocationDesc.Flags = ALLOCATION_FLAG_NEVER_SUBALLOCATE_HEAP; standaloneAllocationDesc.HeapType = D3D12_HEAP_TYPE_DEFAULT; ComPtr firstAllocation; @@ -1512,7 +1512,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferStats) { // Calculate info for two pooled standalone allocations. { - ALLOCATOR_DESC allocatorDesc = CreateBasicAllocatorDesc(); + RESOURCE_ALLOCATOR_DESC allocatorDesc = CreateBasicAllocatorDesc(); ComPtr resourceAllocator; ASSERT_SUCCEEDED(CreateResourceAllocator(allocatorDesc, mDevice.Get(), mAdapter.Get(), @@ -1520,7 +1520,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferStats) { ASSERT_NE(resourceAllocator, nullptr); ALLOCATION_DESC standaloneAllocationDesc = {}; - standaloneAllocationDesc.Flags = ALLOCATION_FLAG_NEVER_SUBALLOCATE_MEMORY; + standaloneAllocationDesc.Flags = ALLOCATION_FLAG_NEVER_SUBALLOCATE_HEAP; standaloneAllocationDesc.HeapType = D3D12_HEAP_TYPE_DEFAULT; ComPtr firstAllocation; @@ -1632,7 +1632,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferStats) { TEST_F(D3D12ResourceAllocatorTests, CreateTexturePooled) { ComPtr poolAllocator; { - ALLOCATOR_DESC allocatorDesc = CreateBasicAllocatorDesc(); + RESOURCE_ALLOCATOR_DESC allocatorDesc = CreateBasicAllocatorDesc(); ASSERT_SUCCEEDED(CreateResourceAllocator(allocatorDesc, mDevice.Get(), mAdapter.Get(), &poolAllocator, nullptr)); ASSERT_NE(poolAllocator, nullptr); @@ -1640,7 +1640,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateTexturePooled) { // Only standalone allocations can be pool-allocated. ALLOCATION_DESC standaloneAllocationDesc = {}; - standaloneAllocationDesc.Flags = ALLOCATION_FLAG_NEVER_SUBALLOCATE_MEMORY; + standaloneAllocationDesc.Flags = ALLOCATION_FLAG_NEVER_SUBALLOCATE_HEAP; standaloneAllocationDesc.HeapType = D3D12_HEAP_TYPE_DEFAULT; // Create a small texture of size A with it's own resource heap that will be returned to the @@ -1655,8 +1655,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateTexturePooled) { } ALLOCATION_DESC reusePoolOnlyDesc = standaloneAllocationDesc; - reusePoolOnlyDesc.Flags = - standaloneAllocationDesc.Flags | ALLOCATION_FLAG_NEVER_ALLOCATE_MEMORY; + reusePoolOnlyDesc.Flags = standaloneAllocationDesc.Flags | ALLOCATION_FLAG_NEVER_ALLOCATE_HEAP; // Check the first small texture of size A was pool-allocated by creating it again. { @@ -1672,7 +1671,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateTexturePooled) { // Verify a 1 byte buffer will be defragmented by creating a heaps large enough to stay under the // fragmentation limit. TEST_F(D3D12ResourceAllocatorTests, CreateBufferWithLimitedFragmentation) { - ALLOCATOR_DESC allocatorDesc = CreateBasicAllocatorDesc(); + RESOURCE_ALLOCATOR_DESC allocatorDesc = CreateBasicAllocatorDesc(); allocatorDesc.ResourceHeapFragmentationLimit = 0.0265; // or 2.65% ALLOCATION_DESC baseAllocationDesc = {}; @@ -1705,7 +1704,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferWithLimitedFragmentation) { ASSERT_NE(resourceAllocator, nullptr); ALLOCATION_DESC standaloneAllocationDesc = baseAllocationDesc; - standaloneAllocationDesc.Flags |= ALLOCATION_FLAG_NEVER_SUBALLOCATE_MEMORY; + standaloneAllocationDesc.Flags |= ALLOCATION_FLAG_NEVER_SUBALLOCATE_HEAP; ComPtr allocation; ASSERT_SUCCEEDED( @@ -1717,7 +1716,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferWithLimitedFragmentation) { // Repeat standalone buffer creation, but using a committed resource. { - allocatorDesc.Flags |= ALLOCATOR_FLAG_ALWAYS_COMMITTED; + allocatorDesc.Flags |= RESOURCE_ALLOCATOR_FLAG_ALWAYS_COMMITTED; ComPtr commitedAllocator; ASSERT_SUCCEEDED(CreateResourceAllocator(allocatorDesc, mDevice.Get(), mAdapter.Get(), @@ -1742,8 +1741,8 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferManyPrefetch) { // Prefetching is explicitly disabled but otherwise allowed, re-enable it by clearing the // disable flag. - ALLOCATOR_DESC allocatorDesc = CreateBasicAllocatorDesc(); - allocatorDesc.Flags ^= ALLOCATOR_FLAG_DISABLE_MEMORY_PREFETCH; + RESOURCE_ALLOCATOR_DESC allocatorDesc = CreateBasicAllocatorDesc(); + allocatorDesc.Flags ^= RESOURCE_ALLOCATOR_FLAG_DISABLE_PREFETCH; ComPtr resourceAllocator; ASSERT_SUCCEEDED(CreateResourceAllocator(allocatorDesc, mDevice.Get(), mAdapter.Get(), @@ -1754,7 +1753,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferManyPrefetch) { ALLOCATION_DESC allocationDesc = {}; allocationDesc.HeapType = D3D12_HEAP_TYPE_DEFAULT; - allocationDesc.Flags = ALLOCATION_FLAG_ALWAYS_PREFETCH_MEMORY; + allocationDesc.Flags = ALLOCATION_FLAG_ALWAYS_PREFETCH_HEAP; constexpr uint32_t kMinBufferSize = GPGMM_KB_TO_BYTES(64);