UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
RenderGraphEvent.inl
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#if RHI_NEW_GPU_PROFILER
6
7// @todo - new gpu profiler
8
9#else
10
11#if HAS_GPU_STATS
12inline FRDGScope_GPU::FRDGScope_GPU(FRDGScopeState& State, FRHIGPUMask GPUMask, const FName& CsvStatName, const TStatId& Stat, const TCHAR* Description, FRHIDrawStatsCategory const& Category)
14 bEmitDuringExecute(AreGPUStatsEnabled() && !State.ScopeState.bParallelExecute)
15{
17 {
19 {
20 StatName = CsvStatName;
21 StatId = Stat;
22 StatDescription = FString(Description);
23 }
24 else
25 {
26 StartQuery = FRealtimeGPUProfiler::Get()->PushEvent(GPUMask, CsvStatName, Stat, Description);
27 }
28 }
29}
30
31inline void FRDGScope_GPU::ImmediateEnd(FRDGScopeState&)
32{
33 if (StartQuery)
34 {
35 StopQuery = FRealtimeGPUProfiler::Get()->PopEvent();
36 }
37}
38
39inline FRDGScope_GPU::~FRDGScope_GPU()
40{
41 if (StartQuery)
42 {
43 StartQuery.Discard(true);
44 }
45 if (StopQuery)
46 {
47 StopQuery.Discard(false);
48 }
49}
50
51inline void FRDGScope_GPU::BeginCPU(FRHIComputeCommandList& RHICmdList, bool bPreScope)
52{
54 {
55 PreviousCategory = RHICmdList.SetDrawStatsCategory(CurrentCategory);
56 }
57}
58
59inline void FRDGScope_GPU::EndCPU(FRHIComputeCommandList& RHICmdList, bool bPreScope)
60{
62 {
63 RHICmdList.SetDrawStatsCategory(PreviousCategory);
64 }
65}
66
67inline void FRDGScope_GPU::BeginGPU(FRHIComputeCommandList& RHICmdList)
68{
70 {
72 {
73 FRealtimeGPUProfiler::Get()->PushStat(RHICmdList.GetAsImmediate(), StatName, StatId, *StatDescription);
74 }
75 else if (StartQuery)
76 {
77 StartQuery.Submit(static_cast<FRHICommandList&>(RHICmdList), true);
78 }
79 }
80}
81
82inline void FRDGScope_GPU::EndGPU(FRHIComputeCommandList& RHICmdList)
83{
85 {
87 {
88 FRealtimeGPUProfiler::Get()->PopStat(RHICmdList.GetAsImmediate());
89 }
90 else if (StopQuery)
91 {
92 StopQuery.Submit(static_cast<FRHICommandList&>(RHICmdList), false);
93 }
94
95 }
96}
97#endif
98
99#endif // (RHI_NEW_GPU_PROFILER == 0)
100
101#if RDG_EVENTS
102
103 template <typename TDesc, typename... TValues>
104 inline FRDGScope_RHI::FRDGScope_RHI(FRDGScopeState& State, TRHIBreadcrumbInitializer<TDesc, TValues...>&& Args)
106 {}
107
108 inline FRDGScope_RHI::FRDGScope_RHI(FRDGScopeState& State, FRHIBreadcrumbNode* Node)
109 : Node(Node)
110 {
111 if (Node)
112 {
113 Node->SetParent(State.CurrentBreadcrumbRef);
114 State.CurrentBreadcrumbRef = Node;
115 Node->TraceBeginCPU();
116
117 if (!State.ScopeState.bImmediate)
118 {
119 // Link breadcrumbs together, so we can iterate over them during RDG compilation.
120 State.LocalBreadcrumbList.Append(Node);
121 }
122 }
123 }
124
125 inline void FRDGScope_RHI::ImmediateEnd(FRDGScopeState& State)
126 {
127 #if WITH_RHI_BREADCRUMBS
128 if (Node)
129 {
130 Node->TraceEndCPU();
131 State.CurrentBreadcrumbRef = Node->GetParent();
132 }
133 #endif
134 }
135
136#endif // RDG_EVENTS
137
138template <typename TScopeType>
139template <typename... TArgs>
141 : State(State)
142 , Scope(State.Allocators.Root.Alloc<FRDGScope>(State.ScopeState.Current))
143{
145 {
146 // Mask off any nested scopes of the same type
147 State.ScopeState.Mask |= FRDGScope::GetTypeMask<TScopeType>();
148 }
149
150 State.ScopeState.Current = Scope;
151
152 Scope->Impl.Emplace<TScopeType>(State, Forward<TArgs>(Args)...);
153
154 if (State.ScopeState.bImmediate)
155 {
156 Scope->BeginCPU(State.RHICmdList, false);
157 Scope->BeginGPU(State.RHICmdList);
158 }
159}
160
161template <typename TScopeType>
163{
164 if (Scope)
165 {
166 if (State.ScopeState.bImmediate)
167 {
168 Scope->EndGPU(State.RHICmdList);
169 Scope->EndCPU(State.RHICmdList, false);
170 }
171
172 Scope->ImmediateEnd(State);
173
174 State.ScopeState.Mask &= ~(FRDGScope::GetTypeMask<TScopeType>());
175 State.ScopeState.Current = State.ScopeState.Current->Parent;
176 }
177}
178
179template <typename TScopeType>
181{
183 {
184 return false;
185 }
186
187 if (ScopeState.ScopeMode == ERDGScopeMode::TopLevelOnly && (ScopeState.Mask & FRDGScope::GetTypeMask<TScopeType>()))
188 {
189 return false;
190 }
191
192 return true;
193}
FPlatformTypes::TCHAR TCHAR
Either ANSICHAR or WIDECHAR, depending on whether the platform supports wide characters or the requir...
Definition Platform.h:1135
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
constexpr bool EnumHasAnyFlags(Enum Flags, Enum Contains)
Definition EnumClassFlags.h:35
RENDERCORE_API bool AreGPUStatsEnabled()
ERDGScopeFlags
Definition RenderGraphEvent.h:74
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
Definition NameTypes.h:617
Definition RenderGraphEvent.h:580
bool ShouldAllocScope(TOptional< TRDGEventScopeGuard< TScopeType > > const &, ERDGScopeFlags Flags) const
Definition RenderGraphEvent.inl:180
struct FRDGScopeState::FState ScopeState
void Emplace(TArgs &&... Args)
Definition RenderGraphEvent.h:259
ERHIPipeline GetPipeline() const
Definition RHICommandList.h:675
FRHICommandListImmediate & GetAsImmediate()
Definition RHICommandList.inl:21
Definition RHICommandList.h:3819
Definition RHICommandList.h:2735
Definition RenderGraphEvent.h:329
~TRDGEventScopeGuard()
Definition RenderGraphEvent.inl:162
Category
Definition DiffResults.h:63
State
Definition PacketHandler.h:88
uint32 Mask
Definition RenderGraphEvent.h:587
static constexpr ERDGScopeMode const ScopeMode
Definition RenderGraphEvent.h:593
Definition RenderGraphEvent.h:236
void BeginCPU(FRHIComputeCommandList &RHICmdList, bool bPreScope)
Definition RenderGraphEvent.h:316
void BeginGPU(FRHIComputeCommandList &RHICmdList)
Definition RenderGraphEvent.h:317
FStorage Impl
Definition RenderGraphEvent.h:298
Definition RHIStats.h:110
Definition MultiGPU.h:33
Definition Optional.h:131
Definition LightweightStats.h:416