r.Shadow.Virtual.Cache
r.Shadow.Virtual.Cache
#Overview
name: r.Shadow.Virtual.Cache
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Turn on to enable caching
It is referenced in 3
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of r.Shadow.Virtual.Cache is to control the caching functionality for virtual shadow maps in Unreal Engine’s rendering system. This setting variable is used to enable or disable the caching of virtual shadow maps.
This setting variable is primarily used by the renderer module, specifically within the virtual shadow map subsystem. Based on the provided code snippets, it’s clear that this variable is utilized in the VirtualShadowMapCacheManager.cpp file, which is part of the renderer’s implementation of virtual shadow maps.
The value of this variable is set through a console variable (CVar) system. It’s initialized with a default value of 1, meaning caching is enabled by default. Users can modify this value at runtime using console commands.
The associated variable CVarCacheVirtualSMs directly interacts with r.Shadow.Virtual.Cache. It’s an instance of TAutoConsoleVariable
Developers must be aware that this variable affects the performance and memory usage of the virtual shadow map system. Enabling caching (value != 0) can improve performance by reusing previously computed shadow information, but it may also increase memory usage.
Best practices when using this variable include:
- Leave it enabled (default value of 1) for most scenarios, as caching generally improves performance.
- Consider disabling it (set to 0) if you’re experiencing memory pressure and are willing to trade some performance for reduced memory usage.
- Profile your application with caching enabled and disabled to understand the impact on your specific use case.
Regarding the associated variable CVarCacheVirtualSMs: The purpose of CVarCacheVirtualSMs is to provide a programmatic interface to the r.Shadow.Virtual.Cache console variable. It allows C++ code to easily read and potentially modify the caching setting.
This variable is used within the FVirtualShadowMapArrayCacheManager class to determine if caching is enabled. The IsCacheEnabled() function checks the value of CVarCacheVirtualSMs to decide whether to perform caching operations.
Developers should be aware that changes to CVarCacheVirtualSMs will directly affect the behavior of the virtual shadow map caching system. When using this variable in code, always access it through the provided getter methods (like GetValueOnRenderThread()) to ensure thread-safe access.
Best practices for using CVarCacheVirtualSMs include:
- Use it for read-only purposes in most cases, allowing users to control the setting via console commands.
- If modifying the value programmatically, ensure it’s done in a thread-safe manner and consider the potential performance implications.
- When checking the value, use the appropriate getter method based on the current execution context (e.g., GetValueOnRenderThread() for render thread code).
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/VirtualShadowMaps/VirtualShadowMapCacheManager.cpp:25
Scope: file
Source code excerpt:
static TAutoConsoleVariable<int32> CVarCacheVirtualSMs(
TEXT("r.Shadow.Virtual.Cache"),
1,
TEXT("Turn on to enable caching"),
ECVF_RenderThreadSafe
);
static TAutoConsoleVariable<int32> CVarDrawInvalidatingBounds(
#Associated Variable and Callsites
This variable is associated with another variable named CVarCacheVirtualSMs
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/VirtualShadowMaps/VirtualShadowMapCacheManager.cpp:24
Scope: file
Source code excerpt:
);
static TAutoConsoleVariable<int32> CVarCacheVirtualSMs(
TEXT("r.Shadow.Virtual.Cache"),
1,
TEXT("Turn on to enable caching"),
ECVF_RenderThreadSafe
);
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/VirtualShadowMaps/VirtualShadowMapCacheManager.cpp:767
Scope (from outer to inner):
file
function bool FVirtualShadowMapArrayCacheManager::IsCacheEnabled
Source code excerpt:
bool FVirtualShadowMapArrayCacheManager::IsCacheEnabled()
{
return CVarCacheVirtualSMs.GetValueOnRenderThread() != 0;
}
bool FVirtualShadowMapArrayCacheManager::IsCacheDataAvailable()
{
return IsCacheEnabled() &&
PhysicalPagePool &&