r.Shaders.WarningsAsErrors

r.Shaders.WarningsAsErrors

#Overview

name: r.Shaders.WarningsAsErrors

The value of this variable can be defined or overridden in .ini config files. 1 .ini config file referencing this setting variable.

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.Shaders.WarningsAsErrors is to control how shader compilation warnings are treated in Unreal Engine 5. It allows developers to specify whether shader compilation warnings should be treated as errors, which can help maintain a higher standard of code quality in shader development.

This setting variable is primarily used by the shader compilation system within Unreal Engine’s rendering module. Based on the callsites, it’s clear that this variable affects the shader compiler’s behavior and the shader map generation process.

The value of this variable is set through a console variable (CVar) system, which allows it to be configured at runtime or through configuration files. It can be set to 0 (disabled), 1 (enabled for global shaders only), or 2 (enabled for all shaders).

This variable interacts with the shader compilation flags, specifically the CFLAG_WarningsAsErrors flag. When enabled, it adds this flag to the shader compilation environment.

Developers must be aware that:

  1. This setting may be ignored on older platforms, as mentioned in the variable description.
  2. Enabling this option can make shader compilation more strict, potentially causing previously compilable shaders to fail.
  3. The setting is read-only (ECVF_ReadOnly), meaning it cannot be changed during runtime.

Best practices when using this variable include:

  1. Use it during development to catch and fix shader warnings early.
  2. Consider enabling it for global shaders (value 1) as a middle ground between strict and lenient compilation.
  3. Be prepared to address more shader compilation issues when enabling this option, especially when set to 2 (all shaders).
  4. Use it in conjunction with other shader debugging and optimization tools for comprehensive shader development.
  5. Be aware that enabling this option may increase compilation times and potentially impact iteration speed during development.

#Setting Variables

#References In INI files

Location: <Workspace>/Engine/Config/ConsoleVariables.ini:45, section: [Startup]

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

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarShaderWarningsAsErrors(
	TEXT("r.Shaders.WarningsAsErrors"),
	0,
	TEXT("Whether to treat warnings as errors when compiling shaders. (0: disabled (default), 1: global shaders only, 2: all shaders)). This setting may be ignored on older platforms."),
	ECVF_ReadOnly);

static TAutoConsoleVariable<int32> CVarShaderFlowControl(
	TEXT("r.Shaders.FlowControlMode"),

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

Scope (from outer to inner):

file
function     void GlobalBeginCompileShader

Source code excerpt:


	{
		static FShaderPlatformCachedIniValue<int32> CVarWarningsAsErrorsPerPlatform(TEXT("r.Shaders.WarningsAsErrors"));
		const int WarnLevel = CVarWarningsAsErrorsPerPlatform.Get(ShaderPlatform);
		if ((WarnLevel == 1 && ShaderType->GetTypeForDynamicCast() == FShaderType::EShaderTypeForDynamicCast::Global) || WarnLevel > 1)
		{
			Input.Environment.CompilerFlags.Add(CFLAG_WarningsAsErrors);
		}
	}

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

Scope (from outer to inner):

file
function     void ShaderMapAppendKeyString

Source code excerpt:


	{
		static FShaderPlatformCachedIniValue<int32> CVarWarningsAsErrorsPerPlatform(TEXT("r.Shaders.WarningsAsErrors"));
		if (const int32 Level = CVarWarningsAsErrorsPerPlatform.Get(Platform); Level != 0)
		{
			KeyString.Appendf(TEXT("_WX%d"), Level);
		}
	}