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

Closed
hajduzsolt wants to merge 2 commits from upstream-pr/1521 into main
hajduzsolt commented 2026-11-24 17:15:26 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by hajduzsolt on 2026-11-24T17:15:26Z.


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.
<!-- greyfinch-sync:ivall/xcl:issue:6587378834 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1521). Originally posted by [hajduzsolt](https://github.com/hajduzsolt) on 2026-11-24T17:15:26Z. --- 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.
GonZiin commented 2026-11-24 18:08:03 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by GonZiin on 2026-11-24T17:27:31Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:ivall/xcl:review:6044171653 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1521#pullrequestreview-6044171653). Originally posted by [GonZiin](https://github.com/GonZiin) on 2026-11-24T17:27:31Z. **Review:** COMMENTED --- 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.
gut0to commented 2026-11-24 19:06:05 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by gut0to on 2026-11-24T18:50:43Z.

Review: COMMENTED


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

<!-- greyfinch-sync:ivall/xcl:review:6045350979 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1521#pullrequestreview-6045350979). Originally posted by [gut0to](https://github.com/gut0to) on 2026-11-24T18:50:43Z. **Review:** COMMENTED --- AI-assisted review; I checked this threshold against the finite inverse for a small-scale matrix.
DavidM1911 commented 2026-11-24 19:07:47 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T18:54:01Z.


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!

<!-- greyfinch-sync:ivall/xcl:comment:7141308815 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1521#issuecomment-7141308815). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-24T18:54:01Z. --- 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!
gut0to commented 2026-11-24 19:08:01 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by gut0to on 2026-11-24T18:50:43Z.

Code review location: crates/xcl/src/gpu/bvh.rs; line 220

@@ -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.

<!-- greyfinch-sync:ivall/xcl:review-comment:4684928847 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1521#discussion_r4684928847). Originally posted by [gut0to](https://github.com/gut0to) on 2026-11-24T18:50:43Z. **Code review location:** `crates/xcl/src/gpu/bvh.rs`; line 220 ~~~~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.
hajduzsolt commented 2026-11-24 21:08:38 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by hajduzsolt on 2026-11-24T19:08:16Z.


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).

<!-- greyfinch-sync:ivall/xcl:comment:7141654390 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1521#issuecomment-7141654390). Originally posted by [hajduzsolt](https://github.com/hajduzsolt) on 2026-11-24T19:08:16Z. --- 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).
throny commented 2026-11-25 01:10:37 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by throny on 2026-11-25T00:15:33Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7148320313 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1521#issuecomment-7148320313). Originally posted by [throny](https://github.com/throny) on 2026-11-25T00:15:33Z. --- <!-- 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.
JJAutoCompare commented 2026-11-25 06:05:46 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by JJAutoCompare on 2026-11-25T05:20:23Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7153675891 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1521#issuecomment-7153675891). Originally posted by [JJAutoCompare](https://github.com/JJAutoCompare) on 2026-11-25T05:20:23Z. --- ### 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.
upstream-sync closed this pull request 2026-11-25 15:05:43 +00:00
hajduzsolt commented 2026-11-25 15:08:03 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by hajduzsolt on 2026-11-25T14:54:41Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7166007338 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1521#issuecomment-7166007338). Originally posted by [hajduzsolt](https://github.com/hajduzsolt) on 2026-11-25T14:54:41Z. --- 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.
DavidM1911 commented 2026-11-26 06:06:46 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-26T05:40:33Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7183702409 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1521#issuecomment-7183702409). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-26T05:40:33Z. --- 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.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!1511
No description provided.