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

Closed
github-bot wants to merge 2 commits from gh-pr/2040/head into gh-pr/2040/base
Owner

@⁠mgunes1311-lab on GitHub · 2026-11-25 03:55 UTC · original
mgunes1311-lab:fix/bvh-built-pointer-64 → main · +514 −52 · 2 files · 2 commits · closed without merging

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
**@⁠mgunes1311-lab** on GitHub · 2026-11-25 03:55 UTC · [original](https://github.com/Marvisak/VIctory/pull/2040) `mgunes1311-lab:fix/bvh-built-pointer-64` → `main` · +514 −52 · 2 files · 2 commits · closed without merging 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`
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:52:34 +00:00
github-bot closed this pull request 2026-11-26 04:52:34 +00:00
Author
Owner

@⁠jeremygold02 on GitHub · 2026-11-25 04:01 UTC · original

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

Evidence

  • @⁠mgunes1311-lab preserves high node-pointer bits and applies the descriptor base mask after adding the root offset. The patch also keeps node loads together across lanes, while limiting page-miss marks to active accesses. #1794 adds packed directions and unsorted-box support in the same lowering path. Those cases remain useful after this lands. High-pointer regression · Masked and page-end regression

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

  • Keep the positive page-miss check alongside the no-stray-marks cases if extending this suite. When rebasing #1794, preserve the active masks and the bounded tail offset while carrying forward its format-specific cases.

This verification was AI-assisted.

**@⁠jeremygold02** on GitHub · 2026-11-25 04:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/2040#issuecomment-7152453061) **Triage verdict — Keep, ready on the reviewed BVH cases** (`7216eb7`) **Evidence** - @⁠mgunes1311-lab preserves high node-pointer bits and applies the descriptor base mask after adding the root offset. The patch also keeps node loads together across lanes, while limiting page-miss marks to active accesses. #1794 adds packed directions and unsorted-box support in the same lowering path. Those cases remain useful after this lands. [High-pointer regression](https://github.com/Marvisak/VIctory/blob/7216eb7f313d6037e0457adcc9af98c5aa53fcb8/crates/victory-shader/src/emit/bvh_tests.rs#L1030) · [Masked and page-end regression](https://github.com/Marvisak/VIctory/blob/7216eb7f313d6037e0457adcc9af98c5aa53fcb8/crates/victory-shader/src/emit/bvh_tests.rs#L1139) **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](https://github.com/Marvisak/VIctory/actions/runs/45543280883/job/138966702803) **Next step** - Keep the positive page-miss check alongside the no-stray-marks cases if extending this suite. When rebasing #1794, preserve the active masks and the bounded tail offset while carrying forward its format-specific cases. This verification was AI-assisted.
Author
Owner

@⁠upipibi on GitHub · 2026-11-25 04:30 UTC · original

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).

**@⁠upipibi** on GitHub · 2026-11-25 04:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/2040#issuecomment-7152906117) 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).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 09:18 UTC · original

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

**@⁠Marvisak** on GitHub · 2026-11-25 09:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/2040#issuecomment-7158158790) <!-- victory-triage v1 head=7216eb7f313d6037e0457adcc9af98c5aa53fcb8 verdict=merge-candidate at=2026-11-25T09:18:32Z --> 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](https://claude.ai/code)_
Author
Owner

@⁠sinan-cmyk on GitHub · 2026-11-25 09:38 UTC · original

Offline measurement on a retail dump

Result: no count change against main.

I merged head 7216eb7f 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).

**@⁠sinan-cmyk** on GitHub · 2026-11-25 09:38 UTC · [original](https://github.com/Marvisak/VIctory/pull/2040#issuecomment-7158593879) ### Offline measurement on a retail dump **Result: no count change against `main`.** I merged head 7216eb7f 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).
Author
Owner

@⁠bvtterbroot on GitHub · 2026-11-25 18:40 UTC · original

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 #2252 (fixed by #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).

**@⁠bvtterbroot** on GitHub · 2026-11-25 18:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/2040#issuecomment-7171229107) 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 #2252 (fixed by #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)._
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 22:05 UTC · original

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** on GitHub · 2026-11-25 22:05 UTC · [original](https://github.com/Marvisak/VIctory/pull/2040#issuecomment-7175912742) 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.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2040
No description provided.