r.OpenGL.ForceDXC
r.OpenGL.ForceDXC
#Overview
name: r.OpenGL.ForceDXC
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Forces DirectX Shader Compiler (DXC) to be used for all OpenGL shaders instead of hlslcc.\n 0: Disable\n 1: Force new compiler for all shaders (default)
It is referenced in 4
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of r.OpenGL.ForceDXC is to control the use of the DirectX Shader Compiler (DXC) for OpenGL shaders instead of the default hlslcc compiler.
This setting variable is primarily used in the rendering system of Unreal Engine, specifically in the shader compilation process. It is relied upon by the ShaderCompiler module and the RenderCore module.
The value of this variable is set through a console variable (CVar) system. It is defined as a TAutoConsoleVariable with a default value of 1, meaning DXC is forced for all shaders by default.
This variable interacts with other shader-related variables and functions, particularly those dealing with shader platforms and compilation. It’s used in conjunction with platform-specific checks (e.g., IsOpenGLPlatform) and other shader-related CVars.
Developers must be aware that this variable can significantly impact shader compilation for OpenGL platforms. Enabling it forces the use of DXC for all OpenGL shaders, which may have performance and compatibility implications.
Best practices when using this variable include:
- Understanding the implications of using DXC vs. hlslcc for your specific project and target platforms.
- Testing thoroughly when changing this setting, as it can affect shader compilation and potentially rendering quality or performance.
- Considering platform-specific requirements and limitations when deciding whether to force DXC or not.
- Keeping in mind that this variable is marked as ECVF_ReadOnly, meaning it should typically be set at startup and not changed during runtime.
- Being aware that this setting may interact with other shader-related settings, such as those for emulated uniform buffers on GLES platforms.
#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:2265
Scope: file
Source code excerpt:
static TAutoConsoleVariable<int32> CVarOpenGLForceDXC(
TEXT("r.OpenGL.ForceDXC"),
1,
TEXT("Forces DirectX Shader Compiler (DXC) to be used for all OpenGL shaders instead of hlslcc.\n")
TEXT(" 0: Disable\n")
TEXT(" 1: Force new compiler for all shaders (default)"),
ECVF_ReadOnly);
#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/Shader.cpp:1455
Scope (from outer to inner):
file
function bool IsDxcEnabledForPlatform
Source code excerpt:
if (IsOpenGLPlatform(Platform))
{
static const IConsoleVariable* CVar = IConsoleManager::Get().FindConsoleVariable(TEXT("r.OpenGL.ForceDXC"));
return (bHlslVersion2021 || (CVar && CVar->GetInt() != 0));
}
// Hlslcc has been removed for Metal and Vulkan. There is only DXC now.
if (IsMetalPlatform(Platform) || IsVulkanPlatform(Platform))
{
return true;
#Loc: <Workspace>/Engine/Source/Runtime/RenderCore/Private/Shader.cpp:1471
Scope (from outer to inner):
file
function bool IsUsingEmulatedUniformBuffers
Source code excerpt:
{
// Currently DXC only supports emulated uniform buffers on GLES
static const auto CForceDXCVar = IConsoleManager::Get().FindConsoleVariable(TEXT("r.OpenGL.ForceDXC"));
if (CForceDXCVar && CForceDXCVar->GetInt() != 0)
{
return true;
}
static auto* CVar = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("OpenGL.UseEmulatedUBs"));
#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);