rdna2spirv: keep NaN-pattern constants out of float-typed selects in image_bvh (#6623) #137
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/137"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ubiquitarianism/leonida. Originally posted by Andretuta on 2026-11-24T02:26:02Z.
Original description (mentions and
#Nreferences are disabled; the numbers refer to the old repository):Claimed in the coordination issue as:
#6623, in#7496Replaces
#7595, closed in the PR cleanup; same change, rebased onto main20cff7e36.Fixes
#6623What and why
On KosmicKrisp (Mesa 26.3.1, Vulkan on Metal),
cs_bvhandcs_bvh32return0x7fc00000where the box miss word should be0xffffffff. KosmicKrisp's MSL type inference gives anOpSelectthe first concrete type that reaches it. In theimage_bvh*_intersect_raylowering 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 as0x7FC00000. Two selects are affected: the box branch's0xFFFFFFFFmiss index andcanon()'s0xFFC00000NaN word.KosmicKrisp's bitwise ops never take a float type, so a local helper
usel_k(c, k, x)buildsc ? k : xas(x & keep) | (k & pick), wherekeepandpickare selects between two constants (justx | pickfork = 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'snir_to_msl.Tests
test_a_nan_with_a_payload_returns_the_canonical_nan: a payload NaN vertex must returnff800000 ffc00000 ffc00000 ffc00000; ausel_kthat drops its mask fails it.test_no_select_mixes_the_nan_or_miss_constant_with_a_computed_word(asked for by@kapitche): noOpSelectin the generated module pairs0xFFC00000/0xFFFFFFFFwith a computed operand. It fails on main (8 such selects) and passes here, on any machine.Tested
run_gpu_tests.py --filter cs_bvh0/2 → 2/2;(NAN)literals in the MSL ofcs_bvh/cs_bvh3216 → 0; full suite 174 → 176 passed, onlycs_bvh/cs_bvh32changed. MoltenVK 1.4.2: no differences.#7595others 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.tests/semantic/test_image_bvh_{tri,box,tri_hw,box_hw}.py18 passed.AI-assisted: yes
Checklist
docs/design.md, with how it was confirmed. (No new instruction rule: the same words are produced through other SPIR-V ops.)Imported from ubiquitarianism/leonida. Originally posted by GeorgiyDemo on 2026-11-24T07:32:24Z.
Tested
cc05917aon Apple M5 Pro (16-core GPU), macOS 26.7.3 (25G342), againstmaind42773d07:mainfailscs_bvhandcs_bvh32without[0..7] = 104 72 64 2143289344 ...(0x7fc00000at word 3); this head passes 2/2.tests/semantic/test_image_bvh_tri.py: 9 tests OK at this head; the same file againstmain's translator fails 1 of 9, so the new tests catch the bug rather than only passing here.Binaries from
main(only the translator changed), llvm-mc 23.1.6, SPIRV-Tools v2026.4. Synthetic fixtures only, no game data. AI-assisted.Imported from ubiquitarianism/leonida. Originally posted by EvgHaze on 2026-11-25T12:40:40Z.
Apple-side check of this draft, on the hardware the failure was reported from.
Before (main,
0d80bc5):With this diff:
So the fix does what it says on a third Apple machine (the report was an M2 Ultra): the KosmicKrisp words are exact now, and MoltenVK is not disturbed.
MSL, the same fixture (
MESA_KK_DEBUG=msl): on main the dump containsr10 = as_type<uint>((as_type<float>(r9)))withr9 = 0xFFFFFFFF, which is where0x7fc00000came from. With this diff that double cast is gone from the dump (as_type<uint>((as_type<float>appears 0 times), which matches the measured words.Tests:
python3 -I scripts/run_semantic_tests.py tests/semantic→ 489 files, 6290 tests, 0 failed (8 jobs, 150 s).One small nit on the docstring:
python -I tests/semantic/test_image_bvh_tri.pycannot work, because-Iremoves the working directory fromsys.pathand thefrom support import ...then fails (ModuleNotFoundError: support). The form in the docstring (python -m unittest tests/semantic/test_image_bvh_tri.py -v) or the runner above does not have that problem.AI-assisted. No game data: the fixtures are hand-written
.asm, and every number above is test output.Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-30T19:10:28Z.
The fix still appears relevant: current
maindoes not containusel_kor the two new image-BVH regressions, whiledocs/design.mdalready specifies the required canonical NaN word (0xFFC00000). The independent M3/M5 reports show the KosmicKrisp NaN-word failure fixed and MoltenVK unchanged, and the CPU translation test distinguishes the old select form. I am leaving this open, not merge-ready: it is still a draft and all available CI checks were cancelled. Please rebase against currentmain, mark ready when complete, and obtain current-base CI plus the relevant GPU/translator checks before merge.Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T12:00:19Z.
Review: COMMENTED
Draft review against current
main: theusel_kbitwise constant-NaN select workaround intools/rdna2spirv.py:14638-14654looks clean, clean-room verified, and still relevant, but CI checks are cancelled and the PR is still Draft. Please merge/rebase currentmainand mark Ready for Review so CI runs green.(AI-assisted review.)
Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T12:09:48Z.
Marking Ready for Review since no WIP/blocker reason for draft status is specified on this PR, so it can enter normal CI and review.
(AI-assisted triage.)
Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T13:02:32Z.
Review: APPROVED
Now ready for review and
MERGEABLE. Clean-room verified: theusel_kbitwise select workaround intools/rdna2spirv.py:14638-14654keeps NaN-pattern constants out of float-typed selects inimage_bvh(independently verified on Apple M3 & M5 Pro KosmicKrisp + MoltenVK, with regression tests intests/semantic/test_image_bvh_tri.py).Approving — ready to merge once fresh CI runs green on current
main(existing Nov 24 checks were cancelled).(AI-assisted review.)