Skip to content

Shaders: 64-bit built BVH pointers and unsplit node loads - #2040

Closed
mgunes1311-lab wants to merge 2 commits into
Marvisak:mainfrom
mgunes1311-lab:fix/bvh-built-pointer-64
Closed

mgunes1311-lab wants to merge 2 commits into
Marvisak:mainfrom
mgunes1311-lab:fix/bvh-built-pointer-64

Conversation

@mgunes1311-lab

Copy link
Copy Markdown
Contributor

Fix two bugs in Lower::bvh (crates/victory-shader/src/emit/lower/bvh.rs):

  1. Root-built BVH descriptors truncated pointer and base arithmetic to 32 bits and dropped node_hi:
    When resource::track resolved a BVH descriptor built by shifting a root SRV/UAV address (Source::Built), Lower::bvh shifted (node & !7) << 3 and added built_offset in 32-bit i32 before widening to 64 bits, ignored node_hi on image_bvh64_intersect_ray, did not mask the shifted base to bits 8..47 (0x0000_FFFF_FFFF_FF00), and did not reject 64-bit node pointers on non-address built buffer views.

    • Compute (root + zext(k) + zext(dynamic)) & 0x0000_FFFF_FFFF_FF00 in 64-bit integers and share the 64-bit (lo | hi << 32) << 3 node address calculation with the unbuilt descriptor path.
    • Reject image_bvh64_intersect_ray when Source::Built resolves to a buffer view without a root GPU address.
  2. Divergent begin_guarded blocks around Lower::memory zeroed BVH node loads on WARP:
    Unlike global_load and raw_view, Lower::bvh wrapped bvh_lanes in begin_guarded(guard) and the box32 tail load in begin_guarded(Some(is32)). Because Lower::memory emits createHandleFromHeap(..., nonUniform = true) followed by begin_guarded(marks) before rawBufferLoad, entering Lower::memory inside a lane-divergent branch caused WARP to read zeros for active lanes whenever lane 0 of the wave was inactive (breaking box32 children 2-3 in bvh_tests on WARP and all node types under masked EXEC).

    • Run both node loads unsplit, passing guard and guard & is32 as active to Lower::memory so inactive or non-box32 lanes never mark stray page misses.
    • Clamp the box32 tail load's byte offset with select(is32, 64, 0) so 64-byte nodes re-read byte 0 of their own page or buffer rather than probing past byte 64.

Verification

  • cargo test -p victory-shader --lib bvh_tests (all 17 tests pass on both hardware D3D12 and WARP)
  • cargo clippy --workspace --all-targets --all-features -- -D warnings
  • cargo doc --workspace --no-deps (with -D warnings)
  • cargo run -p xtask -- policy --staged and cargo test -p xtask

@jeremygold02

Copy link
Copy Markdown
Contributor

Triage verdict — Keep, ready on the reviewed BVH cases (7216eb7)

Evidence

Checks and limits

  • The exact-head BVH group passed 17 tests. A disposable run of the same production code required both hardware D3D12 and WARP to execute the new cases. Both completed.
  • A separate synthetic control put an active box32 node’s first half at the end of a mapped page and left the tail page unmapped. Both backends set exactly the tail-page bit and matched the CPU reference with a zero tail. The existing masked-lane and page-end checks still passed. Windows CI

Next step

This verification was AI-assisted.

@DenRakEiw DenRakEiw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified locally merged onto origin/main (940d32f, Windows 11 x64, NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC, with dxil.dll validator):

  • cargo test -p victory-shader --lib emit::bvh_tests:: — 17 passed, 0 failed on both RTX 5090 hardware and VICTORY_D3D12_WARP=1 (including root_srv_bvh_handles_high_pointer_bits_and_unaligned_bases, masked_lanes_and_page_end_nodes_leave_no_stray_marks, and sixty_four_bit_bvh_pointer_in_non_address_built_view_is_refused)
  • cargo clippy -p victory-shader --all-targets — 0 warnings
  • cargo xtask policy — ok (183 files ok)

Clean 64-bit built BVH pointer handling and unsplit node loads with comprehensive GPU+WARP verification. Looks great.

AI-assisted (Gemini 4 Neon).

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f, cargo test -p victory-shader --locked.

144 passed / 0 failed. 64-bit built BVH pointers and unsplit node loads — BVH traversal with 64-bit pointers; relates to #1794's BVH a16/unsorted-boxes work.

@upipibi

upipibi commented Nov 25, 2026

Copy link
Copy Markdown

Ran on Windows 11 with an RTX 3070 (Ampere, driver 616.56), debug build, at 7216eb7. victory-shader: 247 passed, 3 failed, 3 ignored. The 3 new bvh_tests pass (root_srv_bvh_handles_high_pointer_bits_and_unaligned_bases, masked_lanes_and_page_end_nodes_leave_no_stray_marks, sixty_four_bit_bvh_pointer_in_non_address_built_view_is_refused). The 3 failures are #1744's NVIDIA failures on main. Same as main on this hardware. Not run: a title.

AI-assisted (Claude Code).

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.
Merge candidate.

This fixes two things in crates/victory-shader/src/emit/lower/bvh.rs Lower::bvh. First, a BVH descriptor built from a root address now gets its node address in 64-bit arithmetic and honours node_hi, through the same (lo | hi << 32) << 3 path the unbuilt descriptor already uses. The base is masked to bits 8..47, the same representation main decodes for real descriptors (40-bit base << 8). A 64-bit pointer into a buffer view is now refused instead of silently truncated. Second, the node loads in bvh_lanes / node_dwords / raw_load are no longer split into divergent guarded blocks; inactive lanes are instead masked through Lower::memory's existing active argument, and non-box32 lanes re-read their own first 64 bytes. I checked that this matches how Lower::memory uses active (page-miss marks only). Three new bvh_tests cover both fixes, and two independent runs in the thread report them passing on hardware and WARP. #1794 touches the same lowering for other cases and will need a rebase after this.

Recommending a look, not approving.

CI: passing (check).


Generated by Claude Code

@sinan-cmyk

Copy link
Copy Markdown

Offline measurement on a retail dump

Result: no count change against main.

I merged head 7216eb7 onto main 940d32f (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 23,918 on main, 23,918 with this PR.

No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right.

No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

@bvtterbroot

Copy link
Copy Markdown
Contributor

AMD check at 7216eb7 (base 940d32f), on an RDNA3 and an RDNA2 GPU:

  • Windows 11, Rust 1.98.1. Radeon RX 7900 XTX (RDNA3, driver 32.0.32029.2010) and the Ryzen 7 7800X3D's iGPU (RDNA2, gfx1036, driver 32.0.21045.29003). I picked each as the hardware adapter of the shader test host with a local patch that is not part of this PR. WARP runs in each pass as well.
  • cargo test -p victory-shader -p victory-gpu --locked: 393 passed, 0 failed, 5 ignored, on both GPUs. That includes its 3 new tests (masked_lanes_and_page_end_nodes_leave_no_stray_marks, root_srv_bvh_handles_high_pointer_bits_and_unaligned_bases, sixty_four_bit_bvh_pointer_in_non_address_built_view_is_refused).
  • One of four runs on the RX 7900 XTX failed bindless::tests::heap_views_follow_writes_through_another_mapping (dword 0 read 0, expected 1064). That is the flake of Tests bindless::heap_views_* fail intermittently in a full workspace run #2252 (fixed by Tests: release placed descriptor heaps before reusing their memory #2262), which this PR does not touch. The other three runs on that card passed.

Synthetic tests only, no game files. Tested with AI assistance (Claude Code).

@Marvisak

Copy link
Copy Markdown
Owner

Automated triage for the maintainers, second look (a review against current main, with builds and tests where they could change the verdict).

Closing in favour of #2501 for the one fix both make (the Source::Built root-address branch), because the second part rewrites code every title site runs for a defect that does not reproduce: masked_lanes_and_page_end_nodes_leave_no_stray_marks passes with main's bvh.rs on an RX 6700 XT and on WARP, as do main's existing BVH tests. With the change, inactive and non-box lanes would do page-table lookups and loads they do not do today.

If this is mistaken, reply here with what was missed and it will be looked at again. Thank you for the contribution.

@Marvisak Marvisak closed this Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants