UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
ShaderKeyGenerator.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
7#include "CoreTypes.h"
10#include "UObject/NameTypes.h"
11
12class FSHAHash;
13struct FBlake3Hash;
14struct FGuid;
15
29{
30public:
32 inline FShaderKeyGenerator(TUniqueFunction<void(const void* Data, uint64 Size)>&& InResultFunc);
34 inline FShaderKeyGenerator(FString& InResultString);
36
41 inline bool IsBinary() const;
43 inline bool IsText() const;
44
46 inline void BinaryAppend(const void* Data, uint64 Size);
48 inline FString& TextGetResultString();
49
51 inline void Append(FStringView Value);
56 inline void Append(const TCHAR* Value);
58 inline void Append(FName Value);
60 inline void Append(int64 Value);
62 inline void Append(uint64 Value);
64 inline void Append(int32 Value);
66 inline void Append(uint32 Value);
68 inline void AppendHex(uint32 Value);
70 inline void AppendBoolInt(bool Value);
72 CORE_API void Append(const FBlake3Hash& Value);
74 CORE_API void Append(const FGuid& Value);
76 CORE_API void Append(const FSHAHash& Value);
77
81 inline void AppendSeparator();
82
83private:
84 enum class EOutputType
85 {
86 Text,
87 Binary,
88 };
89
90private:
91 TUniqueFunction<void(const void* Data, uint64 Size)> ResultFunc;
92 FString* ResultString = nullptr;
93 EOutputType OutputType = EOutputType::Text;
94};
95
96
98// Global functions taking FShaderKeyGenerator argument
100
102template <typename T>
104
106template <typename T>
107void Append(FShaderKeyGenerator& KeyGen, const TArray<T>& Value);
108
116// template <typename T>
117// FShaderKeyGenerator& operator<<(FShaderKeyGenerator& KeyGen, const T& Value);
118
119
121// Inline implementations
123
125 : ResultFunc(MoveTemp(InResultFunc))
126 , OutputType(EOutputType::Binary)
127{
128}
129
131 : ResultString(&InResultString)
132 , OutputType(EOutputType::Text)
133{
134}
135
136// This destructor needs to be defined so that it can be called manually from union destructors.
138
140{
141 return OutputType == EOutputType::Binary;
142}
143
145{
146 return OutputType == EOutputType::Text;
147}
148
149inline void FShaderKeyGenerator::BinaryAppend(const void* Data, uint64 Size)
150{
151 check(IsBinary());
152 ResultFunc(Data, Size);
153}
154
156{
157 check(IsText());
158 return *ResultString;
159}
160
162{
163 switch (OutputType)
164 {
165 case EOutputType::Text:
166 ResultString->Append(Value);
167 return;
168 case EOutputType::Binary:
169 ResultFunc(Value.GetData(), Value.Len() * sizeof(Value.GetData()[0]));
170 return;
171 default:
172 checkNoEntry();
173 }
174}
175
177{
179}
180
182{
183 switch (OutputType)
184 {
185 case EOutputType::Text:
186 Value.AppendString(*ResultString);
187 return;
188 case EOutputType::Binary:
189 {
191 ResultFunc(Builder.GetData(), Builder.Len() * sizeof(Builder.GetData()[0]));
192 return;
193 }
194 default:
195 checkNoEntry();
196 }
197}
198
200{
201 switch (OutputType)
202 {
203 case EOutputType::Text:
204 ResultString->Appendf(TEXT(INT64_FMT), Value);
205 return;
206 case EOutputType::Binary:
207 ResultFunc(&Value, sizeof(Value));
208 return;
209 default:
210 checkNoEntry();
211 }
212}
213
215{
216 switch (OutputType)
217 {
218 case EOutputType::Text:
219 ResultString->Appendf(TEXT(UINT64_FMT), Value);
220 return;
221 case EOutputType::Binary:
222 ResultFunc(&Value, sizeof(Value));
223 return;
224 default:
225 checkNoEntry();
226 }
227}
228
230{
231 switch (OutputType)
232 {
233 case EOutputType::Text:
234 ResultString->Appendf(TEXT("%d"), Value);
235 return;
236 case EOutputType::Binary:
237 ResultFunc(&Value, sizeof(Value));
238 return;
239 default:
240 checkNoEntry();
241 }
242}
243
245{
246 switch (OutputType)
247 {
248 case EOutputType::Text:
249 ResultString->Appendf(TEXT("%u"), Value);
250 return;
251 case EOutputType::Binary:
252 ResultFunc(&Value, sizeof(Value));
253 return;
254 default:
255 checkNoEntry();
256 }
257}
258
260{
261 switch (OutputType)
262 {
263 case EOutputType::Text:
264 ResultString->Appendf(TEXT("%X"), Value);
265 return;
266 case EOutputType::Binary:
267 ResultFunc(&Value, sizeof(Value));
268 return;
269 default:
270 checkNoEntry();
271 }
272}
273
275{
276 switch (OutputType)
277 {
278 case EOutputType::Text:
279 ResultString->AppendChar(Value ? '1' : '0');
280 return;
281 case EOutputType::Binary:
282 {
283 uint8 SizedValue = Value ? 1 : 0;
284 ResultFunc(&SizedValue, sizeof(SizedValue));
285 return;
286 }
287 default:
288 checkNoEntry();
289 }
290}
291
293{
294 switch (OutputType)
295 {
296 case EOutputType::Text:
297 ResultString->Append(Value);
298 return;
299 case EOutputType::Binary:
300 // Binary output ignores DebugText
301 return;
302 default:
303 checkNoEntry();
304 }
305}
306
308{
309 switch (OutputType)
310 {
311 case EOutputType::Text:
312 ResultString->AppendChar('_');
313 return;
314 case EOutputType::Binary:
315 // Binary output ignores DebugText; Separator is a type of DebugText
316 return;
317 default:
318 checkNoEntry();
319 }
320}
321
322template <typename T>
324{
326}
327
328template <typename T>
330{
331 for (const T& Element : Value)
332 {
333 KeyGen << Element;
334 }
335}
336
341template <typename T, typename = int>
343 : std::false_type
344{
345};
346
351template <typename T>
352struct IsFShaderKeyGeneratorKnownType<T, decltype(std::declval<FShaderKeyGenerator>().Append(std::declval<T>()), 0)>
353 : std::true_type
354{
355};
356
358template <typename T>
359typename std::enable_if<IsFShaderKeyGeneratorKnownType<T>::value, FShaderKeyGenerator&>::type
360operator<<(FShaderKeyGenerator& KeyGen, const T& Value)
361{
362 KeyGen.Append(Value);
363 return KeyGen;
364}
365
367template <typename T>
368typename std::enable_if<!IsFShaderKeyGeneratorKnownType<T>::value, FShaderKeyGenerator&>::type
369operator<<(FShaderKeyGenerator& KeyGen, const T& Value)
370{
371 Append(KeyGen, Value);
372 return KeyGen;
373}
374
OODEFFUNC typedef void(OODLE_CALLBACK t_fp_OodleCore_Plugin_Free)(void *ptr)
#define UINT64_FMT
Definition AndroidPlatformString.h:66
#define INT64_FMT
Definition AndroidPlatformString.h:59
#define check(expr)
Definition AssertionMacros.h:314
#define checkNoEntry()
Definition AssertionMacros.h:316
@ InPlace
Definition CoreMiscDefines.h:162
#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::int64 int64
A 64-bit signed integer.
Definition Platform.h:1127
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
std::enable_if< IsFShaderKeyGeneratorKnownType< T >::value, FShaderKeyGenerator & >::type operator<<(FShaderKeyGenerator &KeyGen, const T &Value)
Definition ShaderKeyGenerator.h:360
TStringView< TCHAR > FStringView
Definition StringFwd.h:45
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
uint32 Size
Definition VulkanMemory.cpp:4034
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition NameTypes.h:617
Definition SecureHash.h:226
Definition ShaderKeyGenerator.h:29
FShaderKeyGenerator(TUniqueFunction< void(const void *Data, uint64 Size)> &&InResultFunc)
Definition ShaderKeyGenerator.h:124
void AppendSeparator()
Definition ShaderKeyGenerator.h:307
void AppendBoolInt(bool Value)
Definition ShaderKeyGenerator.h:274
void BinaryAppend(const void *Data, uint64 Size)
Definition ShaderKeyGenerator.h:149
void Append(FStringView Value)
Definition ShaderKeyGenerator.h:161
bool IsText() const
Definition ShaderKeyGenerator.h:144
void AppendHex(uint32 Value)
Definition ShaderKeyGenerator.h:259
void AppendDebugText(FStringView Value)
Definition ShaderKeyGenerator.h:292
bool IsBinary() const
Definition ShaderKeyGenerator.h:139
FString & TextGetResultString()
Definition ShaderKeyGenerator.h:155
Definition Array.h:670
CharType * GetData() UE_LIFETIMEBOUND
Definition StringBuilder.h:120
int32 Len() const
Definition StringBuilder.h:114
Definition StringBuilder.h:509
Definition FunctionFwd.h:19
Definition Blake3.h:27
Definition Guid.h:109
Definition ShaderKeyGenerator.h:344