r.SkinCache.CompileShaders

r.SkinCache.CompileShaders

#Overview

name: r.SkinCache.CompileShaders

The value of this variable can be defined or overridden in .ini config files. 1 .ini config file referencing this setting variable.

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

It is referenced in 7 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of r.SkinCache.CompileShaders is to control whether the GPU compute skinning cache shaders are compiled in Unreal Engine 5. This setting is primarily related to the rendering system, specifically the GPU skinning cache functionality.

This setting variable is relied upon by several Unreal Engine subsystems and modules:

  1. The Engine module (GPUSkinCache)
  2. The HairStrands plugin
  3. The GameProjectGeneration module
  4. The RenderCore module

The value of this variable is set through the console variable system in Unreal Engine. It can be modified via the console, configuration files (like DefaultEngine.ini), or programmatically.

This variable interacts with other related variables, such as:

Developers must be aware of several important aspects when using this variable:

  1. It is a compile-time setting, meaning changes require shader recompilation.
  2. It is crucial for ray tracing functionality. Ray tracing requires the skin cache to be enabled.
  3. It affects performance and memory usage, as it determines whether compute shaders for skinning are compiled and available.

Best practices when using this variable include:

  1. Enable it (set to 1) when using ray tracing features.
  2. Consider enabling it for projects that heavily rely on skeletal meshes and could benefit from GPU skinning optimization.
  3. Be aware of the potential increase in shader compilation time and shader cache size when enabled.
  4. Coordinate its setting with related variables like r.SkinCache.Mode for full functionality.
  5. Test performance with and without the setting enabled to determine the best configuration for your specific project.

#Setting Variables

#References In INI files

Location: <Workspace>/Projects/Lyra/Config/DefaultEngine.ini:102, section: [/Script/Engine.RendererSettings]

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/GPUSkinCache.cpp:76

Scope: file

Source code excerpt:


static FAutoConsoleVariableRef CVarEnableGPUSkinCacheShaders(
	TEXT("r.SkinCache.CompileShaders"),
	GEnableGPUSkinCacheShaders,
	TEXT("Whether or not to compile the GPU compute skinning cache shaders.\n")
	TEXT("This will compile the shaders for skinning on a compute job and not skin on the vertex shader.\n")
	TEXT("GPUSkinVertexFactory.usf needs to be touched to cause a recompile if this changes.\n")
	TEXT("0 is off(default), 1 is on"),
	ECVF_RenderThreadSafe | ECVF_ReadOnly

#Loc: <Workspace>/Engine/Plugins/Runtime/HairStrands/Source/HairStrandsCore/Private/GroomManager.cpp:418

Scope (from outer to inner):

file
function     static void AddHairSkinCacheDebugPass

Source code excerpt:

	bool bIsGPUSkinCacheEnable = false;
	{
		static FShaderPlatformCachedIniValue<int32> CVarSkinCacheCompileShader(TEXT("r.SkinCache.CompileShaders"));
		static FShaderPlatformCachedIniValue<int32> CVarSkinCacheMode(TEXT("r.SkinCache.Mode"));
		bIsGPUSkinCacheEnable = 
			CVarSkinCacheCompileShader.Get(View->GetShaderPlatform()) != 0 &&
			CVarSkinCacheMode.Get(View->GetShaderPlatform()) != 0;
	}

#Loc: <Workspace>/Engine/Source/Editor/GameProjectGeneration/Private/GameProjectUtils.cpp:168

Scope (from outer to inner):

file
namespace    anonymous
function     void AddRaytracingConfigValues

Source code excerpt:

			ConfigValues.Emplace(TEXT("DefaultEngine.ini"),
				TEXT("/Script/Engine.RendererSettings"),
				TEXT("r.SkinCache.CompileShaders"),
				TEXT("True"),
				true /* ShouldReplaceExistingValue */);

			ConfigValues.Emplace(TEXT("DefaultEngine.ini"),
				TEXT("/Script/Engine.RendererSettings"),
				TEXT("r.RayTracing"),
				TEXT("True"),
				true /* ShouldReplaceExistingValue */);
		}
	}

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Public/GPUSkinCache.h:7

Scope: file

Source code excerpt:

// Requirements
// * Compute shader support (with Atomics)
// * Project settings needs to be enabled (r.SkinCache.CompileShaders)
// * feature need to be enabled (r.SkinCache.Mode)

// Features
// * Skeletal mesh, 4 / 8 weights per vertex, 16/32 index buffer
// * Supports Morph target animation (morph target blending is not done by this code)
// * Saves vertex shader computations when we render an object multiple times (EarlyZ, velocity, shadow, BasePass, CustomDepth, Shadow masking)

#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/RenderUtils.cpp:963

Scope (from outer to inner):

file
function     void RenderUtilsInit

Source code excerpt:

			// Sanity check: skin cache is *required* for ray tracing.
			// It can be dynamically enabled only when its shaders have been compiled.
			IConsoleVariable* SkinCacheCompileShadersCVar = IConsoleManager::Get().FindConsoleVariable(TEXT("r.SkinCache.CompileShaders"));
			const bool bUseRayTracing = (int32)GRayTracingMode >= (int32)ERayTracingMode::Enabled;
			if (bUseRayTracing && SkinCacheCompileShadersCVar->GetInt() <= 0)
			{
				GRayTracingMode = ERayTracingMode::Disabled;

				UE_LOG(LogRendererCore, Fatal, TEXT("Ray tracing requires skin cache to be enabled. Set r.SkinCache.CompileShaders=1."));

#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/RenderUtils.cpp:1426

Scope (from outer to inner):

file
function     bool AreSkinCacheShadersEnabled

Source code excerpt:

RENDERCORE_API bool AreSkinCacheShadersEnabled(EShaderPlatform Platform)
{
	static FShaderPlatformCachedIniValue<bool> PerPlatformCVar(TEXT("r.SkinCache.CompileShaders"));
	return (PerPlatformCVar.Get(Platform) != 0);
}

RENDERCORE_API bool IsGPUSkinCacheAllowed(EShaderPlatform Platform)
{
	static FShaderPlatformCachedIniValue<bool> PerPlatformCVar(TEXT("r.SkinCache.Allow"));

#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Public/RenderUtils.h:472

Scope: file

Source code excerpt:


/**
 *   Checks if skin cache shaders are enabled for the platform (via r.SkinCache.CompileShaders)
 */
RENDERCORE_API bool AreSkinCacheShadersEnabled(EShaderPlatform Platform);

/**
 * Checks if skin cache shaders are allowed for the platform (via r.SkinCache.Allow)
 */
RENDERCORE_API bool IsGPUSkinCacheAllowed(EShaderPlatform Platform);