rdna2spirv: keep NaN-pattern constants out of float-typed selects in image_bvh (OLD-9868) #1212

Closed
ambroseautomation wants to merge 4 commits from upstream-pr/1212 into main
ambroseautomation commented 2026-11-24 20:24:21 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by ambroseautomation on 2026-11-24T20:24:21Z.


Claimed in the coordination issue as: OLD-9868 (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7143233478)

What and why

Carries forward old-pr/9868 (draft #137, originally authored by Conrage, all 4 original commits preserved; indexed in #17), rebased cleanly onto current main.

Keeps NaN-pattern integer constants (0xFFFFFFFF box-miss and 0xFFC00000 canonical NaN) out of float-typed OpSelect instructions in image_bvh*_intersect_ray lowering (tools/rdna2spirv.py):

  • Builds those selects via bitwise (x & keep) | (k & pick) (usel_k) where keep/pick select between two integer constants, preventing drivers like KosmicKrisp (Mesa 26.3.1) from typing the select as float and emitting (NAN) (0x7FC00000) instead of 0xFFFFFFFF / 0xFFC00000.
  • Adds regression tests in tests/semantic/test_image_bvh_tri.py verifying canonical NaN payload handling and asserting that no OpSelect pairs the NaN/miss constants with a computed word.

Tested

  • python -m unittest discover -s tests/semantic -p test_image_bvh_tri.py -v: 9 tests, OK.
  • python -I scripts/run_semantic_tests.py tests/semantic: 470 files, 6,170 tests, 0 files failed.
  • python -I scripts/check_no_game_data.py tools/rdna2spirv.py tests/semantic/test_image_bvh_tri.py: exit 0 (no game data).

GPUs tested: n/a (CPU SPIR-V interpreter semantic suite on Windows 11 Pro 64-bit, Python 3.12.10)

AI-assisted: yes

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 — preserves identical integer words for existing image_bvh lowering)
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5479734901 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1212). Originally posted by [ambroseautomation](https://github.com/ambroseautomation) on 2026-11-24T20:24:21Z. --- Claimed in the coordination issue as: OLD-9868 (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7143233478) ### What and why Carries forward `old-pr/9868` (draft #137, originally authored by `Conrage`, all 4 original commits preserved; indexed in #17), rebased cleanly onto current `main`. Keeps NaN-pattern integer constants (`0xFFFFFFFF` box-miss and `0xFFC00000` canonical NaN) out of float-typed `OpSelect` instructions in `image_bvh*_intersect_ray` lowering (`tools/rdna2spirv.py`): - Builds those selects via bitwise `(x & keep) | (k & pick)` (`usel_k`) where `keep`/`pick` select between two integer constants, preventing drivers like KosmicKrisp (Mesa 26.3.1) from typing the select as float and emitting `(NAN)` (`0x7FC00000`) instead of `0xFFFFFFFF` / `0xFFC00000`. - Adds regression tests in `tests/semantic/test_image_bvh_tri.py` verifying canonical NaN payload handling and asserting that no `OpSelect` pairs the NaN/miss constants with a computed word. ### Tested - `python -m unittest discover -s tests/semantic -p test_image_bvh_tri.py -v`: 9 tests, OK. - `python -I scripts/run_semantic_tests.py tests/semantic`: 470 files, 6,170 tests, 0 files failed. - `python -I scripts/check_no_game_data.py tools/rdna2spirv.py tests/semantic/test_image_bvh_tri.py`: exit 0 (no game data). GPUs tested: n/a (CPU SPIR-V interpreter semantic suite on Windows 11 Pro 64-bit, Python 3.12.10) AI-assisted: yes ### 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. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a — preserves identical integer words for existing `image_bvh` lowering)
tiguan26 commented 2026-11-25 06:40:04 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by tiguan26 on 2026-11-25T06:40:04Z.

Review: APPROVED


Approving. Merged into current main (42537e7) with no conflicts. The full translator suite, including this PR's test, gives 487 files / 6,281 tests with only test_int32_to_f64 failing, as on main here (Linux, Python 3.13). That replaces my earlier run, whose worktree was shared with another job.

I checked usel_k by hand against the selects it replaces. (x & (c ? 0 : ~0)) | (c ? k : 0) is c ? k : x, and the invert form is c ? x : k. The k == 0xFFFFFFFF shortcut x | km gives the same in both directions. So hb ? child : 0xFFFFFFFF and the NaN canonicalisation are unchanged on drivers that type OpSelect correctly.

AI-assisted (Claude).

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6052983617 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1212#pullrequestreview-6052983617). Originally posted by [tiguan26](https://github.com/tiguan26) on 2026-11-25T06:40:04Z. **Review:** APPROVED --- Approving. Merged into current main (42537e7) with no conflicts. The full translator suite, including this PR's test, gives 487 files / 6,281 tests with only `test_int32_to_f64` failing, as on main here (Linux, Python 3.13). That replaces my earlier run, whose worktree was shared with another job. I checked `usel_k` by hand against the selects it replaces. `(x & (c ? 0 : ~0)) | (c ? k : 0)` is `c ? k : x`, and the `invert` form is `c ? x : k`. The `k == 0xFFFFFFFF` shortcut `x | km` gives the same in both directions. So `hb ? child : 0xFFFFFFFF` and the NaN canonicalisation are unchanged on drivers that type OpSelect correctly. AI-assisted (Claude).
PierreEbele commented 2026-11-25 07:09:30 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by PierreEbele on 2026-11-25T07:09:30Z.


Reviewed 82fde44: ran test_image_bvh_tri.py, test_image_bvh_box.py, test_image_bvh_tri_hw.py, test_image_bvh_box_hw.py, and test_bvh_tri_probe.py in the sandbox on PR and main; all pass on PR (9/4/3/2/17 OK), the new form test fails on main with the 8 expected mixed selects, and a 464-case probe (32/64-bit, both sort flags, static/dynamic EXEC, poked NaN payloads/specials, box16/32, types 6–7) gives bit-identical interpreter output on both trees.
Non-blocking note: in dynamic-EXEC shaders (e.g. cs_bvh.asm, cs_bvh32.asm), L['oth'] (tools/rdna2spirv.py:14977, node types 6–7) still emits 4 OpSelect %uint %active %cffffffff %old per call via Gen.dst() (8 remain in each shader; missed by test_no_select_mixes... because its shader has static EXEC); worth converting via eager=True/usel_k and adding a dynamic-EXEC test if types 6–7 ever run on KosmicKrisp.
GPU tests not run here (no GPU/KosmicKrisp in this environment); commit d01324cda reports cs_bvh/cs_bvh32 0/2 -> 2/2 on Apple M5 KosmicKrisp, so the docs/testing.md row can be updated in a follow-up.
AI-assisted review.

Recommendation: Merge

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7155551361 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1212#issuecomment-7155551361). Originally posted by [PierreEbele](https://github.com/PierreEbele) on 2026-11-25T07:09:30Z. --- Reviewed 82fde44: ran `test_image_bvh_tri.py`, `test_image_bvh_box.py`, `test_image_bvh_tri_hw.py`, `test_image_bvh_box_hw.py`, and `test_bvh_tri_probe.py` in the sandbox on PR and main; all pass on PR (`9/4/3/2/17 OK`), the new form test fails on main with the 8 expected mixed selects, and a 464-case probe (32/64-bit, both sort flags, static/dynamic EXEC, poked NaN payloads/specials, box16/32, types 6–7) gives bit-identical interpreter output on both trees. Non-blocking note: in dynamic-EXEC shaders (e.g. `cs_bvh.asm`, `cs_bvh32.asm`), `L['oth']` (`tools/rdna2spirv.py:14977`, node types 6–7) still emits 4 `OpSelect %uint %active %cffffffff %old` per call via `Gen.dst()` (8 remain in each shader; missed by `test_no_select_mixes...` because its shader has static EXEC); worth converting via `eager=True`/`usel_k` and adding a dynamic-EXEC test if types 6–7 ever run on KosmicKrisp. GPU tests not run here (no GPU/KosmicKrisp in this environment); commit `d01324cda` reports `cs_bvh`/`cs_bvh32` `0/2 -> 2/2` on Apple M5 KosmicKrisp, so the `docs/testing.md` row can be updated in a follow-up. AI-assisted review. **Recommendation:** Merge
Tauwni commented 2026-11-25 10:16:32 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Tauwni on 2026-11-25T10:16:32Z.


Tested on an Apple M3 (macOS 26.5.1), this branch at 82fde4444, test programs built from main 626d1281a: cs_bvh and cs_bvh32 fail on main with KosmicKrisp (Mesa 26.3.1), out[3] = 0x7fc00000, and pass with this PR (out[0..7] = 104 72 64 4294967295 ...). They also still pass on MoltenVK 1.4.2. AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7159471619 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1212#issuecomment-7159471619). Originally posted by [Tauwni](https://github.com/Tauwni) on 2026-11-25T10:16:32Z. --- Tested on an Apple M3 (macOS 26.5.1), this branch at `82fde4444`, test programs built from `main` `626d1281a`: `cs_bvh` and `cs_bvh32` fail on `main` with KosmicKrisp (Mesa 26.3.1), `out[3]` = `0x7fc00000`, and pass with this PR (`out[0..7] = 104 72 64 4294967295 ...`). They also still pass on MoltenVK 1.4.2. AI-assisted (Claude Code).

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
ProjectLeonida/mandy!1212
No description provided.