bForceUseSCWMemoryPressureLimits

bForceUseSCWMemoryPressureLimits

#Overview

name: bForceUseSCWMemoryPressureLimits

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

It is referenced in 3 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of bForceUseSCWMemoryPressureLimits is to control the memory usage of the shader compiler worker (SCW) processes in Unreal Engine 5. This setting variable is primarily used in the shader compilation system.

Based on the callsites, this variable is used within the Engine module, specifically in the ShaderCompiler subsystem. It’s referenced in the FShaderCompilingManager class, which is responsible for managing shader compilation tasks.

The value of this variable is set from the configuration file (GEngineIni) under the [DevOptions.Shaders] section. It’s read using the GConfig->GetBool() function.

This variable interacts with other configuration variables such as CookerMemoryUsedInGB, MemoryToLeaveForTheOSInGB, and MemoryUsedPerSCWProcessInGB. These variables are used together to calculate the number of shader compiling threads.

Developers must be aware that this variable is primarily intended for use on build machines or in scenarios where fine-grained control over shader compiler memory usage is required. When set to true, it enforces the use of memory pressure limits for shader compilation, which can help prevent out-of-memory issues during the cooking process.

Best practices when using this variable include:

  1. Only enable it when necessary, typically on build machines or when experiencing memory-related issues during shader compilation.
  2. Ensure that the related memory configuration variables (CookerMemoryUsedInGB, MemoryToLeaveForTheOSInGB, MemoryUsedPerSCWProcessInGB) are properly set when enabling this option.
  3. Monitor the shader compilation performance and memory usage when this option is enabled, as it may affect the number of concurrent shader compilation threads.
  4. Be cautious when using this on development machines, as it may unnecessarily limit shader compilation performance if not properly configured.

#Setting Variables

#References In INI files

Location: <Workspace>/Engine/Config/BaseEngine.ini:1984, section: [DevOptions.Shaders]

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

Scope (from outer to inner):

file
function     void FShaderCompilingManager::CalculateNumberOfCompilingThreads

Source code excerpt:

	verify(GConfig->GetInt(TEXT("DevOptions.Shaders"), TEXT("ShaderCompilerCoreCountThreshold"), ShaderCompilerCoreCountThreshold, GEngineIni));

	bool bForceUseSCWMemoryPressureLimits = false;
	GConfig->GetBool(TEXT("DevOptions.Shaders"), TEXT("bForceUseSCWMemoryPressureLimits"), bForceUseSCWMemoryPressureLimits, GEngineIni);

	// Don't reserve threads based on a percentage if we are in a commandlet or on a low core machine.
	// In these scenarios we should try to use as many threads as possible.
	if (!IsRunningCommandlet() && !GIsBuildMachine && NumVirtualCores > ShaderCompilerCoreCountThreshold)
	{
		// Reserve a percentage of the threads for general background work.

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

Scope (from outer to inner):

file
function     void FShaderCompilingManager::CalculateNumberOfCompilingThreads

Source code excerpt:

	}
#if PLATFORM_DESKTOP
	else if (GIsBuildMachine || bForceUseSCWMemoryPressureLimits)
	{
		// Cooker ends up running OOM so use a simple heuristic based on some INI values
		float CookerMemoryUsedInGB = 0.0f;
		float MemoryToLeaveForTheOSInGB = 0.0f;
		float MemoryUsedPerSCWProcessInGB = 0.0f;
		bool bFoundEntries = true;

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

Scope (from outer to inner):

file
function     void FShaderCompilingManager::CalculateNumberOfCompilingThreads

Source code excerpt:

			}
		}
		else if (bForceUseSCWMemoryPressureLimits)
		{
			UE_LOG(LogShaderCompilers, Warning, TEXT("bForceUseSCWMemoryPressureLimits was set but missing one or more prerequisite setting(s): CookerMemoryUsedInGB, MemoryToLeaveForTheOSInGB, MemoryUsedPerSCWProcessInGB.  Ignoring bForceUseSCWMemoryPressureLimits"));
		}

		if (GIsBuildMachine)
		{