UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
D3D12BindlessDescriptors.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "D3D12RHICommon.h"
6#include "D3D12Descriptors.h"
7#include "RHIDefinitions.h"
10
15
16struct FD3D12Payload;
17
18#if PLATFORM_SUPPORTS_BINDLESS_RENDERING
19
20#include COMPILED_PLATFORM_HEADER(D3D12BindlessDescriptors.h)
21
22#if !defined(D3D12RHI_BINDLESS_RESOURCE_MANAGER_SUPPORTS_RESIZING)
23 #error D3D12RHI_BINDLESS_RESOURCE_MANAGER_SUPPORTS_RESIZING needs to be defined
24#endif
25
26namespace UE::D3D12BindlessDescriptors
27{
30 void DeferredFreeHeap(FD3D12Device* InDevice, FD3D12DescriptorHeap* InHeap);
31}
32
35{
36public:
39
40 void Init();
41
42 ERHIBindlessConfiguration GetConfiguration() const { return BindlessConfiguration; }
43
44 bool AreResourcesBindless() const { return ResourceAllocator != nullptr; }
45 bool AreSamplersBindless() const { return SamplerAllocator != nullptr; }
46
47 // Bindless descriptor allocators are stored in the adapter, so descriptor handles can be allocated once and shared for multi-GPU objects
48 FRHIDescriptorHandle AllocateDescriptor(ERHIDescriptorType DescriptorType);
50
51 void FreeDescriptor(FRHIDescriptorHandle Handle);
52 void FreeDescriptors(ERHIDescriptorType DescriptorType, uint32 Offset);
53
55
56 uint32 GetResourceCapacity() const { return ResourceAllocator->GetCapacity(); }
57 uint32 GetSamplerCapacity() const { return SamplerAllocator->GetCapacity(); }
58
60
61#if D3D12RHI_CUSTOM_BINDLESS_RESOURCE_MANAGER
63#endif
64
65private:
66#if D3D12RHI_BINDLESS_RESOURCE_MANAGER_SUPPORTS_RESIZING
67 TOptional<FRHIDescriptorAllocation> ResizeGrowAndAllocate(uint32 NumAllocations);
68#endif
69
71
74
78};
79
82{
83public:
86
87 void CleanupResources();
88
90
91 void OpenCommandList(FD3D12CommandContext& Context);
92 void CloseCommandList(FD3D12CommandContext& Context);
93
95
96 FD3D12DescriptorHeap* GetHeap() const { return GpuHeap.GetReference(); }
97 ERHIBindlessConfiguration GetConfiguration() const { return Configuration; }
98
99 constexpr ERHIDescriptorTypeMask GetTypeMask() const
100 {
102 }
103
104 constexpr bool HandlesAllocation(ERHIDescriptorType InType) const
105 {
107 }
108
109private:
111 ERHIBindlessConfiguration Configuration;
112};
113
114#if !D3D12RHI_CUSTOM_BINDLESS_RESOURCE_MANAGER
115
116// Helper container for all context related bindless state.
118{
120 bool bRefreshHeap = false;
121
122 FD3D12ContextBindlessState() = default;
124 {
126 }
127
129 {
130 bRefreshHeap = true;
131 }
132};
133
135template <typename T, int32 ArraySize>
137{
138public:
140 : RemoveNextIdx(0)
141 , NumValuesUsed(0)
142 {
143 static_assert(ArraySize > 0, "ArraySize must be greater than zero");
144 }
145
146 void PushValue(T Value)
147 {
148 if (ArraySize == NumValuesUsed)
149 {
150 ValuesArray[RemoveNextIdx] = Value;
151 RemoveNextIdx = (RemoveNextIdx + 1) % ArraySize;
152 }
153 else
154 {
155 ValuesArray[NumValuesUsed] = Value;
156 ++NumValuesUsed;
157 }
158 }
159
160 T GetMax() const
161 {
162 T Max = static_cast<T>(0);
163 for (int32 Index = 0; Index < NumValuesUsed; ++Index)
164 {
165 Max = FMath::Max(Max, ValuesArray[Index]);
166 }
167 return Max;
168 }
169
170private:
171 TStaticArray<T, ArraySize> ValuesArray;
172
174 int32 RemoveNextIdx;
175 int32 NumValuesUsed;
176};
177
180{
181public:
184
185 void CleanupResources();
186
187 void GarbageCollect();
188 void Recycle(FD3D12DescriptorHeap* DescriptorHeap);
189
191 void UpdateDescriptor(FD3D12ContextArray const& Contexts, FRHIDescriptorHandle DstHandle, FD3D12View* View);
192
193 void FlushPendingDescriptorUpdates(FD3D12CommandContext& Context);
194
195 void OpenCommandList(FD3D12CommandContext& Context);
196 void CloseCommandList(FD3D12CommandContext& Context);
198
201
202 ERHIBindlessConfiguration GetConfiguration() const { return Configuration; }
203
204 // Called from FD3D12Adapter::AllocateBindlessResourceHandle
206
207 constexpr ERHIDescriptorTypeMask GetTypeMask() const
208 {
210 }
211
212 constexpr bool HandlesAllocation(ERHIDescriptorType InType) const
213 {
215 }
216
217private:
221
223 int AddActiveGPUHeap();
224 void ReleaseGPUHeaps();
225 void UpdateInUseGPUHeaps(bool bInUse);
226
227 // Critical section shared across devices
230 const ERHIBindlessConfiguration Configuration;
231
232 uint64 GarbageCollectCycle = 0;
234
235 bool bRequestNewActiveGpuHeap = false;
236 bool bCPUHeapResized = false;
237
241
242 struct FGpuHeapData
243 {
246 bool bInUse = true;
247 uint64 LastUsedGarbageCollectCycle = 0;
248 };
249
253};
254
255#endif
256
258{
259 FD3D12DescriptorHeap* SamplerHeap;
260 FD3D12DescriptorHeap* ResourceHeap;
261};
262
265{
266public:
269
270 void Init();
271 void CleanupResources();
272
274 {
275 return Allocator;
276 }
277
278 FD3D12BindlessResourceManager* GetResourceManager() const
279 {
280 return ResourceManager.Get();
281 }
282
284 {
285 return SamplerManager.Get();
286 }
287
288 ERHIBindlessConfiguration GetConfiguration() const
289 {
290 return Configuration;
291 }
292
295
296 void GarbageCollect();
297 void Recycle(FD3D12DescriptorHeap* DescriptorHeap);
298
301 void UpdateDescriptor(FD3D12ContextArray const& Contexts, FRHIDescriptorHandle DstHandle, FD3D12View* SourceView);
302
304
305 void OpenCommandList(FD3D12CommandContext& Context);
306 void CloseCommandList(FD3D12CommandContext& Context);
307
308 void FlushPendingDescriptorUpdates(FD3D12CommandContext& Context);
310
312
313#if D3D12RHI_USE_CONSTANT_BUFFER_VIEWS
315#endif
316
317private:
319
322
323 ERHIBindlessConfiguration Configuration{};
324};
325
326#endif // !PLATFORM_SUPPORTS_BINDLESS_RENDERING
#define check(expr)
Definition AssertionMacros.h:314
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
FPlatformTypes::uint64 uint64
A 64-bit unsigned integer.
Definition Platform.h:1117
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
UE::FPlatformRecursiveMutex FCriticalSection
Definition CriticalSection.h:53
constexpr bool EnumHasAnyFlags(Enum Flags, Enum Contains)
Definition EnumClassFlags.h:35
void Init()
Definition LockFreeList.h:4
ERHIDescriptorTypeMask
Definition RHIDefinitions.h:1367
ERHIDescriptorType
Definition RHIDefinitions.h:1348
ERHIBindlessConfiguration
Definition RHIDefinitions.h:1432
ERHIDescriptorHeapType
Definition RHIDefinitions.h:1338
constexpr ERHIDescriptorTypeMask RHIDescriptorTypeMaskFromType(ERHIDescriptorType InType)
Definition RHIDefinitions.h:1391
ERHIPipeline
Definition RHIPipeline.h:13
uint32 Offset
Definition VulkanMemory.cpp:4033
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition D3D12RHICommon.h:54
Definition D3D12Adapter.h:136
Definition D3D12CommandContext.h:513
Definition D3D12CommandContext.h:1193
Definition D3D12RHICommon.h:78
Definition D3D12Device.h:176
Definition D3D12State.h:13
Definition D3D12View.h:351
Definition D3D12View.h:388
Definition D3D12View.h:221
Definition RHICommandList.h:455
Definition RHIDescriptorAllocator.h:87
Definition Array.h:670
Definition RHIPipeline.h:55
Definition StaticArray.h:26
Definition UniquePtr.h:107
int32 GetMax(const FIntVector3 &V)
Definition Utilities.h:67
constexpr nat ArraySize(t(&)[n])
Definition VerseGrammar.h:60
U16 Index
Definition radfft.cpp:71
Definition D3D12Descriptors.h:95
Definition WindowsD3D12Submission.h:13
Definition RHIDescriptorAllocator.h:10
Definition RHIDefinitions.h:1401
Definition Optional.h:131