[PR #7034] [MERGED] Flat draws: translucent quads from the translucent arena, a call per page #7282

Closed
opened 2026-11-03 06:37:05 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/7034
Author: @ludovic111
Created: 11/2/2026
Status: ✅ Merged
Merged: 11/2/2026
Merged by: @ludovic111

Base: main ← Head: perf/flat-translucent-arena


📝 Commits (1)

  • b0f9532 Flat draws: translucent quads from the translucent arena, a call per page

📊 Changes

3 files changed (+310 additions, -87 deletions)

View changed files

📝 crates/horizon-client-render/src/gfx.rs (+104 -62)
📝 crates/horizon-client-render/src/gfx/arena.rs (+131 -13)
📝 crates/horizon-client-render/src/gfx/flat.rs (+75 -12)

📄 Description

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

What and why

Closes #6883.

Frames drawn flat (gfx/flat.rs: Metal from render distance 32, Intel Gen11/Gen12 on Vulkan) drew translucent sections back to front from the section arena. Consecutive sections sit in different pages there, so nearly every translucent section was a call of its own, each with a vertex buffer, a bind group and a draw_indexed for the render thread to encode. At RD 32 on an M4 Pro that was 125-565 calls a frame, against 30-100 for all of phase 1's solid terrain.

Translucent Batching's arena (#5984-#6455) keeps translucent quads in one or two large pages, but it was left out of devices that draw flat, as flat draws read translucent quads in the section arena. Now flat draws read them from it:

  • Offered there too. Translucent Batching is offered wherever indirect multi-draws are (still not on OpenGL).
  • Tables per arena. Flat's block tables (section id per 256-vertex block) are keyed by page key: a section arena page, or a translucent arena page plus TRANSLUCENT_KEYS, with tables sized for the large pages. A section's id names both of its ranges.
  • Moves keep the id. Compaction, and now the translucent arena's shrink (#6337), keep the id, so a moved range still finds its section's origin.
  • Partial binding. Flat draws bind a translucent page up to its last range in use, as per-section draws do (#6181).
  • Sorted indices. With flat draws, the sorted indices keep the pages flat draws bind as storage, whether split or not.
  • Pack frames unchanged. Frames whose shader pack draws terrain or a shadow pass keep the section arena (translucent_split, unchanged).

Same picture: the back-to-front order is kept; only the vertex buffer the indices point into changes.

Measured

Mac mini M4 Pro, Metal, 1280x720, perf_bench scenes (fixed camera paths), rc_ab pairs: base = 78383948d2, this branch on it; runs alternate A/B, medians over runs. The machine was shared (load 17-38 at RD 32), so single runs swing by ~0.2 ms; every RD 32 scene is lower in both runs.

RD 32 (flat draws), 2 runs each:

scene main thread ms/frame render phase ms p50 ms p99 ms FPS 1 % low FPS
village 1.86 → 1.69 (−9 %) 1.31 → 1.17 2.71 → 2.58 4.81 → 4.47 358 → 373 192 → 213
forest 2.08 → 1.72 (−17 %) 1.44 → 1.17 5.87 → 5.22 8.79 → 7.64 166 → 187 112 → 123
ocean 2.15 → 1.72 (−20 %) 1.61 → 1.23 4.38 → 3.91 6.97 → 5.97 218 → 247 120 → 154
mountain 2.79 → 2.55 (−9 %) 1.79 → 1.63 5.80 → 4.69 9.53 → 7.48 170 → 204 100 → 113

RD 16 (no flat draws: Translucent Batching is now also on for Metal here), 3 runs each:

scene main thread ms/frame render phase ms p50 ms p99 ms FPS 1 % low FPS
village 1.04 → 1.01 0.66 → 0.64 1.59 → 1.59 3.34 → 2.96 590 → 612 282 → 318
forest 1.07 → 1.04 0.70 → 0.68 2.72 → 2.81 4.48 → 4.60 356 → 345 198 → 199
ocean 1.03 → 0.98 0.71 → 0.68 2.19 → 2.19 3.92 → 3.84 439 → 440 229 → 234
mountain 1.29 → 1.23 0.85 → 0.81 2.53 → 2.49 4.34 → 4.24 382 → 389 212 → 212

Where it comes from (RD 32, a local build with frame spans and call counts, medians of 500-frame windows): translucent flat calls 125-565 → 1 a frame; the renderer's span 1.09 → 0.89 ms and encoder.finish 0.35 → 0.26 ms in the cleaner of two pairs.

Same picture: screenshots of 6 fixed views at RD 32 and 16 (ticks frozen, shot mid animation frame). Five match base within base-vs-base noise. The ocean view differs by ±1-3 on a few % of water pixels, but so does the same build shot twice (4.6 %, max 50) and base at 60 FPS (4.8 %, max 50): run-to-run noise, not this change.

Tests

  • arena::tests::moved_translucent_quads_keep_their_section_s_flat_id builds a real Flat on a device and moves a section's translucent quads off a closing page (move_off_page, as the shrink does). Every block of the new range must still name the section's id, while the section arena's table and another section's blocks are unchanged.
    • Without the moved range keeping its key (to.0 + TRANSLUCENT_KEYS), it fails.
  • translucent_arenas_follow_the_layout now expects storage-bindable index pages wherever flat draws exist.
  • The batching offer test now includes Metal.

GPU tests run on Metal (Mac mini) and Vulkan (lavapipe); they skip on CI without an adapter. The mutation above was checked on lavapipe: the test fails.

Kind

  • perf: faster, or less memory

Vanilla reference

Horizon-only: draw-call grouping. The picture stays vanilla's.

Other projects' code

none

Self-check

pr_ready (tools/pr_ready.py --quick on playhorizon, against origin/main at 78383948d, 2 min 5 s)

Check Result
Scope ✅ 3 files, +310 −87
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ❌ 610 run, FAILED (failures=1, skipped=1) (55 s)
rustfmt ✅ (13 s)
clippy ✅ (43 s)
tests: horizon-client-render ❌ failed (12 s)
doc tests ✅ 0 passed (2 s)
content root tests ➖ content root untouched
mod API up to date ➖ native hooks untouched
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ not run (--quick): CI's parity job picks the affected harnesses
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)
  • Python tests: tests/test_world_input_capture.py (a native-mouse snippet that names input_trace) fails the same at the base 78383948d2; this branch touches no game code.
  • tests: horizon-client-render: the test binary dies with SIGSEGV in a render test on playhorizon's software GPU (lavapipe), as on other branches. The GPU tests of this change pass there when run alone (gfx::arena gfx::flat gfx::tests::translucent: 25 passed, Vulkan), and the crate's lib tests pass on Metal but entity_skin, which fails on main too.

🤖 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/7034 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 11/2/2026 **Status:** ✅ Merged **Merged:** 11/2/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/flat-translucent-arena` --- ### 📝 Commits (1) - [`b0f9532`](https://github.com/horizon-rust/horizon/commit/b0f9532aa8f5fdb6c58c116017b7acf78ff973e0) Flat draws: translucent quads from the translucent arena, a call per page ### 📊 Changes **3 files changed** (+310 additions, -87 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/gfx.rs` (+104 -62) 📝 `crates/horizon-client-render/src/gfx/arena.rs` (+131 -13) 📝 `crates/horizon-client-render/src/gfx/flat.rs` (+75 -12) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. ## What and why Closes #6883. Frames drawn flat (`gfx/flat.rs`: Metal from render distance 32, Intel Gen11/Gen12 on Vulkan) drew translucent sections back to front from the section arena. Consecutive sections sit in different pages there, so nearly every translucent section was a call of its own, each with a vertex buffer, a bind group and a `draw_indexed` for the render thread to encode. At RD 32 on an M4 Pro that was 125-565 calls a frame, against 30-100 for all of phase 1's solid terrain. Translucent Batching's arena (#5984-#6455) keeps translucent quads in one or two large pages, but it was left out of devices that draw flat, as flat draws read translucent quads in the section arena. Now flat draws read them from it: - **Offered there too.** Translucent Batching is offered wherever indirect multi-draws are (still not on OpenGL). - **Tables per arena.** Flat's block tables (section id per 256-vertex block) are keyed by page key: a section arena page, or a translucent arena page plus `TRANSLUCENT_KEYS`, with tables sized for the large pages. A section's id names both of its ranges. - **Moves keep the id.** Compaction, and now the translucent arena's shrink (#6337), keep the id, so a moved range still finds its section's origin. - **Partial binding.** Flat draws bind a translucent page up to its last range in use, as per-section draws do (#6181). - **Sorted indices.** With flat draws, the sorted indices keep the pages flat draws bind as storage, whether split or not. - **Pack frames unchanged.** Frames whose shader pack draws terrain or a shadow pass keep the section arena (`translucent_split`, unchanged). **Same picture:** the back-to-front order is kept; only the vertex buffer the indices point into changes. ## Measured Mac mini M4 Pro, Metal, 1280x720, `perf_bench` scenes (fixed camera paths), `rc_ab` pairs: base = 78383948d2, this branch on it; runs alternate A/B, medians over runs. The machine was shared (load 17-38 at RD 32), so single runs swing by ~0.2 ms; every RD 32 scene is lower in both runs. **RD 32 (flat draws), 2 runs each:** | scene | main thread ms/frame | render phase ms | p50 ms | p99 ms | FPS | 1 % low FPS | |---|---|---|---|---|---|---| | village | 1.86 → 1.69 (−9 %) | 1.31 → 1.17 | 2.71 → 2.58 | 4.81 → 4.47 | 358 → 373 | 192 → 213 | | forest | 2.08 → 1.72 (−17 %) | 1.44 → 1.17 | 5.87 → 5.22 | 8.79 → 7.64 | 166 → 187 | 112 → 123 | | ocean | 2.15 → 1.72 (−20 %) | 1.61 → 1.23 | 4.38 → 3.91 | 6.97 → 5.97 | 218 → 247 | 120 → 154 | | mountain | 2.79 → 2.55 (−9 %) | 1.79 → 1.63 | 5.80 → 4.69 | 9.53 → 7.48 | 170 → 204 | 100 → 113 | **RD 16 (no flat draws: Translucent Batching is now also on for Metal here), 3 runs each:** | scene | main thread ms/frame | render phase ms | p50 ms | p99 ms | FPS | 1 % low FPS | |---|---|---|---|---|---|---| | village | 1.04 → 1.01 | 0.66 → 0.64 | 1.59 → 1.59 | 3.34 → 2.96 | 590 → 612 | 282 → 318 | | forest | 1.07 → 1.04 | 0.70 → 0.68 | 2.72 → 2.81 | 4.48 → 4.60 | 356 → 345 | 198 → 199 | | ocean | 1.03 → 0.98 | 0.71 → 0.68 | 2.19 → 2.19 | 3.92 → 3.84 | 439 → 440 | 229 → 234 | | mountain | 1.29 → 1.23 | 0.85 → 0.81 | 2.53 → 2.49 | 4.34 → 4.24 | 382 → 389 | 212 → 212 | **Where it comes from** (RD 32, a local build with frame spans and call counts, medians of 500-frame windows): translucent flat calls 125-565 → 1 a frame; the renderer's span 1.09 → 0.89 ms and `encoder.finish` 0.35 → 0.26 ms in the cleaner of two pairs. **Same picture:** screenshots of 6 fixed views at RD 32 and 16 (ticks frozen, shot mid animation frame). Five match base within base-vs-base noise. The ocean view differs by ±1-3 on a few % of water pixels, but so does the same build shot twice (4.6 %, max 50) and base at 60 FPS (4.8 %, max 50): run-to-run noise, not this change. ## Tests - `arena::tests::moved_translucent_quads_keep_their_section_s_flat_id` builds a real `Flat` on a device and moves a section's translucent quads off a closing page (`move_off_page`, as the shrink does). Every block of the new range must still name the section's id, while the section arena's table and another section's blocks are unchanged. - Without the moved range keeping its key (`to.0 + TRANSLUCENT_KEYS`), it fails. - `translucent_arenas_follow_the_layout` now expects storage-bindable index pages wherever flat draws exist. - The batching offer test now includes Metal. GPU tests run on Metal (Mac mini) and Vulkan (lavapipe); they skip on CI without an adapter. The mutation above was checked on lavapipe: the test fails. ## Kind - [x] perf: faster, or less memory ## Vanilla reference Horizon-only: draw-call grouping. The picture stays vanilla's. ## Other projects' code none ## Self-check **pr_ready** (`tools/pr_ready.py --quick` on playhorizon, against origin/main at 78383948d, 2 min 5 s) | Check | Result | | --- | --- | | Scope | ✅ 3 files, +310 −87 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ❌ 610 run, FAILED (failures=1, skipped=1) (55 s) | | rustfmt | ✅ (13 s) | | clippy | ✅ (43 s) | | tests: horizon-client-render | ❌ failed (12 s) | | doc tests | ✅ 0 passed (2 s) | | content root tests | ➖ content root untouched | | mod API up to date | ➖ native hooks untouched | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ not run (--quick): CI's parity job picks the affected harnesses | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | - Python tests: `tests/test_world_input_capture.py` (a native-mouse snippet that names `input_trace`) fails the same at the base 78383948d2; this branch touches no game code. - tests: horizon-client-render: the test binary dies with SIGSEGV in a render test on playhorizon's software GPU (lavapipe), as on other branches. The GPU tests of this change pass there when run alone (`gfx::arena gfx::flat gfx::tests::translucent`: 25 passed, Vulkan), and the crate's lib tests pass on Metal but `entity_skin`, which fails on main too. 🤖 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-03 06:37:05 +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#7282
No description provided.