[PR #137] rdna2spirv: keep NaN-pattern constants out of float-typed selects in image_bvh (#6623) #189

Open
opened 2026-11-26 20:17:04 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/137
Author: @Andretuta
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: old-pr/9868


📝 Commits (4)

  • b2ac5f1 rdna2spirv: keep NaN-pattern constants out of float-typed selects in image_bvh (#6623)
  • 69af8b7 test_image_bvh_tri: a NaN vertex with a payload returns the canonical NaN words (#6623)
  • 57729cb test_image_bvh_tri: one blank line between methods
  • cc05917 test_image_bvh_tri: no select pairs the NaN or miss constant with a computed word

📊 Changes

2 files changed (+52 additions, -3 deletions)

View changed files

📝 tests/semantic/test_image_bvh_tri.py (+31 -1)
📝 tools/rdna2spirv.py (+21 -2)

📄 Description

Carried over from old PR 9868 by Conrage in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch old-pr/9868, exactly that PR's last commit. All carried-over PRs are listed in #17.
Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it.
Conrage: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one.


Original description (mentions and #N references are disabled; the numbers refer to the old repository):

Claimed in the coordination issue as: #6623, in #7496

Replaces #7595, closed in the PR cleanup; same change, rebased onto main 20cff7e36.

Fixes #6623

What and why

On KosmicKrisp (Mesa 26.3.1, Vulkan on Metal), cs_bvh and cs_bvh32 return 0x7fc00000 where the box miss word should be 0xffffffff. KosmicKrisp's MSL type inference gives an OpSelect the first concrete type that reaches it. In the image_bvh*_intersect_ray lowering that is float (the result words share registers with bitcast floats), so the select's NaN-pattern constant is printed as (NAN), which Metal reads as 0x7FC00000. Two selects are affected: the box branch's 0xFFFFFFFF miss index and canon()'s 0xFFC00000 NaN word.

KosmicKrisp's bitwise ops never take a float type, so a local helper usel_k(c, k, x) builds c ? k : x as (x & keep) | (k & pick), where keep and pick are selects between two constants (just x | pick for k = 0xFFFFFFFF). Only those two call sites change. The result words are the same on every driver. This is a workaround; the real fix belongs in Mesa's nir_to_msl.

Tests

  • test_a_nan_with_a_payload_returns_the_canonical_nan: a payload NaN vertex must return ff800000 ffc00000 ffc00000 ffc00000; a usel_k that drops its mask fails it.
  • test_no_select_mixes_the_nan_or_miss_constant_with_a_computed_word (asked for by @kapitche): no OpSelect in the generated module pairs 0xFFC00000/0xFFFFFFFF with a computed operand. It fails on main (8 such selects) and passes here, on any machine.

Tested

  • Apple M5, KosmicKrisp (Mesa 26.3.1): run_gpu_tests.py --filter cs_bvh 0/2 → 2/2; (NAN) literals in the MSL of cs_bvh/cs_bvh32 16 → 0; full suite 174 → 176 passed, only cs_bvh/cs_bvh32 changed. MoltenVK 1.4.2: no differences.
  • On #7595 others found no change against main on RTX 3080/3080 Ti/4060 Ti/5060 Laptop/5070/5070 Ti/5090, GTX 1660 SUPER, RX 6650 XT/6800 XT/6900 XT/7800 XT, Radeon 660M and other RDNA2 iGPUs, Steam Deck (RADV), Intel Arc B580 and Raptor Lake, and llvmpipe.
  • This rebase, Linux: tests/semantic/test_image_bvh_{tri,box,tri_hw,box_hw}.py 18 passed.

AI-assisted: yes

Checklist

  • 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. (No new instruction rule: the same words are produced through other SPIR-V ops.)

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/137 **Author:** [@Andretuta](https://github.com/Andretuta) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `old-pr/9868` --- ### 📝 Commits (4) - [`b2ac5f1`](https://github.com/ubiquitarianism/leonida/commit/b2ac5f1980604eb29de9620118279cfa26e7bc42) rdna2spirv: keep NaN-pattern constants out of float-typed selects in image_bvh (#6623) - [`69af8b7`](https://github.com/ubiquitarianism/leonida/commit/69af8b7f795658d110707d9a01a057c2f6c1726c) test_image_bvh_tri: a NaN vertex with a payload returns the canonical NaN words (#6623) - [`57729cb`](https://github.com/ubiquitarianism/leonida/commit/57729cbcba39f6ae5ed022c03c3d18cb2973fd51) test_image_bvh_tri: one blank line between methods - [`cc05917`](https://github.com/ubiquitarianism/leonida/commit/cc05917ae0df21c4791dead7d977b6506e2b5934) test_image_bvh_tri: no select pairs the NaN or miss constant with a computed word ### 📊 Changes **2 files changed** (+52 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `tests/semantic/test_image_bvh_tri.py` (+31 -1) 📝 `tools/rdna2spirv.py` (+21 -2) </details> ### 📄 Description > Carried over from **old PR 9868** by `Conrage` in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch `old-pr/9868`, exactly that PR's last commit. All carried-over PRs are listed in #17. > Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it. > `Conrage`: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one. --- Original description (mentions and `#N` references are disabled; the numbers refer to the old repository): Claimed in the coordination issue as: `#6623`, in `#7496` Replaces `#7595`, closed in the PR cleanup; same change, rebased onto main 20cff7e36. Fixes `#6623` ### What and why On KosmicKrisp (Mesa 26.3.1, Vulkan on Metal), `cs_bvh` and `cs_bvh32` return `0x7fc00000` where the box miss word should be `0xffffffff`. KosmicKrisp's MSL type inference gives an `OpSelect` the first concrete type that reaches it. In the `image_bvh*_intersect_ray` lowering that is float (the result words share registers with bitcast floats), so the select's NaN-pattern constant is printed as `(NAN)`, which Metal reads as `0x7FC00000`. Two selects are affected: the box branch's `0xFFFFFFFF` miss index and `canon()`'s `0xFFC00000` NaN word. KosmicKrisp's bitwise ops never take a float type, so a local helper `usel_k(c, k, x)` builds `c ? k : x` as `(x & keep) | (k & pick)`, where `keep` and `pick` are selects between two constants (just `x | pick` for `k = 0xFFFFFFFF`). Only those two call sites change. The result words are the same on every driver. This is a workaround; the real fix belongs in Mesa's `nir_to_msl`. ### Tests - `test_a_nan_with_a_payload_returns_the_canonical_nan`: a payload NaN vertex must return `ff800000 ffc00000 ffc00000 ffc00000`; a `usel_k` that drops its mask fails it. - `test_no_select_mixes_the_nan_or_miss_constant_with_a_computed_word` (asked for by `@kapitche`): no `OpSelect` in the generated module pairs `0xFFC00000`/`0xFFFFFFFF` with a computed operand. It fails on main (8 such selects) and passes here, on any machine. ### Tested - Apple M5, KosmicKrisp (Mesa 26.3.1): `run_gpu_tests.py --filter cs_bvh` 0/2 → 2/2; `(NAN)` literals in the MSL of `cs_bvh`/`cs_bvh32` 16 → 0; full suite 174 → 176 passed, only `cs_bvh`/`cs_bvh32` changed. MoltenVK 1.4.2: no differences. - On `#7595` others found no change against main on RTX 3080/3080 Ti/4060 Ti/5060 Laptop/5070/5070 Ti/5090, GTX 1660 SUPER, RX 6650 XT/6800 XT/6900 XT/7800 XT, Radeon 660M and other RDNA2 iGPUs, Steam Deck (RADV), Intel Arc B580 and Raptor Lake, and llvmpipe. - This rebase, Linux: `tests/semantic/test_image_bvh_{tri,box,tri_hw,box_hw}.py` 18 passed. AI-assisted: yes ### Checklist - [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. (No new instruction rule: the same words are produced through other SPIR-V ops.) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#189
No description provided.