BVH: guard determinant in world_to_object against zero-scale or singular transforms #1521

Closed
github-bot wants to merge 2 commits from gh-pr/1521/head into gh-pr/1521/base
Owner

@⁠hajduzsolt on GitHub · 2026-11-24 17:15 UTC · original
hajduzsolt:fix/bvh-singular-instance-transform → main · +81 −1 · 1 files · 2 commits · closed without merging

Runtime fix verified with unit tests and RX 9070 XT smoke run.

What is in it

  • crates/xcl/src/gpu/bvh.rs: in world_to_object, return [0f32; 12] when det is non-finite or det.abs() <= 1e-30 to prevent division by zero and NaN emission into instance nodes.
  • crates/xcl/src/gpu/bvh.rs: add unit test zero_scale_or_singular_instance_transform_does_not_emit_nan verifying zero-scale, singular, and non-finite matrices yield finite inverse transforms and clean ray misses without panics or NaNs.

Tested

  • hardware (GPU + driver, CPU), Windows build, Rust version, debug / release: AMD Radeon RX 9070 XT (driver 24.12.1), AMD Ryzen 7 9800X3D, Windows 11 10.0.26100, Rust 1.85.0 (stable-x86_64-pc-windows-msvc), debug (cargo test)
  • cargo test --workspace -- --test-threads=2: 749 passed, 0 failed, 12 ignored
  • cargo test -p xcl --lib gpu::bvh::tests: 8 passed, 0 failed

Regression run

main:

xcl-smoke v1
commit: c160d86ef2efe3a07e4dfb473e4fa72eafb413c0
gpu: AMD Radeon RX 9070 XT
title: A newer retail game
seconds: 60
exit: 0x0
frames shown: 1594 (PresentX 1594)
presents per 2 s (last 3): 49 48 14
device removals: 0
crashes: 0
peak commit: 20195 MB

PR:

xcl-smoke v1
commit: 172041475f0518b778603ed1d1b980514881eb96
gpu: AMD Radeon RX 9070 XT
title: A newer retail game
seconds: 60
exit: 0x0
frames shown: 1679 (PresentX 1679)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14706 MB

Not tested

  • Dynamic BVH rebuilds with procedural AABBs

AI use

  • Antigravity (Gemini 4 Hydrogen, low): static code audit, implementation of det numerical guarding in world_to_object, and synthetic unit test authoring.
**@⁠hajduzsolt** on GitHub · 2026-11-24 17:15 UTC · [original](https://github.com/xcl-dev/xcl/pull/1521) `hajduzsolt:fix/bvh-singular-instance-transform` → `main` · +81 −1 · 1 files · 2 commits · closed without merging Runtime fix verified with unit tests and RX 9070 XT smoke run. **What is in it** - `crates/xcl/src/gpu/bvh.rs`: in `world_to_object`, return `[0f32; 12]` when `det` is non-finite or `det.abs() <= 1e-30` to prevent division by zero and `NaN` emission into instance nodes. - `crates/xcl/src/gpu/bvh.rs`: add unit test `zero_scale_or_singular_instance_transform_does_not_emit_nan` verifying zero-scale, singular, and non-finite matrices yield finite inverse transforms and clean ray misses without panics or `NaN`s. **Tested** - hardware (GPU + driver, CPU), Windows build, Rust version, debug / release: AMD Radeon RX 9070 XT (driver 24.12.1), AMD Ryzen 7 9800X3D, Windows 11 10.0.26100, Rust 1.85.0 (stable-x86_64-pc-windows-msvc), debug (`cargo test`) - `cargo test --workspace -- --test-threads=2`: 749 passed, 0 failed, 12 ignored - `cargo test -p xcl --lib gpu::bvh::tests`: 8 passed, 0 failed **Regression run** main: ``` xcl-smoke v1 commit: c160d86ef2efe3a07e4dfb473e4fa72eafb413c0 gpu: AMD Radeon RX 9070 XT title: A newer retail game seconds: 60 exit: 0x0 frames shown: 1594 (PresentX 1594) presents per 2 s (last 3): 49 48 14 device removals: 0 crashes: 0 peak commit: 20195 MB ``` PR: ``` xcl-smoke v1 commit: 172041475f0518b778603ed1d1b980514881eb96 gpu: AMD Radeon RX 9070 XT title: A newer retail game seconds: 60 exit: 0x0 frames shown: 1679 (PresentX 1679) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14706 MB ``` **Not tested** - Dynamic BVH rebuilds with procedural AABBs **AI use** - Antigravity (Gemini 4 Hydrogen, low): static code audit, implementation of `det` numerical guarding in `world_to_object`, and synthetic unit test authoring.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:56:16 +00:00
github-bot closed this pull request 2026-11-26 04:56:16 +00:00
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 18:54 UTC · original

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~21 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified main.)

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-24 18:54 UTC · [original](https://github.com/xcl-dev/xcl/pull/1521#issuecomment-7141308815) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~21 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified `main`.) Thanks!
Author
Owner

@⁠hajduzsolt on GitHub · 2026-11-24 19:08 UTC · original

Thanks for the concrete repro. The determinant check now rejects zero and non-finite values, and the computed inverse and translation are checked after conversion to f32. Added coverage for the small uniform scale and overflow cases. cargo test --workspace -- --test-threads=2 passed (existing ignored tests remain ignored).

**@⁠hajduzsolt** on GitHub · 2026-11-24 19:08 UTC · [original](https://github.com/xcl-dev/xcl/pull/1521#issuecomment-7141654390) Thanks for the concrete repro. The determinant check now rejects zero and non-finite values, and the computed inverse and translation are checked after conversion to f32. Added coverage for the small uniform scale and overflow cases. `cargo test --workspace -- --test-threads=2` passed (existing ignored tests remain ignored).
Author
Owner

@⁠throny on GitHub · 2026-11-25 00:15 UTC · original

Two contributors checked independently and found that #1633 #1688 solves the same problem (for #1488) in a different way: #1607, group D52. 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.

**@⁠throny** on GitHub · 2026-11-25 00:15 UTC · [original](https://github.com/xcl-dev/xcl/pull/1521#issuecomment-7148320313) <!-- xcl-1607-hint:D52 --> Two contributors checked independently and found that #1633 #1688 solves the same problem (for #1488) in a different way: #1607, group D52. 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.
Author
Owner

@⁠JJAutoCompare on GitHub · 2026-11-25 05:20 UTC · original

Empirical test report (17204147)

Verified PR #1521 at 172041475f0518b778603ed1d1b980514881eb96.

Hardware / environment

  • Windows x64 build 26200. AMD CPU, family 23, model 113, stepping 0. CPU-only execution without acquiring the Arc GPU mutex.
  • rustc 1.100.0 (0ef1bc386 2026-11-09). DXC 1.9.2609.5 (01b62ad47). Cargo used the unoptimized test profile with debug info and incremental compilation disabled.

Commands and results

  • cargo test --workspace --no-run exited 0 and built the workspace test executables.
  • cargo test -p xcl --lib gpu::bvh::tests::inverse_preserves_small_scales_and_rejects_unrepresentable_results -- --exact --nocapture exited 0 with 1 passed, 0 failed, and 0 ignored.
  • cargo test -p xcl --lib gpu::bvh::tests::zero_scale_or_singular_instance_transform_does_not_emit_nan -- --exact --nocapture exited 0 with 1 passed, 0 failed, and 0 ignored.
  • Both focused runs used XCL_ADAPTER=NONE_CPU_ONLY and RUST_TEST_NOCAPTURE=1. The captured output totals 2 passed, 0 failed, 0 ignored, and 0 SKIPPED lines.

Observed behavior

  • The 1e-11 scale retained inverse diagonal entries near 1e11. Overflow in inverse translation or in an inverse coefficient yielded twelve zeros.
  • The zero-scale, singular, and NaN determinant fixtures yielded twelve zeros. The zero-scale instance emitted a valid top-level BVH root and twelve finite inverse words. CPU traversal returned no hit with the test's empty BLAS lookup.

Not tested

The full GPU workspace suite and game smoke runs were omitted.

AI use

Verified with T3 Code / Codex (gpt-6.2-sol, reasoningEffort: high). Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified counts against pr1521-focused.log and published.

**@⁠JJAutoCompare** on GitHub · 2026-11-25 05:20 UTC · [original](https://github.com/xcl-dev/xcl/pull/1521#issuecomment-7153675891) ### Empirical test report (17204147) Verified PR #1521 at `172041475f0518b778603ed1d1b980514881eb96`. **Hardware / environment** - Windows x64 build 26200. AMD CPU, family 23, model 113, stepping 0. CPU-only execution without acquiring the Arc GPU mutex. - `rustc 1.100.0 (0ef1bc386 2026-11-09)`. DXC `1.9.2609.5 (01b62ad47)`. Cargo used the unoptimized test profile with debug info and incremental compilation disabled. **Commands and results** - `cargo test --workspace --no-run` exited 0 and built the workspace test executables. - `cargo test -p xcl --lib gpu::bvh::tests::inverse_preserves_small_scales_and_rejects_unrepresentable_results -- --exact --nocapture` exited 0 with 1 passed, 0 failed, and 0 ignored. - `cargo test -p xcl --lib gpu::bvh::tests::zero_scale_or_singular_instance_transform_does_not_emit_nan -- --exact --nocapture` exited 0 with 1 passed, 0 failed, and 0 ignored. - Both focused runs used `XCL_ADAPTER=NONE_CPU_ONLY` and `RUST_TEST_NOCAPTURE=1`. The captured output totals 2 passed, 0 failed, 0 ignored, and 0 `SKIPPED` lines. **Observed behavior** - The `1e-11` scale retained inverse diagonal entries near `1e11`. Overflow in inverse translation or in an inverse coefficient yielded twelve zeros. - The zero-scale, singular, and NaN determinant fixtures yielded twelve zeros. The zero-scale instance emitted a valid top-level BVH root and twelve finite inverse words. CPU traversal returned no hit with the test's empty BLAS lookup. **Not tested** The full GPU workspace suite and game smoke runs were omitted. **AI use** Verified with T3 Code / Codex (gpt-6.2-sol, reasoningEffort: high). Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified counts against `pr1521-focused.log` and published.
Author
Owner

@⁠hajduzsolt on GitHub · 2026-11-25 14:54 UTC · original

Thank you for the reviews and test reports. Closing this in favor of #1688, which implements the same zero/non-finite determinant guard and validates that the computed inverse remains finite, including the small-scale case raised in review. Its implementation covers the same fix.

**@⁠hajduzsolt** on GitHub · 2026-11-25 14:54 UTC · [original](https://github.com/xcl-dev/xcl/pull/1521#issuecomment-7166007338) Thank you for the reviews and test reports. Closing this in favor of #1688, which implements the same zero/non-finite determinant guard and validates that the computed inverse remains finite, including the small-scale case raised in review. Its implementation covers the same fix.
Author
Owner

@⁠gut0to on GitHub · 2026-11-24 18:50 UTC · original
On crates/xcl/src/gpu/bvh.rs line 220 (outdated):

@@ -217,6 +217,9 @@ fn transform_aabb(m: &[[f32; 4]; 3], (mn, mx): Aabb) -> Aabb {
 fn world_to_object(m: &[[f32; 4]; 3]) -> [f32; 12] {
     let a = |r: usize, c: usize| m[r][c] as f64;
     let det = a(0, 0) * (a(1, 1) * a(2, 2) - a(1, 2) * a(2, 1)) - a(0, 1) * (a(1, 0) * a(2, 2) - a(1, 2) * a(2, 0)) + a(0, 2) * (a(1, 0) * a(2, 1) - a(1, 1) * a(2, 0));
+    if !det.is_finite() || det.abs() <= 1e-30 {

This absolute determinant cutoff rejects valid invertible transforms. For diagonal scales 1e-11, 1e-10, 1e-10, the determinant is 1e-31, while the inverse diagonal (1e11, 1e10, 1e10) is finite and representable as f32; returning zero makes instance-ray traversal degenerate. Could singularity handling validate the computed inverse for finiteness or use a scale-relative criterion instead of this absolute threshold? AI-assisted review; I verified the values.

**@⁠gut0to** on GitHub · 2026-11-24 18:50 UTC · [original](https://github.com/xcl-dev/xcl/pull/1521#discussion_r4684928847) On `crates/xcl/src/gpu/bvh.rs` line 220 (outdated): ```diff @@ -217,6 +217,9 @@ fn transform_aabb(m: &[[f32; 4]; 3], (mn, mx): Aabb) -> Aabb { fn world_to_object(m: &[[f32; 4]; 3]) -> [f32; 12] { let a = |r: usize, c: usize| m[r][c] as f64; let det = a(0, 0) * (a(1, 1) * a(2, 2) - a(1, 2) * a(2, 1)) - a(0, 1) * (a(1, 0) * a(2, 2) - a(1, 2) * a(2, 0)) + a(0, 2) * (a(1, 0) * a(2, 1) - a(1, 1) * a(2, 0)); + if !det.is_finite() || det.abs() <= 1e-30 { ``` This absolute determinant cutoff rejects valid invertible transforms. For diagonal scales `1e-11, 1e-10, 1e-10`, the determinant is `1e-31`, while the inverse diagonal (`1e11, 1e10, 1e10`) is finite and representable as `f32`; returning zero makes instance-ray traversal degenerate. Could singularity handling validate the computed inverse for finiteness or use a scale-relative criterion instead of this absolute threshold? AI-assisted review; I verified the values.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-26 05:40 UTC · original

Re-verification on RTX 3060 Ti (Windows 11): still a merge conflict with current main on the new head — needs another rebase before it can be tested.

**@⁠DavidM1911** on GitHub · 2026-11-26 05:40 UTC · [original](https://github.com/xcl-dev/xcl/pull/1521#issuecomment-7183702409) Re-verification on RTX 3060 Ti (Windows 11): still a **merge conflict with current `main`** on the new head — needs another rebase before it can be tested.
Author
Owner

@⁠GonZiin on GitHub · 2026-11-24 17:27 UTC · original · reviewed

The absolute determinant cutoff turns some invertible transforms into zero matrices. I reproduced a ray hit becoming a miss with a uniform scale of 1e-11 on all three axes. This transform has condition number 1 and its inverse diagonal is finite in f32.

Tested

  • Windows 11 Pro build 26300, Ryzen 7 7800X3D, Rust 1.100.0 MSVC. Compiled each revision's bvh.rs with rustc --edition=2021 --test and ran a CPU-only probe against a real BLAS containing one unit triangle. The ray starts at [0.25s, 0.25s, -s] and points along +z, where s = 1e-11.
  • Base 9e3831e1f570d3646e53ab753b19ec07eb8f1485 returned Some((1e-11, 0, 42)) and an inverse diagonal of 1e11. Head 09877ade1de6738cfbb778ab9988bc0990bc9b0d returned None and a zero inverse. The PR's singular-transform test also passed on this head.

Please preserve invertible transforms whose inverse components remain representable. Checking for a zero determinant and validating the computed inverse and translation after conversion to f32 would preserve this case.

Not tested

GPU traversal and retail titles.

AI use

Codex (gpt-6.2-sol) wrote and ran the probe and drafted this review.

**@⁠GonZiin** on GitHub · 2026-11-24 17:27 UTC · [original](https://github.com/xcl-dev/xcl/pull/1521#pullrequestreview-6044171653) · **reviewed** The absolute determinant cutoff turns some invertible transforms into zero matrices. I reproduced a ray hit becoming a miss with a uniform scale of `1e-11` on all three axes. This transform has condition number 1 and its inverse diagonal is finite in `f32`. **Tested** - Windows 11 Pro build 26300, Ryzen 7 7800X3D, Rust 1.100.0 MSVC. Compiled each revision's `bvh.rs` with `rustc --edition=2021 --test` and ran a CPU-only probe against a real BLAS containing one unit triangle. The ray starts at `[0.25s, 0.25s, -s]` and points along `+z`, where `s = 1e-11`. - Base `9e3831e1f570d3646e53ab753b19ec07eb8f1485` returned `Some((1e-11, 0, 42))` and an inverse diagonal of `1e11`. Head `09877ade1de6738cfbb778ab9988bc0990bc9b0d` returned `None` and a zero inverse. The PR's singular-transform test also passed on this head. Please preserve invertible transforms whose inverse components remain representable. Checking for a zero determinant and validating the computed inverse and translation after conversion to `f32` would preserve this case. **Not tested** GPU traversal and retail titles. **AI use** Codex (`gpt-6.2-sol`) wrote and ran the probe and drafted this review.
Author
Owner

@⁠gut0to on GitHub · 2026-11-24 18:50 UTC · original · reviewed

AI-assisted review; I checked this threshold against the finite inverse for a small-scale matrix.

**@⁠gut0to** on GitHub · 2026-11-24 18:50 UTC · [original](https://github.com/xcl-dev/xcl/pull/1521#pullrequestreview-6045350979) · **reviewed** AI-assisted review; I checked this threshold against the finite inverse for a small-scale matrix.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.