UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
FInstanceCullingContext Class Reference

#include <InstanceCullingContext.h>

Classes

struct  FCompactionData
 
struct  FMeshDrawCommandInfo
 
struct  FPayloadData
 

Public Types

enum class  EInstanceFlags : uint8 { None = 0 , DynamicInstanceDataOffset = 1 << 0 , ForceInstanceCulling = 1 << 1 , PreserveInstanceOrder = 1 << 2 }
 
enum class  EAsyncProcessingMode { DeferredOrAsync , Synchronous }
 
using SyncPrerequisitesFuncType = TFunction< void(FInstanceCullingContext &InstanceCullingContext)>
 
using LoadBalancerArray = TStaticArray< FInstanceProcessingGPULoadBalancer *, static_cast< uint32 >(EBatchProcessingMode::Num)>
 

Public Member Functions

 FInstanceCullingContext ()
 
 FInstanceCullingContext (EShaderPlatform ShaderPlatform, FInstanceCullingManager *InInstanceCullingManager, TArrayView< const int32 > InViewIds, const TRefCountPtr< IPooledRenderTarget > &InPrevHZB, EInstanceCullingMode InInstanceCullingMode=EInstanceCullingMode::Normal, EInstanceCullingFlags InFlags=EInstanceCullingFlags::None, EBatchProcessingMode InSingleInstanceProcessingMode=EBatchProcessingMode::UnCulled)
 
RENDERER_API FInstanceCullingContext (const TCHAR *PassName, EShaderPlatform ShaderPlatform, FInstanceCullingManager *InInstanceCullingManager, TArrayView< const int32 > InViewIds, const TRefCountPtr< IPooledRenderTarget > &InPrevHZB, EInstanceCullingMode InInstanceCullingMode=EInstanceCullingMode::Normal, EInstanceCullingFlags InFlags=EInstanceCullingFlags::None, EBatchProcessingMode InSingleInstanceProcessingMode=EBatchProcessingMode::UnCulled)
 
RENDERER_API ~FInstanceCullingContext ()
 
void ResetCommands (int32 MaxNumCommands)
 
bool IsEnabled () const
 
bool IsInstanceOrderPreservationEnabled () const
 
void AddInstancesToDrawCommand (uint32 IndirectArgsOffset, int32 InstanceDataOffset, uint32 RunOffset, uint32 NumInstances, EInstanceFlags InstanceFlags)
 
void AddInstancesToDrawCommand (uint32 IndirectArgsOffset, int32 InstanceDataOffset, uint32 RunOffset, uint32 NumInstances, EInstanceFlags InstanceFlags, uint32 MaxBatchSize)
 
void AddInstanceRunsToDrawCommand (uint32 IndirectArgsOffset, int32 InstanceDataOffset, const uint32 *Runs, uint32 NumRuns, EInstanceFlags InstanceFlags, uint32 MaxBatchSize)
 
uint32 AllocateIndirectArgs (const FMeshDrawCommand *MeshDrawCommand)
 
uint32 StepInstanceDataOffsetBytes (uint32 NumStepDraws) const
 
uint32 GetInstanceIdNumElements () const
 
void BeginAsyncSetup (SyncPrerequisitesFuncType &&InSyncPrerequisitesFunc)
 
void WaitForSetupTask ()
 
void SetDynamicPrimitiveInstanceOffsets (int32 InDynamicInstanceIdOffset, int32 InDynamicInstanceIdNum)
 
void BuildRenderingCommands (FRDGBuilder &GraphBuilder, const FGPUScene &GPUScene, int32 InDynamicInstanceIdOffset, int32 InDynamicInstanceIdNum, FInstanceCullingResult &Results)
 
void BuildRenderingCommands (FRDGBuilder &GraphBuilder, const FGPUScene &GPUScene, FInstanceCullingDrawParams *InstanceCullingDrawParams)
 
bool HasCullingCommands () const
 
EInstanceCullingMode GetInstanceCullingMode () const
 
void SetupDrawCommands (FMeshCommandOneFrameArray &VisibleMeshDrawCommandsInOut, bool bCompactIdenticalCommands, const FScene *Scene, int32 &MaxInstancesOut, int32 &VisibleMeshDrawCommandsNumOut, int32 &NewPassVisibleMeshDrawCommandsNumOut)
 
void SubmitDrawCommands (const FMeshCommandOneFrameArray &VisibleMeshDrawCommands, const FGraphicsMinimalPipelineStateSet &GraphicsMinimalPipelineStateSet, const FMeshDrawCommandOverrideArgs &OverrideArgs, int32 StartIndex, int32 NumMeshDrawCommands, uint32 InstanceFactor, FRHICommandList &RHICmdList) const
 
void BuildRenderingCommandsInternal (FRDGBuilder &GraphBuilder, const FGPUScene &GPUScene, EAsyncProcessingMode AsyncProcessingMode, FInstanceCullingDrawParams *InstanceCullingDrawParams)
 

Static Public Member Functions

static RENDERER_API uint32 GetInstanceIdBufferStride (EShaderPlatform ShaderPlatform)
 
static RENDERER_API FUniformBufferStaticSlot GetStaticUniformBufferSlot (EShaderPlatform ShaderPlatform)
 
static RENDERER_API const TRDGUniformBufferRef< FInstanceCullingGlobalUniformsCreateDummyInstanceCullingUniformBuffer (FRDGBuilder &GraphBuilder)
 
static bool IsGPUCullingEnabled ()
 
static bool IsOcclusionCullingEnabled ()
 
static FInstanceCullingDeferredContextCreateDeferredContext (FRDGBuilder &GraphBuilder, const FGPUScene &GPUScene, FInstanceCullingManager &InstanceCullingManager)
 
static void SetDeferredContextCullingParams (const FInstanceCullingDeferredContext &DeferredContext, FInstanceCullingDrawParams &Parameters)
 
static void AddClearIndirectArgInstanceCountPass (FRDGBuilder &GraphBuilder, FGlobalShaderMap *ShaderMap, FRDGBufferRef DrawIndirectArgsBuffer, TFunction< int32()> NumIndirectArgsCallback=TFunction< int32()>())
 

Public Attributes

FInstanceCullingManagerInstanceCullingManager = nullptr
 
EShaderPlatform ShaderPlatform = SP_NumPlatforms
 
TArray< int32, TInlineAllocator< 6, SceneRenderingAllocator > > ViewIds
 
TRefCountPtr< IPooledRenderTargetPrevHZB = nullptr
 
bool bIsEnabled = false
 
EInstanceCullingMode InstanceCullingMode = EInstanceCullingMode::Normal
 
EInstanceCullingFlags Flags = EInstanceCullingFlags::None
 
uint32 TotalInstances = 0U
 
int32 DynamicInstanceIdOffset = -1
 
int32 DynamicInstanceIdNum = -1
 
SyncPrerequisitesFuncType SyncPrerequisitesFunc
 
TArray< FMeshDrawCommandInfo, SceneRenderingAllocatorMeshDrawCommandInfos
 
TArray< FRHIDrawIndexedIndirectParameters, SceneRenderingAllocatorIndirectArgs
 
TArray< FUintVector2, SceneRenderingAllocatorDrawCommandDescs
 
TArray< FPayloadData, SceneRenderingAllocatorPayloadData
 
TArray< uint32, SceneRenderingAllocatorInstanceIdOffsets
 
TArray< FCompactionData, SceneRenderingAllocatorDrawCommandCompactionData
 
TArray< uint32, SceneRenderingAllocatorCompactionBlockDataIndices
 
uint32 NumCompactionInstances = 0U
 
LoadBalancerArray LoadBalancers = LoadBalancerArray(InPlace, nullptr)
 
EBatchProcessingMode SingleInstanceProcessingMode = EBatchProcessingMode::UnCulled
 
FUniformBufferStaticSlot InstanceCullingStaticSlot
 
bool bUsesUniformBufferView
 

Static Public Attributes

static constexpr uint32 UniformViewInstanceStride [2]
 
static constexpr uint32 IndirectArgsNumWords = 5
 
static constexpr uint32 CompactionBlockNumInstances = 64
 

Member Typedef Documentation

◆ LoadBalancerArray

◆ SyncPrerequisitesFuncType

Member Enumeration Documentation

◆ EAsyncProcessingMode

Enumerator
DeferredOrAsync 
Synchronous 

◆ EInstanceFlags

Enumerator
None 
DynamicInstanceDataOffset 
ForceInstanceCulling 
PreserveInstanceOrder 

Constructor & Destructor Documentation

◆ FInstanceCullingContext() [1/3]

FInstanceCullingContext::FInstanceCullingContext ( )
inline

◆ FInstanceCullingContext() [2/3]

FInstanceCullingContext::FInstanceCullingContext ( EShaderPlatform  ShaderPlatform,
FInstanceCullingManager InInstanceCullingManager,
TArrayView< const int32 InViewIds,
const TRefCountPtr< IPooledRenderTarget > &  InPrevHZB,
EInstanceCullingMode  InInstanceCullingMode = EInstanceCullingMode::Normal,
EInstanceCullingFlags  InFlags = EInstanceCullingFlags::None,
EBatchProcessingMode  InSingleInstanceProcessingMode = EBatchProcessingMode::UnCulled 
)
inline

◆ FInstanceCullingContext() [3/3]

FInstanceCullingContext::FInstanceCullingContext ( const TCHAR PassName,
EShaderPlatform  ShaderPlatform,
FInstanceCullingManager InInstanceCullingManager,
TArrayView< const int32 InViewIds,
const TRefCountPtr< IPooledRenderTarget > &  InPrevHZB,
EInstanceCullingMode  InInstanceCullingMode = EInstanceCullingMode::Normal,
EInstanceCullingFlags  InFlags = EInstanceCullingFlags::None,
EBatchProcessingMode  InSingleInstanceProcessingMode = EBatchProcessingMode::UnCulled 
)

Create an instance culling context to process draw commands that can be culled using GPU-Scene.

Parameters
InPrevHZBif non-null enables HZB-occlusion culling for the context (if r.InstanceCulling.OcclusionCull is enabled), NOTE: only one PrevHZB target is allowed accross all passes currently, so either must be atlased or otherwise the same.

◆ ~FInstanceCullingContext()

FInstanceCullingContext::~FInstanceCullingContext ( )

Member Function Documentation

◆ AddClearIndirectArgInstanceCountPass()

void FInstanceCullingContext::AddClearIndirectArgInstanceCountPass ( FRDGBuilder GraphBuilder,
FGlobalShaderMap ShaderMap,
FRDGBufferRef  DrawIndirectArgsBuffer,
TFunction< int32()>  NumIndirectArgsCallback = TFunction<int32()>() 
)
static

Helper function to add a pass to zero the instance count in the indirect args.

◆ AddInstanceRunsToDrawCommand()

void FInstanceCullingContext::AddInstanceRunsToDrawCommand ( uint32  IndirectArgsOffset,
int32  InstanceDataOffset,
const uint32 Runs,
uint32  NumRuns,
EInstanceFlags  InstanceFlags,
uint32  MaxBatchSize 
)

Command that is executed in the per-view, post-cull pass to gather up the instances belonging to this primitive. Multiple commands may add to the same slot, ordering is not preserved.

◆ AddInstancesToDrawCommand() [1/2]

void FInstanceCullingContext::AddInstancesToDrawCommand ( uint32  IndirectArgsOffset,
int32  InstanceDataOffset,
uint32  RunOffset,
uint32  NumInstances,
EInstanceFlags  InstanceFlags 
)

Add command to cull a range of instances for the given mesh draw command index. Multiple commands may add to the same slot, ordering is not preserved.

◆ AddInstancesToDrawCommand() [2/2]

void FInstanceCullingContext::AddInstancesToDrawCommand ( uint32  IndirectArgsOffset,
int32  InstanceDataOffset,
uint32  RunOffset,
uint32  NumInstances,
EInstanceFlags  InstanceFlags,
uint32  MaxBatchSize 
)

◆ AllocateIndirectArgs()

uint32 FInstanceCullingContext::AllocateIndirectArgs ( const FMeshDrawCommand MeshDrawCommand)

◆ BeginAsyncSetup()

void FInstanceCullingContext::BeginAsyncSetup ( SyncPrerequisitesFuncType &&  InSyncPrerequisitesFunc)

Set up the context to track an async setup process, or some deferred setup work. The supplied function should do two things, apart from any other processing needed.

  1. wait for the async setup task
  2. Call SetDynamicPrimitiveInstanceOffsets (unless that is achieved somehow else).

◆ BuildRenderingCommands() [1/2]

void FInstanceCullingContext::BuildRenderingCommands ( FRDGBuilder GraphBuilder,
const FGPUScene GPUScene,
FInstanceCullingDrawParams InstanceCullingDrawParams 
)

This BuildRenderingCommands operation may be deferred and merged into a global pass when possible. Note: InstanceCullingDrawParams is captured by the deferred culling passes and must therefore have a RDG-lifetime. If BeginAsyncSetup has been called prior to this, the WaitForSetupTask is deferred as long as possible. If BeginAsyncSetup was not called, then SetDynamicPrimitiveInstanceOffsets must be called before this.

◆ BuildRenderingCommands() [2/2]

void FInstanceCullingContext::BuildRenderingCommands ( FRDGBuilder GraphBuilder,
const FGPUScene GPUScene,
int32  InDynamicInstanceIdOffset,
int32  InDynamicInstanceIdNum,
FInstanceCullingResult Results 
)

This version is never deferred, nor async, calling BeginAsyncSetup before this is an error.

◆ BuildRenderingCommandsInternal()

void FInstanceCullingContext::BuildRenderingCommandsInternal ( FRDGBuilder GraphBuilder,
const FGPUScene GPUScene,
EAsyncProcessingMode  AsyncProcessingMode,
FInstanceCullingDrawParams InstanceCullingDrawParams 
)

◆ CreateDeferredContext()

FInstanceCullingDeferredContext * FInstanceCullingContext::CreateDeferredContext ( FRDGBuilder GraphBuilder,
const FGPUScene GPUScene,
FInstanceCullingManager InstanceCullingManager 
)
static

Add a batched BuildRenderingCommands pass. Each batch represents a BuildRenderingCommands call from a mesh pass. Batches are collected as we walk through the main render setup and are executed when RDG Execute or Drain is called. This implicitly ends the deferred context, so if Drain is used, it should be paired with a new call to BeginDeferredCulling.

◆ CreateDummyInstanceCullingUniformBuffer()

const TRDGUniformBufferRef< FInstanceCullingGlobalUniforms > FInstanceCullingContext::CreateDummyInstanceCullingUniformBuffer ( FRDGBuilder GraphBuilder)
static

◆ GetInstanceCullingMode()

EInstanceCullingMode FInstanceCullingContext::GetInstanceCullingMode ( ) const
inline

◆ GetInstanceIdBufferStride()

uint32 FInstanceCullingContext::GetInstanceIdBufferStride ( EShaderPlatform  ShaderPlatform)
static

◆ GetInstanceIdNumElements()

uint32 FInstanceCullingContext::GetInstanceIdNumElements ( ) const

◆ GetStaticUniformBufferSlot()

FUniformBufferStaticSlot FInstanceCullingContext::GetStaticUniformBufferSlot ( EShaderPlatform  ShaderPlatform)
static

◆ HasCullingCommands()

bool FInstanceCullingContext::HasCullingCommands ( ) const

Returns true if there are any instances in this context needing to be rendered. Must not be called before WaitForSetupTask if BeginAsyncSetup was called.

◆ IsEnabled()

bool FInstanceCullingContext::IsEnabled ( ) const
inline

◆ IsGPUCullingEnabled()

bool FInstanceCullingContext::IsGPUCullingEnabled ( )
static

◆ IsInstanceOrderPreservationEnabled()

bool FInstanceCullingContext::IsInstanceOrderPreservationEnabled ( ) const

◆ IsOcclusionCullingEnabled()

bool FInstanceCullingContext::IsOcclusionCullingEnabled ( )
static

◆ ResetCommands()

void FInstanceCullingContext::ResetCommands ( int32  MaxNumCommands)

Call to empty out the culling commands & other culling data.

◆ SetDeferredContextCullingParams()

void FInstanceCullingContext::SetDeferredContextCullingParams ( const FInstanceCullingDeferredContext DeferredContext,
FInstanceCullingDrawParams Parameters 
)
static

◆ SetDynamicPrimitiveInstanceOffsets()

void FInstanceCullingContext::SetDynamicPrimitiveInstanceOffsets ( int32  InDynamicInstanceIdOffset,
int32  InDynamicInstanceIdNum 
)

◆ SetupDrawCommands()

void FInstanceCullingContext::SetupDrawCommands ( FMeshCommandOneFrameArray VisibleMeshDrawCommandsInOut,
bool  bInCompactIdenticalCommands,
const FScene Scene,
int32 MaxInstances,
int32 VisibleMeshDrawCommandsNum,
int32 NewPassVisibleMeshDrawCommandsNum 
)

Allocate indirect arg slots for all meshes to use instancing, add commands that populate the indirect calls and index & id buffers, and Collapse all commands that share the same state bucket ID NOTE: VisibleMeshDrawCommandsInOut can only become shorter.

◆ StepInstanceDataOffsetBytes()

uint32 FInstanceCullingContext::StepInstanceDataOffsetBytes ( uint32  NumStepDraws) const

◆ SubmitDrawCommands()

void FInstanceCullingContext::SubmitDrawCommands ( const FMeshCommandOneFrameArray VisibleMeshDrawCommands,
const FGraphicsMinimalPipelineStateSet GraphicsMinimalPipelineStateSet,
const FMeshDrawCommandOverrideArgs OverrideArgs,
int32  StartIndex,
int32  NumMeshDrawCommands,
uint32  InstanceFactor,
FRHICommandList RHICmdList 
) const

◆ WaitForSetupTask()

void FInstanceCullingContext::WaitForSetupTask ( )

Calls the sync function passed tp BeginAsyncSetup to ensure the setup processing is completed.

Member Data Documentation

◆ bIsEnabled

bool FInstanceCullingContext::bIsEnabled = false

◆ bUsesUniformBufferView

bool FInstanceCullingContext::bUsesUniformBufferView

◆ CompactionBlockDataIndices

TArray<uint32, SceneRenderingAllocator> FInstanceCullingContext::CompactionBlockDataIndices

◆ CompactionBlockNumInstances

constexpr uint32 FInstanceCullingContext::CompactionBlockNumInstances = 64
staticconstexpr

◆ DrawCommandCompactionData

TArray<FCompactionData, SceneRenderingAllocator> FInstanceCullingContext::DrawCommandCompactionData

◆ DrawCommandDescs

TArray<FUintVector2, SceneRenderingAllocator> FInstanceCullingContext::DrawCommandDescs

◆ DynamicInstanceIdNum

int32 FInstanceCullingContext::DynamicInstanceIdNum = -1

◆ DynamicInstanceIdOffset

int32 FInstanceCullingContext::DynamicInstanceIdOffset = -1

◆ Flags

EInstanceCullingFlags FInstanceCullingContext::Flags = EInstanceCullingFlags::None

◆ IndirectArgs

TArray<FRHIDrawIndexedIndirectParameters, SceneRenderingAllocator> FInstanceCullingContext::IndirectArgs

◆ IndirectArgsNumWords

constexpr uint32 FInstanceCullingContext::IndirectArgsNumWords = 5
staticconstexpr

◆ InstanceCullingManager

FInstanceCullingManager* FInstanceCullingContext::InstanceCullingManager = nullptr

◆ InstanceCullingMode

EInstanceCullingMode FInstanceCullingContext::InstanceCullingMode = EInstanceCullingMode::Normal

◆ InstanceCullingStaticSlot

FUniformBufferStaticSlot FInstanceCullingContext::InstanceCullingStaticSlot

◆ InstanceIdOffsets

TArray<uint32, SceneRenderingAllocator> FInstanceCullingContext::InstanceIdOffsets

◆ LoadBalancers

LoadBalancerArray FInstanceCullingContext::LoadBalancers = LoadBalancerArray(InPlace, nullptr)

◆ MeshDrawCommandInfos

TArray<FMeshDrawCommandInfo, SceneRenderingAllocator> FInstanceCullingContext::MeshDrawCommandInfos

◆ NumCompactionInstances

uint32 FInstanceCullingContext::NumCompactionInstances = 0U

◆ PayloadData

TArray<FPayloadData, SceneRenderingAllocator> FInstanceCullingContext::PayloadData

◆ PrevHZB

TRefCountPtr<IPooledRenderTarget> FInstanceCullingContext::PrevHZB = nullptr

◆ ShaderPlatform

EShaderPlatform FInstanceCullingContext::ShaderPlatform = SP_NumPlatforms

◆ SingleInstanceProcessingMode

EBatchProcessingMode FInstanceCullingContext::SingleInstanceProcessingMode = EBatchProcessingMode::UnCulled

◆ SyncPrerequisitesFunc

SyncPrerequisitesFuncType FInstanceCullingContext::SyncPrerequisitesFunc

◆ TotalInstances

uint32 FInstanceCullingContext::TotalInstances = 0U

◆ UniformViewInstanceStride

constexpr uint32 FInstanceCullingContext::UniformViewInstanceStride[2]
staticconstexpr
Initial value:
=
{
}
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127

◆ ViewIds

TArray<int32, TInlineAllocator<6, SceneRenderingAllocator> > FInstanceCullingContext::ViewIds

The documentation for this class was generated from the following files: