rhi.ResourceTableCaching
rhi.ResourceTableCaching
#Overview
name: rhi.ResourceTableCaching
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
If 1, the RHI will cache resource table contents within a frame. Otherwise resource tables are rebuilt for every draw call.
It is referenced in 6
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of rhi.ResourceTableCaching is to control the caching behavior of resource tables within the Rendering Hardware Interface (RHI) subsystem of Unreal Engine 5. It determines whether the RHI will cache resource table contents within a frame or rebuild them for every draw call.
This setting variable is primarily used by the RHI subsystem, specifically in the OpenGL and Direct3D 11 implementations. It’s referenced in the OpenGLDrv and D3D11RHI modules.
The value of this variable is set through a console variable (CVar) system. It’s defined in the RHI.cpp file with a default value of 1, meaning caching is enabled by default.
The associated variable ResourceTableCachingCvar interacts directly with rhi.ResourceTableCaching. It’s used to retrieve the current value of the setting in the RHIBeginScene() functions of both OpenGL and D3D11 implementations.
Developers should be aware that this variable affects rendering performance. When set to 1 (default), it enables caching of resource table contents within a frame, which can improve performance by reducing redundant rebuilds. When set to 0, resource tables are rebuilt for every draw call, which might be necessary for certain debugging scenarios or specific rendering requirements.
Best practices when using this variable include:
- Leave it at the default value (1) for optimal performance in most cases.
- Only disable it (set to 0) if you’re experiencing rendering issues that might be related to cached resource tables, or if you need to ensure that resource tables are always up-to-date for each draw call.
- Profile your application with both settings to understand the performance impact in your specific use case.
Regarding the associated variable ResourceTableCachingCvar:
The purpose of ResourceTableCachingCvar is to provide a programmatic way to access the value of the rhi.ResourceTableCaching setting within the engine’s C++ code.
It’s used in the RHI subsystem, specifically in the OpenGL and Direct3D 11 implementations, to determine whether to update the ResourceTableFrameCounter.
The value of ResourceTableCachingCvar is set automatically by the engine’s console variable system based on the rhi.ResourceTableCaching setting.
It interacts directly with the rhi.ResourceTableCaching setting, essentially serving as its in-code representation.
Developers should be aware that this variable is used to control the behavior of resource table caching at runtime. Its value determines whether the ResourceTableFrameCounter is updated in the RHIBeginScene() function.
Best practices for using ResourceTableCachingCvar include:
- Use it to read the current state of resource table caching in your code if needed.
- Avoid modifying it directly; instead, change the rhi.ResourceTableCaching setting if you need to alter the caching behavior.
- Be mindful of its impact on rendering performance when making decisions based on its value.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/RHI/Private/RHI.cpp:1088
Scope: file
Source code excerpt:
static TAutoConsoleVariable<int32> ResourceTableCachingCvar(
TEXT("rhi.ResourceTableCaching"),
1,
TEXT("If 1, the RHI will cache resource table contents within a frame. Otherwise resource tables are rebuilt for every draw call.")
);
static TAutoConsoleVariable<int32> GSaveScreenshotAfterProfilingGPUCVar(
TEXT("r.ProfileGPU.Screenshot"),
1,
#Loc: <Workspace>/Engine/Source/Runtime/OpenGLDrv/Private/OpenGLDevice.cpp:254
Scope (from outer to inner):
file
function void FOpenGLDynamicRHI::RHIBeginScene
Source code excerpt:
}
static auto* ResourceTableCachingCvar = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("rhi.ResourceTableCaching"));
if (ResourceTableCachingCvar == NULL || ResourceTableCachingCvar->GetValueOnAnyThread() == 1)
{
ResourceTableFrameCounter = SceneFrameCounter;
}
BeginSceneContextType = (int32)PlatformOpenGLCurrentContext(PlatformDevice);
#Loc: <Workspace>/Engine/Source/Runtime/Windows/D3D11RHI/Private/D3D11RHI.cpp:474
Scope (from outer to inner):
file
function void FD3D11DynamicRHI::RHIBeginScene
Source code excerpt:
}
static auto* ResourceTableCachingCvar = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("rhi.ResourceTableCaching"));
if (ResourceTableCachingCvar == NULL || ResourceTableCachingCvar->GetValueOnAnyThread() == 1)
{
ResourceTableFrameCounter = SceneFrameCounter;
}
}
#Associated Variable and Callsites
This variable is associated with another variable named ResourceTableCachingCvar
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/OpenGLDrv/Private/OpenGLDevice.cpp:254
Scope (from outer to inner):
file
function void FOpenGLDynamicRHI::RHIBeginScene
Source code excerpt:
}
static auto* ResourceTableCachingCvar = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("rhi.ResourceTableCaching"));
if (ResourceTableCachingCvar == NULL || ResourceTableCachingCvar->GetValueOnAnyThread() == 1)
{
ResourceTableFrameCounter = SceneFrameCounter;
}
BeginSceneContextType = (int32)PlatformOpenGLCurrentContext(PlatformDevice);
}
#Loc: <Workspace>/Engine/Source/Runtime/RHI/Private/RHI.cpp:1087
Scope: file
Source code excerpt:
*/
static TAutoConsoleVariable<int32> ResourceTableCachingCvar(
TEXT("rhi.ResourceTableCaching"),
1,
TEXT("If 1, the RHI will cache resource table contents within a frame. Otherwise resource tables are rebuilt for every draw call.")
);
static TAutoConsoleVariable<int32> GSaveScreenshotAfterProfilingGPUCVar(
TEXT("r.ProfileGPU.Screenshot"),
#Loc: <Workspace>/Engine/Source/Runtime/Windows/D3D11RHI/Private/D3D11RHI.cpp:474
Scope (from outer to inner):
file
function void FD3D11DynamicRHI::RHIBeginScene
Source code excerpt:
}
static auto* ResourceTableCachingCvar = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("rhi.ResourceTableCaching"));
if (ResourceTableCachingCvar == NULL || ResourceTableCachingCvar->GetValueOnAnyThread() == 1)
{
ResourceTableFrameCounter = SceneFrameCounter;
}
}
void FD3D11DynamicRHI::RHIEndScene()