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

Open
github-bot wants to merge 1 commit from github-bot/gh-44 into beta AGit
Owner

@⁠Vladimir-Human on GitHub · 2026-11-25 21:06 UTC · original
Vladimir-Human:feat/rt-bvh-quarantine-nvidia → beta · +2542 −338 · 6 files · 1 commits · open

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).
**@⁠Vladimir-Human** on GitHub · 2026-11-25 21:06 UTC · [original](https://github.com/PastiiJay/klbf-lab/pull/44) `Vladimir-Human:feat/rt-bvh-quarantine-nvidia` → `beta` · +2542 −338 · 6 files · 1 commits · open 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`**).
Port compute BVH shader lowering, GPU memory directory quarantine/ordering
fixes, builder verification deduplication, and GPU traversal benchmarks onto
klbf-lab beta:

Shader (victory-shader):
- Track dynamic BVH descriptor word1 (s_or_b32/s_and_b32/s_lshr_b32/s_bfe_u32
  and runtime BOX_SORT bit 31) plus static zero_base in resource.rs, and pack
  partial dmask (1..=0xf) channels without clobbering untouched VGPRs.
- Keep bvh_address and directory lookup inside the lane guard and kind < 6
  gate so masked-out lanes and instance/procedural kinds (6/7) never touch
  SLOT_MEMORY or record spurious SLOT_FAULTS.
- Replace per-node URem + unconditional SLOT_FAULTS[0] sink writes with a cold
  copy == 0 fault branch skipping page 0 and sentinel MEMORY_PAGES - 1, unify
  the first 64-byte box fetch before kind == 5, skip the second directory
  lookup for intra-page 128-byte box32 nodes ((low & 0xffff) < 0xffc0), and
  use pure 32-bit bvh_address arithmetic with 8/16-byte aligned raw loads.
- Add bvh.rs 32-bit split-address tests plus intersect_tests.rs coverage for
  dynamic word1, partial dmask, cross-page box32 (including page2_off = 0
  wrapping) and fault isolation, and the bench_bvh_intersect_gpu benchmark.

GPU runtime (victory-gpu):
- Fix memory.rs in-place placement bias in directory offsets and raw UAV view
  lengths, and skip in-place buffers (D3D12_RESOURCE_FLAG_ALLOW_CROSS_ADAPTER)
  in SLOT_MEMORY while VICTORY_BVH_QUARANTINE=1 so builder stores stay isolated
  from title memory without modifying shadow.rs.
- Protect registered title buffers from loose windows via merged disjoint
  buffer spans, migrate loose-window sibling pages on revalidation while
  skipping active registered buffers (can_claim_sibling_page), and use
  clear-before-rewrite ordering in write_directory_entry.
- Allocate and initialize each heap's dynamic copy range to null_raw_uav
  before mutating directory/copies/faults, publish write_copy_uav with a
  Release fence before assign_page, clear quiescent retired slots back to
  null_raw_uav_at, gate multi-heap slot recycling via slot_cleared_heaps, and
  track per-list read/write epochs via ListSync.
- Catch 64B-aligned low offsets at 4 GiB boundaries in constant address
  extraction, drain faults on new frames and list first-use with 64-bit
  volatile scans, and parallelize BVH builder stage verification in pipeline.rs
  outside BUILDER.lock() while deduplicating shared Pending handles and
  preserving klbf-lab's skipped-shader / crashed-pipeline prewarm checks.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:53:27 +00:00
Author
Owner

@⁠PastiiJay on GitHub · 2026-11-25 21:07 UTC · original

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.

**@⁠PastiiJay** on GitHub · 2026-11-25 21:07 UTC · [original](https://github.com/PastiiJay/klbf-lab/pull/44#issuecomment-7174655288) 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.
Author
Owner

@⁠HandshakeHackin on GitHub · 2026-11-26 04:29 UTC · original

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

**@⁠HandshakeHackin** on GitHub · 2026-11-26 04:29 UTC · [original](https://github.com/PastiiJay/klbf-lab/pull/44#issuecomment-7182638083) 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)
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 origin '+refs/pull/44/head:github-bot/gh-44'
git switch 'github-bot/gh-44'

Merge

Merge the changes and update on Forgejo.
git switch 'beta'
git merge --no-ff 'github-bot/gh-44'
git switch 'github-bot/gh-44'
git rebase 'beta'
git switch 'beta'
git merge --ff-only 'github-bot/gh-44'
git switch 'github-bot/gh-44'
git rebase 'beta'
git switch 'beta'
git merge --no-ff 'github-bot/gh-44'
git switch 'beta'
git merge --squash 'github-bot/gh-44'
git switch 'beta'
git merge --ff-only 'github-bot/gh-44'
git switch 'beta'
git merge 'github-bot/gh-44'
git push origin 'beta'
This discussion has been locked. Commenting is limited to contributors.
No description provided.