r.ShaderPipelineCache.MinBindCount

r.ShaderPipelineCache.MinBindCount

#Overview

name: r.ShaderPipelineCache.MinBindCount

This variable is created as a Console Variable (cvar).

It is referenced in 3 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of r.ShaderPipelineCache.MinBindCount is to set a minimum threshold for the number of times a Pipeline State Object (PSO) must be bound before it is considered for precompilation in the shader pipeline cache system.

This setting variable is primarily used by the rendering system, specifically the shader pipeline caching mechanism in Unreal Engine 5. It is part of the RenderCore module, as evidenced by its location in the ShaderPipelineCache.cpp file.

The value of this variable is set through the console variable system (CVarPSOFileCacheMinBindCount) with a default value of 0. It can be modified at runtime using console commands or through configuration files.

This variable interacts closely with the shader pipeline cache system, particularly in the process of determining which PSOs should be precompiled. It’s associated with CVarPSOFileCacheMinBindCount, which is the actual console variable that stores and manages this setting.

Developers must be aware that changes to this value will not affect PSOs that have already been removed from consideration for precompilation. This means that adjusting the value at runtime may not have an immediate effect on all PSOs.

Best practices when using this variable include:

  1. Setting it to an appropriate value based on the game’s performance profile and shader complexity.
  2. Monitoring the impact on load times and runtime performance when adjusting this value.
  3. Using it in conjunction with other shader pipeline cache settings for optimal performance.

Regarding the associated variable CVarPSOFileCacheMinBindCount:

This is the actual console variable that implements the r.ShaderPipelineCache.MinBindCount setting. It’s defined as a TAutoConsoleVariable, which means it’s an integer value that can be modified through the console system.

The purpose of CVarPSOFileCacheMinBindCount is to provide a runtime-accessible interface for the r.ShaderPipelineCache.MinBindCount setting. It’s used directly in the shader pipeline cache system to filter PSOs for precompilation.

This variable is set and used within the RenderCore module, specifically in the ShaderPipelineCache.cpp file. Its value is accessed in the FShaderPipelineCacheTask::BeginPrecompilingPipelineCache function to determine which PSOs should be included in the precompilation process.

Developers should be aware that this variable can be accessed from any thread (as indicated by the GetValueOnAnyThread() call), which means changes to its value can potentially affect multiple parts of the rendering system simultaneously.

Best practices for using CVarPSOFileCacheMinBindCount include:

  1. Modifying it through the established console variable system rather than direct code manipulation.
  2. Considering its impact on shader compilation times and runtime performance when adjusting its value.
  3. Using it in conjunction with other shader pipeline cache settings for a balanced approach to PSO precompilation.

#References in C++ code

#Callsites

This variable is referenced in the following C++ source code:

#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/ShaderPipelineCache.cpp:143

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarPSOFileCacheMinBindCount(
                                                                TEXT("r.ShaderPipelineCache.MinBindCount"),
                                                                (int32)0,
                                                                TEXT("The minimum bind count to allow a PSO to be precompiled.  Changes to this value will not affect PSOs that have already been removed from consideration."),
                                                                ECVF_Default | ECVF_RenderThreadSafe
                                                                );

static TAutoConsoleVariable<float> CVarPSOFileCacheMaxPrecompileTime(

#Associated Variable and Callsites

This variable is associated with another variable named CVarPSOFileCacheMinBindCount. They share the same value. See the following C++ source code.

#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/ShaderPipelineCache.cpp:142

Scope: file

Source code excerpt:



static TAutoConsoleVariable<int32> CVarPSOFileCacheMinBindCount(
                                                                TEXT("r.ShaderPipelineCache.MinBindCount"),
                                                                (int32)0,
                                                                TEXT("The minimum bind count to allow a PSO to be precompiled.  Changes to this value will not affect PSOs that have already been removed from consideration."),
                                                                ECVF_Default | ECVF_RenderThreadSafe
                                                                );

#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/ShaderPipelineCache.cpp:2067

Scope (from outer to inner):

file
function     void FShaderPipelineCacheTask::BeginPrecompilingPipelineCache

Source code excerpt:

		TArray<FPipelineCachePSOHeader> LocalPreFetchedTasks;

		FPipelineFileCacheManager::GetOrderedPSOHashes(PSOCacheKey, LocalPreFetchedTasks, (FPipelineFileCacheManager::PSOOrder)Order, (int64)CVarPSOFileCacheMinBindCount.GetValueOnAnyThread(), FShaderPipelineCache::Get()->CompiledHashes);
		// Iterate over all the tasks we haven't yet begun to read data for - these are the 'waiting' tasks
		int64 EligibleTaskCount = LocalPreFetchedTasks.Num();

		// Only interested in global shaders when PSO precaching is enabled
		FString LibraryName(TEXT("Global"));