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

Closed
mgunes1311-lab wants to merge 2 commits from upstream-pr/2040 into main
mgunes1311-lab commented 2026-11-25 03:55:32 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mgunes1311-lab on 2026-11-25T03:55:32Z.


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
<!-- greyfinch-sync:Marvisak/VIctory:issue:6596852067 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2040). Originally posted by [mgunes1311-lab](https://github.com/mgunes1311-lab) on 2026-11-25T03:55:32Z. --- 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 commented 2026-11-25 04:07:13 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-25T04:01:10Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7152453061 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2040#issuecomment-7152453061). Originally posted by [jeremygold02](https://github.com/jeremygold02) on 2026-11-25T04:01:10Z. --- **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.
DenRakEiw commented 2026-11-25 05:05:42 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T04:06:54Z.

Review: APPROVED


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

<!-- greyfinch-sync:Marvisak/VIctory:review:6051715674 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2040#pullrequestreview-6051715674). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-25T04:06:54Z. **Review:** APPROVED --- 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 commented 2026-11-25 05:05:42 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T04:17:01Z.

Review: APPROVED


Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f69b, 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.

<!-- greyfinch-sync:Marvisak/VIctory:review:6051785858 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2040#pullrequestreview-6051785858). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T04:17:01Z. **Review:** APPROVED --- Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f69b, `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 commented 2026-11-25 05:06:19 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by upipibi on 2026-11-25T04:30:32Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7152906117 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2040#issuecomment-7152906117). Originally posted by [upipibi](https://github.com/upipibi) on 2026-11-25T04:30:32Z. --- 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).
Marvisak commented 2026-11-25 10:07:37 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T09:18:39Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7158158790 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2040#issuecomment-7158158790). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T09:18:39Z. --- <!-- 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)_
sinan-cmyk commented 2026-11-25 10:07:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-25T09:38:01Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7158593879 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2040#issuecomment-7158593879). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-25T09:38:01Z. --- ### 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).
bvtterbroot commented 2026-11-25 19:06:27 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by bvtterbroot on 2026-11-25T18:40:11Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7171229107 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2040#issuecomment-7171229107). Originally posted by [bvtterbroot](https://github.com/bvtterbroot) on 2026-11-25T18:40:11Z. --- 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)._
upstream-sync closed this pull request 2026-11-25 23:03:37 +00:00
Marvisak commented 2026-11-25 23:05:57 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T22:05:00Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7175912742 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2040#issuecomment-7175912742). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T22:05:00Z. --- 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

Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!2038
No description provided.