r.ShaderPipelineCache.AutoSaveTime

r.ShaderPipelineCache.AutoSaveTime

#Overview

name: r.ShaderPipelineCache.AutoSaveTime

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.AutoSaveTime is to control the automatic saving of logged Pipeline State Objects (PSOs) in the Unreal Engine 5 rendering system. It sets a time interval for saving logged PSOs to the shader pipeline cache file.

This setting variable is primarily used by the rendering system, specifically the shader pipeline cache subsystem. It is part of the RenderCore module in Unreal Engine 5.

The value of this variable is set through a console variable (CVar) system. It is initialized with a default value of 30 seconds but can be modified at runtime.

This variable interacts closely with another variable, r.ShaderPipelineCache.SaveAfterPSOsLogged. The auto-save functionality is disabled when r.ShaderPipelineCache.SaveAfterPSOsLogged is set to 0.

Developers should be aware that this variable affects performance and disk I/O. Setting a very low value might cause frequent saves, potentially impacting performance, while setting a very high value might risk losing PSO data in case of unexpected shutdowns.

Best practices when using this variable include:

  1. Balancing between frequent saves and performance impact.
  2. Considering the target platform’s I/O capabilities when setting this value.
  3. Using in conjunction with r.ShaderPipelineCache.SaveAfterPSOsLogged for optimal PSO caching behavior.

Regarding the associated variable CVarPSOFileCacheAutoSaveTime:

This is the internal representation of the r.ShaderPipelineCache.AutoSaveTime console variable. It is used within the engine’s C++ code to access and modify the auto-save time value.

The purpose of CVarPSOFileCacheAutoSaveTime is to provide a programmatic interface to the r.ShaderPipelineCache.AutoSaveTime setting. It is used in the FShaderPipelineCache::ReadyForAutoSave() function to determine when to trigger an auto-save of the PSO cache.

This variable is part of the RenderCore module and is crucial for the shader pipeline cache system’s operation.

The value of CVarPSOFileCacheAutoSaveTime is set when the r.ShaderPipelineCache.AutoSaveTime console variable is modified, ensuring they always have the same value.

Developers working directly with the engine’s C++ code should use CVarPSOFileCacheAutoSaveTime.GetValueOnAnyThread() to access the current auto-save time value in a thread-safe manner.

Best practices for using CVarPSOFileCacheAutoSaveTime include:

  1. Always accessing its value through the GetValueOnAnyThread() method for thread safety.
  2. Avoiding direct modification of this variable; instead, modify the r.ShaderPipelineCache.AutoSaveTime console variable.
  3. Consider the performance implications when frequently checking this value in performance-critical code paths.

#References in C++ code

#Callsites

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

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

Scope: file

Source code excerpt:

 
static TAutoConsoleVariable<int32> CVarPSOFileCacheAutoSaveTime(
															TEXT("r.ShaderPipelineCache.AutoSaveTime"),
															30,
															TEXT("Set the time where any logged PSO's will be saved if the number is < r.ShaderPipelineCache.SaveAfterPSOsLogged. Disabled when r.ShaderPipelineCache.SaveAfterPSOsLogged is 0"),
															ECVF_Default | ECVF_RenderThreadSafe
														);

static TAutoConsoleVariable<int32> CVarPSOFileCachePreCompileMask(

#Associated Variable and Callsites

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

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

Scope: file

Source code excerpt:

														   );
 
static TAutoConsoleVariable<int32> CVarPSOFileCacheAutoSaveTime(
															TEXT("r.ShaderPipelineCache.AutoSaveTime"),
															30,
															TEXT("Set the time where any logged PSO's will be saved if the number is < r.ShaderPipelineCache.SaveAfterPSOsLogged. Disabled when r.ShaderPipelineCache.SaveAfterPSOsLogged is 0"),
															ECVF_Default | ECVF_RenderThreadSafe
														);

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

Scope (from outer to inner):

file
function     bool FShaderPipelineCache::ReadyForAutoSave

Source code excerpt:

	// autosave if its enabled, and we have more than the desired number, or it's been a while since our last save
	if (SaveAfterNum > 0 &&
		(NumLogged >= SaveAfterNum || (NumLogged > 0 && TimeSinceSave >= CVarPSOFileCacheAutoSaveTime.GetValueOnAnyThread()))
		)
	{
		bAutoSave = true;
	}
	return bAutoSave;
}