r.Nanite.FilterPrimitives

r.Nanite.FilterPrimitives

#Overview

name: r.Nanite.FilterPrimitives

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.FilterPrimitives is to control whether per-view filtering of primitives is enabled in the Nanite rendering system. This setting variable is part of Unreal Engine 5’s Nanite technology, which is a virtualized geometry system for highly detailed meshes.

This setting variable is primarily used in the Nanite rendering subsystem, specifically in the culling and rasterization process. It’s referenced in the NaniteCullRaster.cpp file, which is part of the Renderer module.

The value of this variable is set through a console variable (CVar) system. It’s initialized with a default value of 1, meaning the feature is enabled by default. Developers can change this value at runtime using console commands or through project settings.

The associated variable CVarNaniteFilterPrimitives directly interacts with r.Nanite.FilterPrimitives. They share the same value and purpose.

Developers must be aware that this variable affects the performance and visual output of Nanite-enabled meshes. When enabled (set to 1), it performs per-view filtering of primitives, which can improve rendering efficiency by culling unnecessary geometry early in the rendering pipeline.

Best practices when using this variable include:

  1. Leaving it enabled (default value of 1) for most scenarios, as it can improve performance.
  2. Testing the impact of disabling it (setting to 0) in specific cases where you suspect it might be causing issues or if you need to debug the raw, unfiltered primitive data.
  3. Profiling your game with both settings to understand the performance impact in your specific use case.

Regarding the associated variable CVarNaniteFilterPrimitives:

The purpose of CVarNaniteFilterPrimitives is identical to r.Nanite.FilterPrimitives. It’s the actual console variable implementation that controls the behavior described above.

This variable is used directly in the Nanite renderer code to determine whether to perform the primitive filtering. For example, in the AddPass_PrimitiveFilter function, it’s checked to decide whether to create and populate a PrimitiveFilterBuffer.

The value of CVarNaniteFilterPrimitives is set through the console variable system and can be modified at runtime.

Developers should be aware that changes to this variable will immediately affect the Nanite rendering pipeline. It’s thread-safe for the render thread (ECVF_RenderThreadSafe), which means it can be safely changed even while the renderer is active.

Best practices for CVarNaniteFilterPrimitives are the same as for r.Nanite.FilterPrimitives, as they represent the same setting. Developers should use the r.Nanite.FilterPrimitives console command to modify this setting, rather than trying to change CVarNaniteFilterPrimitives directly in code.

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

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarNaniteFilterPrimitives(
	TEXT("r.Nanite.FilterPrimitives"),
	1,
	TEXT("Whether per-view filtering of primitive is enabled."),
	ECVF_RenderThreadSafe
);

static TAutoConsoleVariable<int32> CVarNaniteMeshShaderRasterization(

#Associated Variable and Callsites

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

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

Scope: file

Source code excerpt:

);

static TAutoConsoleVariable<int32> CVarNaniteFilterPrimitives(
	TEXT("r.Nanite.FilterPrimitives"),
	1,
	TEXT("Whether per-view filtering of primitive is enabled."),
	ECVF_RenderThreadSafe
);

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

Scope (from outer to inner):

file
namespace    Nanite
function     void FRenderer::AddPass_PrimitiveFilter

Source code excerpt:

	const bool bAnyFilterFlags = PrimitiveCount > 0 && HiddenFilterFlags != EFilterFlags::None;
	
	if (CVarNaniteFilterPrimitives.GetValueOnRenderThread() != 0 && (bAnyPrimitiveFilter || bAnyFilterFlags))
	{
		check(PrimitiveCount > 0);
		const uint32 DWordCount = FMath::DivideAndRoundUp(PrimitiveCount, 32u); // 32 primitive bits per uint32
		const uint32 PrimitiveFilterBufferElements = FMath::RoundUpToPowerOfTwo(DWordCount);

		PrimitiveFilterBuffer = GraphBuilder.CreateBuffer(FRDGBufferDesc::CreateStructuredDesc(sizeof(uint32), PrimitiveFilterBufferElements), TEXT("Nanite.PrimitiveFilter"));