r.Shaders.ZeroInitialise

r.Shaders.ZeroInitialise

#Overview

name: r.Shaders.ZeroInitialise

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 4 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of r.Shaders.ZeroInitialise is to enforce zero initialization of local variables of primitive types in shaders. This setting is primarily used for Metal shader compilation.

This variable is used in the shader compilation system, specifically in the Engine and RenderCore modules. It affects how shaders are compiled and initialized, particularly for Metal platforms.

The value of this variable is set through a console variable (CVar) system. It’s defined as a TAutoConsoleVariable with a default value of 1 (enabled).

The associated variable CVarShaderZeroInitialise interacts directly with r.Shaders.ZeroInitialise. They share the same value and purpose.

Developers should be aware that:

  1. This setting is platform-specific, primarily affecting Metal platforms.
  2. Enabling this (which is the default) may have a performance impact, as it forces initialization of local variables.
  3. It’s a read-only console variable, meaning it cannot be changed at runtime.

Best practices when using this variable:

  1. Leave it enabled (default) unless you have specific performance needs and have thoroughly tested the implications of disabling it.
  2. Be aware that not all shader languages can omit zero initialization, so the effect may vary across platforms.
  3. When optimizing shader performance, consider this setting as a potential factor, especially on Metal platforms.

Regarding the associated variable CVarShaderZeroInitialise:

#Setting Variables

#References In INI files

Location: <Workspace>/Engine/Config/BaseDeviceProfiles.ini:1159, section: [Mac DeviceProfile]

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

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarShaderZeroInitialise(
	TEXT("r.Shaders.ZeroInitialise"),
	1,
	TEXT("Whether to enforce zero initialise local variables of primitive type in shaders. Defaults to 1 (enabled). Not all shader languages can omit zero initialisation."),
	ECVF_ReadOnly);

static TAutoConsoleVariable<int32> CVarShaderBoundsChecking(
	TEXT("r.Shaders.BoundsChecking"),

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

Scope (from outer to inner):

file
function     void ShaderMapAppendKeyString

Source code excerpt:

	{
		{
			static const auto CVar = IConsoleManager::Get().FindConsoleVariable(TEXT("r.Shaders.ZeroInitialise"));
			KeyString += (CVar && CVar->GetInt() != 0) ? TEXT("_ZeroInit") : TEXT("");
		}
		{
			static const auto CVar = IConsoleManager::Get().FindConsoleVariable(TEXT("r.Shaders.BoundsChecking"));
			KeyString += (CVar && CVar->GetInt() != 0) ? TEXT("_BoundsChecking") : TEXT("");
		}

#Associated Variable and Callsites

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

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

Scope: file

Source code excerpt:

	ECVF_ReadOnly);

static TAutoConsoleVariable<int32> CVarShaderZeroInitialise(
	TEXT("r.Shaders.ZeroInitialise"),
	1,
	TEXT("Whether to enforce zero initialise local variables of primitive type in shaders. Defaults to 1 (enabled). Not all shader languages can omit zero initialisation."),
	ECVF_ReadOnly);

static TAutoConsoleVariable<int32> CVarShaderBoundsChecking(

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

Scope (from outer to inner):

file
function     void GlobalBeginCompileShader

Source code excerpt:

	if (IsMetalPlatform((EShaderPlatform)Target.Platform))
	{
		if (CVarShaderZeroInitialise.GetValueOnAnyThread() != 0)
		{
			Input.Environment.CompilerFlags.Add(CFLAG_ZeroInitialise);
		}

		if (CVarShaderBoundsChecking.GetValueOnAnyThread() != 0)
		{