[PR #905] [MERGED] Renderer: one command buffer per frame, uploads before the first pass #2900

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

📋 Pull Request Information

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

Base: main ← Head: perf/render-encode


📝 Commits (1)

  • aea18f2 Renderer: one command buffer per frame, uploads before the first pass

📊 Changes

3 files changed (+123 additions, -103 deletions)

View changed files

📝 crates/horizon-client/src/gfx.rs (+90 -75)
📝 crates/horizon-client/src/gfx/upload.rs (+3 -1)
📝 crates/horizon-client/src/hud.rs (+30 -27)

📄 Description

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

What

The frame now goes to the GPU as one command buffer, and every upload is recorded before the frame's first pass:

  • The frame records its commands into the section-copies encoder (when meshes arrived since the last frame) instead of submitting that encoder as a command buffer of its own.
  • The HUD's fire animation and glyph patches go through the frame's staging belt instead of Queue::write_texture, which made a staging buffer per write and a separate pending-writes command buffer.
  • The screen-effect vertices, the HUD's vertices and uniform, the flatten pass's inputs and the indirect draws are staged before the first pass. HudRenderer::draw is split into prepare (uploads) and draw (the pass).

The passes, their draws and the draw order inside each pass are unchanged.

Why

wgpu-core ends its hal command buffer at every pass: each render or compute pass costs two (the pass and its pre-pass barriers), and each run of copies between passes one more. wgpu-hal's Metal backend creates and commits every one of them on its own. The frame made about 16–18. At render distance 32, queue.submit took 2–5 ms per frame on the Mac mini, most of it in -[_MTLCommandQueue enqueueCommandBuffer:] waiting for the command queue's lock (sample profile, exploring at RD32: submit 5.4 ms per frame, encode 3.0 ms). Encode and submit together were the biggest render-thread cost (perf-frame-5's profile).

Numbers (Mac mini M4 Pro, Metal)

Seed 1234 template world (no mobs), RD 32, 1280×720 offscreen, ticks frozen, HUD off, 260 FPS cap, VSync off, standing at the meadow view after streaming settles. 4 base/PR pairs in order main, PR, PR, main, PR, main, main, PR; fresh game each, 15 s each, with HORIZON_SPIKES=0 for the per-frame spans:

RD32 standing main this PR
average FPS 116.1 163.3 (+41%)
1% low FPS 10.1 14.0
CPU ms per frame 7.09 4.98
renderer span (ms/frame) 6.68 4.78
submit span 2.28 1.39
encode span (encoder.finish) 1.43 0.97
GPU ms (timestamps) 1.41 0.64

Every PR run beat every main run next to it. The GPU timestamps still bracket the same commands (a marker pass before the world pass, one after the HUD). The drop comes from fewer separately committed command buffers inside that window, i.e. less idle time between them, not from cheaper shaders.

A second set (meadow + overview, 4 pairs, no spans): 61.4 → 76.3 FPS, CPU 13.1 → 10.6 ms (the Mac mini was heavily loaded by other sessions, hence the lower absolute numbers). Exploring (flying 1,200 blocks at RD32): profile 46.7 → 67.3 FPS, submit 5.4 → 2.2 ms per frame. Paired exploring runs were too noisy on the shared machine to quote (main alone 74 and 38 FPS).

Screenshots

Static captures (animated textures off: the water's animation phase otherwise differs run to run), seed 1234, RD16, 1280×720, three fresh games: main, PR, main again for the noise floor.

view main vs PR px main vs main px PR diff outside main-vs-main areas
meadow 0 0 0
forest 98 95 0
slope 0 0 0
mountain 0 0 0
peak 0 0 0
overview 23 236 0
HUD meadow 0 0 0
HUD forest 75 79 0
creative inventory 0 0 0

How tested

cargo fmt --all --check                                         ok
cargo clippy --workspace --all-targets -- -D warnings           ok
cargo test -p horizon-client (lib + integration, .local)        ok (875 lib + integration suites)
tools/parity.py --changed origin/main (95 harnesses)            95 passed, 0 failed (incl. section_mesh, translucency, light, hud, cloud_render, environment_render, weather_render, world_border_render)

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/905 **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/render-encode` --- ### 📝 Commits (1) - [`aea18f2`](https://github.com/horizon-rust/horizon/commit/aea18f245f33cade3403133cde107c3d6be9a6bd) Renderer: one command buffer per frame, uploads before the first pass ### 📊 Changes **3 files changed** (+123 additions, -103 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/gfx.rs` (+90 -75) 📝 `crates/horizon-client/src/gfx/upload.rs` (+3 -1) 📝 `crates/horizon-client/src/hud.rs` (+30 -27) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. ## What The frame now goes to the GPU as one command buffer, and every upload is recorded before the frame's first pass: - The frame records its commands into the section-copies encoder (when meshes arrived since the last frame) instead of submitting that encoder as a command buffer of its own. - The HUD's fire animation and glyph patches go through the frame's staging belt instead of `Queue::write_texture`, which made a staging buffer per write and a separate pending-writes command buffer. - The screen-effect vertices, the HUD's vertices and uniform, the flatten pass's inputs and the indirect draws are staged before the first pass. `HudRenderer::draw` is split into `prepare` (uploads) and `draw` (the pass). The passes, their draws and the draw order inside each pass are unchanged. ## Why wgpu-core ends its hal command buffer at every pass: each render or compute pass costs two (the pass and its pre-pass barriers), and each run of copies between passes one more. wgpu-hal's Metal backend creates and commits every one of them on its own. The frame made about 16–18. At render distance 32, `queue.submit` took 2–5 ms per frame on the Mac mini, most of it in `-[_MTLCommandQueue enqueueCommandBuffer:]` waiting for the command queue's lock (`sample` profile, exploring at RD32: submit 5.4 ms per frame, encode 3.0 ms). Encode and submit together were the biggest render-thread cost (perf-frame-5's profile). ## Numbers (Mac mini M4 Pro, Metal) Seed 1234 template world (no mobs), RD 32, 1280×720 offscreen, ticks frozen, HUD off, 260 FPS cap, VSync off, standing at the meadow view after streaming settles. 4 base/PR pairs in order main, PR, PR, main, PR, main, main, PR; fresh game each, 15 s each, with `HORIZON_SPIKES=0` for the per-frame spans: | RD32 standing | main | this PR | | --- | ---: | ---: | | average FPS | 116.1 | **163.3** (+41%) | | 1% low FPS | 10.1 | **14.0** | | CPU ms per frame | 7.09 | **4.98** | | renderer span (ms/frame) | 6.68 | **4.78** | | submit span | 2.28 | **1.39** | | encode span (`encoder.finish`) | 1.43 | **0.97** | | GPU ms (timestamps) | 1.41 | **0.64** | Every PR run beat every main run next to it. The GPU timestamps still bracket the same commands (a marker pass before the world pass, one after the HUD). The drop comes from fewer separately committed command buffers inside that window, i.e. less idle time between them, not from cheaper shaders. A second set (meadow + overview, 4 pairs, no spans): 61.4 → 76.3 FPS, CPU 13.1 → 10.6 ms (the Mac mini was heavily loaded by other sessions, hence the lower absolute numbers). Exploring (flying 1,200 blocks at RD32): profile 46.7 → 67.3 FPS, submit 5.4 → 2.2 ms per frame. Paired exploring runs were too noisy on the shared machine to quote (main alone 74 and 38 FPS). ## Screenshots Static captures (animated textures off: the water's animation phase otherwise differs run to run), seed 1234, RD16, 1280×720, three fresh games: main, PR, main again for the noise floor. | view | main vs PR px | main vs main px | PR diff outside main-vs-main areas | | --- | ---: | ---: | ---: | | meadow | 0 | 0 | 0 | | forest | 98 | 95 | 0 | | slope | 0 | 0 | 0 | | mountain | 0 | 0 | 0 | | peak | 0 | 0 | 0 | | overview | 23 | 236 | 0 | | HUD meadow | 0 | 0 | 0 | | HUD forest | 75 | 79 | 0 | | creative inventory | 0 | 0 | 0 | ## How tested ``` cargo fmt --all --check ok cargo clippy --workspace --all-targets -- -D warnings ok cargo test -p horizon-client (lib + integration, .local) ok (875 lib + integration suites) tools/parity.py --changed origin/main (95 harnesses) 95 passed, 0 failed (incl. section_mesh, translucency, light, hud, cloud_render, environment_render, weather_render, world_border_render) ``` ## 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:56 +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#2900
No description provided.