r.ShaderCompiler.DebugDumpShaderCode

r.ShaderCompiler.DebugDumpShaderCode

#Overview

name: r.ShaderCompiler.DebugDumpShaderCode

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.ShaderCompiler.DebugDumpShaderCode is to enable debugging of shader compilation by dumping the output shader code object to a file. This setting is primarily used for the rendering system, specifically for shader compilation and debugging.

This setting variable is relied upon by the Unreal Engine’s shader compiler subsystem, which is part of the rendering module. It’s primarily used in the ShaderCompiler.cpp file, which is responsible for managing shader compilation tasks.

The value of this variable is set through a console variable (CVar) system. It’s defined as a static TAutoConsoleVariable with a default value of false. This means it can be changed at runtime through console commands or configuration files.

The associated variable CVarDebugDumpShaderCode directly interacts with r.ShaderCompiler.DebugDumpShaderCode. They share the same value and purpose.

Developers must be aware that enabling this variable will cause additional files to be generated during shader compilation. Each shader job will create a ShaderCode.bin file containing the compiled shader code. This can be useful for debugging but may impact performance and disk usage if left enabled in production builds.

Best practices when using this variable include:

  1. Only enable it when debugging shader issues.
  2. Be prepared for increased compilation times and disk usage.
  3. Remember to disable it before creating production builds.
  4. Use in conjunction with other shader debugging tools for comprehensive analysis.

Regarding the associated variable CVarDebugDumpShaderCode:

The purpose of CVarDebugDumpShaderCode is the same as r.ShaderCompiler.DebugDumpShaderCode. It’s an internal representation of the console variable within the engine’s C++ code.

This variable is used directly in the shader compiler subsystem to determine whether to dump shader code. It’s referenced in the FShaderCompilingManager::GetDumpShaderDebugInfoFlags() function, where it contributes to the debug flags if enabled.

The value of CVarDebugDumpShaderCode is set when the r.ShaderCompiler.DebugDumpShaderCode console variable is set. It can be accessed in C++ code using the GetValueOnAnyThread() method.

CVarDebugDumpShaderCode interacts directly with the EShaderDebugInfoFlags enum, specifically setting the ShaderCodeBinary flag when enabled.

Developers should be aware that this variable is marked as ECVF_ReadOnly, meaning its value should not be changed during runtime after initial setup.

Best practices for using CVarDebugDumpShaderCode include:

  1. Use it for programmatic checks in C++ code when you need to know if shader code dumping is enabled.
  2. Remember that changing this variable directly won’t affect the console variable; always modify through the console variable system.
  3. Consider the performance implications when this flag is enabled in performance-critical code paths.

#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:178

Scope: file

Source code excerpt:


static TAutoConsoleVariable<bool> CVarDebugDumpShaderCode(
	TEXT("r.ShaderCompiler.DebugDumpShaderCode"),
	false,
	TEXT("If true, each shader job will dump a ShaderCode.bin containing the contents of the output shader code object (the contents of this can differ for each shader format; note that this is the data that is hashed to produce the OutputHash.txt file)"),
	ECVF_ReadOnly);

static TAutoConsoleVariable<bool> CVarDebugDumpDetailedShaderSource(
	TEXT("r.ShaderCompiler.DebugDumpDetailedShaderSource"),

#Associated Variable and Callsites

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

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

Scope: file

Source code excerpt:

	ECVF_ReadOnly);

static TAutoConsoleVariable<bool> CVarDebugDumpShaderCode(
	TEXT("r.ShaderCompiler.DebugDumpShaderCode"),
	false,
	TEXT("If true, each shader job will dump a ShaderCode.bin containing the contents of the output shader code object (the contents of this can differ for each shader format; note that this is the data that is hashed to produce the OutputHash.txt file)"),
	ECVF_ReadOnly);

static TAutoConsoleVariable<bool> CVarDebugDumpDetailedShaderSource(

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

Scope (from outer to inner):

file
function     EShaderDebugInfoFlags FShaderCompilingManager::GetDumpShaderDebugInfoFlags

Source code excerpt:

	}

	if (CVarDebugDumpShaderCode.GetValueOnAnyThread())
	{
		Flags |= EShaderDebugInfoFlags::ShaderCodeBinary;
	}

	if (CVarDebugDumpDetailedShaderSource.GetValueOnAnyThread())
	{