r.SupportReversedIndexBuffers

r.SupportReversedIndexBuffers

#Overview

name: r.SupportReversedIndexBuffers

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

It is referenced in 5 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of r.SupportReversedIndexBuffers is to enable or disable support for reversed index buffers in Unreal Engine’s rendering system. This setting is primarily used for optimizing rendering performance at the cost of increased memory usage.

  1. The r.SupportReversedIndexBuffers variable is used in the rendering system, specifically for static mesh rendering.

  2. This setting variable is primarily used in the Engine module, particularly in the StaticMesh.cpp file. It affects the behavior of static mesh rendering and resource management.

  3. The value of this variable is set through a console variable (CVar) system. It is initialized with a default value of 1 (enabled) and can be changed at runtime through console commands.

  4. This variable interacts closely with CVarSupportDepthOnlyIndexBuffers, another rendering optimization setting. Both are often used together to determine the behavior of index buffer creation and usage.

  5. Developers should be aware that enabling this feature (which is the default) will double the size of index buffers. This trade-off should be considered when optimizing for memory usage versus rendering performance.

  6. Best practices for using this variable include:

    • Carefully consider the performance vs. memory trade-off for your specific project.
    • Test the impact of enabling/disabling this feature on your target hardware.
    • Be aware that changing this setting at runtime may not affect already loaded resources.

Regarding the associated variable CVarSupportReversedIndexBuffers:

This is the actual console variable that controls the r.SupportReversedIndexBuffers setting. It is defined as a TAutoConsoleVariable, which means it can be changed at runtime through console commands.

The CVarSupportReversedIndexBuffers variable is used in several places within the StaticMesh.cpp file to determine whether reversed index buffers should be created or used. It’s important to note that this variable is marked as ECVF_ReadOnly and ECVF_RenderThreadSafe, which means it’s intended to be set at startup and not changed during runtime, and it’s safe to read from any thread.

When using this variable in code, it’s typically accessed using the GetValueOnAnyThread() method, which returns the current int32 value of the console variable. This value is then used in boolean contexts to determine if reversed index buffers should be supported.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/StaticMesh.cpp:137

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarSupportReversedIndexBuffers(
	TEXT("r.SupportReversedIndexBuffers"),
	1,
	TEXT("Enables reversed index buffers. Saves a little time at the expense of doubling the size of index buffers."),
	ECVF_ReadOnly | ECVF_RenderThreadSafe);

static TAutoConsoleVariable<int32> CVarStripDistanceFieldDataDuringLoad(
	TEXT("r.StaticMesh.StripDistanceFieldDataDuringLoad"),

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/StaticMesh.cpp:136

Scope: file

Source code excerpt:

	ECVF_ReadOnly | ECVF_RenderThreadSafe);

static TAutoConsoleVariable<int32> CVarSupportReversedIndexBuffers(
	TEXT("r.SupportReversedIndexBuffers"),
	1,
	TEXT("Enables reversed index buffers. Saves a little time at the expense of doubling the size of index buffers."),
	ECVF_ReadOnly | ECVF_RenderThreadSafe);

static TAutoConsoleVariable<int32> CVarStripDistanceFieldDataDuringLoad(

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/StaticMesh.cpp:461

Scope (from outer to inner):

file
function     uint32 FStaticMeshLODResources::FStaticMeshBuffersSize::CalcBuffersSize

Source code excerpt:

	// Assumes these two cvars don't change at runtime
	const bool bEnableDepthOnlyIndexBuffer = !!CVarSupportDepthOnlyIndexBuffers.GetValueOnAnyThread();
	const bool bEnableReversedIndexBuffer = !!CVarSupportReversedIndexBuffers.GetValueOnAnyThread();
	return SerializedBuffersSize
		- (bEnableDepthOnlyIndexBuffer ? 0 : DepthOnlyIBSize)
		- (bEnableReversedIndexBuffer ? 0 : ReversedIBsSize);
}

void FStaticMeshLODResources::SerializeBuffers(FArchive& Ar, UStaticMesh* OwnerStaticMesh, uint8 InStripFlags, FStaticMeshBuffersSize& OutBuffersSize)

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/StaticMesh.cpp:473

Scope (from outer to inner):

file
function     void FStaticMeshLODResources::SerializeBuffers

Source code excerpt:

	// If the index buffers have already been initialized, do not change the behavior since the RHI resource pointer may have been cached somewhere already.
	const bool bEnableDepthOnlyIndexBuffer = bHasDepthOnlyIndices || (CVarSupportDepthOnlyIndexBuffers.GetValueOnAnyThread() == 1);
	const bool bEnableReversedIndexBuffer = bHasReversedIndices || bHasReversedDepthOnlyIndices || (CVarSupportReversedIndexBuffers.GetValueOnAnyThread() == 1);

	// See if the mesh wants to keep resources CPU accessible
	bool bMeshCPUAcces = OwnerStaticMesh ? OwnerStaticMesh->bAllowCPUAccess : false;

	// Note: this is all derived data, native versioning is not needed, but be sure to bump STATICMESH_DERIVEDDATA_VER when modifying!

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/StaticMesh.cpp:599

Scope (from outer to inner):

file
function     void FStaticMeshLODResources::SerializeAvailabilityInfo

Source code excerpt:

	bool bHasAdjacencyInfo = false;
	const bool bEnableDepthOnlyIndexBuffer = !!CVarSupportDepthOnlyIndexBuffers.GetValueOnAnyThread();
	const bool bEnableReversedIndexBuffer = !!CVarSupportReversedIndexBuffers.GetValueOnAnyThread();

	Ar << DepthOnlyNumTriangles;
	uint32 Packed;
#if WITH_EDITOR
	if (Ar.IsSaving())
	{