r.Nanite.PrimShaderRasterization

r.Nanite.PrimShaderRasterization

#Overview

name: r.Nanite.PrimShaderRasterization

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.PrimShaderRasterization is to control the use of primitive shaders for hardware rasterization in Unreal Engine’s Nanite system. Nanite is a virtualized geometry system in Unreal Engine 5 that allows for highly detailed geometric models.

This setting variable is primarily used in the rendering system, specifically within the Nanite subsystem of Unreal Engine. Based on the callsites, it’s clear that this variable is utilized in the NaniteCullRaster module, which is part of the Renderer.

The value of this variable is set through a console variable (CVar) system. It’s initialized with a default value of 1, meaning primitive shaders are enabled by default for hardware rasterization if available.

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

Developers must be aware that this variable affects the rasterization method used in Nanite. When set to a non-zero value and if the hardware supports primitive shaders, Nanite will use primitive shaders for rasterization. This can potentially impact performance and visual quality.

Best practices when using this variable include:

  1. Ensure that the target hardware supports primitive shaders before relying on this feature.
  2. Test performance with this feature both enabled and disabled to determine the optimal setting for your specific use case.
  3. Be cautious when changing this setting at runtime, as it may affect rendering performance and quality.

Regarding the associated variable CVarNanitePrimShaderRasterization:

The purpose of CVarNanitePrimShaderRasterization is identical to r.Nanite.PrimShaderRasterization. It’s the actual console variable implementation that controls the use of primitive shaders in Nanite’s rasterization process.

This variable is used in the Nanite subsystem of the Unreal Engine renderer. It’s specifically referenced in the NaniteCullRaster module.

The value is set when the engine initializes the console variables. It can be modified at runtime through console commands.

CVarNanitePrimShaderRasterization interacts directly with the GRHISupportsPrimitiveShaders variable, which likely indicates whether the current hardware supports primitive shaders.

Developers should be aware that this variable is checked on the render thread, as indicated by the ECVF_RenderThreadSafe flag. Changes to this variable will affect rendering in real-time.

Best practices for using CVarNanitePrimShaderRasterization include:

  1. Use it in conjunction with hardware capability checks (like GRHISupportsPrimitiveShaders) to ensure compatibility.
  2. Consider exposing this setting in your game’s graphics options to allow users to optimize for their hardware.
  3. Profile your application’s performance with different values to understand the impact on your specific use case.

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

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarNanitePrimShaderRasterization(
	TEXT("r.Nanite.PrimShaderRasterization"),
	1,
	TEXT("If available, use primitive shaders for hardware rasterization."),
	ECVF_RenderThreadSafe
);

static TAutoConsoleVariable<int32> CVarNaniteVSMInvalidateOnLODDelta(

#Associated Variable and Callsites

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

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

Scope: file

Source code excerpt:

);

static TAutoConsoleVariable<int32> CVarNanitePrimShaderRasterization(
	TEXT("r.Nanite.PrimShaderRasterization"),
	1,
	TEXT("If available, use primitive shaders for hardware rasterization."),
	ECVF_RenderThreadSafe
);

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

Scope (from outer to inner):

file
function     static bool UsePrimitiveShader

Source code excerpt:

static bool UsePrimitiveShader()
{
	return CVarNanitePrimShaderRasterization.GetValueOnAnyThread() != 0 && GRHISupportsPrimitiveShaders;
}

static bool ShouldCompileSvBarycentricPermutation(EShaderPlatform ShaderPlatform, bool bPixelProgrammable, bool bMeshShaderRasterPath, bool bAllowSvBarycentrics)
{
	if (!bPixelProgrammable || !bMeshShaderRasterPath || FDataDrivenShaderPlatformInfo::GetSupportsBarycentricsIntrinsics(ShaderPlatform))
	{