[PR #520] [MERGED] Per-frame uploads through the staging belt; skip unchanged lightmaps #2620

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

📋 Pull Request Information

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

Base: main ← Head: perf/frame-uploads


📝 Commits (1)

  • baaa5e7 Per-frame uploads through the staging belt; skip unchanged lightmaps

📊 Changes

3 files changed (+146 additions, -38 deletions)

View changed files

📝 crates/horizon-client/src/gfx.rs (+77 -36)
📝 crates/horizon-client/src/gfx/upload.rs (+60 -0)
📝 crates/horizon-client/src/hud.rs (+9 -2)

📄 Description

What

Follow-up to #501. Renderer::render's per-frame buffer writes (the three globals uniforms, section origins and indirect draws, entity, cloud, celestial, border, outline, debug-line and screen-effect vertices) and the HUD's vertex and uniform writes now go through the frame's staging belt instead of Queue::write_buffer. The lightmap is uploaded only when its pixels change instead of every frame.

Why

Every Queue::write_buffer / write_texture call creates a new staging buffer, on Metal a kernel call (IOGPUResourceCreate), and the renderer made about 15 of them every frame plus the lightmap texture write. perf-ticks-1 measured the lightmap alone at about 4% of the main thread while nothing changed.

How

  • Uploads::buffer(encoder, target, offset, bytes): StagingBelt::write_buffer into the frame's encoder. The writes happen before the passes that read them, as before; empty writes are skipped.
  • update_lightmap compares the new 16x16 pixels with the last uploaded ones and records a belt copy only when they differ (the first frame always uploads).
  • HudRenderer::draw takes the Uploads for its two writes; its map/patch texture writes are unchanged.
  • Section mesh uploads (Renderer::upload, outside render) still use Queue::write_buffer: moving them needs the arena's page growth recorded in the same encoder, a separate change.

Measurements

Mac mini M4 Pro (Metal), 1280x720 offscreen, seed 1234 creative world, at the village path's end (-960 125 272, pitch 35), noon, render distance 16. The machine was shared with other agents' builds and harnesses (load 60-90), so frame times swung by 3x between identical runs; these are 6 s Time Profiler captures, base/new/base/new, as shares of the render thread:

Main-thread share main this PR main this PR
StagingBuffer::new (staging buffer creation) 7.6% 1.6% 6.8% 1.9%
IOGPUResourceCreate (its kernel call) 5.8% 1.1% 5.1% 1.4%
queue_write_buffer 9.4% 1.6% 8.7% 0.6%
queue_write_texture 3.7% 0.5% 3.6% 0.2%
StagingBelt::write_buffer (the replacement) - 0.4% - 0.4%
Renderer::render total 53.7% 44.0% 51.3% 50.0%

What remains of the staging-buffer creation is section mesh uploads.

Correctness

  • New GPU test belt_buffer_writes_land_in_order_at_their_offsets: overlapping belt writes over three frames read back as the queue's last-write-wins result; joins #501's texture test.
  • Screenshot of the village street with the branch build: terrain lighting, water, sky, clouds and HUD render normally. The lightmap is still uploaded whenever it changes (time of day, flicker, effects, gamma), since the comparison is on the computed pixels.
cargo fmt --all --check                                   ok
cargo clippy --workspace --all-targets -- -D warnings      ok
cargo test -p horizon-client --lib                        751 passed, 5 ignored
tools/parity.py --changed origin/main (84 harnesses)       84 passed, 0 failed

Needs from 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/520 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/16/2026 **Status:** ✅ Merged **Merged:** 10/16/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/frame-uploads` --- ### 📝 Commits (1) - [`baaa5e7`](https://github.com/horizon-rust/horizon/commit/baaa5e737413af9d0f729c1580903e1942ae9a07) Per-frame uploads through the staging belt; skip unchanged lightmaps ### 📊 Changes **3 files changed** (+146 additions, -38 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/gfx.rs` (+77 -36) 📝 `crates/horizon-client/src/gfx/upload.rs` (+60 -0) 📝 `crates/horizon-client/src/hud.rs` (+9 -2) </details> ### 📄 Description ## What Follow-up to #501. `Renderer::render`'s per-frame buffer writes (the three globals uniforms, section origins and indirect draws, entity, cloud, celestial, border, outline, debug-line and screen-effect vertices) and the HUD's vertex and uniform writes now go through the frame's staging belt instead of `Queue::write_buffer`. The lightmap is uploaded only when its pixels change instead of every frame. ## Why Every `Queue::write_buffer` / `write_texture` call creates a new staging buffer, on Metal a kernel call (`IOGPUResourceCreate`), and the renderer made about 15 of them every frame plus the lightmap texture write. perf-ticks-1 measured the lightmap alone at about 4% of the main thread while nothing changed. ## How - `Uploads::buffer(encoder, target, offset, bytes)`: `StagingBelt::write_buffer` into the frame's encoder. The writes happen before the passes that read them, as before; empty writes are skipped. - `update_lightmap` compares the new 16x16 pixels with the last uploaded ones and records a belt copy only when they differ (the first frame always uploads). - `HudRenderer::draw` takes the `Uploads` for its two writes; its map/patch texture writes are unchanged. - Section mesh uploads (`Renderer::upload`, outside `render`) still use `Queue::write_buffer`: moving them needs the arena's page growth recorded in the same encoder, a separate change. ## Measurements Mac mini M4 Pro (Metal), 1280x720 offscreen, seed 1234 creative world, at the village path's end (-960 125 272, pitch 35), noon, render distance 16. The machine was shared with other agents' builds and harnesses (load 60-90), so frame times swung by 3x between identical runs; these are 6 s Time Profiler captures, base/new/base/new, as shares of the render thread: | Main-thread share | main | this PR | main | this PR | | --- | --- | --- | --- | --- | | `StagingBuffer::new` (staging buffer creation) | 7.6% | 1.6% | 6.8% | 1.9% | | `IOGPUResourceCreate` (its kernel call) | 5.8% | 1.1% | 5.1% | 1.4% | | `queue_write_buffer` | 9.4% | 1.6% | 8.7% | 0.6% | | `queue_write_texture` | 3.7% | 0.5% | 3.6% | 0.2% | | `StagingBelt::write_buffer` (the replacement) | - | 0.4% | - | 0.4% | | `Renderer::render` total | 53.7% | 44.0% | 51.3% | 50.0% | What remains of the staging-buffer creation is section mesh uploads. ## Correctness - New GPU test `belt_buffer_writes_land_in_order_at_their_offsets`: overlapping belt writes over three frames read back as the queue's last-write-wins result; joins #501's texture test. - Screenshot of the village street with the branch build: terrain lighting, water, sky, clouds and HUD render normally. The lightmap is still uploaded whenever it changes (time of day, flicker, effects, gamma), since the comparison is on the computed pixels. ``` cargo fmt --all --check ok cargo clippy --workspace --all-targets -- -D warnings ok cargo test -p horizon-client --lib 751 passed, 5 ignored tools/parity.py --changed origin/main (84 harnesses) 84 passed, 0 failed ``` Needs from 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:57:41 +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#2620
No description provided.