UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
D3D12CommandList.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3/*=============================================================================
4D3D12CommandList.h: Implementation of D3D12 Command List functions
5=============================================================================*/
6#pragma once
7
8#include "D3D12RHICommon.h"
9#include "RHICommandList.h"
11#include "D3D12Resources.h"
12#include "D3D12Submission.h"
13#include "D3D12Util.h"
14
16class FD3D12Device;
19class FD3D12Queue;
20
22
23enum class ED3D12QueueType;
24
26{
27 class ResidencySet;
28}
29typedef D3DX12Residency::ResidencySet FD3D12ResidencySet;
30
31//
32// Wraps a D3D command list allocator object.
33// Allocators are obtained from the parent device, and recycled in that device's object pool.
34//
36{
37private:
38 friend FD3D12Device;
41
43
44public:
46
49
50 void Reset();
51
52 operator ID3D12CommandAllocator*() { return CommandAllocator.GetReference(); }
53
54private:
56};
57
58//
59// Wraps a D3D command list object. Includes additional data required by the command context and submission thread.
60// Command lists are obtained from the parent device, and recycled in that device's object pool.
61//
63{
64private:
65 friend FD3D12Device;
67 friend FD3D12DynamicRHI;
68 friend FD3D12Queue;
69
70 FD3D12CommandList(FD3D12CommandList const&) = delete;
72
74
75 void BeginLocalQueries();
76 void EndLocalQueries();
77
78public:
80
81 void BeginQuery(FD3D12QueryLocation const& Location);
82 void EndQuery (FD3D12QueryLocation const& Location);
83
85 void Close();
86
87 bool IsOpen () const { return !State.IsClosed; }
88 bool IsClosed() const { return State.IsClosed; }
89
90 uint32 GetNumCommands() const { return State.NumCommands; }
91
94
95private:
96 FD3D12ResidencySet* const ResidencySet;
97
98public:
99 // Indicate that a resource must be made resident before execution on GPU.
100 // Either immediately adds residency handle for this resource to the residency set
101 // or defers it until submission time (residency handles may not be known until then).
102 void UpdateResidency(const FD3D12Resource* Resource);
103
104#if ENABLE_RESIDENCY_MANAGEMENT
105 // Immediately add residency handles to the residency set for this command list.
107
108 // Closes and returns the residency set. Used only during submission.
110#endif // ENABLE_RESIDENCY_MANAGEMENT
111
112#if RHI_NEW_GPU_PROFILER
113 template <typename TEventType, typename... TArgs>
115 {
116 TEventType& Data = State.EventStream.Emplace<TEventType>(Forward<TArgs>(Args)...);
117
118 if constexpr (std::is_same_v<UE::RHI::GPUProfiler::FEvent::FBeginWork, TEventType>)
119 {
120 // Store BeginEvents in a separate array as the CPUTimestamp field needs updating at submit time.
121 State.BeginEvents.Add(&Data);
122 }
123
124 return Data;
125 }
126
127 void FlushProfilerEvents(UE::RHI::GPUProfiler::FEventStream& Destination, uint64 CPUTimestamp)
128 {
130 {
131 BeginEvent->CPUTimestamp = CPUTimestamp;
132 }
133
134 Destination.Append(MoveTemp(State.EventStream));
135 }
136#endif
137
138private:
139 struct FInterfaces
140 {
143 TRefCountPtr<ID3D12GraphicsCommandList> GraphicsCommandList;
144
145#if D3D12_MAX_COMMANDLIST_INTERFACE >= 1
147#endif
148#if D3D12_MAX_COMMANDLIST_INTERFACE >= 2
150#endif
151#if D3D12_MAX_COMMANDLIST_INTERFACE >= 3
153#endif
154#if D3D12_MAX_COMMANDLIST_INTERFACE >= 4
156#endif
157#if D3D12_MAX_COMMANDLIST_INTERFACE >= 5
159#endif
160#if D3D12_MAX_COMMANDLIST_INTERFACE >= 6
162#endif
163#if D3D12_MAX_COMMANDLIST_INTERFACE >= 7
165#endif
166#if D3D12_MAX_COMMANDLIST_INTERFACE >= 8
168#endif
169#if D3D12_MAX_COMMANDLIST_INTERFACE >= 9
171#endif
172#if D3D12_MAX_COMMANDLIST_INTERFACE >= 10
174#endif
175
176#if D3D12_SUPPORTS_DEBUG_COMMAND_LIST
178#endif
179#if NV_AFTERMATH
180 UE::RHICore::Nvidia::Aftermath::D3D12::FCommandList AftermathHandle = nullptr;
181#endif
182#if INTEL_GPU_CRASH_DUMPS
184#endif
185 } Interfaces;
186
187public:
188 //
189 // Wrapper type to prevent l-value use of the returned command list interfaces.
190 // A context's command list may be swapped out during recording. Users should access the command
191 // list via the context itself, to ensure they always have the correct command list instance.
192 //
193 template <typename T>
195 {
196 friend FD3D12CommandList;
197
198 FD3D12CommandList& CommandList;
199 T* Ptr;
200
201 TRValuePtr(FD3D12CommandList& CommandList, T* Ptr)
202 : CommandList(CommandList)
203 , Ptr(Ptr)
204 {}
205
206 public:
207 TRValuePtr() = delete;
208
209 TRValuePtr(TRValuePtr const&) = delete;
211
214
215 operator bool () const&& { return !!Ptr; }
216 bool operator!() const&& { return !Ptr; }
217
218 // These accessor functions count useful work on command lists
219 T* operator -> () && { CommandList.State.NumCommands++; return Ptr; }
220 T* Get () && { CommandList.State.NumCommands++; return Ptr; }
221
222 T* GetNoRefCount() && { return Ptr; }
223 };
224
225private:
226 template <typename FInterfaceType>
227 auto BuildRValuePtr(TRefCountPtr<FInterfaceType> FInterfaces::* Member)
228 {
229 return TRValuePtr<FInterfaceType>(*this, Interfaces.*Member);
230 }
231
232public:
233 auto BaseCommandList () { return BuildRValuePtr(&FInterfaces::CommandList ); }
234 auto CopyCommandList () { return BuildRValuePtr(&FInterfaces::CopyCommandList ); }
235 auto GraphicsCommandList () { return BuildRValuePtr(&FInterfaces::GraphicsCommandList ); }
236#if D3D12_MAX_COMMANDLIST_INTERFACE >= 1
237 auto GraphicsCommandList1 () { return BuildRValuePtr(&FInterfaces::GraphicsCommandList1); }
238#endif
239#if D3D12_MAX_COMMANDLIST_INTERFACE >= 2
240 auto GraphicsCommandList2 () { return BuildRValuePtr(&FInterfaces::GraphicsCommandList2); }
241#endif
242#if D3D12_MAX_COMMANDLIST_INTERFACE >= 3
243 auto GraphicsCommandList3 () { return BuildRValuePtr(&FInterfaces::GraphicsCommandList3); }
244#endif
245#if D3D12_MAX_COMMANDLIST_INTERFACE >= 4
246 auto GraphicsCommandList4 () { return BuildRValuePtr(&FInterfaces::GraphicsCommandList4); }
247#endif
248#if D3D12_MAX_COMMANDLIST_INTERFACE >= 5
249 auto GraphicsCommandList5 () { return BuildRValuePtr(&FInterfaces::GraphicsCommandList5); }
250#endif
251#if D3D12_MAX_COMMANDLIST_INTERFACE >= 6
252 auto GraphicsCommandList6 () { return BuildRValuePtr(&FInterfaces::GraphicsCommandList6); }
253#endif
254#if D3D12_MAX_COMMANDLIST_INTERFACE >= 7
255 auto GraphicsCommandList7 () { return BuildRValuePtr(&FInterfaces::GraphicsCommandList7); }
256#endif
257#if D3D12_MAX_COMMANDLIST_INTERFACE >= 8
258 auto GraphicsCommandList8 () { return BuildRValuePtr(&FInterfaces::GraphicsCommandList8); }
259#endif
260#if D3D12_MAX_COMMANDLIST_INTERFACE >= 9
261 auto GraphicsCommandList9 () { return BuildRValuePtr(&FInterfaces::GraphicsCommandList9); }
262#endif
263#if D3D12_MAX_COMMANDLIST_INTERFACE >= 10
264 auto GraphicsCommandList10() { return BuildRValuePtr(&FInterfaces::GraphicsCommandList10); }
265#endif
266
267#if D3D12_SUPPORTS_DEBUG_COMMAND_LIST
268 auto DebugCommandList () { return BuildRValuePtr(&FInterfaces::DebugCommandList ); }
269#endif
270#if D3D12_RHI_RAYTRACING
271 auto RayTracingCommandList() { return BuildRValuePtr(&FInterfaces::GraphicsCommandList4); }
272#endif
273#if NV_AFTERMATH
274 auto AftermathHandle () { return Interfaces.AftermathHandle; }
275#endif
276
277private:
278 void WriteTimestamp(FD3D12QueryLocation const& Location, ED3D12QueryPosition Position);
279
280 // Contents of the state struct are reset when the command list is recycled
281 struct FState
282 {
284
285 // The allocator currently assigned to this command list.
286 FD3D12CommandAllocator* CommandAllocator;
287
288#if DEBUG_RESOURCE_STATES
289 // Tracks all the resources barriers being issued on this command list in order
291#endif
292
293 FD3D12QueryLocation BeginTimestamp;
294 FD3D12QueryLocation EndTimestamp;
295
297
298 TArray<FD3D12QueryLocation> TimestampQueries;
299 TArray<FD3D12QueryLocation> OcclusionQueries;
300 TArray<FD3D12QueryLocation> PipelineStatsQueries;
301
302 // Resources whose residency must be updated on the submission thread, as their residency handles are not known during translation.
303 // This includes reserved resources that may refer to different heaps at different points on the submission timeline.
304 TSet<const FD3D12Resource*> DeferredResidencyUpdateSet;
305
306 uint32 NumCommands = 0;
307
308 bool IsClosed = false;
309
310 #if DO_CHECK
311 bool bLocalQueriesBegun = false;
312 bool bLocalQueriesEnded = false;
313 #endif
314
315 #if RHI_NEW_GPU_PROFILER
318 #endif
319
320 } State;
321};
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
D3DX12Residency::ResidencySet FD3D12ResidencySet
Definition D3D12CommandList.h:29
ED3D12QueryPosition
Definition D3D12Query.h:38
ED3D12QueueType
Definition D3D12Queue.h:11
const bool
Definition NetworkReplayStreaming.h:178
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition D3D12CommandList.h:36
ED3D12QueueType const QueueType
Definition D3D12CommandList.h:48
~FD3D12CommandAllocator()
Definition D3D12CommandList.cpp:83
void Reset()
Definition D3D12CommandList.cpp:89
FD3D12Device *const Device
Definition D3D12CommandList.h:47
Definition D3D12CommandList.h:195
T * GetNoRefCount() &&
Definition D3D12CommandList.h:222
T * operator->() &&
Definition D3D12CommandList.h:219
T * Get() &&
Definition D3D12CommandList.h:220
bool operator!() const &&
Definition D3D12CommandList.h:216
TRValuePtr(TRValuePtr &&)=delete
TRValuePtr & operator=(TRValuePtr const &)=delete
TRValuePtr(TRValuePtr const &)=delete
Definition D3D12CommandList.h:63
auto CopyCommandList()
Definition D3D12CommandList.h:234
auto GraphicsCommandList()
Definition D3D12CommandList.h:235
void Close()
Definition D3D12CommandList.cpp:219
void EndQuery(FD3D12QueryLocation const &Location)
Definition D3D12CommandList.cpp:308
bool IsClosed() const
Definition D3D12CommandList.h:88
void BeginQuery(FD3D12QueryLocation const &Location)
Definition D3D12CommandList.cpp:296
void UpdateResidency(const FD3D12Resource *Resource)
Definition D3D12CommandList.cpp:7
ED3D12QueueType const QueueType
Definition D3D12CommandList.h:93
auto BaseCommandList()
Definition D3D12CommandList.h:233
bool IsOpen() const
Definition D3D12CommandList.h:87
~FD3D12CommandList()
Definition D3D12CommandList.cpp:188
uint32 GetNumCommands() const
Definition D3D12CommandList.h:90
FD3D12Device *const Device
Definition D3D12CommandList.h:92
Definition D3D12CommandContext.h:199
Definition D3D12Device.h:176
Definition D3D12RHIPrivate.h:160
Definition D3D12Query.h:184
Definition D3D12Device.h:104
Definition D3D12Resources.h:181
Definition Array.h:670
Definition RefCounting.h:454
UE_FORCEINLINE_HINT ReferencedType * GetReference() const
Definition RefCounting.h:584
Definition GPUProfiler.h:310
void Append(FEventStream &&Other)
Definition GPUProfiler.h:447
Definition D3D12CommandList.h:26
Definition D3D12Query.h:129
Definition D3D12Residency.h:46
Definition GPUProfiler.h:172