r.ShaderPipelineCache.AlwaysGenerateOSCache

r.ShaderPipelineCache.AlwaysGenerateOSCache

#Overview

name: r.ShaderPipelineCache.AlwaysGenerateOSCache

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.AlwaysGenerateOSCache is to control the generation of the shader pipeline cache for the operating system. This setting is part of Unreal Engine’s rendering system, specifically the shader pipeline caching mechanism.

This setting variable is primarily used in the RHI (Rendering Hardware Interface) module of Unreal Engine 5. It’s referenced in the PipelineFileCache.cpp file, which is responsible for managing the shader pipeline cache.

The value of this variable is set through a console variable (CVar) system. It’s initialized with a default value of 1, meaning it will generate the cache every run by default.

The associated variable CVarAlwaysGeneratePOSSOFileCache directly interacts with r.ShaderPipelineCache.AlwaysGenerateOSCache. They share the same value and are used interchangeably in the code.

Developers must be aware that this variable affects the performance and startup time of the engine. When set to 1, it forces the generation of the shader pipeline cache every time the engine runs, which can increase startup time but ensures the cache is always up-to-date. When set to 0, it only generates the cache when it’s missing, which can lead to faster startup times in subsequent runs but might use outdated cache data.

Best practices when using this variable include:

  1. During development, keep it set to 1 to ensure you’re always working with the most up-to-date shader pipeline cache.
  2. For release builds or when optimizing for faster startup times, consider setting it to 0 after ensuring a complete cache has been generated.
  3. Be cautious when changing this value, as it can affect the rendering performance and stability of your game.

Regarding the associated variable CVarAlwaysGeneratePOSSOFileCache:

The purpose of CVarAlwaysGeneratePOSSOFileCache is identical to r.ShaderPipelineCache.AlwaysGenerateOSCache. It’s an internal representation of the same setting.

This variable is used within the RHI module, specifically in the FPipelineFileCacheManager::ShouldEnableFileCache() function. It’s used to determine whether the file cache should be enabled based on the existence of certain cache files on iOS platforms.

The value of this variable is set through the same console variable system as r.ShaderPipelineCache.AlwaysGenerateOSCache.

Developers should be aware that this variable is platform-specific (used in iOS-specific code) and its behavior might differ on other platforms.

Best practices for CVarAlwaysGeneratePOSSOFileCache align with those of r.ShaderPipelineCache.AlwaysGenerateOSCache, as they represent the same setting. However, developers should pay extra attention when working on iOS platforms, as this variable has specific implications for cache file management on that system.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/RHI/Private/PipelineFileCache.cpp:167

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarAlwaysGeneratePOSSOFileCache(
														   TEXT("r.ShaderPipelineCache.AlwaysGenerateOSCache"),
														   1,
														   TEXT("1 generates the cache every run, 0 generates it only when it is missing."),
														   ECVF_Default | ECVF_RenderThreadSafe
														   );

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/RHI/Private/PipelineFileCache.cpp:166

Scope: file

Source code excerpt:

														   );

static TAutoConsoleVariable<int32> CVarAlwaysGeneratePOSSOFileCache(
														   TEXT("r.ShaderPipelineCache.AlwaysGenerateOSCache"),
														   1,
														   TEXT("1 generates the cache every run, 0 generates it only when it is missing."),
														   ECVF_Default | ECVF_RenderThreadSafe
														   );

#Loc: <Workspace>/Engine/Source/Runtime/RHI/Private/PipelineFileCache.cpp:3121

Scope (from outer to inner):

file
function     bool FPipelineFileCacheManager::ShouldEnableFileCache

Source code excerpt:

{
#if PLATFORM_IOS
	if (CVarAlwaysGeneratePOSSOFileCache.GetValueOnAnyThread() == 0)
	{
		struct stat FileInfo;
		static FString PrivateWritePathBase = FString([NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) objectAtIndex:0]) + TEXT("/");
		FString Result = PrivateWritePathBase + FString([NSString stringWithFormat:@"/Caches/%@/com.apple.metal/functions.data", [NSBundle mainBundle].bundleIdentifier]);
		FString Result2 = PrivateWritePathBase + FString([NSString stringWithFormat:@"/Caches/%@/com.apple.metal/usecache.txt", [NSBundle mainBundle].bundleIdentifier]);
		if (stat(TCHAR_TO_UTF8(*Result), &FileInfo) != -1 && stat(TCHAR_TO_UTF8(*Result2), &FileInfo) != -1)