GPU BVH: audit box16/box32 node intersection for inf/NaN ray directions and zero extents #1559
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!1559
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1559"
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?
@slopgobblercobbler on GitHub · 2026-11-24 17:39 UTC · original
slopgobblercobbler:fix/bvh-node-intersection→main· +142 −3 · 2 files · 1 commits · openSummary
Audits bounding volume hierarchy (BVH) node intersection in
crates/xcl/src/gpu/bvh.rsand HLSL recompiler emission incrates/xcl/src/gpu/recomp/emit.rsfor NaN/infinite ray parameters, degenerate directions, and zero-extent bounds:intersect_node:o), non-finite/NaN ray directions (d), NaN inverse ray directions (inv), all-zero ray directions (d == [0, 0, 0]), and negative/NaN ray extents (!(tmax >= 0.0)).NaN.min(NaN)/maxpropagation leaving slab interval[a, b]as[-inf, inf].tmaxfrom falsely matching enclosing boxes with negativet.inv[axis] == 0.0withinv[axis].is_infinite(): rays with zero inverse direction (infinite velocity) only intersect if the origin already lies within the slab interval[mn, mx], rather than collapsing(mn - o) * 0.0to0.0and declaring a false entry hit att = 0.0.mn[axis] == mx[axis], line segment boxes, and point boxes) across box32 and box16 half-precision formats.tmax == 0.0): hits only when ray originolies within or on the box boundary, and misses otherwise.crates/xcl/src/gpu/recomp/emit.rs):any(isnan(o)),any(isinf(o)),any(isnan(d)),any(isinf(d)),any(isnan(inv)),all(d == 0.0f),isnan(tmax),tmax < 0.0f) and unified zero/infinite inverse direction handling in HLSLbvh_intersect.box_intersection_nan_inf_ray_directions_and_boundsandbox_intersection_zero_extents_box32_and_box16inbvh.rs.Changes
crates/xcl/src/gpu/bvh.rs: upfront ray parameter validation, infinite direction handling, and zero-extent bounds.crates/xcl/src/gpu/recomp/emit.rs: HLSL emulation parity for ray intersection validation.Tested
cargo test -p xcl -- bvh: 12 passed, 0 failed.cargo test -p xcl --test console_dlls_e2e: 7 passed, 0 failed.upstream/main, GPL-2.0-only compliant, zero retail game data or keys.Not Tested
AI Use
Co-Authored-By: Claude Code (Claude Opus 5.5) / Gemini Antigravity
@Diskuss on GitHub · 2026-11-24 17:48 UTC · original
Tested on AMD Radeon RX 9070 XT (RDNA4) at
ca5f6a5e4345eabdbddc48e4513f0fecf3112031AMD Radeon RX 9070 XT (RDNA4), driver 32.0.32015.7029; Ryzen 7 5700X3D; 32 GB RAM; Windows 11 Pro build 26300.9974; Rust 1.100.0 x86_64-pc-windows-msvc; DXC 1.9.2602.17; debug build.
Tested:
9e3831e, so no local merge was needed).cargo build --workspace: OK.cargo test --workspace --no-fail-fast -- --test-threads=4: 778 passed, 0 failed, 41 ignored.cargo test -p xcl --lib <name> -- --test-threads=1:box_intersection_nan_inf_ray_directions_and_bounds5/5 passed,box_intersection_zero_extents_box32_and_box165/5 passed (1 passed each run).heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows, same on main); 2 debug-layer tests skip silently, no Graphics Tools installed.9e3831eon the same machine: 776 passed, 0 failed, 41 ignored. The +2 is the two new tests.Not tested: retail title /
scripts/smoke.ps1(no game files), release build.Report written by Claude Code (Claude Sonnet 5.5) from a real run on this machine.
@Anon64 on GitHub · 2026-11-24 17:54 UTC · original
Regression run for this PR: head
ca5f6a5, based onmain9e3831e. RTX 3060 12 GB (581.80, wave32), Windows 11 26200, release,XCL_NETWORK=0, A pressed every 4 s from 20 s,scripts/smoke.ps1on a retail title for 60 s.main
9e3831e:this PR:
No device removals or crashes; 95 % of main's frames, 29 % of its peak commit.
Peak commit on this machine is mostly the pipeline preload's DXC compiles (#1035) and varies a lot from run to run (21–92 GB with the same build), so it says little about this PR.
Not tested: the whole suite; whether the title reaches the changed code in these 60 s.
Written with Claude Code (Claude Opus 5.5) from runs on this machine.
@DavidM1911 on GitHub · 2026-11-24 19:32 UTC · original
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~22 ignored. (Intermittent single-test flake under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodifiedmain.)Thanks!
@Melow-code on GitHub · 2026-11-24 23:02 UTC · original
The NaN/inf guards in
intersect_nodeare correct in isolation, but Anon64 reports a 37-42 FPS regression from 60 FPS on a retail title. That needs investigation before merge.Likely cause: the upfront
if !origin.is_finite() || !dir.is_finite() || inv_dir.has_nan() || dir == Vec3::ZERO || tmax < 0.0 || tmax.is_nan()branch adds divergent control flow to the hottest loop in RT. On RDNA2/3, a branch that is almost never taken still costs the wavefront a few cycles per traversal step because the SIMD must evaluate both paths when any lane diverges.Suggested fix: instead of an upfront branch, handle the edge cases in the slab math itself. For example,
f32::min/f32::maxwith a NaN-aware clamp after the slab computation catches the same cases without a branch. This is what PR #1322 does for the NaN-ray case alone — extend it.If performance is acceptable on the author's hardware, the reviewer data from Anon64 still suggests a problem on different configs. At minimum, the author should run the same 60-second smoke test to compare.
@Melow-code on GitHub · 2026-11-24 23:02 UTC · original · requested changes
The upfront branch adds divergent control flow to the hottest RT loop. Anon64 measured 37-42 FPS vs 60 on main. The NaN/inf cases should be handled in the slab math (branchless), not with an upfront rejection — see PR #1322 for a partial model. Also, the zero-direction rejection changes the semantics of point-in-box tests that the game's shaders may rely on. Needs an RDNA2 hardware measurement before merge.
@thehollowedone on GitHub · 2026-11-26 08:15 UTC · original · edited 2026-11-26 08:23 UTC
Independent Direct DXIL BVH check on current main
b49be18. #1559 headca5f6a5changes the CPU and HLSL box paths, but leavesgpu/dxil/lower_image.rsuntouched. This is a separate Direct DXIL gap; I did not run the PR head.Tested: Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti / NVIDIA 621.35, Rust 1.99.1 MSVC, DXC 1.8.2502.11. On
b49be18with only the synthetic regression added,cargo test --offline --locked -p xcl --lib direct_dxil_bvh_rejects_nan_ray_parameters -- --nocapture --test-threads=1failed (0 passed, 1 failed, 0 ignored, 0 skipped): BOX16 and BOX32 each returned a child for a NaN origin and a NaN inverse direction. The finite hit, finite miss, and NaN parallel-origin controls behaved as expected. With the local Direct DXIL guard below, the same command passed (1 passed, 0 failed, 0 ignored, 0 skipped). WithXCL_DXIL_CACHEset to a writable worktree-local cache,cargo build --offline --locked --workspacepassed.cargo test --offline --locked --workspace --no-fail-fast -- --test-threads=4 --quietthen reported 1,436 passed, 0 failed, 47 ignored across 37 targets, with 25 GPUSKIPPEDnotices. Untouchedb49be18under the same cache setting reported 1,435 passed, 0 failed, 47 ignored, and the same 25 skips. Without the override, the publicconsole_meshcache test fails because this managed sandbox cannot persist its default%LOCALAPPDATA%DXIL cache; it passed in isolation after redirectingXCL_DXIL_CACHE. That setup failure is unrelated to the BVH change.The proposed guard computes one ordered predicate per box from its three origin/inverse pairs, then includes it in each child's hit predicate. It avoids adding a branch to the finite-ray path. The regression covers both box formats and five synthetic rays each. This addresses the measured NaN slab-input gap; it does not establish parity for all of #1559's Inf, zero-direction, or
tmaxcases.Suggested local diff (runtime guard and failing-before regression)
Not tested: #1559 exact head, AMD, a retail title, or performance impact. No game files or dumps were used. AI use: Codex (GPT-6.2 Sol) investigated, wrote the local diff, ran the tests, and drafted this report.
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.