r.Nanite.MaxVisiblePatches

r.Nanite.MaxVisiblePatches

#Overview

name: r.Nanite.MaxVisiblePatches

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.MaxVisiblePatches is to set the maximum number of visible Nanite patches in the rendering system. This setting variable is crucial for controlling the performance and visual quality of Nanite-based geometry in Unreal Engine 5.

This setting variable is primarily used by the Nanite rendering subsystem within the Renderer module of Unreal Engine 5. Based on the callsites, it’s clear that this variable is defined and used within the Nanite-specific code.

The value of this variable is set through the console variable system in Unreal Engine. It’s initialized with a default value of 2,097,152 (2 * 1048576) and can be modified at runtime using console commands or through project settings.

The associated variable GNaniteMaxVisiblePatches directly interacts with r.Nanite.MaxVisiblePatches. They share the same value, with GNaniteMaxVisiblePatches being the actual integer variable used in the C++ code, while r.Nanite.MaxVisiblePatches is the console variable name used for external access and modification.

Developers must be aware that this variable affects the memory usage and performance of Nanite rendering. Setting it too high might lead to excessive memory consumption, while setting it too low could result in visual artifacts or reduced detail in Nanite-based geometry.

Best practices when using this variable include:

  1. Monitoring performance and memory usage when adjusting this value.
  2. Testing with different values to find the optimal balance between visual quality and performance for your specific project.
  3. Considering scaling this value based on the target hardware capabilities.

Regarding the associated variable GNaniteMaxVisiblePatches:

The purpose of GNaniteMaxVisiblePatches is to store the actual integer value of the maximum number of visible Nanite patches. It’s used internally by the Nanite rendering system to limit the number of patches processed.

This variable is used within the Nanite namespace in the Renderer module. Specifically, it’s accessed through the FGlobalResources::GetMaxVisiblePatches() function, which suggests it’s part of the global resource management for Nanite.

The value of GNaniteMaxVisiblePatches is set directly by the console variable system when r.Nanite.MaxVisiblePatches is modified.

As mentioned earlier, this variable directly interacts with r.Nanite.MaxVisiblePatches, serving as its C++ representation within the engine code.

Developers should be aware that modifying GNaniteMaxVisiblePatches directly in code is not recommended. Instead, they should use the console variable r.Nanite.MaxVisiblePatches to ensure proper synchronization and thread-safety.

Best practices for GNaniteMaxVisiblePatches include:

  1. Accessing its value through the provided FGlobalResources::GetMaxVisiblePatches() function rather than directly.
  2. Avoiding direct modification of this variable in code, instead using the console variable system.
  3. Considering the impact on performance and memory when working with systems that rely on this value.

#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:63

Scope: file

Source code excerpt:

int32 GNaniteMaxVisiblePatches = 2 * 1048576;
FAutoConsoleVariableRef CVarNaniteMaxVisiblePatches(
	TEXT("r.Nanite.MaxVisiblePatches"),
	GNaniteMaxVisiblePatches,
	TEXT("Maximum number of visible Nanite patches."),
	ECVF_RenderThreadSafe
);

#define MAX_CLUSTERS	(16 * 1024 * 1024)

#Associated Variable and Callsites

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

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

Scope: file

Source code excerpt:

);

int32 GNaniteMaxVisiblePatches = 2 * 1048576;
FAutoConsoleVariableRef CVarNaniteMaxVisiblePatches(
	TEXT("r.Nanite.MaxVisiblePatches"),
	GNaniteMaxVisiblePatches,
	TEXT("Maximum number of visible Nanite patches."),
	ECVF_RenderThreadSafe
);

#define MAX_CLUSTERS	(16 * 1024 * 1024)

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

Scope (from outer to inner):

file
namespace    Nanite
function     uint32 FGlobalResources::GetMaxVisiblePatches

Source code excerpt:

uint32 FGlobalResources::GetMaxVisiblePatches()
{
	return GNaniteMaxVisiblePatches;
}

TGlobalResource< FGlobalResources > GGlobalResources;

} // namespace Nanite