r.SkinCache.Mode
r.SkinCache.Mode
#Overview
name: r.SkinCache.Mode
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Whether or not to use the GPU compute skinning cache.\nThis will perform skinning on a compute job and not skin on the vertex shader.\nRequires r.SkinCache.CompileShaders=1 and r.SkinCache.Allow=1\n 0: off\n 1: on(default)\n
It is referenced in 7
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of r.SkinCache.Mode is to control the usage of the GPU compute skinning cache in Unreal Engine 5. This setting is primarily used for the character animation and rendering system.
The GPU Skin Cache is a feature that offloads skinning calculations from the vertex shader to a compute shader, potentially improving performance for complex character animations. This variable determines whether the GPU Skin Cache is enabled or disabled.
Based on the callsites, this setting is used in the following Unreal Engine subsystems and modules:
- Engine module (GPUSkinCache.cpp)
- HairStrands plugin (GroomManager.cpp)
The value of this variable is set through the console variable system. It’s defined as a TAutoConsoleVariable with a default value of 1 (enabled). Developers can change this value at runtime using console commands or through configuration files.
This variable interacts with several other variables, including:
- r.SkinCache.CompileShaders
- r.SkinCache.Allow
- r.SkinCache.DefaultBehavior
Developers should be aware of the following when using this variable:
- It requires r.SkinCache.CompileShaders=1 and r.SkinCache.Allow=1 to function properly.
- It affects performance and memory usage, as it determines whether skinning calculations are performed on the GPU or in the vertex shader.
- It can be toggled at runtime, allowing for dynamic performance tuning.
Best practices for using this variable include:
- Enable it (set to 1) for complex character animations to potentially improve performance.
- Ensure that r.SkinCache.CompileShaders and r.SkinCache.Allow are also set to 1.
- Profile your application with and without the GPU Skin Cache enabled to determine the optimal setting for your specific use case.
Regarding the associated variable CVarEnableGPUSkinCache:
The purpose of CVarEnableGPUSkinCache is to provide a console variable interface for controlling the r.SkinCache.Mode setting. It’s defined as a TAutoConsoleVariable and shares the same value and purpose as r.SkinCache.Mode.
This variable is used in the Engine module, specifically in the GPUSkinCache system. Its value is set through the console variable system, just like r.SkinCache.Mode.
CVarEnableGPUSkinCache interacts directly with the GEnableGPUSkinCache global variable, which is used internally by the engine to quickly check the GPU Skin Cache state.
Developers should be aware that changes to CVarEnableGPUSkinCache will affect the GPU Skin Cache system’s behavior at runtime. The FGPUSkinCache::CVarSinkFunction() method is responsible for updating the internal state when this variable changes.
Best practices for using CVarEnableGPUSkinCache are the same as those for r.SkinCache.Mode, as they essentially control the same feature.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/GPUSkinCache.cpp:97
Scope: file
Source code excerpt:
int32 GEnableGPUSkinCache = 1;
static TAutoConsoleVariable<int32> CVarEnableGPUSkinCache(
TEXT("r.SkinCache.Mode"),
1,
TEXT("Whether or not to use the GPU compute skinning cache.\n")
TEXT("This will perform skinning on a compute job and not skin on the vertex shader.\n")
TEXT("Requires r.SkinCache.CompileShaders=1 and r.SkinCache.Allow=1\n")
TEXT(" 0: off\n")
TEXT(" 1: on(default)\n"),
#Loc: <Workspace>/Engine/Plugins/Runtime/HairStrands/Source/HairStrandsCore/Private/GroomManager.cpp:419
Scope (from outer to inner):
file
function static void AddHairSkinCacheDebugPass
Source code excerpt:
{
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;
}
const uint32 InstanceCount = Instances.Num();
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/GPUSkinCache.cpp:201
Scope (from outer to inner):
file
function static inline bool IsGPUSkinCacheEnable
Source code excerpt:
static inline bool IsGPUSkinCacheEnable(EShaderPlatform Platform)
{
static FShaderPlatformCachedIniValue<int32> PerPlatformCVar(TEXT("r.SkinCache.Mode"));
return (PerPlatformCVar.Get(Platform) != 0);
}
static inline bool IsGPUSkinCacheInclusive(EShaderPlatform Platform)
{
static FShaderPlatformCachedIniValue<int32> PerPlatformCVar(TEXT("r.SkinCache.DefaultBehavior"));
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Public/GPUSkinCache.h:8
Scope: file
Source code excerpt:
// * 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)
// * Fixes velocity rendering (needed for MotionBlur and TemporalAA) for WorldPosOffset animation and morph target animation
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Public/GPUSkinCache.h:18
Scope: file
Source code excerpt:
// * fixed amount of memory per Scene (r.SkinCache.SceneMemoryLimitInMB)
// * Velocity Rendering for MotionBlur and TemporalAA (test Velocity in BasePass)
// * r.SkinCache.Mode and r.SkinCache.RecomputeTangents can be toggled at runtime
// TODO:
// * Test: Tessellation
// * Quality/Optimization: increase TANGENT_RANGE for better quality or accumulate two components in one 32bit value
// * Bug: UpdateMorphVertexBuffer needs to handle SkinCacheObjects that have been rejected by the SkinCache (e.g. because it was running out of memory)
// * Refactor: Unify the 3 compute shaders to use the same C++ setup code for the variables
#Associated Variable and Callsites
This variable is associated with another variable named CVarEnableGPUSkinCache
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/GPUSkinCache.cpp:96
Scope: file
Source code excerpt:
// 0/1
int32 GEnableGPUSkinCache = 1;
static TAutoConsoleVariable<int32> CVarEnableGPUSkinCache(
TEXT("r.SkinCache.Mode"),
1,
TEXT("Whether or not to use the GPU compute skinning cache.\n")
TEXT("This will perform skinning on a compute job and not skin on the vertex shader.\n")
TEXT("Requires r.SkinCache.CompileShaders=1 and r.SkinCache.Allow=1\n")
TEXT(" 0: off\n")
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/GPUSkinCache.cpp:2305
Scope (from outer to inner):
file
function void FGPUSkinCache::CVarSinkFunction
Source code excerpt:
void FGPUSkinCache::CVarSinkFunction()
{
int32 NewGPUSkinCacheValue = CVarEnableGPUSkinCache.GetValueOnAnyThread() != 0;
int32 NewRecomputeTangentsValue = CVarGPUSkinCacheRecomputeTangents.GetValueOnAnyThread();
const float NewSceneMaxSizeInMb = CVarGPUSkinCacheSceneMemoryLimitInMB.GetValueOnAnyThread();
const int32 NewNumTangentIntermediateBuffers = CVarGPUSkinNumTangentIntermediateBuffers.GetValueOnAnyThread();
const bool NewSkipCompilingGPUSkinVF = CVarSkipCompilingGPUSkinVF.GetValueOnAnyThread();
if (GEnableGPUSkinCacheShaders)