UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
PSOPrecacheValidation.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3/*=============================================================================
4 PSOPrecacheValidation.h
5=============================================================================*/
6
7#pragma once
8
9#include "PSOPrecache.h"
10#include "PSOPrecacheMaterial.h"
12#include "MaterialShared.h"
13
14// enable detailed tracking of all PSO request for better logging on PSO misses
15#define PSO_PRECACHING_TRACKING !WITH_EDITOR && !UE_BUILD_SHIPPING && !UE_BUILD_TEST && UE_WITH_PSO_PRECACHING
16
17#if UE_WITH_PSO_PRECACHING
18
19#if PSO_PRECACHING_VALIDATE
20
23
27extern ENGINE_API void ConditionalBreakOnPSOPrecacheMaterial(const FMaterial& Material, int32 PSOCollectorIndex);
28
34
38enum class EPSOPrecacheMissType : uint8
39{
40 ShadersOnly = 0, //< ShaderOnly miss - all other states not checked
41 MinimalPSOState, //< MinimalGraphicsPSO miss - shaders match, but render state is different than precached data
42 FullPSO //< Full PSO precache miss - minimal graphics PSO match, but bound render target and depth stencil state is different
43};
44
48extern ENGINE_API void LogPSOMissInfo(
49 const FGraphicsPipelineStateInitializer& GraphicsPSOInitializer,
52 const FMaterial* Material,
53 const FVertexFactoryType* VFType,
54 const FPrimitiveSceneProxy* PrimitiveSceneProxy,
56 int32 PSOCollectorIndex,
58
62extern ENGINE_API void LogPSOMissInfo(
65 const FMaterial* Material,
66 int32 PSOCollectorIndex);
67
71namespace PSOCollectorStats
72{
74 {
75 Disabled = 0,
76 Lightweight = 1,
77 Full = 2
78 };
79
83
87 extern ENGINE_API uint64 GetPSOPrecacheHash(const FGraphicsPipelineStateInitializer& GraphicsPSOInitializer);
88
93
99 EPSOPrecacheResult PSOPrecacheResult,
100 const FMaterialRenderProxy* MaterialRenderProxy,
101 const FVertexFactoryType* VFType,
102 const FPrimitiveSceneProxy* PrimitiveSceneProxy,
103 int32 PSOCollectorIndex);
104
110 EPSOPrecacheResult PSOPrecacheResult,
111 const FMaterial* Material,
112 const FVertexFactoryType* VFType,
113 const FPrimitiveSceneProxy* PrimitiveSceneProxy,
114 int32 PSOCollectorIndex);
115
121 EPSOPrecacheResult PSOPrecacheResult,
123 int32 PSOCollectorIndex);
124
130
131 /*
132 * Update the CSV stats
133 */
134 extern ENGINE_API void UpdateCSVStats(EPSOPrecacheResult PSOPrecacheResult);
135
137 struct FShaderStateUsage
138 {
139 bool bPrecached = false;
140 bool bUsed = false;
141
142#if PSO_PRECACHING_TRACKING
143 FString MaterialName;
144 int32 PSOCollectorIndex = INDEX_NONE;
145 const FVertexFactoryType* VertexFactoryType = nullptr;
146#endif // PSO_PRECACHING_TRACKING
147 };
148
154 {
155 public:
158 {
159 Empty();
160 }
161
162 uint64 GetTotalCount() const
163 {
164 return FPlatformAtomics::AtomicRead(&Count);
165 }
166
167 ENGINE_API void Empty();
168
169 ENGINE_API void UpdateStats(EPSOPrecacheType PrecacheType, int32 PSOCollectorIndex, const FVertexFactoryType* VFType);
170
171 private:
172 bool ShouldRecordFullStats(EPSOPrecacheType PrecacheType, int32 PSOCollectorIndex, const FVertexFactoryType* VFType) const
173 {
175 {
176 return IsFullPrecachingValidationEnabled() && ((PSOCollectorIndex != INDEX_NONE && PSOCollectorIndex < FPSOCollectorCreateManager::MaxPSOCollectorCount) || VFType != nullptr);
177 }
178 else
179 {
180 return IsFullPrecachingValidationEnabled() && PSOCollectorIndex != INDEX_NONE && PSOCollectorIndex < FGlobalPSOCollectorManager::MaxPSOCollectorCount;
181 }
182 }
183
184 volatile int64 Count;
185
187
188 // Full stats by mesh pass type and by vertex factory type.
189 // Only used when the validation mode is set to EPSOPrecacheValidationMode::Full,
190 // and when the mesh pass and vertex factory type are known.
197 };
198
202 struct FPrecacheStats
203 {
206 , HitData(HitStatFName)
210 {
211 }
212
213 void Empty()
214 {
215 PrecacheData.Empty();
216 UsageData.Empty();
217 HitData.Empty();
218 MissData.Empty();
219 TooLateData.Empty();
220 UntrackedData.Empty();
221 }
222
223 FPrecacheUsageData PrecacheData; //< PSOs which have been precached
224 FPrecacheUsageData UsageData; //< PSOs which are used during rendering
225 FPrecacheUsageData HitData; //< PSOs which are used during rendering and have been successfully precached
226 FPrecacheUsageData MissData; //< PSOs which are used during rendering and have not been precached (but should have been)
227 FPrecacheUsageData TooLateData; //< PSOs which are used during rendering and are still precaching (will cause hitch - component could wait for it to be done)
228 FPrecacheUsageData UntrackedData; //< PSOs which are used during rendering but are currently not precached because for example the MeshPassProcessor or VertexFactory type don't support PSO precaching yet
229 };
230
232 {
233 public:
236 {
237 }
238
239 void ResetStats()
240 {
241 Stats.Empty();
242 }
243
244 const FPrecacheStats& GetStats() const { return Stats; }
245
246 template <typename TPrecacheState>
247 bool AddStateToCache(EPSOPrecacheType PrecacheType, const TPrecacheState& PrecacheState, uint64 HashFn(const TPrecacheState&), const FMaterial* Material, int32 PSOCollectorIndex, const FVertexFactoryType* VertexFactoryType)
248 {
250 {
251 return false;
252 }
253
254 uint64 PrecacheStateHash = HashFn(PrecacheState);
255
256 // Only update stats once per state.
257 bool bUpdateStats = false;
258 {
260
262 if (!Value->bPrecached)
263 {
264 Value->bPrecached = true;
265 bUpdateStats = true;
266
267#if PSO_PRECACHING_TRACKING
268 Value->MaterialName = Material ? Material->GetAssetName() : FString(TEXT("Unknown"));
269 Value->PSOCollectorIndex = PSOCollectorIndex;
270 Value->VertexFactoryType = VertexFactoryType;
271#endif //PSO_PRECACHING_TRACKING
272 }
273 }
274
275 if (bUpdateStats)
276 {
277 Stats.PrecacheData.UpdateStats(PrecacheType, PSOCollectorIndex, VertexFactoryType);
278 }
279
280 return bUpdateStats;
281 }
282
283 template <typename TPrecacheState>
284 bool CheckStateInCache(EPSOPrecacheType PrecacheType, const TPrecacheState& PrecacheState, uint64 HashFn(const TPrecacheState&), int32 PSOCollectorIndex, const FVertexFactoryType* VertexFactoryType, EPSOPrecacheResult& InOutPrecacheResult)
285 {
287 {
289 return false;
290 }
291
292 uint64 PrecacheStateHash = HashFn(PrecacheState);
293 return CheckStateInCacheByHash(PrecacheType, PrecacheStateHash, PSOCollectorIndex, VertexFactoryType, InOutPrecacheResult);
294 }
295
297 {
299 {
301 return false;
302 }
303
304 bool bTracked = IsStateTracked(PrecacheType, PSOCollectorIndex, VertexFactoryType);
305 return UpdatePrecacheStats(PrecacheType, PrecacheStateHash, PSOCollectorIndex, VertexFactoryType, bTracked, InOutPrecacheResult);
306 }
307
309#if PSO_PRECACHING_TRACKING
311#endif
312
313 static ENGINE_API bool IsStateTracked(EPSOPrecacheType PrecacheType, int32 PSOCollectorIndex, const FVertexFactoryType* VertexFactoryType);
314
315 private:
316
318
319 FPrecacheStats Stats;
320
323 };
324
328}
329
330#endif // PSO_PRECACHING_VALIDATE
331
332#endif // UE_WITH_PSO_PRECACHING
@ INDEX_NONE
Definition CoreMiscDefines.h:150
#define TEXT(x)
Definition Platform.h:1272
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
UE::FPlatformRecursiveMutex FCriticalSection
Definition CriticalSection.h:53
EPSOPrecacheType
Definition PSOPrecache.h:21
EPSOPrecacheResult
Definition PipelineStateCache.h:55
FRWLock Lock
Definition UnversionedPropertySerialization.cpp:921
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition RobinHoodHashTable.h:1135
static constexpr uint32 MaxPSOCollectorCount
Definition PSOPrecache.h:315
Definition RHIResources.h:4572
Definition MaterialRenderProxy.h:102
Definition MaterialShared.h:2058
Definition NameTypes.h:617
static constexpr uint32 MaxPSOCollectorCount
Definition PSOPrecacheMaterial.h:56
Definition PrimitiveSceneProxy.h:296
Definition RHIResources.h:1018
Definition ScopeLock.h:141
Definition VertexFactory.h:314