UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
ShaderPipelineCache.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
8#pragma once
9
10#include "CoreMinimal.h"
11#include "Containers/List.h"
12#include "Stats/Stats.h"
13#include "RHI.h"
15#include "PipelineFileCache.h"
18
20class FRHIBlendState;
24class FSHAHash;
28
79{
80 // the FShaderPipelineCacheTask class represents a pipeline precompile of a single PSO file cache.
82public:
89 static RENDERCORE_API void Shutdown();
90
92 static RENDERCORE_API void PauseBatching();
93
94 enum class BatchMode
95 {
96 Background, // The maximum batch size is defined by r.ShaderPipelineCache.BackgroundBatchSize
97 Fast, // The maximum batch size is defined by r.ShaderPipelineCache.BatchSize
98 Precompile // The maximum batch size is defined by r.ShaderPipelineCache.PrecompileBatchSize
99 };
100
102 static RENDERCORE_API void SetBatchMode(BatchMode Mode);
103
105 static RENDERCORE_API void ResumeBatching();
106
108 static RENDERCORE_API bool IsPrecompiling();
109
113
116
119
122
125
127
133
134 static RENDERCORE_API bool IsBatchingPaused();
135
138
139 RENDERCORE_API bool IsTickable() const;
140
141 RENDERCORE_API void Tick( FRHICommandListImmediate& RHICmdList, float DeltaTime );
142
143 UE_DEPRECATED(5.7, "Tick needs a command list")
144 RENDERCORE_API void Tick( float DeltaTime );
145
147
149
156
159
162 {
163 bool bSlowPrecompileTask = false;
164 FString CacheName;
165 public:
168
169 const FString& GetCacheName() const { return CacheName; }
170 void SetPrecompilationIsSlowTask() { bSlowPrecompileTask = true; }
171 bool IsPrecompilationSlowTask() const { return bSlowPrecompileTask; }
172 };
173
177 DECLARE_MULTICAST_DELEGATE_ThreeParams(FShaderCachePreOpenDelegate, FString const& /* Name */, EShaderPlatform /* Platform*/, bool& /* Ready */);
178
182 static FShaderCachePreOpenDelegate& GetCachePreOpenDelegate() { return OnCachePreOpen; }
183
187 DECLARE_MULTICAST_DELEGATE_FiveParams(FShaderCacheOpenedDelegate, FString const& /* Name */, EShaderPlatform /* Platform*/, uint32 /* Count */, const FGuid& /* CacheFileGuid */, FShaderCachePrecompileContext& /*ShaderCachePrecompileContext*/);
188
192 static FShaderCacheOpenedDelegate& GetCacheOpenedDelegate() { return OnCachedOpened; }
193
198
202 static FShaderCacheClosedDelegate& GetCacheClosedDelegate() { return OnCachedClosed; }
203
208
213
217 static FShaderPrecompilationBeginDelegate& GetPrecompilationBeginDelegate() { return OnPrecompilationBegin; }
218
223
224private:
225 static inline FShaderPipelineCache* Get() { return ShaderPipelineCache; }
226
227 RENDERCORE_API bool OpenPipelineFileCacheInternal(bool bUserCache, const FString& PSOCacheKey, const FString& CacheName, EShaderPlatform Platform);
228
229 RENDERCORE_API void BeginNextPrecompileCacheTask();
230 RENDERCORE_API void BeginNextPrecompileCacheTaskInternal();
231 RENDERCORE_API bool ReadyForAutoSave() const;
232
233 RENDERCORE_API void ClearPendingPrecompileTaskQueue();
234 RENDERCORE_API void EnqueuePendingPrecompileTask(const FString& PSOCacheKey);
235 RENDERCORE_API int ApplyNewUsageMaskToAllTasks(uint64 Mask);
236
240
241private:
242 static RENDERCORE_API FShaderPipelineCache* ShaderPipelineCache;
243 static RENDERCORE_API uint32 BatchSize;
244 static RENDERCORE_API float BatchTime;
245 bool bPaused;
246 int32 PausedCount;
247 double LastAutoSaveTime = 0.0;
248 double LastAutoSaveTimeLogBoundPSO = 0.0;
249 int32 LastAutoSaveNum = 0;
250 TSet<uint32> CompiledHashes;
251
254
255 static RENDERCORE_API FString UserCacheTaskKey;
256
257 struct FPipelineCachePSOContext
258 {
259 FString FileName;
260 EShaderPlatform CurrentPlatform;
261
262 FShaderCachePrecompileContext PrecompileContext;
263 };
264
266
267 class FShaderPipelineCacheTask* GetTask(const FString& Name) {
268 TUniquePtr<class FShaderPipelineCacheTask>* CacheTask = FShaderPipelineCache::Get()->ShaderCacheTasks.Find(Name);
269 return CacheTask ? CacheTask->Get() : nullptr;
270 }
271
272 // The list of pending PSO cache names to precompile.
273 TArray<FString> PendingPrecompilePSOCacheKeys;
274
275 // The name of the current precompiling PSO cache.
276 FString CurrentPrecompilingPSOFCKey;
277
278 // Used for threadsafe query of pending pipeline compiles.
279 std::atomic_bool bHasShaderPipelineTask = false;
280
281 mutable FCriticalSection Mutex;
282 FGraphEventRef NextPrecompileCacheTask;
283
284 static RENDERCORE_API FShaderCachePreOpenDelegate OnCachePreOpen;
285 static RENDERCORE_API FShaderCacheOpenedDelegate OnCachedOpened;
286 static RENDERCORE_API FShaderCacheClosedDelegate OnCachedClosed;
287 static RENDERCORE_API FShaderPrecompilationBeginDelegate OnPrecompilationBegin;
288 static RENDERCORE_API FShaderPrecompilationCompleteDelegate OnPrecompilationComplete;
289
293};
#define UE_DEPRECATED(Version, Message)
Definition CoreMiscDefines.h:302
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
UE::FPlatformRecursiveMutex FCriticalSection
Definition CriticalSection.h:53
bool(* FPSOMaskComparisonFn)(uint64 ReferenceMask, uint64 PSOMask)
Definition PipelineFileCache.h:295
EShaderPlatform
Definition RHIShaderPlatform.h:11
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition RHI.h:403
SaveMode
Definition PipelineFileCache.h:317
Definition RHIResources.h:696
Definition RHICommandList.h:4626
Definition RHIResources.h:686
Definition RHIResources.h:679
Definition SecureHash.h:226
Definition ShaderPipelineCache.cpp:287
Definition ShaderPipelineCache.cpp:405
Definition ShaderPipelineCache.h:162
const FString & GetCacheName() const
Definition ShaderPipelineCache.h:169
void SetPrecompilationIsSlowTask()
Definition ShaderPipelineCache.h:170
FShaderCachePrecompileContext(const FString &CacheNameIn)
Definition ShaderPipelineCache.h:167
bool IsPrecompilationSlowTask() const
Definition ShaderPipelineCache.h:171
Definition ShaderPipelineCache.h:79
static RENDERCORE_API bool OpenPipelineFileCache(EShaderPlatform Platform)
Definition ShaderPipelineCache.cpp:852
DECLARE_MULTICAST_DELEGATE_ThreeParams(FShaderPrecompilationCompleteDelegate, uint32, double, const FShaderCachePrecompileContext &)
static RENDERCORE_API void PauseBatching()
Definition ShaderPipelineCache.cpp:754
static RENDERCORE_API void Shutdown()
Definition ShaderPipelineCache.cpp:745
static FShaderCacheOpenedDelegate & GetCacheOpenedDelegate()
Definition ShaderPipelineCache.h:192
RENDERCORE_API TStatId GetStatId() const
Definition ShaderPipelineCache.cpp:2018
ELibraryState
Definition ShaderPipelineCache.h:151
@ Opened
Definition ShaderPipelineCache.h:152
@ Closed
Definition ShaderPipelineCache.h:154
@ OpenedComponent
Definition ShaderPipelineCache.h:153
DECLARE_MULTICAST_DELEGATE_FiveParams(FShaderCacheOpenedDelegate, FString const &, EShaderPlatform, uint32, const FGuid &, FShaderCachePrecompileContext &)
static FShaderCachePreOpenDelegate & GetCachePreOpenDelegate()
Definition ShaderPipelineCache.h:182
static RENDERCORE_API bool SetGameUsageMaskWithComparison(uint64 Mask, FPSOMaskComparisonFn InComparisonFnPtr)
Definition ShaderPipelineCache.cpp:668
static FShaderCacheClosedDelegate & GetCacheClosedDelegate()
Definition ShaderPipelineCache.h:202
RENDERCORE_API bool NeedsRenderingResumedForRenderingThreadTick() const
Definition ShaderPipelineCache.cpp:2013
DECLARE_MULTICAST_DELEGATE_ThreeParams(FShaderCachePreOpenDelegate, FString const &, EShaderPlatform, bool &)
static RENDERCORE_API void CloseUserPipelineFileCache()
Definition ShaderPipelineCache.cpp:928
RENDERCORE_API bool IsTickable() const
Definition ShaderPipelineCache.cpp:1773
DECLARE_MULTICAST_DELEGATE_TwoParams(FShaderCacheClosedDelegate, FString const &, EShaderPlatform)
static RENDERCORE_API int32 GetGameVersionForPSOFileCache()
Definition ShaderPipelineCache.cpp:645
static RENDERCORE_API bool OpenUserPipelineFileCache(EShaderPlatform Platform)
Definition ShaderPipelineCache.cpp:874
BatchMode
Definition ShaderPipelineCache.h:95
static RENDERCORE_API bool IsPrecompiling()
Definition ShaderPipelineCache.cpp:1726
virtual RENDERCORE_API ~FShaderPipelineCache()
Definition ShaderPipelineCache.cpp:1639
static RENDERCORE_API void SetBatchMode(BatchMode Mode)
Definition ShaderPipelineCache.cpp:776
static RENDERCORE_API void ShaderLibraryStateChanged(ELibraryState State, EShaderPlatform Platform, FString const &Name, int32 ComponentID)
Definition ShaderPipelineCache.cpp:958
static RENDERCORE_API uint32 NumPrecompilesRemaining()
Definition ShaderPipelineCache.cpp:824
static RENDERCORE_API bool IsBatchingPaused()
Definition ShaderPipelineCache.cpp:767
DECLARE_MULTICAST_DELEGATE_TwoParams(FShaderPrecompilationBeginDelegate, uint32, const FShaderCachePrecompileContext &)
static FShaderPrecompilationCompleteDelegate & GetPrecompilationCompleteDelegate()
Definition ShaderPipelineCache.h:222
static FShaderPrecompilationBeginDelegate & GetPrecompilationBeginDelegate()
Definition ShaderPipelineCache.h:217
static RENDERCORE_API bool SavePipelineFileCache(FPipelineFileCacheManager::SaveMode Mode)
Definition ShaderPipelineCache.cpp:911
static RENDERCORE_API void ResumeBatching()
Definition ShaderPipelineCache.cpp:809
Definition TickableObjectRenderThread.h:15
Definition Array.h:670
Definition UnrealString.h.inl:34
Definition UniquePtr.h:107
Definition ShaderStableKeyDebugInfoReader.h:19
Definition Guid.h:109
Definition RHI.h:278
Definition LightweightStats.h:416