r.Vulkan.RHIThread
r.Vulkan.RHIThread
#Overview
name: r.Vulkan.RHIThread
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
0 to only use Render Thread\n1 to use ONE RHI Thread\n2 to use multiple RHI Thread\n
It is referenced in 4
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of r.Vulkan.RHIThread is to control the usage of RHI (Rendering Hardware Interface) threads in the Vulkan rendering system of Unreal Engine 5. It determines whether to use only the Render Thread, a single RHI Thread, or multiple RHI Threads.
This setting variable is primarily used by the Vulkan RHI subsystem within Unreal Engine 5. It’s referenced in the VulkanRHI module, specifically in the VulkanRHI.cpp and VulkanDevice.cpp files.
The value of this variable is set through a console variable (CVar) system, allowing it to be changed at runtime. It’s initialized with a default value of 1, which means it uses one RHI Thread by default.
The variable interacts closely with its associated variable GRHIThreadCvar, which is used to access the value set by r.Vulkan.RHIThread throughout the code.
Developers should be aware that this variable significantly impacts the rendering pipeline’s threading model. Changing its value can affect performance and behavior of the Vulkan renderer.
Best practices when using this variable include:
- Testing different values (0, 1, 2) to find the optimal setting for your specific game and target hardware.
- Considering the impact on different platforms, as some may not support all threading options.
- Being cautious when changing this value at runtime, as it can have substantial effects on rendering performance and stability.
Regarding the associated variable GRHIThreadCvar:
The purpose of GRHIThreadCvar is to provide programmatic access to the r.Vulkan.RHIThread setting within the C++ code.
It’s used in the VulkanRHI module to determine the threading model for the Vulkan renderer. It’s referenced in both the device initialization (FVulkanDevice::InitGPU) and the RHI initialization (FVulkanDynamicRHI::InitInstance).
The value of GRHIThreadCvar is set automatically based on the r.Vulkan.RHIThread CVar.
GRHIThreadCvar interacts with other variables like GRHISupportsRHIThread and GRHISupportsParallelRHIExecute, which are set based on its value.
Developers should be aware that GRHIThreadCvar is used to make runtime decisions about threading in the Vulkan renderer. Its value affects how command contexts are created and how parallel execution is handled.
Best practices for GRHIThreadCvar include:
- Avoiding direct modification of GRHIThreadCvar; instead, modify r.Vulkan.RHIThread.
- Being aware of its impact when initializing Vulkan devices and the RHI system.
- Considering its value when debugging rendering issues, especially those related to threading or command execution.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/VulkanRHI/Private/VulkanRHI.cpp:64
Scope: file
Source code excerpt:
TAutoConsoleVariable<int32> GRHIThreadCvar(
TEXT("r.Vulkan.RHIThread"),
1,
TEXT("0 to only use Render Thread\n")
TEXT("1 to use ONE RHI Thread\n")
TEXT("2 to use multiple RHI Thread\n")
);
#Associated Variable and Callsites
This variable is associated with another variable named GRHIThreadCvar
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/VulkanRHI/Private/VulkanDevice.cpp:1284
Scope (from outer to inner):
file
function void FVulkanDevice::InitGPU
Source code excerpt:
}
extern TAutoConsoleVariable<int32> GRHIThreadCvar;
if (GRHIThreadCvar->GetInt() > 1)
{
int32 Num = FTaskGraphInterface::Get().GetNumWorkerThreads();
for (int32 Index = 0; Index < Num; Index++)
{
FVulkanCommandListContext* CmdContext = new FVulkanCommandListContext(GVulkanRHI, this, GfxQueue, ImmediateContext);
CommandContexts.Add(CmdContext);
#Loc: <Workspace>/Engine/Source/Runtime/VulkanRHI/Private/VulkanRHI.cpp:63
Scope: file
Source code excerpt:
///////////////////////////////////////////////////////////////////////////////
TAutoConsoleVariable<int32> GRHIThreadCvar(
TEXT("r.Vulkan.RHIThread"),
1,
TEXT("0 to only use Render Thread\n")
TEXT("1 to use ONE RHI Thread\n")
TEXT("2 to use multiple RHI Thread\n")
);
#Loc: <Workspace>/Engine/Source/Runtime/VulkanRHI/Private/VulkanRHI.cpp:963
Scope (from outer to inner):
file
function void FVulkanDynamicRHI::InitInstance
Source code excerpt:
GRHISupportsParallelRHIExecute = false;
#else
GRHISupportsRHIThread = GRHIThreadCvar->GetInt() != 0;
GRHISupportsParallelRHIExecute = GRHIThreadCvar->GetInt() > 1;
#endif
// Some platforms might only have CPU for an RHI thread, but not for parallel tasks
GSupportsParallelRenderingTasksWithSeparateRHIThread = GRHISupportsRHIThread ? FVulkanPlatform::SupportParallelRenderingTasks() : false;
//#todo-rco: Add newer Nvidia also