UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
PSOPrecache.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3/*=============================================================================
4 PSOPrecache.h
5=============================================================================*/
6
7#pragma once
8
9#include "RHIDefinitions.h"
10#include "RHIFeatureLevel.h"
11#include "RHIResources.h"
12#include "Engine/EngineTypes.h"
13#include "PipelineStateCache.h"
14#include "PSOPrecacheFwd.h"
15#include "Shader.h"
16
19
21{
22 Global = 0,
24};
25
30{
54
56 {
57 return Data == Other.Data;
58 }
59
61 {
62 return !(*this == rhs);
63 }
64
66 {
67 return GetTypeHash(Params.Data);
68 }
69
74
79
84
89
94
99
104
105 union
106 {
107 struct
108 {
110
113
116
122
129
133
135
137 };
139 };
140
141};
142
143// Unique ID to find the FVertexDeclarationElementList - these can be shared
145
150{
154
156
157 // Custom vertex declaration used for EVertexInputStreamType::Default if provided - the others are directly retrieved from the type if needed
159
161 {
162 return VertexFactoryType == Other.VertexFactoryType && CustomDefaultVertexDeclaration == Other.CustomDefaultVertexDeclaration;
163 }
164
166 {
167 return !(*this == rhs);
168 }
169
171 {
172 return HashCombine(PointerHash(Params.VertexFactoryType), PointerHash(Params.CustomDefaultVertexDeclaration));
173 }
174};
175
177
183
185
193
195
197{
199
204
209
210 // Can have 3 shaders at most (vertex, geometry, pixel).
212};
213
215{
216 PSO = 0,
217 PreloadShader = 1,
218};
219
221
226{
229 , PSOCollectorIndex(INDEX_NONE)
230 , bDefaultMaterial(0)
231 , VertexFactoryType(nullptr)
232#endif // PSO_PRECACHING_VALIDATE
233 {
234 }
235
236 enum class EType : uint8
237 {
238 Graphics,
239 Compute,
240 };
242
243 // Is the PSO required to be able render the object or can it provide a fallback path
244 // (proxy creation won't wait for these PSOs if enabled)
246
247 union
248 {
251 };
252
254
256 {
258 {
260 }
261 else
262 {
263 ComputeShader = InComputeShader.GetComputeShader();
264 }
265 }
266
267#if PSO_PRECACHING_VALIDATE
268 int32 PSOCollectorIndex : 31;
269 int32 bDefaultMaterial : 1;
270 const FVertexFactoryType* VertexFactoryType;
271#endif // PSO_PRECACHING_VALIDATE
272};
273
276
278{
280 FMaterial* Material = nullptr;
283
285 {
286 return FeatureLevel == Other.FeatureLevel &&
287 Material == Other.Material &&
288 VertexFactoryData == Other.VertexFactoryData &&
289 PrecachePSOParams == Other.PrecachePSOParams;
290 }
291
293 {
294 return !(*this == rhs);
295 }
296
298 {
299 return HashCombine(GetTypeHash(Params.FeatureLevel), HashCombine(PointerHash(Params.Material),
300 HashCombine(GetTypeHash(Params.VertexFactoryData), GetTypeHash(Params.PrecachePSOParams))));
301 }
302};
303
308
313{
314public:
315 constexpr static uint32 MaxPSOCollectorCount = 4;
316
317 static int32 GetPSOCollectorCount() { return PSOCollectorCount; }
319 {
321 return PSOCollectors[Index].CollectFunction;
322 }
323 static const TCHAR* GetName(int32 Index)
324 {
325 if (Index == INDEX_NONE)
326 {
327 return TEXT("Unknown");
328 }
330 return PSOCollectors[Index].Name;
331 }
332 static ENGINE_API int32 GetIndex(const TCHAR* Name);
333
334private:
335
336 // Have to used fixed size array instead of TArray because of order of initialization of static member variables
337 static inline int32 PSOCollectorCount = 0;
338
339 struct FPSOCollectorData
340 {
341 GlobalPSOCollectorFunction CollectFunction;
342 const TCHAR* Name = nullptr;
343 };
344 static ENGINE_API FPSOCollectorData PSOCollectors[MaxPSOCollectorCount];
345
347};
348
353{
354public:
356 {
357 Index = FGlobalPSOCollectorManager::PSOCollectorCount;
359
360 FGlobalPSOCollectorManager::PSOCollectors[Index].CollectFunction = InCollectFunction;
361 FGlobalPSOCollectorManager::PSOCollectors[Index].Name = InName;
362 FGlobalPSOCollectorManager::PSOCollectorCount++;
363 }
364
366 {
367 FGlobalPSOCollectorManager::PSOCollectors[Index].CollectFunction = nullptr;
368 FGlobalPSOCollectorManager::PSOCollectors[Index].Name = nullptr;
369 }
370
371 int32 GetIndex() const { return Index; }
372
373private:
375};
376
377
378
383
388
393
398
400{
401 // Always create the render proxy regardless of whether the PSO has finished precaching or not.
402 // This will introduce a blocking wait when the proxy is rendered if the PSO is not ready.
403 AlwaysCreate = 0,
404
405 // Delay the creation of the render proxy until the PSO has finished precaching.
406 // This effectively skips drawing components until the PSO is ready, when the proxy will be created.
408
409 // Create a render proxy that uses the default material if the PSO has not finished precaching by creation time.
410 // The proxy will be re-created with the actual materials once the PSO is ready.
411 // Currently implemented only for static and skinned mesh components, while Niagara components will skip render proxy creation altogether.
413};
414
416
421
426
OODEFFUNC typedef void(OODLE_CALLBACK t_fp_OodleCore_Plugin_Free)(void *ptr)
#define check(expr)
Definition AssertionMacros.h:314
@ INDEX_NONE
Definition CoreMiscDefines.h:150
FPlatformTypes::int16 int16
A 16-bit signed integer.
Definition Platform.h:1123
#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
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
return true
Definition ExternalRpcRegistry.cpp:601
#define PSO_PRECACHING_VALIDATE
Definition PSOPrecacheFwd.h:22
EPSOPrecacheMode
Definition PSOPrecache.h:215
ENGINE_API void AddMaterialInterfacePSOPrecacheParamsToList(const FMaterialInterfacePSOPrecacheParams &EntryToAdd, FMaterialInterfacePSOPrecacheParamsList &List)
Definition PSOPrecache.cpp:154
ENGINE_API bool IsResourcePSOPrecachingEnabled()
Definition PSOPrecache.cpp:104
ENGINE_API EPSOPrecacheProxyCreationStrategy GetPSOPrecacheProxyCreationStrategy()
Definition PSOPrecache.cpp:114
ENGINE_API bool ProxyCreationWhenPSOReady()
Definition PSOPrecache.cpp:132
void(* GlobalPSOCollectorFunction)(const FSceneTexturesConfig &SceneTexturesConfig, int32 GlobalPSOCollectorIndex, TArray< FPSOPrecacheData > &PSOInitializers)
Definition PSOPrecache.h:307
TArray< FPSOPrecacheData > FPSOPrecacheDataArray
Definition PSOPrecache.h:274
TArray< FPSOPrecacheRequestResult, TInlineAllocator< 4 > > FPSOPrecacheRequestResultArray
Definition PSOPrecache.h:275
ENGINE_API bool ShouldBoostPSOPrecachePriorityOnDraw()
Definition PSOPrecache.cpp:109
TArray< FPSOPrecacheVertexFactoryData, TInlineAllocator< 2 > > FPSOPrecacheVertexFactoryDataList
Definition PSOPrecache.h:176
EPSOPrecacheProxyCreationStrategy
Definition PSOPrecache.h:400
ENGINE_API void BoostPrecachedPSORequestsOnDraw(const class FPrimitiveSceneInfo *SceneInfo)
ENGINE_API EPSOPrecacheMode GetPSOPrecacheMode()
Definition PSOPrecache.cpp:81
EPSOPrecacheType
Definition PSOPrecache.h:21
uint16 FVertexDeclarationElementListID
Definition PSOPrecache.h:144
TArray< FPSOPrecacheVertexFactoryDataPerMaterialIndex, TInlineAllocator< 4 > > FPSOPrecacheVertexFactoryDataPerMaterialIndexList
Definition PSOPrecache.h:184
ENGINE_API bool IsPSOShaderPreloadingEnabled()
Definition PSOPrecache.cpp:94
ENGINE_API FPSOPrecacheRequestResultArray RequestPrecachePSOs(EPSOPrecacheType PSOPrecacheType, const FPSOPrecacheDataArray &PSOInitializers)
Definition PSOPrecache.cpp:198
ENGINE_API bool IsComponentPSOPrecachingEnabled()
Definition PSOPrecache.cpp:99
EPSOPrecachePriority
Definition PipelineStateCache.h:33
EPixelFormat
Definition PixelFormat.h:16
@ PF_Unknown
Definition PixelFormat.h:17
EStencilMask
Definition RHIDefinitions.h:428
@ SM_Default
Definition RHIDefinitions.h:429
@ PT_TriangleList
Definition RHIDefinitions.h:824
uint32 PointerHash(const void *Key)
Definition TypeHash.h:91
constexpr uint32 HashCombine(uint32 A, uint32 C)
Definition TypeHash.h:36
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
if(Failed) console_printf("Failed.\n")
uint8_t uint8
Definition binka_ue_file_header.h:8
uint16_t uint16
Definition binka_ue_file_header.h:7
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition PSOPrecache.h:313
static constexpr uint32 MaxPSOCollectorCount
Definition PSOPrecache.h:315
static GlobalPSOCollectorFunction GetCollectFunction(int32 Index)
Definition PSOPrecache.h:318
static int32 GetPSOCollectorCount()
Definition PSOPrecache.h:317
static ENGINE_API int32 GetIndex(const TCHAR *Name)
Definition PSOPrecache.cpp:177
static const TCHAR * GetName(int32 Index)
Definition PSOPrecache.h:323
Definition RHIResources.h:4572
Definition MaterialShared.h:2058
Definition PrimitiveSceneInfo.h:266
Definition RHIResources.h:1018
Definition RHIResources.h:725
Definition PSOPrecache.h:353
FRegisterGlobalPSOCollectorFunction(GlobalPSOCollectorFunction InCollectFunction, const TCHAR *InName)
Definition PSOPrecache.h:355
int32 GetIndex() const
Definition PSOPrecache.h:371
~FRegisterGlobalPSOCollectorFunction()
Definition PSOPrecache.h:365
Definition VertexFactory.h:314
Definition EnumAsByte.h:22
Definition Shader.h:1021
Definition ContainerAllocationPolicies.h:894
Definition MaterialInterface.h:296
Type
Definition EngineTypes.h:3789
@ Stationary
Definition EngineTypes.h:3804
@ Static
Definition EngineTypes.h:3795
@ Movable
Definition EngineTypes.h:3812
Type
Definition RHIFeatureLevel.h:20
@ Num
Definition RHIFeatureLevel.h:54
U16 Index
Definition radfft.cpp:71
Definition PSOPrecache.h:187
UMaterialInterface * MaterialInterface
Definition PSOPrecache.h:189
EPSOPrecachePriority Priority
Definition PSOPrecache.h:188
FPSOPrecacheVertexFactoryDataList VertexFactoryDataList
Definition PSOPrecache.h:191
FPSOPrecacheParams PSOPrecacheParams
Definition PSOPrecache.h:190
Definition PSOPrecache.h:278
friend uint32 GetTypeHash(const FMaterialPSOPrecacheParams &Params)
Definition PSOPrecache.h:297
FPSOPrecacheVertexFactoryData VertexFactoryData
Definition PSOPrecache.h:281
bool operator==(const FMaterialPSOPrecacheParams &Other) const
Definition PSOPrecache.h:284
FPSOPrecacheParams PrecachePSOParams
Definition PSOPrecache.h:282
ERHIFeatureLevel::Type FeatureLevel
Definition PSOPrecache.h:279
bool operator!=(const FMaterialPSOPrecacheParams &rhs) const
Definition PSOPrecache.h:292
FMaterial * Material
Definition PSOPrecache.h:280
Definition PSOPrecache.h:226
FGraphicsPipelineStateInitializer GraphicsPSOInitializer
Definition PSOPrecache.h:249
EType
Definition PSOPrecache.h:237
FShaderPreloadData ShaderPreloadData
Definition PSOPrecache.h:253
FRHIComputeShader * ComputeShader
Definition PSOPrecache.h:250
bool bRequired
Definition PSOPrecache.h:245
FPSOPrecacheData()
Definition PSOPrecache.h:227
EType Type
Definition PSOPrecache.h:241
void SetComputeShader(const TShaderRef< FShader > &InComputeShader)
Definition PSOPrecache.h:255
Definition PSOPrecache.h:30
uint64 bRenderInDepthPass
Definition PSOPrecache.h:118
uint64 bForceLODModel
Definition PSOPrecache.h:128
uint64 bSkinnedMesh
Definition PSOPrecache.h:115
uint64 bUsesIndirectLightingCache
Definition PSOPrecache.h:123
uint64 Unused
Definition PSOPrecache.h:136
TEnumAsByte< EComponentMobility::Type > GetMobility() const
Definition PSOPrecache.h:75
TEnumAsByte< EStencilMask > GetStencilWriteMask() const
Definition PSOPrecache.h:90
uint64 Data
Definition PSOPrecache.h:138
FPSOPrecacheParams()
Definition PSOPrecache.h:31
void SetStencilWriteMask(EStencilMask InStencilMask)
Definition PSOPrecache.h:85
friend uint32 GetTypeHash(const FPSOPrecacheParams &Params)
Definition PSOPrecache.h:65
uint64 bAnyMaterialHasWorldPositionOffset
Definition PSOPrecache.h:131
uint64 bRenderInMainPass
Definition PSOPrecache.h:117
uint64 bDisableBackFaceCulling
Definition PSOPrecache.h:126
uint64 StencilWriteMask
Definition PSOPrecache.h:132
EPixelFormat GetBassPixelFormat() const
Definition PSOPrecache.h:100
uint64 bStaticLighting
Definition PSOPrecache.h:119
uint64 bDefaultMaterial
Definition PSOPrecache.h:111
uint64 bRenderCustomDepth
Definition PSOPrecache.h:121
uint64 bAffectDynamicIndirectLighting
Definition PSOPrecache.h:124
uint64 BasePassPixelFormat
Definition PSOPrecache.h:134
bool operator==(const FPSOPrecacheParams &Other) const
Definition PSOPrecache.h:55
uint64 bSplineMesh
Definition PSOPrecache.h:114
uint64 bCastShadow
Definition PSOPrecache.h:120
bool operator!=(const FPSOPrecacheParams &rhs) const
Definition PSOPrecache.h:60
void SetMobility(EComponentMobility::Type InMobility)
Definition PSOPrecache.h:70
uint64 bCastShadowAsTwoSided
Definition PSOPrecache.h:127
uint64 Mobility
Definition PSOPrecache.h:130
bool IsMoveable() const
Definition PSOPrecache.h:80
uint64 bReverseCulling
Definition PSOPrecache.h:125
void SetBassPixelFormat(EPixelFormat InBasePassPixelFormat)
Definition PSOPrecache.h:95
uint64 PrimitiveType
Definition PSOPrecache.h:109
uint64 bCanvasMaterial
Definition PSOPrecache.h:112
FPSOPrecacheVertexFactoryDataList VertexFactoryDataList
Definition PSOPrecache.h:181
int16 MaterialIndex
Definition PSOPrecache.h:180
Definition PSOPrecache.h:150
bool operator!=(const FPSOPrecacheVertexFactoryData &rhs) const
Definition PSOPrecache.h:165
bool operator==(const FPSOPrecacheVertexFactoryData &Other) const
Definition PSOPrecache.h:160
friend uint32 GetTypeHash(const FPSOPrecacheVertexFactoryData &Params)
Definition PSOPrecache.h:170
FPSOPrecacheVertexFactoryData(const FVertexFactoryType *InVertexFactoryType)
Definition PSOPrecache.h:152
const FVertexFactoryType * VertexFactoryType
Definition PSOPrecache.h:155
FRHIVertexDeclaration * CustomDefaultVertexDeclaration
Definition PSOPrecache.h:158
Definition SceneTexturesConfig.h:114
Definition PSOPrecache.h:197
TArray< TShaderRef< FShader >, TInlineAllocator< 3 > > Shaders
Definition PSOPrecache.h:211
FShaderPreloadData(const TShaderRef< FShader > &InShader)
Definition PSOPrecache.h:200
FShaderPreloadData(TArray< TShaderRef< FShader >, TInlineAllocator< 3 > > &&InShaders)
Definition PSOPrecache.h:205
FShaderPreloadData()=default