37 #include <unordered_set>
45 class DescriptorHeapAllocation;
46 class DescriptorHeapAllocationManager;
47 class RenderDeviceD3D12Impl;
74 m_pDescriptorHeap {
nullptr},
78 m_FirstCpuHandle.ptr = 0;
79 m_FirstGpuHandle.ptr = 0;
84 ID3D12DescriptorHeap* pHeap,
85 D3D12_CPU_DESCRIPTOR_HANDLE CpuHandle,
86 D3D12_GPU_DESCRIPTOR_HANDLE GpuHandle,
88 Uint16 AllocationManagerId) noexcept :
90 m_FirstCpuHandle {CpuHandle },
91 m_FirstGpuHandle {GpuHandle },
92 m_pAllocator {&Allocator },
93 m_NumHandles {NHandles },
94 m_pDescriptorHeap {pHeap },
95 m_AllocationManagerId {AllocationManagerId}
98 VERIFY_EXPR(m_pAllocator !=
nullptr && m_pDescriptorHeap !=
nullptr);
101 m_DescriptorSize =
static_cast<Uint16>(DescriptorSize);
107 m_FirstCpuHandle {std::move(Allocation.m_FirstCpuHandle) },
108 m_FirstGpuHandle {std::move(Allocation.m_FirstGpuHandle) },
109 m_NumHandles {std::move(Allocation.m_NumHandles) },
110 m_pAllocator {std::move(Allocation.m_pAllocator) },
111 m_AllocationManagerId {std::move(Allocation.m_AllocationManagerId)},
112 m_pDescriptorHeap {std::move(Allocation.m_pDescriptorHeap) },
113 m_DescriptorSize {std::move(Allocation.m_DescriptorSize) }
122 m_FirstCpuHandle = std::move(Allocation.m_FirstCpuHandle);
123 m_FirstGpuHandle = std::move(Allocation.m_FirstGpuHandle);
124 m_NumHandles = std::move(Allocation.m_NumHandles);
125 m_pAllocator = std::move(Allocation.m_pAllocator);
126 m_AllocationManagerId = std::move(Allocation.m_AllocationManagerId);
127 m_pDescriptorHeap = std::move(Allocation.m_pDescriptorHeap);
128 m_DescriptorSize = std::move(Allocation.m_DescriptorSize);
137 m_FirstCpuHandle.ptr = 0;
138 m_FirstGpuHandle.ptr = 0;
139 m_pAllocator =
nullptr;
140 m_pDescriptorHeap =
nullptr;
142 m_AllocationManagerId =
static_cast<Uint16>(-1);
143 m_DescriptorSize = 0;
155 if (!
IsNull() && m_pAllocator)
156 m_pAllocator->
Free(std::move(*
this), ~
Uint64{0});
158 VERIFY(
IsNull(),
"Non-null descriptor is being destroyed");
166 D3D12_CPU_DESCRIPTOR_HANDLE CPUHandle = m_FirstCpuHandle;
167 CPUHandle.ptr += m_DescriptorSize * Offset;
176 D3D12_GPU_DESCRIPTOR_HANDLE GPUHandle = m_FirstGpuHandle;
177 GPUHandle.ptr += m_DescriptorSize * Offset;
182 template <
typename HandleType>
186 D3D12_CPU_DESCRIPTOR_HANDLE GetHandle<D3D12_CPU_DESCRIPTOR_HANDLE>(
Uint32 Offset)
const
192 D3D12_GPU_DESCRIPTOR_HANDLE GetHandle<D3D12_GPU_DESCRIPTOR_HANDLE>(
Uint32 Offset)
const
204 bool IsNull()
const {
return m_FirstCpuHandle.ptr == 0; }
212 D3D12_CPU_DESCRIPTOR_HANDLE m_FirstCpuHandle = {0};
215 D3D12_GPU_DESCRIPTOR_HANDLE m_FirstGpuHandle = {0};
221 IDescriptorAllocator* m_pAllocator =
nullptr;
224 ID3D12DescriptorHeap* m_pDescriptorHeap =
nullptr;
236 Uint16 m_DescriptorSize = 0;
255 size_t ThisManagerId,
256 const D3D12_DESCRIPTOR_HEAP_DESC& HeapDesc);
263 size_t ThisManagerId,
264 ID3D12DescriptorHeap* pd3d12DescriptorHeap,
272 m_ParentAllocator {rhs.m_ParentAllocator },
273 m_DeviceD3D12Impl {rhs.m_DeviceD3D12Impl },
274 m_ThisManagerId {rhs.m_ThisManagerId },
275 m_HeapDesc {rhs.m_HeapDesc },
276 m_DescriptorSize {rhs.m_DescriptorSize },
277 m_NumDescriptorsInAllocation{rhs.m_NumDescriptorsInAllocation},
278 m_FirstCPUHandle {rhs.m_FirstCPUHandle },
279 m_FirstGPUHandle {rhs.m_FirstGPUHandle },
280 m_MaxAllocatedSize {rhs.m_MaxAllocatedSize },
283 m_FreeBlockManager {std::move(rhs.m_FreeBlockManager) },
284 m_pd3d12DescriptorHeap {std::move(rhs.m_pd3d12DescriptorHeap)}
287 rhs.m_NumDescriptorsInAllocation = 0;
288 rhs.m_ThisManagerId =
static_cast<size_t>(-1);
289 rhs.m_FirstCPUHandle.ptr = 0;
290 rhs.m_FirstGPUHandle.ptr = 0;
291 rhs.m_MaxAllocatedSize = 0;
292 #ifdef DILIGENT_DEVELOPMENT
293 m_AllocationsCounter.store(rhs.m_AllocationsCounter.load());
294 rhs.m_AllocationsCounter = 0;
295 m_pd3d12InvalidDescriptorHeap = std::move(rhs.m_pd3d12InvalidDescriptorHeap);
309 DescriptorHeapAllocation
Allocate(uint32_t Count);
318 #ifdef DILIGENT_DEVELOPMENT
319 int32_t DvpGetAllocationsCounter()
const
321 return m_AllocationsCounter;
326 IDescriptorAllocator& m_ParentAllocator;
327 RenderDeviceD3D12Impl& m_DeviceD3D12Impl;
330 size_t m_ThisManagerId =
static_cast<size_t>(-1);
333 const D3D12_DESCRIPTOR_HEAP_DESC m_HeapDesc;
335 const UINT m_DescriptorSize = 0;
340 Uint32 m_NumDescriptorsInAllocation = 0;
343 std::mutex m_FreeBlockManagerMutex;
344 VariableSizeAllocationsManager m_FreeBlockManager;
347 CComPtr<ID3D12DescriptorHeap> m_pd3d12DescriptorHeap;
350 D3D12_CPU_DESCRIPTOR_HANDLE m_FirstCPUHandle = {0};
353 D3D12_GPU_DESCRIPTOR_HANDLE m_FirstGPUHandle = {0};
355 size_t m_MaxAllocatedSize = 0;
357 #ifdef DILIGENT_DEVELOPMENT
358 std::atomic_int32_t m_AllocationsCounter = 0;
363 static constexpr
Uint32 InvalidDescriptorsCount = 128;
364 CComPtr<ID3D12DescriptorHeap> m_pd3d12InvalidDescriptorHeap;
393 Uint32 NumDescriptorsInHeap,
394 D3D12_DESCRIPTOR_HEAP_TYPE
Type,
395 D3D12_DESCRIPTOR_HEAP_FLAGS
Flags);
410 #ifdef DILIGENT_DEVELOPMENT
411 int32_t DvpGetTotalAllocationCount();
421 std::mutex m_HeapPoolMutex;
422 std::vector<DescriptorHeapAllocationManager, STDAllocatorRawMem<DescriptorHeapAllocationManager>> m_HeapPool;
426 D3D12_DESCRIPTOR_HEAP_DESC m_HeapDesc;
427 const UINT m_DescriptorSize = 0;
478 Uint32 NumDescriptorsInHeap,
479 Uint32 NumDynamicDescriptors,
480 D3D12_DESCRIPTOR_HEAP_TYPE
Type,
481 D3D12_DESCRIPTOR_HEAP_FLAGS
Flags);
509 #ifdef DILIGENT_DEVELOPMENT
510 int32_t DvpGetTotalAllocationCount()
const
577 const String m_ManagerName;
581 std::vector<DescriptorHeapAllocation, STDAllocatorRawMem<DescriptorHeapAllocation>> m_Suballocations;
583 Uint32 m_CurrentSuballocationOffset = 0;
584 Uint32 m_DynamicChunkSize = 0;
586 Uint32 m_CurrDescriptorCount = 0;
587 Uint32 m_PeakDescriptorCount = 0;
588 Uint32 m_CurrSuballocationsTotalSize = 0;
589 Uint32 m_PeakSuballocationsTotalSize = 0;