[PR #834] [MERGED] Upload section meshes through a reused staging belt #2845

Closed
opened 2026-11-02 15:59:31 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/834
Author: @ludovic111
Created: 10/18/2026
Status: ✅ Merged
Merged: 10/18/2026
Merged by: @ludovic111

Base: main ← Head: perf/section-upload-belt


📝 Commits (1)

  • 8901a49 Upload section meshes through a reused staging belt

📊 Changes

4 files changed (+141 additions, -33 deletions)

View changed files

📝 crates/horizon-client/src/gfx.rs (+63 -8)
📝 crates/horizon-client/src/gfx/arena.rs (+63 -21)
📝 crates/horizon-client/src/gfx/flat.rs (+9 -3)
📝 crates/horizon-client/src/gfx/upload.rs (+6 -1)

📄 Description

🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself.

The cost

While exploring at render distance 32, the render thread uploads every newly meshed section with Queue::write_buffer: two calls per section (solid and translucent vertices) plus one for its flat-draw ids. In wgpu each call creates a staging buffer. On Metal that is a kernel call (IOGPUResourceCreate) per write, then page faults while the mesh is copied into the fresh memory, and the next queue.submit has to process every one of those buffers.

A sample profile of the render thread while flying through new terrain at RD 32 (Mac mini, main) put 16% of the thread in Renderer::upload: half in memmove into new staging memory, most of the rest in StagingBuffer::new → -[AGXBuffer init…] → mach_msg.

The change

Vanilla 26.3 copies compiled sections into one persistent staging buffer and records the GPU copies in one command encoder (SectionRenderDispatcher.uploadTerrainBuffersToGpu). Horizon now does the same:

  • Section meshes and flat ids go through their own StagingBelt (4 MiB mapped buffers, handed back for reuse once the GPU has read them) into one "Section uploads" encoder.
  • The frame's submission runs that encoder ahead of its own commands, in the same queue.submit, so the frame draws what it wrote, as before.
  • A page of the section arena that grows records its copy into the same encoder (it used to submit its own), so copies recorded before the grow land in the grown buffer. A test covers that case.
  • A frame that is not drawn still submits the copies, and more than 64 MiB of staged copies are submitted early, which bounds the staging memory.

The bytes and their destinations are unchanged.

Performance

Mac mini M4 Pro (Metal), offscreen 1280×720, seed 1234, spectator flight at 16 blocks/s through fresh terrain from (-960, 125, 80), RD 32, Fancy. The machine was shared with other sessions, so the comparison is paired in one game: a local-only switch (not in this PR) alternated between the queue writes (main) and the belt, in ABBA order over 3 s flight segments. "Better" counts the pairs where the belt won.

RD 32, exploring (12 pairs) main this PR better in
avg FPS 43.5 56.0 8/12
1% low FPS 7.9 9.1 8/12
frame p99 (ms) 122.1 105.9 8/12
CPU ms/frame 23.7 18.6 9/12
update phase (ms) 5.55 3.65 10/12
render phase (ms) 10.03 7.78 10/12
upload span (ms/frame) 2.11 0.49
submit span (ms/frame) 4.43 2.65
GPU ms/frame 1.76 1.54 8/12

About 70 MB/s of section meshes were uploaded in both modes (~2,000 meshes/s).

ThinkPad (Intel HD 620, Vulkan through Mesa, RD 16, same paired method, 8 pairs): neutral. Uploads there are 5–20 MB/s and write_buffer was already cheap on Vulkan (upload span 0.02 → 0.01 ms/frame; FPS, CPU and GPU time within noise).

Picture

Same game (ticks frozen, HUD hidden), 6 views at RD 16 and RD 32. For each view: switch to main's uploads, reload all chunks (F3+A), wait for meshing to finish, capture; the same with the belt; then main's uploads again (the noise floor).

  • Drawn section counts are identical in all 12 views (for example 4,045, 3,837 and 5,932 at RD 32).
  • RD 16 mountain (no water in view): 0 pixels differ. Every other difference is on water surfaces, which animate between captures even with ticks frozen, and is within the noise floor:
changed pixels RD 16 main vs PR RD 16 main vs main RD 32 main vs PR RD 32 main vs main
village 10,316 11,816 7,901 11,760
village-n 3,170 3,125 3,513 3,512
forest 18,263 7,567 7,188 8,591
ocean 433,813 373,789 282,726 455,742
mountain 0 0 91 54
down (ocean below) 801,200 683,056 534,706 553,244

(The RD 16 forest mask is only the river.)

Self-check

Run on one integration commit of both PRs (#834 and #835 merged onto origin/main d85a3603):

  • cargo fmt --all --check: ok
  • cargo clippy --workspace --all-targets -- -D warnings: ok
  • cargo test -p horizon-client --lib: 861 passed
  • cargo test -p horizon-world --lib: 102 passed
  • Harnesses that cover these files, on that commit (Mac mini): section_mesh, translucency, weather_render, world_border_render, decoration: 5 of 5 pass.
  • tools/parity.py --changed origin/main (Mac mini), on an earlier integration of the same changes: 293 of 294 harnesses pass. tooltip_display fails the same way on plain origin/main: the harness writes Python's False and the fixture parses it as a Rust bool (ParseBoolError).
  • New test gfx::arena::tests::writes_recorded_before_a_grow_reach_the_grown_page; gfx:: tests pass.

Needs Ludovic

Nothing.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/834 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/18/2026 **Status:** ✅ Merged **Merged:** 10/18/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/section-upload-belt` --- ### 📝 Commits (1) - [`8901a49`](https://github.com/horizon-rust/horizon/commit/8901a49d0b914f7812c4c1be204596f681d16593) Upload section meshes through a reused staging belt ### 📊 Changes **4 files changed** (+141 additions, -33 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/gfx.rs` (+63 -8) 📝 `crates/horizon-client/src/gfx/arena.rs` (+63 -21) 📝 `crates/horizon-client/src/gfx/flat.rs` (+9 -3) 📝 `crates/horizon-client/src/gfx/upload.rs` (+6 -1) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. ## The cost While exploring at render distance 32, the render thread uploads every newly meshed section with `Queue::write_buffer`: two calls per section (solid and translucent vertices) plus one for its flat-draw ids. In wgpu each call creates a staging buffer. On Metal that is a kernel call (`IOGPUResourceCreate`) per write, then page faults while the mesh is copied into the fresh memory, and the next `queue.submit` has to process every one of those buffers. A `sample` profile of the render thread while flying through new terrain at RD 32 (Mac mini, main) put 16% of the thread in `Renderer::upload`: half in `memmove` into new staging memory, most of the rest in `StagingBuffer::new` → `-[AGXBuffer init…]` → `mach_msg`. ## The change Vanilla 26.3 copies compiled sections into one persistent staging buffer and records the GPU copies in one command encoder (`SectionRenderDispatcher.uploadTerrainBuffersToGpu`). Horizon now does the same: - Section meshes and flat ids go through their own `StagingBelt` (4 MiB mapped buffers, handed back for reuse once the GPU has read them) into one "Section uploads" encoder. - The frame's submission runs that encoder ahead of its own commands, in the same `queue.submit`, so the frame draws what it wrote, as before. - A page of the section arena that grows records its copy into the same encoder (it used to submit its own), so copies recorded before the grow land in the grown buffer. A test covers that case. - A frame that is not drawn still submits the copies, and more than 64 MiB of staged copies are submitted early, which bounds the staging memory. The bytes and their destinations are unchanged. ## Performance Mac mini M4 Pro (Metal), offscreen 1280×720, seed 1234, spectator flight at 16 blocks/s through fresh terrain from (-960, 125, 80), RD 32, Fancy. The machine was shared with other sessions, so the comparison is paired in one game: a local-only switch (not in this PR) alternated between the queue writes (main) and the belt, in ABBA order over 3 s flight segments. "Better" counts the pairs where the belt won. | RD 32, exploring (12 pairs) | main | this PR | better in | | --- | --- | --- | --- | | avg FPS | 43.5 | 56.0 | 8/12 | | 1% low FPS | 7.9 | 9.1 | 8/12 | | frame p99 (ms) | 122.1 | 105.9 | 8/12 | | CPU ms/frame | 23.7 | 18.6 | 9/12 | | update phase (ms) | 5.55 | 3.65 | 10/12 | | render phase (ms) | 10.03 | 7.78 | 10/12 | | `upload` span (ms/frame) | 2.11 | 0.49 | | | `submit` span (ms/frame) | 4.43 | 2.65 | | | GPU ms/frame | 1.76 | 1.54 | 8/12 | About 70 MB/s of section meshes were uploaded in both modes (~2,000 meshes/s). ThinkPad (Intel HD 620, Vulkan through Mesa, RD 16, same paired method, 8 pairs): neutral. Uploads there are 5–20 MB/s and `write_buffer` was already cheap on Vulkan (`upload` span 0.02 → 0.01 ms/frame; FPS, CPU and GPU time within noise). ## Picture Same game (ticks frozen, HUD hidden), 6 views at RD 16 and RD 32. For each view: switch to main's uploads, reload all chunks (F3+A), wait for meshing to finish, capture; the same with the belt; then main's uploads again (the noise floor). - Drawn section counts are identical in all 12 views (for example 4,045, 3,837 and 5,932 at RD 32). - RD 16 mountain (no water in view): 0 pixels differ. Every other difference is on water surfaces, which animate between captures even with ticks frozen, and is within the noise floor: | changed pixels | RD 16 main vs PR | RD 16 main vs main | RD 32 main vs PR | RD 32 main vs main | | --- | --- | --- | --- | --- | | village | 10,316 | 11,816 | 7,901 | 11,760 | | village-n | 3,170 | 3,125 | 3,513 | 3,512 | | forest | 18,263 | 7,567 | 7,188 | 8,591 | | ocean | 433,813 | 373,789 | 282,726 | 455,742 | | mountain | 0 | 0 | 91 | 54 | | down (ocean below) | 801,200 | 683,056 | 534,706 | 553,244 | (The RD 16 forest mask is only the river.) ## Self-check Run on one integration commit of both PRs (#834 and #835 merged onto origin/main `d85a3603`): - `cargo fmt --all --check`: ok - `cargo clippy --workspace --all-targets -- -D warnings`: ok - `cargo test -p horizon-client --lib`: 861 passed - `cargo test -p horizon-world --lib`: 102 passed - Harnesses that cover these files, on that commit (Mac mini): section_mesh, translucency, weather_render, world_border_render, decoration: 5 of 5 pass. - `tools/parity.py --changed origin/main` (Mac mini), on an earlier integration of the same changes: 293 of 294 harnesses pass. `tooltip_display` fails the same way on plain origin/main: the harness writes Python's `False` and the fixture parses it as a Rust `bool` (`ParseBoolError`). - New test `gfx::arena::tests::writes_recorded_before_a_grow_reach_the_grown_page`; `gfx::` tests pass. ## Needs Ludovic Nothing. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 15:59:31 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#2845
No description provided.