r.Vulkan.AllowAsyncCompute

r.Vulkan.AllowAsyncCompute

#Overview

name: r.Vulkan.AllowAsyncCompute

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

It is referenced in 5 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of r.Vulkan.AllowAsyncCompute is to control the usage of the async compute queue in Vulkan-based rendering for Unreal Engine 5. This setting variable is primarily used in the Vulkan RHI (Rendering Hardware Interface) subsystem.

Based on the callsites, the Vulkan RHI module relies on this setting variable. It is used in the FVulkanDevice class, which is responsible for initializing and managing the Vulkan device and its queues.

The value of this variable is set through a console variable (CVar) system. It is initialized with a default value of 0, which means async compute is disabled by default. Users can change this value at runtime or through configuration files.

This variable interacts closely with GRHIAllowAsyncComputeCvar, which is the actual CVar object associated with r.Vulkan.AllowAsyncCompute. They share the same value and are used interchangeably in the code.

Developers must be aware that:

  1. This variable affects the creation and usage of compute queues in the Vulkan device.
  2. Enabling async compute (by setting the value to 1) may impact performance and should be tested thoroughly.
  3. The variable interacts with other settings, such as GAllowPresentOnComputeQueue.

Best practices when using this variable include:

  1. Benchmark performance with and without async compute enabled to determine the optimal setting for your specific application.
  2. Consider the target hardware capabilities, as not all devices support or benefit from async compute.
  3. Use in conjunction with other Vulkan-specific settings for optimal performance tuning.

Regarding the associated variable GRHIAllowAsyncComputeCvar:

The purpose of GRHIAllowAsyncComputeCvar is to provide programmatic access to the r.Vulkan.AllowAsyncCompute setting within the C++ code.

This variable is used in the Vulkan RHI module to make runtime decisions about queue creation and usage.

The value of GRHIAllowAsyncComputeCvar is set through the CVar system and can be accessed using the GetValueOnAnyThread() method.

It interacts directly with r.Vulkan.AllowAsyncCompute, effectively serving as its in-code representation.

Developers should be aware that:

  1. Changes to this variable at runtime will affect the behavior of the Vulkan device.
  2. It’s used in critical device initialization code, so changing it may require device recreation.

Best practices for using GRHIAllowAsyncComputeCvar include:

  1. Use GetValueOnAnyThread() to access its current value in performance-critical code.
  2. Consider caching the value if it’s accessed frequently, as CVar lookups can have a small performance cost.
  3. Be cautious when changing this value at runtime, as it may have significant implications for the rendering pipeline.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/VulkanRHI/Private/VulkanDevice.cpp:22

Scope: file

Source code excerpt:


TAutoConsoleVariable<int32> GRHIAllowAsyncComputeCvar(
	TEXT("r.Vulkan.AllowAsyncCompute"),
	0,
	TEXT("0 to disable async compute queue(if available)")
	TEXT("1 to allow async compute queue")
);

TAutoConsoleVariable<int32> GAllowPresentOnComputeQueue(

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/VulkanRHI/Private/VulkanDevice.cpp:21

Scope: file

Source code excerpt:

#include "VulkanChunkedPipelineCache.h"

TAutoConsoleVariable<int32> GRHIAllowAsyncComputeCvar(
	TEXT("r.Vulkan.AllowAsyncCompute"),
	0,
	TEXT("0 to disable async compute queue(if available)")
	TEXT("1 to allow async compute queue")
);

#Loc: <Workspace>/Engine/Source/Runtime/VulkanRHI/Private/VulkanDevice.cpp:366

Scope (from outer to inner):

file
function     void FVulkanDevice::CreateDevice

Source code excerpt:

		{
			if (ComputeQueueFamilyIndex == -1 &&
				(GRHIAllowAsyncComputeCvar.GetValueOnAnyThread() != 0 || GAllowPresentOnComputeQueue.GetValueOnAnyThread() != 0) && GfxQueueFamilyIndex != FamilyIndex)
			{
				ComputeQueueFamilyIndex = FamilyIndex;
				bIsValidQueue = true;
			}
		}

#Loc: <Workspace>/Engine/Source/Runtime/VulkanRHI/Private/VulkanDevice.cpp:456

Scope (from outer to inner):

file
function     void FVulkanDevice::CreateDevice

Source code excerpt:

	{
		// Dedicated queue
		if (GRHIAllowAsyncComputeCvar.GetValueOnAnyThread() != 0)
		{
			bAsyncComputeQueue = true;
		}
	}
	ComputeQueue = new FVulkanQueue(this, ComputeQueueFamilyIndex);
	if (TransferQueueFamilyIndex == -1)

#Loc: <Workspace>/Engine/Source/Runtime/VulkanRHI/Private/VulkanDevice.cpp:1274

Scope (from outer to inner):

file
function     void FVulkanDevice::InitGPU

Source code excerpt:

	ImmediateContext = new FVulkanCommandListContextImmediate(GVulkanRHI, this, GfxQueue);

	if (GfxQueue->GetFamilyIndex() != ComputeQueue->GetFamilyIndex() && GRHIAllowAsyncComputeCvar.GetValueOnAnyThread() != 0)
	{
		ComputeContext = new FVulkanCommandListContextImmediate(GVulkanRHI, this, ComputeQueue);
		GEnableAsyncCompute = true;
	}
	else
	{