Skip to content

Blend moving meshes on the GPU, in the occlusion culling pass - #258

Closed
BenjaFriend wants to merge 8 commits into
mainfrom
perf/gpu-blend
Closed

BenjaFriend wants to merge 8 commits into
mainfrom
perf/gpu-blend

Conversation

@BenjaFriend

Copy link
Copy Markdown
Member

Moving meshes are no longer blended on the CPU. The snapshot carries the two ends (From, To) and the frame's BlendAlpha; cull.comp makes the world matrix, tests the frustum, and the G-buffer vertex shader reads matrices from one storage buffer by slot. Design and measurements: Plans/gpu-blend.md.

Stacked on #257. This branch contains #257's commits (one-pass blend, direct LocalMatrix, PreCullView), so the diff against main shrinks when #257 merges. Merge #257 first.

  • --gpu-blend on|off (also [Engine] GpuBlend, and a checkbox in GPU Options). On by default. Needs occlusion culling; otherwise the CPU blends as before.
  • Children of a moving parent, and meshes far outside the last view, keep a CPU matrix.
  • Shader reflection now tells a storage buffer from a uniform buffer.

Testing

  • 693/693 tests pass.
  • GPU and CPU pictures at the same tick differ by at most 3/255 on about 1,700 of 2M pixels (float rounding). No validation layer messages, with and without occlusion culling.
  • Real window on a real GPU (RelWithDebInfo, 1080p, rotating spheres): 2.75 ms/frame on, 2.80 ms off. GPU-bound, so no fps change there. The CPU saving shows in Debug builds.
  • The only GPU to CPU readback is two stats counters (occluded, frustum-culled), read one frame late from mapped memory.

🤖 Generated with Claude Code

https://claude.ai/code/session_017NN37Q2jpV81xZaX3ocojK

BenjaFriend and others added 8 commits November 17, 2026 11:03
…meshes

Found with --profile: with the lighting test level's 3,136 rotating spheres,
Graphics.PublishSnapshot cost 6.4 ms a frame in a Debug build (1.6 ms still),
and FPS dropped by almost half.

- Interpolate::BlendedWorld walks the parent chain once and keeps the two ends,
  where it walked it twice. A chain deeper than 8 uses the old code
  (BlendedWorldDeep). A test holds the two to the same matrices at every depth
  around the limit.
- TransformUtil::LocalMatrix is written out: the same values as the three glm
  calls (a test checks it), without the matrix products.
- The renderer publishes the view it culled with (PreCullView), and
  PublishSnapshot draws the published LocalToWorld of a mesh far outside it
  instead of blending. The view is one frame old: a mesh that comes into view
  that frame is drawn at the latest tick's place for that frame.

Debug, rotating: PublishSnapshot 6.5 ms down to 1.8 ms. The simulation checksum
is the same.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017NN37Q2jpV81xZaX3ocojK
…e matrix

A mesh that moved between the two ticks and has no Parent goes into the
RenderSnapshot as its two Transform values (HasBlend, From, To) and the frame's
factor (BlendAlpha), instead of a matrix made on the CPU. The renderer resolves
it once a frame (OffscreenSubpass::ResolveWorlds, MeshDrawItem::ResolveWorld).
No picture change: this is the first step of blending on the GPU
(Plans/gpu-blend.md).

MeshCuller::Cull takes the resolved matrices.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017NN37Q2jpV81xZaX3ocojK
The cull compute shader makes the world matrix of each mesh that moves between
two ticks, from the two ends of its Transform and the frame's blend factor, and
tests it against the view volume (the CPU has no matrix for it). The G-buffer
vertex shader reads its matrix from one storage buffer, by slot; the per mesh
UBO holds only the slot. The CPU writes the matrix of a still mesh when its
LocalToWorld version changes.

- --gpu-blend on|off, [Engine] GpuBlend, a GPU Options checkbox. On by default;
  it needs occlusion culling, otherwise the CPU blends (as before).
- Shader reflection tells a storage buffer from a uniform buffer.
- OcclusionSlot has the two ends in place of the matrix.

GPU and CPU blend match to 3/255 on 1,697 of 2 million pixels at the same tick;
no validation layer messages. Plans/gpu-blend.md has the design and the numbers.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017NN37Q2jpV81xZaX3ocojK
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017NN37Q2jpV81xZaX3ocojK
@BenjaFriend

Copy link
Copy Markdown
Member Author

Folded into #257 (same branch now).

@BenjaFriend
BenjaFriend deleted the perf/gpu-blend branch November 17, 2026 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant