shader/bvh: reject partial-axis NaN and inverted boxes via ordered min <= max #464
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/464"
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?
Imported from fxceless/victory-fork. Originally posted by IlyassRS3 on 2026-11-25T01:16:56Z.
Summary
Tightens the BVH box validity check in both the CPU reference (
crates/victory-shader/src/bvh.rs::boxes) and the lowered DXIL slab test (crates/victory-shader/src/emit/intersect.rs::Lower::bvh_boxes) to require ordered per-axis bounds (b[0] <= b[3] && b[1] <= b[4] && b[2] <= b[5], emitted viapred::OLE).Bug
Previously, box validity only checked
!b[0].is_nan(), which allowed two degenerate box classes to register as false hits:NaN(b[1..6] == NaNwith finiteb[0]):low.min(high)/low.max(high)(and DXILFMin/FMax) follow IEEEminNum/maxNumsemantics and silently drop a singleNaNoperand, keepingenterandleavefinite so the ray hits the disabled box.min > maxon any axis): e.g. standard(+inf, -inf)empty BVH sentinels or BOX16(+65504, -65504)sentinels. Takinglow.min(high)andlow.max(high)silently swaps the inverted endpoints back into a solid box (turning(+inf, -inf)into an all-space box every ray hits).Using three ordered comparisons (
pred::OLEin DXIL,<=in Rust) rejects both partial-axisNaNin any of the six coordinates and inverted/empty boxes on any axis, while preserving zero-thickness (min == max) and unbounded (-inf <= +inf) boxes.Scope & non-overlap
#213,#230, and#414: all three checkchildren[n] != NONE, whereas this PR addresses box bound validity (b[a] <= b[3 + a]). They do not duplicate each other.crates/victory-shader/src/emit/intersect_tests.rs::scene()so the Windows GPU/WARP parity tests cover these cases directly.Verification
1.98.1, no Windows GPU / no game files.cargo test --locked -p victory-shader -p xtask: 172 passed, 0 failed (victory-shader, including newbvh::tests::partial_axis_nan_and_inverted_boxes_miss_in_box32_and_box16) + 4 passed, 0 failed (xtask, includingrepository_passes_policy).cargo clippy --locked -p victory-shader --all-targets --target x86_64-pc-windows-msvc -- -D warnings: 0 warnings (includesemit/intersect_tests.rs).cargo clippy --locked -p victory-shader --all-targets --all-features --target x86_64-pc-windows-msvc -- -D warnings: 0 warnings.upstream/main(a803c87): runningpartial_axis_nan_and_inverted_boxes_miss_in_box32_and_box16against unpatchedbvh.rsfails immediately (box32 coord 3returns hit[8, NONE, NONE, NONE]instead of[NONE; 4]).Imported from fxceless/victory-fork. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-25T01:17:08Z.
Review: COMMENTED
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
Imported from fxceless/victory-fork. Originally posted by pr0vId3nce on 2026-11-25T16:05:57Z.
Hardware result: an RDNA2 GPU never enters the empty and inverted boxes this PR rejects, but it does hit boxes with a NaN bound, and boxes entered exactly at the extent
I ran the box test through the real instruction:
image_bvh64_intersect_rayandimage_bvh_intersect_ray, run natively from raw words on a Ryzen 9 7900X's iGPU (gfx1036, RDNA2 with the ray accelerators, driver 32.0.21042.62) through the AMD driver's own amd_comgr/HIP DLLs. I compared that against this PR'sbvh.rs(head02be6ab2a) over the same cases.What it gets right. In 1,902 empty-slot cases, this PR's
bvh.rsreturns the GPU's words in every one. Those cases are six nodes, 16-bit and 32-bit, with +inf/−inf slots beside real children and underffffffffpointers, each tested with 317 rays.maingets 604 of them. The GPU never enters such a slot, and with this PR neither doesbvh.rs. Among the f16 probes, boxes inverted on one axis and the +inf/−inf patterns from #16 match too.Where it still differs. It matches 389 of 552 f16 box probes. 160 of the other 163 fall into two cases. All rows below are 16-bit nodes, children
8, 10, 18, 20, sorted. Slots 1 to 3 are all NaN (missed by both). The ray runs along x, and the result is the four dwords.A NaN bound: the GPU hits, this PR misses (34 of the 552 rows). Slot 0, halves as (min x, min y, min z / max x, max y, max z), ray from (−5, 0, 0) along +x, extent 100:
7e00 bc00 bc00 / 3c00 3c00 3c00(min x NaN)00000008 ffffffff ffffffff ffffffffffffffff ffffffff ffffffff ffffffffbc00 bc00 bc00 / 7e00 3c00 3c00(max x NaN)00000008 ffffffff ffffffff ffffffffffffffff ffffffff ffffffff ffffffffbc00 7e00 bc00 / 3c00 7e00 3c00(y NaN on both sides)00000008 ffffffff ffffffff ffffffffffffffff ffffffff ffffffff ffffffffRule: a NaN bound drops out of the max that forms the entry and the min that forms the exit. The box is missed only when the entry or the exit is still NaN, as with all six bounds NaN, which the GPU missed with all 6 rays.
An entry exactly at the extent: the GPU hits, this PR misses (126 of the 552 rows: 63 halves, each as a min and as a max face). Ray from the origin, extent equal to the entry:
0001 bc00 bc00 / 7bff 3c00 3c0033800000(2^-24)00000008 ffffffff ffffffff ffffffffffffffff ffffffff ffffffff fffffffffbff bc00 bc00 / 8001 3c00 3c003380000000000008 ffffffff ffffffff ffffffffffffffff ffffffff ffffffff ffffffff3c00 bc00 bc00 / 7bff 3c00 3c003f800000(1.0)00000008 ffffffff ffffffff ffffffffffffffff ffffffff ffffffff ffffffffRule: a box is hit iff max(entry, 0) ≤ min(exit, extent). This PR keeps
enter < ray.extent. With the extent one f32 ulp lower, the GPU misses all 126.I have both fixes (NaN bounds dropped from the entry and exit, and the extent compare above), with a test per case holding these GPU words, for
bvh.rsand the DXIL; happy to send them as a suggestion here or as a PR on top of this one.Scope: desktop RDNA2, not the console. Synthetic nodes, no game data. I ran this PR's
bvh.rson the CPU, not its DXIL.AI-assisted (Claude Code); the runs are from my machine.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.