AllowAsyncRenderThreadUpdates

AllowAsyncRenderThreadUpdates

#Overview

name: AllowAsyncRenderThreadUpdates

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 AllowAsyncRenderThreadUpdates is to control asynchronous render thread updates in Unreal Engine 5. This setting variable is primarily used in the rendering system to manage the synchronization between the game thread and the render thread.

This setting variable is primarily used in the Engine module, specifically within the LevelTick.cpp file. It’s part of the core engine functionality that handles level updates and component rendering.

The value of this variable is set through a console variable (CVar) system. It’s initialized with a default value of 1 (enabled) but can be changed at runtime through console commands or programmatically.

AllowAsyncRenderThreadUpdates interacts with another variable, CVarAllowAsyncRenderThreadUpdatesDuringGamethreadUpdates. Both of these variables work together to control the behavior of asynchronous render thread updates.

Developers must be aware that this variable is also gated by FApp::ShouldUseThreadingForPerformance(). This means that even if AllowAsyncRenderThreadUpdates is set to 1, asynchronous updates may not occur if the application determines that threading for performance should not be used.

Best practices when using this variable include:

  1. Consider performance implications when enabling or disabling async render thread updates.
  2. Be cautious when changing this value at runtime, as it can affect rendering behavior and potentially cause visual artifacts if not managed properly.
  3. Use in conjunction with profiling tools to determine the optimal setting for your specific game or application.

Regarding the associated variable CVarAllowAsyncRenderThreadUpdates:

The purpose of CVarAllowAsyncRenderThreadUpdates is to provide a programmatic interface to control the AllowAsyncRenderThreadUpdates setting. It’s a TAutoConsoleVariable which allows for runtime modification of the setting.

This variable is used in the same Engine module and LevelTick.cpp file. It’s the actual implementation of the console variable that controls the behavior.

The value of CVarAllowAsyncRenderThreadUpdates is set when the variable is initialized, but can be changed at runtime through console commands or programmatic access.

CVarAllowAsyncRenderThreadUpdates directly controls the behavior of async render thread updates. It’s used in conditional statements to determine whether to force updates on the game thread or allow them to occur asynchronously on the render thread.

Developers should be aware that this variable can be accessed from any thread (as evident from the use of GetValueOnAnyThread()), which means it’s thread-safe for reading but care should be taken when modifying its value to avoid race conditions.

Best practices for using CVarAllowAsyncRenderThreadUpdates include:

  1. Use GetValueOnAnyThread() when accessing the value from multiple threads.
  2. Consider using this variable for debug or performance tuning scenarios.
  3. Document any changes to this variable in your project, as it can significantly affect rendering behavior and performance.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/LevelTick.cpp:773

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarAllowAsyncRenderThreadUpdates(
	TEXT("AllowAsyncRenderThreadUpdates"),
	1,
	TEXT("Used to control async renderthread updates. Also gated on FApp::ShouldUseThreadingForPerformance()."));

static TAutoConsoleVariable<int32> CVarAllowAsyncRenderThreadUpdatesDuringGamethreadUpdates(
	TEXT("AllowAsyncRenderThreadUpdatesDuringGamethreadUpdates"),
	1,

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/LevelTick.cpp:772

Scope: file

Source code excerpt:

}

static TAutoConsoleVariable<int32> CVarAllowAsyncRenderThreadUpdates(
	TEXT("AllowAsyncRenderThreadUpdates"),
	1,
	TEXT("Used to control async renderthread updates. Also gated on FApp::ShouldUseThreadingForPerformance()."));

static TAutoConsoleVariable<int32> CVarAllowAsyncRenderThreadUpdatesDuringGamethreadUpdates(
	TEXT("AllowAsyncRenderThreadUpdatesDuringGamethreadUpdates"),

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/LevelTick.cpp:918

Scope (from outer to inner):

file
function     void UWorld::MarkActorComponentForNeededEndOfFrameUpdate

Source code excerpt:

			}
#else
			bForceGameThread = !CVarAllowAsyncRenderThreadUpdates.GetValueOnAnyThread();
#endif
		}

		if (bForceGameThread)
		{
			FMarkComponentEndOfFrameUpdateState::Set(Component, ComponentsThatNeedEndOfFrameUpdate_OnGameThread.Num(), EComponentMarkedForEndOfFrameUpdateState::MarkedForGameThread);