r.ShaderCompiler.ParallelInProcess

r.ShaderCompiler.ParallelInProcess

#Overview

name: r.ShaderCompiler.ParallelInProcess

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.ParallelInProcess is to control whether shader compilation is executed in-process in parallel. This setting variable is specifically for the shader compilation system in Unreal Engine 5.

This setting variable is primarily used by the shader compiler subsystem within the Engine module. Based on the callsites, it’s referenced in the ShaderCompiler.cpp file, which is part of the shader compilation system.

The value of this variable is set through a console variable (CVar) named CVarCompileParallelInProcess. It’s initialized with a default value of false, indicating that parallel in-process shader compilation is disabled by default.

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

Developers must be aware that this feature is marked as EXPERIMENTAL. The comment in the code also notes that enabling this option may cause serialization if the legacy preprocessor is enabled. This suggests potential performance implications or compatibility issues with older shader preprocessing methods.

Best practices when using this variable include:

  1. Only enable it in controlled development environments, not in production builds, due to its experimental nature.
  2. Monitor performance and stability when enabled, as it may impact shader compilation times and overall engine performance.
  3. Ensure that the legacy preprocessor is not in use when enabling this option to avoid potential serialization issues.
  4. Use in conjunction with other shader compilation settings to optimize the compilation process for your specific project needs.

Regarding the associated variable CVarCompileParallelInProcess:

The purpose of CVarCompileParallelInProcess is to provide a programmatic way to access and control the r.ShaderCompiler.ParallelInProcess setting within the engine’s C++ code.

This variable is used in the Engine module, specifically in the shader compiler system. It’s defined and used in the ShaderCompiler.cpp file.

The value of CVarCompileParallelInProcess is set when the console variable r.ShaderCompiler.ParallelInProcess is modified. It directly reflects the state of the console variable.

CVarCompileParallelInProcess interacts closely with the FShaderCompileThreadRunnable class, as seen in the CompilingLoop() function. It’s used to determine whether to allow parallel in-process shader compilation.

Developers should be aware that this variable is marked as read-only (ECVF_ReadOnly), meaning its value should not be modified directly in code but rather through the console variable system.

Best practices for using CVarCompileParallelInProcess include:

  1. Use GetValueOnAnyThread() when accessing its value, as shown in the example code.
  2. Treat it as a read-only variable and modify its value through the r.ShaderCompiler.ParallelInProcess console variable instead.
  3. Consider the implications of enabling parallel in-process compilation on different platforms and hardware configurations.

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

Scope: file

Source code excerpt:


static TAutoConsoleVariable<bool> CVarCompileParallelInProcess(
	TEXT("r.ShaderCompiler.ParallelInProcess"),
	false,
	TEXT("EXPERIMENTAL- If true, shader compilation will be executed in-process in parallel. Note that this will serialize if the legacy preprocessor is enabled."),
	ECVF_ReadOnly);

static TAutoConsoleVariable<bool> CVarShaderCompilerPerShaderDDCAsync(
	TEXT("r.ShaderCompiler.PerShaderDDCAsync"),

#Associated Variable and Callsites

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

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

Scope: file

Source code excerpt:

	ECVF_ReadOnly);

static TAutoConsoleVariable<bool> CVarCompileParallelInProcess(
	TEXT("r.ShaderCompiler.ParallelInProcess"),
	false,
	TEXT("EXPERIMENTAL- If true, shader compilation will be executed in-process in parallel. Note that this will serialize if the legacy preprocessor is enabled."),
	ECVF_ReadOnly);

static TAutoConsoleVariable<bool> CVarShaderCompilerPerShaderDDCAsync(

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

Scope (from outer to inner):

file
function     int32 FShaderCompileThreadRunnable::CompilingLoop

Source code excerpt:

int32 FShaderCompileThreadRunnable::CompilingLoop()
{
	if (!Manager->bAllowCompilingThroughWorkers && CVarCompileParallelInProcess.GetValueOnAnyThread())
	{
		int32 NumJobs = Manager->GetNumPendingJobs();
		if (NumJobs == 0)
		{
			return 0;
		}