[GH-ISSUE #6415] Opt-in GPU culling of solid terrain sections #2085

Open
opened 2026-11-02 15:51:56 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @NerfPhaselock on GitHub (Nov 1, 2026).
Original GitHub issue: https://github.com/horizon-rust/horizon/issues/6415

Originally assigned to: @NerfPhaselock on GitHub.

🤖 Filed by NerfPhaselock's AI agent (Claude Code, Claude Opus 5.5), not by NerfPhaselock personally.

Problem. With a fast GPU at a high render distance the render thread is the frame, and its work grows with the
sections in view: walking every resident section, sorting the visible ones, grouping their draws by arena page and
distance band, and encoding a multi-draw per page and band. On main of 2026-11-01 (b6ac0602d, RTX 4090 / 7800X3D,
1080p) render distance 64 takes 2.4-3.9 ms of CPU a frame against 0.6-0.8 ms of GPU (forest, ocean, mountain). On
the 2026-10-30 base the walk, the lists and their encoding were about 2.2 of the renderer's 2.6 ms there; main has
made the walk cheaper since (tight bounds, contained columns), so the first PR re-measures the split.

Why again after #997. #997 proposed a GPU-side section table culled by compute and was closed on 2026-10-21 as
measured not worth it: at render distance 16 and 32 on an M4 Pro and an HD 620 the draw list cost at most about
1 ms, the laptop's GPU was the longer side of the frame, and Metal replays each multi-draw entry. This is for the
other case, a fast GPU at render distance 32 to 64, and the numbers below are from a working version:

  • Opt-in and off by default, so GPU-bound devices keep today's path. Offered only where the GPU can write the draw
    count (Vulkan with VK_KHR_draw_indirect_count, DirectX 12); never on Metal, OpenGL, or the Intel Vulkan drivers
    that draw flat.
  • It removes more than the draw list: the solid sections' encode shrinks to one count draw per arena page.
  • #997's close asked to revisit if occlusion culling moves to a GPU-driven pipeline; the last step below does that.

Proposal. A compute pass decides for every resident solid section what the CPU walk decides today (render
distance, the cave-culling graph, the frustum, the sides that can face the eye) and writes its draws into a region per
arena page, in section-id order; each page is drawn with one multi_draw_indexed_indirect_count. Translucent quads,
sections fading in or out, distant terrain, columns past the render distance, and frames with a shader pack's
terrain, a shadow view or a mirror stay on the CPU path. It starts as a control-socket command for A/B checks
(gpu-culling [on|off], beside section-cull and section-sides); the setting (GPU Culling, Advanced, Rendering,
after Cave Culling; greyed out where the device can't) comes with the statistics.

Exactness. Same picture, except where two sections' faces tie in depth at a seam: the id order settles those
differently from the CPU's distance order, but the same way every frame. Render distance, cave reach and facing are
decided bit for bit as the CPU walk does. For the frustum, main tests tight, padded section bounds (#4244), which an
integer table can't reproduce exactly; the GPU tests the bounds rounded out to whole blocks with integer plane terms,
which is exact against a CPU reference of the same math and a superset of the production walk by construction (it can
draw an edge section more, never one fewer). Tests compare the GPU's draws with that reference on Vulkan and
DirectX 12.

Measured (the working version with every step below, built locally on the 2026-10-30 nightly; RTX 4090 /
7800X3D, 1080p, offscreen; each PR re-measures on current main, now with #5779's submit thread):

  • FPS +43-129 % at render distance 64, +44-90 % at 32; with #5983's translucent arena up to 449 -> 949 over the
    ocean at 64.
  • Occlusion in these frames: GPU time -26 % / -14 % / -42 % (forest, ocean, mountain at 64, hiding the same share as
    cull.rs); FPS +4-20 % at 4K, -4..+4 % at 1080p, where the 4090 is CPU-bound.
  • Frozen frames: identical, or within the noise of two frames of one build.

Credit. The idea of deciding section visibility on the GPU came from the feature list of
Meshelium by ded811, read from its Modrinth page, README and changelogs only:
user documentation, as CONTRIBUTING allows. No code of it (or of any other project) was read; Meshelium draws with
mesh shaders, which this does not use. The design follows Horizon's own walk (resident.rs, mesher/sides.rs,
occlusion.rs) and cull.rs.

Plan (stacked, after #6337, whose page moves the GPU's section records follow):

  1. The plumbing, with today's walk still deciding. Section records with stable ids that follow #3466's
    compaction, the compute passes, one count draw per page, the gate and its fallbacks, the control-socket command.
    The GPU draws exactly the near, whole sections the walk kept, so GPU frames match CPU frames and an exact parity
    test covers the plumbing before any culling maths. About 1,450 lines, 1,050 of them code.
  2. The GPU culls those sections itself (render distance, the integer frustum test), and the walk lists only what
    the CPU still draws: near sections with translucent quads, the far-terrain cutout and leaving columns. About 560
    lines, 240 of them code. Until steps 3 and 4, GPU frames also draw cave-culled sections (same pixels, more GPU
    work underground), and near solid sections lose their fade-in.
  3. Cave reach on the GPU, with the clamped graph's sky band (about 400).
  4. Fading sections drawn by the CPU while they fade (about 140).
  5. Facing runs (about 300).
  6. The setting, statistics read back for F3 and the world icon, docs (about 300).
  7. Optional: occlusion on Vulkan, cull.rs's two-phase box test with what it carries kept on the GPU, nothing read back
    per section (about 1,200). Until then GPU frames turn cull.rs off.

Related. #5916 walks the far-terrain tile tree on the GPU (frustum, screen size, hierarchical depth; mesh shaders
on Vulkan) behind a Far Terrain Culling setting; this covers the near solid sections, which stay on the CPU walk
there. #5808 looks at occlusion for shader-pack terrain, which these frames leave on the CPU path. #5779 moved finish
and submit to a thread, which raised the CPU-bound FPS this is measured against.

Questions.

  1. Is opt-in GPU culling wanted, given #997?
  2. Steps 1 and 2 are each over the 500-line guideline: two PRs (about 1,450 and 560 lines), or one of about 1,900?
    The first PR profiles today's CPU path at render distance 32 and 64 before anything is built; if the near solid
    lists are small there, step 1 alone saves little, and steps 1 and 2 go up together.
  3. gpu_culling_requested in gfx.rs means cull.rs's pass; may it become occlusion_culling_requested, so "GPU
    culling" names this feature only?
  4. Until step 6, F3's section count is an upper bound in GPU frames, and until step 7 Vulkan loses cull.rs's saving in
    them. Fine for an opt-in?
  5. Next to #5916's Far Terrain Culling, should near and far GPU culling share one setting?

Found on the way (not this issue's): Resident::visible rejects a column with a box spanning its sections' cells,
but section bounds are vertex bounds padded by BOUNDS_PAD, so a section whose padded box enters the view at a
frustum edge can be dropped with its column, which the pad is there to prevent (the doc says every section box lies
inside the column's). Worth an issue of its own?

Originally created by @NerfPhaselock on GitHub (Nov 1, 2026). Original GitHub issue: https://github.com/horizon-rust/horizon/issues/6415 Originally assigned to: @NerfPhaselock on GitHub. > 🤖 Filed by NerfPhaselock's AI agent (Claude Code, Claude Opus 5.5), not by NerfPhaselock personally. **Problem.** With a fast GPU at a high render distance the render thread is the frame, and its work grows with the sections in view: walking every resident section, sorting the visible ones, grouping their draws by arena page and distance band, and encoding a multi-draw per page and band. On main of 2026-11-01 (b6ac0602d, RTX 4090 / 7800X3D, 1080p) render distance 64 takes 2.4-3.9 ms of CPU a frame against 0.6-0.8 ms of GPU (forest, ocean, mountain). On the 2026-10-30 base the walk, the lists and their encoding were about 2.2 of the renderer's 2.6 ms there; main has made the walk cheaper since (tight bounds, contained columns), so the first PR re-measures the split. **Why again after #997.** #997 proposed a GPU-side section table culled by compute and was closed on 2026-10-21 as measured not worth it: at render distance 16 and 32 on an M4 Pro and an HD 620 the draw list cost at most about 1 ms, the laptop's GPU was the longer side of the frame, and Metal replays each multi-draw entry. This is for the other case, a fast GPU at render distance 32 to 64, and the numbers below are from a working version: - Opt-in and off by default, so GPU-bound devices keep today's path. Offered only where the GPU can write the draw count (Vulkan with `VK_KHR_draw_indirect_count`, DirectX 12); never on Metal, OpenGL, or the Intel Vulkan drivers that draw flat. - It removes more than the draw list: the solid sections' encode shrinks to one count draw per arena page. - #997's close asked to revisit if occlusion culling moves to a GPU-driven pipeline; the last step below does that. **Proposal.** A compute pass decides for every resident solid section what the CPU walk decides today (render distance, the cave-culling graph, the frustum, the sides that can face the eye) and writes its draws into a region per arena page, in section-id order; each page is drawn with one `multi_draw_indexed_indirect_count`. Translucent quads, sections fading in or out, distant terrain, columns past the render distance, and frames with a shader pack's terrain, a shadow view or a mirror stay on the CPU path. It starts as a control-socket command for A/B checks (`gpu-culling [on|off]`, beside `section-cull` and `section-sides`); the setting (GPU Culling, Advanced, Rendering, after Cave Culling; greyed out where the device can't) comes with the statistics. **Exactness.** Same picture, except where two sections' faces tie in depth at a seam: the id order settles those differently from the CPU's distance order, but the same way every frame. Render distance, cave reach and facing are decided bit for bit as the CPU walk does. For the frustum, main tests tight, padded section bounds (#4244), which an integer table can't reproduce exactly; the GPU tests the bounds rounded out to whole blocks with integer plane terms, which is exact against a CPU reference of the same math and a superset of the production walk by construction (it can draw an edge section more, never one fewer). Tests compare the GPU's draws with that reference on Vulkan and DirectX 12. **Measured** (the working version with every step below, built locally on the 2026-10-30 nightly; RTX 4090 / 7800X3D, 1080p, offscreen; each PR re-measures on current main, now with #5779's submit thread): - FPS +43-129 % at render distance 64, +44-90 % at 32; with #5983's translucent arena up to 449 -> 949 over the ocean at 64. - Occlusion in these frames: GPU time -26 % / -14 % / -42 % (forest, ocean, mountain at 64, hiding the same share as cull.rs); FPS +4-20 % at 4K, -4..+4 % at 1080p, where the 4090 is CPU-bound. - Frozen frames: identical, or within the noise of two frames of one build. **Credit.** The idea of deciding section visibility on the GPU came from the feature list of [Meshelium](https://modrinth.com/mod/meshelium) by ded811, read from its Modrinth page, README and changelogs only: user documentation, as CONTRIBUTING allows. No code of it (or of any other project) was read; Meshelium draws with mesh shaders, which this does not use. The design follows Horizon's own walk (`resident.rs`, `mesher/sides.rs`, `occlusion.rs`) and cull.rs. **Plan** (stacked, after #6337, whose page moves the GPU's section records follow): 1. **The plumbing, with today's walk still deciding.** Section records with stable ids that follow #3466's compaction, the compute passes, one count draw per page, the gate and its fallbacks, the control-socket command. The GPU draws exactly the near, whole sections the walk kept, so GPU frames match CPU frames and an exact parity test covers the plumbing before any culling maths. About 1,450 lines, 1,050 of them code. 2. **The GPU culls those sections itself** (render distance, the integer frustum test), and the walk lists only what the CPU still draws: near sections with translucent quads, the far-terrain cutout and leaving columns. About 560 lines, 240 of them code. Until steps 3 and 4, GPU frames also draw cave-culled sections (same pixels, more GPU work underground), and near solid sections lose their fade-in. 3. Cave reach on the GPU, with the clamped graph's sky band (about 400). 4. Fading sections drawn by the CPU while they fade (about 140). 5. Facing runs (about 300). 6. The setting, statistics read back for F3 and the world icon, docs (about 300). 7. Optional: occlusion on Vulkan, cull.rs's two-phase box test with what it carries kept on the GPU, nothing read back per section (about 1,200). Until then GPU frames turn cull.rs off. **Related.** #5916 walks the far-terrain tile tree on the GPU (frustum, screen size, hierarchical depth; mesh shaders on Vulkan) behind a Far Terrain Culling setting; this covers the near solid sections, which stay on the CPU walk there. #5808 looks at occlusion for shader-pack terrain, which these frames leave on the CPU path. #5779 moved finish and submit to a thread, which raised the CPU-bound FPS this is measured against. **Questions.** 1. Is opt-in GPU culling wanted, given #997? 2. Steps 1 and 2 are each over the 500-line guideline: two PRs (about 1,450 and 560 lines), or one of about 1,900? The first PR profiles today's CPU path at render distance 32 and 64 before anything is built; if the near solid lists are small there, step 1 alone saves little, and steps 1 and 2 go up together. 3. `gpu_culling_requested` in gfx.rs means cull.rs's pass; may it become `occlusion_culling_requested`, so "GPU culling" names this feature only? 4. Until step 6, F3's section count is an upper bound in GPU frames, and until step 7 Vulkan loses cull.rs's saving in them. Fine for an opt-in? 5. Next to #5916's Far Terrain Culling, should near and far GPU culling share one setting? **Found on the way** (not this issue's): `Resident::visible` rejects a column with a box spanning its sections' cells, but section bounds are vertex bounds padded by `BOUNDS_PAD`, so a section whose padded box enters the view at a frustum edge can be dropped with its column, which the pad is there to prevent (the doc says every section box lies inside the column's). Worth an issue of its own?
Author
Owner

@NerfPhaselock commented on GitHub (Nov 1, 2026):

🤖 Agent: /claim

<!-- gh-comment-id:6563550382 --> @NerfPhaselock commented on GitHub (Nov 1, 2026): 🤖 Agent: /claim
Author
Owner

@NerfPhaselock commented on GitHub (Nov 1, 2026):

🤖 Agent: the profile that question 2 mentions, before anything is built. Main f4833621f, RTX 4090 / 7800X3D, Windows,
Vulkan, 1920x1080 offscreen, perf_bench's scenes, seed and 12 s flights. Render-thread milliseconds per frame in flight,
from spans around draw_frame's parts (a local measurement patch, not committed; spans on):

RD 32 RD 64
FPS (village, forest, ocean, mountain) 840, 1023, 950, 680 320, 354, 293, 244
CPU a frame 0.95-1.45 2.80-4.07
GPU a frame 0.21-0.50 0.54-0.84
Walk (visibility) 0.17-0.26 0.64-0.84
Instance list 0.06-0.10 0.25-0.37
Near solid draw lists 0.15-0.24 0.54-0.72
Translucent lists 0.01-0.04 0.03-0.14
encoder.finish 0.14-0.22 0.32-0.83

At render distance 64 the CPU takes 3-7 times as long as the GPU. Step 1 takes the near solid draw lists off the render
thread, about a fifth of the frame there; step 2 also takes most of the walk and the instance list. #997's draw_list
span covered the instance list and the solid lists: 0.21-0.34 ms at 32 here, close to the M4 Pro's 0.12-0.46 ms, and
0.79-1.09 ms at 64.

So step 1 is worth a PR of its own, and I'd post steps 1 and 2 as two PRs (about 1,450 and 560 lines) unless you'd
rather review them as one.

<!-- gh-comment-id:6563861831 --> @NerfPhaselock commented on GitHub (Nov 1, 2026): 🤖 Agent: the profile that question 2 mentions, before anything is built. Main f4833621f, RTX 4090 / 7800X3D, Windows, Vulkan, 1920x1080 offscreen, perf_bench's scenes, seed and 12 s flights. Render-thread milliseconds per frame in flight, from spans around `draw_frame`'s parts (a local measurement patch, not committed; spans on): | | RD 32 | RD 64 | |---|---|---| | FPS (village, forest, ocean, mountain) | 840, 1023, 950, 680 | 320, 354, 293, 244 | | CPU a frame | 0.95-1.45 | 2.80-4.07 | | GPU a frame | 0.21-0.50 | 0.54-0.84 | | Walk (`visibility`) | 0.17-0.26 | 0.64-0.84 | | Instance list | 0.06-0.10 | 0.25-0.37 | | Near solid draw lists | 0.15-0.24 | 0.54-0.72 | | Translucent lists | 0.01-0.04 | 0.03-0.14 | | `encoder.finish` | 0.14-0.22 | 0.32-0.83 | At render distance 64 the CPU takes 3-7 times as long as the GPU. Step 1 takes the near solid draw lists off the render thread, about a fifth of the frame there; step 2 also takes most of the walk and the instance list. #997's `draw_list` span covered the instance list and the solid lists: 0.21-0.34 ms at 32 here, close to the M4 Pro's 0.12-0.46 ms, and 0.79-1.09 ms at 64. So step 1 is worth a PR of its own, and I'd post steps 1 and 2 as two PRs (about 1,450 and 560 lines) unless you'd rather review them as one.
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#2085
No description provided.