rhi.SyncAllowEarlyKick

rhi.SyncAllowEarlyKick

#Overview

name: rhi.SyncAllowEarlyKick

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 rhi.SyncAllowEarlyKick is to control the behavior of the RHI (Rendering Hardware Interface) vsync thread in Unreal Engine 5. Specifically, it determines whether the vsync thread is allowed to initiate the next frame early if a vsync has been missed.

This setting variable is primarily used in the RHI subsystem of Unreal Engine 5, which is responsible for managing the interface between the engine and the graphics hardware. It’s particularly relevant to the frame synchronization and presentation mechanisms.

The value of this variable is set through the console variable system in Unreal Engine. It’s initialized with a default value of 1, meaning the early kick feature is enabled by default.

The associated variable CVarRHISyncAllowEarlyKick is an instance of TAutoConsoleVariable that directly corresponds to the rhi.SyncAllowEarlyKick setting. This variable is used in the C++ code to access the current value of the setting.

Developers should be aware that:

  1. This variable affects frame timing and synchronization, which can impact gameplay smoothness and visual consistency.
  2. Changing this value may affect performance and frame pacing, especially on systems that are struggling to maintain the target frame rate.
  3. The effect of this setting may vary depending on the specific hardware and driver implementations.

Best practices when using this variable include:

  1. Testing the impact of enabling and disabling this feature (setting to 1 or 0) on different hardware configurations.
  2. Monitoring frame times and vsync behavior when adjusting this setting.
  3. Consider exposing this as a user-configurable option for players with different performance needs or preferences.
  4. Be cautious about disabling this feature (setting to 0) as it may lead to more noticeable frame rate inconsistencies during performance hitches.

Regarding the associated variable CVarRHISyncAllowEarlyKick:

This is the C++ representation of the rhi.SyncAllowEarlyKick console variable. It’s used within the engine code to read the current value of the setting. The variable is accessed using the GetValueOnAnyThread() method, which suggests that it can be safely read from multiple threads.

Developers should note that changes to this variable will take effect immediately, potentially affecting frame synchronization mid-game. Therefore, it’s important to consider the timing and context of any changes to this variable during runtime.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/RHI/Private/RHIUtilities.cpp:105

Scope: file

Source code excerpt:


TAutoConsoleVariable<int32> CVarRHISyncAllowEarlyKick(
	TEXT("rhi.SyncAllowEarlyKick"),
	1,
	TEXT("When 1, allows the RHI vsync thread to kick off the next frame early if we've missed the vsync."),
	ECVF_Default
);

#if USE_FRAME_OFFSET_THREAD

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/RHI/Private/RHIUtilities.cpp:104

Scope: file

Source code excerpt:

);

TAutoConsoleVariable<int32> CVarRHISyncAllowEarlyKick(
	TEXT("rhi.SyncAllowEarlyKick"),
	1,
	TEXT("When 1, allows the RHI vsync thread to kick off the next frame early if we've missed the vsync."),
	ECVF_Default
);

#Loc: <Workspace>/Engine/Source/Runtime/RHI/Private/RHIUtilities.cpp:399

Scope (from outer to inner):

file
function     uint32 FRHIFrameFlipTrackingRunnable::Run

Source code excerpt:

			SyncFrame = FlippedFrame.PresentIndex;
			SyncTime = FlippedFrame.VBlankTimeInSeconds;
			bForceFlipSync = CVarRHISyncAllowEarlyKick.GetValueOnAnyThread() == 0;
		}
		else if (SyncInterval != 0 && !bForceFlipSync && (CurrentTimeInSeconds > ExpectedNextFlipTimeInSeconds))
		{
			// We've missed a flip. Signal the next frame
			// anyway to optimistically recover from a hitch.
			SyncFrame = FlippedFrame.PresentIndex + 1;