perf(rt): zero-waterfall wave-uniform SRV BVH walker and single-lookup Box32 #287

Open
github-bot wants to merge 1 commit from github-bot/gh-287 into main AGit
Owner

@⁠Vladimir-Human on GitHub · 2026-11-27 13:40 UTC · original
Vladimir-Human:perf/rt-zero-waterfall-srv-bvh → main · +1943 −141 · 13 files · 1 commits · open

Summary

Eliminates redundant directory lookups, descriptor waterfalls, and uncached raw UAV reads in by-address ray-tracing BVH walkers while keeping builders and storing shaders on coherent raw UAVs:

  1. Single-lookup & single-handle Box32 fast path (crates/victory-shader/src/emit/intersect.rs)
    • Guards the second bvh_memory(low + 64) lookup in bvh_second_half() behind (low & 0xFFFF) >= 0xFFC0. Because bvh_address() is always 64-byte aligned, on the 1,023 / 1,024 (99.902%) same-page path all 28 Box32 dwords (112 bytes) lie in the same 64 KiB page and view slot and issue under one descriptor handle and one wave-uniform check (at most 1 divergent waterfall instead of 2).
    • Moves the initial bvh_memory() lookup inside the active-lane (begin_guarded) and valid-kind (is_box | is_triangle) guard so masked-out and kind 6/7 lanes never touch SLOT_MEMORY or SLOT_FAULTS.
  2. Wave-uniform handle fast path & selective FMA (intersect.rs, bvh.rs, lib.rs)
    • Emits waveReadLaneFirst.i32 + icmp eq + waveAllTrue in bvh_with_handle() on non-PS stages so coherent compute waves take a uniform createHandleFromHeap (nonuniform = false, zero NonUniformResourceIndex waterfall), joining only plain i32 PHIs (zero %dx.types.Handle PHIs). Pixel shaders (StageIo::Ps) fall back directly to NonUniformResourceIndex for helper-lane safety.
    • Fuses triangle shearing and hit distance t via DXIL FMad (opcode 46), keeping box slabs (b - origin) * inv and watertight triangle cross products unfused to preserve axis-aligned NaN safety, Sterbenz precision far from the origin, and shared-edge antisymmetry.
    • Bumps TRANSLATOR_VERSION from 9 to 10 (rebased onto main 7728185).
  3. Parallel read-only raw SRV run for non-storing walkers (lower.rs, shader.rs, mod.rs, memory.rs, draw.rs, host.rs, host/place.rs)
    • Allocates a parallel read-only raw ByteAddressBuffer SRV run (USER_MEMORY_SRV_BASE = 0x107, DXIL properties (11, 0)) alongside the raw UAV run (2 * (COPIES + 1) dynamic slots per heap) for read-only non-storing shaders (!store && !stores_by_address); builders and storing shaders continue using raw UAVs (11 | 0x1000 | coherent).
    • Tracks both UAV writes (by-address builders and regular buffer-storing dispatches/draws) and RO SRV reads in HostList::note_memory_access, emitting a global cache-coherency barrier (place::wait_for_all) on both RAW (UAV -> SRV) and WAR (SRV -> UAV) transitions inside a command list with zero barriers on pure walker or pure non-RT recordings.
  4. Tests & GPU Timestamp Benchmark (intersect_tests.rs, memory.rs, host/rtbench.rs)
    • Adds real-directory HW & WARP tests covering intra-page (0x0000/0xFF80) vs cross-page (0xFFC0) Box32 nodes, unmapped fault pages and masked-out lanes, coherent/divergent SRV vs UAV waves, separate uniform-CS vs helper-lane PS fallback coverage, and intra-list UAV -> SRV -> UAV coherency on a COMMON buffer under D3D12 Debug.
    • Adds ID3D12QueryHeap SM 6.6 (cs_6_6) rtbench (--ignored) comparing the baseline 2-lookup NonUniformResourceIndex UAV path against the 1-lookup wave-uniform SRV path with bit-exact parity.

GPU Benchmark (host::rtbench, --release, RTX 4070 SUPER)

ID3D12QueryHeap median of 5 runs, 3,686,400 rays x 48 Box32 nodes/ray over a full 16 MiB (MEMORY_PAGES) directory, with bit-exact output parity asserted across intra-page and cross-page (0xFFC0) nodes:

Workload Baseline (2-lookup NonUniform UAV) New (1-lookup Wave-Uniform SRV) Delta Speedup
VRAM coherent 17,342.5 us (17.34 ms) 14,416.9 us (14.42 ms) -2,925.6 us (-16.9%) 1.20x
VRAM divergent (2 copies/wave) 37,461.0 us (37.46 ms) 28,140.5 us (28.14 ms) -9,320.5 us (-24.9%) 1.33x
VRAM divergent (8 copies/wave) 59,565.1 us (59.57 ms) 34,917.4 us (34.92 ms) -24,647.7 us (-41.4%) 1.71x
PC-RAM coherent 139,657.2 us (139.66 ms) 103,348.2 us (103.35 ms) -36,309.0 us (-26.0%) 1.35x

Verification

  • cargo clippy -p victory-shader -p victory-gpu --all-targets -- -D warnings (default & --features diagnostics): 0 warnings
  • cargo run -p xtask -- policy --staged & cargo test -p xtask: 11/11 passed, policy clean
  • victory-shader (VICTORY_D3D12_DEBUG=1, dxil.dll validation): bvh 16/16, intersect_tests 11/11 HW & 11/11 WARP
  • victory-gpu (VICTORY_D3D12_DEBUG=1, 0 ID3D12InfoQueue errors): memory::tests 3/3 HW (default & diagnostics) & 3/3 WARP (incl. intra_list_uav_srv_uav_coherency_on_common_buffer)
**@⁠Vladimir-Human** on GitHub · 2026-11-27 13:40 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/287) `Vladimir-Human:perf/rt-zero-waterfall-srv-bvh` → `main` · +1943 −141 · 13 files · 1 commits · open ## Summary Eliminates redundant directory lookups, descriptor waterfalls, and uncached raw UAV reads in by-address ray-tracing BVH walkers while keeping builders and storing shaders on coherent raw UAVs: 1. **Single-lookup & single-handle `Box32` fast path (`crates/victory-shader/src/emit/intersect.rs`)** - Guards the second `bvh_memory(low + 64)` lookup in `bvh_second_half()` behind `(low & 0xFFFF) >= 0xFFC0`. Because `bvh_address()` is always 64-byte aligned, on the `1,023 / 1,024` (`99.902%`) same-page path all 28 `Box32` dwords (`112` bytes) lie in the same 64 KiB page and view slot and issue under **one** descriptor handle and **one** wave-uniform check (at most 1 divergent waterfall instead of 2). - Moves the initial `bvh_memory()` lookup inside the active-lane (`begin_guarded`) and valid-kind (`is_box | is_triangle`) guard so masked-out and kind `6`/`7` lanes never touch `SLOT_MEMORY` or `SLOT_FAULTS`. 2. **Wave-uniform handle fast path & selective FMA (`intersect.rs`, `bvh.rs`, `lib.rs`)** - Emits `waveReadLaneFirst.i32` + `icmp eq` + `waveAllTrue` in `bvh_with_handle()` on non-PS stages so coherent compute waves take a uniform `createHandleFromHeap` (`nonuniform = false`, zero `NonUniformResourceIndex` waterfall), joining only plain `i32` PHIs (zero `%dx.types.Handle` PHIs). Pixel shaders (`StageIo::Ps`) fall back directly to `NonUniformResourceIndex` for helper-lane safety. - Fuses triangle shearing and hit distance `t` via DXIL `FMad` (opcode 46), keeping box slabs `(b - origin) * inv` and watertight triangle cross products unfused to preserve axis-aligned NaN safety, Sterbenz precision far from the origin, and shared-edge antisymmetry. - Bumps `TRANSLATOR_VERSION` from `9` to `10` (rebased onto `main` `7728185`). 3. **Parallel read-only raw SRV run for non-storing walkers (`lower.rs`, `shader.rs`, `mod.rs`, `memory.rs`, `draw.rs`, `host.rs`, `host/place.rs`)** - Allocates a parallel read-only raw `ByteAddressBuffer` SRV run (`USER_MEMORY_SRV_BASE = 0x107`, DXIL properties `(11, 0)`) alongside the raw UAV run (`2 * (COPIES + 1)` dynamic slots per heap) for read-only non-storing shaders (`!store && !stores_by_address`); builders and storing shaders continue using raw UAVs (`11 | 0x1000 | coherent`). - Tracks both UAV writes (by-address builders and regular buffer-storing dispatches/draws) and RO SRV reads in `HostList::note_memory_access`, emitting a global cache-coherency barrier (`place::wait_for_all`) on both RAW (`UAV -> SRV`) and WAR (`SRV -> UAV`) transitions inside a command list with zero barriers on pure walker or pure non-RT recordings. 4. **Tests & GPU Timestamp Benchmark (`intersect_tests.rs`, `memory.rs`, `host/rtbench.rs`)** - Adds real-directory HW & WARP tests covering intra-page (`0x0000`/`0xFF80`) vs cross-page (`0xFFC0`) `Box32` nodes, unmapped fault pages and masked-out lanes, coherent/divergent SRV vs UAV waves, separate uniform-CS vs helper-lane PS fallback coverage, and intra-list `UAV -> SRV -> UAV` coherency on a `COMMON` buffer under D3D12 Debug. - Adds `ID3D12QueryHeap` SM 6.6 (`cs_6_6`) `rtbench` (`--ignored`) comparing the baseline 2-lookup `NonUniformResourceIndex` UAV path against the 1-lookup wave-uniform SRV path with bit-exact parity. ## GPU Benchmark (`host::rtbench`, `--release`, RTX 4070 SUPER) `ID3D12QueryHeap` median of 5 runs, `3,686,400` rays x `48` `Box32` nodes/ray over a full 16 MiB (`MEMORY_PAGES`) directory, with bit-exact output parity asserted across intra-page and cross-page (`0xFFC0`) nodes: | Workload | Baseline (2-lookup NonUniform UAV) | New (1-lookup Wave-Uniform SRV) | Delta | Speedup | |---|---:|---:|---:|---:| | VRAM coherent | `17,342.5 us` (`17.34 ms`) | `14,416.9 us` (`14.42 ms`) | `-2,925.6 us` (`-16.9%`) | `1.20x` | | VRAM divergent (2 copies/wave) | `37,461.0 us` (`37.46 ms`) | `28,140.5 us` (`28.14 ms`) | `-9,320.5 us` (`-24.9%`) | `1.33x` | | VRAM divergent (8 copies/wave) | `59,565.1 us` (`59.57 ms`) | `34,917.4 us` (`34.92 ms`) | `-24,647.7 us` (`-41.4%`) | `1.71x` | | PC-RAM coherent | `139,657.2 us` (`139.66 ms`) | `103,348.2 us` (`103.35 ms`) | `-36,309.0 us` (`-26.0%`) | `1.35x` | ## Verification - `cargo clippy -p victory-shader -p victory-gpu --all-targets -- -D warnings` (default & `--features diagnostics`): **0 warnings** - `cargo run -p xtask -- policy --staged` & `cargo test -p xtask`: **11/11 passed**, policy clean - `victory-shader` (`VICTORY_D3D12_DEBUG=1`, `dxil.dll` validation): `bvh` **16/16**, `intersect_tests` **11/11 HW** & **11/11 WARP** - `victory-gpu` (`VICTORY_D3D12_DEBUG=1`, `0` `ID3D12InfoQueue` errors): `memory::tests` **3/3 HW** (default & `diagnostics`) & **3/3 WARP** (incl. `intra_list_uav_srv_uav_coherency_on_common_buffer`)
Eliminates redundant directory lookups, descriptor waterfalls, and uncached raw
UAV reads in by-address ray-tracing BVH walkers:

1. Single-lookup & single-handle Box32 fast path (`intersect.rs`):
   - Guards the second `bvh_memory(low + 64)` lookup in `bvh_second_half()`
     behind `(low & 0xFFFF) >= 0xFFC0`. Because `bvh_address()` is always
     64-byte aligned, on the 1,023 / 1,024 (99.902%) same-page path all 28
     dwords (112 bytes) stay inside the same 64 KiB page and view slot and
     issue under ONE handle and ONE wave-uniform check.
   - Moves initial `bvh_memory()` inside the active-lane and valid-kind
     (`is_box | is_triangle`) guard so masked-out and kind 6/7 lanes never
     touch `SLOT_MEMORY` or `SLOT_FAULTS`.
2. Wave-uniform handle fast path & selective FMA (`intersect.rs`, `bvh.rs`):
   - Emits `waveReadLaneFirst.i32` + `icmp eq` + `waveAllTrue` in
     `bvh_with_handle()` on non-PS stages so coherent compute waves use a
     uniform `createHandleFromHeap` (zero `NonUniformResourceIndex` waterfall),
     joining only plain `i32` PHIs (zero `%dx.types.Handle` PHIs); pixel
     shaders fall back to `NonUniformResourceIndex` for helper-lane safety.
   - Fuses triangle shearing and hit distance `t` via DXIL `FMad` (opcode 46),
     keeping box slabs `(b - origin) * inv` and watertight edge cross products
     unfused to preserve axis-aligned NaN safety, Sterbenz precision, and
     shared-edge antisymmetry.
   - Bumps `TRANSLATOR_VERSION` from 8 to 9.
3. Parallel read-only raw SRV run for non-storing walkers (`lower.rs`,
   `shader.rs`, `memory.rs`, `draw.rs`, `host.rs`):
   - Allocates parallel read-only raw `ByteAddressBuffer` SRV views alongside
     the raw UAV run (`USER_MEMORY_SRV_BASE = 0x107`, DXIL props `(11, 0)`),
     routing read-only non-storing shaders through read-only caches while
     keeping builders and storing shaders on raw UAVs.
   - Tracks both UAV writes (by-address builders and regular buffer-storing
     dispatches/draws) and RO SRV reads in `HostList::note_memory_access`,
     emitting a global cache-coherency barrier (`place::wait_for_all`) on both
     RAW (`UAV -> SRV`) and WAR (`SRV -> UAV`) transitions inside a command
     list with zero barriers on pure walker or pure non-RT recordings.
4. Verification (`intersect_tests.rs`, `memory.rs`, `host/rtbench.rs`):
   - Adds D3D12 HW & WARP real-directory tests for intra-page vs cross-page
     (`0xFFC0`) Box32 nodes, unmapped fault pages, coherent/divergent SRV vs
     UAV waves, PS helper-lane wave-op exclusion, and intra-list
     `UAV -> SRV -> UAV` coherency on a `COMMON` buffer under D3D12 Debug.
   - Adds `ID3D12QueryHeap` SM 6.6 `rtbench` microbenchmark (`--ignored`)
     measuring 2-lookup NonUniform UAV vs 1-lookup Wave-Uniform SRV with
     bit-exact parity.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 13:47:54 +00:00
Author
Owner

@⁠TaynanGT on GitHub · 2026-11-27 13:43 UTC · original

@⁠Vladimir-Human The cross-page Box32 case and masked lanes matter here. Keep the uniform compute path and pixel helper-lane fallback separately covered. Use the same ray results and the right translator cache key before measuring the runtime benefit.

**@⁠TaynanGT** on GitHub · 2026-11-27 13:43 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/287#issuecomment-7219866926) @⁠Vladimir-Human The cross-page Box32 case and masked lanes matter here. Keep the uniform compute path and pixel helper-lane fallback separately covered. Use the same ray results and the right translator cache key before measuring the runtime benefit.
github-bot force-pushed github-bot/gh-287 from bf125c807d to b79d989118 2026-11-27 14:02:00 +00:00 Compare
Author
Owner

@⁠Vladimir-Human on GitHub · 2026-11-27 13:52 UTC · original

Rebased cleanly onto main (7728185, clean merge-tree against latest main) and updated TRANSLATOR_VERSION from 9 -> 10 in crates/victory-shader/src/lib.rs (commit b79d9891).

Coverage addressing each review point (all verified on both HW RTX 4070 SUPER and WARP under VICTORY_D3D12_DEBUG=1 with dxil.dll validation and bit-exact ray-result parity against bvh::intersect_fused on HW / bvh::intersect on WARP):

  1. Cross-page Box32 (0xFFC0) & masked-out lanes: emit::intersect_tests::box32_same_page_and_cross_page_directory_on_the_card runs a real SLOT_MEMORY + SLOT_FAULTS directory on HW and WARP testing intra-page 0x0000 / 0xFF80 (with an unmapped successor page proving no spurious second lookup/fault), cross-page 0xFFC0 spanning two distinct copies (with poison bytes immediately after page 0), cross-page 0xFFC0 with an unmapped second page (children 0..1 hit, 2..3 masked to NONE, only missing page faulted), and masked-out lanes pointing at an unmapped page (output untouched, zero faults recorded).
  2. Separate uniform compute vs pixel helper-lane fallback:
    • emit::intersect_tests::wave_uniform_and_divergent_srv_vs_uav_on_the_card exercises both coherent (uniform WaveReadLaneFirst + WaveAllTrue path) and divergent (NonUniformResourceIndex fallback) compute waves across read-only SRV (USER_MEMORY_SRV_BASE) and UAV (USER_MEMORY_BASE) modes on HW and WARP with bit-exact parity.
    • emit::intersect_tests::pixel_shader_bvh_memory_skips_wave_ops_for_helper_lane_safety verifies the identical StageIo::Cs program emits wave_ops == true while StageIo::Ps skips wave ops (wave_ops == false, falling back to NonUniformResourceIndex for helper-lane safety), passes dxil.dll validation, and still routes read-only walks through USER_MEMORY_SRV_BASE.
  3. Intra-list UAV <-> SRV coherency: memory::tests::intra_list_uav_srv_uav_coherency_on_common_buffer runs UAV write -> RO SRV read -> UAV overwrite on the same COMMON-state uav_buffer inside a single HostList via HostList::note_memory_access with 0 ID3D12InfoQueue errors on both HW and WARP.
**@⁠Vladimir-Human** on GitHub · 2026-11-27 13:52 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/287#issuecomment-7220042980) Rebased cleanly onto `main` (`7728185`, clean merge-tree against latest `main`) and updated `TRANSLATOR_VERSION` from **`9 -> 10`** in `crates/victory-shader/src/lib.rs` (commit `b79d9891`). Coverage addressing each review point (all verified on both HW RTX 4070 SUPER and WARP under `VICTORY_D3D12_DEBUG=1` with `dxil.dll` validation and bit-exact ray-result parity against `bvh::intersect_fused` on HW / `bvh::intersect` on WARP): 1. **Cross-page `Box32` (`0xFFC0`) & masked-out lanes:** `emit::intersect_tests::box32_same_page_and_cross_page_directory_on_the_card` runs a real `SLOT_MEMORY` + `SLOT_FAULTS` directory on HW and WARP testing intra-page `0x0000` / `0xFF80` (with an unmapped successor page proving no spurious second lookup/fault), cross-page `0xFFC0` spanning two distinct copies (with poison bytes immediately after page 0), cross-page `0xFFC0` with an unmapped second page (children 0..1 hit, 2..3 masked to `NONE`, only missing page faulted), and masked-out lanes pointing at an unmapped page (output untouched, zero faults recorded). 2. **Separate uniform compute vs pixel helper-lane fallback:** - `emit::intersect_tests::wave_uniform_and_divergent_srv_vs_uav_on_the_card` exercises both coherent (uniform `WaveReadLaneFirst` + `WaveAllTrue` path) and divergent (`NonUniformResourceIndex` fallback) compute waves across read-only SRV (`USER_MEMORY_SRV_BASE`) and UAV (`USER_MEMORY_BASE`) modes on HW and WARP with bit-exact parity. - `emit::intersect_tests::pixel_shader_bvh_memory_skips_wave_ops_for_helper_lane_safety` verifies the identical `StageIo::Cs` program emits `wave_ops == true` while `StageIo::Ps` skips wave ops (`wave_ops == false`, falling back to `NonUniformResourceIndex` for helper-lane safety), passes `dxil.dll` validation, and still routes read-only walks through `USER_MEMORY_SRV_BASE`. 3. **Intra-list `UAV <-> SRV` coherency:** `memory::tests::intra_list_uav_srv_uav_coherency_on_common_buffer` runs `UAV write -> RO SRV read -> UAV overwrite` on the same `COMMON`-state `uav_buffer` inside a single `HostList` via `HostList::note_memory_access` with `0` `ID3D12InfoQueue` errors on both HW and WARP.
Author
Owner

@⁠TaynanGT on GitHub · 2026-11-27 14:11 UTC · original

@⁠Vladimir-Human The missing second page and masked-lane tests cover the Box32 boundary I was concerned about. The compute/pixel split and the UAV/SRV coherency test cover the other two paths. Use a cache directory dedicated to b79d989 for timing. #258 and #289 also declare translator version 10.

**@⁠TaynanGT** on GitHub · 2026-11-27 14:11 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/287#issuecomment-7220457054) @⁠Vladimir-Human The missing second page and masked-lane tests cover the Box32 boundary I was concerned about. The compute/pixel split and the UAV/SRV coherency test cover the other two paths. Use a cache directory dedicated to `b79d989` for timing. #258 and #289 also declare translator version 10.
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/lib.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/287/head:github-bot/gh-287'
git switch 'github-bot/gh-287'

Merge

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