r.PathTracing.MultiGPU
r.PathTracing.MultiGPU
#Overview
name: r.PathTracing.MultiGPU
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Run the path tracer using all available GPUs when enabled (default = 0)\nUsing this functionality in the editor requires -MaxGPUCount=N setting on the command line
It is referenced in 3
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of r.PathTracing.MultiGPU is to control whether the path tracing system in Unreal Engine 5 utilizes multiple GPUs for rendering. This setting is specifically designed for the rendering system, particularly the path tracing component.
This setting variable is primarily used in the Renderer module of Unreal Engine, specifically within the path tracing subsystem. It’s defined and used in the PathTracing.cpp file, which is part of the core rendering functionality.
The value of this variable is set through a console variable (CVar) system. It’s initialized with a default value of 0, meaning multi-GPU path tracing is disabled by default. Users can change this value at runtime through console commands or configuration files.
The associated variable CVarPathTracingMultiGPU directly interacts with r.PathTracing.MultiGPU. They share the same value and purpose, with CVarPathTracingMultiGPU being the actual C++ variable that stores and provides access to the setting.
Developers must be aware of several important points when using this variable:
- It’s only effective when the engine is compiled with multi-GPU support (WITH_MGPU preprocessor definition).
- Enabling this in the editor requires additional command-line settings (-MaxGPUCount=N).
- It’s not compatible with adaptive sampling in the current implementation.
Best practices for using this variable include:
- Only enable it when you have multiple GPUs available and want to leverage them for path tracing.
- Be cautious when using it in the editor, and ensure you set the correct MaxGPUCount.
- Be aware that enabling this might disable adaptive sampling, which could affect rendering quality and performance.
Regarding the associated variable CVarPathTracingMultiGPU:
The purpose of CVarPathTracingMultiGPU is to provide a programmatic interface to the r.PathTracing.MultiGPU setting within the C++ code. It allows the engine to query and use the current state of the multi-GPU path tracing setting.
This variable is used directly in the Renderer module, specifically in the path tracing implementation. It’s accessed in the rendering thread to determine whether to use multi-GPU path tracing.
The value of CVarPathTracingMultiGPU is set automatically based on the r.PathTracing.MultiGPU console variable. It’s an instance of TAutoConsoleVariable, which means it’s automatically updated when the console variable changes.
CVarPathTracingMultiGPU interacts directly with the Config.UseMultiGPU flag in the path tracing configuration. When the CVar is non-zero, multi-GPU path tracing is enabled (unless adaptive sampling is also enabled).
Developers should be aware that this variable is thread-safe for the render thread (ECVF_RenderThreadSafe), meaning it’s safe to access from render thread code.
Best practices include using GetValueOnRenderThread() to access the value safely from render thread code, and being aware of the implications of enabling multi-GPU path tracing on other rendering features like adaptive sampling.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/PathTracing.cpp:227
Scope: file
Source code excerpt:
#if WITH_MGPU
TAutoConsoleVariable<int32> CVarPathTracingMultiGPU(
TEXT("r.PathTracing.MultiGPU"),
0,
TEXT("Run the path tracer using all available GPUs when enabled (default = 0)\n")
TEXT("Using this functionality in the editor requires -MaxGPUCount=N setting on the command line"),
ECVF_RenderThreadSafe
);
#Associated Variable and Callsites
This variable is associated with another variable named CVarPathTracingMultiGPU
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/PathTracing.cpp:226
Scope: file
Source code excerpt:
#if WITH_MGPU
TAutoConsoleVariable<int32> CVarPathTracingMultiGPU(
TEXT("r.PathTracing.MultiGPU"),
0,
TEXT("Run the path tracer using all available GPUs when enabled (default = 0)\n")
TEXT("Using this functionality in the editor requires -MaxGPUCount=N setting on the command line"),
ECVF_RenderThreadSafe
);
#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/PathTracing.cpp:2645
Scope: file
Source code excerpt:
}
#if WITH_MGPU
Config.UseMultiGPU = CVarPathTracingMultiGPU.GetValueOnRenderThread() != 0;
// TODO: Figure out how to support adaptive sampling in multi-gpu cases (this is complicated due to the swizzled layout of the variance texture)
Config.UseMultiGPU &= !Config.UseAdaptiveSampling;
#else
Config.UseMultiGPU = false;
#endif