r.VT.AVT.MaxFreePerFrame
r.VT.AVT.MaxFreePerFrame
#Overview
name: r.VT.AVT.MaxFreePerFrame
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Max number of allocated VT for adaptive VT to free per frame
It is referenced in 4
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of r.VT.AVT.MaxFreePerFrame is to control the maximum number of allocated Virtual Textures (VT) that the Adaptive Virtual Texture (AVT) system can free per frame. This setting is part of Unreal Engine 5’s rendering system, specifically the Virtual Texturing subsystem.
This setting variable is primarily used in the Renderer module, specifically within the Adaptive Virtual Texture system. It’s referenced in the file AdaptiveVirtualTexture.cpp, which suggests it’s crucial for managing virtual texture allocations and deallocations.
The value of this variable is set through a console variable (CVarAVTMaxFreePerFrame) with a default value of 1. It can be modified at runtime through console commands or programmatically.
This variable interacts closely with other AVT-related variables, such as CVarAVTAgeToFree and CVarAVTMaxPageResidency. These variables work together to manage the lifecycle and residency of virtual texture pages.
Developers should be aware that this variable directly impacts performance and memory usage. Setting it too high might cause frame rate drops due to excessive deallocation work per frame, while setting it too low might lead to inefficient memory usage if unused textures aren’t freed quickly enough.
Best practices for using this variable include:
- Monitoring performance and memory usage when adjusting this value.
- Balancing it with other AVT settings for optimal performance.
- Consider adjusting it based on the target hardware capabilities and the specific needs of your game or application.
Regarding the associated variable CVarAVTMaxFreePerFrame:
This is the actual console variable that controls the r.VT.AVT.MaxFreePerFrame setting. It’s defined as a TAutoConsoleVariable
The purpose of CVarAVTMaxFreePerFrame is to provide a programmable interface for the r.VT.AVT.MaxFreePerFrame setting. It’s used directly in the UpdateAllocations function of the FAdaptiveVirtualTexture class to determine how many virtual texture pages can be freed in a single frame.
This variable is crucial for the Renderer module, specifically the Virtual Texturing system. It’s accessed using the GetValueOnRenderThread() method, ensuring thread-safe access in the render thread.
The value of CVarAVTMaxFreePerFrame is set when it’s defined, with a default value of 1. It can be changed through console commands or programmatically at runtime.
Developers should be aware that changing this value directly impacts the behavior of the Adaptive Virtual Texture system. It’s used in conjunction with other variables like CVarAVTAgeToFree and CVarAVTMaxPageResidency to manage virtual texture allocations.
Best practices for using CVarAVTMaxFreePerFrame include:
- Use it in conjunction with other AVT settings for fine-tuned control over virtual texture management.
- Monitor its impact on performance, especially when modifying it at runtime.
- Consider exposing it as a configurable setting for different performance profiles in your game or application.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/VT/AdaptiveVirtualTexture.cpp:17
Scope: file
Source code excerpt:
static TAutoConsoleVariable<int32> CVarAVTMaxFreePerFrame(
TEXT("r.VT.AVT.MaxFreePerFrame"),
1,
TEXT("Max number of allocated VT for adaptive VT to free per frame"),
ECVF_RenderThreadSafe
);
static TAutoConsoleVariable<int32> CVarAVTMaxPageResidency(
#Associated Variable and Callsites
This variable is associated with another variable named CVarAVTMaxFreePerFrame
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/VT/AdaptiveVirtualTexture.cpp:16
Scope: file
Source code excerpt:
);
static TAutoConsoleVariable<int32> CVarAVTMaxFreePerFrame(
TEXT("r.VT.AVT.MaxFreePerFrame"),
1,
TEXT("Max number of allocated VT for adaptive VT to free per frame"),
ECVF_RenderThreadSafe
);
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/VT/AdaptiveVirtualTexture.cpp:678
Scope (from outer to inner):
file
function void FAdaptiveVirtualTexture::UpdateAllocations
Source code excerpt:
// Free old unused pages if there is no other work to do.
const uint32 FrameAgeToFree = CVarAVTAgeToFree.GetValueOnRenderThread();
const int32 NumToFree = FMath::Min(NumAllocated, CVarAVTMaxFreePerFrame.GetValueOnRenderThread());
bool bFreeSuccess = true;
for (int32 FreeCount = 0; bFreeSuccess && FreeCount < NumToFree; FreeCount++)
{
bFreeSuccess = FreeLRU(RHICmdList, InSystem, InFrame, FrameAgeToFree);
}
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/VT/AdaptiveVirtualTexture.cpp:693
Scope (from outer to inner):
file
function void FAdaptiveVirtualTexture::UpdateAllocations
Source code excerpt:
const uint32 ResidencyPercent = FMath::Clamp(CVarAVTMaxPageResidency.GetValueOnRenderThread(), 10, 95);
const uint32 TargetPages = TotalPages * ResidencyPercent / 100;
const int32 NumToFree = FMath::Min(NumAllocated, CVarAVTMaxFreePerFrame.GetValueOnRenderThread());
bool bFreeSuccess = true;
for (int32 FreeCount = 0; bFreeSuccess && FreeCount < NumToFree && Space->GetAllocator().GetNumAllocatedPages() > TargetPages; FreeCount++)
{
const uint32 FrameAgeToFree = 15; // Hardcoded threshold. Don't release anything used more recently then this.
bFreeSuccess = FreeLRU(RHICmdList, InSystem, InFrame, FrameAgeToFree);