r.Shadow.ShouldBeginDeferredCullingAfterShadowRendering

r.Shadow.ShouldBeginDeferredCullingAfterShadowRendering

#Overview

name: r.Shadow.ShouldBeginDeferredCullingAfterShadowRendering

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.ShouldBeginDeferredCullingAfterShadowRendering is to control the timing of deferred culling in relation to shadow depth rendering. It is a temporary setting used to address a specific bug in the rendering system.

This setting variable is primarily used by the rendering system in Unreal Engine 5, specifically within the shadow rendering module. Based on the callsites, it is utilized in the ShadowDepthRendering.cpp file, which is part of the Renderer module.

The value of this variable is set through a console variable (CVarShouldBeginDeferredCullingAfterShadowRendering) with a default value of 1. It can be changed at runtime through console commands or project settings.

This variable interacts closely with the instance culling system. It is used in conjunction with FInstanceCullingContext::IsOcclusionCullingEnabled() to determine whether to begin a new deferred culling scope after shadow depth rendering.

Developers should be aware that this is a temporary setting introduced to work around a specific bug. It should not be relied upon as a permanent solution, and its behavior may change in future engine versions.

Best practices when using this variable include:

  1. Only modify it if experiencing issues related to instance culling and shadow rendering.
  2. Monitor its impact on performance, as it may affect the rendering pipeline.
  3. Keep track of engine updates that might address the underlying bug, potentially making this workaround unnecessary.

Regarding the associated variable CVarShouldBeginDeferredCullingAfterShadowRendering:

This is the actual console variable that controls the r.Shadow.ShouldBeginDeferredCullingAfterShadowRendering setting. It is defined as a TAutoConsoleVariable with the same name as the setting.

The purpose of this variable is to provide a runtime-configurable way to enable or disable the deferred culling behavior after shadow rendering. It is used directly in the rendering code to determine whether to begin a new deferred culling scope.

This variable is set in the ShadowDepthRendering.cpp file and is accessed using the GetValueOnRenderThread() method in the rendering code.

Developers should be aware that this variable is marked as ECVF_RenderThreadSafe, meaning it can be safely accessed from the render thread. Changes to this variable will take effect immediately in the rendering pipeline.

Best practices for using this console variable include:

  1. Use it for debugging and performance testing related to shadow rendering and instance culling.
  2. Be cautious when modifying it in a production environment, as it may impact rendering performance and visual quality.
  3. Consider removing any custom logic relying on this variable once the underlying bug is fixed in future engine versions.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadowDepthRendering.cpp:109

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarShouldBeginDeferredCullingAfterShadowRendering(
	TEXT("r.Shadow.ShouldBeginDeferredCullingAfterShadowRendering"),
	1,
	TEXT("Temporary: If turned on, a new deferred scope of instance culling will be started directly after shadow depth rendering (iff instance occlusion culling is enabled) to work around a bug."),
	ECVF_RenderThreadSafe);

static TAutoConsoleVariable<int32> CVarShadowForceSerialSingleRenderPass(
	TEXT("r.Shadow.ForceSerialSingleRenderPass"),

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadowDepthRendering.cpp:108

Scope: file

Source code excerpt:



static TAutoConsoleVariable<int32> CVarShouldBeginDeferredCullingAfterShadowRendering(
	TEXT("r.Shadow.ShouldBeginDeferredCullingAfterShadowRendering"),
	1,
	TEXT("Temporary: If turned on, a new deferred scope of instance culling will be started directly after shadow depth rendering (iff instance occlusion culling is enabled) to work around a bug."),
	ECVF_RenderThreadSafe);

static TAutoConsoleVariable<int32> CVarShadowForceSerialSingleRenderPass(

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/ShadowDepthRendering.cpp:1971

Scope (from outer to inner):

file
function     void FSceneRenderer::RenderShadowDepthMaps

Source code excerpt:

	
	// Begin another deferred batch here to avoid any subsequent passes enabling HZB for all (an unfortunate side effect).
	if (FInstanceCullingContext::IsOcclusionCullingEnabled() && CVarShouldBeginDeferredCullingAfterShadowRendering.GetValueOnRenderThread() != 0)
	{
		InstanceCullingManager.BeginDeferredCulling(GraphBuilder, Scene->GPUScene);
	}


	bShadowDepthRenderCompleted = true;