[pr-performance] shadow,onepass,heap_twin: bound one-pass windows, open emitter lazily, LPT-sort dirty spans #218

Open
hingeowl wants to merge 2 commits from hingeowl/Darner:pr/onepass-lpt-spans into main
Contributor

Re-submitted from the previous CodeFloe repository (original PR #165, commit 0bb0d6b0db27c64153965b57ffd6fc8bc43f9559, preserving original authorship by Ethan Anderson) so it is not lost after the forge move.

What it changes

  • Clamps speculative pre-opened one-pass send windows to [16 MiB, 32 MiB] in host::send::onepass.
  • Pads hot atomics (ACTIVE, TOP, META) to 128 B, aligns window slices to 64 B (WC_ALIGN), and reuses thread-local scratch buffers across emits.
  • Captures the slot forget-epoch up front (onepass::slot_epoch) and opens the emitter lazily in Shadow::take_into only on the first changed page.
  • Replaces single-element largest_first with descending LPT sorting for dirty spans in Batch::refresh_front_spans.
  • Checks !used.load(Relaxed) before SeqCst store in heap_twin::note_used.

Notes

  • Rebased cleanly onto main (f3840d7).
  • Submitted primarily to preserve the patch on GTA Hub for review/testing; standalone A/B on current main has not been run yet.
Re-submitted from the previous CodeFloe repository (original PR #165, commit `0bb0d6b0db27c64153965b57ffd6fc8bc43f9559`, preserving original authorship by Ethan Anderson) so it is not lost after the forge move. ### What it changes - Clamps speculative pre-opened one-pass send windows to `[16 MiB, 32 MiB]` in `host::send::onepass`. - Pads hot atomics (`ACTIVE`, `TOP`, `META`) to 128 B, aligns window slices to 64 B (`WC_ALIGN`), and reuses thread-local scratch buffers across emits. - Captures the slot forget-epoch up front (`onepass::slot_epoch`) and opens the emitter lazily in `Shadow::take_into` only on the first changed page. - Replaces single-element `largest_first` with descending LPT sorting for dirty spans in `Batch::refresh_front_spans`. - Checks `!used.load(Relaxed)` before `SeqCst` store in `heap_twin::note_used`. ### Notes - Rebased cleanly onto `main` (`f3840d7`). - Submitted primarily to preserve the patch on GTA Hub for review/testing; standalone A/B on current `main` has not been run yet.
Reduce per-frame CPU overhead and D3D12 upload-heap churn during shadow
refreshes and one-pass sends:

- Clamp speculative pre-opened one-pass send windows to [16 MiB, 32 MiB]
  in host::send::onepass so steady small frames do not overflow on
  camera-cut bursts and load outliers do not force repeated >BIG upload
  heap churn.
- Pad hot atomics (ACTIVE, TOP, META) to 128 B and align window slices
  to 64 B (WC_ALIGN) in shadow::onepass; reuse thread-local scratch
  buffers across emits.
- Capture the slot forget-epoch up front (onepass::slot_epoch) and open
  the emitter lazily in Shadow::take_into only on the first changed
  page, using a zero-allocation word_runs_and_update_into scratch buffer.
- Replace single-element largest_first with descending LPT sorting for
  dirty spans in Batch::refresh_front_spans.
- Check !used.load(Relaxed) before SeqCst store in heap_twin::note_used.

(cherry picked from commit 0bb0d6b0db27c64153965b57ffd6fc8bc43f9559)
First-time contributor

CHANGES NEEDED

Review of 252ae44fd.

Both strict Clippy gates fail on the new unnecessary_sort_by warnings in crates/darner-gpu/src/host.rs:17106 and :17111. Replace the comparator sorts with the suggested sort_unstable_by_key forms (using Reverse) so the workspace gates pass.

Windows validation: G1 FAIL; G2 FAIL (the two Clippy warnings above); cargo xtask policy PASS (555 files ok); heap_twin tests — 9 passed, 0 failed; onepass tests — 8 passed, 0 failed.

Not run in-game.

AI-assisted: yes (GitHub Copilot, Auto mode).

**CHANGES NEEDED** Review of `252ae44fd`. Both strict Clippy gates fail on the new `unnecessary_sort_by` warnings in `crates/darner-gpu/src/host.rs:17106` and `:17111`. Replace the comparator sorts with the suggested `sort_unstable_by_key` forms (using `Reverse`) so the workspace gates pass. Windows validation: G1 FAIL; G2 FAIL (the two Clippy warnings above); `cargo xtask policy` PASS (`555 files ok`); `heap_twin` tests — 9 passed, 0 failed; `onepass` tests — 8 passed, 0 failed. Not run in-game. AI-assisted: yes (GitHub Copilot, Auto mode).
First-time contributor

Replay A/B on RTX 5070 Ti: no measurable difference

Measured 252ae44fde merged on top of release v2026.12.03.02, against the plain release, on a ~6.5 minute replay route (same save, recorded controller input) through a cutscene, a scene cut and a stretch of free play.

Build fps (range) CPU prep ms median ms p95 ms p99 ms frames over 100 ms per run
v2026.12.03.02 (3 runs) 38.30 (38.17-38.46) 9.57 26.8 29.8 37.8 20 / 11 / 8
+ PR 218 (2 runs) 38.24 (38.19-38.30) 9.74 27.1 28.8 34.3 7 / 8

Crashes: none in any run (no device loss, no host GPU failure). Fps means are within the release's own run-to-run spread, so: no measurable difference on this route. With only 3 release runs, that spread is not well known yet; differences under ~2-3% can't be resolved here.

Config: RTX 5070 Ti 16 GB, Ryzen 7 9800X3D, 32 GB RAM, Windows 11; scripts\play-nvidia.ps1 -Build release (Series X, 1440p native, DLSS Quality, no frame generation, fullscreen, no fps cap). Each build had one unmeasured warm-up run first. The release base excludes its first measured run, which was still compiling shaders (about 3,300 compiles during the route).

Measured unattended on a replay bench (same save, recorded controller input); numbers and text prepared with Claude.

### Replay A/B on RTX 5070 Ti: no measurable difference Measured `252ae44fde` merged on top of release v2026.12.03.02, against the plain release, on a ~6.5 minute replay route (same save, recorded controller input) through a cutscene, a scene cut and a stretch of free play. | Build | fps (range) | CPU prep ms | median ms | p95 ms | p99 ms | frames over 100 ms per run | |---|---:|---:|---:|---:|---:|---:| | v2026.12.03.02 (3 runs) | 38.30 (38.17-38.46) | 9.57 | 26.8 | 29.8 | 37.8 | 20 / 11 / 8 | | + PR 218 (2 runs) | 38.24 (38.19-38.30) | 9.74 | 27.1 | 28.8 | 34.3 | 7 / 8 | Crashes: none in any run (no device loss, no host GPU failure). Fps means are within the release's own run-to-run spread, so: **no measurable difference** on this route. With only 3 release runs, that spread is not well known yet; differences under ~2-3% can't be resolved here. Config: RTX 5070 Ti 16 GB, Ryzen 7 9800X3D, 32 GB RAM, Windows 11; `scripts\play-nvidia.ps1 -Build release` (Series X, 1440p native, DLSS Quality, no frame generation, fullscreen, no fps cap). Each build had one unmeasured warm-up run first. The release base excludes its first measured run, which was still compiling shaders (about 3,300 compiles during the route). Measured unattended on a replay bench (same save, recorded controller input); numbers and text prepared with Claude.
Author
Contributor

Fixed in e4dafb3: replaced both comparator sorts in crates/darner-gpu/src/host.rs (:17106 and :17111) with sort_unstable_by_key + std::cmp::Reverse.

Validation on e4dafb3:

  • cargo clippy -p darner-gpu --all-targets --all-features --locked -- -D warnings — passed.

Ready for re-review.

Fixed in `e4dafb3`: replaced both comparator sorts in `crates/darner-gpu/src/host.rs` (`:17106` and `:17111`) with `sort_unstable_by_key` + `std::cmp::Reverse`. Validation on `e4dafb3`: - `cargo clippy -p darner-gpu --all-targets --all-features --locked -- -D warnings` — passed. Ready for re-review.
Author
Contributor

cam-city ABBA Benchmark on RTX 4090 + 7950X3D: Consistent Regression (+8.2% Median Frame Time)

Tested e4dafb3 against main (f3840d7) in a full ABBA sequence (A1 -> B1 -> B2 -> A2) on the full 172 s cam-city route using bench-kit (with the foot.py pinsfix update), after warming pipelines on main.

Per-Run Results (all tagged rows, ~176 s)

Run Build Overall FPS Median FPS Median ms p95 ms p99 ms >100 ms prep_ms (med) card_idle_ms (med) card_lists_ms (med) pipe_made
A1 main (f3840d7) 10.45 11.04 90.54 131.99 169.24 36.7% 81.12 59.83 29.19 2
B1 PR #218 (e4dafb3) 9.60 10.03 99.73 146.06 183.25 49.4% 86.40 66.51 29.77 4
B2 PR #218 (e4dafb3) 9.66 9.97 100.31 140.32 172.29 50.6% 84.84 63.78 29.43 3
A2 main (f3840d7) 10.22 10.60 94.33 135.69 167.99 42.6% 83.17 62.06 29.22 0
Mean A main 10.34 10.82 92.44 133.84 168.62 39.7% 82.14 60.94 29.21 —
Mean B PR #218 9.63 (-6.8%) 10.00 (-7.6%) 100.02 (+8.2%) 143.19 (+7.0%) 177.77 (+5.4%) 50.0% 85.62 (+4.2%) 65.15 (+6.9%) 29.60 (+1.3%) —

Segment Breakdown (Median Frame Time)

  • Segment 1 (fast): A = 112.26, 113.37 ms (mean 112.82 ms) → B = 117.92, 109.91 ms (mean 113.92 ms, +1.0%)
  • Segment 2 (slow): A = 83.37, 85.38 ms (mean 84.38 ms) → B = 91.15, 83.19 ms (mean 87.17 ms, +3.3%)

Summary

  • Measurable regression on cam-city: both PR #218 runs (99.73, 100.31 ms median) landed outside main's A1–A2 spread (90.54, 94.33 ms), with overall FPS down -6.8%, p95 up +7.0%, prep_ms up +4.2%, and frames >100 ms rising from 39.7% to 50.0%.
  • Note: B1 had near-zero pipe_wait_ms (9 ms) and still matched B2 at 99.73 ms median, so the slowdown is not attributable to pipeline compilation.
  • All 4 runs passed cam-bench.py clean checks (RESULT: camera route flown, clean) with zero crashes or device losses.

Environment

  • Hardware / OS: NVIDIA GeForce RTX 4090 (24 GB, driver 621.14), AMD Ryzen 9 7950X3D, Windows 11 Pro (build 26300).
  • Build: cargo build --release --locked -p darner --features bench-remote.
  • Settings: bench-kit (pinsfix foot.py), cam-city (172 s), Series X profile, HW RT enabled (DARNER_HW_RT=1, DARNER_BVH_BUILDER=1), play.rs DEFAULT_ENV tuning, no frame generation.
### `cam-city` ABBA Benchmark on RTX 4090 + 7950X3D: Consistent Regression (+8.2% Median Frame Time) Tested **`e4dafb3`** against **`main` (`f3840d7`)** in a full ABBA sequence (`A1 -> B1 -> B2 -> A2`) on the full 172 s `cam-city` route using `bench-kit` (with the `foot.py` pinsfix update), after warming pipelines on `main`. #### Per-Run Results (`all tagged rows`, ~176 s) | Run | Build | Overall FPS | Median FPS | Median ms | p95 ms | p99 ms | >100 ms | `prep_ms` (med) | `card_idle_ms` (med) | `card_lists_ms` (med) | `pipe_made` | |---|---|---:|---:|---:|---:|---:|---:|---:|---:|---:|---:| | A1 | `main` (`f3840d7`) | 10.45 | 11.04 | 90.54 | 131.99 | 169.24 | 36.7% | 81.12 | 59.83 | 29.19 | 2 | | B1 | PR #218 (`e4dafb3`) | 9.60 | 10.03 | 99.73 | 146.06 | 183.25 | 49.4% | 86.40 | 66.51 | 29.77 | 4 | | B2 | PR #218 (`e4dafb3`) | 9.66 | 9.97 | 100.31 | 140.32 | 172.29 | 50.6% | 84.84 | 63.78 | 29.43 | 3 | | A2 | `main` (`f3840d7`) | 10.22 | 10.60 | 94.33 | 135.69 | 167.99 | 42.6% | 83.17 | 62.06 | 29.22 | 0 | | **Mean A** | **`main`** | **10.34** | **10.82** | **92.44** | **133.84** | **168.62** | **39.7%** | **82.14** | **60.94** | **29.21** | — | | **Mean B** | **PR #218** | **9.63 (-6.8%)** | **10.00 (-7.6%)** | **100.02 (+8.2%)** | **143.19 (+7.0%)** | **177.77 (+5.4%)** | **50.0%** | **85.62 (+4.2%)** | **65.15 (+6.9%)** | **29.60 (+1.3%)** | — | #### Segment Breakdown (Median Frame Time) - **Segment 1 (fast):** A = `112.26, 113.37 ms` (mean `112.82 ms`) → B = `117.92, 109.91 ms` (mean `113.92 ms`, **+1.0%**) - **Segment 2 (slow):** A = `83.37, 85.38 ms` (mean `84.38 ms`) → B = `91.15, 83.19 ms` (mean `87.17 ms`, **+3.3%**) #### Summary - **Measurable regression on `cam-city`:** both PR #218 runs (`99.73, 100.31 ms` median) landed outside `main`'s A1–A2 spread (`90.54, 94.33 ms`), with overall FPS down **-6.8%**, p95 up **+7.0%**, `prep_ms` up **+4.2%**, and frames >100 ms rising from **39.7% to 50.0%**. - Note: `B1` had near-zero `pipe_wait_ms` (`9 ms`) and still matched `B2` at `99.73 ms` median, so the slowdown is not attributable to pipeline compilation. - All 4 runs passed `cam-bench.py` clean checks (`RESULT: camera route flown, clean`) with zero crashes or device losses. #### Environment - **Hardware / OS:** NVIDIA GeForce RTX 4090 (24 GB, driver `621.14`), AMD Ryzen 9 7950X3D, Windows 11 Pro (build `26300`). - **Build:** `cargo build --release --locked -p darner --features bench-remote`. - **Settings:** `bench-kit` (`pinsfix` `foot.py`), `cam-city` (172 s), Series X profile, HW RT enabled (`DARNER_HW_RT=1`, `DARNER_BVH_BUILDER=1`), `play.rs` `DEFAULT_ENV` tuning, no frame generation.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'pr/onepass-lpt-spans:hingeowl-pr/onepass-lpt-spans'
git switch 'hingeowl-pr/onepass-lpt-spans'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'hingeowl-pr/onepass-lpt-spans'
git switch 'hingeowl-pr/onepass-lpt-spans'
git rebase 'main'
git switch 'main'
git merge --ff-only 'hingeowl-pr/onepass-lpt-spans'
git switch 'hingeowl-pr/onepass-lpt-spans'
git rebase 'main'
git switch 'main'
git merge --no-ff 'hingeowl-pr/onepass-lpt-spans'
git switch 'main'
git merge --squash 'hingeowl-pr/onepass-lpt-spans'
git switch 'main'
git merge --ff-only 'hingeowl-pr/onepass-lpt-spans'
git switch 'main'
git merge 'hingeowl-pr/onepass-lpt-spans'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
3 participants
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
TrustNo1/Darner!218
No description provided.