UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
ShaderCompilerJobTypes.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include <atomic>
6#include "HAL/PlatformTime.h"
7#include "Hash/Blake3.h"
8#include "Shader.h"
11#include "VertexFactory.h"
12#include "Templates/Function.h"
13
18
19namespace UE::DerivedData { class FRequestOwner; }
20
40
46
47
75
92
94{
95public:
96 void Reset()
97 {
98 // Unset status before the input hash since GetInputHash() uses it as a substitute for lock guards
100 InputHash = nullptr;
101 IsDuplicate.store(false);
102 }
103
113
115 {
116 Status.store(NewStatus);
117 }
118
120 {
121 return Status.load();
122 }
123
124 void SetIsDuplicate(bool bDuplicate = true)
125 {
126 IsDuplicate.store(bDuplicate);
127 }
128
129 bool GetIsDuplicate() const
130 {
131 return IsDuplicate.load();
132 }
133
135 {
136 InputHash = InInputHash;
137 }
138
140 {
141 return InputHash ? *InputHash : FShaderCompilerInputHash::Zero;
142 }
143
144private:
145 const FShaderCompilerInputHash* InputHash = nullptr; // set when input hash is computed during submission
146 std::atomic<EShaderCompileJobStatus> Status{ EShaderCompileJobStatus::Unset };
147 std::atomic<bool> IsDuplicate{ false };
148};
149
152{
153public:
157
159
163
166
171
173
193
201 double TimeTaskSubmitJobs = 0.0;
203
205
207
214
219
221 {
222 return uint32(NumRefs.Increment());
223 }
224
226 {
227 uint32 Refs = uint32(NumRefs.Decrement());
228 if (Refs == 0)
229 {
230 Destroy();
231 }
232 return Refs;
233 }
235 {
236 return uint32(NumRefs.GetValue());
237 }
238
241
244
246 virtual void AppendDiagnostics(FString& OutDiagnostics, int32 InJobIndex, int32 InNumJobs, const TCHAR* Indentation = nullptr) const = 0;
247
252
253 UE_DEPRECATED(5.7, "Use overload of OnComplete accepting a context object")
254 virtual void OnComplete() = 0;
255
256 // Executed for all jobs (including those read from cache) on completion.
258
260
261 bool Equals(const FShaderCommonCompileJob& Rhs) const;
262
264 void ForEachSingleShaderJob(const TFunction<void(const FShaderCompileJob& SingleJob)>& Predicate) const;
266
269
273
296
298
299private:
301 static FThreadSafeCounter JobIdCounter;
302
303 void Destroy() const;
304};
306
308{
312
313 uint32 MakeHash(uint32 Id) const { return HashCombine(HashCombine(HashCombine(GetTypeHash(Id), GetTypeHash(VFType)), GetTypeHash(ShaderType)), GetTypeHash(PermutationId)); }
314 RENDERCORE_API FString ToString() const;
318
319 friend inline bool operator==(const FShaderCompileJobKey& Lhs, const FShaderCompileJobKey& Rhs)
320 {
321 return Lhs.VFType == Rhs.VFType && Lhs.ShaderType == Rhs.ShaderType && Lhs.PermutationId == Rhs.PermutationId;
322 }
323 friend inline bool operator!=(const FShaderCompileJobKey& Lhs, const FShaderCompileJobKey& Rhs)
324 {
325 return !operator==(Lhs, Rhs);
326 }
327};
328
331{
332public:
334
336
342
349
350 // List of pipelines that are sharing this job.
352
354
360
361 UE_DEPRECATED(5.7, "OnComplete now accepts a FDebugDataContext object")
362 virtual void OnComplete() override {}
363
365
366 virtual RENDERCORE_API void AppendDebugName(FStringBuilderBase& OutName) const override;
367
368 // Serializes only the subset of data written by SCW/read back from ShaderCompiler when using worker processes.
370
371 // Serializes only the subset of data written by ShaderCompiler and read from SCW when using worker processes.
373
375
376 // Serializes the compile job for a cook artifact for later analysis in a commandlet.
378
380
381 virtual RENDERCORE_API void AppendDiagnostics(FString& OutDiagnostics, int32 InJobIndex, int32 InNumJobs, const TCHAR* Indentation = nullptr) const override final;
382
385
390
391private:
392 void SerializeWorkerOutputInner(FArchive& Ar, bool bSerializeForArtifact = false);
393
394};
395
397{
401
402 uint32 MakeHash(uint32 Id) const { return HashCombine(HashCombine(HashCombine(GetTypeHash(Id), GetTypeHash(ShaderPipeline)), GetTypeHash(VFType)), GetTypeHash(PermutationId)); }
403
407
409 {
410 return Lhs.ShaderPipeline == Rhs.ShaderPipeline && Lhs.VFType == Rhs.VFType && Lhs.PermutationId == Rhs.PermutationId;
411 }
413 {
414 return !operator==(Lhs, Rhs);
415 }
416};
417
439
441inline const FShaderCompileJob* FShaderCommonCompileJob::GetSingleShaderJob() const { return Type == EShaderCompileJobType::Single ? static_cast<const FShaderCompileJob*>(this) : nullptr; }
444
446{
447 if (Type == Rhs.Type && Id == Rhs.Id)
448 {
449 switch (Type)
450 {
451 case EShaderCompileJobType::Single: return static_cast<const FShaderCompileJob*>(this)->Key == static_cast<const FShaderCompileJob&>(Rhs).Key;
452 case EShaderCompileJobType::Pipeline: return static_cast<const FShaderPipelineCompileJob*>(this)->Key == static_cast<const FShaderPipelineCompileJob&>(Rhs).Key;
453 default: checkNoEntry(); break;
454 }
455 }
456 return false;
457}
458
459inline void FShaderCommonCompileJob::Destroy() const
460{
461 switch (Type)
462 {
463 case EShaderCompileJobType::Single: delete static_cast<const FShaderCompileJob*>(this); break;
464 case EShaderCompileJobType::Pipeline: delete static_cast<const FShaderPipelineCompileJob*>(this); break;
465 default: checkNoEntry();
466 }
467}
468
470{
472 {
474 }
476 {
478 {
480 {
482 }
483 }
484 }
485}
486
488{
490 {
492 }
494 {
496 {
498 {
500 }
501 }
502 }
503}
OODEFFUNC typedef void(OODLE_CALLBACK t_fp_OodleCore_Plugin_Free)(void *ptr)
#define check(expr)
Definition AssertionMacros.h:314
#define checkNoEntry()
Definition AssertionMacros.h:316
@ INDEX_NONE
Definition CoreMiscDefines.h:150
#define UE_DEPRECATED(Version, Message)
Definition CoreMiscDefines.h:302
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
return true
Definition ExternalRpcRegistry.cpp:601
@ Num
Definition MetalRHIPrivate.h:234
EShaderCompileJobType
Definition ShaderCompilerCore.h:787
FBlake3Hash FShaderCompilerInputHash
Definition ShaderCompilerCore.h:200
EShaderCompilerWorkerType
Definition ShaderCompilerCore.h:780
RENDERCORE_API const TCHAR * LexToString(EShaderCompileJobStatus Status)
Definition ShaderCore.cpp:4283
EShaderCompileJobStatus
Definition ShaderCompilerJobTypes.h:77
EShaderCompileJobPriority
Definition ShaderCore.h:803
constexpr uint32 HashCombine(uint32 A, uint32 C)
Definition TypeHash.h:36
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition Archive.h:1208
Definition RefCounting.h:213
Definition ShaderCompilerJobTypes.h:152
uint8 bErrorsAreLikelyToBeCode
Definition ShaderCompilerJobTypes.h:178
FShaderJobCacheRef JobCacheRef
Definition ShaderCompilerJobTypes.h:204
virtual void AppendDebugName(FStringBuilderBase &OutName) const =0
void UpdateInputHash()
Definition ShaderCompilerJobTypes.h:208
FShaderCompileJob * GetSingleShaderJob()
Definition ShaderCompilerJobTypes.h:440
uint8 bBypassCache
Definition ShaderCompilerJobTypes.h:190
double TimeAddedToPendingQueue
Definition ShaderCompilerJobTypes.h:195
virtual ~FShaderCommonCompileJob()
Definition ShaderCompilerJobTypes.h:297
uint32 Id
Definition ShaderCompilerJobTypes.h:165
uint32 Hash
Definition ShaderCompilerJobTypes.h:162
FShaderPipelineCompileJob * GetShaderPipelineJob()
Definition ShaderCompilerJobTypes.h:442
uint32 Release() const
Definition ShaderCompilerJobTypes.h:225
FShaderCommonCompileJob * NextLink
Definition ShaderCompilerJobTypes.h:155
double TimeTaskSubmitJobsStall
Definition ShaderCompilerJobTypes.h:202
virtual void SerializeOutput(FShaderCacheSerializeContext &Ctx)
Definition ShaderCompilerJobTypes.h:243
uint32 GetRefCount() const
Definition ShaderCompilerJobTypes.h:234
virtual void AppendDiagnostics(FString &OutDiagnostics, int32 InJobIndex, int32 InNumJobs, const TCHAR *Indentation=nullptr) const =0
double TimeExecutionCompleted
Definition ShaderCompilerJobTypes.h:199
EShaderCompileJobPriority Priority
Definition ShaderCompilerJobTypes.h:168
uint8 bInputHashSet
Definition ShaderCompilerJobTypes.h:184
EShaderCompilerWorkerType CurrentWorker
Definition ShaderCompilerJobTypes.h:170
EShaderCompileJobPriority PendingPriority
Definition ShaderCompilerJobTypes.h:169
double TimeTaskSubmitJobs
Definition ShaderCompilerJobTypes.h:201
uint8 bIsGlobalShader
Definition ShaderCompilerJobTypes.h:188
static RENDERCORE_API uint32 GetNextJobId()
Definition ShaderCore.cpp:4330
FShaderCommonCompileJob ** PrevLink
Definition ShaderCompilerJobTypes.h:156
FThreadSafeCounter NumRefs
Definition ShaderCompilerJobTypes.h:160
int32 JobIndex
Definition ShaderCompilerJobTypes.h:161
TPimplPtr< UE::DerivedData::FRequestOwner > RequestOwner
Definition ShaderCompilerJobTypes.h:172
virtual FShaderCompilerInputHash GetInputHash()
Definition ShaderCompilerJobTypes.h:240
virtual void OnComplete()=0
void ForEachSingleShaderJob(const TFunction< void(const FShaderCompileJob &SingleJob)> &Predicate) const
EShaderCompileJobType Type
Definition ShaderCompilerJobTypes.h:167
uint8 bSucceeded
Definition ShaderCompilerJobTypes.h:177
FPendingShaderMapCompileResultsPtr PendingShaderMap
Definition ShaderCompilerJobTypes.h:158
FShaderCompilerInputHash InputHash
Definition ShaderCompilerJobTypes.h:192
uint8 bIsDefaultMaterial
Definition ShaderCompilerJobTypes.h:186
double TimeAssignedToExecution
Definition ShaderCompilerJobTypes.h:197
bool Equals(const FShaderCommonCompileJob &Rhs) const
Definition ShaderCompilerJobTypes.h:445
uint32 AddRef() const
Definition ShaderCompilerJobTypes.h:220
uint8 bReleased
Definition ShaderCompilerJobTypes.h:182
TSharedPtr< FShaderCompileJobStatus > JobStatusPtr
Definition ShaderCompilerJobTypes.h:206
uint8 bFinalized
Definition ShaderCompilerJobTypes.h:175
void UpdateStatus(EShaderCompileJobStatus NewStatus)
Definition ShaderCompilerJobTypes.h:215
Definition ShaderCompilerJobTypes.h:94
void SetInputHash(const FShaderCompilerInputHash *InInputHash)
Definition ShaderCompilerJobTypes.h:134
void SetIsDuplicate(bool bDuplicate=true)
Definition ShaderCompilerJobTypes.h:124
bool GetIsDuplicate() const
Definition ShaderCompilerJobTypes.h:129
EShaderCompileJobStatus GetStatus() const
Definition ShaderCompilerJobTypes.h:119
void Reset()
Definition ShaderCompilerJobTypes.h:96
const FShaderCompilerInputHash & GetInputHash() const
Definition ShaderCompilerJobTypes.h:139
void SetStatus(EShaderCompileJobStatus NewStatus)
Definition ShaderCompilerJobTypes.h:114
bool WasCompilationSkipped() const
Definition ShaderCompilerJobTypes.h:104
Definition ShaderCompilerJobTypes.h:331
void SerializeWorkerInputNoSource(FArchive &Ar)
Definition ShaderCore.cpp:4669
static const EShaderCompileJobType Type
Definition ShaderCompilerJobTypes.h:333
TUniquePtr< FShaderCompilerOutput > SecondaryOutput
Definition ShaderCompilerJobTypes.h:348
FShaderPreprocessOutput PreprocessOutput
Definition ShaderCompilerJobTypes.h:345
RENDERCORE_API void SerializeOutput(FShaderCacheSerializeContext &Ctx, int32 CodeIndex)
Definition ShaderCore.cpp:4424
virtual void OnComplete() override
Definition ShaderCompilerJobTypes.h:362
virtual RENDERCORE_API FShaderCompilerInputHash GetInputHash() override
Definition ShaderCore.cpp:4363
virtual RENDERCORE_API void AppendDiagnostics(FString &OutDiagnostics, int32 InJobIndex, int32 InNumJobs, const TCHAR *Indentation=nullptr) const override final
Definition ShaderCore.cpp:4709
RENDERCORE_API void SerializeArtifact(FArchive &Ar)
Definition ShaderCore.cpp:4684
FShaderCompilerInput Input
Definition ShaderCompilerJobTypes.h:344
FShaderCompilerOutput Output
Definition ShaderCompilerJobTypes.h:347
TMap< const FVertexFactoryType *, TArray< const FShaderPipelineType * > > SharingPipelines
Definition ShaderCompilerJobTypes.h:351
virtual RENDERCORE_API void AppendDebugName(FStringBuilderBase &OutName) const override
Definition ShaderCore.cpp:4570
virtual void SerializeOutput(FShaderCacheSerializeContext &Ctx)
Definition ShaderCompilerJobTypes.h:356
RENDERCORE_API void SerializeWorkerOutput(FArchive &Ar)
Definition ShaderCore.cpp:4586
RENDERCORE_API void SerializeWorkerInput(FArchive &Ar)
Definition ShaderCore.cpp:4650
FShaderCompileJobKey Key
Definition ShaderCompilerJobTypes.h:335
TSharedPtr< const FShaderType::FParameters, ESPMode::ThreadSafe > ShaderParameters
Definition ShaderCompilerJobTypes.h:341
FShaderCompileJob(uint32 InHash, uint32 InId, EShaderCompileJobPriority InPriroity, const FShaderCompileJobKey &InKey)
Definition ShaderCompilerJobTypes.h:386
TUniquePtr< FShaderPreprocessOutput > SecondaryPreprocessOutput
Definition ShaderCompilerJobTypes.h:346
RENDERCORE_API FStringView GetFinalSourceView() const
Definition ShaderCore.cpp:4692
Definition ShaderCompiler.h:894
Definition ShaderCompilerJobTypes.h:419
static const EShaderCompileJobType Type
Definition ShaderCompilerJobTypes.h:421
virtual RENDERCORE_API void SerializeOutput(FShaderCacheSerializeContext &Ctx) override
Definition ShaderCore.cpp:4756
TArray< TRefCountPtr< FShaderCompileJob > > StageJobs
Definition ShaderCompilerJobTypes.h:424
virtual RENDERCORE_API FShaderCompilerInputHash GetInputHash() override
Definition ShaderCore.cpp:4303
void OnComplete() override
Definition ShaderCompilerJobTypes.h:431
virtual RENDERCORE_API void AppendDiagnostics(FString &OutDiagnostics, int32 InJobIndex, int32 InNumJobs, const TCHAR *Indentation=nullptr) const override final
Definition ShaderCore.cpp:4832
FShaderPipelineCompileJobKey Key
Definition ShaderCompilerJobTypes.h:423
virtual RENDERCORE_API void AppendDebugName(FStringBuilderBase &OutName) const override
Definition ShaderCore.cpp:4821
Definition Shader.h:1931
Definition ShaderPreprocessTypes.h:64
Definition Shader.h:1238
Definition ThreadSafeCounter.h:14
int32 Increment()
Definition ThreadSafeCounter.h:52
int32 Decrement()
Definition ThreadSafeCounter.h:75
int32 GetValue() const
Definition ThreadSafeCounter.h:120
Definition VertexFactory.h:314
Definition Array.h:670
Definition AndroidPlatformMisc.h:14
Definition UnrealString.h.inl:34
Definition SharedPointer.h:692
Definition UniquePtr.h:107
Definition DerivedData.cpp:40
@ false
Definition radaudio_common.h:23
Definition AndroidPlatformTime.h:18
Definition Blake3.h:27
static const FBlake3Hash Zero
Definition Blake3.h:56
Definition ShaderCompilerJobTypes.h:44
Definition ShaderSerialization.h:66
Definition ShaderCompilerJobTypes.h:308
FShaderCompileJobKey(const FShaderType *InType=nullptr, const FVertexFactoryType *InVFType=nullptr, int32 InPermutationId=0)
Definition ShaderCompilerJobTypes.h:309
int32 PermutationId
Definition ShaderCompilerJobTypes.h:317
friend bool operator==(const FShaderCompileJobKey &Lhs, const FShaderCompileJobKey &Rhs)
Definition ShaderCompilerJobTypes.h:319
RENDERCORE_API FString ToString() const
Definition ShaderCore.cpp:4340
uint32 MakeHash(uint32 Id) const
Definition ShaderCompilerJobTypes.h:313
friend bool operator!=(const FShaderCompileJobKey &Lhs, const FShaderCompileJobKey &Rhs)
Definition ShaderCompilerJobTypes.h:323
const FVertexFactoryType * VFType
Definition ShaderCompilerJobTypes.h:316
const FShaderType * ShaderType
Definition ShaderCompilerJobTypes.h:315
Definition ShaderCompilerCore.h:210
Definition ShaderCompilerCore.h:491
Definition ShaderCompilerCore.h:203
Definition ShaderCompilerJobTypes.h:58
int32 IndexInBlock
Definition ShaderCompilerJobTypes.h:63
int32 DuplicateIndex
Definition ShaderCompilerJobTypes.h:66
void Clear()
Definition ShaderCompilerJobTypes.h:68
struct FShaderJobDataBlock * Block
Definition ShaderCompilerJobTypes.h:60
Definition ShaderCompilerJobCache.cpp:299
Definition ShaderCompilerJobTypes.h:23
TArray< TRefCountPtr< class FShaderCommonCompileJob > > FinishedJobs
Definition ShaderCompilerJobTypes.h:33
double TimeStarted
Definition ShaderCompilerJobTypes.h:37
bool bSkipResultProcessing
Definition ShaderCompilerJobTypes.h:36
void CheckIfHung()
Definition ShaderCompiler.cpp:2589
bool bAllJobsSucceeded
Definition ShaderCompilerJobTypes.h:35
FThreadSafeCounter NumPendingJobs
Definition ShaderCompilerJobTypes.h:34
bool bIsHung
Definition ShaderCompilerJobTypes.h:38
FShaderMapCompileResults()
Definition ShaderCompilerJobTypes.h:24
Definition ShaderCompilerJobTypes.h:397
const FVertexFactoryType * VFType
Definition ShaderCompilerJobTypes.h:405
FShaderPipelineCompileJobKey(const FShaderPipelineType *InType=nullptr, const FVertexFactoryType *InVFType=nullptr, int32 InPermutationId=0)
Definition ShaderCompilerJobTypes.h:398
friend bool operator!=(const FShaderPipelineCompileJobKey &Lhs, const FShaderPipelineCompileJobKey &Rhs)
Definition ShaderCompilerJobTypes.h:412
uint32 MakeHash(uint32 Id) const
Definition ShaderCompilerJobTypes.h:402
const FShaderPipelineType * ShaderPipeline
Definition ShaderCompilerJobTypes.h:404
int32 PermutationId
Definition ShaderCompilerJobTypes.h:406
friend bool operator==(const FShaderPipelineCompileJobKey &Lhs, const FShaderPipelineCompileJobKey &Rhs)
Definition ShaderCompilerJobTypes.h:408
Definition PimplPtr.h:50