r.RayTracing.SceneUpdateOnce
r.RayTracing.SceneUpdateOnce
#Overview
name: r.RayTracing.SceneUpdateOnce
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Experimental: Improves GPU perf by updating ray tracing scene once, but may cause artifacts (mainly for nDisplay)\n
It is referenced in 3
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of r.RayTracing.SceneUpdateOnce is to improve GPU performance in ray tracing scenarios by updating the ray tracing scene only once. This is an experimental feature primarily aimed at addressing performance issues in nDisplay setups.
This setting variable is used in the rendering system, specifically in the ray tracing subsystem of Unreal Engine 5. Based on the callsites, it’s primarily utilized in the SceneRendering module, which is responsible for rendering the game scene.
The value of this variable is set through a console variable (CVar) system. It’s defined as a TAutoConsoleVariable with an initial value of 0, meaning it’s disabled by default.
The associated variable CVarRayTracingSceneUpdateOnce directly interacts with r.RayTracing.SceneUpdateOnce. They share the same value and purpose.
Developers must be aware that while this variable can improve GPU performance, it may cause artifacts in the rendered scene. This trade-off is particularly noticeable in nDisplay setups, which are typically used for multi-display or multi-projector configurations.
Best practices when using this variable include:
- Only enable it if you’re experiencing performance issues with ray tracing, especially in nDisplay setups.
- Thoroughly test the visual quality of your scenes after enabling this feature, as it may introduce artifacts.
- Use it as a last resort optimization, after other performance improvements have been exhausted.
- Consider providing an in-game option to toggle this feature, allowing end-users to choose between performance and visual quality.
Regarding the associated variable CVarRayTracingSceneUpdateOnce:
The purpose of CVarRayTracingSceneUpdateOnce is to provide programmatic access to the r.RayTracing.SceneUpdateOnce setting within the C++ code of the engine.
It’s used in the SceneRendering module to determine whether the ray tracing scene should be updated only once. This is evident from the code snippet where its value is checked in the render thread:
const bool bRayTracingSceneUpdateOnce = CVarRayTracingSceneUpdateOnce.GetValueOnRenderThread() != 0;
The value of this variable is set through the console variable system, just like r.RayTracing.SceneUpdateOnce.
Developers should be aware that changes to this variable will directly affect the behavior of the ray tracing system. It’s important to use this variable consistently with r.RayTracing.SceneUpdateOnce to avoid confusion or unexpected behavior.
Best practices for using CVarRayTracingSceneUpdateOnce include:
- Always access its value using the GetValueOnRenderThread() method to ensure thread-safety.
- Consider caching the value if it’s used frequently in performance-critical sections of code.
- Be cautious when modifying this variable at runtime, as it could lead to visual inconsistencies if not handled properly.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/SceneRendering.cpp:238
Scope: file
Source code excerpt:
static TAutoConsoleVariable<int32> CVarRayTracingSceneUpdateOnce(
TEXT("r.RayTracing.SceneUpdateOnce"),
0,
TEXT("Experimental: Improves GPU perf by updating ray tracing scene once, but may cause artifacts (mainly for nDisplay)\n"),
ECVF_RenderThreadSafe
);
static TAutoConsoleVariable<int32> CVarAllowTranslucencyAfterDOF(
#Associated Variable and Callsites
This variable is associated with another variable named CVarRayTracingSceneUpdateOnce
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/SceneRendering.cpp:237
Scope: file
Source code excerpt:
);
static TAutoConsoleVariable<int32> CVarRayTracingSceneUpdateOnce(
TEXT("r.RayTracing.SceneUpdateOnce"),
0,
TEXT("Experimental: Improves GPU perf by updating ray tracing scene once, but may cause artifacts (mainly for nDisplay)\n"),
ECVF_RenderThreadSafe
);
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/SceneRendering.cpp:4321
Scope (from outer to inner):
file
function void FSceneRenderer::CreateSceneRenderers
lambda-function
Source code excerpt:
// update it for all scene renders.
bool bShouldUpdateRayTracingScene = true;
const bool bRayTracingSceneUpdateOnce = CVarRayTracingSceneUpdateOnce.GetValueOnRenderThread() != 0;
for (int32 RendererIndex = 0; RendererIndex < SceneRenderers.Num(); RendererIndex++)
{
FDeferredShadingSceneRenderer* SceneRenderer = (FDeferredShadingSceneRenderer*)SceneRenderers[RendererIndex];
SceneRenderer->InitializeRayTracingFlags_RenderThread();