r.Shadow.Denoiser.MaxBatchSize

r.Shadow.Denoiser.MaxBatchSize

#Overview

name: r.Shadow.Denoiser.MaxBatchSize

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.Shadow.Denoiser.MaxBatchSize is to control the maximum number of shadows that can be denoised simultaneously in the rendering system of Unreal Engine 5. This setting is specifically related to the shadow denoising process, which is part of the engine’s rendering pipeline.

This setting variable is primarily used by the Renderer module of Unreal Engine 5, particularly in the light rendering subsystem. The code references are found in the LightRendering.cpp file, which is part of the runtime renderer.

The value of this variable is set through a console variable (CVar) system. It’s initialized with a default value of 4, but can be changed at runtime through console commands or configuration files.

The variable interacts closely with another variable named CVarMaxShadowDenoisingBatchSize, which is the C++ representation of the console variable. They share the same value and purpose.

Developers should be aware that this variable directly affects the performance and quality trade-off in shadow rendering. A higher value may improve performance by processing more shadows at once, but it might also increase memory usage and potentially affect frame rate if set too high.

Best practices when using this variable include:

  1. Keeping the value between 1 and IScreenSpaceDenoiser::kMaxBatchSize (the maximum allowed by the denoiser).
  2. Adjusting it based on the specific needs of the game and the target hardware capabilities.
  3. Testing different values to find the optimal balance between performance and visual quality.

Regarding the associated variable CVarMaxShadowDenoisingBatchSize:

The purpose of CVarMaxShadowDenoisingBatchSize is to provide a programmatic way to access and modify the r.Shadow.Denoiser.MaxBatchSize setting within the C++ code.

This variable is used directly in the rendering code, specifically in the FDeferredShadingSceneRenderer::RenderLights function. It’s retrieved using the GetValueOnRenderThread() method, ensuring thread-safe access to the current value.

The value of this variable is set when the console variable r.Shadow.Denoiser.MaxBatchSize is modified, as they are directly linked.

CVarMaxShadowDenoisingBatchSize interacts with other variables in the rendering process, such as CVarMaxShadowRayTracingBatchSize, to determine the overall shadow batching behavior.

Developers should be aware that changes to this variable will take effect on the render thread, which may not be immediate depending on when it’s accessed.

Best practices for using CVarMaxShadowDenoisingBatchSize include:

  1. Using it in render thread operations only.
  2. Clamping its value to ensure it stays within valid ranges, as done in the provided code snippet.
  3. Considering its impact on both shadow denoising and potentially ray tracing operations when modifying its value.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/LightRendering.cpp:95

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarMaxShadowDenoisingBatchSize(
	TEXT("r.Shadow.Denoiser.MaxBatchSize"), 4,
	TEXT("Maximum number of shadow to denoise at the same time."),
	ECVF_RenderThreadSafe);

static TAutoConsoleVariable<int32> CVarMaxShadowRayTracingBatchSize(
	TEXT("r.RayTracing.Shadows.MaxBatchSize"), 8,
	TEXT("Maximum number of shadows to trace at the same time."),

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/LightRendering.cpp:94

Scope: file

Source code excerpt:

	ECVF_RenderThreadSafe);

static TAutoConsoleVariable<int32> CVarMaxShadowDenoisingBatchSize(
	TEXT("r.Shadow.Denoiser.MaxBatchSize"), 4,
	TEXT("Maximum number of shadow to denoise at the same time."),
	ECVF_RenderThreadSafe);

static TAutoConsoleVariable<int32> CVarMaxShadowRayTracingBatchSize(
	TEXT("r.RayTracing.Shadows.MaxBatchSize"), 8,

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/LightRendering.cpp:1503

Scope (from outer to inner):

file
function     void FDeferredShadingSceneRenderer::RenderLights

Source code excerpt:

			TArray<FRDGTextureRef, SceneRenderingAllocator> PreprocessedShadowMaskSubPixelTextures;

			const int32 MaxDenoisingBatchSize = FMath::Clamp(CVarMaxShadowDenoisingBatchSize.GetValueOnRenderThread(), 1, IScreenSpaceDenoiser::kMaxBatchSize);
			const int32 MaxRTShadowBatchSize = CVarMaxShadowRayTracingBatchSize.GetValueOnRenderThread();
			const bool bDoShadowDenoisingBatching = DenoiserMode != 0 && MaxDenoisingBatchSize > 1;

			//#dxr_todo: support multiview for the batching case
			const bool bDoShadowBatching = (bDoShadowDenoisingBatching || MaxRTShadowBatchSize > 1) && Views.Num() == 1;