[PR #1641] [MERGED] Renderer: leave out solid quads facing away from the eye (clean-room, stacked on #1564) #3656

Closed
opened 2026-11-03 04:11:12 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

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

Base: main ← Head: perf/face-cull-cr1


📝 Commits (6)

  • 7a1638a Renderer: remove the section face groups modelled on another renderer
  • db758a6 Merge remote-tracking branch 'origin/main' into pa1/remove-face-groups
  • 7c1dd49 Renderer: leave out solid quads that face away from the eye
  • 2716ad4 Renderer: Metal's flat draws and occlusion culling switch on by sections in view
  • fab71df Mesher: sort solid quads in the meshing workers, not in Mesher::mesh
  • 149864c Merge remote-tracking branch 'origin/main' into perf/face-cull-cr1

📊 Changes

12 files changed (+485 additions, -328 deletions)

View changed files

📝 crates/horizon-client/src/game/control.rs (+10 -0)
📝 crates/horizon-client/src/game/render_control.rs (+1 -0)
📝 crates/horizon-client/src/gfx.rs (+82 -20)
📝 crates/horizon-client/src/gfx/cull.rs (+12 -10)
📝 crates/horizon-client/src/gfx/flat.rs (+12 -10)
📝 crates/horizon-client/src/lod.rs (+2 -5)
📝 crates/horizon-client/src/lod/mesh.rs (+1 -3)
📝 crates/horizon-client/src/mesher.rs (+14 -11)
➖ crates/horizon-client/src/mesher/facing.rs (+0 -267)
➕ crates/horizon-client/src/mesher/sides.rs (+346 -0)
📝 crates/horizon-client/src/streaming.rs (+2 -1)
📝 crates/horizon-client/tests/streaming_meshes.rs (+3 -1)

📄 Description

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

Stacked on #1564 (base pa1/remove-face-groups): the two should merge together. Written from scratch from the general back-face technique; no other renderer's code or Horizon's removed code read (sources: horizon-parity/cleanroom/face-culling/provenance.md).

What

After #1564 each section's solid quads are one draw again, and at render distance 32 the GPU shades 30–50% more vertices than on main. This gets that back with code of our own:

  • mesher/sides.rs (new): meshing sorts a mesh's solid quads into seven buckets, one per axis direction plus one for every other quad, and keeps each axis bucket's extreme plane. A quad goes in an axis bucket only when its four corners lie in one axis plane and both its triangles (0-1-2, 0-2-3, as drawn) wind the same way; sloped, rotated, degenerate or bow-tie quads go in the "other" bucket, drawn from everywhere. A +X quad at x = p is a back face from an eye at x <= p, which the solid pipeline culls anyway, so a bucket can be left out whenever the eye is behind all of its planes (with a 1/16-block margin). The sort is stable, so coplanar quads facing one way (overlays) keep their order. The bucket order (+X, +Z, other, +Y, -Z, -X, -Y) was picked by brute force over all 5,040 orders so that the buckets an eye sees are usually one or two contiguous runs. Sections and distant tiles are both sorted on the meshing workers (Mesher::mesh itself keeps model order).
  • gfx.rs: each section and tile pushes one indirect draw per run of buckets that can face the eye (1–3, about 1.6 per section in the benchmark scenes) on the existing page-run, occlusion-culling and flat paths. The eye is solved from the frame's view-projection (the point where clip x, y and w are 0), so the view bob's offset is exact; with no such point (orthographic) everything is drawn.
  • Metal's two switches (gfx/cull.rs, gfx/flat.rs): occlusion culling and flat draws switched on past 4,096 section draws, a number measured when sections had 2.2–2.5 draws each. Draws per section now depend on the eye, so both count sections in view, with the bar at 1,600, where 4,096 draws fell. Without this, the village scene stayed at 543 FPS (GPU p50 1.81 ms) because neither path switched on.
  • horizon-ctl section-sides on|off switches it, for A/B checks, like section-cull and section-draws.

Translucent quads are not bucketed: their indices are re-sorted back to front, and their share of the vertex work is small.

Picture

In-process A/B: the same game, paused without a menu (F3+Esc, which stops the lightmap flicker and the clouds), screenshots with section-sides on, off, then on again, at 7 views (the four benchmark scenes, back over the village, steeply down on it, and a low view looking up): render distance 16 with flat draws, 16 with per-section indirect draws, and 32 (flat draws and occlusion culling on). All 42 on/off pairs are byte-identical, while the frame's draws change (for example 4,045 vs 2,922 draws over 2,409 sections). Two runs of the game can't be compared byte for byte: frames differ in the lightmap flicker even with ticks frozen.

Benchmark

Mac mini M4 Pro, Metal, horizon-client --benchmark <scene> --render-distance N --offscreen --width 1280 --height 720 (seed 1234, 12 s flight), fast-profile builds of main (d65282fb0, the main #1564 contains), #1564 (db758a622) and this branch, alternated, each run in fresh temporary folders. The machine was shared with other agents throughout (load average 47 to 102), so single runs swing; RD 32 is what the vertex work shows in.

RD Scene Avg FPS, main Avg FPS, #1564 Avg FPS, #1564 + this GPU p50 ms, main #1564 #1564 + this
16 village 1200, 2106, 1224, 1227, 1206, 1567 1512, 1098, 1097, 1376, 1097, 1085 1247, 1204, 1251, 1231, 1625, 1388 0.78 0.87 0.77
16 ocean 1036, 1168, 987, 988, 824, 1020 955, 1006, 1031, 839, 896, 720 1097, 1170, 1037, 969, 997, 984 1.15 1.17 1.10
32 village 671, 674, 669, 671, 669 464, 460 606, 664, 674, 639, 679 1.38 2.13 1.39
32 ocean 360, 474, 367, 371, 337 248, 276 362, 362, 382, 371, 350 2.47 3.78 2.45

GPU p50 is the median over the runs. RD 16 runs come from three rounds (the switches don't engage at 16: under 1,600 sections in view); RD 32 runs for this branch are of the final head. At RD 32 this branch is level with main (village 1.39 vs 1.38 ms, ocean 2.45 vs 2.47 ms) and 35–55% faster than #1564 alone. In these scenes 32% of the solid quads of the sections in view are left out (measured over a village flight); the rest are the sides that face the eye plus the 16% of "other" quads (crossed plants).

Self-check

Full run (harnesses) on the previous head 2716ad41b; its one test failure was leaf_culling_tests, which paired the sorted quads with the model's faces in model order. Fixed in fab71df18 (the workers sort, Mesher::mesh keeps model order); the quick run below is on that head. The parity harnesses don't depend on the quad order (the section-mesh harness pairs quads by position).

pr_ready (tools/pr_ready.py --base origin/pa1/remove-face-groups on ludovics-mac-mini, against origin/pa1/remove-face-groups at db758a622, 116 min 31 s)

Check Result
Scope ⚠️ 8 files, +484 −39; 523 lines of code: over 500, split it if it can ship in parts
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ➖ no Python change
rustfmt ✅ (6 s)
clippy ✅ (7 s)
tests: horizon-client ❌ 1063 passed, 1 failed (2 min 36 s)
doc tests ✅ 0 passed (2 s)
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ✅ 108 affected, 108 passed (112 min 9 s)
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

pr_ready (tools/pr_ready.py --quick --base origin/pa1/remove-face-groups on ludovics-mac-mini, against origin/pa1/remove-face-groups at db758a622, 2 min 14 s)

Check Result
Scope ⚠️ 10 files, +487 −40; 523 lines of code: over 500, split it if it can ship in parts
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ➖ no Python change
rustfmt ✅ (4 s)
clippy ✅
tests: horizon-client ✅ 1188 passed (2 min 0 s)
doc tests ✅ 0 passed (1 s)
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ 105 affected, to run in CI (--quick): ambient_sound, arrow, audio_attributes, auto_jump, block_entity_anim, block_entity_render, block_entity_tickers, block_particles, block_removal, block_transformer, breaking_model, camera and 93 more
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

No label: players see the frame rate change.

Needs from Ludovic: nothing beyond merging it together with #1564. Linux (Vulkan multi-draw) was not run here; its path is the same list of indirect draws the per-section path on the Mac uses, which the A/B covered.

🤖 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/1641 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/24/2026 **Status:** ✅ Merged **Merged:** 10/25/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/face-cull-cr1` --- ### 📝 Commits (6) - [`7a1638a`](https://github.com/horizon-rust/horizon/commit/7a1638a1908f5183102b7f649a79c4d95db8fe7c) Renderer: remove the section face groups modelled on another renderer - [`db758a6`](https://github.com/horizon-rust/horizon/commit/db758a622f9b7a42805e152da080a4074fa38b75) Merge remote-tracking branch 'origin/main' into pa1/remove-face-groups - [`7c1dd49`](https://github.com/horizon-rust/horizon/commit/7c1dd4981062ce9e0cb0db0b7d919109243b2470) Renderer: leave out solid quads that face away from the eye - [`2716ad4`](https://github.com/horizon-rust/horizon/commit/2716ad41bed4da8f7ac71e7a5bfe482cfc93881e) Renderer: Metal's flat draws and occlusion culling switch on by sections in view - [`fab71df`](https://github.com/horizon-rust/horizon/commit/fab71df1857dafcf3768f3d86afff40e210612da) Mesher: sort solid quads in the meshing workers, not in Mesher::mesh - [`149864c`](https://github.com/horizon-rust/horizon/commit/149864c3b47d732b26fb1de95254bfcd4a92f608) Merge remote-tracking branch 'origin/main' into perf/face-cull-cr1 ### 📊 Changes **12 files changed** (+485 additions, -328 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game/control.rs` (+10 -0) 📝 `crates/horizon-client/src/game/render_control.rs` (+1 -0) 📝 `crates/horizon-client/src/gfx.rs` (+82 -20) 📝 `crates/horizon-client/src/gfx/cull.rs` (+12 -10) 📝 `crates/horizon-client/src/gfx/flat.rs` (+12 -10) 📝 `crates/horizon-client/src/lod.rs` (+2 -5) 📝 `crates/horizon-client/src/lod/mesh.rs` (+1 -3) 📝 `crates/horizon-client/src/mesher.rs` (+14 -11) ➖ `crates/horizon-client/src/mesher/facing.rs` (+0 -267) ➕ `crates/horizon-client/src/mesher/sides.rs` (+346 -0) 📝 `crates/horizon-client/src/streaming.rs` (+2 -1) 📝 `crates/horizon-client/tests/streaming_meshes.rs` (+3 -1) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Stacked on #1564 (base `pa1/remove-face-groups`): the two should merge together. Written from scratch from the general back-face technique; no other renderer's code or Horizon's removed code read (sources: `horizon-parity/cleanroom/face-culling/provenance.md`). ## What After #1564 each section's solid quads are one draw again, and at render distance 32 the GPU shades 30–50% more vertices than on main. This gets that back with code of our own: - **`mesher/sides.rs`** (new): meshing sorts a mesh's solid quads into seven buckets, one per axis direction plus one for every other quad, and keeps each axis bucket's extreme plane. A quad goes in an axis bucket only when its four corners lie in one axis plane and both its triangles (0-1-2, 0-2-3, as drawn) wind the same way; sloped, rotated, degenerate or bow-tie quads go in the "other" bucket, drawn from everywhere. A +X quad at `x = p` is a back face from an eye at `x <= p`, which the solid pipeline culls anyway, so a bucket can be left out whenever the eye is behind all of its planes (with a 1/16-block margin). The sort is stable, so coplanar quads facing one way (overlays) keep their order. The bucket order (+X, +Z, other, +Y, -Z, -X, -Y) was picked by brute force over all 5,040 orders so that the buckets an eye sees are usually one or two contiguous runs. Sections and distant tiles are both sorted on the meshing workers (`Mesher::mesh` itself keeps model order). - **`gfx.rs`**: each section and tile pushes one indirect draw per run of buckets that can face the eye (1–3, about 1.6 per section in the benchmark scenes) on the existing page-run, occlusion-culling and flat paths. The eye is solved from the frame's view-projection (the point where clip x, y and w are 0), so the view bob's offset is exact; with no such point (orthographic) everything is drawn. - **Metal's two switches** (`gfx/cull.rs`, `gfx/flat.rs`): occlusion culling and flat draws switched on past 4,096 section draws, a number measured when sections had 2.2–2.5 draws each. Draws per section now depend on the eye, so both count sections in view, with the bar at 1,600, where 4,096 draws fell. Without this, the village scene stayed at 543 FPS (GPU p50 1.81 ms) because neither path switched on. - `horizon-ctl section-sides on|off` switches it, for A/B checks, like `section-cull` and `section-draws`. Translucent quads are not bucketed: their indices are re-sorted back to front, and their share of the vertex work is small. ## Picture In-process A/B: the same game, paused without a menu (F3+Esc, which stops the lightmap flicker and the clouds), screenshots with `section-sides` on, off, then on again, at 7 views (the four benchmark scenes, back over the village, steeply down on it, and a low view looking up): render distance 16 with flat draws, 16 with per-section indirect draws, and 32 (flat draws and occlusion culling on). **All 42 on/off pairs are byte-identical**, while the frame's draws change (for example 4,045 vs 2,922 draws over 2,409 sections). Two runs of the game can't be compared byte for byte: frames differ in the lightmap flicker even with ticks frozen. ## Benchmark Mac mini M4 Pro, Metal, `horizon-client --benchmark <scene> --render-distance N --offscreen --width 1280 --height 720` (seed 1234, 12 s flight), fast-profile builds of main (d65282fb0, the main #1564 contains), #1564 (db758a622) and this branch, alternated, each run in fresh temporary folders. The machine was shared with other agents throughout (load average 47 to 102), so single runs swing; RD 32 is what the vertex work shows in. | RD | Scene | Avg FPS, main | Avg FPS, #1564 | Avg FPS, #1564 + this | GPU p50 ms, main | #1564 | #1564 + this | |---|---|---|---|---|---:|---:|---:| | 16 | village | 1200, 2106, 1224, 1227, 1206, 1567 | 1512, 1098, 1097, 1376, 1097, 1085 | 1247, 1204, 1251, 1231, 1625, 1388 | 0.78 | 0.87 | 0.77 | | 16 | ocean | 1036, 1168, 987, 988, 824, 1020 | 955, 1006, 1031, 839, 896, 720 | 1097, 1170, 1037, 969, 997, 984 | 1.15 | 1.17 | 1.10 | | 32 | village | 671, 674, 669, 671, 669 | 464, 460 | 606, 664, 674, 639, 679 | 1.38 | 2.13 | 1.39 | | 32 | ocean | 360, 474, 367, 371, 337 | 248, 276 | 362, 362, 382, 371, 350 | 2.47 | 3.78 | 2.45 | GPU p50 is the median over the runs. RD 16 runs come from three rounds (the switches don't engage at 16: under 1,600 sections in view); RD 32 runs for this branch are of the final head. At RD 32 this branch is level with main (village 1.39 vs 1.38 ms, ocean 2.45 vs 2.47 ms) and 35–55% faster than #1564 alone. In these scenes 32% of the solid quads of the sections in view are left out (measured over a village flight); the rest are the sides that face the eye plus the 16% of "other" quads (crossed plants). ## Self-check Full run (harnesses) on the previous head 2716ad41b; its one test failure was `leaf_culling_tests`, which paired the sorted quads with the model's faces in model order. Fixed in fab71df18 (the workers sort, `Mesher::mesh` keeps model order); the quick run below is on that head. The parity harnesses don't depend on the quad order (the section-mesh harness pairs quads by position). **pr_ready** (`tools/pr_ready.py --base origin/pa1/remove-face-groups` on ludovics-mac-mini, against origin/pa1/remove-face-groups at db758a622, 116 min 31 s) | Check | Result | | --- | --- | | Scope | ⚠️ 8 files, +484 −39; 523 lines of code: over 500, split it if it can ship in parts | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ➖ no Python change | | rustfmt | ✅ (6 s) | | clippy | ✅ (7 s) | | tests: horizon-client | ❌ 1063 passed, 1 failed (2 min 36 s) | | doc tests | ✅ 0 passed (2 s) | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ✅ 108 affected, 108 passed (112 min 9 s) | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | **pr_ready** (`tools/pr_ready.py --quick --base origin/pa1/remove-face-groups` on ludovics-mac-mini, against origin/pa1/remove-face-groups at db758a622, 2 min 14 s) | Check | Result | | --- | --- | | Scope | ⚠️ 10 files, +487 −40; 523 lines of code: over 500, split it if it can ship in parts | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ➖ no Python change | | rustfmt | ✅ (4 s) | | clippy | ✅ | | tests: horizon-client | ✅ 1188 passed (2 min 0 s) | | doc tests | ✅ 0 passed (1 s) | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ 105 affected, to run in CI (--quick): ambient_sound, arrow, audio_attributes, auto_jump, block_entity_anim, block_entity_render, block_entity_tickers, block_particles, block_removal, block_transformer, breaking_model, camera and 93 more | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | No label: players see the frame rate change. Needs from Ludovic: nothing beyond merging it together with #1564. Linux (Vulkan multi-draw) was not run here; its path is the same list of indirect draws the per-section path on the Mac uses, which the A/B covered. 🤖 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 04:11:12 +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#3656
No description provided.