rhi.SyncSlackMS

rhi.SyncSlackMS

#Overview

name: rhi.SyncSlackMS

This variable is created as a Console Variable (cvar).

It is referenced in 4 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of rhi.SyncSlackMS is to introduce a controlled delay in the rendering pipeline to improve performance at the cost of slightly increased input latency. It determines how many milliseconds before the vertical sync (vsync) the game thread should be initiated.

This setting variable is primarily used by the RHI (Rendering Hardware Interface) subsystem of Unreal Engine 5. It’s specifically related to the frame synchronization and timing mechanisms within the rendering pipeline.

The value of this variable is set through a console variable (CVar) system. It’s defined as a TAutoConsoleVariable with a default value of 10 milliseconds. Developers can modify this value at runtime or through configuration files.

The variable interacts closely with the frame offset thread system, as evidenced by the #if USE_FRAME_OFFSET_THREAD conditional compilation directives. When the frame offset thread is not in use, the system falls back to using the entire frame interval as the sync slack.

Developers should be aware that:

  1. This variable directly affects the trade-off between performance and input latency.
  2. It’s only effective when the frame offset thread system is enabled (USE_FRAME_OFFSET_THREAD is defined).
  3. The value is in milliseconds, so small changes can have noticeable effects.

Best practices when using this variable include:

  1. Carefully tuning the value based on the specific needs of the game or application.
  2. Monitoring both performance metrics and perceived input latency when adjusting this value.
  3. Considering different values for different hardware configurations or performance profiles.

Regarding the associated variable CVarRHISyncSlackMS: This is the actual console variable that stores the value of rhi.SyncSlackMS. It’s defined as a TAutoConsoleVariable, which allows it to be easily modified at runtime. The purpose and usage considerations are the same as for rhi.SyncSlackMS, as they represent the same concept within the engine. The CVarRHISyncSlackMS variable is used internally by the engine to retrieve the current value of the sync slack setting, as seen in the RHIGetSyncSlackMS() function.

#References in C++ code

#Callsites

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

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

Scope: file

Source code excerpt:

#if USE_FRAME_OFFSET_THREAD
TAutoConsoleVariable<float> CVarRHISyncSlackMS(
	TEXT("rhi.SyncSlackMS"),
	10,
	TEXT("Increases input latency by this many milliseconds, to help performance (trade-off tunable). Gamethread will be kicked off this many milliseconds before the vsync"),
	ECVF_Default
);
#endif

#Loc: <Workspace>/Engine/Source/Runtime/RHI/Public/RHIUtilities.h:618

Scope: file

Source code excerpt:

extern RHI_API uint32 RHIGetSyncInterval();

/** Returns the value of the rhi.SyncSlackMS CVar or length of a full frame interval if the frame offset system is disabled. */
extern RHI_API float RHIGetSyncSlackMS();

/** Returns the top and bottom vsync present thresholds (the values of rhi.PresentThreshold.Top and rhi.PresentThreshold.Bottom) */
extern RHI_API void RHIGetPresentThresholds(float& OutTopPercent, float& OutBottomPercent);

/** Returns the value of the rhi.SyncAllowVariable CVar. */

#Associated Variable and Callsites

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

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

Scope: file

Source code excerpt:


#if USE_FRAME_OFFSET_THREAD
TAutoConsoleVariable<float> CVarRHISyncSlackMS(
	TEXT("rhi.SyncSlackMS"),
	10,
	TEXT("Increases input latency by this many milliseconds, to help performance (trade-off tunable). Gamethread will be kicked off this many milliseconds before the vsync"),
	ECVF_Default
);
#endif

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

Scope (from outer to inner):

file
function     float RHIGetSyncSlackMS

Source code excerpt:

{
#if USE_FRAME_OFFSET_THREAD
	const float SyncSlackMS = CVarRHISyncSlackMS.GetValueOnAnyThread();
#else // #if USE_FRAME_OFFSET_THREAD
	const float SyncSlackMS = RHIGetSyncInterval() / float(FPlatformMisc::GetMaxRefreshRate()) * 1000.f;		// Sync slack is entire frame interval if we aren't using the frame offset system
#endif // #else // #if USE_FRAME_OFFSET_THREAD
	return SyncSlackMS;
}