perf(rt): zero-waterfall wave-uniform SRV BVH walker and single-lookup Box32 #287
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/TaynanGT--Vice-Tay!287
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-287"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@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 · openSummary
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:
Box32fast path (crates/victory-shader/src/emit/intersect.rs)bvh_memory(low + 64)lookup inbvh_second_half()behind(low & 0xFFFF) >= 0xFFC0. Becausebvh_address()is always 64-byte aligned, on the1,023 / 1,024(99.902%) same-page path all 28Box32dwords (112bytes) 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).bvh_memory()lookup inside the active-lane (begin_guarded) and valid-kind (is_box | is_triangle) guard so masked-out and kind6/7lanes never touchSLOT_MEMORYorSLOT_FAULTS.intersect.rs,bvh.rs,lib.rs)waveReadLaneFirst.i32+icmp eq+waveAllTrueinbvh_with_handle()on non-PS stages so coherent compute waves take a uniformcreateHandleFromHeap(nonuniform = false, zeroNonUniformResourceIndexwaterfall), joining only plaini32PHIs (zero%dx.types.HandlePHIs). Pixel shaders (StageIo::Ps) fall back directly toNonUniformResourceIndexfor helper-lane safety.tvia DXILFMad(opcode 46), keeping box slabs(b - origin) * invand watertight triangle cross products unfused to preserve axis-aligned NaN safety, Sterbenz precision far from the origin, and shared-edge antisymmetry.TRANSLATOR_VERSIONfrom9to10(rebased ontomain7728185).lower.rs,shader.rs,mod.rs,memory.rs,draw.rs,host.rs,host/place.rs)ByteAddressBufferSRV 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).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.intersect_tests.rs,memory.rs,host/rtbench.rs)0x0000/0xFF80) vs cross-page (0xFFC0)Box32nodes, unmapped fault pages and masked-out lanes, coherent/divergent SRV vs UAV waves, separate uniform-CS vs helper-lane PS fallback coverage, and intra-listUAV -> SRV -> UAVcoherency on aCOMMONbuffer under D3D12 Debug.ID3D12QueryHeapSM 6.6 (cs_6_6)rtbench(--ignored) comparing the baseline 2-lookupNonUniformResourceIndexUAV path against the 1-lookup wave-uniform SRV path with bit-exact parity.GPU Benchmark (
host::rtbench,--release, RTX 4070 SUPER)ID3D12QueryHeapmedian of 5 runs,3,686,400rays x48Box32nodes/ray over a full 16 MiB (MEMORY_PAGES) directory, with bit-exact output parity asserted across intra-page and cross-page (0xFFC0) nodes:17,342.5 us(17.34 ms)14,416.9 us(14.42 ms)-2,925.6 us(-16.9%)1.20x37,461.0 us(37.46 ms)28,140.5 us(28.14 ms)-9,320.5 us(-24.9%)1.33x59,565.1 us(59.57 ms)34,917.4 us(34.92 ms)-24,647.7 us(-41.4%)1.71x139,657.2 us(139.66 ms)103,348.2 us(103.35 ms)-36,309.0 us(-26.0%)1.35xVerification
cargo clippy -p victory-shader -p victory-gpu --all-targets -- -D warnings(default &--features diagnostics): 0 warningscargo run -p xtask -- policy --staged&cargo test -p xtask: 11/11 passed, policy cleanvictory-shader(VICTORY_D3D12_DEBUG=1,dxil.dllvalidation):bvh16/16,intersect_tests11/11 HW & 11/11 WARPvictory-gpu(VICTORY_D3D12_DEBUG=1,0ID3D12InfoQueueerrors):memory::tests3/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.@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.
bf125c807dtob79d989118@Vladimir-Human on GitHub · 2026-11-27 13:52 UTC · original
Rebased cleanly onto
main(7728185, clean merge-tree against latestmain) and updatedTRANSLATOR_VERSIONfrom9 -> 10incrates/victory-shader/src/lib.rs(commitb79d9891).Coverage addressing each review point (all verified on both HW RTX 4070 SUPER and WARP under
VICTORY_D3D12_DEBUG=1withdxil.dllvalidation and bit-exact ray-result parity againstbvh::intersect_fusedon HW /bvh::intersecton WARP):Box32(0xFFC0) & masked-out lanes:emit::intersect_tests::box32_same_page_and_cross_page_directory_on_the_cardruns a realSLOT_MEMORY+SLOT_FAULTSdirectory on HW and WARP testing intra-page0x0000/0xFF80(with an unmapped successor page proving no spurious second lookup/fault), cross-page0xFFC0spanning two distinct copies (with poison bytes immediately after page 0), cross-page0xFFC0with an unmapped second page (children 0..1 hit, 2..3 masked toNONE, only missing page faulted), and masked-out lanes pointing at an unmapped page (output untouched, zero faults recorded).emit::intersect_tests::wave_uniform_and_divergent_srv_vs_uav_on_the_cardexercises both coherent (uniformWaveReadLaneFirst+WaveAllTruepath) and divergent (NonUniformResourceIndexfallback) 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_safetyverifies the identicalStageIo::Csprogram emitswave_ops == truewhileStageIo::Psskips wave ops (wave_ops == false, falling back toNonUniformResourceIndexfor helper-lane safety), passesdxil.dllvalidation, and still routes read-only walks throughUSER_MEMORY_SRV_BASE.UAV <-> SRVcoherency:memory::tests::intra_list_uav_srv_uav_coherency_on_common_bufferrunsUAV write -> RO SRV read -> UAV overwriteon the sameCOMMON-stateuav_bufferinside a singleHostListviaHostList::note_memory_accesswith0ID3D12InfoQueueerrors on both HW and WARP.@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
b79d989for timing. #258 and #289 also declare translator version 10.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.Merge
Merge the changes and update on Forgejo.