r.SceneCulling.ValidateAllInstanceAllocations

r.SceneCulling.ValidateAllInstanceAllocations

#Overview

name: r.SceneCulling.ValidateAllInstanceAllocations

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.SceneCulling.ValidateAllInstanceAllocations is to enable validation of all instance IDs stored in the scene culling grid. This setting is primarily used for debugging and performance analysis in the rendering system of Unreal Engine 5.

The Unreal Engine subsystem that relies on this setting variable is the Renderer module, specifically the SceneCulling component. This can be inferred from the file path “Engine/Source/Runtime/Renderer/Private/SceneCulling/SceneCulling.cpp”.

The value of this variable is set through the console variable system in Unreal Engine. It’s defined as a TAutoConsoleVariable with an initial value of 0, which means the validation is disabled by default.

The associated variable CVarValidateAllInstanceAllocations directly interacts with r.SceneCulling.ValidateAllInstanceAllocations. They share the same value and purpose.

Developers must be aware that enabling this validation is very slow, as stated in the comment: “Perform validation of all instance IDs stored in the grid. This is very slow.” Therefore, it should only be used for debugging purposes and not in production builds or during normal development.

Best practices when using this variable include:

  1. Only enable it when debugging issues related to scene culling or instance allocation.
  2. Disable it immediately after debugging to avoid performance impacts.
  3. Use it in conjunction with other debugging tools to isolate and identify problems in the scene culling system.

Regarding the associated variable CVarValidateAllInstanceAllocations:

The purpose of CVarValidateAllInstanceAllocations is the same as r.SceneCulling.ValidateAllInstanceAllocations. It’s used to control the validation of instance IDs in the scene culling grid.

This variable is used directly in the code, specifically in the ValidateAllInstanceAllocations() function of the FSceneCulling class. The validation is only performed if the value of this variable is non-zero.

The value of CVarValidateAllInstanceAllocations is set and retrieved using the console variable system, specifically with the GetValueOnRenderThread() method.

Developers should be aware that this variable is marked as ECVF_RenderThreadSafe, meaning it can be safely accessed from the render thread.

Best practices for using CVarValidateAllInstanceAllocations are the same as for r.SceneCulling.ValidateAllInstanceAllocations, with the addition that developers should be mindful of potential threading issues when accessing or modifying this variable, ensuring it’s only done in render thread safe contexts.

#References in C++ code

#Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/SceneCulling/SceneCulling.cpp:163

Scope: file

Source code excerpt:


static TAutoConsoleVariable<int32> CVarValidateAllInstanceAllocations(
	TEXT("r.SceneCulling.ValidateAllInstanceAllocations"), 
	0, 
	TEXT("Perform validation of all instance IDs stored in the grid. This is very slow."), 
	ECVF_RenderThreadSafe);

static TAutoConsoleVariable<int32> CVarSceneCullingUseExplicitCellBounds(
	TEXT("r.SceneCulling.ExplicitCellBounds"), 

#Associated Variable and Callsites

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

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/SceneCulling/SceneCulling.cpp:162

Scope: file

Source code excerpt:

	ECVF_RenderThreadSafe);

static TAutoConsoleVariable<int32> CVarValidateAllInstanceAllocations(
	TEXT("r.SceneCulling.ValidateAllInstanceAllocations"), 
	0, 
	TEXT("Perform validation of all instance IDs stored in the grid. This is very slow."), 
	ECVF_RenderThreadSafe);

static TAutoConsoleVariable<int32> CVarSceneCullingUseExplicitCellBounds(

#Loc: <Workspace>/Engine/Source/Runtime/Renderer/Private/SceneCulling/SceneCulling.cpp:2781

Scope (from outer to inner):

file
function     void FSceneCulling::ValidateAllInstanceAllocations

Source code excerpt:

{
#if DO_CHECK
	if (CVarValidateAllInstanceAllocations.GetValueOnRenderThread() != 0)
	{
		for (TConstSetBitIterator<> BitIt(CellOccupancyMask); BitIt; ++BitIt)
		{
			uint32 CellId = uint32(BitIt.GetIndex());
			FCellHeader CellHeader = UnpackCellHeader(CellHeaders[CellId]);
			check(IsValidCell(CellHeader));