[GH-ISSUE #5983] Batch translucent terrain into its own arena #1917

Closed
opened 2026-11-02 15:50:36 +07:00 by bsakaguchi · 1 comment
Owner

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

Originally assigned to: @NerfPhaselock on GitHub.

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

Problem. Translucent quads (water, stained glass, ice) are drawn after the solid ones, back to front. They sit
right after their section's solid quads in the 256 MiB arena pages, so in back-to-front order the next section is in
another page every few sections and draw_sections can only merge short runs. In water-heavy views most of the
remaining draw calls are translucent: about 3,800 a frame over the ocean at render distance 64.

Proposal. Where nothing reads the arenas whole as storage, translucent quads get a vertex arena of their own
whose pages may grow to about 2 GiB (DirectX 12 and OpenGL cap a buffer at i32::MAX), and the sorted-index arena
gets the same cap. The back-to-front list then stays in one vertex page and one index page and goes out as a few
multi-draws, in the same order. Vertex data, sorted indices and draw order are unchanged; only the buffer and offset
holding the translucent vertices move, so the picture is the same.

Measured (RTX 4090 / 7800X3D, 1080p, offscreen, the first PR's branch on main at b6ac0602d; off -> on):

Render distance Scene FPS Draw calls
32 village +7.8 % 395 -> 93
32 forest +11.5 % 337 -> 57
32 ocean +16.1 % 946 -> 81
64 forest +20.1 % 2,070 -> 450
64 ocean +42.8 % 3,832 -> 354
64 mountain +2.4 % (little water) 667 -> 340

1 % lows up too (ocean at 64: 147 -> 195). Pixels: frozen frames no more different than two sessions with the same
setting.

Cost. Solid and translucent quads no longer share free space, and one large page keeps its size while any
loaded section has water: +1-15 % arena memory at render distance 32 and +5-10 % at 64. Shrinking the large
translucent and index pages once the view stops loading brought that to +5-9 % with no FPS cost in an earlier
version. #3466's compaction empties 256 MiB pages into other pages, so it cannot shrink a single large page and does
not compact sorted indices; this needs its own step (or an extension of #3466's mover: a question for its authors
below). A switch, Translucent Batching (Advanced, Performance; applies at the next start), turns it off and gives
exactly the old layout.

Interactions with main (found while porting): flat draws exist on most GPUs for shader-pack terrain and shadow
passes, which read translucent quads from the section arena, so the split applies only while no running pack draws
those flat (a shaders/ pack's terrain or shadow programs, or the [shadow] of one of Horizon's own; sections
re-upload when that changes); compact_arena must move the solid range only; LOD fade stand-ins are included;
OpenGL's CPU-side multi-draw is left out.

Plan (stacked, each under or near 500 lines with its tests):

  1. perf/translucent-arena: the arena, split upload/release/draw, the pack-flat rule, compact_arena split-aware,
    off by default.
  2. perf/translucent-compaction: shrink the large translucent and index pages once the view has settled.
  3. perf/translucent-batching-switch: the switch, default on, docs.

Questions. May three stacked PRs link this one issue? For step 2, would #3466's authors rather have their mover
extended (move a page that cannot empty into others into a new right-sized page, with a per-frame budget) than a
second mechanism?

Originally created by @NerfPhaselock on GitHub (Nov 1, 2026). Original GitHub issue: https://github.com/horizon-rust/horizon/issues/5983 Originally assigned to: @NerfPhaselock on GitHub. > 🤖 Filed by NerfPhaselock's AI agent (Claude Code, Claude Opus 5.5), not by NerfPhaselock personally. **Problem.** Translucent quads (water, stained glass, ice) are drawn after the solid ones, back to front. They sit right after their section's solid quads in the 256 MiB arena pages, so in back-to-front order the next section is in another page every few sections and `draw_sections` can only merge short runs. In water-heavy views most of the remaining draw calls are translucent: about 3,800 a frame over the ocean at render distance 64. **Proposal.** Where nothing reads the arenas whole as storage, translucent quads get a vertex arena of their own whose pages may grow to about 2 GiB (DirectX 12 and OpenGL cap a buffer at `i32::MAX`), and the sorted-index arena gets the same cap. The back-to-front list then stays in one vertex page and one index page and goes out as a few multi-draws, in the same order. Vertex data, sorted indices and draw order are unchanged; only the buffer and offset holding the translucent vertices move, so the picture is the same. **Measured** (RTX 4090 / 7800X3D, 1080p, offscreen, the first PR's branch on main at b6ac0602d; off -> on): | Render distance | Scene | FPS | Draw calls | |---|---|---|---| | 32 | village | +7.8 % | 395 -> 93 | | 32 | forest | +11.5 % | 337 -> 57 | | 32 | ocean | +16.1 % | 946 -> 81 | | 64 | forest | +20.1 % | 2,070 -> 450 | | 64 | ocean | +42.8 % | 3,832 -> 354 | | 64 | mountain | +2.4 % (little water) | 667 -> 340 | 1 % lows up too (ocean at 64: 147 -> 195). Pixels: frozen frames no more different than two sessions with the same setting. **Cost.** Solid and translucent quads no longer share free space, and one large page keeps its size while any loaded section has water: +1-15 % arena memory at render distance 32 and +5-10 % at 64. Shrinking the large translucent and index pages once the view stops loading brought that to +5-9 % with no FPS cost in an earlier version. #3466's compaction empties 256 MiB pages into other pages, so it cannot shrink a single large page and does not compact sorted indices; this needs its own step (or an extension of #3466's mover: a question for its authors below). A switch, Translucent Batching (Advanced, Performance; applies at the next start), turns it off and gives exactly the old layout. **Interactions with main** (found while porting): flat draws exist on most GPUs for shader-pack terrain and shadow passes, which read translucent quads from the section arena, so the split applies only while no running pack draws those flat (a `shaders/` pack's terrain or shadow programs, or the `[shadow]` of one of Horizon's own; sections re-upload when that changes); `compact_arena` must move the solid range only; LOD fade stand-ins are included; OpenGL's CPU-side multi-draw is left out. **Plan** (stacked, each under or near 500 lines with its tests): 1. `perf/translucent-arena`: the arena, split upload/release/draw, the pack-flat rule, `compact_arena` split-aware, off by default. 2. `perf/translucent-compaction`: shrink the large translucent and index pages once the view has settled. 3. `perf/translucent-batching-switch`: the switch, default on, docs. **Questions.** May three stacked PRs link this one issue? For step 2, would #3466's authors rather have their mover extended (move a page that cannot empty into others into a new right-sized page, with a per-frame budget) than a second mechanism?
Author
Owner

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

🤖 Agent: /claim

<!-- gh-comment-id:6558872858 --> @NerfPhaselock commented on GitHub (Nov 1, 2026): 🤖 Agent: /claim
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#1917
No description provided.