Shaders: root-derived BVH node addresses lose high pointer bits and descriptor alignment #2368

Open
opened 2026-11-26 05:03:42 +00:00 by github-bot · 2 comments
Owner

@⁠FunWithFlagsDev on GitHub · 2026-11-25 12:03 UTC · original

<html>

Summary

While auditing the upstream ray-tracing implementation at commit 940d32f69b22265690a0b5a15d6ded572ba33baf, I found an address-calculation inconsistency between the root-derived and explicit-address BVH lowering paths.

The root-derived path can discard the upper bits of the node offset before converting it to a 64-bit address. It also reconstructs the descriptor base without preserving its 256-byte quantization.

This can cause an intersection instruction to read a different BVH node from the one requested.

Source evidence

The Source::Built path calculates the node offset using an i32 shift and additions before widening it with a zero high word.

By contrast, the explicit-address path reconstructs the full pointer and performs the shift in i64.

Minimal counterexamples

For an aligned BVH base B, with no additional descriptor offsets:

Node pointer | Expected address | Current Built/Raw address -- | -- | -- lo=0x1ffffffd, hi=0 | B + 4 GiB − 64 bytes | Correct lo=0x20000005, hi=0 | B + 4 GiB | B lo=0x00000005, hi=1 | B + 32 GiB | B

All seven regression tests passed.

The randomized inputs deliberately stress large offsets, descriptor alignment and arithmetic boundaries. These mismatch counts are not estimates of the defect's frequency in the title.

A sparse two-level page-table model also demonstrates that the truncated address can resolve to a valid but incorrect node, rather than necessarily causing a missing-memory access.

Proposed fix

Reuse the existing explicit-address descriptor decoder for the Source::Built path when root_address(src) is available.

This would preserve:

  • Both halves of the node pointer.

  • Full-width offset arithmetic.

  • The descriptor's actual encoded base and alignment.

  • The existing title-memory lookup and bounds-checking path.

Keep the buffer-backed fallback and resource-tracking checks unchanged in this initial correction.

Regression coverage

The existing wide-pointer GPU test uses small node offsets and leaves the upper pointer word zero.

I suggest extending that fixture with sparse guest-memory mappings at B, B + 4 GiB and B + 32 GiB, using distinguishable valid box nodes and explicitly populating the upper pointer word.

The attached archive includes a proposed fixture design requiring only approximately 336 KiB of page-table and mapped data storage, excluding auxiliary GPU resources.

Attachment

bvh_address_audit_v2.zip contains:

  • Source audit and reproduction instructions.

  • Executable LLVM JIT regression tests.

  • Recorded test results.

  • Proposed Rust implementation changes.

  • Native GPU regression-test design.

Scope and limitations

Related work: #1794, #2098, #2118, #2206 and #2311.

This report concerns BVH node address calculation, not intersection mathematics or traversal optimization.

The proposed Rust change has not been compiled, and native DXIL validation and GPU execution remain pending. I have not established whether the title encounters these particular address patterns or whether they contribute to the missing ray-traced lighting.

No title files, proprietary assets, game captures or memory dumps were used.

AI-assisted source audit and synthetic verification.

</html>## Summary

While auditing the upstream ray-tracing implementation at commit 940d32f69b22265690a0b5a15d6ded572ba33baf, I found an address-calculation inconsistency between the root-derived and explicit-address BVH lowering paths.

The root-derived path can discard the upper bits of the node offset before converting it to a 64-bit address. It also reconstructs the descriptor base without preserving its 256-byte quantization.

This can cause an intersection instruction to read a different BVH node from the one requested.

Source evidence

The Source::Built path calculates the node offset using an i32 shift and additions before widening it with a zero high word.

By contrast, the explicit-address path reconstructs the full pointer and performs the shift in i64.

Minimal counterexamples

For an aligned BVH base B, with no additional descriptor offsets:

Node pointer Expected address Current Built/Raw address
lo=0x1ffffffd, hi=0 B + 4 GiB − 64 bytes Correct
lo=0x20000005, hi=0 B + 4 GiB B
lo=0x00000005, hi=1 B + 32 GiB B

These addresses can remain within the supported 40-bit guest address space.

There is also a separate alignment limitation: widening the arithmetic alone does not preserve the descriptor's 256-byte base quantization. The current source explicitly acknowledges this alignment shortcut.

Independent verification

I implemented three versions of the address calculation in hand-authored LLVM IR and executed them using the LLVM 20.1.8 CPU JIT.

Implementation Divergences in 20,000 synthetic cases
Current Built/Raw arithmetic 20,000
Widening the arithmetic only 19,920
Decoding the actual descriptor operands 0

All seven regression tests passed.

The randomized inputs deliberately stress large offsets, descriptor alignment and arithmetic boundaries. These mismatch counts are not estimates of the defect's frequency in the title.

A sparse two-level page-table model also demonstrates that the truncated address can resolve to a valid but incorrect node, rather than necessarily causing a missing-memory access.

Proposed fix

Reuse the existing explicit-address descriptor decoder for the Source::Built path when root_address(src) is available.

This would preserve:

  • Both halves of the node pointer.
  • Full-width offset arithmetic.
  • The descriptor's actual encoded base and alignment.
  • The existing title-memory lookup and bounds-checking path.

Keep the buffer-backed fallback and resource-tracking checks unchanged in this initial correction.

Regression coverage

The existing wide-pointer GPU test uses small node offsets and leaves the upper pointer word zero.

I suggest extending that fixture with sparse guest-memory mappings at B, B + 4 GiB and B + 32 GiB, using distinguishable valid box nodes and explicitly populating the upper pointer word.

The attached archive includes a proposed fixture design requiring only approximately 336 KiB of page-table and mapped data storage, excluding auxiliary GPU resources.

Attachment

bvh_address_audit_v2.zip contains:

  • Source audit and reproduction instructions.
  • Executable LLVM JIT regression tests.
  • Recorded test results.
  • Proposed Rust implementation changes.
  • Native GPU regression-test design.

Scope and limitations

Related work: #1794, #2098, #2118, #2206 and #2311.

This report concerns BVH node address calculation, not intersection mathematics or traversal optimization.

The proposed Rust change has not been compiled, and native DXIL validation and GPU execution remain pending. I have not established whether the title encounters these particular address patterns or whether they contribute to the missing ray-traced lighting.

No title files, proprietary assets, game captures or memory dumps were used.

bvh_address_audit_v2.zip

**@⁠FunWithFlagsDev** on GitHub · 2026-11-25 12:03 UTC · [original](https://github.com/Marvisak/VIctory/issues/2368) <html> <body> <!--StartFragment--><h2><span>Summary</span></h2><p><span>While auditing the upstream ray-tracing implementation at commit </span><code><span>940d32f69b22265690a0b5a15d6ded572ba33baf</span></code><span>, I found an address-calculation inconsistency between the root-derived and explicit-address BVH lowering paths.</span></p><p><span>The root-derived path can discard the upper bits of the node offset before converting it to a 64-bit address. It also reconstructs the descriptor base without preserving its 256-byte quantization.</span></p><p><span>This can cause an intersection instruction to read a different BVH node from the one requested.</span></p><h2><span>Source evidence</span></h2><ul><li><p><a href="https://github.com/Marvisak/VIctory/blob/940d32f/crates/victory-shader/src/emit/lower/bvh.rs#L120-L180"><span>BVH lowering — bvh.rs</span></a></p></li><li><p><a href="https://github.com/Marvisak/VIctory/blob/940d32f/crates/victory-shader/src/resource.rs#L1271-L1340"><span>BVH descriptor tracking — resource.rs</span></a></p></li><li><p><a href="https://github.com/Marvisak/VIctory/blob/940d32f/crates/victory-shader/src/emit/bvh_tests.rs#L714-L838"><span>Existing GPU regression tests — bvh_tests.rs</span></a></p></li></ul><p><span>The </span><code><span>Source::Built</span></code><span> path calculates the node offset using an i32 shift and additions before widening it with a zero high word.</span></p><p><span>By contrast, the explicit-address path reconstructs the full pointer and performs the shift in i64.</span></p><h2><span>Minimal counterexamples</span></h2><p><span>For an aligned BVH base B, with no additional descriptor offsets:</span></p> Node pointer | Expected address | Current Built/Raw address -- | -- | -- lo=0x1ffffffd, hi=0 | B + 4 GiB − 64 bytes | Correct lo=0x20000005, hi=0 | B + 4 GiB | B lo=0x00000005, hi=1 | B + 32 GiB | B <p><span>All seven regression tests passed.</span></p><p><span>The randomized inputs deliberately stress large offsets, descriptor alignment and arithmetic boundaries. These mismatch counts are not estimates of the defect's frequency in the title.</span></p><p><span>A sparse two-level page-table model also demonstrates that the truncated address can resolve to a valid but incorrect node, rather than necessarily causing a missing-memory access.</span></p><h2><span>Proposed fix</span></h2><p><span>Reuse the existing explicit-address descriptor decoder for the </span><code><span>Source::Built</span></code><span> path when </span><code><span>root_address(src)</span></code><span> is available.</span></p><p><span>This would preserve:</span></p><ul><li><p><span>Both halves of the node pointer.</span></p></li><li><p><span>Full-width offset arithmetic.</span></p></li><li><p><span>The descriptor's actual encoded base and alignment.</span></p></li><li><p><span>The existing title-memory lookup and bounds-checking path.</span></p></li></ul><p><span>Keep the buffer-backed fallback and resource-tracking checks unchanged in this initial correction.</span></p><h2><span>Regression coverage</span></h2><p><span>The existing wide-pointer GPU test uses small node offsets and leaves the upper pointer word zero.</span></p><p><span>I suggest extending that fixture with sparse guest-memory mappings at B, B + 4 GiB and B + 32 GiB, using distinguishable valid box nodes and explicitly populating the upper pointer word.</span></p><p><span>The attached archive includes a proposed fixture design requiring only approximately 336 KiB of page-table and mapped data storage, excluding auxiliary GPU resources.</span></p><h2><span>Attachment</span></h2><p><code><span>bvh_address_audit_v2.zip</span></code><span> contains:</span></p><ul><li><p><span>Source audit and reproduction instructions.</span></p></li><li><p><span>Executable LLVM JIT regression tests.</span></p></li><li><p><span>Recorded test results.</span></p></li><li><p><span>Proposed Rust implementation changes.</span></p></li><li><p><span>Native GPU regression-test design.</span></p></li></ul><h2><span>Scope and limitations</span></h2><p><span>Related work: #1794, #2098, #2118, #2206 and #2311.</span></p><p><span>This report concerns BVH node address calculation, not intersection mathematics or traversal optimization.</span></p><p><span>The proposed Rust change has not been compiled, and native DXIL validation and GPU execution remain pending. I have not established whether the title encounters these particular address patterns or whether they contribute to the missing ray-traced lighting.</span></p><p><span>No title files, proprietary assets, game captures or memory dumps were used.</span></p><p><span>AI-assisted source audit and synthetic verification.</span></p><!--EndFragment--> </body> </html>## Summary While auditing the upstream ray-tracing implementation at commit `940d32f69b22265690a0b5a15d6ded572ba33baf`, I found an address-calculation inconsistency between the root-derived and explicit-address BVH lowering paths. The root-derived path can discard the upper bits of the node offset before converting it to a 64-bit address. It also reconstructs the descriptor base without preserving its 256-byte quantization. This can cause an intersection instruction to read a different BVH node from the one requested. ## Source evidence - [[BVH lowering — bvh.rs](https://github.com/Marvisak/VIctory/blob/940d32f/crates/victory-shader/src/emit/lower/bvh.rs#L120-L180)](https://github.com/Marvisak/VIctory/blob/940d32f/crates/victory-shader/src/emit/lower/bvh.rs#L120-L180) - [[BVH descriptor tracking — resource.rs](https://github.com/Marvisak/VIctory/blob/940d32f/crates/victory-shader/src/resource.rs#L1271-L1340)](https://github.com/Marvisak/VIctory/blob/940d32f/crates/victory-shader/src/resource.rs#L1271-L1340) - [[Existing GPU regression tests — bvh_tests.rs](https://github.com/Marvisak/VIctory/blob/940d32f/crates/victory-shader/src/emit/bvh_tests.rs#L714-L838)](https://github.com/Marvisak/VIctory/blob/940d32f/crates/victory-shader/src/emit/bvh_tests.rs#L714-L838) The `Source::Built` path calculates the node offset using an i32 shift and additions before widening it with a zero high word. By contrast, the explicit-address path reconstructs the full pointer and performs the shift in i64. ## Minimal counterexamples For an aligned BVH base B, with no additional descriptor offsets: | Node pointer | Expected address | Current Built/Raw address | |---|---|---| | `lo=0x1ffffffd, hi=0` | B + 4 GiB − 64 bytes | Correct | | `lo=0x20000005, hi=0` | B + 4 GiB | B | | `lo=0x00000005, hi=1` | B + 32 GiB | B | These addresses can remain within the supported 40-bit guest address space. There is also a separate alignment limitation: widening the arithmetic alone does not preserve the descriptor's 256-byte base quantization. The current source explicitly acknowledges this alignment shortcut. ## Independent verification I implemented three versions of the address calculation in hand-authored LLVM IR and executed them using the LLVM 20.1.8 CPU JIT. | Implementation | Divergences in 20,000 synthetic cases | |---|---:| | Current Built/Raw arithmetic | 20,000 | | Widening the arithmetic only | 19,920 | | Decoding the actual descriptor operands | 0 | All seven regression tests passed. The randomized inputs deliberately stress large offsets, descriptor alignment and arithmetic boundaries. These mismatch counts are not estimates of the defect's frequency in the title. A sparse two-level page-table model also demonstrates that the truncated address can resolve to a valid but incorrect node, rather than necessarily causing a missing-memory access. ## Proposed fix Reuse the existing explicit-address descriptor decoder for the `Source::Built` path when `root_address(src)` is available. This would preserve: - Both halves of the node pointer. - Full-width offset arithmetic. - The descriptor's actual encoded base and alignment. - The existing title-memory lookup and bounds-checking path. Keep the buffer-backed fallback and resource-tracking checks unchanged in this initial correction. ## Regression coverage The existing wide-pointer GPU test uses small node offsets and leaves the upper pointer word zero. I suggest extending that fixture with sparse guest-memory mappings at B, B + 4 GiB and B + 32 GiB, using distinguishable valid box nodes and explicitly populating the upper pointer word. The attached archive includes a proposed fixture design requiring only approximately 336 KiB of page-table and mapped data storage, excluding auxiliary GPU resources. ## Attachment `bvh_address_audit_v2.zip` contains: - Source audit and reproduction instructions. - Executable LLVM JIT regression tests. - Recorded test results. - Proposed Rust implementation changes. - Native GPU regression-test design. ## Scope and limitations Related work: #1794, #2098, #2118, #2206 and #2311. This report concerns BVH node address calculation, not intersection mathematics or traversal optimization. The proposed Rust change has not been compiled, and native DXIL validation and GPU execution remain pending. I have not established whether the title encounters these particular address patterns or whether they contribute to the missing ray-traced lighting. No title files, proprietary assets, game captures or memory dumps were used. [bvh_address_audit_v2.zip](https://github.com/user-attachments/files/35410289/bvh_address_audit_v2.zip)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:03:42 +00:00
Author
Owner

@⁠Calvix2k on GitHub · 2026-11-25 14:54 UTC · original

The shift/add half of this is #2501. What was there: with the base from a root descriptor (Source::Built), the node's offset was (node & !7) << 3 plus the constant and computed parts in 32 bits, then zero-extended to 64 — so a node offset past 2 GiB wraps, and any negative intermediate becomes an offset about 4 GiB too large instead of sign-extending. The explicit-descriptor path in the same function already did that shift in 64 bits, which is what made it look like an inconsistency worth fixing. #2501 moves the raw path to 64-bit arithmetic and leaves the buffer-view path 32-bit, because that is the width D3D12 takes for a buffer's offset.

On the second half — "reconstructs the descriptor base without preserving its 256-byte quantization" — I could not reproduce the reading: in this path the base comes from root_address, i.e. the root descriptor's user-data words (dword 0 and dword 1 bits 0-15), which is the whole 40-bit title address, not the >> 8 descriptor form that the explicit path reconstructs with << 8. Nothing there drops a low byte. If you meant a different reconstruction (a descriptor the title built by shifting a different root, or the console's image_bvh descriptor layout itself), could you point at the line and the value you expect? That would be its own change.

One caveat on #2501 worth writing down here: a case that fails before it needs a BVH over 2 GiB of nodes in title memory, which this machine cannot hold — so the fix is argued from the arithmetic plus the explicit path's existing form, not from a red test. The existing 64-bit-pointer GPU test covers the path and stays green.

**@⁠Calvix2k** on GitHub · 2026-11-25 14:54 UTC · [original](https://github.com/Marvisak/VIctory/issues/2368#issuecomment-7166013724) The shift/add half of this is **#2501**. What was there: with the base from a root descriptor (`Source::Built`), the node's offset was `(node & !7) << 3` plus the constant and computed parts **in 32 bits**, then zero-extended to 64 — so a node offset past 2 GiB wraps, and any negative intermediate becomes an offset about 4 GiB too large instead of sign-extending. The explicit-descriptor path in the same function already did that shift in 64 bits, which is what made it look like an inconsistency worth fixing. #2501 moves the raw path to 64-bit arithmetic and leaves the buffer-view path 32-bit, because that is the width D3D12 takes for a buffer's offset. On the second half — "reconstructs the descriptor base without preserving its 256-byte quantization" — I could not reproduce the reading: in this path the base comes from `root_address`, i.e. the root descriptor's user-data words (dword 0 and dword 1 bits 0-15), which is the whole 40-bit title address, not the `>> 8` descriptor form that the explicit path reconstructs with `<< 8`. Nothing there drops a low byte. If you meant a different reconstruction (a descriptor the title built by shifting a *different* root, or the console's `image_bvh` descriptor layout itself), could you point at the line and the value you expect? That would be its own change. One caveat on #2501 worth writing down here: a case that **fails** before it needs a BVH over 2 GiB of nodes in title memory, which this machine cannot hold — so the fix is argued from the arithmetic plus the explicit path's existing form, not from a red test. The existing 64-bit-pointer GPU test covers the path and stays green.
Author
Owner

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

Automated triage for the maintainers.

Confirmed in main, in the BVH intersection lowering in crates/victory-shader/src/emit/lower/bvh.rs. On the Source::Built path, the node offset (node & !7) << 3 plus the constant and computed parts is built in i32. It is then widened with a zero high word (wide64(self, at, zero)) before it is added to the root address. That path also never reads the node pointer's high word (node_hi). The explicit-descriptor path below it shifts wide64(lo, node_hi) in i64.

On alignment, the same branch carries a shortcut: comment saying the root address is taken to be 256-byte aligned. So that half is a known shortcut and not a slip.

Open PR #2501 does the raw path's offset in 64 bits. Its description does not mention node_hi, so the reviewer should check that the third counterexample (hi=1) is covered. #2402 was closed. The attached zip was not opened by this triage.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 18:48 UTC · [original](https://github.com/Marvisak/VIctory/issues/2368#issuecomment-7171435965) <!-- victory-issue-triage v1 verdict=confirmed seen=2026-11-25T14:54:55Z at=2026-11-25T18:55:00Z --> Automated triage for the maintainers. Confirmed in main, in the BVH intersection lowering in `crates/victory-shader/src/emit/lower/bvh.rs`. On the `Source::Built` path, the node offset `(node & !7) << 3` plus the constant and computed parts is built in i32. It is then widened with a zero high word (`wide64(self, at, zero)`) before it is added to the root address. That path also never reads the node pointer's high word (`node_hi`). The explicit-descriptor path below it shifts `wide64(lo, node_hi)` in i64. On alignment, the same branch carries a `shortcut:` comment saying the root address is taken to be 256-byte aligned. So that half is a known shortcut and not a slip. Open PR #2501 does the raw path's offset in 64 bits. Its description does not mention `node_hi`, so the reviewer should check that the third counterexample (`hi=1`) is covered. #2402 was closed. The attached zip was not opened by this triage. --- _Generated by [Claude Code](https://claude.ai/code)_
This discussion has been locked. Commenting is limited to contributors.
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#2368
No description provided.