r.Composite.TemporalUpsampleDepth

r.Composite.TemporalUpsampleDepth

#Overview

name: r.Composite.TemporalUpsampleDepth

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 r.Composite.TemporalUpsampleDepth is to control the temporal upsample factor of the depth buffer used for depth testing editor primitives. This setting is primarily used in the rendering system, specifically for post-processing and composite primitives.

This setting variable is utilized by the Renderer module of Unreal Engine 5, particularly in the post-processing and composite primitives subsystem. It’s referenced in the file PostProcessCompositePrimitivesCommon.cpp, which suggests its importance in handling editor primitives and depth buffer operations.

The value of this variable is set through a console variable (CVarCompositeTemporalUpsampleDepth) with a default value of 2. It can be changed at runtime using console commands or through engine configuration files.

The variable interacts closely with its associated variable CVarCompositeTemporalUpsampleDepth, which is the actual TAutoConsoleVariable instance that stores and manages the value. They essentially represent the same setting but in different contexts.

Developers should be aware that this variable affects the quality and performance of depth testing for editor primitives. A higher value may improve visual quality but could impact performance. The value is clamped between 0 and a maximum value determined by the current rendering capabilities and anti-aliasing method.

Best practices when using this variable include:

  1. Consider the performance implications when adjusting the value.
  2. Test different values to find the optimal balance between visual quality and performance for your specific use case.
  3. Be aware of its interaction with Temporal Anti-Aliasing (TAA) and other post-processing effects.

Regarding the associated variable CVarCompositeTemporalUpsampleDepth:

The purpose of CVarCompositeTemporalUpsampleDepth is to provide a configurable interface for the r.Composite.TemporalUpsampleDepth setting. It’s an instance of TAutoConsoleVariable, which allows for runtime modification of the setting.

This variable is used directly in the Renderer module, specifically in the TemporalUpscaleDepthPass function. It determines the actual upsample factor applied to the depth buffer.

The value of this variable is set when it’s declared, with a default value of 2. It can be modified at runtime through console commands.

CVarCompositeTemporalUpsampleDepth interacts with other rendering systems, particularly those involving Temporal Anti-Aliasing (TAA) and depth buffer processing.

Developers should be aware that changes to this variable will immediately affect the rendering pipeline. It’s thread-safe (ECVF_RenderThreadSafe), meaning it can be safely accessed from the render thread.

Best practices for using CVarCompositeTemporalUpsampleDepth include:

  1. Use GetValueOnRenderThread() when accessing the value in render thread code.
  2. Consider exposing this setting in your game’s graphics options for advanced users.
  3. Monitor performance impact when modifying this value, especially on lower-end hardware.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/PostProcess/PostProcessCompositePrimitivesCommon.cpp:10

Scope: file

Source code excerpt:

#define MAX_DEPTHTEX_UPSCALE_FACTOR 4
TAutoConsoleVariable<int32> CVarCompositeTemporalUpsampleDepth(
	TEXT("r.Composite.TemporalUpsampleDepth"), 2,
	TEXT("Temporal upsample factor of the depth buffer for depth testing editor primitives against."),
	ECVF_RenderThreadSafe);

const FViewInfo* CreateCompositePrimitiveView(const FViewInfo& ParentView, FIntRect ViewRect, uint32 NumMSAASamples)
{
	FViewInfo* View = ParentView.CreateSnapshot();

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/PostProcess/PostProcessCompositePrimitivesCommon.cpp:9

Scope: file

Source code excerpt:

#define MIN_DEPTHTEX_UPSCALE_FACTOR 1
#define MAX_DEPTHTEX_UPSCALE_FACTOR 4
TAutoConsoleVariable<int32> CVarCompositeTemporalUpsampleDepth(
	TEXT("r.Composite.TemporalUpsampleDepth"), 2,
	TEXT("Temporal upsample factor of the depth buffer for depth testing editor primitives against."),
	ECVF_RenderThreadSafe);

const FViewInfo* CreateCompositePrimitiveView(const FViewInfo& ParentView, FIntRect ViewRect, uint32 NumMSAASamples)
{

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/PostProcess/PostProcessCompositePrimitivesCommon.cpp:173

Scope (from outer to inner):

file
function     void TemporalUpscaleDepthPass

Source code excerpt:

		const int32 ComputeMaxUpsampleFactor = FMath::Clamp(ComputeMaxUpsampleFactorDueToTAA, 0, MaxRHIUpsampleFactor);

		const int32 DepthUpsampleFactor = FMath::Clamp(CVarCompositeTemporalUpsampleDepth.GetValueOnRenderThread(), 0, ComputeMaxUpsampleFactor);

		// Upsample the depth at higher resolution to reduce depth intersection instability of editor primitives.
		if (DepthUpsampleFactor > 0 && View.ViewState && IsTemporalAccumulationBasedMethod(View.AntiAliasingMethod))
		{
			FScreenPassTexture History;
			const FRDGTextureDesc Desc = FRDGTextureDesc::Create2D(