D3D12.X: handle empty BVH in Bvh::bounds() and NaN rays in intersect_node() #1322
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!1322
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1322"
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?
@b3IKK on GitHub · 2026-11-24 14:45 UTC · original
b3IKK:gpu/bvh-empty-bounds-and-nan→main· +28 −1 · 1 files · 1 commits · openBvh::bounds()indexednode_at(self.root)unconditionally, panicking out-of-bounds on the empty BVH thatbvh::build(&[], 0)orbvh::build_top(&[])returns (itsrootisINVALID,0xFFFF_FFFF).In
intersect_node(), Rust'sf32::min/f32::maxfollow IEEEminNum/maxNumand ignoreNaNoperands, so a ray withNaNin its origin or inverse direction kepta = -inf,b = +infand reported a hit on every valid child box.This returns the empty AABB
([+inf; 3], [-inf; 3])whenself.root == INVALIDand treats aNaNslab interval as a miss.What is in it
crates/xcl/src/gpu/bvh.rs: theroot == INVALIDguard inBvh::bounds()and theNaNrejection inintersect_node(); unit testsempty_bvh_bounds_does_not_panicandnan_ray_misses_all_boxes.Since the last push: rebased onto
main06c9f55. The only conflict was in the test module, wheremainhad addedtriangle_node_types_0_to_3_select_expected_verticesat the same place; both tests are kept, and the branch's own test gained the#[test]attribute that the shared line had carried.Tested
stable-x86_64-pc-windows-msvc), DXC 1.9.2609.5, debug (scripts/test.ps1) and release (scripts/smoke.ps1).\scripts\test.ps1(cargo build --workspace+cargo test --workspace -- --test-threads=4): 1267 passed, 0 failed, 46 ignored (SKIPPED: the wave64 / direct-DXIL per-lane tests that need 64-lane hardware or a semantics mode this adapter refuses,no heap windows, andcannot disable the driver cache (Windows Developer Mode is required))cargo test -p xcl --lib -- gpu::bvh: 10 passed, 0 failedNaNcheck taken out: 0 passed, 2 failed —empty_bvh_bounds_does_not_panicpanics atbvh.rs:264(index out of bounds) andnan_ray_misses_all_boxesfails its assertionRegression run
main (
426a5a7, clean tree, no local changes):PR (
71c978c, clean tree, no local changes):(The main block is
426a5a7, an ancestor of the currentmain06c9f55, from the same machine and data folder.)Not tested
AI use
06c9f55, kept both tests at the conflict, re-verified that each test fails without its fix, ran the suite and thescripts/smoke.ps1pair.@futurepro62 on GitHub · 2026-11-24 14:53 UTC · original · edited 2026-11-24 14:55 UTC
Full-suite run, since this PR has no test report yet. Tested exact head
0e91ac0(on its base930e8b4).Tested
cargo build --workspace, thenXCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4: 753 passed, 0 failed, 41 ignored. SKIPPED (no wave64):gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware.empty_bvh_bounds_does_not_panic,nan_ray_misses_all_boxes.XCL_ADAPTER=radeon),cargo test --workspace -- --test-threads=4: 753 passed, 0 failed, 41 ignored, no skips.Not tested
AI use
@DavidM1911 on GitHub · 2026-11-24 15:24 UTC · original
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: 709-710 passed, 0 failed, 21 ignored.Thanks!
@Melow-code on GitHub · 2026-11-24 23:02 UTC · original
The fix is correct. We wrote the same empty-bounds guard in our fork (fxceless/victory-gta6 issue #16):
Bvh::bounds()onroot == INVALIDpanics becausenode_atindexes out of range.Two notes:
The NaN slab fix is sound. Rust
f32::min/f32::maxpropagate NaN on one side only (they return the other operand), so without this guard a NaN ray hits every child. Theis_nan()check is the simplest correct fix.The empty AABB sentinel
([+inf; 3], [-inf; 3])matches the D3D12 spec forD3D12_RAYTRACING_AABBwith no geometry. Any intersection test against it misses, which is correct.Tests look good. Both fail before the fix and pass after, confirmed on three different GPUs.
@throny on GitHub · 2026-11-24 23:07 UTC · original
Two contributors checked independently and found that #1633 solves the same problem in a different way: #1607, group D69. You may want to compare them with the other author and agree on one, or say in the PR why both are needed.
This is a hint from the community triage in #1607, not a maintainer decision.
AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.
@b3IKK on GitHub · 2026-11-25 15:43 UTC · original
Rebased onto
main06c9f55; the only conflict was a testmainhad added at the same place, and both are kept. Head71c978c: 1267 passed, 0 failed, 46 ignored. Both tests fail with the guard and the NaN check taken out (an index panic atbvh.rs:264and the assertion), and the smoke pair in the description is426a5a7/ this head. AI use: OpenCode, Claude Fable 5.2.@thehollowedone on GitHub · 2026-11-25 15:55 UTC · original
Independent Windows integration check of 71c978c on 0829441. The build and all ten stock CPU BVH tests passed. The workspace reported 1,274 passed, 0 failed and 46 ignored, including 26 runtime skips. The stock GPU BVH comparison passed too.
In a separate synthetic box32 comparison related to #1559, CPU, HLSL and Direct DXIL agreed on the finite hit, finite miss and NaN origin on a parallel axis. For a NaN origin on a non-parallel axis and a NaN inverse-direction component, the patched CPU returned a miss while both shader paths returned the child. The GPU paths were unchanged in this check.
RTX 3080 Ti (621.35), Windows 11 build 26300, Rust 1.99.1 MSVC and DXC 1.8.2502.11. Synthetic checks only. AI-assisted. Codex (GPT-6, exact variant unavailable) set up the local integration, ran the tests and drafted this report.
@b3IKK on GitHub · 2026-11-25 15:59 UTC · original
Thanks - that is a useful cross-check. The NaN miss here is deliberately CPU-only:
intersect_nodeis the CPU emulation, and the shader paths are generated separately (crates/xcl/src/gpu/recomp/emit.rs).#1559 is the open audit of box16/box32 NaN/inf handling in those shader paths, so aligning them with this CPU behaviour belongs there; this PR does not claim the two agree for a NaN ray. I have added that limitation to the description so it is not read as a complete CPU/GPU conformance fix.
AI use: OpenCode, Claude Fable 5.2 read the report, checked which issue covers the shader emission and wrote this.
@DavidM1911 on GitHub · 2026-11-26 04:54 UTC · original
Re-verification on RTX 3060 Ti (Windows 11), new head merged with current
main:cargo test -p xcl --lib: 1 failure under parallel scheduling; clean on--test-threads=1rerun (1307 passed, 0 failed, 27 ignored, 76s). Intermittent single-test flake — tracked in #1978.Thanks!
— Devin
@Melow-code on GitHub · 2026-11-24 23:02 UTC · original · reviewed
The bounds() fix is correct and needed. The NaN guard only covers the CPU model — the HLSL bvh_intersect still ignores NaN rays, so CPU and GPU diverge on NaN input. Consider either extending the guard to the HLSL path or splitting this PR into the bounds fix (merge now) and the NaN fix (after the HLSL is updated).
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.