[PR #6804] GPU culling (1/7): the GPU lists the near solid sections the walk keeps #7107

Open
opened 2026-11-03 06:33:59 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/6804
Author: @NerfPhaselock
Created: 11/2/2026
Status: 🔄 Open

Base: main ← Head: perf/gpu-culling


📝 Commits (1)

  • 67f910f Renderer: GPU culling lists the near solid sections the walk keeps

📊 Changes

7 files changed (+2016 additions, -55 deletions)

View changed files

📝 crates/horizon-client-render/src/gfx.rs (+315 -39)
📝 crates/horizon-client-render/src/gfx/arena.rs (+39 -13)
➕ crates/horizon-client-render/src/gfx/gpu_culling.rs (+1417 -0)
➕ crates/horizon-client-render/src/gfx/gpu_culling.wgsl (+203 -0)
📝 crates/horizon-client-render/src/gfx/resident.rs (+29 -3)
📝 crates/horizon-client/src/game/control.rs (+12 -0)
📝 crates/horizon-client/src/game/render_control.rs (+1 -0)

📄 Description

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

What and why

Part of #6415 (1 of 7).

The render thread lists the near solid sections' draws itself: a few per section, by the sides it shows the eye, grouped
by arena page and distance band. At render distance 64 that is 0.54-0.72 ms of a 2.8-4.1 ms frame on an RTX 4090 /
7800X3D, whose GPU needs 0.5-0.8 ms (the profile in #6415). This moves those lists to the GPU, behind a control word for
now (gpu-culling on; the setting is step 6):

  • Records. Every resident section with solid quads has a record (its key, page, first vertex and quads) under an id
    it keeps while it stays (SectionGpu::gpu_id). Uploads, releases, remove_columns (both of its paths) and
    clear_sections keep them in step, and #3466's move_off_page relocates a section's record in the step that records
    its copy. Changed records go to the GPU in one belt write a frame (apply); switching on, a table that grew or more
    than 21,845 changes in one frame write the whole table. Free ids are a bitset, so a teleport that drops most of the
    view frees its records in one pass over the freed ids, and a freed record is not written back: the walk never chooses
    a free id, so its stale copy is never read.
  • The pass (gfx/gpu_culling.wgsl). cull keeps the chosen records and counts them per page and block of ids,
    scan turns the counts into where each block's draws start, and scatter writes one draw per section, all its solid
    quads, in id order. Each page is drawn with one multi_draw_indexed_indirect_count. Where faces of two sections tie in
    depth at a seam, id order settles them the same way every frame (appended with atomics alone, they would flicker).
  • The walk still decides. In a GPU frame its solid loop marks the whole sections it keeps within the render
    distance that have a record (a bitmask), and the pass draws exactly those. Sections fading in or out, columns past the
    render distance, far terrain and translucent quads stay on the CPU's lists. So the picture is the CPU's and no culling
    maths is new yet: step 2 moves the render distance and frustum tests to the GPU, and the walk shrinks.
  • Where it runs. Offered where the device draws a count the GPU wrote (DirectX 12, Vulkan 1.2 or
    VK_KHR_draw_indirect_count) and runs compute shaders, and where vanilla frames are never drawn flat (not Metal, nor
    Intel's Gen11/Gen12 Vulkan driver, nor with flat draws forced on). Frames with the title, a pack's terrain, a shadow
    view or the water mirror stay CPU frames. GPU frames leave cull.rs's occlusion test off, as its bookkeeping lives in
    the CPU's lists; step 7 brings occlusion into GPU frames on Vulkan.
  • gpu_culling_requested, which means cull.rs's pass, becomes occlusion_culling_requested (question 3 in #6415; four
    lines, easy to drop).

wgpu checks a count draw only against its buffers' sizes, so every draw here is in bounds by construction: its index
count is its section's own solid quads × 6, its base vertex starts its section's own range of the bound page, its first
instance is an id the origins buffer holds, and each page's count is clamped to its region.

Measured (RTX 4090 / 7800X3D, Windows, 1920x1080 offscreen, Translucent Batching on; perf_bench's four 12 s flights
in the same order in every run, as the arena's page layout depends on the teleports; FPS against main without this
change, counterbalanced; main 5afa1de5f, three runs of each at Vulkan render distance 64, two elsewhere):

Village Forest Ocean Mountain
Vulkan, render distance 32 +29.5 % +21.3 % +35.6 % +31.8 %
Vulkan, render distance 64 +47.5 % +52.3 % +42.6 % +39.3 %
DirectX 12, render distance 64 +51.1 % +57.7 % +44.2 % +41.3 %
  • 1% lows at render distance 64 on Vulkan: +31.7 to +42.6 %. CPU time per frame: -28.4 to -36.0 %.
  • GPU time rises (Vulkan +50 to +142 % at render distance 64: no occlusion test, all of a section's facing buckets, solid
    draws no longer front to back). It stays below the CPU time in most frames, but the forest at render distance 32 is
    GPU-bound in 55-59 % of GPU frames; where the GPU is the limit the trade can go the other way, hence opt-in.
  • With the word off this costs nothing measurable: -1.1 to +2.4 % against main (on b91226cac), inside the run-to-run
    spread.
  • Teleports. A far teleport drops most of the view at once (#6898). At render distance 32 its drop frames take the
    same render-thread time with the word on as off (-1.05 to +1.05 ms across the four scenes, one run each way); before
    this push's bitset free list and unwritten frees they took +1.4 to +3.9 ms more.

Draft until the last short checks finish on today's main: render distance 64 teleports, pixels after teleports and
the gate cases below. The rest was checked on 5afa1de5f and e8b55fbe5.

Checked in game (on 5afa1de5f, e8b55fbe5 and today's 0c7b5b61a):

  • Pixels: GPU frames match CPU frames within the noise two CPU frames show between themselves (the forest
    bit-identical), on Vulkan and on DirectX 12, with Translucent Batching on and off, with far terrain and after
    teleports (and, on b91226cac, through 781 shots during chunk fades). Three pixels at the ocean differ by one level, as
    a depth tie at a seam would.
  • Records live through everything that moves or drops them, with the debug check of every record on the first GPU
    frame and every 64th after (it never fired): compaction from render distance 64 to 16 and back with T2's translucent
    shrink beside it, teleports through #6898's at-once path and the column-by-column one with far terrain, the word
    switched every second during a flight, the Nether and back, 1,000,000 blocks out and back.
  • Frames that stay CPU frames: the title screen, a shaders/ pack, a native pack's [shadow] and its water mirror,
    HORIZON_SUBMIT_THREAD=1; with HORIZON_FLAT_DRAWS=1 GPU culling isn't offered and the word is refused. No panic,
    validation error or warning in any run beyond the harness's own audio-off notice.

Tests. gpu_culling.rs: records_keep_ids_page_counts_and_moves (ids reused lowest first, page counts, moves,
many removed at once as one by one), params_and_records_match_the_shader (naga's layouter against the Rust structs,
and the shader's constants), and on a device (Vulkan, DirectX 12 with FXC and with DXC; skipped without one, and on
Intel's Gen11/Gen12 Vulkan driver) the_pass_lists_the_draws_of_the_sections_it_is_given (24 cases: ids reused,
records moved across pages, the whole-table path, a regrown table, a clear, cameras 20 million blocks out) and
the_count_draws_draw_each_chosen_section_with_its_origin (the real count draws in a render pass, each quad writing the
origin it was drawn with to a pixel of its own). arena.rs's compaction test checks that the records follow the moves
in both layouts. gfx.rs: gpu_culling_is_offered_where_counts_are_drawn_and_vanilla_never_draws_flat. In debug builds
check_gpu_records checks every record, page count and the live count. Dropping the relocation in move_off_page, the
table range check in cull, the count, the 20-byte draw stride or the origins binding each fails a test. GPU tests skip
without an adapter; CI has none.

Size. 2,071 lines, about 750 of them tests: over the guideline, as #6415 asks about. The records, the pass and the
draws only work together, and keeping the walk in charge lets this step be checked against the CPU path exactly before
step 2 adds the culling maths.

Kind

  • parity: Horizon now does what vanilla 26.3 does
  • bug: a crash or a breakage
  • perf: faster, or less memory
  • feature: something new for players (listed under New in the release notes)
  • extra: Horizon-only, off by default
  • tooling: tools, CI, tests, harnesses
  • docs

Vanilla reference

Horizon-only: vanilla lists sections on the CPU. The picture stays vanilla's.

Other projects' code

none (the idea is credited in #6415)

Self-check

pr_ready (tools/pr_ready.py --quick --base upstream/main on DESKTOP-4R7C0FC, against upstream/main at 0c7b5b61a)

Check Result
Scope ⚠️ 7 files, +2016 −55; 2071 lines of code: over 500, split it if it can ship in parts
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 614 passed (1 min 26 s)
rustfmt ✅ (9 s)
clippy ✅ (50 s)
tests: horizon-client, horizon-client-render ✅ 1898 passed (2 min 20 s)
doc tests ✅ 0 passed (3 s)
content root tests ➖ content root untouched
mod API up to date ✅ (17 s)
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)

The render crate's tests also pass on their own (1,176), with the GPU tests on Vulkan and on DirectX 12 (FXC and DXC).

🤖 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/6804 **Author:** [@NerfPhaselock](https://github.com/NerfPhaselock) **Created:** 11/2/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `perf/gpu-culling` --- ### 📝 Commits (1) - [`67f910f`](https://github.com/horizon-rust/horizon/commit/67f910fa7960d90cdab7d1f1f9d5f1481b9fab77) Renderer: GPU culling lists the near solid sections the walk keeps ### 📊 Changes **7 files changed** (+2016 additions, -55 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/gfx.rs` (+315 -39) 📝 `crates/horizon-client-render/src/gfx/arena.rs` (+39 -13) ➕ `crates/horizon-client-render/src/gfx/gpu_culling.rs` (+1417 -0) ➕ `crates/horizon-client-render/src/gfx/gpu_culling.wgsl` (+203 -0) 📝 `crates/horizon-client-render/src/gfx/resident.rs` (+29 -3) 📝 `crates/horizon-client/src/game/control.rs` (+12 -0) 📝 `crates/horizon-client/src/game/render_control.rs` (+1 -0) </details> ### 📄 Description > 🤖 Opened by NerfPhaselock's AI agent (Claude Code, Claude Opus 5.5), not by NerfPhaselock personally. ## What and why Part of #6415 (1 of 7). The render thread lists the near solid sections' draws itself: a few per section, by the sides it shows the eye, grouped by arena page and distance band. At render distance 64 that is 0.54-0.72 ms of a 2.8-4.1 ms frame on an RTX 4090 / 7800X3D, whose GPU needs 0.5-0.8 ms (the profile in #6415). This moves those lists to the GPU, behind a control word for now (`gpu-culling on`; the setting is step 6): - **Records.** Every resident section with solid quads has a record (its key, page, first vertex and quads) under an id it keeps while it stays (`SectionGpu::gpu_id`). Uploads, releases, `remove_columns` (both of its paths) and `clear_sections` keep them in step, and #3466's `move_off_page` relocates a section's record in the step that records its copy. Changed records go to the GPU in one belt write a frame (`apply`); switching on, a table that grew or more than 21,845 changes in one frame write the whole table. Free ids are a bitset, so a teleport that drops most of the view frees its records in one pass over the freed ids, and a freed record is not written back: the walk never chooses a free id, so its stale copy is never read. - **The pass** (`gfx/gpu_culling.wgsl`). `cull` keeps the chosen records and counts them per page and block of ids, `scan` turns the counts into where each block's draws start, and `scatter` writes one draw per section, all its solid quads, in id order. Each page is drawn with one `multi_draw_indexed_indirect_count`. Where faces of two sections tie in depth at a seam, id order settles them the same way every frame (appended with atomics alone, they would flicker). - **The walk still decides.** In a GPU frame its solid loop marks the whole sections it keeps within the render distance that have a record (a bitmask), and the pass draws exactly those. Sections fading in or out, columns past the render distance, far terrain and translucent quads stay on the CPU's lists. So the picture is the CPU's and no culling maths is new yet: step 2 moves the render distance and frustum tests to the GPU, and the walk shrinks. - **Where it runs.** Offered where the device draws a count the GPU wrote (DirectX 12, Vulkan 1.2 or `VK_KHR_draw_indirect_count`) and runs compute shaders, and where vanilla frames are never drawn flat (not Metal, nor Intel's Gen11/Gen12 Vulkan driver, nor with flat draws forced on). Frames with the title, a pack's terrain, a shadow view or the water mirror stay CPU frames. GPU frames leave cull.rs's occlusion test off, as its bookkeeping lives in the CPU's lists; step 7 brings occlusion into GPU frames on Vulkan. - `gpu_culling_requested`, which means cull.rs's pass, becomes `occlusion_culling_requested` (question 3 in #6415; four lines, easy to drop). wgpu checks a count draw only against its buffers' sizes, so every draw here is in bounds by construction: its index count is its section's own solid quads × 6, its base vertex starts its section's own range of the bound page, its first instance is an id the origins buffer holds, and each page's count is clamped to its region. **Measured** (RTX 4090 / 7800X3D, Windows, 1920x1080 offscreen, Translucent Batching on; perf_bench's four 12 s flights in the same order in every run, as the arena's page layout depends on the teleports; FPS against main without this change, counterbalanced; main 5afa1de5f, three runs of each at Vulkan render distance 64, two elsewhere): | | Village | Forest | Ocean | Mountain | |---|---|---|---|---| | Vulkan, render distance 32 | +29.5 % | +21.3 % | +35.6 % | +31.8 % | | Vulkan, render distance 64 | +47.5 % | +52.3 % | +42.6 % | +39.3 % | | DirectX 12, render distance 64 | +51.1 % | +57.7 % | +44.2 % | +41.3 % | - 1% lows at render distance 64 on Vulkan: +31.7 to +42.6 %. CPU time per frame: -28.4 to -36.0 %. - GPU time rises (Vulkan +50 to +142 % at render distance 64: no occlusion test, all of a section's facing buckets, solid draws no longer front to back). It stays below the CPU time in most frames, but the forest at render distance 32 is GPU-bound in 55-59 % of GPU frames; where the GPU is the limit the trade can go the other way, hence opt-in. - With the word off this costs nothing measurable: -1.1 to +2.4 % against main (on b91226cac), inside the run-to-run spread. - **Teleports.** A far teleport drops most of the view at once (#6898). At render distance 32 its drop frames take the same render-thread time with the word on as off (-1.05 to +1.05 ms across the four scenes, one run each way); before this push's bitset free list and unwritten frees they took +1.4 to +3.9 ms more. **Draft** until the last short checks finish on today's main: render distance 64 teleports, pixels after teleports and the gate cases below. The rest was checked on 5afa1de5f and e8b55fbe5. **Checked in game** (on 5afa1de5f, e8b55fbe5 and today's 0c7b5b61a): - **Pixels:** GPU frames match CPU frames within the noise two CPU frames show between themselves (the forest bit-identical), on Vulkan and on DirectX 12, with Translucent Batching on and off, with far terrain and after teleports (and, on b91226cac, through 781 shots during chunk fades). Three pixels at the ocean differ by one level, as a depth tie at a seam would. - **Records live through everything that moves or drops them,** with the debug check of every record on the first GPU frame and every 64th after (it never fired): compaction from render distance 64 to 16 and back with T2's translucent shrink beside it, teleports through #6898's at-once path and the column-by-column one with far terrain, the word switched every second during a flight, the Nether and back, 1,000,000 blocks out and back. - **Frames that stay CPU frames:** the title screen, a `shaders/` pack, a native pack's `[shadow]` and its water mirror, `HORIZON_SUBMIT_THREAD=1`; with `HORIZON_FLAT_DRAWS=1` GPU culling isn't offered and the word is refused. No panic, validation error or warning in any run beyond the harness's own audio-off notice. **Tests.** `gpu_culling.rs`: `records_keep_ids_page_counts_and_moves` (ids reused lowest first, page counts, moves, many removed at once as one by one), `params_and_records_match_the_shader` (naga's layouter against the Rust structs, and the shader's constants), and on a device (Vulkan, DirectX 12 with FXC and with DXC; skipped without one, and on Intel's Gen11/Gen12 Vulkan driver) `the_pass_lists_the_draws_of_the_sections_it_is_given` (24 cases: ids reused, records moved across pages, the whole-table path, a regrown table, a clear, cameras 20 million blocks out) and `the_count_draws_draw_each_chosen_section_with_its_origin` (the real count draws in a render pass, each quad writing the origin it was drawn with to a pixel of its own). `arena.rs`'s compaction test checks that the records follow the moves in both layouts. `gfx.rs`: `gpu_culling_is_offered_where_counts_are_drawn_and_vanilla_never_draws_flat`. In debug builds `check_gpu_records` checks every record, page count and the live count. Dropping the relocation in `move_off_page`, the table range check in `cull`, the count, the 20-byte draw stride or the origins binding each fails a test. GPU tests skip without an adapter; CI has none. **Size.** 2,071 lines, about 750 of them tests: over the guideline, as #6415 asks about. The records, the pass and the draws only work together, and keeping the walk in charge lets this step be checked against the CPU path exactly before step 2 adds the culling maths. ## Kind - [ ] parity: Horizon now does what vanilla 26.3 does - [ ] bug: a crash or a breakage - [x] perf: faster, or less memory - [ ] feature: something new for players (listed under New in the release notes) - [ ] extra: Horizon-only, off by default - [ ] tooling: tools, CI, tests, harnesses - [ ] docs ## Vanilla reference Horizon-only: vanilla lists sections on the CPU. The picture stays vanilla's. ## Other projects' code none (the idea is credited in #6415) ## Self-check **pr_ready** (`tools/pr_ready.py --quick --base upstream/main` on DESKTOP-4R7C0FC, against upstream/main at 0c7b5b61a) | Check | Result | | --- | --- | | Scope | ⚠️ 7 files, +2016 −55; 2071 lines of code: over 500, split it if it can ship in parts | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 614 passed (1 min 26 s) | | rustfmt | ✅ (9 s) | | clippy | ✅ (50 s) | | tests: horizon-client, horizon-client-render | ✅ 1898 passed (2 min 20 s) | | doc tests | ✅ 0 passed (3 s) | | content root tests | ➖ content root untouched | | mod API up to date | ✅ (17 s) | | 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) | The render crate's tests also pass on their own (1,176), with the GPU tests on Vulkan and on DirectX 12 (FXC and DXC). 🤖 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>
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#7107
No description provided.