r.VRS.ContrastAdaptiveShading.Preview

r.VRS.ContrastAdaptiveShading.Preview

#Overview

name: r.VRS.ContrastAdaptiveShading.Preview

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.VRS.ContrastAdaptiveShading.Preview is to control whether Contrast Adaptive Shading (CAS) is included in the Variable Rate Shading (VRS) preview overlay. This setting is part of the rendering system, specifically related to the Variable Rate Shading feature in Unreal Engine 5.

This setting variable is primarily used in the Renderer module of Unreal Engine, specifically within the Variable Rate Shading subsystem. Based on the callsites, it’s clear that this variable is utilized in the ContrastAdaptiveImageGenerator.cpp file, which is part of the VRS implementation.

The value of this variable is set through a console variable (CVar) system. It’s initialized with a default value of 1 (on) and can be changed at runtime. The variable is defined as an integer, where 0 means off and 1 means on.

The associated variable CVarCASPreview directly interacts with r.VRS.ContrastAdaptiveShading.Preview. They share the same value and purpose, with CVarCASPreview being the actual C++ variable used in the code to access the setting.

Developers must be aware that this variable affects the debug visualization of the VRS system. When using this variable, they should consider:

  1. The impact on performance when enabling the preview, as it may introduce additional rendering overhead.
  2. The visual feedback provided by the preview overlay, which can be crucial for debugging and fine-tuning VRS settings.

Best practices when using this variable include:

  1. Enable it during development and debugging phases to visualize the CAS effect on VRS.
  2. Disable it in release builds or when performance is critical, as it’s primarily a debug feature.
  3. Use it in conjunction with other VRS-related settings to get a comprehensive understanding of the VRS system’s behavior.

Regarding the associated variable CVarCASPreview:

The purpose of CVarCASPreview is to provide a programmatic way to access and modify the r.VRS.ContrastAdaptiveShading.Preview setting within the C++ code. It’s an instance of TAutoConsoleVariable, which is a template class used in Unreal Engine to create console variables.

CVarCASPreview is used in the Renderer module, specifically in the ContrastAdaptiveImageGenerator class. It’s checked in the GetDebugImage function to determine whether to generate and return a debug image for the CAS preview.

The value of CVarCASPreview is set through the console variable system, just like r.VRS.ContrastAdaptiveShading.Preview. They are essentially two interfaces to the same setting - one for console input and one for C++ code.

Developers should be aware that changes to CVarCASPreview will directly affect the behavior of the CAS preview in the VRS system. They should use the GetValueOnRenderThread() method to access its value safely from the render thread.

Best practices for using CVarCASPreview include:

  1. Always access its value using GetValueOnRenderThread() when in render thread code.
  2. Consider the performance implications of frequently checking this value in performance-critical code paths.
  3. Use it as a quick way to toggle CAS preview functionality during development and debugging.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/VariableRateShading/ContrastAdaptiveImageGenerator.cpp:57

Scope: file

Source code excerpt:


TAutoConsoleVariable<int32> CVarCASPreview(
	TEXT("r.VRS.ContrastAdaptiveShading.Preview"),
	1,
	TEXT("Whether to include CAS in VRS preview overlay.")
	TEXT("0 - off, 1 - on (default)"),
	ECVF_RenderThreadSafe);

/**

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/VariableRateShading/ContrastAdaptiveImageGenerator.cpp:56

Scope: file

Source code excerpt:

 */

TAutoConsoleVariable<int32> CVarCASPreview(
	TEXT("r.VRS.ContrastAdaptiveShading.Preview"),
	1,
	TEXT("Whether to include CAS in VRS preview overlay.")
	TEXT("0 - off, 1 - on (default)"),
	ECVF_RenderThreadSafe);

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/VariableRateShading/ContrastAdaptiveImageGenerator.cpp:547

Scope (from outer to inner):

file
function     FRDGTextureRef FContrastAdaptiveImageGenerator::GetDebugImage

Source code excerpt:

FRDGTextureRef FContrastAdaptiveImageGenerator::GetDebugImage(FRDGBuilder& GraphBuilder, const FViewInfo& ViewInfo, FVariableRateShadingImageManager::EVRSImageType ImageType, bool bGetSoftwareImage)
{
	if (!CVarCASPreview.GetValueOnRenderThread() || !FCASImageData::IsInitialized(GraphBuilder))
	{
		return nullptr;
	}

	ESRIPreviewType::Type PreviewType = static_cast<ESRIPreviewType::Type>(ImageType);