victory-shader: preserve high bits in root-derived BVH node addresses (#2368) #2467

Open
github-bot wants to merge 5 commits from github-bot/gh-2467 into main AGit
Owner

@⁠cloph-dsp on GitHub · 2026-11-25 14:10 UTC · original
cloph-dsp:fix/bvh-root-address-width → main · +41 −11 · 2 files · 5 commits · open

Claim on the coordination issue #1633: claiming: new item, issue #2368 — shaders: preserve high pointer bits and 256-byte descriptor alignment for root-derived BVH node addresses; CPU-only arithmetic fix + synthetic unit test, no game data, AI-assisted (Hy4 flash) (comment 7163470612).

Problem: in crates/victory-shader/src/emit/lower/bvh.rs, the Source::Built + root_address path computed the node offset as a 32-bit i32 and then zero-extended it with wide64(at, zero). High pointer bits and carries from node_hi, k and dynamic were lost; the explicit-address path already reconstructed the full 64-bit pointer.

Change: one file, +42/−2. The title-memory root path now widens lo|node_hi to 64 bits, shifts in i64, widens k with Cast::ZExt and dynamic with Cast::SExt, and adds everything in 64 bits before constructing Nodes::Raw. The Nodes::Buffer fallback keeps its 32-bit offset. A #[cfg(test)] module adds a pure CPU arithmetic mirror test for the two counterexamples: lo=0x20000005 → base+4GiB, lo=5, node_hi=1 → base+32GiB.

I initially also applied the explicit descriptor path's 256-byte base quantization (base << 8), but that made the existing hardware BVH tests fail: the root descriptor in the synthetic fixture carries the base directly, already aligned. The quantization is therefore deliberately NOT applied here; the fix covers the high-bits/carry loss only.

Validation (Windows, Rust 1.100.0/MSVC, no game data):

  • cargo test --locked -p victory-shader --lib emit::lower::bvh::tests::root_derived_node_address_keeps_high_pointer_bits -- --exact — 1 passed
  • cargo test --locked -p victory-shader --lib emit::bvh_tests::intersections_on_nodes_in_title_memory_equal_the_reference -- --exact — 1 passed
  • cargo test --locked -p victory-shader --lib emit::bvh_tests::intersections_on_the_gpu_equal_the_reference -- --exact — passed (hardware, RTX 5060 Laptop)
  • cargo test --locked -p victory-shader --lib — 248 passed, 0 failed, 3 ignored
  • cargo test --workspace --locked — exit 0
  • git diff --check — clean

AI-assisted (Hy4 flash). GPU/driver: NVIDIA GeForce RTX 5060 Laptop, driver 621.24, Vulkan 1.4.357. No game data, assets, executables or extracted content were used, created or uploaded.

**@⁠cloph-dsp** on GitHub · 2026-11-25 14:10 UTC · [original](https://github.com/Marvisak/VIctory/pull/2467) `cloph-dsp:fix/bvh-root-address-width` → `main` · +41 −11 · 2 files · 5 commits · open Claim on the coordination issue #1633: `claiming: new item, issue #2368 — shaders: preserve high pointer bits and 256-byte descriptor alignment for root-derived BVH node addresses; CPU-only arithmetic fix + synthetic unit test, no game data, AI-assisted (Hy4 flash)` (comment 7163470612). **Problem:** in `crates/victory-shader/src/emit/lower/bvh.rs`, the `Source::Built` + `root_address` path computed the node offset as a 32-bit `i32` and then zero-extended it with `wide64(at, zero)`. High pointer bits and carries from `node_hi`, `k` and `dynamic` were lost; the explicit-address path already reconstructed the full 64-bit pointer. **Change:** one file, +42/−2. The title-memory root path now widens `lo|node_hi` to 64 bits, shifts in i64, widens `k` with `Cast::ZExt` and `dynamic` with `Cast::SExt`, and adds everything in 64 bits before constructing `Nodes::Raw`. The `Nodes::Buffer` fallback keeps its 32-bit offset. A `#[cfg(test)]` module adds a pure CPU arithmetic mirror test for the two counterexamples: `lo=0x20000005` → base+4GiB, `lo=5, node_hi=1` → base+32GiB. I initially also applied the explicit descriptor path's 256-byte base quantization (`base << 8`), but that made the existing hardware BVH tests fail: the root descriptor in the synthetic fixture carries the base directly, already aligned. The quantization is therefore deliberately NOT applied here; the fix covers the high-bits/carry loss only. **Validation (Windows, Rust 1.100.0/MSVC, no game data):** - `cargo test --locked -p victory-shader --lib emit::lower::bvh::tests::root_derived_node_address_keeps_high_pointer_bits -- --exact` — 1 passed - `cargo test --locked -p victory-shader --lib emit::bvh_tests::intersections_on_nodes_in_title_memory_equal_the_reference -- --exact` — 1 passed - `cargo test --locked -p victory-shader --lib emit::bvh_tests::intersections_on_the_gpu_equal_the_reference -- --exact` — passed (hardware, RTX 5060 Laptop) - `cargo test --locked -p victory-shader --lib` — 248 passed, 0 failed, 3 ignored - `cargo test --workspace --locked` — exit 0 - `git diff --check` — clean AI-assisted (Hy4 flash). GPU/driver: NVIDIA GeForce RTX 5060 Laptop, driver 621.24, Vulkan 1.4.357. No game data, assets, executables or extracted content were used, created or uploaded.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:06:45 +00:00
Author
Owner

@⁠upipibi on GitHub · 2026-11-25 14:23 UTC · original

Overlap check: #2402 (Xvania7, opened 12:57Z, "fixes #2368") and #2040 (mgunes1311-lab) target the same issue, and andrewpozdnakov7-jpg has been comparing #2402 with #2040 on WARP. From reading the diffs against main 940d32f, this is a different approach, not a copy:

  • This PR keeps the root-address Nodes::Raw path in lower/bvh.rs and widens the node offset to 64 bits: (ptr << 3) + k, where ptr carries node_hi, plus any dynamic offset, added to the 64-bit root base.
  • #2402 reshapes the Source::Built arm. A built root without a known root address goes through the buffer handle. The root-address case leaves that arm, and #2402 adds 137 lines of bvh_tests.rs.

So the three need one pick, or a combination. I haven't run any of them.

AI-assisted (Claude Code). Read from the diffs only.

**@⁠upipibi** on GitHub · 2026-11-25 14:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/2467#issuecomment-7165213079) Overlap check: #2402 (Xvania7, opened 12:57Z, "fixes #2368") and #2040 (mgunes1311-lab) target the same issue, and andrewpozdnakov7-jpg has been comparing #2402 with #2040 on WARP. From reading the diffs against `main` `940d32f`, this is a different approach, not a copy: - **This PR** keeps the root-address `Nodes::Raw` path in `lower/bvh.rs` and widens the node offset to 64 bits: `(ptr << 3) + k`, where `ptr` carries `node_hi`, plus any dynamic offset, added to the 64-bit root base. - **#2402** reshapes the `Source::Built` arm. A built root without a known root address goes through the buffer handle. The root-address case leaves that arm, and #2402 adds 137 lines of `bvh_tests.rs`. So the three need one pick, or a combination. I haven't run any of them. AI-assisted (Claude Code). Read from the diffs only.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 15:58 UTC · original · edited 2026-11-26 07:22 UTC

Automated triage for the maintainers.

Needs work (the test). Thanks for the update. In Lower::bvh (emit/lower/bvh.rs, root-address arm), the lowering now does what was asked. It widens lo/node_hi before the << 3, zero-extends k and dynamic separately, and adds in 64 bits. The comment now agrees with shortcut:.

The new test intersections_when_a_node_pointer_carries_into_the_high_word does not tell the old lowering from the new one. page_table_at(1, 3, base, TITLE) maps both base (TITLE - 2^32) and TITLE to the same view at the same low word. So the address the old code computed (carry lost, base + offset) reads the same nodes as the right one (TITLE + offset). Map only the carried-to address (for example, leave base's page empty or point it at the null pair), so the test fails on main and passes here. The test also uses wide = false, so node_hi is not exercised; a wide = true case with a non-zero high word would cover it.

This still overlaps #2501 on the same lines, and the maintainer should pick one or combine them.

CI: check passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 15:58 UTC · [original](https://github.com/Marvisak/VIctory/pull/2467#issuecomment-7167486773) · edited 2026-11-26 07:22 UTC <!-- victory-triage v1 head=86761342860c5d9c2e35bf2d653d20ff2cbc3e0e verdict=needs-work at=2026-11-26T07:22:18Z --> Automated triage for the maintainers. **Needs work (the test).** Thanks for the update. In `Lower::bvh` (`emit/lower/bvh.rs`, root-address arm), the lowering now does what was asked. It widens `lo`/`node_hi` before the `<< 3`, zero-extends `k` and `dynamic` separately, and adds in 64 bits. The comment now agrees with `shortcut:`. The new test `intersections_when_a_node_pointer_carries_into_the_high_word` does not tell the old lowering from the new one. `page_table_at(1, 3, base, TITLE)` maps both `base` (`TITLE - 2^32`) and `TITLE` to the same view at the same low word. So the address the old code computed (carry lost, `base + offset`) reads the same nodes as the right one (`TITLE + offset`). Map only the carried-to address (for example, leave `base`'s page empty or point it at the null pair), so the test fails on `main` and passes here. The test also uses `wide = false`, so `node_hi` is not exercised; a `wide = true` case with a non-zero high word would cover it. This still overlaps #2501 on the same lines, and the maintainer should pick one or combine them. CI: `check` passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 16:53 UTC · original

Real fix, two bugs in the old path: lo << 3 computed the byte offset in 32 bits (high pointer bits lost), and node_hi was read for wide nodes then dropped entirely on the root-address path — wide64(at, zero) widened a value whose carries had already been truncated. The new order widens first (wide64(lo, node_hi)), then shifts/adds in 64 bits, with correct extension signedness (ZExt for the static k, SExt for dynamic). The Nodes::Buffer path keeping a 32-bit at is fine — it's an offset within a buffer view, which is 32-bit.

Minor: let at = lo << three is still computed before root_address and used only by the None arm — dead work on the root path, harmless.

**@⁠kotekompotek** on GitHub · 2026-11-25 16:53 UTC · [original](https://github.com/Marvisak/VIctory/pull/2467#issuecomment-7168675299) Real fix, two bugs in the old path: `lo << 3` computed the byte offset in 32 bits (high pointer bits lost), and `node_hi` was read for `wide` nodes then dropped entirely on the root-address path — `wide64(at, zero)` widened a value whose carries had already been truncated. The new order widens first (`wide64(lo, node_hi)`), then shifts/adds in 64 bits, with correct extension signedness (`ZExt` for the static `k`, `SExt` for `dynamic`). The `Nodes::Buffer` path keeping a 32-bit `at` is fine — it's an offset within a buffer view, which is 32-bit. Minor: `let at = lo << three` is still computed before `root_address` and used only by the `None` arm — dead work on the root path, harmless.
Author
Owner

@⁠rminzao on GitHub · 2026-11-26 01:52 UTC · original

Tested head 90ee09d on Windows 11 with an RTX 4050 Laptop (595.97) and WARP, running cargo test -p victory-shader --lib bvh: 14 passed on both. The existing BVH tests stay green.

  • The description lists a test this head doesn't have. The diff against the base is the 13 lines in lower/bvh.rs, with no #[cfg(test)] module, so root_derived_node_address_keeps_high_pointer_bits doesn't exist here. A CPU mirror of the arithmetic wouldn't check the lowering anyway. #2501's a_node_pointer_above_two_gib_reads_where_it_points does: it fails on the base's lowering and passes on this PR's too (WARP, 15 passed with its bvh_tests.rs).
  • node_hi: this is the one change of the two that covers the issue's third counterexample (hi=1, base + 32 GiB). #2501 still widens with a zero high word.
  • Carry: k and the computed part are summed in 32 bits and then zero-extended. resource::Address::offset is "added modulo 2^32 (with carry into the high half)", once per part, so a sum that overflows 32 bits loses a carry the title's own s_add_u32/s_addc_u32 pairs would keep. Widening each part before the add, as #2501 does, avoids that.

The two PRs fix the same lines, each covering what the other misses. The simplest landing is #2501 plus node_hi. Otherwise this PR could take #2501's test and the per-part widening.

AI-assisted (Claude Code).

**@⁠rminzao** on GitHub · 2026-11-26 01:52 UTC · [original](https://github.com/Marvisak/VIctory/pull/2467#issuecomment-7180238148) Tested head 90ee09d on Windows 11 with an RTX 4050 Laptop (595.97) and WARP, running `cargo test -p victory-shader --lib bvh`: 14 passed on both. The existing BVH tests stay green. - **The description lists a test this head doesn't have.** The diff against the base is the 13 lines in `lower/bvh.rs`, with no `#[cfg(test)]` module, so `root_derived_node_address_keeps_high_pointer_bits` doesn't exist here. A CPU mirror of the arithmetic wouldn't check the lowering anyway. #2501's `a_node_pointer_above_two_gib_reads_where_it_points` does: it fails on the base's lowering and passes on this PR's too (WARP, 15 passed with its `bvh_tests.rs`). - **`node_hi`:** this is the one change of the two that covers the issue's third counterexample (`hi=1`, base + 32 GiB). #2501 still widens with a zero high word. - **Carry:** `k` and the computed part are summed in 32 bits and then zero-extended. `resource::Address::offset` is "added modulo 2^32 (with carry into the high half)", once per part, so a sum that overflows 32 bits loses a carry the title's own `s_add_u32`/`s_addc_u32` pairs would keep. Widening each part before the add, as #2501 does, avoids that. The two PRs fix the same lines, each covering what the other misses. The simplest landing is #2501 plus `node_hi`. Otherwise this PR could take #2501's test and the per-part widening. _AI-assisted (Claude Code)._
Author
Owner

@⁠DenRakEiw on GitHub · 2026-11-25 14:17 UTC · original · approved these changes

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

  • Preserving high pointer bits in root-derived BVH node addresses (#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_derived_node_address_keeps_high_pointer_bits 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).

**@⁠DenRakEiw** on GitHub · 2026-11-25 14:17 UTC · [original](https://github.com/Marvisak/VIctory/pull/2467#pullrequestreview-6059295702) · **approved these changes** Verified against `origin/main` (`940d32f`) on Windows 11 + NVIDIA GeForce RTX 5090 and WARP: - Preserving high pointer bits in root-derived BVH node addresses (`#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_derived_node_address_keeps_high_pointer_bits` 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).
Author
Owner

@⁠catminou4 on GitHub · 2026-11-25 14:57 UTC · original · approved these changes

Tested locally: merged into main 940d32f69b, cargo test -p victory-shader --locked on macOS arm64 — 145 passed, 0 failed, 2 ignored (Windows-gated hardware execution tests not run here). Approving — high bits preserved in root-derived buffer addresses.

**@⁠catminou4** on GitHub · 2026-11-25 14:57 UTC · [original](https://github.com/Marvisak/VIctory/pull/2467#pullrequestreview-6059995076) · **approved these changes** Tested locally: merged into main 940d32f69b, `cargo test -p victory-shader --locked` on macOS arm64 — 145 passed, 0 failed, 2 ignored (Windows-gated hardware execution tests not run here). Approving — high bits preserved in root-derived buffer addresses.
Author
Owner

@⁠oni-swr on GitHub · 2026-11-25 15:11 UTC · original · reviewed

Side-by-side check of #2501 (ca57ed43) and #2467 (c79cb207). Both change only the Source::Built + root_address (Nodes::Raw) arm of crates/victory-shader/src/emit/lower/bvh.rs, for #2368. I read both diffs in full.

Overlap: both stop shifting the node offset in 32 bits and then zero-extending it. Both build base64 + (node << 3) + k (+ dynamic) in 64 bits. The Nodes::Buffer fallback is unchanged in behaviour in both.

Differences

#2501 #2467
image_bvh64 high node word (node_hi) still ignored on this arm; only lo<<3 is widened folded in: ptr = lo | node_hi<<32, then <<3
dynamic term ZExt to 64 bits SExt to 64 bits
k constant i64 ZExt of the 32-bit value
tests none added one test, a Rust mirror of the arithmetic; it does not call the lowering. It is also not rustfmt-clean (rustfmt --check fails on the test fn signature)
buffer path rewritten in an explicit else branch (same ops) untouched

Edge cases.

  • With node_hi != 0, #2501 still drops the high pointer bits. It fixes the lo<<3 overflow for BVHs above 512 MiB, but not 64-bit pointers. #2467 handles both, and the already-passing intersections_with_64_bit_pointers_on_the_gpu_equal_the_reference test exercises the None path rather than this one.
  • dynamic sign: the two disagree for values >= 2^31. Under #2501, a negative dynamic that used to wrap correctly in 32 bits, with the sum below 2^32, now lands 2^32 too high. Under #2467 it is correct for negative values but wrong for an unsigned offset >= 2^31. Nothing I read in Address.dynamic or built_offset states which is intended. The authors should say, ideally with a test through the real lowering.
  • Neither adds a GPU/WARP test of the Nodes::Raw path, so the new arithmetic is not exercised end to end by the suite.

Supersede or complement? They are alternative fixes to the same lines and will conflict, so only one can merge as written. #2467 is the more complete one (it includes node_hi). #2501 has the cleaner 64-bit constants, and its comment about negative offsets does not match its own ZExt of dynamic. If #2467 is picked, its dynamic sign question and a real lowering test should be settled first.

Verification (Windows, VICTORY_D3D12_WARP=1, WARP only):

  • #2501 ca57ed43289e97748adb277cbfcbcec4994dcc0e: cargo test -p victory-shader --locked --lib — 247 passed, 0 failed, 3 ignored; ... --lib bvh — 14 passed, 0 failed, 0 ignored. rustfmt clean.
  • #2467 c79cb207dcbea305a35f91a541b6bea0a522f9d8: cargo test -p victory-shader --locked --lib — 248 passed, 0 failed, 3 ignored; ... --lib bvh — 15 passed, 0 failed, 0 ignored (includes its new test).

AI-assisted (Claude Code / Claude Sonnet 5.5)

**@⁠oni-swr** on GitHub · 2026-11-25 15:11 UTC · [original](https://github.com/Marvisak/VIctory/pull/2467#pullrequestreview-6060223958) · **reviewed** Side-by-side check of #2501 (`ca57ed43`) and #2467 (`c79cb207`). Both change only the `Source::Built` + `root_address` (`Nodes::Raw`) arm of `crates/victory-shader/src/emit/lower/bvh.rs`, for #2368. I read both diffs in full. **Overlap:** both stop shifting the node offset in 32 bits and then zero-extending it. Both build `base64 + (node << 3) + k (+ dynamic)` in 64 bits. The `Nodes::Buffer` fallback is unchanged in behaviour in both. **Differences** | | #2501 | #2467 | |---|---|---| | `image_bvh64` high node word (`node_hi`) | still ignored on this arm; only `lo<<3` is widened | folded in: `ptr = lo \| node_hi<<32`, then `<<3` | | `dynamic` term | `ZExt` to 64 bits | `SExt` to 64 bits | | `k` | constant `i64` | `ZExt` of the 32-bit value | | tests | none added | one test, a Rust mirror of the arithmetic; it does not call the lowering. It is also not rustfmt-clean (`rustfmt --check` fails on the test fn signature) | | buffer path | rewritten in an explicit else branch (same ops) | untouched | **Edge cases.** - With `node_hi != 0`, #2501 still drops the high pointer bits. It fixes the `lo<<3` overflow for BVHs above 512 MiB, but not 64-bit pointers. #2467 handles both, and the already-passing `intersections_with_64_bit_pointers_on_the_gpu_equal_the_reference` test exercises the `None` path rather than this one. - `dynamic` sign: the two disagree for values >= 2^31. Under #2501, a negative `dynamic` that used to wrap correctly in 32 bits, with the sum below 2^32, now lands 2^32 too high. Under #2467 it is correct for negative values but wrong for an unsigned offset >= 2^31. Nothing I read in `Address.dynamic` or `built_offset` states which is intended. The authors should say, ideally with a test through the real lowering. - Neither adds a GPU/WARP test of the `Nodes::Raw` path, so the new arithmetic is not exercised end to end by the suite. **Supersede or complement?** They are alternative fixes to the same lines and will conflict, so only one can merge as written. #2467 is the more complete one (it includes `node_hi`). #2501 has the cleaner 64-bit constants, and its comment about negative offsets does not match its own `ZExt` of `dynamic`. If #2467 is picked, its `dynamic` sign question and a real lowering test should be settled first. **Verification** (Windows, `VICTORY_D3D12_WARP=1`, WARP only): - #2501 `ca57ed43289e97748adb277cbfcbcec4994dcc0e`: `cargo test -p victory-shader --locked --lib` — 247 passed, 0 failed, 3 ignored; `... --lib bvh` — 14 passed, 0 failed, 0 ignored. rustfmt clean. - #2467 `c79cb207dcbea305a35f91a541b6bea0a522f9d8`: `cargo test -p victory-shader --locked --lib` — 248 passed, 0 failed, 3 ignored; `... --lib bvh` — 15 passed, 0 failed, 0 ignored (includes its new test). AI-assisted (Claude Code / Claude Sonnet 5.5)
Author
Owner

@⁠fyernald on GitHub · 2026-11-25 17:33 UTC · original · requested changes

Tested on RTX 3080 (617.42), Windows 10 (19045) plus WARP, main 67e8ae1 + #486 + #2596 (the suite crashes on NVIDIA without #2596, #2571). cargo test -p victory-shader --lib --locked -- --test-threads=1: 268 passed, 3 failed (the #1835 ones, also on the base). Nothing regresses. Two things, though:

  1. dynamic is sign-extended (Cast::SExt), but it's the byte offset the built descriptor adds to the root address (built_offset). The console adds that with an unsigned carry, and this PR zero-extends the constant part k. A dynamic offset of 2 GiB or more would come out 4 GiB too low. #2501 zero-extends it.
  2. The test can't fail on the lowering. built_root_node_address re-implements the arithmetic in plain Rust and checks it against itself, so it would pass even if bvh.rs were unchanged. #2501 has an end-to-end test (a_node_pointer_above_two_gib_reads_where_it_points) that passes on an RTX 3080.

#2501 is the same 64-bit shift and add without node_hi. The node_hi part is what this PR adds over it (it matches the explicit-descriptor path on main), so it might be easiest to rebase that onto #2501 with zero-extension and a hardware test.

**@⁠fyernald** on GitHub · 2026-11-25 17:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/2467#pullrequestreview-6062135530) · **requested changes** Tested on **RTX 3080 (617.42), Windows 10 (19045)** plus WARP, `main` `67e8ae1` + #486 + #2596 (the suite crashes on NVIDIA without #2596, #2571). `cargo test -p victory-shader --lib --locked -- --test-threads=1`: 268 passed, 3 failed (the #1835 ones, also on the base). Nothing regresses. Two things, though: 1. **`dynamic` is sign-extended** (`Cast::SExt`), but it's the byte offset the built descriptor adds to the root address (`built_offset`). The console adds that with an unsigned carry, and this PR zero-extends the constant part `k`. A dynamic offset of 2 GiB or more would come out 4 GiB too low. #2501 zero-extends it. 2. **The test can't fail on the lowering.** `built_root_node_address` re-implements the arithmetic in plain Rust and checks it against itself, so it would pass even if `bvh.rs` were unchanged. #2501 has an end-to-end test (`a_node_pointer_above_two_gib_reads_where_it_points`) that passes on an RTX 3080. #2501 is the same 64-bit shift and add without `node_hi`. The `node_hi` part is what this PR adds over it (it matches the explicit-descriptor path on `main`), so it might be easiest to rebase that onto #2501 with zero-extension and a hardware test.
Author
Owner

@⁠fyernald on GitHub · 2026-11-26 02:02 UTC · original · approved these changes

Retested 90ee09d on the same RTX 3080 / Windows 10, now on main 63bcca4 (+ #486, #2596 for #2571).

  • The sign extension is gone. The offsets now go through zero extension, and the self-checking test is removed.
  • To exercise the lowering itself, I applied only #2501's bvh_tests.rs change (the 4 GiB-higher page and node pointer with bit 29 set) on top of this branch. a_node_pointer_above_two_gib_reads_where_it_points passes on the RTX 3080 with this PR and fails on main, and all 15 bvh_tests pass.
  • Full cargo test -p victory-shader --lib -- --test-threads=1: 298 passed, 4 failed, the same four as the base. Nothing regresses.

The one thing left is that the PR has no test of its own now. Carrying #2501's end-to-end test over, or landing the two together, would cover it. One difference from #2501 for whoever picks between them: here k + dynamic is summed in 32 bits before widening, so a carry out of that sum is dropped, while #2501 adds each part in 64 bits. That only matters when the two together reach 4 GiB.

**@⁠fyernald** on GitHub · 2026-11-26 02:02 UTC · [original](https://github.com/Marvisak/VIctory/pull/2467#pullrequestreview-6067573201) · **approved these changes** Retested `90ee09d` on the same RTX 3080 / Windows 10, now on `main` `63bcca4` (+ #486, #2596 for #2571). - The sign extension is gone. The offsets now go through zero extension, and the self-checking test is removed. - To exercise the lowering itself, I applied only #2501's `bvh_tests.rs` change (the 4 GiB-higher page and node pointer with bit 29 set) on top of this branch. `a_node_pointer_above_two_gib_reads_where_it_points` **passes on the RTX 3080** with this PR and fails on `main`, and all 15 `bvh_tests` pass. - Full `cargo test -p victory-shader --lib -- --test-threads=1`: 298 passed, 4 failed, the same four as the base. Nothing regresses. The one thing left is that the PR has no test of its own now. Carrying #2501's end-to-end test over, or landing the two together, would cover it. One difference from #2501 for whoever picks between them: here `k + dynamic` is summed in 32 bits before widening, so a carry out of that sum is dropped, while #2501 adds each part in 64 bits. That only matters when the two together reach 4 GiB.
Author
Owner

@⁠cloph-dsp on GitHub · 2026-11-26 05:59 UTC · original

Pushed three follow-up commits addressing the triage and review points:

  • c106e19 adds intersections_when_a_node_pointer_carries_into_the_high_word in src/emit/bvh_tests.rs. It goes through the real lowering (page table for the carried base + node pointer above 2^29), not a CPU mirror of the arithmetic.
  • 5680f77 zero-extends k and dynamic separately to 64 bits before adding them, so a carry out of k + dynamic is preserved, matching resource::Address::offset ("modulo 2^32 with carry into the high half") and the hardware s_add_u32/s_addc_u32 pair. The node_hi widening is kept.
  • 8676134 rewords the root-descriptor comment so it agrees with the 256-byte shortcut: above it.

Validation (Windows, Rust 1.100.0/MSVC, CARGO_TARGET_DIR=D:\Victory-Contrib\shared-target):

  • cargo test -p victory-shader --lib bvh — 15 passed, 0 failed (including the new carry test and the existing GPU/WARP intersection tests).
  • Full cargo test -p victory-shader — 277 passed, 3 ignored (run before the comment-only commit).
  • git diff --check — clean.
  • GPU available on this host: RTX 5060 Laptop (driver 621.24); Radeon 780M RDNA3 is also present. The BVH tests select an available D3D12/WARP device.

Thanks @⁠Marvisak, @⁠rminzao and @⁠fyernald for the precise reviews. Please re-check the updated head 8676134.

AI-assisted (Hy4 flash). No game assets, extracted data, shaders or DRM-related material were used or uploaded.

**@⁠cloph-dsp** on GitHub · 2026-11-26 05:59 UTC · [original](https://github.com/Marvisak/VIctory/pull/2467#issuecomment-7183989440) Pushed three follow-up commits addressing the triage and review points: - `c106e19` adds `intersections_when_a_node_pointer_carries_into_the_high_word` in `src/emit/bvh_tests.rs`. It goes through the real lowering (page table for the carried base + node pointer above `2^29`), not a CPU mirror of the arithmetic. - `5680f77` zero-extends `k` and `dynamic` separately to 64 bits before adding them, so a carry out of `k + dynamic` is preserved, matching `resource::Address::offset` ("modulo 2^32 with carry into the high half") and the hardware `s_add_u32`/`s_addc_u32` pair. The `node_hi` widening is kept. - `8676134` rewords the root-descriptor comment so it agrees with the 256-byte `shortcut:` above it. Validation (Windows, Rust 1.100.0/MSVC, `CARGO_TARGET_DIR=D:\Victory-Contrib\shared-target`): - `cargo test -p victory-shader --lib bvh` — 15 passed, 0 failed (including the new carry test and the existing GPU/WARP intersection tests). - Full `cargo test -p victory-shader` — 277 passed, 3 ignored (run before the comment-only commit). - `git diff --check` — clean. - GPU available on this host: RTX 5060 Laptop (driver 621.24); Radeon 780M RDNA3 is also present. The BVH tests select an available D3D12/WARP device. Thanks @⁠Marvisak, @⁠rminzao and @⁠fyernald for the precise reviews. Please re-check the updated head `8676134`. AI-assisted (Hy4 flash). No game assets, extracted data, shaders or DRM-related material were used or uploaded.
Author
Owner

@⁠nathanbzrr on GitHub · 2026-11-26 07:48 UTC · original · requested changes

Reviewed 8676134 merged onto main (63bcca4). The 64-bit widening in crates/victory-shader/src/emit/lower/bvh.rs:138-158 (super::flags::INT64 with wide64 and Cast::ZExt on k and dynamic) correctly propagates carries into the upper 32 bits of Nodes::Raw, and policy (191 files ok), clippy, and bvh tests pass on Windows 11 (AMD Radeon RX 7600 + VICTORY_WARP=1, 15 passed; 0 failed).

However, two test gaps should be addressed before merge:

  1. intersections_when_a_node_pointer_carries_into_the_high_word (crates/victory-shader/src/emit/bvh_tests.rs:818-854) does not fail if the 64-bit carry is dropped.
    It calls run_cases_at(false, 4, false, TITLE - 0x1_0000_0000, 0x2000_0000). In page_table_at (bvh_tests.rs:825-837), both base (0x11_3450_0000) and target (0x12_3450_0000) share the exact same low 32 bits (0x3450_0000), map both L1 indices (275 and 291) to the same L2 block 1, and populate the same L2 slot [view, 0x3450_0000] backed by View::Memory(&data). If the carry out of the low word were truncated and the shader loaded from base (0x11_3450_0000) instead of TITLE (0x12_3450_0000), the page table would still return identical data and the test would still pass. Giving base and target distinct page-table targets (e.g., mapping base to null or a different offset) would make it genuinely catch a dropped high-word carry.
  2. No coverage with wide = true (node_hi != 0) in title memory.
    intersections_when_a_node_pointer_carries_into_the_high_word passes wide = false (node_hi = None), while run_cases(true, 8, false) passes a zero node-pointer base (node_hi == 0). Adding a wide = true case where node_hi != 0 contributes to (base + (ptr << 3)) resolving to a distinct high-word title page would cover bvh.rs:145 with node_hi non-zero.

AI-assisted; synthetic tests only, no game files.

**@⁠nathanbzrr** on GitHub · 2026-11-26 07:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/2467#pullrequestreview-6070250704) · **requested changes** Reviewed `8676134` merged onto `main` (`63bcca4`). The 64-bit widening in `crates/victory-shader/src/emit/lower/bvh.rs:138-158` (`super::flags::INT64` with `wide64` and `Cast::ZExt` on `k` and `dynamic`) correctly propagates carries into the upper 32 bits of `Nodes::Raw`, and `policy` (`191 files ok`), `clippy`, and `bvh` tests pass on Windows 11 (AMD Radeon RX 7600 + `VICTORY_WARP=1`, `15 passed; 0 failed`). However, two test gaps should be addressed before merge: 1. **`intersections_when_a_node_pointer_carries_into_the_high_word` (`crates/victory-shader/src/emit/bvh_tests.rs:818-854`) does not fail if the 64-bit carry is dropped.** It calls `run_cases_at(false, 4, false, TITLE - 0x1_0000_0000, 0x2000_0000)`. In `page_table_at` (`bvh_tests.rs:825-837`), both `base` (`0x11_3450_0000`) and `target` (`0x12_3450_0000`) share the exact same low 32 bits (`0x3450_0000`), map both L1 indices (`275` and `291`) to the **same L2 block `1`**, and populate the same L2 slot `[view, 0x3450_0000]` backed by `View::Memory(&data)`. If the carry out of the low word were truncated and the shader loaded from `base` (`0x11_3450_0000`) instead of `TITLE` (`0x12_3450_0000`), the page table would still return identical data and the test would still pass. Giving `base` and `target` distinct page-table targets (e.g., mapping `base` to `null` or a different offset) would make it genuinely catch a dropped high-word carry. 2. **No coverage with `wide = true` (`node_hi != 0`) in title memory.** `intersections_when_a_node_pointer_carries_into_the_high_word` passes `wide = false` (`node_hi = None`), while `run_cases(true, 8, false)` passes a zero node-pointer base (`node_hi == 0`). Adding a `wide = true` case where `node_hi != 0` contributes to `(base + (ptr << 3))` resolving to a distinct high-word title page would cover `bvh.rs:145` with `node_hi` non-zero. AI-assisted; synthetic tests only, no game files.
Author
Owner

@⁠rezioliver-collab on GitHub · 2026-11-26 13:05 UTC · original

On an Apple M1, #2467 computed both the +4 GiB and +32 GiB node addresses correctly. #2501 handled the +4 GiB carry, but read the node at the base when the pointer’s high word was 1.

The table shows the address actually read. The root SRV base was B = 0x1234500000.

Node pointer (low, high) Expected main (63bcca43) #2501 (d916d066) #2467 (86761342)
(0x00000005, 0) B B B B
(0x20000005, 0) B + 4 GiB B B + 4 GiB B + 4 GiB
(0x00000005, 1) B + 32 GiB B B B + 32 GiB

I built each revision separately with Rust 1.98.1 on macOS 14.7 and translated the same 100-byte synthetic image_bvh64_intersect_ray shader from emit/bvh_tests.rs. For the CPU replay, Apple Clang 16 compiled the emitted DXIL function at -O0, with a small native adapter for DXIL resource operations. The disassembly step adapted the module’s i8 alignment for Apple LLVM and preserved the shader instructions.

The synthetic page table mapped B, B + 4 GiB and B + 32 GiB to three distinct nodes. Their first child IDs were 0xa000, 0xb000 and 0xc000. For one shader thread per case, I traced all 28 node dwords and checked all four child IDs written by the shader. In the +32 GiB case, #2501 returned 0xa000 and #2467 returned 0xc000. In the emitted IR, #2501 supplies a zero high word before the 64-bit shift, while #2467 combines both pointer words before shifting.

**@⁠rezioliver-collab** on GitHub · 2026-11-26 13:05 UTC · [original](https://github.com/Marvisak/VIctory/pull/2467#issuecomment-7192863377) **On an Apple M1, #2467 computed both the +4 GiB and +32 GiB node addresses correctly.** #2501 handled the +4 GiB carry, but read the node at the base when the pointer’s high word was 1. The table shows the address actually read. The root SRV base was `B = 0x1234500000`. | Node pointer (low, high) | Expected | `main` (`63bcca43`) | #2501 (`d916d066`) | #2467 (`86761342`) | |---|---|---|---|---| | `(0x00000005, 0)` | B | B | B | B | | `(0x20000005, 0)` | B + 4 GiB | B | B + 4 GiB | B + 4 GiB | | `(0x00000005, 1)` | B + 32 GiB | B | B | B + 32 GiB | I built each revision separately with Rust 1.98.1 on macOS 14.7 and translated the same 100-byte synthetic `image_bvh64_intersect_ray` shader from `emit/bvh_tests.rs`. For the CPU replay, Apple Clang 16 compiled the emitted DXIL function at `-O0`, with a small native adapter for DXIL resource operations. The disassembly step adapted the module’s `i8` alignment for Apple LLVM and preserved the shader instructions. The synthetic page table mapped B, B + 4 GiB and B + 32 GiB to **three distinct nodes**. Their first child IDs were `0xa000`, `0xb000` and `0xc000`. For one shader thread per case, I traced all 28 node dwords and checked all four child IDs written by the shader. In the +32 GiB case, #2501 returned `0xa000` and #2467 returned `0xc000`. In the emitted IR, #2501 supplies a zero high word before the 64-bit shift, while #2467 combines both pointer words before shifting.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2467/head:github-bot/gh-2467'
git switch 'github-bot/gh-2467'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2467'
git switch 'github-bot/gh-2467'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2467'
git switch 'github-bot/gh-2467'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2467'
git switch 'main'
git merge --squash 'github-bot/gh-2467'
git switch 'main'
git merge --ff-only 'github-bot/gh-2467'
git switch 'main'
git merge 'github-bot/gh-2467'
git push origin 'main'
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!2467
No description provided.