r.Nanite.MaterialBuffers.MaterialDataMinSizeBytes

r.Nanite.MaterialBuffers.MaterialDataMinSizeBytes

#Overview

name: r.Nanite.MaterialBuffers.MaterialDataMinSizeBytes

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.MaterialBuffers.MaterialDataMinSizeBytes is to set the minimum size in bytes for the Nanite material data buffer in Unreal Engine 5’s rendering system. This setting is specifically related to the Nanite geometry system, which is a key feature of UE5 for handling high-detail meshes efficiently.

This setting variable is primarily used in the Renderer module of Unreal Engine 5, specifically within the Nanite subsystem. It’s referenced in the NaniteMaterialsSceneExtension.cpp file, which suggests it’s closely tied to how Nanite handles materials for its geometry system.

The value of this variable is set as a console variable (CVar) with a default value of 4 * 1024 bytes (4 KB). It’s defined as read-only and render thread safe, meaning it can be safely accessed from the render thread but cannot be changed at runtime.

This variable interacts closely with an associated variable named CVarNaniteMaterialDataBufferMinSizeBytes. They share the same value and are used interchangeably in the code.

Developers should be aware that this variable affects the memory allocation for Nanite material data. Setting it too low might lead to frequent reallocations, while setting it too high might waste memory. It’s also important to note that this is a minimum size, so the actual buffer might be larger depending on the needs of the scene.

Best practices when using this variable include:

  1. Monitoring performance and memory usage to find the optimal value for your specific use case.
  2. Considering the complexity and variety of materials in your Nanite geometries when adjusting this value.
  3. Being cautious about changing it at runtime, as it’s marked as read-only.

Regarding the associated variable CVarNaniteMaterialDataBufferMinSizeBytes:

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/Nanite/NaniteMaterialsSceneExtension.cpp:5

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarNaniteMaterialDataBufferMinSizeBytes(
	TEXT("r.Nanite.MaterialBuffers.MaterialDataMinSizeBytes"),
	4 * 1024,
	TEXT("The smallest size (in bytes) of the Nanite material data buffer."),
	ECVF_ReadOnly | ECVF_RenderThreadSafe
);

static TAutoConsoleVariable<int32> CVarNanitePrimitiveMaterialDataBufferMinSizeBytes(

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/Nanite/NaniteMaterialsSceneExtension.cpp:4

Scope: file

Source code excerpt:

#include "RenderUtils.h"

static TAutoConsoleVariable<int32> CVarNaniteMaterialDataBufferMinSizeBytes(
	TEXT("r.Nanite.MaterialBuffers.MaterialDataMinSizeBytes"),
	4 * 1024,
	TEXT("The smallest size (in bytes) of the Nanite material data buffer."),
	ECVF_ReadOnly | ECVF_RenderThreadSafe
);

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/Nanite/NaniteMaterialsSceneExtension.cpp:227

Scope (from outer to inner):

file
function     bool FMaterialsSceneExtension::ProcessBufferDefragmentation

Source code excerpt:


	const bool bAllowDefrag = CVarNaniteMaterialBufferDefrag.GetValueOnRenderThread();
	static const int32 MinMaterialBufferSizeDwords = CVarNaniteMaterialDataBufferMinSizeBytes.GetValueOnRenderThread() / 4;
	const float LowWaterMarkRatio = CVarNaniteMaterialBufferDefragLowWaterMark.GetValueOnRenderThread();
	const int32 EffectiveMaxSize = FMath::RoundUpToPowerOfTwo(MaterialBufferAllocator.GetMaxSize());
	const int32 LowWaterMark = uint32(EffectiveMaxSize * LowWaterMarkRatio);
	const int32 UsedSize = MaterialBufferAllocator.GetSparselyAllocatedSize();
	
	if (!bAllowDefrag)

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/Nanite/NaniteMaterialsSceneExtension.cpp:279

Scope (from outer to inner):

file
function     FMaterialsSceneExtension::FMaterialBuffers::FMaterialBuffers

Source code excerpt:

	),
	MaterialDataBuffer(
		CVarNaniteMaterialDataBufferMinSizeBytes.GetValueOnAnyThread() / 4,
		TEXT("Nanite.MaterialData")
	)
{
}