r.ShaderPipelineCache.MaxPrecompileTime
r.ShaderPipelineCache.MaxPrecompileTime
#Overview
name: r.ShaderPipelineCache.MaxPrecompileTime
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
The maximum time to allow a PSO to be precompiled. if greather than 0, the amount of wall time we will allow pre-compile of PSOs and then switch to background processing.
It is referenced in 4
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of r.ShaderPipelineCache.MaxPrecompileTime is to control the maximum time allowed for precompiling Pipeline State Objects (PSOs) in Unreal Engine’s rendering system. This setting is part of the shader pipeline cache optimization system.
This setting variable is primarily used in the RenderCore module of Unreal Engine, specifically within the shader pipeline cache system. It’s referenced in the ShaderPipelineCache.cpp file, which is responsible for managing and optimizing shader pipeline states.
The value of this variable is set through the console variable system in Unreal Engine. It’s defined as a TAutoConsoleVariable with a default value of 0.0f. Developers can modify this value at runtime or through configuration files.
The associated variable CVarPSOFileCacheMaxPrecompileTime directly interacts with r.ShaderPipelineCache.MaxPrecompileTime. They share the same value and purpose.
Developers must be aware that:
- This variable affects the balance between initial loading time and runtime performance.
- Setting a value greater than 0 will limit the time spent precompiling PSOs before switching to background processing.
- It can impact the game’s initial loading time and potentially the runtime performance if set too low.
Best practices when using this variable include:
- Carefully tuning the value based on the specific needs of the project.
- Monitoring the impact on loading times and runtime performance when adjusting this value.
- Consider platform-specific requirements, as shader compilation times can vary across different hardware.
Regarding the associated variable CVarPSOFileCacheMaxPrecompileTime:
- It’s the internal representation of the r.ShaderPipelineCache.MaxPrecompileTime setting.
- It’s used directly in the code to control the precompilation behavior.
- The variable is checked in the Tick function of FShaderPipelineCache to determine when to switch to background processing mode.
- It’s also used to calculate the number of remaining precompiles in the NumPrecompilesRemaining function.
When working with this variable, developers should consider the trade-offs between initial loading time and runtime performance, and adjust the value based on profiling results and target platform requirements.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/ShaderPipelineCache.cpp:150
Scope: file
Source code excerpt:
static TAutoConsoleVariable<float> CVarPSOFileCacheMaxPrecompileTime(
TEXT("r.ShaderPipelineCache.MaxPrecompileTime"),
(float)0.f,
TEXT("The maximum time to allow a PSO to be precompiled. if greather than 0, the amount of wall time we will allow pre-compile of PSOs and then switch to background processing."),
ECVF_Default | ECVF_RenderThreadSafe
);
static TAutoConsoleVariable<int32> CVarPSOGlobalShadersOnlyWhenPSOPrecaching(
#Associated Variable and Callsites
This variable is associated with another variable named CVarPSOFileCacheMaxPrecompileTime
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/ShaderPipelineCache.cpp:149
Scope: file
Source code excerpt:
);
static TAutoConsoleVariable<float> CVarPSOFileCacheMaxPrecompileTime(
TEXT("r.ShaderPipelineCache.MaxPrecompileTime"),
(float)0.f,
TEXT("The maximum time to allow a PSO to be precompiled. if greather than 0, the amount of wall time we will allow pre-compile of PSOs and then switch to background processing."),
ECVF_Default | ECVF_RenderThreadSafe
);
#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/ShaderPipelineCache.cpp:818
Scope (from outer to inner):
file
function uint32 FShaderPipelineCache::NumPrecompilesRemaining
Source code excerpt:
if (ShaderPipelineCache)
{
if (CVarPSOFileCacheMaxPrecompileTime.GetValueOnAnyThread() > 0.0 && FShaderPipelineCacheTask::TotalPrecompileTasks > 0)
{
float Mult = FShaderPipelineCacheTask::TotalPrecompileWallTime / CVarPSOFileCacheMaxPrecompileTime.GetValueOnAnyThread();
NumRemaining = uint32(FMath::Max(0.f, 1.f - Mult) * FShaderPipelineCacheTask::TotalPrecompileTasks);
}
else
{
int64 NumActiveTasksRemaining = FMath::Max((int64_t)0, FShaderPipelineCacheTask::TotalActiveTasks.load());
int64 NumWaitingTasksRemaining = FMath::Max((int64_t)0, FShaderPipelineCacheTask::TotalWaitingTasks.load());
#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/ShaderPipelineCache.cpp:1789
Scope (from outer to inner):
file
function void FShaderPipelineCache::Tick
Source code excerpt:
if (!bHasActiveCacheTask || bHasCurrentCacheTaskCompleted )
{
// drop to background mode if CVarPSOFileCacheMaxPrecompileTime exceeded.
if (CVarPSOFileCacheMaxPrecompileTime.GetValueOnAnyThread() > 0.0 && FShaderPipelineCacheTask::TotalPrecompileWallTime - 20.0f > CVarPSOFileCacheMaxPrecompileTime.GetValueOnAnyThread() && FShaderPipelineCacheTask::TotalPrecompileTasks > 0)
{
SetBatchMode(BatchMode::Background);
}
if (bHasCurrentCacheTaskCompleted)
{