r.Shaders.AllowCompilingThroughWorkers

r.Shaders.AllowCompilingThroughWorkers

#Overview

name: r.Shaders.AllowCompilingThroughWorkers

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.AllowCompilingThroughWorkers is to control whether shader compilation can be performed through external ShaderCompileWorker processes or not. This setting is primarily related to the shader compilation system in Unreal Engine 5.

The Unreal Engine subsystem that relies on this setting variable is the shader compilation system, which is part of the rendering pipeline. It’s specifically used in the ShaderCompiler module of the Engine.

The value of this variable is set through a console variable (CVar) system. It’s defined in the RenderCore module and is set to 1 (true) by default, allowing external shader compiler workers.

This variable interacts with another variable named CVarAllowCompilingThroughWorkers. They share the same value and are used interchangeably in the code.

Developers must be aware that changing this variable can significantly impact shader compilation performance and debugging. When set to 0, shader compilation will run in-process within the Unreal Engine, which can be useful for debugging but may impact performance.

Best practices when using this variable include:

  1. Keeping it set to 1 (default) for normal development and production use to benefit from parallel shader compilation.
  2. Setting it to 0 only when debugging shader compiler issues or when external worker processes are causing problems.
  3. Being aware that changing this setting may require a restart of the engine to take effect fully.

Regarding the associated variable CVarAllowCompilingThroughWorkers:

#References in C++ code

#Callsites

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

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

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarAllowCompilingThroughWorkers(
	TEXT("r.Shaders.AllowCompilingThroughWorkers"),
	1,
	TEXT("Allows shader compilation through external ShaderCompileWorker processes.\n")
	TEXT("1 - (Default) Allows external shader compiler workers\n") 
	TEXT("0 - Disallows external shader compiler workers. Will run shader compilation in proc of UE process."),
	ECVF_ReadOnly
	);

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

Scope (from outer to inner):

file
function     FShaderCompilingManager::FShaderCompilingManager

Source code excerpt:

	
	// override the use of workers, can be helpful for debugging shader compiler code
	static const IConsoleVariable* CVarAllowCompilingThroughWorkers = IConsoleManager::Get().FindConsoleVariable(TEXT("r.Shaders.AllowCompilingThroughWorkers"), false);
	if (!FPlatformProcess::SupportsMultithreading() || FParse::Param(FCommandLine::Get(), TEXT("noshaderworker")) || (CVarAllowCompilingThroughWorkers && CVarAllowCompilingThroughWorkers->GetInt() == 0))
	{
		bAllowCompilingThroughWorkers = false;
	}

	if (!FPlatformProcess::SupportsMultithreading())

#Associated Variable and Callsites

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

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

Scope (from outer to inner):

file
function     FShaderCompilingManager::FShaderCompilingManager

Source code excerpt:

	
	// override the use of workers, can be helpful for debugging shader compiler code
	static const IConsoleVariable* CVarAllowCompilingThroughWorkers = IConsoleManager::Get().FindConsoleVariable(TEXT("r.Shaders.AllowCompilingThroughWorkers"), false);
	if (!FPlatformProcess::SupportsMultithreading() || FParse::Param(FCommandLine::Get(), TEXT("noshaderworker")) || (CVarAllowCompilingThroughWorkers && CVarAllowCompilingThroughWorkers->GetInt() == 0))
	{
		bAllowCompilingThroughWorkers = false;
	}

	if (!FPlatformProcess::SupportsMultithreading())
	{

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

Scope: file

Source code excerpt:

	);

static TAutoConsoleVariable<int32> CVarAllowCompilingThroughWorkers(
	TEXT("r.Shaders.AllowCompilingThroughWorkers"),
	1,
	TEXT("Allows shader compilation through external ShaderCompileWorker processes.\n")
	TEXT("1 - (Default) Allows external shader compiler workers\n") 
	TEXT("0 - Disallows external shader compiler workers. Will run shader compilation in proc of UE process."),
	ECVF_ReadOnly