perf(rt,gpu): speed up BVH traversal, add ListSync/quarantine, and fix multi-heap directory ordering #44

Closed
Vladimir-Human wants to merge 84 commits from upstream-pr/44 into main
Vladimir-Human commented 2026-11-25 21:06:36 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by Vladimir-Human on 2026-11-25T21:06:36Z.


AI-assisted clean-room contribution (victory-shader + victory-gpu, D3D12 hardware/unit tests + synthetic BVH traversal benchmark only — no title files used).

Summary

Optimizes GFX10 compute ray/box intersection emission and fixes BVH directory / multi-heap / quarantine / parallel-pipeline soundness issues across 6 files (victory-shader/src/{bvh.rs, resource.rs, emit/intersect.rs, emit/intersect_tests.rs} and victory-gpu/src/{memory.rs, pipeline.rs}):

  1. GFX10 compute BVH traversal & descriptor lowering (bvh.rs, resource.rs, emit/intersect.rs):
    • Lane-guarded kind < 6 bvh_address & directory lookup with cold copy == 0 fault path skipping page 0 and sentinel MEMORY_PAGES - 1, unified first 64-byte box fetch, intra-page box32 single-lookup fast path, wrapping cross-page byte2 - 64 fix (page2_off = 0x4000 & 0), partial dmask (1..=0xf) channel packing, pure 32-bit address math, 8/16B aligned raw loads, and dynamic BVH descriptor word1 + zero_base tracking.
  2. GPU memory directory, heap-before-directory ordering, multi-heap recycling & RT quarantine (memory.rs):
    • Sibling page migration: when a loose window replaces a superseded copy on revalidate, migrates sibling pages still pointing at the old slot while skipping active registered buffers (merge_sorted_spans / overlaps_any_buffer).
    • Heap-before-directory ordering & Release fences: allocates/initializes heap.dynamic(COPIES + 1) -> null_raw_uav_at before directory/copies/faults mutation, publishes write_copy_uav with a Release fence before assign_page, clears retired quiescent slots (> RETIRE_DELAY_FRAMES), and gates multi-heap slot recycling via slot_cleared_heaps.
    • Adds ListSync per-list epoch tracking, 64B-aligned 4 GiB constant address extraction, 64-bit volatile fault scans, and VICTORY_BVH_QUARANTINE=1 in-place placement skip (ALLOW_CROSS_ADAPTER, keeping shadow.rs untouched).
  3. Deduplicated parallel builder batch verification (pipeline.rs):
    • Shares Pending builder handles across concurrent requests and verifies verify_builder_batch in parallel outside BUILDER.lock(), preserving klbf-lab's skipped_shader / library::crashed prewarm guards.
  • Disjoint scope: zero edits to shadow.rs, opt.rs, emit/lower.rs, emit/lds.rs, or indirect.rs (git merge-tree clean against beta and sibling PRs #41, #42, and our indirect-gather PR).

Verification (beta e328c88, RTX 4070 SUPER / i5-13400F)

  • cargo clippy -p victory-shader --all-targets -- -D warnings: 0 warnings.
  • cargo clippy -p victory-gpu --all-targets: 0 warnings in touched files (memory.rs, pipeline.rs).
  • cargo test -p victory-shader --all-targets: 227 passed, 0 failed (incl. dynamic word1, partial dmask, and real-directory cross-page box32 hardware GPU tests).
  • cargo test -p victory-gpu -- --test-threads=1: 160 passed, 0 failed.
  • cargo test -p victory-shader bench_bvh_intersect_gpu -- --ignored --nocapture (during parallel build load; uncontested benchmark follow-up planned): box32_memory 243.71 us, box16_memory 187.39 us, divergent_memory 328.70 us, tri_memory 139.26 us, box32_resource 238.59 us, tri_resource 122.88 us (all 6 workloads parity=OK, spurious_faults=0).
<!-- greyfinch-sync:PastiiJay/klbf-lab:issue:5499180275 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/44). Originally posted by [Vladimir-Human](https://github.com/Vladimir-Human) on 2026-11-25T21:06:36Z. --- AI-assisted clean-room contribution (`victory-shader` + `victory-gpu`, D3D12 hardware/unit tests + synthetic BVH traversal benchmark only — no title files used). ### Summary Optimizes GFX10 compute ray/box intersection emission and fixes BVH directory / multi-heap / quarantine / parallel-pipeline soundness issues across 6 files (`victory-shader/src/{bvh.rs, resource.rs, emit/intersect.rs, emit/intersect_tests.rs}` and `victory-gpu/src/{memory.rs, pipeline.rs}`): 1. **GFX10 compute BVH traversal & descriptor lowering (`bvh.rs`, `resource.rs`, `emit/intersect.rs`)**: - Lane-guarded `kind < 6` `bvh_address` & directory lookup with cold `copy == 0` fault path skipping page `0` and sentinel `MEMORY_PAGES - 1`, unified first 64-byte box fetch, intra-page `box32` single-lookup fast path, wrapping cross-page `byte2 - 64` fix (`page2_off = 0x4000` & `0`), partial `dmask` (`1..=0xf`) channel packing, pure 32-bit address math, 8/16B aligned raw loads, and dynamic BVH descriptor `word1` + `zero_base` tracking. 2. **GPU memory directory, heap-before-directory ordering, multi-heap recycling & RT quarantine (`memory.rs`)**: - **Sibling page migration**: when a loose window replaces a superseded copy on `revalidate`, migrates sibling pages still pointing at the old slot while skipping active registered buffers (`merge_sorted_spans` / `overlaps_any_buffer`). - **Heap-before-directory ordering & `Release` fences**: allocates/initializes `heap.dynamic(COPIES + 1)` -> `null_raw_uav_at` before directory/copies/faults mutation, publishes `write_copy_uav` with a `Release` fence before `assign_page`, clears retired quiescent slots (`> RETIRE_DELAY_FRAMES`), and gates multi-heap slot recycling via `slot_cleared_heaps`. - Adds `ListSync` per-list epoch tracking, 64B-aligned 4 GiB constant address extraction, 64-bit volatile fault scans, and `VICTORY_BVH_QUARANTINE=1` in-place placement skip (`ALLOW_CROSS_ADAPTER`, keeping `shadow.rs` untouched). 3. **Deduplicated parallel builder batch verification (`pipeline.rs`)**: - Shares `Pending` builder handles across concurrent requests and verifies `verify_builder_batch` in parallel outside `BUILDER.lock()`, preserving `klbf-lab`'s `skipped_shader` / `library::crashed` prewarm guards. - **Disjoint scope**: zero edits to `shadow.rs`, `opt.rs`, `emit/lower.rs`, `emit/lds.rs`, or `indirect.rs` (`git merge-tree` clean against `beta` and sibling PRs `#41`, `#42`, and our indirect-gather PR). ### Verification (`beta` `e328c88`, RTX 4070 SUPER / i5-13400F) - `cargo clippy -p victory-shader --all-targets -- -D warnings`: **0 warnings**. - `cargo clippy -p victory-gpu --all-targets`: **0 warnings** in touched files (`memory.rs`, `pipeline.rs`). - `cargo test -p victory-shader --all-targets`: **227 passed, 0 failed** (incl. dynamic `word1`, partial `dmask`, and real-directory cross-page `box32` hardware GPU tests). - `cargo test -p victory-gpu -- --test-threads=1`: **160 passed, 0 failed**. - `cargo test -p victory-shader bench_bvh_intersect_gpu -- --ignored --nocapture` (during parallel build load; uncontested benchmark follow-up planned): `box32_memory 243.71 us`, `box16_memory 187.39 us`, `divergent_memory 328.70 us`, `tri_memory 139.26 us`, `box32_resource 238.59 us`, `tri_resource 122.88 us` (**all 6 workloads `parity=OK, spurious_faults=0`**).
PastiiJay commented 2026-11-25 21:07:59 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-25T21:07:59Z.


Thanks a lot @Vladimir-Human! We test one change at a time on the RX 9070 XT (same save, same 7-minute run, fps and picture compared with our reference build), so this one goes into that queue on its own. Results will be posted here, then we merge or report back what we saw.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7174655288 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/44#issuecomment-7174655288). Originally posted by [PastiiJay](https://github.com/PastiiJay) on 2026-11-25T21:07:59Z. --- Thanks a lot @Vladimir-Human! We test one change at a time on the RX 9070 XT (same save, same 7-minute run, fps and picture compared with our reference build), so this one goes into that queue on its own. Results will be posted here, then we merge or report back what we saw.
HandshakeHackin commented 2026-11-26 04:29:18 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by HandshakeHackin on 2026-11-26T04:29:18Z.


I tested 2e41aaf on native Windows WARP. I extended the PR’s 64-bit BVH intersection fixture from two output masks on the first batch to all 15 nonempty masks on all 10 batches. All 4,800 lane results matched the scalar reference, including the registers that each mask leaves untouched. The empty mask was still rejected. The fixture ran 150 dispatches.

I also ran the cross-page box32 fixture with WARP explicitly required. Both offsets for the second page (0 and 0x4000) produced the expected intersections. Only the two expected fault-table entries were written. These checks changed the test fixtures only. In-game performance on the RX 9070 XT remains for the hardware run. Windows test log

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7182638083 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/44#issuecomment-7182638083). Originally posted by [HandshakeHackin](https://github.com/HandshakeHackin) on 2026-11-26T04:29:18Z. --- I tested `2e41aaf` on native Windows WARP. I extended the PR’s 64-bit BVH intersection fixture from two output masks on the first batch to all 15 nonempty masks on all 10 batches. All 4,800 lane results matched the scalar reference, including the registers that each mask leaves untouched. The empty mask was still rejected. The fixture ran 150 dispatches. I also ran the cross-page `box32` fixture with WARP explicitly required. Both offsets for the second page (`0` and `0x4000`) produced the expected intersections. Only the two expected fault-table entries were written. These checks changed the test fixtures only. In-game performance on the RX 9070 XT remains for the hardware run. [Windows test log](https://github.com/HandshakeHackin/klbf-lab/actions/runs/45755215978/job/139692137148)
PastiiJay commented 2026-11-26 10:42:20 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by PastiiJay on 2026-11-26T10:42:20Z.


Thanks for widening the BVH fixture to every mask. The ray tracing side is next on our in-game list.

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7189722729 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/44#issuecomment-7189722729). Originally posted by [PastiiJay](https://github.com/PastiiJay) on 2026-11-26T10:42:20Z. --- Thanks for widening the BVH fixture to every mask. The ray tracing side is next on our in-game list.
Vladimir-Human commented 2026-11-28 18:30:02 +00:00 (Migrated from github.com)

Imported from PastiiJay/klbf-lab. Originally posted by Vladimir-Human on 2026-11-28T18:30:02Z.


Superseded by https://github.com/PastiiJay/klbf-lab/pull/187 cleanly ported onto origin/stable-amd (75022ba).

<!-- greyfinch-sync:PastiiJay/klbf-lab:comment:7243836389 --> Imported from [PastiiJay/klbf-lab](https://github.com/PastiiJay/klbf-lab/pull/44#issuecomment-7243836389). Originally posted by [Vladimir-Human](https://github.com/Vladimir-Human) on 2026-11-28T18:30:02Z. --- Superseded by https://github.com/PastiiJay/klbf-lab/pull/187 cleanly ported onto `origin/stable-amd` (`75022ba`).

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
PastiiJay/klbf-lab!44
No description provided.