r.VirtualTextureReducedMemory
r.VirtualTextureReducedMemory
#Overview
name: r.VirtualTextureReducedMemory
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
If set to 1, the cost of virtual textures will be reduced by using a more packed layout.
It is referenced in 6
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of r.VirtualTextureReducedMemory is to optimize memory usage for virtual textures in Unreal Engine 5. It is primarily used in the rendering system to control the memory layout and allocation for virtual textures.
This setting variable is relied upon by the Engine’s rendering subsystem, particularly in components dealing with texture streaming and resource management. It is referenced in the Core, Engine, and Rendering modules of Unreal Engine.
The value of this variable is set through the console or configuration files. It is defined as a console variable (CVar) with an initial value of 0, which can be changed at runtime.
This variable interacts with other texture-related variables and flags, such as bUsePartiallyResidentMips and TexCreate_Virtual. It influences decisions about texture creation, memory allocation, and streaming behavior.
Developers must be aware that enabling this variable (setting it to 1) will result in a more packed layout for virtual textures, which can significantly reduce memory usage. However, this may come at the cost of some performance or visual quality in certain scenarios.
Best practices when using this variable include:
- Testing thoroughly to ensure that enabling reduced memory mode doesn’t negatively impact visual quality or performance in your specific use case.
- Considering the trade-off between memory savings and potential performance impacts.
- Using this in conjunction with other texture streaming and memory management settings for optimal results.
- Monitoring performance and memory usage with and without this setting enabled to determine if it’s beneficial for your project.
- Being cautious when changing this setting at runtime, as it can affect texture creation and streaming behavior.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Core/Private/HAL/ConsoleManager.cpp:4082
Scope: file
Source code excerpt:
static TAutoConsoleVariable<int32> CVarVirtualTextureReducedMemoryEnabled(
TEXT("r.VirtualTextureReducedMemory"),
0,
TEXT("If set to 1, the cost of virtual textures will be reduced by using a more packed layout."),
ECVF_RenderThreadSafe);
static TAutoConsoleVariable<int32> CVarPrecomputedVisibilityWarning(
TEXT("r.PrecomputedVisibilityWarning"),
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Rendering/StreamableTextureResource.cpp:119
Scope (from outer to inner):
file
function FStreamableTextureResource::FStreamableTextureResource
Source code excerpt:
// Whether the virtual update path is enabled for this texture. This allows to map / unmap top mip memory in an out.
// Whether the texture will be created with TexCreate_Virtual depends on the requested mip count and "r.VirtualTextureReducedMemory"
bUsePartiallyResidentMips = bAllowPartiallyResidentMips && InPostInitState.bSupportsStreaming && CanCreateWithPartiallyResidentMips(CreationFlags);
STAT(LODGroupStatName = TextureGroupStatFNames[LODGroup]);
STAT(bIsNeverStream = InOwner->NeverStream);
}
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Rendering/StreamableTextureResource.cpp:176
Scope (from outer to inner):
file
function void FStreamableTextureResource::InitRHI
Source code excerpt:
// Check if this is the initial creation of the texture, or if we're recreating a texture that was released by ReleaseRHI.
static TConsoleVariableData<int32>* CVarReducedMode = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.VirtualTextureReducedMemory"));
check(CVarReducedMode);
if (bUsePartiallyResidentMips && (!CVarReducedMode->GetValueOnRenderThread() || State.NumRequestedLODs > State.NumNonStreamingLODs))
{
CreatePartiallyResidentTexture();
}
else
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Rendering/Texture2DResource.cpp:202
Scope (from outer to inner):
file
function uint64 FTexture2DResource::GetPlatformMipsSize
Source code excerpt:
if (PlatformData && NumMips > 0)
{
static TConsoleVariableData<int32>* CVarReducedMode = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.VirtualTextureReducedMemory"));
check(CVarReducedMode);
uint32 TextureAlign = 0;
// Must be consistent with the logic in FTexture2DResource::InitRHI
if (bUsePartiallyResidentMips && (!CVarReducedMode->GetValueOnRenderThread() || NumMips > State.NumNonStreamingLODs))
{
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Streaming/Texture2DStreamOut_Virtual.cpp:28
Scope (from outer to inner):
file
function void FTexture2DStreamOut_Virtual::Finalize
Source code excerpt:
check(Context.CurrentThread == TT_Render);
static TConsoleVariableData<int32>* CVarReducedMode = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.VirtualTextureReducedMemory"));
check(CVarReducedMode);
if (!CVarReducedMode->GetValueOnRenderThread() || ResourceState.NumRequestedLODs > ResourceState.NumNonStreamingLODs)
{
IntermediateTextureRHI = Context.Resource->GetTexture2DRHI();
RHIVirtualTextureSetFirstMipVisible(IntermediateTextureRHI, PendingFirstLODIdx);
#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/Texture2D.cpp:808
Scope (from outer to inner):
file
function int32 UTexture2D::CalcTextureMemorySize
Source code excerpt:
if (GetPlatformData())
{
static TConsoleVariableData<int32>* CVarReducedMode = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.VirtualTextureReducedMemory"));
check(CVarReducedMode);
ETextureCreateFlags TexCreateFlags = (SRGB ? TexCreate_SRGB : TexCreate_None) | (bNoTiling ? TexCreate_NoTiling : TexCreate_None) | (bNotOfflineProcessed ? TexCreate_None : TexCreate_OfflineProcessed) | TexCreate_Streamable;
const bool bCanUsePartiallyResidentMips = CanCreateWithPartiallyResidentMips(TexCreateFlags);
const int32 SizeX = GetSizeX();