Skip to content

Cull meshes before the render snapshot's blend and matrix work #250

Open

Description

@BenjaFriend

Follow-up to #249 (frame-side frustum culling).

Problem

#249 culls in the G-buffer pass (OffscreenSubpass::Draw), so a mesh outside the view skips its draw and its uniform buffer write. The per-mesh frame work before that still runs for every mesh, visible or not:

  • Graphics.PublishSnapshot (PublishSnapshotSystem) blends each Transform up the parent chain (Interpolate::BlendedWorld: lerp, slerp and a matrix per parent) and writes a MeshDrawItem for every mesh.
  • The proxy sync in OffscreenSubpass walks every snapshot item.

In Level_1, 591 of 756 meshes are culled each frame, yet all 756 are blended and written into the snapshot.

This is not new in #249: before it, every mesh was blended and drawn. #249 just doesn't reduce this part.

Root cause

The renderer's camera (FirstPersonCamera) is only final in VulkanApp::Update, after the frame systems (Order::Frame, Order::Render) have run. PublishSnapshotSystem can't cull against it: the previous frame's camera would not be conservative and could hide a mesh that is on screen.

Proposed fix

  1. Settle the camera before the frame systems run: move the debug/first-person camera update into a frame system that writes CameraView (or a new Presentation singleton with the final view-projection), ordered before Graphics.PublishSnapshot.
  2. In PublishSnapshotSystem, test each mesh's world bounds against that frustum before the blend. Skip the blend and the snapshot entry for culled meshes, or mark them culled.
    • It needs a cheap conservative bound before the blend, for example the union of the bounds at BlendFrom and BlendTo.
    • Bounds would need to be reachable from the frame side, for example a Presentation component or a lookup from the mesh path.
  3. Keep the culling in the G-buffer pass as the exact test, or remove it if the snapshot test is exact.

Watch out for:

  • Proxy churn: a mesh leaving the snapshot frees its proxy and GPU resources. Prefer a "culled" flag on MeshDrawItem over dropping the entry.
  • Point-light gizmos and any future shadow pass need the casters outside the view.

Out of scope

The publish copy from the game thread to the main thread (TickPacket) is separate. Change tracking / delta packets are the fix for that, not camera culling.

Done when

  • Culled meshes do no blend or matrix work in PublishSnapshotSystem (shown by a test, e.g. a counter or an instrumented run).
  • Offscreen screenshots are byte-identical with culling on and off (Level_1, Levels/PhysicsTest.json).
  • GraphicsTests "[culling]" and the full CTest suite pass.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions