r.D3D.ForceDXC

r.D3D.ForceDXC

#Overview

name: r.D3D.ForceDXC

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

It is referenced in 3 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of r.D3D.ForceDXC is to force the use of the DirectX Shader Compiler (DXC) for all D3D shaders in Unreal Engine 5. This setting is primarily related to the shader compilation and rendering system.

This setting variable is utilized by the shader compilation subsystem within Unreal Engine 5. It’s particularly relevant to the D3D (DirectX) rendering backend, as evidenced by its presence in ShaderCompiler.cpp and Shader.cpp files.

The value of this variable is set through a console variable (CVar) system, allowing it to be adjusted at runtime or through configuration files. It’s defined as a TAutoConsoleVariable with default value 0 (disabled).

This variable interacts with other shader-related settings, particularly those involving shader platforms and HLSL versions. For example, it’s used in conjunction with a check for HLSL 2021 version in the IsDxcEnabledForPlatform function.

Developers must be aware that enabling this variable (setting it to 1) will force all D3D shaders to be compiled with DXC, which is only compatible with D3D12. This could potentially impact shader compatibility and performance across different hardware configurations.

Best practices when using this variable include:

  1. Only enable it when specifically targeting D3D12 platforms.
  2. Test thoroughly after enabling, as it affects all D3D shaders in the project.
  3. Be aware of potential performance implications, especially on older hardware.
  4. Consider using it in conjunction with other shader-related settings for optimal results.
  5. Remember that it’s marked as ECVF_ReadOnly, meaning its value should typically be set at startup and not changed during runtime.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/ShaderCompiler/ShaderCompiler.cpp:2257

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarD3DForceDXC(
	TEXT("r.D3D.ForceDXC"),
	0,
	TEXT("Forces DirectX Shader Compiler (DXC) to be used for all D3D shaders. Shaders compiled with this option are only compatible with D3D12.\n")
	TEXT(" 0: Disable (default)\n")
	TEXT(" 1: Force new compiler for all shaders"),
	ECVF_ReadOnly);

#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/Shader.cpp:1450

Scope (from outer to inner):

file
function     bool IsDxcEnabledForPlatform

Source code excerpt:

	{
		// D3D backend supports a precompile step for HLSL2021 which is separate from ForceDXC option
		static const IConsoleVariable* CVar = IConsoleManager::Get().FindConsoleVariable(TEXT("r.D3D.ForceDXC"));
		return ((CVar && CVar->GetInt() != 0));
	}
	if (IsOpenGLPlatform(Platform))
	{
		static const IConsoleVariable* CVar = IConsoleManager::Get().FindConsoleVariable(TEXT("r.OpenGL.ForceDXC"));
		return (bHlslVersion2021 || (CVar && CVar->GetInt() != 0));

#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Public/Shader.h:2519

Scope: file

Source code excerpt:

extern RENDERCORE_API bool IsUsingEmulatedUniformBuffers(EShaderPlatform Platform);

/** Returns whether DirectXShaderCompiler (DXC) is enabled for the specified shader platform. See console variables "r.OpenGL.ForceDXC", "r.D3D.ForceDXC". */
extern RENDERCORE_API bool IsDxcEnabledForPlatform(EShaderPlatform Platform, bool bHlslVersion2021 = false);

/** Appends to KeyString for all shaders. */
extern RENDERCORE_API void ShaderMapAppendKeyString(EShaderPlatform Platform, FString& KeyString);