r.Nanite.AsyncRasterization.ShadowDepths

r.Nanite.AsyncRasterization.ShadowDepths

#Overview

name: r.Nanite.AsyncRasterization.ShadowDepths

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.Nanite.AsyncRasterization.ShadowDepths is to control whether Nanite compute rasterization of shadows should run as asynchronous compute when available. This setting variable is part of the Nanite rendering system in Unreal Engine 5, specifically related to shadow rendering optimization.

This setting variable is primarily used in the Renderer module of Unreal Engine, particularly within the Nanite subsystem. Based on the callsites, it’s evident that this variable is utilized in the NaniteCullRaster.cpp file, which is responsible for culling and rasterization operations in Nanite.

The value of this variable is set through the console variable system in Unreal Engine. It’s defined as a TAutoConsoleVariable with an initial value of 0, meaning it’s disabled by default.

The associated variable CVarNaniteAsyncRasterizeShadowDepths directly interacts with this setting. It’s the actual console variable object that stores and provides access to the value of r.Nanite.AsyncRasterization.ShadowDepths.

Developers must be aware that enabling this feature (by setting it to a non-zero value) will cause Nanite to use asynchronous compute for shadow depth rasterization when available. However, it’s important to note that this feature is automatically disabled when Lumen async compute is enabled, as it can negatively impact overall frame performance in that scenario.

Best practices when using this variable include:

  1. Only enable it if you’re specifically looking to optimize shadow rendering performance.
  2. Test thoroughly to ensure it doesn’t negatively impact overall performance, especially in conjunction with other rendering features like Lumen.
  3. Be aware of the potential interactions with other async compute tasks in your rendering pipeline.

Regarding the associated variable CVarNaniteAsyncRasterizeShadowDepths:

The purpose of CVarNaniteAsyncRasterizeShadowDepths is to provide programmatic access to the r.Nanite.AsyncRasterization.ShadowDepths setting within the engine’s C++ code.

This variable is used in the Renderer module, specifically in the Nanite subsystem’s culling and rasterization logic.

The value of this variable is set when the r.Nanite.AsyncRasterization.ShadowDepths console command is used, and it’s accessed in the code using the GetValueOnRenderThread() method.

It directly controls the behavior of the r.Nanite.AsyncRasterization.ShadowDepths setting and is used in the UseAsyncComputeForShadowMaps function to determine whether async compute should be used for shadow maps.

Developers should be aware that this variable is render thread safe (ECVF_RenderThreadSafe), meaning it can be safely accessed and modified from the render thread.

Best practices include using the GetValueOnRenderThread() method to access its value in render thread code, and being mindful of the performance implications of enabling or disabling this feature, especially in relation to other rendering systems like Lumen.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/Nanite/NaniteCullRaster.cpp:56

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarNaniteAsyncRasterizeShadowDepths(
	TEXT("r.Nanite.AsyncRasterization.ShadowDepths"),
	0,
	TEXT("If available, run Nanite compute rasterization of shadows as asynchronous compute."),
	ECVF_RenderThreadSafe
);

static TAutoConsoleVariable<int32> CVarNaniteCullInstanceHierarchy(

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/Nanite/NaniteCullRaster.cpp:55

Scope: file

Source code excerpt:

);

static TAutoConsoleVariable<int32> CVarNaniteAsyncRasterizeShadowDepths(
	TEXT("r.Nanite.AsyncRasterization.ShadowDepths"),
	0,
	TEXT("If available, run Nanite compute rasterization of shadows as asynchronous compute."),
	ECVF_RenderThreadSafe
);

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/Nanite/NaniteCullRaster.cpp:461

Scope (from outer to inner):

file
function     static bool UseAsyncComputeForShadowMaps

Source code excerpt:

{
	// Automatically disabled when Lumen async is enabled, as it then delays graphics pipe too much and regresses overall frame performance
	return CVarNaniteAsyncRasterizeShadowDepths.GetValueOnRenderThread() != 0 && !Lumen::UseAsyncCompute(ViewFamily);
}

#if WANTS_DRAW_MESH_EVENTS
static FORCEINLINE const TCHAR* GetRasterMaterialName(const FMaterialRenderProxy* InRasterMaterial, const FMaterialRenderProxy* InFixedFunction)
{
	if ((InRasterMaterial == nullptr) || (InRasterMaterial == InFixedFunction))