xdxr_bvh: handle D3D12 inactive primitives and NaN bounds (OLD-10063) #598

Merged
jarvixaiassistant-glitch merged 2 commits from upstream-pr/598 into main 2026-11-24 22:33:50 +00:00
jarvixaiassistant-glitch commented 2026-11-24 09:38:15 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by jarvixaiassistant-glitch on 2026-11-24T09:38:15Z.


Claimed in the coordination issue as: OLD-10063

What and why

Carries forward old-pr/10063 (draft #329) onto main (d7576d56a), preserving ShotTechOp's original commit verbatim per CONTRIBUTING.md and adding one focused hardening commit on top:

  1. Original commit (ShotTechOp): Updates tools/xdxr_bvh.py to handle D3D12 inactive triangles (NaN vertices → empty box (+inf, -inf), never paired; zero-length edges skipped during pairing), inactive TLAS instances (blas_va == 0, zero mask, empty blas_bounds, or NaN-transformed corners → empty world box), NaN-safe _box_test, and explicit NaN child-box rejection in validate(), plus synthetic unit tests in tests/test_xdxr_bvh.py.
  2. Hardening commit (JARVIX): Updates invert_affine() in tools/xdxr_bvh.py to reject non-finite determinants (not math.isfinite(det)) and non-finite inverse entries. Previously, a NaN in an inactive TLAS instance's rotation or translation bypassed det == 0 and packed NaN floats into the instance record's inverse matrix instead of triggering build_tlas()'s zero-matrix fallback. Adds test_nan_transform_falls_back_to_zero_inverse_in_tlas covering both rotation and translation NaNs.

Tested

All synthetic CPU/stdlib/docs checks on Windows 11 x64, Python 3.12.14, Node v24.19.0 (no game files):

  • python -I tests/test_xdxr_bvh.py -v — 54/54 passed (reproduced invert_affine() returning all-NaN before the hardening commit; 54/54 pass after)
  • python -I scripts/check_no_game_data.py — passed (0 forbidden tracked extensions)
  • python -m compileall -q make_game.py tools tests — passed
  • python -I tests/test_text_write_line_endings.py, tests/test_report_paths.py, tests/test_i18n_index.py, and all tests/test_docs_*.py — passed
  • node --test tests/test_viewer_streaming.cjs — passed

GPUs tested: n/a (CPU BVH reference / unit tests only)

AI-assisted: yes (JARVIX multi-model team: Antigravity + DeepSeek-V4-Pro + NVIDIA NIM Nemotron-3.5-Lightning & Nemotron-3-Ultra-550B)

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (N/A — CPU BVH reference tool only, no shader-translator rule changed.)
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5469665521 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/598). Originally posted by [jarvixaiassistant-glitch](https://github.com/jarvixaiassistant-glitch) on 2026-11-24T09:38:15Z. --- Claimed in the coordination issue as: OLD-10063 ### What and why Carries forward `old-pr/10063` (draft #329) onto `main` (`d7576d56a`), preserving `ShotTechOp`'s original commit verbatim per `CONTRIBUTING.md` and adding one focused hardening commit on top: 1. **Original commit (`ShotTechOp`):** Updates `tools/xdxr_bvh.py` to handle D3D12 inactive triangles (NaN vertices → empty box `(+inf, -inf)`, never paired; zero-length edges skipped during pairing), inactive TLAS instances (`blas_va == 0`, zero mask, empty `blas_bounds`, or NaN-transformed corners → empty world box), NaN-safe `_box_test`, and explicit NaN child-box rejection in `validate()`, plus synthetic unit tests in `tests/test_xdxr_bvh.py`. 2. **Hardening commit (`JARVIX`):** Updates `invert_affine()` in `tools/xdxr_bvh.py` to reject non-finite determinants (`not math.isfinite(det)`) and non-finite inverse entries. Previously, a `NaN` in an inactive TLAS instance's rotation or translation bypassed `det == 0` and packed `NaN` floats into the instance record's inverse matrix instead of triggering `build_tlas()`'s zero-matrix fallback. Adds `test_nan_transform_falls_back_to_zero_inverse_in_tlas` covering both rotation and translation NaNs. ### Tested All synthetic CPU/stdlib/docs checks on Windows 11 x64, Python 3.12.14, Node v24.19.0 (no game files): - `python -I tests/test_xdxr_bvh.py -v` — 54/54 passed (reproduced `invert_affine()` returning all-NaN before the hardening commit; 54/54 pass after) - `python -I scripts/check_no_game_data.py` — passed (0 forbidden tracked extensions) - `python -m compileall -q make_game.py tools tests` — passed - `python -I tests/test_text_write_line_endings.py`, `tests/test_report_paths.py`, `tests/test_i18n_index.py`, and all `tests/test_docs_*.py` — passed - `node --test tests/test_viewer_streaming.cjs` — passed GPUs tested: n/a (CPU BVH reference / unit tests only) AI-assisted: yes (JARVIX multi-model team: Antigravity + DeepSeek-V4-Pro + NVIDIA NIM Nemotron-3.5-Lightning & Nemotron-3-Ultra-550B) ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. *(N/A — CPU BVH reference tool only, no shader-translator rule changed.)*
PierreEbele commented 2026-11-24 19:59:11 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by PierreEbele on 2026-11-24T19:59:11Z.


Reviewed 428f941: ran python3 -I tests/test_xdxr_bvh.py (54 OK; all 7 added tests fail on main),
compileall, and edge-case probes on both trees: active-only builds are byte-identical and trace
== brute_force; NaN-inactive triangles/instances now build and validate cleanly where main
aborted TLAS builds (ValueError on singular inactive instances) or wrote NaN bounds/inverses;
the pair remap rework diverges only for zero-area triangles, which never hit. Two non-blocking
notes: brute_force now raises on NaN-transform scene entries that build_tlas treats as inactive
(reference stricter than builder), and validate still accepts NaN header scene bounds.
AI-assisted review.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7142881461 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/598#issuecomment-7142881461). Originally posted by [PierreEbele](https://github.com/PierreEbele) on 2026-11-24T19:59:11Z. --- Reviewed 428f941: ran `python3 -I tests/test_xdxr_bvh.py` (54 OK; all 7 added tests fail on main), compileall, and edge-case probes on both trees: active-only builds are byte-identical and trace == brute_force; NaN-inactive triangles/instances now build and validate cleanly where main aborted TLAS builds (ValueError on singular inactive instances) or wrote NaN bounds/inverses; the pair remap rework diverges only for zero-area triangles, which never hit. Two non-blocking notes: brute_force now raises on NaN-transform scene entries that build_tlas treats as inactive (reference stricter than builder), and validate still accepts NaN header scene bounds. AI-assisted review.
aslan2142 commented 2026-11-24 22:33:53 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-11-24T22:33:53Z.


Merged. Thanks, and thanks to ShotTechOp for the original commit. Checked locally on today's main + 428f9419d:

  • Claim: valid. claiming: OLD-10063 was posted at 09:38 UTC, before this PR, and is unedited. #743 carried the first commit only and was closed as a duplicate of this one.
  • tests/test_xdxr_bvh.py: 47 tests pass on main, 54 with this PR.
  • On GPU-built BVHs: tools/xdxr_bvh.py check-build <cases> --rays 1000 over the case files that the xdxr_build and d3d12_xdxr_rt tests wrote in two local Wine runs (llvmpipe and an RDNA2 iGPU; four sets, 74 files each run) reports all cases matching, the same as main's tool on the same files.
  • Also clean: check_no_game_data.py on both files and test_text_write_line_endings. It merges without conflicts.
  • CI did not run on this PR (the workflows were waiting for approval), so the merge rests on the runs above and on PierreEbele's (54 tests OK on this head).

PierreEbele's two notes are fine as follow-ups: brute_force is stricter than build_tlas on NaN transforms, and validate accepts NaN header bounds.

AI-assisted (Claude Code, Claude Fable 5.2 and Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7146381360 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/598#issuecomment-7146381360). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-11-24T22:33:53Z. --- Merged. Thanks, and thanks to ShotTechOp for the original commit. Checked locally on today's `main` + `428f9419d`: - **Claim:** valid. `claiming: OLD-10063` was posted at 09:38 UTC, before this PR, and is unedited. #743 carried the first commit only and was closed as a duplicate of this one. - **`tests/test_xdxr_bvh.py`:** 47 tests pass on `main`, 54 with this PR. - **On GPU-built BVHs:** `tools/xdxr_bvh.py check-build <cases> --rays 1000` over the case files that the `xdxr_build` and `d3d12_xdxr_rt` tests wrote in two local Wine runs (llvmpipe and an RDNA2 iGPU; four sets, 74 files each run) reports all cases matching, the same as `main`'s tool on the same files. - **Also clean:** `check_no_game_data.py` on both files and `test_text_write_line_endings`. It merges without conflicts. - **CI did not run on this PR** (the workflows were waiting for approval), so the merge rests on the runs above and on PierreEbele's (54 tests OK on this head). PierreEbele's two notes are fine as follow-ups: `brute_force` is stricter than `build_tlas` on NaN transforms, and `validate` accepts NaN header bounds. AI-assisted (Claude Code, Claude Fable 5.2 and Claude Opus 5.5).
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
ProjectLeonida/mandy!598
No description provided.