ProcessGameThreadTargetTime

ProcessGameThreadTargetTime

#Overview

name: ProcessGameThreadTargetTime

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

#Summary

#Usage in the C++ source code

The purpose of ProcessGameThreadTargetTime is to control the execution time for processing asynchronous shader compilation results on the game thread. This variable is used to balance between speeding up async shader map processing and minimizing hitchiness during async compilation.

ProcessGameThreadTargetTime is primarily used by the shader compilation system within Unreal Engine’s rendering module. It is referenced in the FShaderCompilingManager class, which is responsible for managing shader compilation tasks.

The value of this variable is set in the engine configuration file (GEngineIni) under the “DevOptions.Shaders” section. It is loaded during the initialization of the FShaderCompilingManager.

ProcessGameThreadTargetTime interacts with the bLimitExecutionTime parameter in the ProcessAsyncResults function. When bLimitExecutionTime is true, ProcessGameThreadTargetTime is used as the time slice for processing async results.

Developers should be aware that:

  1. In debug builds, the value is tripled to accommodate for slower processing times.
  2. Larger values will speed up async shader map processing but may cause more noticeable hitches during gameplay.
  3. This variable directly affects the responsiveness of the game thread during shader compilation.

Best practices when using this variable include:

  1. Adjust the value carefully based on the target platform and desired balance between compilation speed and gameplay smoothness.
  2. Monitor performance metrics to ensure the chosen value doesn’t negatively impact frame rates or cause excessive hitching.
  3. Consider different values for development and shipping builds to optimize for different scenarios.
  4. Use in conjunction with other shader compilation settings to fine-tune the overall compilation process.

#Setting Variables

#References In INI files

Location: <Workspace>/Engine/Config/BaseEngine.ini:1967, 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:5635

Scope (from outer to inner):

file
function     FShaderCompilingManager::FShaderCompilingManager

Source code excerpt:

	GConfig->GetFloat(TEXT("DevOptions.Shaders"), TEXT("BuildWorkerTimeToLive"), GBuildWorkerTimeToLive, GEngineIni);

	verify(GConfig->GetFloat( TEXT("DevOptions.Shaders"), TEXT("ProcessGameThreadTargetTime"), ProcessGameThreadTargetTime, GEngineIni ));

#if UE_BUILD_DEBUG
	// Increase budget for processing results in debug or else it takes forever to finish due to poor framerate
	ProcessGameThreadTargetTime *= 3;
#endif

	// Get the current process Id, this will be used by the worker app to shut down when it's parent is no longer running.
	ProcessId = FPlatformProcess::GetCurrentProcessId();

	// Use a working directory unique to this game, process and thread so that it will not conflict 

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

Scope (from outer to inner):

file
function     void FShaderCompilingManager::ProcessAsyncResults

Source code excerpt:

void FShaderCompilingManager::ProcessAsyncResults(bool bLimitExecutionTime, bool bBlockOnGlobalShaderCompletion)
{
	const float TimeSlice = bLimitExecutionTime ? ProcessGameThreadTargetTime : 0.f;
	ProcessAsyncResults(TimeSlice, bBlockOnGlobalShaderCompletion);
}

void FShaderCompilingManager::ProcessAsyncResults(float TimeSlice, bool bBlockOnGlobalShaderCompletion)
{
	LLM_SCOPE_BYTAG(ShaderCompiler);

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Public/ShaderCompiler.h:722

Scope (from outer to inner):

file
class        class FShaderCompilingManager : IAssetCompilingManager

Source code excerpt:

	bool bLogJobCompletionTimes;
	/** Target execution time for ProcessAsyncResults.  Larger values speed up async shader map processing but cause more hitchiness while async compiling is happening. */
	float ProcessGameThreadTargetTime;
	/** Base directory where temporary files are written out during multi core shader compiling. */
	FString ShaderBaseWorkingDirectory;
	/** Absolute version of ShaderBaseWorkingDirectory. */
	FString AbsoluteShaderBaseWorkingDirectory;
	/** Absolute path to the directory to dump shader debug info to. */
	FString AbsoluteShaderDebugInfoDirectory;

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Public/ShaderCompiler.h:1014

Scope: file

Source code excerpt:

	ENGINE_API void ProcessAsyncResults(float TimeSlice, bool bBlockOnGlobalShaderCompletion);

	/** Version of ProcessAsyncResults that specifies use of ProcessGameThreadTargetTime for the timeslice. */
	ENGINE_API void ProcessAsyncResults(bool bLimitExecutionTime, bool bBlockOnGlobalShaderCompletion);

	/**
	 * Returns true if the given shader compile worker is still running.
	 */
	static bool IsShaderCompilerWorkerRunning(FProcHandle & WorkerHandle);