r.ShaderPipelineCache.BatchTime

r.ShaderPipelineCache.BatchTime

#Overview

name: r.ShaderPipelineCache.BatchTime

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

It is referenced in 5 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of r.ShaderPipelineCache.BatchTime is to control the target time (in milliseconds) spent precompiling shaders each frame when shader compilation takes priority. This setting is part of Unreal Engine’s rendering system, specifically the shader pipeline cache optimization.

This setting variable is primarily used in the RenderCore module of Unreal Engine, as evidenced by its implementation in the ShaderPipelineCache.cpp file. The shader pipeline cache system relies on this variable to manage the precompilation process efficiently.

The value of this variable is set through a console variable (CVarPSOFileCacheBatchTime) with a default value of 16.0 milliseconds. It can be modified at runtime through console commands or programmatically.

The r.ShaderPipelineCache.BatchTime variable interacts closely with other shader pipeline cache-related variables, such as r.ShaderPipelineCache.BatchSize and r.ShaderPipelineCache.PrecompileBatchTime. It’s used in conjunction with these variables to control the precompilation process.

Developers should be aware that:

  1. Setting this value to 0.0 will disable the precompilation process.
  2. The actual batch size for precompilation will dynamically adjust based on this time target. If precompilation is faster than the target time, the batch size will grow, and if slower, it will shrink.
  3. This variable is render thread safe, meaning it can be safely modified from any thread.

Best practices when using this variable include:

  1. Adjusting the value based on the specific needs of your project and target hardware.
  2. Monitoring performance to find the optimal balance between precompilation time and frame rate.
  3. Consider lowering this value on less powerful hardware to maintain smoother frame rates.

The associated variable CVarPSOFileCacheBatchTime is the actual console variable that controls r.ShaderPipelineCache.BatchTime. It’s used to get and set the value of the batch time in various parts of the shader pipeline cache system. The same considerations and best practices apply to this variable as they do to r.ShaderPipelineCache.BatchTime.

#References in C++ code

#Callsites

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

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

Scope: file

Source code excerpt:

														  );
static TAutoConsoleVariable<float> CVarPSOFileCacheBatchTime(
														   TEXT("r.ShaderPipelineCache.BatchTime"),
														   16.0f,
														   TEXT("The target time (in ms) to spend precompiling each frame when compiling takes priority or 0.0 to disable. When precompiling is faster the batch size will grow and when slower will shrink to attempt to occupy the full amount. Defaults to 16.0 (max. ms per-frame of precompilation)."),
														   ECVF_Default | ECVF_RenderThreadSafe
														   );
static TAutoConsoleVariable<float> CVarPSOFileCachePrecompileBatchTime(
															 TEXT("r.ShaderPipelineCache.PrecompileBatchTime"),

#Associated Variable and Callsites

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

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

Scope: file

Source code excerpt:

														  ECVF_Default | ECVF_RenderThreadSafe
														  );
static TAutoConsoleVariable<float> CVarPSOFileCacheBatchTime(
														   TEXT("r.ShaderPipelineCache.BatchTime"),
														   16.0f,
														   TEXT("The target time (in ms) to spend precompiling each frame when compiling takes priority or 0.0 to disable. When precompiling is faster the batch size will grow and when slower will shrink to attempt to occupy the full amount. Defaults to 16.0 (max. ms per-frame of precompilation)."),
														   ECVF_Default | ECVF_RenderThreadSafe
														   );
static TAutoConsoleVariable<float> CVarPSOFileCachePrecompileBatchTime(

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

Scope (from outer to inner):

file
function     void FShaderPipelineCache::SetBatchMode

Source code excerpt:

			{
				ShaderPipelineCache->BatchSize = CVarPSOFileCacheBatchSize.GetValueOnAnyThread();
				ShaderPipelineCache->BatchTime = CVarPSOFileCacheBatchTime.GetValueOnAnyThread();
				break;
			}
			case BatchMode::Background:
			default:
			{
				ShaderPipelineCache->BatchSize = CVarPSOFileCacheBackgroundBatchSize.GetValueOnAnyThread();

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

Scope (from outer to inner):

file
function     FShaderPipelineCache::FShaderPipelineCache

Source code excerpt:

		case 0:
			BatchSize = CVarPSOFileCacheBatchSize.GetValueOnAnyThread();
			BatchTime = CVarPSOFileCacheBatchTime.GetValueOnAnyThread();
			PausedCount = 1;
			bPaused = true;
			UE_LOG(LogRHI, Display, TEXT("ShaderPipelineCache: Starting paused. %d"), PausedCount);
			break;
		case 2:
			BatchSize = CVarPSOFileCacheBackgroundBatchSize.GetValueOnAnyThread();

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

Scope (from outer to inner):

file
function     FShaderPipelineCache::FShaderPipelineCache

Source code excerpt:

		default:
			BatchSize = CVarPSOFileCacheBatchSize.GetValueOnAnyThread();
			BatchTime = CVarPSOFileCacheBatchTime.GetValueOnAnyThread();
			break;
	}
	
	FString StableShaderKeyFile;
	if (FParse::Value(FCommandLine::Get(), TEXT("-shkfile="), StableShaderKeyFile) && !StableShaderKeyFile.IsEmpty())
	{