fix(victory-shader): support dynamic BVH descriptor word1, partial dmask, and clamp >=1 TiB directory addresses #535
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/535"
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?
Imported from LooperSalty/AnyXboxX. Originally posted by mauroalvare on 2026-11-27T17:42:29Z.
Change
Updates
image_bvh*_intersect_raydescriptor tracking, result masking, and title-memory directory addressing onmain(a4453083), validated end-to-end on an NVIDIA GeForce RTX 5070 Ti and WARP over synthetic BVH scenes and the realSLOT_MEMORY/SLOT_FAULTSdirectory path:word1& runtimeBOX_SORT(resource.rs,emit/intersect.rs):resource::trackpreviously required descriptor dword 1 (word1) to beTerm::Constto classifyimage_bvh*_intersect_rayasBvhNodes::Memory. Any shader packing a runtime 48-bit BVH base address (from root constants, a constant buffer, or a picked heap view viaSLOT_STRIDES/VIEW_ADDRESSES) into(word0, word1)failed translation withShaderError::Untraceable, even thoughintersect.rsalready readswords[1]from SGPRs at runtime.BvhNodes::Memory { box_sort: Option<bool>, word3: u32 }is recognized from constantword3(word3 >> 28 == bvh::DESCRIPTOR_TYPE). Bit 31 (BOX_SORT) is statically inferred when possible (Term::Const,s_or_b32,s_and_b32,s_lshr_b32), keeping zero-overhead static sorting; when bit 31 is truly dynamic at runtime (box_sort: None),bvh_boxesgates the sorting network on(words[1] & bvh::BOX_SORT) != 0.dmask(1..=0xf) forimage_bvh*_intersect_ray(emit/intersect.rs):gfx10/fields.rsalready decodesdmask.count_ones().max(1)destination VGPRs forMIMGinstructions, butLower::bvhrejected everydmask != 0xf.dmask(1..=0xf) writes the requested channels sequentially intov[dst..dst + popcount(dmask)]and leaves the other VGPRs untouched.dmaskbehavior unspecified. Consecutive VGPR packing is an assumption covered by synthetic tests. Title validation is pending.>= 1 TiBdirectory wraparound aliasing (emit/lower.rs):Lower::memorypreviously masked the high address dword withhi & 0xFFbefore shifting into the 21-bit page index. Addresses at or above 2^40 bytes (1 TiB, e.g.hi = 0x100or0x300) silently wrapped back onto mapped low pages below 128 GiB (returning false BVH hits from the wrong page instead of clamping to the unmapped sentinelMEMORY_PAGES - 1).and hi, 0xFFwithumin(hi, MEMORY_PAGES >> 16)before shifting (1instruction for1instruction, zero runtime overhead), clamping all out-of-range addresses toMEMORY_PAGES - 1.TRANSLATOR_VERSIONis9because the shared title-memory lookup changes DXIL for already-translatable shaders. For addresses outside the directory,SLOT_FAULTSrecords the clamped sentinel pageMEMORY_PAGES - 1.Hardware Profiling Note (RTX 5070 Ti ABBA Benchmark)
ABBA comparison (
a4453083base vs92cc6fd1head, 32,768 threads × 64 steps = 2,097,152image_bvh64_intersect_raycalls/dispatch, 10 warmups + 40 timed dispatches) confirms 100% bit-identical BLAKE3 lane-output hashes across all 11 workloads, zero spurious faults, and zero runtime regression:box32_only0.2816 / 0.28160.2815 / 0.2815-0.04%0box32_2child0.1631 / 0.16320.1632 / 0.16310.00%0box32_l1_coherent0.0369 / 0.03680.0368 / 0.0367-0.27%0box32_8arenas0.3854 / 0.38750.3832 / 0.3858-0.51%0box16_only0.1632 / 0.16320.1632 / 0.1631-0.03%0box16_l1_coherent0.0299 / 0.03000.0297 / 0.0297-0.83%0mixed_box16_box320.2247 / 0.22470.2247 / 0.22470.00%0triangle_only0.0537 / 0.05350.0539 / 0.0538+0.47%0tri_l1_coherent0.0269 / 0.02690.0268 / 0.0268-0.37%0mixed_traversal0.1587 / 0.15860.1585 / 0.1586-0.06%0mixed_pc_faults0.1586 / 0.15860.1586 / 0.15860.00%0We also profiled isolated RTX 5070 Ti diagnostics on
image_bvh64_intersect_raybefore finalizing this PR: varyingbvh_node_wordschunk sizes (1, 2, 3, 4dwords), load alignment (align = 4vs16),NonUniformResourceIndex(truevsfalse), andRWByteAddressBuffer(UAV) vsByteAddressBuffer(SRV) all produced identical timings (±0.2 µs), confirming that post-#476image_bvh64_intersect_rayis already hardware L2-bandwidth-bound on Blackwell (and reading all 16 dwords of a triangle node instead of only the 10 dwords needed regressestriangle_onlyfrom0.054 msto0.162 ms, so the existing selective 10-dword triangle fetch is preserved).Verification
Oracle and test data
crate::bvh::intersectCPU reference, compared bit-for-bit across hits, misses, sorted vs unsorted box children, partialdmaskchannel packing, and faulted page lists on both NVIDIA GeForce RTX 5070 Ti and WARP, plusdxil.dllDXIL validation.intersect_tests.rs. No game, console, or SDK files.main(a4453083):dynamic_bvh_descriptor_word1_and_picked_view_address_match_reference_on_gpu: fails translation withShaderError::Untraceablefor dynamicword1(root constants, runtimeBOX_SORT, and picked heap viewVIEW_ADDRESSES).partial_dmask_bvh_intersect_writes_only_requested_channels_on_gpu: fails translation withShaderError::Unsupported("a ray-tracing node test with 16-bit operands or a partial result")fordmask0x3,0x5,0x1.directory_clamps_addresses_at_or_above_one_tib_without_aliasing: fails on RTX 5070 Ti and WARP becausehi = 0x100/0x300wraps viahi & 0xFFonto mapped page0x100and returns false hits instead ofMISS/[NONE; 4]and faultMEMORY_PAGES - 1.Checklist
E_NOTIMPL), never a fake success.This pull request was prepared with AI coding assistance (Antigravity), with all code reviewed, compiled, and validated locally on an NVIDIA GeForce RTX 5070 Ti and WARP.
Imported from LooperSalty/AnyXboxX. Originally posted by LooperSalty on 2026-11-27T18:38:32Z.
Thanks, the 1 TiB aliasing fix in
Lower::memory()is a real bug fix, and the out-of-range lanes still reach the missing-page path andSLOT_FAULTS. Two things before merge:TRANSLATOR_VERSION. Parts 1 and 2 only make shaders translate that failed before, which the rule invictory-shader/src/lib.rsexempts. Part 3 does not:memory()is the shared title-memory lookup for every buffer, global and BVH access, so the newuminchanges the DXIL of every shader that touches title memory, and caches from earlier builds would keep the aliasing. Please bump it; 3 to 8 are taken by open PRs (#456, #485, #306, #321, #327, #295), so 9 is the next free value (re-bump if another lands first).intersect.rs,dst + out_reg) is an assumption. Please say in the description where it comes from (measured on the title, or assumed). A wrong guess here would silently corrupt hit data.Minor: for an out-of-range address the page written to
SLOT_FAULTSis the clamped one, not the real one; a comment saying so would help whoever reads the fault log.Since
memory()is on every shader's path, we'll also check it in game before merge.Imported from LooperSalty/AnyXboxX. Originally posted by mauroalvare on 2026-11-27T19:34:19Z.
Thanks, @LooperSalty. In
b26315d1I bumpedTRANSLATOR_VERSIONto9so shaders that already translated pick up the directory clamp. The fault code now documents that an out-of-range address reports the sentinel page. The description identifies consecutive VGPR packing for partial BVH masks as an assumption based on ordinary MIMG behavior. The shader suite passed 329 tests with 5 ignored. The three targeted BVH regressions passed on the RTX 5070 Ti and with WARP alone. In-game validation is still pending.Imported from LooperSalty/AnyXboxX. Originally posted by LooperSalty on 2026-11-27T19:43:43Z.
Thanks, that settles both points. After #545, main's
TRANSLATOR_VERSIONis 8, so the only conflict is that line invictory-shader/src/lib.rs: keep 9 when you rebase (no other open PR uses 9). Please force-push after rebasing.Imported from LooperSalty/AnyXboxX. Originally posted by mauroalvare on 2026-11-27T19:49:22Z.
Follow-up after #545. This PR now includes
ec3b7348, whose translator version is8. The branch retains9, the directory clamp, and both sets of BVH tests. The rebased headf0162f92passed 16 intersection tests and the VIctory asset policy. Two benchmarks were ignored.Imported from LooperSalty/AnyXboxX. Originally posted by LooperSalty on 2026-11-28T00:15:34Z.
Main just took #563 (the VIctory copy moved to Vice-Tay
4f15f09e) and #564 (memory stack), and this PR now conflicts inthird_party/victory/crates/victory-shader/src/lib.rs. Please rebase on current main, rerun the tests for the files you touch, and force-push. Main'sTRANSLATOR_VERSIONis now 16, so please take 17 when you resolve that line.Imported from LooperSalty/AnyXboxX. Originally posted by LooperSalty on 2026-11-28T00:16:14Z.
Correction to my note above: #456 (open) already moved
TRANSLATOR_VERSIONto 17, so please take 18 here instead (and re-bump if another translation change lands first).View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.