r.Shadow.Virtual.Cache.AllocateViaLRU
r.Shadow.Virtual.Cache.AllocateViaLRU
#Overview
name: r.Shadow.Virtual.Cache.AllocateViaLRU
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Prioritizes keeping more recently requested cached physical pages when allocating for new requests.
It is referenced in 3
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of r.Shadow.Virtual.Cache.AllocateViaLRU is to control the allocation strategy for physical pages in the virtual shadow map system. Specifically, it prioritizes keeping more recently requested cached physical pages when allocating for new requests.
This setting variable is primarily used by the rendering system, particularly in the virtual shadow mapping subsystem of Unreal Engine 5. It’s part of the optimization mechanisms for managing shadow map resources efficiently.
The value of this variable is set through a console variable (CVar) system. It’s initialized with a default value of 0, which means the LRU (Least Recently Used) allocation strategy is not enabled by default.
The associated variable CVarCacheAllocateViaLRU directly interacts with r.Shadow.Virtual.Cache.AllocateViaLRU. They share the same value and purpose.
Developers should be aware that enabling this option (by setting it to a non-zero value) may impact the performance and memory usage of the shadow mapping system. It could potentially improve cache efficiency by prioritizing recently used pages, but it might also introduce some overhead in managing the LRU order.
Best practices when using this variable include:
- Testing the impact on performance and visual quality with and without this option enabled.
- Monitoring memory usage, especially if dealing with complex scenes with many shadow-casting objects.
- Considering the trade-off between potentially improved cache efficiency and the overhead of LRU management.
Regarding the associated variable CVarCacheAllocateViaLRU:
The purpose of CVarCacheAllocateViaLRU is identical to r.Shadow.Virtual.Cache.AllocateViaLRU. It’s the internal representation of the console variable in the C++ code.
This variable is used directly in the rendering code, specifically in the FVirtualShadowMapArray::BuildPageAllocations function. It’s queried to determine whether to enable LRU-based allocation for the virtual shadow map system.
The value is set through the CVar system and can be changed at runtime.
Developers should be aware that changes to this variable will take effect on the render thread, as indicated by the ECVF_RenderThreadSafe flag.
Best practices include using this variable for debugging and performance tuning, and ensuring that any runtime changes are made with consideration for potential impacts on rendering performance and quality.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/VirtualShadowMaps/VirtualShadowMapArray.cpp:233
Scope: file
Source code excerpt:
static TAutoConsoleVariable<int32> CVarCacheAllocateViaLRU(
TEXT("r.Shadow.Virtual.Cache.AllocateViaLRU"),
0,
TEXT("Prioritizes keeping more recently requested cached physical pages when allocating for new requests."),
ECVF_RenderThreadSafe
);
static TAutoConsoleVariable<int32> CVarClipmapGreedyLevelSelection(
#Associated Variable and Callsites
This variable is associated with another variable named CVarCacheAllocateViaLRU
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/VirtualShadowMaps/VirtualShadowMapArray.cpp:232
Scope: file
Source code excerpt:
);
static TAutoConsoleVariable<int32> CVarCacheAllocateViaLRU(
TEXT("r.Shadow.Virtual.Cache.AllocateViaLRU"),
0,
TEXT("Prioritizes keeping more recently requested cached physical pages when allocating for new requests."),
ECVF_RenderThreadSafe
);
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/VirtualShadowMaps/VirtualShadowMapArray.cpp:1609
Scope (from outer to inner):
file
function void FVirtualShadowMapArray::BuildPageAllocations
Source code excerpt:
PassParameters->bDynamicPageInvalidation = CVarDebugSkipDynamicPageInvalidation.GetValueOnRenderThread() == 0 ? 1 : 0;
#endif
PassParameters->bAllocateViaLRU = CVarCacheAllocateViaLRU.GetValueOnRenderThread();
}
FUpdatePhysicalPages::FPermutationDomain PermutationVector;
PermutationVector.Set<FUpdatePhysicalPages::FHasCacheDataDim>(bCacheDataAvailable);
SetStatsArgsAndPermutation<FUpdatePhysicalPages>(StatsBufferUAV, PassParameters, PermutationVector);
auto ComputeShader = Views[0].ShaderMap->GetShader<FUpdatePhysicalPages>(PermutationVector);