Shaders: preserve 64-bit node offsets and descriptor alignment in built BVH paths (fixes #2368) #2400

Closed
Xvania7 wants to merge 2 commits from upstream-pr/2402 into main
Xvania7 commented 2026-11-25 12:57:14 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Xvania7 on 2026-11-25T12:57:14Z.


Fixes #2368.

Summary

Addresses the address-calculation inconsistency reported by @FunWithFlagsDev in #2368 between the root-derived (Source::Built) and explicit-address BVH lowering paths.

Previously, crates/victory-shader/src/emit/lower/bvh.rs calculated node offsets in Source::Built using a 32-bit shift (Bin::Shl, lo, three), losing the upper bits of node pointers when offsets crossed 4 GiB, dropping node_hi, and ignoring the descriptor's 256-byte quantization.

Changes

  • In crates/victory-shader/src/emit/lower/bvh.rs:
    • When Source::Built has root memory address available (root_address(src).is_some()), route to the explicit descriptor decoder path instead of truncating via 32-bit arithmetic.
    • Retains 64-bit precision for node pointers (wide64(self, lo, node_hi.unwrap_or(zero)) << 3), preserves the descriptor's 256-byte base quantization (wide64(d[0], d[1] & 0xFF) << 8), and preserves the existing title-memory bounds-checking pipeline.
    • Leaves the buffer-backed fallback (root_address(src).is_none()) and resource tracking unchanged.

Verification

  • cargo test -p victory-shader emit::bvh_tests::boxes_ passed (1/1).
  • cargo test -p victory-shader emit::lower::tests passed (21/21).
  • cargo clippy -p victory-shader passed with 0 warnings.
  • cargo run -p xtask policy verified clean (182 files ok).
<!-- greyfinch-sync:Marvisak/VIctory:issue:6604994954 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2402). Originally posted by [Xvania7](https://github.com/Xvania7) on 2026-11-25T12:57:14Z. --- Fixes #2368. ### Summary Addresses the address-calculation inconsistency reported by @FunWithFlagsDev in #2368 between the root-derived (`Source::Built`) and explicit-address BVH lowering paths. Previously, `crates/victory-shader/src/emit/lower/bvh.rs` calculated node offsets in `Source::Built` using a 32-bit shift (`Bin::Shl, lo, three`), losing the upper bits of node pointers when offsets crossed 4 GiB, dropping `node_hi`, and ignoring the descriptor's 256-byte quantization. ### Changes - In `crates/victory-shader/src/emit/lower/bvh.rs`: - When `Source::Built` has root memory address available (`root_address(src).is_some()`), route to the explicit descriptor decoder path instead of truncating via 32-bit arithmetic. - Retains 64-bit precision for node pointers (`wide64(self, lo, node_hi.unwrap_or(zero)) << 3`), preserves the descriptor's 256-byte base quantization (`wide64(d[0], d[1] & 0xFF) << 8`), and preserves the existing title-memory bounds-checking pipeline. - Leaves the buffer-backed fallback (`root_address(src).is_none()`) and resource tracking unchanged. ### Verification - `cargo test -p victory-shader emit::bvh_tests::boxes_` passed (1/1). - `cargo test -p victory-shader emit::lower::tests` passed (21/21). - `cargo clippy -p victory-shader` passed with 0 warnings. - `cargo run -p xtask policy` verified clean (182 files ok).
catminou4 commented 2026-11-25 14:06:42 +00:00 (Migrated from github.com)

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

Review: APPROVED


Tested locally: merged into main 940d32f69b, cargo test -p victory-shader --locked on macOS arm64 — 144 passed, 0 failed, 2 ignored (Windows-gated hardware execution tests not run here). Approving — 64-bit node offsets and descriptor alignment preserved.

<!-- greyfinch-sync:Marvisak/VIctory:review:6058343303 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2402#pullrequestreview-6058343303). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T13:19:17Z. **Review:** APPROVED --- Tested locally: merged into main 940d32f69b, `cargo test -p victory-shader --locked` on macOS arm64 — 144 passed, 0 failed, 2 ignored (Windows-gated hardware execution tests not run here). Approving — 64-bit node offsets and descriptor alignment preserved.
Xvania7 commented 2026-11-25 14:07:17 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Xvania7 on 2026-11-25T13:21:45Z.


Thanks @catminou4 for the macOS validation and approval!

To complement your ARM64 test pass, we verified this on native Windows 10 x64 + NVIDIA GeForce RTX 5060:

  • cargo test -p victory-shader --locked — all targeted unit tests pass cleanly (emit::bvh_tests, emit::lower::tests, emit::stride_tests).
  • cargo clippy --workspace --all-targets --locked -- -D warnings — zero warnings.
  • cargo run -p xtask --target-dir ... -- policy — all asset and encoding checks pass.

Ready for upstream merge into main.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7163666410 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2402#issuecomment-7163666410). Originally posted by [Xvania7](https://github.com/Xvania7) on 2026-11-25T13:21:45Z. --- Thanks @catminou4 for the macOS validation and approval! To complement your ARM64 test pass, we verified this on native Windows 10 x64 + NVIDIA GeForce RTX 5060: * `cargo test -p victory-shader --locked` — all targeted unit tests pass cleanly (`emit::bvh_tests`, `emit::lower::tests`, `emit::stride_tests`). * `cargo clippy --workspace --all-targets --locked -- -D warnings` — zero warnings. * `cargo run -p xtask --target-dir ... -- policy` — all asset and encoding checks pass. Ready for upstream merge into `main`.
andrewpozdnakov7-jpg commented 2026-11-25 14:07:25 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-25T13:33:59Z.


I ran the same translated compute test on Windows/WARP with three sparse synthetic guest pages. Each node has one hittable child, so the readback identifies the address used by the shader.

Root-built BVH case main 940d32f this PR 5e873ab #2040 7216eb7
Aligned control 1 1 1
Root address with low byte 0x80 4 1 1
Node offset above 4 GiB 1 2 2
Node pointer with a nonzero high word (above 32 GiB) 1 3 3

Test-only commit 1f8ce62 is directly on 5e873ab7fe if this narrower PR is selected. The base was 940d32f69b. All 15 BVH tests passed here. The full shader suite moved from 244 passed / 4 failed / 3 ignored to 245 passed / 3 failed / 3 ignored. The three shared failures are gather, lane permute and edge-flagged triangles under this WARP runtime. Strict shader Clippy and staged asset policy passed.

#2040 covers these address cases in its own fixture and also has tests for masked lanes and a non-address buffer fallback. Its 18 BVH tests passed here with the independent test included.

Please keep the Git author if you cherry-pick the test. If you fold the fixture into another commit, please add:

Co-authored-by: andrewpozdnakov7-jpg [email protected]

<!-- greyfinch-sync:Marvisak/VIctory:comment:7163962172 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2402#issuecomment-7163962172). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-25T13:33:59Z. --- I ran the same translated compute test on Windows/WARP with three sparse synthetic guest pages. Each node has one hittable child, so the readback identifies the address used by the shader. | Root-built BVH case | main 940d32f | this PR 5e873ab | #2040 7216eb7 | | --- | ---: | ---: | ---: | | Aligned control | 1 | 1 | 1 | | Root address with low byte 0x80 | 4 | 1 | 1 | | Node offset above 4 GiB | 1 | 2 | 2 | | Node pointer with a nonzero high word (above 32 GiB) | 1 | 3 | 3 | [Test-only commit 1f8ce62](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/1f8ce62320015cc11463dc901ccfba9724b42509) is directly on 5e873ab7fe579046f91288c1f1537e658bac59cb if this narrower PR is selected. The base was 940d32f69b22265690a0b5a15d6ded572ba33baf. All 15 BVH tests passed here. The full shader suite moved from 244 passed / 4 failed / 3 ignored to 245 passed / 3 failed / 3 ignored. The three shared failures are gather, lane permute and edge-flagged triangles under this WARP runtime. Strict shader Clippy and staged asset policy passed. #2040 covers these address cases in its own fixture and also has tests for masked lanes and a non-address buffer fallback. Its 18 BVH tests passed here with the independent test included. Please keep the Git author if you cherry-pick the test. If you fold the fixture into another commit, please add: Co-authored-by: andrewpozdnakov7-jpg <[email protected]>
Xvania7 commented 2026-11-25 14:07:29 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Xvania7 on 2026-11-25T13:43:01Z.


@andrewpozdnakov7-jpg Thanks for running the Windows/WARP compute tests across the sparse guest page scenarios and verifying all 15 BVH tests pass cleanly on 5e873ab.

The readback breakdown on low byte 0x80 alignment, 4 GiB offsets, and high word preservation proves the 64-bit root decoding works as expected without clipping. Happy to fold your synthetic test fixture commit 1f8ce62 into the branch with attribution.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7164184641 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2402#issuecomment-7164184641). Originally posted by [Xvania7](https://github.com/Xvania7) on 2026-11-25T13:43:01Z. --- @andrewpozdnakov7-jpg Thanks for running the Windows/WARP compute tests across the sparse guest page scenarios and verifying all 15 BVH tests pass cleanly on `5e873ab`. The readback breakdown on low byte 0x80 alignment, 4 GiB offsets, and high word preservation proves the 64-bit root decoding works as expected without clipping. Happy to fold your synthetic test fixture commit `1f8ce62` into the branch with attribution.
DenRakEiw commented 2026-11-25 15:03:26 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T14:18:28Z.

Review: APPROVED


Verified against origin/main (940d32f) on Windows 11 + NVIDIA GeForce RTX 5090 and WARP:

  • Preserving 64-bit node offsets and descriptor alignment in built BVH paths (#2368) passes all unit and live GPU BVH intersection tests.
  • cargo test -p victory-shader bvh: 15/15 passed on RTX 5090, 15/15 passed on WARP (including root_built_bvh_uses_aligned_base_and_wide_node_offsets and all GPU intersection tests).
  • cargo clippy -p victory-shader --all-targets -- -D warnings: 0 warnings.
  • cargo xtask policy: 183 files ok.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6059311735 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2402#pullrequestreview-6059311735). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-25T14:18:28Z. **Review:** APPROVED --- Verified against `origin/main` (`940d32f`) on Windows 11 + NVIDIA GeForce RTX 5090 and WARP: - Preserving 64-bit node offsets and descriptor alignment in built BVH paths (`#2368`) passes all unit and live GPU BVH intersection tests. - `cargo test -p victory-shader bvh`: 15/15 passed on RTX 5090, 15/15 passed on WARP (including `root_built_bvh_uses_aligned_base_and_wide_node_offsets` and all GPU intersection tests). - `cargo clippy -p victory-shader --all-targets -- -D warnings`: 0 warnings. - `cargo xtask policy`: 183 files ok. AI-assisted (Gemini 4 Neon).
Xvania7 commented 2026-11-25 15:04:17 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Xvania7 on 2026-11-25T14:19:32Z.


Thanks @DenRakEiw for testing across NVIDIA GeForce RTX 5090 and WARP, and verifying all 15/15 BVH unit and GPU intersection tests pass cleanly! Ready for upstream merge.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7165102828 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2402#issuecomment-7165102828). Originally posted by [Xvania7](https://github.com/Xvania7) on 2026-11-25T14:19:32Z. --- Thanks @DenRakEiw for testing across NVIDIA GeForce RTX 5090 and WARP, and verifying all 15/15 BVH unit and GPU intersection tests pass cleanly! Ready for upstream merge.
upstream-sync closed this pull request 2026-11-25 16:08:00 +00:00
Marvisak commented 2026-11-25 16:09:14 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T15:30:47Z.


Automated triage for the maintainers.

Proposed close (duplicate). Thanks for picking up #2368; the change looks sound: in Lower::bvh (crates/victory-shader/src/emit/lower/bvh.rs), a Source::Built descriptor with a root address now goes through the explicit descriptor decode, which keeps node_hi, shifts in 64 bits and keeps the 256-byte base, and the tests check the high-offset cases. However, #2040 (opened earlier, a merge candidate) fixes the same root-built BVH address truncation and covers more: 64-bit base and offset arithmetic, node_hi, refusing 64-bit pointers on built buffer views with no address, and the WARP zeroed-load problem in the guarded node loads; a comment here reports #2040 passing the same address cases. Two fixes to the same lines would conflict. If something here is missing from #2040 (for example the test commit 1f8ce62), please offer it there.

This PR will be closed in 48 hours unless the author pushes a change or a maintainer removes the label.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7166958277 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2402#issuecomment-7166958277). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T15:30:47Z. --- <!-- victory-triage v1 head=fde95208977a45ca8f9fd7fc313fc4b33dbbc95a verdict=proposed-close at=2026-11-25T15:31:00Z --> Automated triage for the maintainers. **Proposed close (duplicate).** Thanks for picking up #2368; the change looks sound: in `Lower::bvh` (`crates/victory-shader/src/emit/lower/bvh.rs`), a `Source::Built` descriptor with a root address now goes through the explicit descriptor decode, which keeps `node_hi`, shifts in 64 bits and keeps the 256-byte base, and the tests check the high-offset cases. However, #2040 (opened earlier, a merge candidate) fixes the same root-built BVH address truncation and covers more: 64-bit base and offset arithmetic, `node_hi`, refusing 64-bit pointers on built buffer views with no address, and the WARP zeroed-load problem in the guarded node loads; a comment here reports #2040 passing the same address cases. Two fixes to the same lines would conflict. If something here is missing from #2040 (for example the test commit 1f8ce62), please offer it there. This PR will be closed in 48 hours unless the author pushes a change or a maintainer removes the label. --- _Generated by [Claude Code](https://claude.ai/code)_
Xvania7 commented 2026-11-25 16:09:20 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Xvania7 on 2026-11-25T15:46:30Z.


Concur with triage: #2040 is the prior and more comprehensive fix for root-built BVH descriptors, covering 64-bit base and offset arithmetic, node_hi preservation, and the WARP zeroed-load behavior across its test suite. Closing in favor of #2040.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7167304953 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2402#issuecomment-7167304953). Originally posted by [Xvania7](https://github.com/Xvania7) on 2026-11-25T15:46:30Z. --- Concur with triage: #2040 is the prior and more comprehensive fix for root-built BVH descriptors, covering 64-bit base and offset arithmetic, `node_hi` preservation, and the WARP zeroed-load behavior across its test suite. Closing in favor of #2040.
Xvania7 commented 2026-11-25 16:09:20 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Xvania7 on 2026-11-25T15:46:47Z.


Concur with triage: #2040 is the prior and more comprehensive fix for root-built BVH descriptors, covering 64-bit base and offset arithmetic, node_hi preservation, and the WARP zeroed-load behavior across its test suite. Closing in favor of #2040.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7167308754 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2402#issuecomment-7167308754). Originally posted by [Xvania7](https://github.com/Xvania7) on 2026-11-25T15:46:47Z. --- Concur with triage: #2040 is the prior and more comprehensive fix for root-built BVH descriptors, covering 64-bit base and offset arithmetic, `node_hi` preservation, and the WARP zeroed-load behavior across its test suite. Closing in favor of #2040.

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!2400
No description provided.