r.Vulkan.GPUValidation

r.Vulkan.GPUValidation

#Overview

name: r.Vulkan.GPUValidation

This variable is created as a Console Variable (cvar).

It is referenced in 6 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of r.Vulkan.GPUValidation is to enable GPU-assisted validation when using Vulkan validation layers in Unreal Engine 5. This setting is specifically for the Vulkan rendering system and is used to enhance debugging and validation capabilities.

The Unreal Engine subsystem that relies on this setting variable is the Vulkan RHI (Rendering Hardware Interface) module. This can be seen from the file paths in the callsites, which are all within the VulkanRHI directory.

The value of this variable is set through a console variable (CVar) named GGPUValidationCvar. It can be set to 0 (default, disabled), 1 (enable GPU-assisted validation), or 2 (enable GPU-assisted validation and extra binding slot).

This variable interacts with other debugging and validation-related variables, such as GValidationCvar. It’s also used in conjunction with command-line parameters like “vulkanbestpractices” and “vulkandebugsync”.

Developers must be aware that:

  1. This variable is marked as read-only and render thread safe (ECVF_ReadOnly | ECVF_RenderThreadSafe).
  2. It’s primarily used in debug builds, as indicated by the #if VULKAN_HAS_DEBUGGING_ENABLED conditional compilation.
  3. Enabling this feature may have performance implications, so it should be used judiciously.

Best practices when using this variable include:

  1. Use it during development and debugging phases, not in production builds.
  2. Combine it with other Vulkan validation tools for comprehensive debugging.
  3. Be aware of the performance impact when enabled, especially at higher settings.

The associated variable GGPUValidationCvar is the actual console variable that controls this setting. It’s used throughout the Vulkan RHI code to determine the level of GPU validation to apply. The usage is consistent with the r.Vulkan.GPUValidation setting, and the same considerations apply when using it directly in C++ code.

#References in C++ code

#Callsites

This variable is referenced in the following C++ source code:

#Loc: <Workspace>/Engine/Source/Runtime/VulkanRHI/Private/VulkanLayers.cpp:32

Scope: file

Source code excerpt:


TAutoConsoleVariable<int32> GGPUValidationCvar(
	TEXT("r.Vulkan.GPUValidation"),
	0,
	TEXT("2 to use enable GPU assisted validation AND extra binding slot when using validation layers\n")
	TEXT("1 to use enable GPU assisted validation when using validation layers, or\n")
	TEXT("0 to not use (default)"),
	ECVF_ReadOnly | ECVF_RenderThreadSafe
);

#Associated Variable and Callsites

This variable is associated with another variable named GGPUValidationCvar. They share the same value. See the following C++ source code.

#Loc: <Workspace>/Engine/Source/Runtime/VulkanRHI/Private/VulkanExtensions.cpp:84

Scope: file

Source code excerpt:


#if VULKAN_HAS_DEBUGGING_ENABLED
extern TAutoConsoleVariable<int32> GGPUValidationCvar;
#endif

TSharedPtr<IHeadMountedDisplayVulkanExtensions, ESPMode::ThreadSafe> FVulkanDynamicRHI::HMDVulkanExtensions;
TArray<const ANSICHAR*> FVulkanDeviceExtension::ExternalExtensions;
TArray<const ANSICHAR*> FVulkanInstanceExtension::ExternalExtensions;

#Loc: <Workspace>/Engine/Source/Runtime/VulkanRHI/Private/VulkanExtensions.cpp:1477

Scope (from outer to inner):

file
class        class FVulkanEXTValidationFeaturesExtension : public FVulkanInstanceExtension
function     virtual void PreCreateInstance
lambda-function

Source code excerpt:

		{
			TArray<VkValidationFeatureEnableEXT> Features;
			const int32 GPUValidationValue = GGPUValidationCvar.GetValueOnAnyThread();
			if (GPUValidationValue > 0)
			{
				Features.Add(VK_VALIDATION_FEATURE_ENABLE_GPU_ASSISTED_EXT);
				if (GPUValidationValue > 1)
				{
					Features.Add(VK_VALIDATION_FEATURE_ENABLE_GPU_ASSISTED_RESERVE_BINDING_SLOT_EXT);

#Loc: <Workspace>/Engine/Source/Runtime/VulkanRHI/Private/VulkanLayers.cpp:31

Scope: file

Source code excerpt:

);

TAutoConsoleVariable<int32> GGPUValidationCvar(
	TEXT("r.Vulkan.GPUValidation"),
	0,
	TEXT("2 to use enable GPU assisted validation AND extra binding slot when using validation layers\n")
	TEXT("1 to use enable GPU assisted validation when using validation layers, or\n")
	TEXT("0 to not use (default)"),
	ECVF_ReadOnly | ECVF_RenderThreadSafe

#Loc: <Workspace>/Engine/Source/Runtime/VulkanRHI/Private/VulkanLayers.cpp:328

Scope (from outer to inner):

file
function     void FVulkanDynamicRHI::SetupValidationRequests

Source code excerpt:

			GValidationCvar->Set(2, ECVF_SetByCommandline);
		}
		GGPUValidationCvar->Set(2, ECVF_SetByCommandline);
	}
	GRHIGlobals.IsDebugLayerEnabled = (GValidationCvar.GetValueOnAnyThread() > 0);
#endif
}

#Loc: <Workspace>/Engine/Source/Runtime/VulkanRHI/Private/VulkanLayers.cpp:447

Scope (from outer to inner):

file
function     void FVulkanIntanceSetupHelper::AddDebugLayers

Source code excerpt:

		}

		const bool bRequiresValidationFeatures = (GGPUValidationCvar.GetValueOnAnyThread() != 0) ||
			(FParse::Param(FCommandLine::Get(), TEXT("vulkanbestpractices"))) ||
			(FParse::Param(FCommandLine::Get(), TEXT("vulkandebugsync")));
		if (bRequiresValidationFeatures)
		{
			ActivateDebuggingExtension(VK_EXT_VALIDATION_FEATURES_EXTENSION_NAME);
		}