r.D3D12.GPUTimeout

r.D3D12.GPUTimeout

#Overview

name: r.D3D12.GPUTimeout

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.D3D12.GPUTimeout is to control the GPU timeout behavior in the Direct3D 12 rendering system of Unreal Engine. It allows developers to enable or disable the GPU timeout mechanism, which is a safety feature that prevents GPU operations from hanging indefinitely.

This setting variable is primarily used by the D3D12RHI (Direct3D 12 Rendering Hardware Interface) module of Unreal Engine. It’s also referenced in the MovieRenderPipelineCore plugin, which suggests it has implications for movie rendering processes.

The value of this variable is set through a console variable (CVar) system. It’s defined with a default value of 1, meaning GPU timeout is enabled by default. Developers can modify this value at runtime or through configuration files.

The associated variable CVarD3D12GPUTimeout interacts directly with r.D3D12.GPUTimeout. It’s the actual TAutoConsoleVariable object that stores and manages the value of the setting.

Developers must be aware that disabling the GPU timeout (setting the value to 0) can potentially cause system freezes if GPU operations hang. This should be used with caution and only in controlled environments or for specific debugging purposes.

Best practices when using this variable include:

  1. Keep it enabled (value 1) for most development and production scenarios to prevent system hangs.
  2. Only disable it (value 0) when necessary for debugging GPU-related issues or when running very long GPU operations that might trigger a false timeout.
  3. When disabling, ensure proper error handling and recovery mechanisms are in place to prevent system-wide freezes.

Regarding the associated variable CVarD3D12GPUTimeout:

Developers should be cautious when modifying CVarD3D12GPUTimeout directly in code, as it can have significant impacts on system stability and debugging capabilities. It’s generally safer to modify this through engine configuration or console commands rather than hard-coding changes to its value.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/D3D12RHI/Private/D3D12Device.cpp:6

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarD3D12GPUTimeout(
	TEXT("r.D3D12.GPUTimeout"),
	1,
	TEXT("0: Disable GPU Timeout; use with care as it could freeze your PC!\n")
	TEXT("1: Enable GPU Timeout; operation taking long on the GPU will fail(default)\n"),
	ECVF_ReadOnly
);

#Loc: <Workspace>/Engine/Plugins/MovieScene/MovieRenderPipeline/Source/MovieRenderPipelineCore/Private/MoviePipelineGameOverrideSetting.cpp:95

Scope (from outer to inner):

file
function     void UMoviePipelineGameOverrideSetting::ApplyCVarSettings

Source code excerpt:

	{
		// This CVAR only exists if the D3D12RHI module is loaded
		MOVIEPIPELINE_STORE_AND_OVERRIDE_CVAR_INT_IF_EXIST(PreviousGPUTimeout, TEXT("r.D3D12.GPUTimeout"), 0, bOverrideValues);
	}

	if (bFlushStreamingManagers)
	{
		MOVIEPIPELINE_STORE_AND_OVERRIDE_CVAR_INT(PreviousStreamingManagerSyncState, TEXT("r.Streaming.SyncStatesWhenBlocking"), 1, bOverrideValues);
	}

#Loc: <Workspace>/Engine/Plugins/MovieScene/MovieRenderPipeline/Source/MovieRenderPipelineCore/Private/MoviePipelineGameOverrideSetting.cpp:217

Scope (from outer to inner):

file
function     void UMoviePipelineGameOverrideSetting::BuildNewProcessCommandLineArgsImpl

Source code excerpt:

	if (bDisableGPUTimeout)
	{
		InOutDeviceProfileCvars.Add(TEXT("r.D3D12.GPUTimeout=0"));
	}

	if (bFlushStreamingManagers)
	{
		InOutDeviceProfileCvars.Add(TEXT("r.Streaming.SyncStatesWhenBlocking=1"));
	}

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/D3D12RHI/Private/D3D12Device.cpp:5

Scope: file

Source code excerpt:

#include "D3D12ExplicitDescriptorCache.h"

static TAutoConsoleVariable<int32> CVarD3D12GPUTimeout(
	TEXT("r.D3D12.GPUTimeout"),
	1,
	TEXT("0: Disable GPU Timeout; use with care as it could freeze your PC!\n")
	TEXT("1: Enable GPU Timeout; operation taking long on the GPU will fail(default)\n"),
	ECVF_ReadOnly
);

#Loc: <Workspace>/Engine/Source/Runtime/D3D12RHI/Private/D3D12Device.cpp:45

Scope (from outer to inner):

file
function     FD3D12Queue::FD3D12Queue

Source code excerpt:

	CommandQueueDesc.Priority = 0;
	CommandQueueDesc.NodeMask = Device->GetGPUMask().GetNative();
	CommandQueueDesc.Flags = (bFullGPUCrashDebugging || CVarD3D12GPUTimeout.GetValueOnAnyThread() == 0)
		? D3D12_COMMAND_QUEUE_FLAG_DISABLE_GPU_TIMEOUT
		: D3D12_COMMAND_QUEUE_FLAG_NONE;

	FD3D12DynamicRHI::GetD3DRHI()->CreateCommandQueue(Device, CommandQueueDesc, D3DCommandQueue);
	D3DCommandQueue->SetName(*FString::Printf(TEXT("%s Queue (GPU %d)"), GetD3DCommandQueueTypeName(QueueType), Device->GetGPUIndex()));