[PR #6337] [MERGED] Translucent batching (3/4): the large pages shrink once the view has settled #6808

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

📋 Pull Request Information

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

Base: main ← Head: perf/translucent-compaction


📝 Commits (1)

  • b91226c Renderer: shrink the large translucent pages once the view has settled

📊 Changes

7 files changed (+580 additions, -37 deletions)

View changed files

📝 crates/horizon-client-render/src/gfx.rs (+215 -28)
📝 crates/horizon-client-render/src/gfx/arena.rs (+242 -8)
📝 crates/horizon-client-render/src/gfx/lod.rs (+4 -0)
📝 crates/horizon-client-render/src/lod.rs (+5 -0)
📝 crates/horizon-client-render/src/streaming.rs (+92 -0)
📝 crates/horizon-client/src/game.rs (+21 -0)
📝 docs/graphics.md (+1 -1)

📄 Description

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

What and why

Part of #5983 (3 of 4).

Translucent Batching's vertex and sorted-index pages grow up to about 2 GiB (#5984) and never shrank, so a page kept
its high-water size after the water that filled it was gone: an ocean left behind, a lower render distance. In the
run below, render distance 64 then 16 over the ocean leaves 1.48 GB in the arenas for 0.40 GB of vertices.

This shrinks them with #3466's mover instead of a second mechanism (the question in #5983):

  • Which pages. One of 64 MiB or more that a right-sized page (grown(used)) would halve, or make 256 MiB smaller
    (Arena::oversized).
  • How. The arena opens that page in video memory and closes the large one (Arena::open_page, begin_shrink).
    #3466's move_off_page then empties it into the new page within the same copy budget as the section arena's
    compaction (32 MiB a frame; 8 MiB for sorted indices, which come as many small ranges), and trim drops it. Each
    mesh's pointer switches in the step that records its copy. With no room for the new page, or a range no mesh owns,
    the page stays as it is and the next try waits 5 s.
  • Only once the view has settled (ShrinkGate): a second after terrain stops arriving, in a frame the section
    arena's compaction copied nothing. The game reports terrain arriving (Renderer::set_terrain_loading): the view's
    outermost columns not all there yet (ViewArrival, capped at the server's view distance and given up 30 s after the
    view last changed), events from the server waiting to be handled, far tiles being sampled, and, for those 30 s,
    re-meshes and pending uploads. The renderer also waits while translucent sections or far tiles wait to upload.
    Single player joins its integrated server like a remote one, so streaming alone can't see terrain not sent yet. A
    shrink under way finishes.
  • One change to #3466's mover: move_off_page always moves the first range it is given, so a range larger than
    the budget no longer keeps a page closed for good (today one over 32 MiB would).

Measured (RTX 4090 / 7800X3D, 1920x1080, offscreen; ocean at render distance 64, then 16, then 64 again, batching
on, the camera flying in place with every frame time recorded; this branch on main 3adcfcbb3 against the same tree without the shrink,
one run each):

Without With the shrink
Arenas at 16 1.48 GB 0.68 GB, from 12 s after the change
GPU memory allocated at 16 1.99 GB 0.96 GB
Slowest frame while it shrinks – 7.5 ms, as the new page is made; the rest under 3.1 ms (most frames 0.3 ms)
Arenas back at 64 5.90 GB 5.78 GB
Slowest frames growing back to 64 6.7 ms 11.3 and 18.0 ms

The last row is the cost: back at a high render distance the shrunk pages grow again, and growth is #5984's one-frame
copy into a bigger page. Growing a page by the same per-frame budget would be a PR of its own. Frozen frames after
the shrink match the run without it (117 pixels differ, by one level: less than two shots of one run do); at 64 only
the far-terrain band differs, as between any two runs. No validation errors.

Tests. arena.rs: large_pages_shrink_when_that_halves_them_or_saves_a_page (the rule, at its edges),
a_large_page_moves_into_one_of_the_size_its_ranges_get (GPU: vertices and sorted indices move with their data read
back and each mesh's pointer following, its other range untouched; the emptied page takes no new range until trim;
with no video memory for the new page nothing changes and nothing spills to system memory). gfx.rs: shrinking_starts_once_terrain_has_settled (ShrinkGate: the settle time, the budget, the retry).
streaming.rs: a_view_has_arrived_once_its_outermost_columns_are_in (every edge column, the 30 s give-up, a view
that changes). GPU tests run on Vulkan and skip without an adapter; CI has none.

Not covered by a run yet: DirectX 12, a remote server, splitscreen.

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 has no arena.

Other projects' code

none

Self-check

pr_ready (tools/pr_ready.py --quick --base upstream/main on DESKTOP-4R7C0FC, against upstream/main at 904ef97e5, 3 min 40 s)

Check Result
Scope ⚠️ 7 files, +580 −37; 615 lines of code: over 500, split it if it can ship in parts
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ❌ 594 run, FAILED (errors=1, skipped=11) (1 min 18 s)
rustfmt ✅ (8 s)
clippy ✅ (49 s)
tests: horizon-client, horizon-client-render ❌ 558 passed, 1 failed (1 min 18 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 ➖ 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)

Neither failure is this PR's. native_loot_kinds_stay_hookable looks for "\n}\n" in horizon-world/src/loot.rs, which
this Windows checkout has with CRLF line endings; it also stopped the run before the render crate's tests, which pass
on their own (915 passed, 32 ignored, GPU tests on Vulkan). The Python error is test_world_input_capture's capture
helper exiting with 101 on this machine; this PR touches no input code.

On size: 615 changed lines, about 250 of them tests. The rule, the move and the gate only make sense together; the
binding fix that the move needs went ahead as its own PR (#6181).

🤖 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/6337 **Author:** [@NerfPhaselock](https://github.com/NerfPhaselock) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/translucent-compaction` --- ### 📝 Commits (1) - [`b91226c`](https://github.com/horizon-rust/horizon/commit/b91226cac9aefcc53d2a4c55e26ecdb9d436bc33) Renderer: shrink the large translucent pages once the view has settled ### 📊 Changes **7 files changed** (+580 additions, -37 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/gfx.rs` (+215 -28) 📝 `crates/horizon-client-render/src/gfx/arena.rs` (+242 -8) 📝 `crates/horizon-client-render/src/gfx/lod.rs` (+4 -0) 📝 `crates/horizon-client-render/src/lod.rs` (+5 -0) 📝 `crates/horizon-client-render/src/streaming.rs` (+92 -0) 📝 `crates/horizon-client/src/game.rs` (+21 -0) 📝 `docs/graphics.md` (+1 -1) </details> ### 📄 Description > 🤖 Opened by NerfPhaselock's AI agent (Claude Code, Claude Opus 5.5), not by NerfPhaselock personally. ## What and why Part of #5983 (3 of 4). Translucent Batching's vertex and sorted-index pages grow up to about 2 GiB (#5984) and never shrank, so a page kept its high-water size after the water that filled it was gone: an ocean left behind, a lower render distance. In the run below, render distance 64 then 16 over the ocean leaves 1.48 GB in the arenas for 0.40 GB of vertices. This shrinks them with #3466's mover instead of a second mechanism (the question in #5983): - **Which pages.** One of 64 MiB or more that a right-sized page (`grown(used)`) would halve, or make 256 MiB smaller (`Arena::oversized`). - **How.** The arena opens that page in video memory and closes the large one (`Arena::open_page`, `begin_shrink`). #3466's `move_off_page` then empties it into the new page within the same copy budget as the section arena's compaction (32 MiB a frame; 8 MiB for sorted indices, which come as many small ranges), and `trim` drops it. Each mesh's pointer switches in the step that records its copy. With no room for the new page, or a range no mesh owns, the page stays as it is and the next try waits 5 s. - **Only once the view has settled** (`ShrinkGate`): a second after terrain stops arriving, in a frame the section arena's compaction copied nothing. The game reports terrain arriving (`Renderer::set_terrain_loading`): the view's outermost columns not all there yet (`ViewArrival`, capped at the server's view distance and given up 30 s after the view last changed), events from the server waiting to be handled, far tiles being sampled, and, for those 30 s, re-meshes and pending uploads. The renderer also waits while translucent sections or far tiles wait to upload. Single player joins its integrated server like a remote one, so streaming alone can't see terrain not sent yet. A shrink under way finishes. - **One change to #3466's mover:** `move_off_page` always moves the first range it is given, so a range larger than the budget no longer keeps a page closed for good (today one over 32 MiB would). **Measured** (RTX 4090 / 7800X3D, 1920x1080, offscreen; ocean at render distance 64, then 16, then 64 again, batching on, the camera flying in place with every frame time recorded; this branch on main 3adcfcbb3 against the same tree without the shrink, one run each): | | Without | With the shrink | |---|---|---| | Arenas at 16 | 1.48 GB | 0.68 GB, from 12 s after the change | | GPU memory allocated at 16 | 1.99 GB | 0.96 GB | | Slowest frame while it shrinks | – | 7.5 ms, as the new page is made; the rest under 3.1 ms (most frames 0.3 ms) | | Arenas back at 64 | 5.90 GB | 5.78 GB | | Slowest frames growing back to 64 | 6.7 ms | 11.3 and 18.0 ms | The last row is the cost: back at a high render distance the shrunk pages grow again, and growth is #5984's one-frame copy into a bigger page. Growing a page by the same per-frame budget would be a PR of its own. Frozen frames after the shrink match the run without it (117 pixels differ, by one level: less than two shots of one run do); at 64 only the far-terrain band differs, as between any two runs. No validation errors. **Tests.** `arena.rs`: `large_pages_shrink_when_that_halves_them_or_saves_a_page` (the rule, at its edges), `a_large_page_moves_into_one_of_the_size_its_ranges_get` (GPU: vertices and sorted indices move with their data read back and each mesh's pointer following, its other range untouched; the emptied page takes no new range until `trim`; with no video memory for the new page nothing changes and nothing spills to system memory). `gfx.rs`: `shrinking_starts_once_terrain_has_settled` (`ShrinkGate`: the settle time, the budget, the retry). `streaming.rs`: `a_view_has_arrived_once_its_outermost_columns_are_in` (every edge column, the 30 s give-up, a view that changes). GPU tests run on Vulkan and skip without an adapter; CI has none. Not covered by a run yet: DirectX 12, a remote server, splitscreen. ## 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 has no arena. ## Other projects' code none ## Self-check **pr_ready** (`tools/pr_ready.py --quick --base upstream/main` on DESKTOP-4R7C0FC, against upstream/main at 904ef97e5, 3 min 40 s) | Check | Result | | --- | --- | | Scope | ⚠️ 7 files, +580 −37; 615 lines of code: over 500, split it if it can ship in parts | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ❌ 594 run, FAILED (errors=1, skipped=11) (1 min 18 s) | | rustfmt | ✅ (8 s) | | clippy | ✅ (49 s) | | tests: horizon-client, horizon-client-render | ❌ 558 passed, 1 failed (1 min 18 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 | ➖ 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) | Neither failure is this PR's. `native_loot_kinds_stay_hookable` looks for `"\n}\n"` in `horizon-world/src/loot.rs`, which this Windows checkout has with CRLF line endings; it also stopped the run before the render crate's tests, which pass on their own (915 passed, 32 ignored, GPU tests on Vulkan). The Python error is `test_world_input_capture`'s capture helper exiting with 101 on this machine; this PR touches no input code. On size: 615 changed lines, about 250 of them tests. The rule, the move and the gate only make sense together; the binding fix that the move needs went ahead as its own PR (#6181). 🤖 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:27:19 +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#6808
No description provided.