r.PostProcessing.PreferCompute

r.PostProcessing.PreferCompute

#Overview

name: r.PostProcessing.PreferCompute

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.PostProcessing.PreferCompute is to control whether compute shaders are used for post-processing operations in Unreal Engine 5’s rendering system. This setting variable is primarily used in the rendering subsystem, specifically for post-processing effects.

The Unreal Engine subsystem that relies on this setting variable is the Renderer module, as evidenced by its location in the “Runtime/Renderer/Private/PostProcess/PostProcessing.cpp” file.

The value of this variable is set through a console variable (CVar) system. It’s initialized with a default value of 0, which means compute shaders are not preferred by default for post-processing.

This variable interacts with the associated variable CVarPostProcessingPreferCompute. They share the same value and purpose.

Developers must be aware that this variable only takes effect when the feature level is SM5 (Shader Model 5) or higher. This is checked in the IsPostProcessingWithComputeEnabled function.

Best practices when using this variable include:

  1. Only enable it when targeting platforms that support Shader Model 5 or higher.
  2. Consider the performance implications of using compute shaders for post-processing, as it may not always be beneficial on all hardware.
  3. Test thoroughly when enabling this feature, as it may affect the visual output or performance of post-processing effects.

Regarding the associated variable CVarPostProcessingPreferCompute:

The purpose of CVarPostProcessingPreferCompute is the same as r.PostProcessing.PreferCompute. It’s an internal representation of the console variable used in the C++ code.

This variable is used directly in the IsPostProcessingWithComputeEnabled function to determine whether compute shaders should be used for post-processing.

The value of this variable is set through the console variable system, just like r.PostProcessing.PreferCompute.

Developers should be aware that this variable is accessed using GetValueOnAnyThread(), which means it can be read from any thread. This is important for thread-safety considerations.

Best practices for using CVarPostProcessingPreferCompute include:

  1. Use it in conjunction with feature level checks, as demonstrated in the IsPostProcessingWithComputeEnabled function.
  2. Be cautious when accessing it from multiple threads, as it’s designed to be read from any thread.
  3. Consider caching its value if it’s going to be used frequently in performance-critical sections of code.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/PostProcess/PostProcessing.cpp:111

Scope (from outer to inner):

file
namespace    anonymous

Source code excerpt:


TAutoConsoleVariable<int32> CVarPostProcessingPreferCompute(
	TEXT("r.PostProcessing.PreferCompute"),
	0,
	TEXT("Will use compute shaders for post processing where implementations available."),
	ECVF_RenderThreadSafe);

TAutoConsoleVariable<int32> CVarPostProcessingQuarterResolutionDownsample(
	TEXT("r.PostProcessing.QuarterResolutionDownsample"),

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/PostProcess/PostProcessing.cpp:110

Scope (from outer to inner):

file
namespace    anonymous

Source code excerpt:

	ECVF_ReadOnly);

TAutoConsoleVariable<int32> CVarPostProcessingPreferCompute(
	TEXT("r.PostProcessing.PreferCompute"),
	0,
	TEXT("Will use compute shaders for post processing where implementations available."),
	ECVF_RenderThreadSafe);

TAutoConsoleVariable<int32> CVarPostProcessingQuarterResolutionDownsample(

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/PostProcess/PostProcessing.cpp:166

Scope (from outer to inner):

file
function     bool IsPostProcessingWithComputeEnabled

Source code excerpt:

{
	// Any thread is used due to FViewInfo initialization.
	return CVarPostProcessingPreferCompute.GetValueOnAnyThread() && FeatureLevel >= ERHIFeatureLevel::SM5;
}

bool IsPostProcessingOutputInHDR()
{
	static const auto CVarDumpFramesAsHDR = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.BufferVisualizationDumpFramesAsHDR"));