Shaders: root-derived BVH node addresses lose high pointer bits and descriptor alignment #2368
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory#2368
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@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
BVH lowering — bvh.rs
BVH descriptor tracking — resource.rs
Existing GPU regression tests — bvh_tests.rs
The
Source::Builtpath 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 | BAll 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::Builtpath whenroot_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.zipcontains: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>## SummaryWhile 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
github.com/Marvisak/VIctory@940d32f/crates/victory-shader/src/emit/lower/bvh.rs (L120-L180))github.com/Marvisak/VIctory@940d32f/crates/victory-shader/src/resource.rs (L1271-L1340))github.com/Marvisak/VIctory@940d32f/crates/victory-shader/src/emit/bvh_tests.rs (L714-L838))The
Source::Builtpath 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:
lo=0x1ffffffd, hi=0lo=0x20000005, hi=0lo=0x00000005, hi=1These 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.
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::Builtpath whenroot_address(src)is available.This would preserve:
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.zipcontains: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
@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) << 3plus 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>> 8descriptor 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'simage_bvhdescriptor 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.
@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 theSource::Builtpath, the node offset(node & !7) << 3plus 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 shiftswide64(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