[PR #6500] [MERGED] Metal: each solid pass draws only its own quads #6915

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

📋 Pull Request Information

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

Base: main ← Head: perf/solid-pass-parts


📝 Commits (1)

  • de59ab9 Metal: each solid pass draws only its own quads

📊 Changes

6 files changed (+447 additions, -108 deletions)

View changed files

📝 crates/horizon-client-render/src/gfx.rs (+122 -59)
📝 crates/horizon-client-render/src/gfx/flat.rs (+63 -3)
📝 crates/horizon-client-render/src/gfx/page_runs.rs (+37 -2)
📝 crates/horizon-client-render/src/mesher.rs (+1 -1)
📝 crates/horizon-client-render/src/mesher/sides.rs (+220 -39)
📝 crates/horizon-client-render/src/terrain.wgsl (+4 -4)

📄 Description

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

Stacked on #6499 (it uses that PR's fade_code); GitHub retargets it to main when #6499 merges.

Why

#6005 draws opaque terrain through a shader that never discards, so Apple's GPUs keep their hidden surface removal. But it drew every solid list twice on Metal, once per pass, and each pass clipped the other pass's quads in the vertex shader. On the Mac mini (M4 Pro) at render distance 32 with far terrain 256, that cost +1.05 ms of GPU per frame against the build before it (4.43 → 5.51 ms). A diagnostic build showed where: the opaque pass alone took 3.2 ms, both passes 5.4 ms, and 97 % of the indices were in meshes holding both kinds of quads, so splitting by list could not help.

What it does

  • mesher::sides::sort keeps each bucket's opaque quads (OPAQUE_LAYER) and cutout quads apart, and Sides::visible_from / Sides::every draw one part (mesher::Part: All, Opaque, Cutout).
  • Where the renderer draws two solid passes (Metal, group_parts), meshes put all their opaque buckets first, so each part is one or two runs per mesh. Elsewhere each bucket holds its opaque quads then its cutout ones, so the single pass draws the same runs as before.
  • Phase 1 lists every section's and tile's opaque runs, then their cutout runs (PageRuns::push_in groups); a fading mesh goes whole to the cutout pass, as opaque_quad treats fading quads. The opaque pass draws [..opaque_end], the cutout pass [cutout_start..phase 1]; phase 2 and the mirror still draw everything. flat::plan starts a call at those bounds (pass_calls).
  • The shader is unchanged: it still clips the other pass's quads, so a mesh that was not sorted (Sides::unsorted) stays correct.

Measurements

Mac mini M4 Pro, 1920×1080 offscreen, --profile fast, same seed, spot and settings, alternating runs (the GPU is shared with other bench agents, so batches take a lock and alternate), median of the runs' medians from horizon-ctl bench. "Before #6005" is its parent.

Scene before #6005 #6005 (main) this PR
RD 32, far 256 GPU 4.43 ms 5.51 ms 3.72 ms
RD 32, far 256, capped 100 fps GPU 4.77 ms 5.66 ms 4.21 ms
CPU 2.58 ms 2.69 ms 2.88 ms
RD 12, no far GPU 1.39 ms 1.25 ms 0.97 ms
CPU 0.68 ms 0.65 ms 0.63 ms

The GPU frame drops by 1.4–1.8 ms against #6005 and by 0.4–0.7 ms against the build before it. The render thread spends ~0.2 ms more at RD 32 with far terrain (each mesh now gives an opaque and a cutout run; far tiles are most of them), none at RD 12; frames there are GPU-bound, so the frame time falls by the GPU saving.

Look

Screenshots before #6005 vs this PR (village and forest at RD 12, the village at RD 32 with far terrain; tick frozen, time 6000, HUD hidden): the only differing pixels are the clouds and mobs that moved, animated water, and crops at another growth stage, the same as two captures of one build. Leaves, grass, flowers, crops and far terrain draw as before.

Self-check

pr_ready (tools/pr_ready.py --quick --base perf/fade-idle-skip on ludovics-mac-mini, against perf/fade-idle-skip at e296a7ee3, 7 min 36 s)

Check Result
Scope ⚠️ 6 files, +447 −108; 555 lines of code: over 500, split it if it can ship in parts
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 594 passed (4 min 22 s)
rustfmt ✅ (9 s)
clippy ✅ (1 min 20 s)
tests: horizon-client-render ✅ 979 passed (1 min 7 s)
doc tests ✅ 0 passed (2 s)
content root tests ➖ content root untouched
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ 132 affected, to run in CI (--quick): ambient_sound, armor_stand_frost, arrow, arrow_wind_charge, audio_attributes, auto_jump, block_entity_anim, block_entity_render, block_entity_tickers, block_particles, block_removal, block_tint and 120 more
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

🤖 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/6500 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/solid-pass-parts` --- ### 📝 Commits (1) - [`de59ab9`](https://github.com/horizon-rust/horizon/commit/de59ab97c568168d14718a1b27880cead8134997) Metal: each solid pass draws only its own quads ### 📊 Changes **6 files changed** (+447 additions, -108 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/gfx.rs` (+122 -59) 📝 `crates/horizon-client-render/src/gfx/flat.rs` (+63 -3) 📝 `crates/horizon-client-render/src/gfx/page_runs.rs` (+37 -2) 📝 `crates/horizon-client-render/src/mesher.rs` (+1 -1) 📝 `crates/horizon-client-render/src/mesher/sides.rs` (+220 -39) 📝 `crates/horizon-client-render/src/terrain.wgsl` (+4 -4) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Stacked on #6499 (it uses that PR's `fade_code`); GitHub retargets it to main when #6499 merges. ## Why #6005 draws opaque terrain through a shader that never discards, so Apple's GPUs keep their hidden surface removal. But it drew **every solid list twice** on Metal, once per pass, and each pass clipped the other pass's quads in the vertex shader. On the Mac mini (M4 Pro) at render distance 32 with far terrain 256, that cost **+1.05 ms of GPU** per frame against the build before it (4.43 → 5.51 ms). A diagnostic build showed where: the opaque pass alone took 3.2 ms, both passes 5.4 ms, and 97 % of the indices were in meshes holding both kinds of quads, so splitting by list could not help. ## What it does - `mesher::sides::sort` keeps each bucket's opaque quads (`OPAQUE_LAYER`) and cutout quads apart, and `Sides::visible_from` / `Sides::every` draw one part (`mesher::Part`: `All`, `Opaque`, `Cutout`). - Where the renderer draws two solid passes (Metal, `group_parts`), meshes put all their opaque buckets first, so each part is one or two runs per mesh. Elsewhere each bucket holds its opaque quads then its cutout ones, so the single pass draws the same runs as before. - Phase 1 lists every section's and tile's opaque runs, then their cutout runs (`PageRuns::push_in` groups); a fading mesh goes whole to the cutout pass, as `opaque_quad` treats fading quads. The opaque pass draws `[..opaque_end]`, the cutout pass `[cutout_start..phase 1]`; phase 2 and the mirror still draw everything. `flat::plan` starts a call at those bounds (`pass_calls`). - The shader is unchanged: it still clips the other pass's quads, so a mesh that was not sorted (`Sides::unsorted`) stays correct. ## Measurements Mac mini M4 Pro, 1920×1080 offscreen, `--profile fast`, same seed, spot and settings, alternating runs (the GPU is shared with other bench agents, so batches take a lock and alternate), median of the runs' medians from `horizon-ctl bench`. "Before #6005" is its parent. | Scene | | before #6005 | #6005 (main) | this PR | |---|---|---|---|---| | RD 32, far 256 | GPU | 4.43 ms | 5.51 ms | **3.72 ms** | | RD 32, far 256, capped 100 fps | GPU | 4.77 ms | 5.66 ms | **4.21 ms** | | | CPU | 2.58 ms | 2.69 ms | 2.88 ms | | RD 12, no far | GPU | 1.39 ms | 1.25 ms | **0.97 ms** | | | CPU | 0.68 ms | 0.65 ms | 0.63 ms | The GPU frame drops by 1.4–1.8 ms against #6005 and by 0.4–0.7 ms against the build before it. The render thread spends ~0.2 ms more at RD 32 with far terrain (each mesh now gives an opaque and a cutout run; far tiles are most of them), none at RD 12; frames there are GPU-bound, so the frame time falls by the GPU saving. ## Look Screenshots before #6005 vs this PR (village and forest at RD 12, the village at RD 32 with far terrain; tick frozen, time 6000, HUD hidden): the only differing pixels are the clouds and mobs that moved, animated water, and crops at another growth stage, the same as two captures of one build. Leaves, grass, flowers, crops and far terrain draw as before. ## Self-check **pr_ready** (`tools/pr_ready.py --quick --base perf/fade-idle-skip` on ludovics-mac-mini, against perf/fade-idle-skip at e296a7ee3, 7 min 36 s) | Check | Result | | --- | --- | | Scope | ⚠️ 6 files, +447 −108; 555 lines of code: over 500, split it if it can ship in parts | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 594 passed (4 min 22 s) | | rustfmt | ✅ (9 s) | | clippy | ✅ (1 min 20 s) | | tests: horizon-client-render | ✅ 979 passed (1 min 7 s) | | doc tests | ✅ 0 passed (2 s) | | content root tests | ➖ content root untouched | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ 132 affected, to run in CI (--quick): ambient_sound, armor_stand_frost, arrow, arrow_wind_charge, audio_attributes, auto_jump, block_entity_anim, block_entity_render, block_entity_tickers, block_particles, block_removal, block_tint and 120 more | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | 🤖 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:29:10 +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#6915
No description provided.