r.Vulkan.RayTracing
r.Vulkan.RayTracing
#Overview
name: r.Vulkan.RayTracing
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
0: Do not enable Vulkan ray tracing extensions\n1: Enable experimental ray tracing support (default)
It is referenced in 8
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of r.Vulkan.RayTracing is to control the enabling of Vulkan ray tracing extensions in Unreal Engine 5. It is primarily used for the rendering system, specifically for ray tracing functionality in the Vulkan backend.
This setting variable is relied upon by the VulkanRHI module, which is responsible for implementing the Vulkan rendering backend in Unreal Engine. It is used in several key areas:
-
The value of this variable is set through a console variable (CVar) named GVulkanRayTracingCVar. It is defined in VulkanExtensions.cpp with a default value of 1, meaning ray tracing support is enabled by default.
-
This variable interacts with several Vulkan extension classes:
- FVulkanKHRAccelerationStructureExtension
- FVulkanKHRRayTracingPipelineExtension
- FVulkanKHRRayQueryExtension
These classes use the value of GVulkanRayTracingCVar to determine whether to enable their respective ray tracing-related Vulkan extensions.
-
In the FVulkanDynamicRHI::CreateInstance function, this variable is used to determine whether to perform a profile check for ray tracing support and potentially disable ray tracing if the necessary requirements are not met.
Developers should be aware that:
- This variable is marked as ECVF_ReadOnly, meaning it should not be changed at runtime.
- It can be overridden by the command line parameter “-noraytracing”.
- The actual enabling of ray tracing extensions also depends on other factors like device support and shader platform compatibility.
Best practices when using this variable include:
- Ensure that the target hardware supports Vulkan ray tracing before relying on it.
- Be prepared to fall back to non-ray tracing rendering methods if this variable is set to 0 or if ray tracing is not supported.
- Consider the performance implications of enabling ray tracing, especially on lower-end hardware.
Regarding the associated variable GVulkanRayTracingCVar:
- It is the actual console variable that stores and manages the value of r.Vulkan.RayTracing.
- It is used throughout the VulkanRHI module to check whether ray tracing should be enabled.
- Its value can be accessed using the GetValueOnAnyThread() method.
- It can be set programmatically, as seen in the CreateInstance function where it’s set to 0 if ray tracing requirements are not met.
Developers should use GVulkanRayTracingCVar.GetValueOnAnyThread() to check the current state of Vulkan ray tracing support in their code when working with the VulkanRHI module.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/VulkanRHI/Private/VulkanExtensions.cpp:44
Scope: file
Source code excerpt:
TAutoConsoleVariable<int32> GVulkanRayTracingCVar(
TEXT("r.Vulkan.RayTracing"),
1,
TEXT("0: Do not enable Vulkan ray tracing extensions\n")
TEXT("1: Enable experimental ray tracing support (default)"),
ECVF_ReadOnly
);
#Associated Variable and Callsites
This variable is associated with another variable named GVulkanRayTracingCVar
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/VulkanRHI/Private/VulkanExtensions.cpp:43
Scope: file
Source code excerpt:
);
TAutoConsoleVariable<int32> GVulkanRayTracingCVar(
TEXT("r.Vulkan.RayTracing"),
1,
TEXT("0: Do not enable Vulkan ray tracing extensions\n")
TEXT("1: Enable experimental ray tracing support (default)"),
ECVF_ReadOnly
);
#Loc: <Workspace>/Engine/Source/Runtime/VulkanRHI/Private/VulkanExtensions.cpp:742
Scope (from outer to inner):
file
class class FVulkanKHRAccelerationStructureExtension : public FVulkanDeviceExtension
function FVulkanKHRAccelerationStructureExtension
Source code excerpt:
: FVulkanDeviceExtension(InDevice, VK_KHR_ACCELERATION_STRUCTURE_EXTENSION_NAME, VULKAN_RHI_RAYTRACING)
{
bEnabledInCode = bEnabledInCode && GVulkanRayTracingCVar.GetValueOnAnyThread() && !FParse::Param(FCommandLine::Get(), TEXT("noraytracing"));
}
virtual void PrePhysicalDeviceFeatures(VkPhysicalDeviceFeatures2KHR& PhysicalDeviceFeatures2) override final
{
ZeroVulkanStruct(AccelerationStructureFeatures, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ACCELERATION_STRUCTURE_FEATURES_KHR);
AddToPNext(PhysicalDeviceFeatures2, AccelerationStructureFeatures);
#Loc: <Workspace>/Engine/Source/Runtime/VulkanRHI/Private/VulkanExtensions.cpp:790
Scope (from outer to inner):
file
class class FVulkanKHRRayTracingPipelineExtension : public FVulkanDeviceExtension
function FVulkanKHRRayTracingPipelineExtension
Source code excerpt:
: FVulkanDeviceExtension(InDevice, VK_KHR_RAY_TRACING_PIPELINE_EXTENSION_NAME, VULKAN_RHI_RAYTRACING)
{
bEnabledInCode = bEnabledInCode && GVulkanRayTracingCVar.GetValueOnAnyThread() && !FParse::Param(FCommandLine::Get(), TEXT("noraytracing"));
}
virtual void PrePhysicalDeviceFeatures(VkPhysicalDeviceFeatures2KHR& PhysicalDeviceFeatures2) override final
{
ZeroVulkanStruct(RayTracingPipelineFeatures, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_TRACING_PIPELINE_FEATURES_KHR);
AddToPNext(PhysicalDeviceFeatures2, RayTracingPipelineFeatures);
#Loc: <Workspace>/Engine/Source/Runtime/VulkanRHI/Private/VulkanExtensions.cpp:840
Scope (from outer to inner):
file
class class FVulkanKHRRayQueryExtension : public FVulkanDeviceExtension
function FVulkanKHRRayQueryExtension
Source code excerpt:
: FVulkanDeviceExtension(InDevice, VK_KHR_RAY_QUERY_EXTENSION_NAME, VULKAN_RHI_RAYTRACING)
{
bEnabledInCode = bEnabledInCode && GVulkanRayTracingCVar.GetValueOnAnyThread() && !FParse::Param(FCommandLine::Get(), TEXT("noraytracing"));
}
virtual void PrePhysicalDeviceFeatures(VkPhysicalDeviceFeatures2KHR& PhysicalDeviceFeatures2) override final
{
ZeroVulkanStruct(RayQueryFeatures, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_RAY_QUERY_FEATURES_KHR);
AddToPNext(PhysicalDeviceFeatures2, RayQueryFeatures);
#Loc: <Workspace>/Engine/Source/Runtime/VulkanRHI/Private/VulkanRHI.cpp:118
Scope: file
Source code excerpt:
bool GGPUCrashDebuggingEnabled = false;
extern TAutoConsoleVariable<int32> GVulkanRayTracingCVar;
// All shader stages supported by VK device - VK_PIPELINE_STAGE_VERTEX_SHADER_BIT, FRAGMENT etc
uint32 GVulkanDevicePipelineStageBits = 0;
DEFINE_LOG_CATEGORY(LogVulkan)
#Loc: <Workspace>/Engine/Source/Runtime/VulkanRHI/Private/VulkanRHI.cpp:683
Scope (from outer to inner):
file
function void FVulkanDynamicRHI::CreateInstance
Source code excerpt:
#if VULKAN_RHI_RAYTRACING
// Run a profile check to see if this device can support our raytacing requirements since it might change the required API version of the instance
if (FVulkanPlatform::SupportsProfileChecks() && GVulkanRayTracingCVar.GetValueOnAnyThread())
{
static IConsoleVariable* RequireSM6CVar = IConsoleManager::Get().FindConsoleVariable(TEXT("r.RayTracing.RequireSM6"));
const bool bRequireSM6 = RequireSM6CVar && RequireSM6CVar->GetBool();
const bool bRayTracingAllowedOnCurrentShaderPlatform = (bRequireSM6 == false) || (GMaxRHIShaderPlatform == SP_VULKAN_SM6 || IsVulkanMobileSM5Platform(GMaxRHIShaderPlatform));
if (CheckVulkanProfile(GMaxRHIFeatureLevel, true) && bRayTracingAllowedOnCurrentShaderPlatform)
#Loc: <Workspace>/Engine/Source/Runtime/VulkanRHI/Private/VulkanRHI.cpp:697
Scope (from outer to inner):
file
function void FVulkanDynamicRHI::CreateInstance
Source code excerpt:
{
// Raytracing is not supported, disable it completely instead of only loading parts of it
GVulkanRayTracingCVar->Set(0, ECVF_SetByCode);
if (!bRayTracingAllowedOnCurrentShaderPlatform)
{
UE_LOG(LogVulkanRHI, Display, TEXT("Vulkan RayTracing disabled because SM6 shader platform is required (r.RayTracing.RequireSM6=1)."));
}
else