r.InstancedStaticMeshes.FetchInstanceCountFromScene

r.InstancedStaticMeshes.FetchInstanceCountFromScene

#Overview

name: r.InstancedStaticMeshes.FetchInstanceCountFromScene

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.InstancedStaticMeshes.FetchInstanceCountFromScene is to enable a data path that allows the instance count to be fetched from the Scene rather than the Mesh Draw Commands (MDCs) for Instanced Static Meshes (ISMs). This setting is primarily used in the rendering system, specifically for optimizing the handling of ISMs.

This setting variable is used within the Engine module, particularly in the Instanced Static Mesh component of Unreal Engine 5. It affects how the engine manages and renders multiple instances of static meshes.

The value of this variable is set using a console variable (CVarISMFetchInstanceCountFromScene) with a default value of 1 (enabled). It can be changed at runtime through console commands or programmatically.

The associated variable CVarISMFetchInstanceCountFromScene directly interacts with r.InstancedStaticMeshes.FetchInstanceCountFromScene. They share the same value and purpose.

Developers must be aware that enabling this variable (which is the default behavior) changes how instance counts are retrieved for ISMs. This can have implications on performance and the need to re-cache Mesh Draw Commands.

Best practices when using this variable include:

  1. Understanding its impact on performance, especially in scenes with many instanced static meshes.
  2. Testing the application with both enabled and disabled states to determine the optimal setting for specific use cases.
  3. Being aware that changing this setting might require adjustments in other parts of the rendering pipeline that depend on instance count information.

Regarding the associated variable CVarISMFetchInstanceCountFromScene:

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/InstancedStaticMesh.cpp:181

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarISMFetchInstanceCountFromScene(
	TEXT("r.InstancedStaticMeshes.FetchInstanceCountFromScene"),
	1,
	TEXT("Enables the data path that allows instance count to be fetched from the Scene rather than the Mesh Draw Commands (MDCs), which removes the need to re-cache MDCs when instance count changes."));

static int32 GConservativeBoundsThreshold = 30;
FAutoConsoleVariableRef CVarISMConservativeBoundsThreshold(
	TEXT("r.InstancedStaticMeshes.ConservativeBounds.Threshold"),

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/InstancedStaticMesh.cpp:180

Scope: file

Source code excerpt:

	TEXT("Force the RemoveAtSwap optimization when removing instances from an ISM."));

static TAutoConsoleVariable<int32> CVarISMFetchInstanceCountFromScene(
	TEXT("r.InstancedStaticMeshes.FetchInstanceCountFromScene"),
	1,
	TEXT("Enables the data path that allows instance count to be fetched from the Scene rather than the Mesh Draw Commands (MDCs), which removes the need to re-cache MDCs when instance count changes."));

static int32 GConservativeBoundsThreshold = 30;
FAutoConsoleVariableRef CVarISMConservativeBoundsThreshold(

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/InstancedStaticMesh.cpp:1352

Scope (from outer to inner):

file
function     void FInstancedStaticMeshSceneProxy::SetupProxy

Source code excerpt:

#endif

	bDoesMeshBatchesUseSceneInstanceCount = CVarISMFetchInstanceCountFromScene.GetValueOnGameThread() != 0;

	SetupInstanceSceneDataBuffers(InstanceDataSceneProxy->GeInstanceSceneDataBuffers());

	bAnySegmentUsesWorldPositionOffset = false;

	// Make sure all the materials are okay to be rendered as an instanced mesh.

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/InstancedStaticMesh.cpp:1498

Scope (from outer to inner):

file
function     void FInstancedStaticMeshSceneProxy::SetupInstancedMeshBatch

Source code excerpt:

		}
	}
	BatchElement0.bFetchInstanceCountFromScene = CVarISMFetchInstanceCountFromScene.GetValueOnRenderThread() != 0;
	BatchElement0.NumInstances = GetInstanceDataHeader().NumInstances;
}

void FInstancedStaticMeshSceneProxy::GetLightRelevance(const FLightSceneProxy* LightSceneProxy, bool& bDynamic, bool& bRelevant, bool& bLightMapped, bool& bShadowMapped) const
{
	FStaticMeshSceneProxy::GetLightRelevance(LightSceneProxy, bDynamic, bRelevant, bLightMapped, bShadowMapped);