Skip to main content
Version: Next

Parallel Splitting of FrustumCull and ComputeRelevance in SceneVisibility

Visibility computation sits early in the rendering pipeline: it decides which primitives are worth carrying further this frame. Because the input is a set of static and dynamic primitives and the output is a per-view visible set, it is naturally parallelisable by slicing the data. Understanding the split is the precondition for analysing MeshPassProcessor behaviour and MeshDrawCommand caching later.

Exact function names and task granularity shift between engine versions. What follows describes a structure that is stable in the UE5 renderer; when implementing, follow SceneVisibility.cpp in your current version.

Inputs and outputs​

StageInputOutput
View preparationFSceneView / FViewInfoFrustum planes, culling matrices, occlusion query history
Frustum cullingPrimitive set + boundsPass / reject bit flags
Relevance computationPrimitives that survived cullingPer-view FPrimitiveSceneInfo visibility flags, static mesh batches
Downstream consumptionVisible setMeshPassProcessor generating MeshDrawCommands

The key point: neither culling nor relevance computation draws while iterating. Both write their verdicts into per-view flags or arrays, and later stages consume those results. This "write results first, consume later" structure is the root reason it can be parallelised.

Why it parallelises​

Testing one primitive against the frustum needs only the read-only bounds and frustum planes, and the verdict is written into that primitive's own slot. With no shared writes between tasks, the work can be sliced by index range and handed to the TaskGraph:

// Illustrative: slice by primitive range, write into per-index slots, no cross-task write conflicts
ParallelFor(Primitives.Num(), [&](int32 Index)
{
const FPrimitiveSceneInfo* Primitive = Primitives[Index];
const bool bVisible = ViewFrustum.IntersectBox(Primitive->Bounds.GetBox());
VisibilityFlags[Index] = bVisible ? 1 : 0;
});

ComputeRelevance is more involved: it folds per-primitive render properties (shadow casting, pass participation, LOD, material relevance) into view-scoped structures. In practice that is done with per-thread or per-task local buffers followed by a merge, to avoid concurrent appends into the same view array:

Task 0..N -> each writes LocalRelevant[...] -> gathered into View.Primitives

That is why reading the source shows a clear "parallel collect then serial merge" two-phase shape, rather than one lock guarding a global array.

Engineering impact of the split​

  1. Result order is not stable: a parallel merge does not preserve scene registration order. Any logic that depends on draw order (certain translucent or custom pass sorting) cannot assume the visible set is ordered; sort explicitly in the MeshPassProcessor.
  2. Cache keys must avoid order dependence: MeshDrawCommand cache hits rely on stable draw state. If the visible set shuffles every frame, reuse of static draw commands drops, showing up as increased render-thread cost rather than visual errors — the kind of problem screenshots never reveal.
  3. Culling-stage information must be complete: flags that FrustumCull could not compute or wrote incorrectly are treated as "invisible" by ComputeRelevance and never recovered later. When debugging, inspect VisibilityFlags first instead of diving straight into pass code.

Relationship to the render and RHI threads​

Visibility completes on the render thread, and the resulting commands are handed to the RHI thread for execution. The parallelism ceiling here is bounded by two things: dependencies on earlier render-thread work, and core count versus task granularity. Slice too finely and scheduling overhead eats the gain; slice too coarsely and long-tail tasks stall the frame. When analysing this, look at the task-duration distribution rather than the mean.

Suggested reading order​

Start with view initialisation and frustum plane construction, then follow the write slots in FrustumCull, then the local buffers and merge in ComputeRelevance, and only then enter the MeshPassProcessor. Skipping the first two steps and reading draw-command generation directly makes it easy to mistake visibility flags for pass filter conditions.