UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
OverridePassSequence.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "ScreenPass.h"
7
8
21template <typename EPass>
23{
24public:
28
30 {
31#if RDG_ENABLE_DEBUG
32 if (bFinalized)
33 {
34 for (int32 PassIndex = 0; PassIndex < PassCountMax; ++PassIndex)
35 {
36 if (Passes[PassIndex].bEnabled)
37 {
38 checkf(Passes[PassIndex].bAccepted, TEXT("Pass was enabled but not accepted: %s."), Passes[PassIndex].Name);
39 }
40 }
41 }
42#endif
43 }
44
45 void SetName(EPass Pass, const TCHAR* Name)
46 {
47#if RDG_ENABLE_DEBUG
48 Passes[(int32)Pass].Name = Name;
49#endif
50 }
51
52 void SetNames(const TCHAR* const* Names, uint32 NameCount)
53 {
54#if RDG_ENABLE_DEBUG
55 check(NameCount == PassCountMax);
56 for (int32 PassIndex = 0; PassIndex < PassCountMax; ++PassIndex)
57 {
58 Passes[PassIndex].Name = Names[PassIndex];
59 }
60#endif
61 }
62
63 void SetEnabled(EPass Pass, bool bEnabled)
64 {
65 const int32 PassIndex = (int32)Pass;
66
67#if RDG_ENABLE_DEBUG
68 check(!bFinalized);
69 checkf(!Passes[PassIndex].bAssigned, TEXT("Pass cannot be assigned multiple times: %s."), Passes[PassIndex].Name);
70 Passes[PassIndex].bAssigned = true;
71#endif
72
73 Passes[PassIndex].bEnabled = bEnabled;
74 }
75
76 bool IsEnabled(EPass Pass) const
77 {
78 const int32 PassIndex = (int32)Pass;
79#if RDG_ENABLE_DEBUG
80 check(Passes[PassIndex].bAssigned);
81#endif
82 return Passes[PassIndex].bEnabled;
83 }
84
85 bool IsLastPass(EPass Pass) const
86 {
87#if RDG_ENABLE_DEBUG
88 check(bFinalized);
89#endif
90 return Pass == LastPass;
91 }
92
94 {
95#if RDG_ENABLE_DEBUG
96 const int32 PassIndex = (int32)Pass;
97
98 check(bFinalized);
99 checkf(NextPass == Pass, TEXT("Pass was accepted out of order: %s. Expected %s."), Passes[PassIndex].Name, Passes[(int32)NextPass].Name);
100 checkf(Passes[PassIndex].bEnabled, TEXT("Only accepted passes can be enabled: %s."), Passes[PassIndex].Name);
101
102 Passes[PassIndex].bAccepted = true;
103
104 // Walk the remaining passes until we hit one that's enabled. This will be the next pass to add.
105 for (int32 NextPassIndex = int32(NextPass) + 1; NextPassIndex < PassCountMax; ++NextPassIndex)
106 {
107 if (Passes[NextPassIndex].bEnabled)
108 {
110 break;
111 }
112 }
113#endif
114 }
115
117 {
118 const int32 PassIndex = (int32)Pass;
120
122 {
123 bHasMoreAfterPassCallbacks = AfterPassCallbackIndex.GetValue() < AfterPass[PassIndex].Num() - 1;
124 }
125 else
126 {
127 bHasMoreAfterPassCallbacks = AfterPass[PassIndex].Num() > 0;
128
129 // Display debug information for a Pass unless it is an after pass.
131 }
132
133 // We need to override output only if this is the last pass and the last after pass.
134 if (AcceptOverrideInPassIndex == PassIndex && !bHasMoreAfterPassCallbacks)
135 {
136 OutTargetToOverride = OverrideOutput;
137 return true;
138 }
139
140 return false;
141 }
142
143 void Finalize()
144 {
145#if RDG_ENABLE_DEBUG
146 check(!bFinalized);
147 bFinalized = true;
148
149 for (int32 PassIndex = 0; PassIndex < PassCountMax; ++PassIndex)
150 {
151 checkf(Passes[PassIndex].bAssigned, TEXT("Pass was not assigned to enabled or disabled: %s."), Passes[PassIndex].Name);
152 }
153#endif
154
155 bool bFirstPass = true;
156
157 for (int32 PassIndex = 0; PassIndex < PassCountMax; ++PassIndex)
158 {
159 if (Passes[PassIndex].bEnabled)
160 {
161 if (bFirstPass)
162 {
163#if RDG_ENABLE_DEBUG
165#endif
166 bFirstPass = false;
167 }
168 LastPass = (EPass)PassIndex;
169 AcceptOverrideInPassIndex = PassIndex;
170 }
171
172 // We can have callbacks for disabled passes which come after the last enabled pass. In that case we only
173 // accept the output override for the last callback of that pass, regardless of its state.
174 if (AfterPass[PassIndex].Num() > 0)
175 {
176 AcceptOverrideInPassIndex = PassIndex;
177 }
178 }
179 }
180
186
187private:
188 static const int32 PassCountMax = (int32)EPass::MAX;
189
190 struct FPassInfo
191 {
192#if RDG_ENABLE_DEBUG
193 const TCHAR* Name = nullptr;
194 bool bAssigned = false;
195 bool bAccepted = false;
196#endif
197 bool bEnabled = false;
198 };
199
200 FScreenPassRenderTarget OverrideOutput;
203 EPass LastPass = EPass::MAX;
204 int32 AcceptOverrideInPassIndex = PassCountMax;
205
206#if RDG_ENABLE_DEBUG
207 EPass NextPass = EPass(0);
208 bool bFinalized = false;
209#endif
210};
#define check(expr)
Definition AssertionMacros.h:314
#define checkf(expr, format,...)
Definition AssertionMacros.h:315
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::TCHAR TCHAR
Either ANSICHAR or WIDECHAR, depending on whether the platform supports wide characters or the requir...
Definition Platform.h:1135
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
@ Num
Definition MetalRHIPrivate.h:234
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition Array.h:670
Definition OverridePassSequence.h:23
void SetEnabled(EPass Pass, bool bEnabled)
Definition OverridePassSequence.h:63
bool AcceptOverrideIfLastPass(EPass Pass, FScreenPassRenderTarget &OutTargetToOverride, const TOptional< int32 > &AfterPassCallbackIndex=TOptional< int32 >())
Definition OverridePassSequence.h:116
TOverridePassSequence(const FScreenPassRenderTarget &InOverrideOutput)
Definition OverridePassSequence.h:25
void AcceptPass(EPass Pass)
Definition OverridePassSequence.h:93
FAfterPassCallbackDelegateArray & GetAfterPassCallbacks(EPass Pass)
Definition OverridePassSequence.h:181
bool IsLastPass(EPass Pass) const
Definition OverridePassSequence.h:85
void Finalize()
Definition OverridePassSequence.h:143
~TOverridePassSequence()
Definition OverridePassSequence.h:29
bool IsEnabled(EPass Pass) const
Definition OverridePassSequence.h:76
void SetName(EPass Pass, const TCHAR *Name)
Definition OverridePassSequence.h:45
void SetNames(const TCHAR *const *Names, uint32 NameCount)
Definition OverridePassSequence.h:52
Definition StaticArray.h:26
Definition ScreenPass.h:83
Definition Optional.h:131