[PR #4747] [MERGED] LOD: incremental frame path and parallel zero-copy meshing #5827

Closed
opened 2026-11-03 05:15:16 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/4747
Author: @sirrayi
Created: 10/30/2026
Status: ✅ Merged
Merged: 10/31/2026
Merged by: @ludovic111

Base: main ← Head: lod-engine-overhaul


📝 Commits (10+)

  • c5b1959 LOD: incremental frame path and parallel zero-copy meshing
  • 7b2f4bf Merge remote-tracking branch 'origin/main' into lod-engine-overhaul-v2
  • 41490a4 LOD: keep completion, removals and cutout incremental
  • 210c6ee LOD: keep completion, removals and cutout incremental
  • 4f26b75 Merge remote-tracking branch 'origin/main' into lod-engine-overhaul-v2
  • 5bd4653 Merge remote-tracking branch 'origin/main' into review-4747-fixes
  • 11d5d87 Fix incremental LOD result retention
  • 42ffa89 LOD: pin the result-retention rule with a test
  • 576737b Merge remote-tracking branch 'origin/main' into lod-final
  • ea63737 Merge main into #4747

📊 Changes

8 files changed (+1822 additions, -541 deletions)

View changed files

📝 Cargo.lock (+1 -0)
📝 crates/horizon-client-render/Cargo.toml (+1 -0)
📝 crates/horizon-client-render/src/gfx/lod.rs (+5 -16)
📝 crates/horizon-client-render/src/lod.rs (+1669 -434)
📝 crates/horizon-client-render/src/lod/mesh.rs (+138 -88)
📝 crates/horizon-client-render/src/mesher.rs (+5 -0)
📝 crates/horizon-client/src/save.rs (+1 -1)
📝 crates/horizon-client/src/vanillagen/lod.rs (+2 -2)

📄 Description

🤖 Opened by sirrayi's AI agent (omp, DeepSeek V4.1 Flash), not by sirrayi personally.

What and why

The far-terrain (LOD) scheduler evaluated the whole quadtree on the frame thread for every finished sample, cloned every active tile's columns into every mesh job, and gave a whole selection batch to one worker. This makes the frame/tick side incremental and moves the remaining work to parallel workers, on top of current main's circular range, fade in/out, lod/cache.rs and DETAIL_LEVEL full chunks.

  • Incremental selection. A finished sample re-evaluates only its ancestors (O(tree depth)). active/complete are cached per tile; a ready split fallback counts as complete exactly as Plan::select did. Pure completion of an undrawn subtree changes no mesh.
  • Incremental sampling queue. Unsampled final tiles live in a nearest-first heap, rebuilt when the view moves a chunk (73 µs), instead of scanning and sorting every plan node every frame. This keeps current main's nearest-first policy.
  • Zero-copy mesh inputs. A batch shares one immutable snapshot; each tile's input is a base Arc plus overrides, and the mesher borrows &Column. MeshInput::columns() for 256 columns takes ~2–5 µs.
  • Parallel per-tile meshing. A worker pool (cores - samplers - 1, capped) pops a priority queue of one-tile jobs; results carry a revision, so stale batches cannot overwrite newer meshes. Dispatches coalesce while the pool is saturated.
  • No frame-thread vertex scans. LOD meshes track bounds in emit_quad on the worker; gfx::Bounds consumes them instead of walking every vertex per uploaded tile.
  • Correct fade/removal ordering. Removals wait until every overlapping replacement has an accepted mesh. A cutout waits only for the active tiles whose meshes had to stop clipping the changed columns (a retired waiter hands its wait to its active descendants), not for global mesh idleness.
  • Compact columns. Column.spans is an inline SmallVec<[Span; 4]> (80-byte Column); a cold 1024-chunk view creates millions of columns with one allocation each, and this removes almost all of those allocations.
  • Sampling threads scale with cores (half, up to 8) instead of a quarter capped at 3; the 8-core case goes from 2 to 4 samplers.
  • Shutdown. Both worker pools are stopped under their own wait locks, so Lod::drop cannot miss a wake and hang.

What is drawn is unchanged. active is checked to equal Plan::select after every sample, across camera moves and coverage changes; neighbour dirtying, active-descendant redraws, removal gating and cutout sequencing have dedicated tests.

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: distant-terrain LOD has no vanilla counterpart. No vanilla class or harness applies; the horizon-client-render LOD tests and the new scheduler tests cover it.

Measurements

Synthetic LOD bookkeeping benchmark (release, 1024-chunk view, ~7.3k plan nodes), before = the same scheduler code on the previous main (dc35e7817), after = this branch. No game assets are present on this machine, so these isolate scheduler/mesher CPU, not worldgen throughput; the machine was shared, so treat them as order-of-magnitude.

Work Before After
Finished-sample selection + dirty scan 61 + 40 µs/sample ~26 µs update + ~7 µs finish per sample, including dispatch
Unsampled-tile scan 65 µs every frame 0; 73 µs heap rebuild only on chunk/yaw change
Plan + selection rebuild at a chunk crossing n/a (same Plan) ~1 ms
Mesh input (256 columns) 256 column clones + span allocations 2–5 µs by reference
Tile bounds every vertex scanned on the frame thread tracked during emission on the worker
Tile meshing one selection batch, scoped threads inside it per-tile priority jobs on a worker pool

Column is 80 bytes with four inline spans; a cold view's columns no longer allocate per column.

Overlap

This supersedes the dirty-tile scan in #4255 (the quadratic scan is gone entirely, so there is nothing to sort); the FxHashMap mesher change from #4255 is not included and remains compatible. #3468 changes what far tiles are made from and would sit on top of this scheduler.

Self-check

pr_ready (tools/pr_ready.py --quick on MacBookPro, against origin/main at 2509598c1, 12 min 57 s)

Check Result
Scope ⚠️ 8 files, +1626 −514; 2140 lines of code: over 500, split it if it can ship in parts
Cargo.lock ✅ changes with a Cargo.toml
Public tree ✅
Python tests ❌ 458 run, FAILED (errors=13) (1 min 29 s)
rustfmt ✅ (11 s)
clippy ✅ (3 min 5 s)
tests: workspace ✅ 3116 passed (5 min 56 s)
doc tests ✅ 0 passed (8 s)
content root tests ✅ 6 passed (1 min 5 s)
tokens.css up to date ➖ theme untouched
launcher rustfmt ✅ (1 s)
launcher clippy ✅ (19 s)
launcher tests ✅ 300 passed (43 s)
Parity ➖ 359 affected, to run in CI (--quick): active_effect_tick, active_effects, ambient_sound, anchor, arrow, attribute_health, attribute_map_queries, attribute, attribute_updates, audio_attributes, auto_jump, bamboo and 347 more
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

The Python test errors are environmental: this Python lacks hashlib.file_digest (AttributeError, Python < 3.11), raised from tools/lab.py before any changed code runs. All Rust checks and tests pass locally.

🤖 Generated with omp (DeepSeek V4.1 Flash).


🔄 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/4747 **Author:** [@sirrayi](https://github.com/sirrayi) **Created:** 10/30/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `lod-engine-overhaul` --- ### 📝 Commits (10+) - [`c5b1959`](https://github.com/horizon-rust/horizon/commit/c5b195907fd45160a7a05532c9388b7270b7e731) LOD: incremental frame path and parallel zero-copy meshing - [`7b2f4bf`](https://github.com/horizon-rust/horizon/commit/7b2f4bf999534d1e380385eb3f40614c1b8bd15e) Merge remote-tracking branch 'origin/main' into lod-engine-overhaul-v2 - [`41490a4`](https://github.com/horizon-rust/horizon/commit/41490a413d266fc610668c427b248a018adfe772) LOD: keep completion, removals and cutout incremental - [`210c6ee`](https://github.com/horizon-rust/horizon/commit/210c6ee10c3d2a14cd0b089d598220edbd5b04ca) LOD: keep completion, removals and cutout incremental - [`4f26b75`](https://github.com/horizon-rust/horizon/commit/4f26b7543b10774ac6d2c7251d784120d12109ef) Merge remote-tracking branch 'origin/main' into lod-engine-overhaul-v2 - [`5bd4653`](https://github.com/horizon-rust/horizon/commit/5bd465312cf0a551da06a278f537280b3fdfc1e6) Merge remote-tracking branch 'origin/main' into review-4747-fixes - [`11d5d87`](https://github.com/horizon-rust/horizon/commit/11d5d87d1fb0365fb589ab120acd4e7bea6cebef) Fix incremental LOD result retention - [`42ffa89`](https://github.com/horizon-rust/horizon/commit/42ffa89bcab278be76583644adce64ec6f984ec1) LOD: pin the result-retention rule with a test - [`576737b`](https://github.com/horizon-rust/horizon/commit/576737b0f5e74e356fa3634e1229be262998bc47) Merge remote-tracking branch 'origin/main' into lod-final - [`ea63737`](https://github.com/horizon-rust/horizon/commit/ea6373755c0e256b8633091a30db5ad3e83af2ec) Merge main into #4747 ### 📊 Changes **8 files changed** (+1822 additions, -541 deletions) <details> <summary>View changed files</summary> 📝 `Cargo.lock` (+1 -0) 📝 `crates/horizon-client-render/Cargo.toml` (+1 -0) 📝 `crates/horizon-client-render/src/gfx/lod.rs` (+5 -16) 📝 `crates/horizon-client-render/src/lod.rs` (+1669 -434) 📝 `crates/horizon-client-render/src/lod/mesh.rs` (+138 -88) 📝 `crates/horizon-client-render/src/mesher.rs` (+5 -0) 📝 `crates/horizon-client/src/save.rs` (+1 -1) 📝 `crates/horizon-client/src/vanillagen/lod.rs` (+2 -2) </details> ### 📄 Description > 🤖 Opened by sirrayi's AI agent (omp, DeepSeek V4.1 Flash), not by sirrayi personally. ## What and why The far-terrain (LOD) scheduler evaluated the whole quadtree on the frame thread for every finished sample, cloned every active tile's columns into every mesh job, and gave a whole selection batch to one worker. This makes the frame/tick side incremental and moves the remaining work to parallel workers, on top of current `main`'s circular range, fade in/out, `lod/cache.rs` and `DETAIL_LEVEL` full chunks. - **Incremental selection.** A finished sample re-evaluates only its ancestors (`O(tree depth)`). `active`/`complete` are cached per tile; a ready split fallback counts as complete exactly as `Plan::select` did. Pure completion of an undrawn subtree changes no mesh. - **Incremental sampling queue.** Unsampled final tiles live in a nearest-first heap, rebuilt when the view moves a chunk (73 µs), instead of scanning and sorting every plan node every frame. This keeps current main's nearest-first policy. - **Zero-copy mesh inputs.** A batch shares one immutable snapshot; each tile's input is a base `Arc` plus overrides, and the mesher borrows `&Column`. `MeshInput::columns()` for 256 columns takes ~2–5 µs. - **Parallel per-tile meshing.** A worker pool (`cores - samplers - 1`, capped) pops a priority queue of one-tile jobs; results carry a revision, so stale batches cannot overwrite newer meshes. Dispatches coalesce while the pool is saturated. - **No frame-thread vertex scans.** LOD meshes track bounds in `emit_quad` on the worker; `gfx::Bounds` consumes them instead of walking every vertex per uploaded tile. - **Correct fade/removal ordering.** Removals wait until every overlapping replacement has an accepted mesh. A cutout waits only for the active tiles whose meshes had to stop clipping the changed columns (a retired waiter hands its wait to its active descendants), not for global mesh idleness. - **Compact columns.** `Column.spans` is an inline `SmallVec<[Span; 4]>` (80-byte `Column`); a cold 1024-chunk view creates millions of columns with one allocation each, and this removes almost all of those allocations. - **Sampling threads** scale with cores (half, up to 8) instead of a quarter capped at 3; the 8-core case goes from 2 to 4 samplers. - **Shutdown.** Both worker pools are stopped under their own wait locks, so `Lod::drop` cannot miss a wake and hang. What is drawn is unchanged. `active` is checked to equal `Plan::select` after every sample, across camera moves and coverage changes; neighbour dirtying, active-descendant redraws, removal gating and cutout sequencing have dedicated tests. ## 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: distant-terrain LOD has no vanilla counterpart. No vanilla class or harness applies; the `horizon-client-render` LOD tests and the new scheduler tests cover it. ## Measurements Synthetic LOD bookkeeping benchmark (release, 1024-chunk view, ~7.3k plan nodes), before = the same scheduler code on the previous main (`dc35e7817`), after = this branch. No game assets are present on this machine, so these isolate scheduler/mesher CPU, not worldgen throughput; the machine was shared, so treat them as order-of-magnitude. | Work | Before | After | | --- | --- | --- | | Finished-sample selection + dirty scan | 61 + 40 µs/sample | ~26 µs update + ~7 µs finish per sample, including dispatch | | Unsampled-tile scan | 65 µs every frame | 0; 73 µs heap rebuild only on chunk/yaw change | | Plan + selection rebuild at a chunk crossing | n/a (same `Plan`) | ~1 ms | | Mesh input (256 columns) | 256 column clones + span allocations | 2–5 µs by reference | | Tile bounds | every vertex scanned on the frame thread | tracked during emission on the worker | | Tile meshing | one selection batch, scoped threads inside it | per-tile priority jobs on a worker pool | `Column` is 80 bytes with four inline spans; a cold view's columns no longer allocate per column. ## Overlap This supersedes the dirty-tile scan in #4255 (the quadratic scan is gone entirely, so there is nothing to sort); the `FxHashMap` mesher change from #4255 is not included and remains compatible. #3468 changes what far tiles are made from and would sit on top of this scheduler. ## Self-check **pr_ready** (`tools/pr_ready.py --quick` on MacBookPro, against origin/main at 2509598c1, 12 min 57 s) | Check | Result | | --- | --- | | Scope | ⚠️ 8 files, +1626 −514; 2140 lines of code: over 500, split it if it can ship in parts | | Cargo.lock | ✅ changes with a Cargo.toml | | Public tree | ✅ | | Python tests | ❌ 458 run, FAILED (errors=13) (1 min 29 s) | | rustfmt | ✅ (11 s) | | clippy | ✅ (3 min 5 s) | | tests: workspace | ✅ 3116 passed (5 min 56 s) | | doc tests | ✅ 0 passed (8 s) | | content root tests | ✅ 6 passed (1 min 5 s) | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ✅ (1 s) | | launcher clippy | ✅ (19 s) | | launcher tests | ✅ 300 passed (43 s) | | Parity | ➖ 359 affected, to run in CI (--quick): active_effect_tick, active_effects, ambient_sound, anchor, arrow, attribute_health, attribute_map_queries, attribute, attribute_updates, audio_attributes, auto_jump, bamboo and 347 more | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | The Python test errors are environmental: this Python lacks `hashlib.file_digest` (`AttributeError`, Python < 3.11), raised from `tools/lab.py` before any changed code runs. All Rust checks and tests pass locally. 🤖 Generated with omp (DeepSeek V4.1 Flash). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 05:15:16 +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#5827
No description provided.