D3D12.X: handle empty BVH in Bvh::bounds() and NaN rays in intersect_node() #1312
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/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?
Imported from ivall/xcl. Originally posted by b3IKK on 2026-11-24T14:45:45Z.
Bvh::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.Imported from ivall/xcl. Originally posted by futurepro62 on 2026-11-24T14:53:19Z.
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
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T15:24:12Z.
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!
Imported from ivall/xcl. Originally posted by Melow-code on 2026-11-24T23:02:46Z.
Review: COMMENTED
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).
Imported from ivall/xcl. Originally posted by Melow-code on 2026-11-24T23:02:19Z.
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.
Imported from ivall/xcl. Originally posted by throny on 2026-11-24T23:07:10Z.
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.
upstream-sync referenced this pull request2026-11-25 06:04:27 +00:00
upstream-sync referenced this pull request2026-11-25 16:10:51 +00:00
Imported from ivall/xcl. Originally posted by b3IKK on 2026-11-25T15:43:19Z.
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.Imported from ivall/xcl. Originally posted by thehollowedone on 2026-11-25T15:55:56Z.
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.
Imported from ivall/xcl. Originally posted by b3IKK on 2026-11-25T15:59:34Z.
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.
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-26T04:54:51Z.
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
Imported from ivall/xcl. Originally posted by upipibi on 2026-11-26T16:03:45Z.
NVIDIA test report for
71c978c: RTX 3070 8 GB (Ampere, driver 616.56), Windows 11 26100, Rust 1.100.0, debug.cargo test -p xcl --lib -- --skip hle::xaudio2 --test-threads=4on the head as it is (on06c9f55): 1189 passed, 0 failed, 26 ignored; all 10gpu::bvhtests ok. 25 SKIPPED: 21no wave64, 3 wave32 per-lane forms the translator refuses (#1426), 1pso_measurement_compiles_an_exact_synthetic_recordwithout Developer Mode. None is inbvh.rs.empty_bvh_bounds_does_not_panicandnan_ray_misses_all_boxes,--exact --test-threads=1 --nocapture, 3 runs each: 6/6 passed, 0 SKIPPED (CPU model only; the shader-path NaN cases of #1559 are not covered).Lib tests only; no title run.
AI-assisted (Claude Code, Claude Opus 5.5).
Imported from ivall/xcl. Originally posted by Decodere on 2026-11-27T00:18:24Z.
Independent desktop NVIDIA verification of PR #1322 at head
71c978c935ff0ba0358b0f5e56b7942f59f3e5bd(1commit; exact parent & merge-base:06c9f5505f63f10c5ec49ef932d75b2c28177324, pre-#2555ancestor ofmain).Environment
7956 MiBreported by D3D12), driver32.0.16.2114(NVIDIA621.14, WDDM 3.2)31.9 GiBusable), Windows 11 Home26200(Developer Mode off)rustc 1.100.0 (0ef1bc386 2026-11-09)MSVC, DXC1.9.2609.5,--releaseTargeted release tests & build (
71c978c9)cargo test --release -p xcl --lib empty_bvh_bounds_does_not_panic -- --nocapture(3 consecutive runs)1 passed; 0 failed; 0 ignored; 1223 filtered out× 3 (0.00s× 3)cargo test --release -p xcl --lib nan_ray_misses_all_boxes -- --nocapture(3 consecutive runs)1 passed; 0 failed; 0 ignored; 1223 filtered out× 3 (0.00s× 3)cargo test --release -p xcl --lib gpu::bvh::(3 consecutive runs)10 passed; 0 failed; 0 ignored; 1214 filtered out× 3 (0.10s× 3,0skipped)cargo build --release -p xcl1m 04s, exit0,0new warnings)Paired quiet 60 s retail smoke (
title: 29640639)Exact parent & merge-base (
06c9f5505f63f10c5ec49ef932d75b2c28177324, cached baseline on the same machine):PR #1322 (
71c978c935ff0ba0358b0f5e56b7942f59f3e5bd):Runtime log observations (
xcl.log)9210log lines,0[ERROR]/ device-removal / panic lines.19627 draws with translated pipelines (0 skipped, 0 with PC pipelines), 1024 dispatches (0 skipped); last memory sample14448 MB committed by the process; video memory 6115 MB local, 4683 MB non-local.Limits of coverage
Bvh::bounds()(root == INVALID) and NaN-ray slab-miss handling inintersect_node()are pure BVH paths verified directly via both new unit tests (3/3each) andgpu::bvh::(10/10× 3).title: 29640639(frame-count delta vs. cached parent smoke reflects single-run startup variance, not this PR).AI disclosure: test execution and report drafting assisted by Google Antigravity (Gemini 4 Neon).
Imported from ivall/xcl. Originally posted by JJAutoCompare on 2026-11-27T00:32:06Z.
Tested: Clean
71c978c935ff0ba0358b0f5e56b7942f59f3e5bd, Windows 11 build 26200.9974, Ryzen 7 3800X, Intel Arc A770 driver 32.0.101.9175, Rust 1.100.0 MSVC debug. Builtcargo test -j 2 -p xcl --lib --no-run. Thegpu::bvh::tests::filter passed 10 CPU tests including empty bounds and NaN rays. Three exact Arc fixtures passed:gpu_bvh_intersect_ray,gpu_bvh64_intersect_ray_across_memory_windows_and_grazing,gpu_bvh_triangle_types_2_and_3. Zero failures, ignores or skips. The GPU cases cover adjacent finite-ray sorting/traversal and hit/miss behavior.Not tested: NaN-ray handling on GPU, Direct DXIL, native DXR, workspace suite, and retail smoke.
AI use: T3 Code / Codex (
gpt-6.2-sol) ran and reran the checks and drafted this report.Imported from ivall/xcl. Originally posted by thehollowedone on 2026-11-28T09:47:14Z.
merge-check
base:
e429936c10head:
71c978c935merge: clean
build:
cargo build --offline --locked -j 4 --workspace-> oktests:
cargo test --offline --locked -j 4 --workspace --no-fail-fast -- --test-threads=4-> 2,127 passed, 10 failed, 48 ignored; 25 GPU skip notices. The same 10 tests failed in my earlier untouched-main run at this base:dispatch_chain_oversized_loop_matches_whole,dispatch_chain_wave32_live_loops,dispatch_chain_wave64_live_loops_and_exchange,gpu_heap_flat_reads_match_guarded_and_root_output,console_mesh_caches_hlsl_compute_pass_in_memory_and_on_disk,gpu_compute_mode_dispatch_abi,gpu_float_cas_uses_ieee_equality, and the threetest_title_*e2e cases. The focusedgpu::bvh::testsfilter passed 10/10, including both new regressions, with 0 ignored or skipped.review: no blocker found in the full diff. The empty-root guard avoids indexing
INVALIDand returns the inverted empty AABB; the NaN-slab check rejects the affected child without changing finite-ray results. #1633 overlaps the empty-bounds hunk but addresses separate transform guards and returns a different sentinel there. If #1322 merges first, preserve its empty-box semantics when #1633 is rebased. The CPU model's NaN behavior still differs from the shader paths, tracked separately in #1559.performance: reasoned only. Source search found no production caller of this CPU BVH model in
crates/xcl/src; the shader paths are unchanged. No frame-time benchmark was run.verdict: safe to merge relative to the checked main base; the full suite remains red for the same 10 base failures.
hardware / tool and model: Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti / 621.35, DXC 1.8.2502.11; Codex (GPT-6.2 Sol) reviewed the diff and ran these checks.
Imported from ivall/xcl. Originally posted by throny on 2026-11-28T13:22:55Z.
merge-check claim
head:
71c978c935Imported from ivall/xcl. Originally posted by throny on 2026-11-28T13:38:31Z.
merge-check
base:
e429936chead:
71c978c935merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2128 passed, 9 failed, 48 ignored (26 SKIPPED lines). The 9 failures are main's own at
e429936con this GPU (#3093), the same set with and without this PR; base alone: 2126 passed, 9 failed, 48 ignored.review: no blocker. An empty structure's bounds are now the inverted empty box; both changed functions are used only by tests and the CPU model on main, so nothing at run time consumes the result. NaN rays: with a finite inverse direction and a NaN origin, or a NaN inverse, the slab test used to fall out as a hit (min and max drop the NaN) and is now a miss; the parallel-axis and invalid-box cases were misses already. Open from the thread: the GPU paths still report a hit for NaN rays (that is #1559), so the CPU model and the GPU now disagree there, and the comment 'same results as the HLSL emulation' is no longer true for NaN rays.
performance: none; not a translator source.
verdict: safe to merge
hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300, Rust 1.100.0, debug. Claude Code; merge, build and suite run by Claude Fable 5.2, diff review by Claude Opus 5.5 (every hunk read; nothing run on the GPU beyond the suite).