r.Nanite.MaxNodes

r.Nanite.MaxNodes

#Overview

name: r.Nanite.MaxNodes

This variable is created as a Console Variable (cvar).

It is referenced in 4 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of r.Nanite.MaxNodes is to set the maximum number of Nanite nodes that can be traversed during a culling pass in Unreal Engine’s Nanite geometry system.

This setting variable is primarily used by the Nanite rendering system, which is a part of Unreal Engine’s rendering module. Based on the callsites, it’s clear that this variable is crucial for the Nanite subsystem’s performance and visual quality.

The value of this variable is set through the console variable system, as evidenced by the FAutoConsoleVariableRef declaration. It can be modified at runtime using console commands or through configuration files.

The associated variable GNaniteMaxNodes directly interacts with r.Nanite.MaxNodes. They share the same value, with GNaniteMaxNodes being the actual integer variable used in the C++ code.

Developers must be aware that setting this value too low may result in visual artifacts. The feedback system in NaniteFeedback.cpp warns users when the node buffer overflows, suggesting an increase in r.Nanite.MaxNodes to prevent potential issues.

Best practices when using this variable include:

  1. Monitor the feedback messages for node buffer overflow warnings.
  2. Increase the value if overflow occurs frequently, but be mindful of potential performance impacts.
  3. Consider the trade-off between visual quality and performance when adjusting this value.

Regarding GNaniteMaxNodes: The purpose of GNaniteMaxNodes is to store the actual integer value used in the Nanite system’s calculations.

It’s used directly in the Nanite subsystem of the rendering module, particularly in the FGlobalResources class.

The value is set initially to 2 * 1048576 (2 million nodes) but can be modified through the r.Nanite.MaxNodes console variable.

GNaniteMaxNodes interacts directly with r.Nanite.MaxNodes and is used in calculations like GetMaxNodes() where it’s aligned to a specific boundary (NANITE_MAX_BVH_NODES_PER_GROUP).

Developers should be aware that modifying GNaniteMaxNodes directly in code is not recommended. Instead, they should use the r.Nanite.MaxNodes console variable to ensure proper synchronization.

Best practices include using the GetMaxNodes() function when needing this value in code, as it applies necessary alignment, and avoiding direct manipulation of GNaniteMaxNodes.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/Nanite/NaniteShared.cpp:31

Scope: file

Source code excerpt:

int32 GNaniteMaxNodes = 2 * 1048576;
FAutoConsoleVariableRef CVarNaniteMaxNodes(
	TEXT("r.Nanite.MaxNodes"),
	GNaniteMaxNodes,
	TEXT("Maximum number of Nanite nodes traversed during a culling pass."),
	ECVF_RenderThreadSafe
);

int32 GNaniteMaxCandidateClusters = 16 * 1048576;

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/Nanite/NaniteFeedback.cpp:73

Scope (from outer to inner):

file
function     FFeedbackManager::FFeedbackManager
lambda-function

Source code excerpt:

				FText::Format(LOCTEXT("NaniteNodeOverflow",
					"Nanite node buffer overflow detected: {0} / {1}. High-water mark is {2}. "
					"Increase r.Nanite.MaxNodes to prevent potential visual artifacts."),
					NodeState.LatestOverflowPeak, MaxNodes, NodeState.HighWaterMark));
		}

		if (CurrentTime - CandidateClusterState.LatestOverflowTime < ShowWarningSeconds)
		{
			OutMessages.Add(FCoreDelegates::EOnScreenMessageSeverity::Warning,

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/Nanite/NaniteShared.cpp:29

Scope: file

Source code excerpt:

);

int32 GNaniteMaxNodes = 2 * 1048576;
FAutoConsoleVariableRef CVarNaniteMaxNodes(
	TEXT("r.Nanite.MaxNodes"),
	GNaniteMaxNodes,
	TEXT("Maximum number of Nanite nodes traversed during a culling pass."),
	ECVF_RenderThreadSafe
);

int32 GNaniteMaxCandidateClusters = 16 * 1048576;
FAutoConsoleVariableRef CVarNaniteMaxCandidateClusters(

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/Nanite/NaniteShared.cpp:326

Scope (from outer to inner):

file
namespace    Nanite
function     uint32 FGlobalResources::GetMaxNodes

Source code excerpt:

uint32 FGlobalResources::GetMaxNodes()
{
	return GNaniteMaxNodes & -NANITE_MAX_BVH_NODES_PER_GROUP;
}

uint32 FGlobalResources::GetMaxCandidatePatches()
{
	return GNaniteMaxCandidatePatches;
}