Skip to content

rdna2spirv: keep NaN-pattern constants out of float-typed selects in image_bvh (#6623) - #7595

Open
Conrage wants to merge 3 commits into
ItsNotRexed:mainfrom
Conrage:fix-6623-kk-bvh-nan
Open

Conrage wants to merge 3 commits into
ItsNotRexed:mainfrom
Conrage:fix-6623-kk-bvh-nan

Conversation

@Conrage

@Conrage Conrage commented Nov 23, 2026

Copy link
Copy Markdown

Claimed in the coordination issue as: #6623, in #7496 (#7496 (comment))

Depends on: nothing

Fixes #6623

What and why

On KosmicKrisp (Mesa 26.3.1, Vulkan on Metal), cs_bvh and cs_bvh32 return 0x7fc00000 where the miss word should be 0xffffffff. The cause is in KosmicKrisp's type inference (src/kosmickrisp/compiler/msl_type_inference.c):

  • An OpSelect gets the first concrete type that reaches it.
  • In the image_bvh*_intersect_ray lowering, the result words share registers with bitcast floats from the triangle branch, so that type is float.
  • The select's constant is then printed as the MSL literal (NAN), which Metal reads as 0x7FC00000.

This affects two selects. The MESA_KK_DEBUG=msl dump shows 16 (NAN) literals in cs_bvh:

  • the box branch's 0xFFFFFFFF "no hit" index, which is what the test catches;
  • canon()'s 0xFFC00000 NaN word in the triangle branch, which has the same bug.

KosmicKrisp's bitwise ops never take a float type. When a float value reaches one, it inserts an as_type<uint> cast. So this PR adds a local helper, usel_k(c, k, x), that builds c ? k : x as (x & keep) | (k & pick), where keep and pick are selects between two constants. For k = 0xFFFFFFFF that is just x | pick. Only those two call sites change. The result words are the same on every driver, and spirv-val passes.

This is a workaround for KosmicKrisp; it doesn't fix it. The real fix belongs in Mesa's nir_to_msl, either by printing float NaN constants as as_type<float>(0x...u) or by keeping shared registers typed uint. #6627's docs note still applies to older builds of the translator.

Tested

Apple M5, macOS, Vulkan SDK with KosmicKrisp (Mesa 26.3.1) and MoltenVK 1.4.2, no game files. "Before" is upstream main and "after" is this branch:

before after
run_gpu_tests.py --filter cs_bvh, KosmicKrisp 0/2 2/2, bvh out = 00000068 00000048 00000040 ffffffff | c1200000 bf800000 be800000 be800000, 0 mismatches
run_gpu_tests.py --filter cs_bvh, MoltenVK 2/2 2/2, identical words
(NAN) literals in the KosmicKrisp MSL of cs_bvh / cs_bvh32 16 0
full run_gpu_tests.py, KosmicKrisp 174 passed, 62 skipped 176 passed, 62 skipped (only cs_bvh/cs_bvh32 changed)
full run_gpu_tests.py, MoltenVK 180 passed, 59 skipped 180 passed, 59 skipped, no differences
scripts/run_semantic_tests.py tests/semantic 444 files, 5902 tests identical
pytest tests/test_*bvh*.py 261 passed identical

Failures that are the same before and after, and that this PR doesn't touch:

  • KosmicKrisp: ps_cndmask_sign_mods and ps_valu16_mad_sel.
  • MoltenVK: cs_fma_fused.
  • Semantic tests: test_image_atomics_guard and test_image_store_d16.
  • pytest: 3 tests that use tools/bvh_slot_check.py.

On Linux (no GPU), pytest tests/semantic/test_image_bvh_*.py gives 16 passed and 1610 subtests passed, both on main and on this branch.

Not measured:

  • Corpus counts. This changes only the code generated for image_bvh*_intersect_ray, not which instructions translate.
  • AMD/NVIDIA GPUs. The words are built by plain integer ops, so they should be identical there, but a RADV or NVIDIA cs_bvh run would be welcome.
  • canon()'s NaN path. No GPU test here checks a NaN result word from a BVH triangle, so that half is verified only through the Metal dump.

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

…image_bvh (ItsNotRexed#6623)

KosmicKrisp (Mesa 26.3.1) types an OpSelect by the first concrete type that
reaches it. In the image_bvh*_intersect_ray lowering the result words share
registers with bitcast floats, so the box branch's 0xFFFFFFFF "no hit" select
and canon()'s 0xFFC00000 select were typed float and their constants printed
as the MSL literal (NAN), which Metal reads as 0x7FC00000. cs_bvh and
cs_bvh32 returned 0x7fc00000 for the miss word.

Build those two selects as (x & keep) | (k & pick) with keep/pick selects
between two constants. Bitwise ops never take a float type in KosmicKrisp's
inference, so the constants stay integers. The result words are the same on
every driver.

Tested on an Apple M5 (macOS): cs_bvh/cs_bvh32 0/2 -> 2/2 on KosmicKrisp
and 2/2 -> 2/2 on MoltenVK 1.4.2; full run_gpu_tests.py unchanged otherwise
on both; tests/semantic unchanged.

AI-assisted: yes
@Kev-Ball

Kev-Ball commented Nov 23, 2026 •

Copy link
Copy Markdown

I exercised the triangle canon() path on d657c88d6 with a local variation of the synthetic vk_compute_test BVH scene. In the first triangle, immediately after the harness writes the scene, overwrite its nine vertex-coordinate words at 0x200 + 4*k (k=0..8) with 0x7fc12345u. Keep the box bounds, ray, triangle-ID word and shader unchanged. This puts NaNs in the triangle arithmetic while keeping the box traversal as a control.

On CachyOS / llvmpipe (LLVM 23.1.5), both cs_bvh and cs_bvh32 returned exactly ff800000 ffc00000 ffc00000 ffc00000 for the triangle. The four box words matched the stock fixture, including the ffffffff miss. Both modules passed spirv-val.

For a negative control I changed only the triangle canonical constant in the translator to positive 0x7fc00000. The stock two fixtures still passed. The NaN-triangle case failed all four triangle words for both pointer widths: the three NaNs changed sign, and so did the infinity derived from the determinant sign. This gives a runnable regression case for the second select independent of the Metal source dump. AI-assisted QA.

NVIDIA hardware retest: Compared parent 203a348cf with head d657c88d6 on a GeForce RTX 3080 Ti (driver 620.73.04, subgroup 32) on CachyOS. Each fixture’s SPIR-V binary changed between revisions. Both revisions validated 2/2 modules and passed 2/2 stock GPU cases. The separate NaN-triangle harness also passed on both revisions at both pointer widths, with zero mismatches across all eight words in each dispatch. The box miss remained ffffffff and the triangle returned ff800000 ffc00000 ffc00000 ffc00000 in all four dispatches.

Retail translation: I scanned all 26,503 ordinary listings and translated every listing containing either BVH intersection opcode on the same parent/head pair. All 64 are compute shaders. Both revisions translated and passed spirv-val for 64/64. All 64 SPIR-V binaries changed, and all 64 per-shader index entries were identical between revisions.

I also checked the separate 2,684-listing compute pipeline library. Its 64 opcode-bearing listings have exactly the same set of DXBC container hashes as the 64 above. With the library listings and their own sidecars, both revisions emitted modules for the same 25/64; all 25 validated and changed binary, with equal index entries. The other 39 produced no indexed module on either revision. The two extraction paths therefore have different baseline coverage and should not be added together as 128 distinct inputs. GPU execution above used the synthetic scenes.

I ran the new three-payload fixture from b959fab5a through the RTX 3080 Ti Vulkan harness with the fixture’s inputs. All three readbacks returned the expected negative infinity and three negative canonical NaNs. Changing just the triangle canonical NaN constant to positive flipped the sign of all four words for all three inputs, on both NVIDIA and llvmpipe. The corresponding semantic test also failed all three mutant cases. I checked the diff through ac665326d; it removes one blank line in the test.

@kapitche

Copy link
Copy Markdown
Contributor

Tested d657c88 merged with main dde82f2 on Linux/Python 3.12.16: concern

Merge is clean (tools/rdna2spirv.py only, no test file). Nothing fails, but nothing in the repo's tests can tell this change from main, so I cannot call it a pass.

  • Read: usel_k(c, k, x, invert) builds c ? k : x (or c ? x : k) as (x & keep) | (k & pick), and x | pick when k == 0xFFFFFFFF. I checked both invert polarities and both call sites (canon() with 0xFFC00000, and the box child index with 0xFFFFFFFF, invert=True); the selected values are the same as the old OpSelects.
  • With the PR merged: tests/semantic test_image_bvh_tri.py (7 tests), test_image_bvh_box.py (4), test_image_bvh_box_hw.py (2), test_image_bvh_tri_hw.py (3) are OK, and python -I tests/test_rdna2_decode.py is OK (16 tests, 1 skipped).
  • Negative control (tools/rdna2spirv.py restored from upstream/main): the same box and box_hw suites are also OK, so they do not discriminate. That is expected, since the bug is only in KosmicKrisp's MSL output (the PR body reports it on Apple M5), and the SPIR-V result words are meant to be identical on other drivers.
  • A small test that checks the generated image_bvh SPIR-V for the miss-word and canonical-NaN paths (for example that no OpSelect takes 0xFFFFFFFF / 0xFFC00000 as an operand) would let a Linux run catch a regression of this workaround.

@monomah133

monomah133 commented Nov 23, 2026 •

Copy link
Copy Markdown

Independent NVIDIA Windows check for d657c88: PASS.

Windows 11 Pro 10.0.26200, GeForce RTX 3080, NVIDIA 616.92, Vulkan 1.4.351, subgroup 32. Built this head's GPU test programs with MSVC 19.44 / RelWithDebInfo and used llvm-mc 23.1.6 and SPIRV-Tools 2026.4.

python -I scripts/run_gpu_tests.py --build <build> --work <work> --filter cs_bvh --require-pass: 2/2 shaders translated and passed spirv-val; cs_bvh and cs_bvh32 both PASS on the RTX 3080 (2/2, no skips). This was the stock synthetic fixture; it does not independently test the NaN triangle path or the original KosmicKrisp bug. No game files used.

@airp1ane

Copy link
Copy Markdown
Contributor

Tested d657c88d6 on Windows 11, NVIDIA GeForce RTX 4060 Ti (driver 621.24, Vulkan 1.4.357, Vulkan SDK 1.4.363.1), LLVM 21.1.8 (llvm-mc), Python 3.15.2, MSVC 19.52 (no game files): pass.

  • GPU tests (scripts/run_gpu_tests.py --filter bvh --require-pass with LEONIDA_VK_VALIDATION=1):
    • Native: 2/2 translated, 2/2 pass spirv-val; cs_bvh PASS, cs_bvh32 PASS (0 validation errors).
    • LEONIDA_W64_EMULATE=1: 2/2 translated, 2/2 pass spirv-val; cs_bvh PASS, cs_bvh32 PASS (0 validation errors).
  • CPU semantic & unit tests:
    • test_image_bvh_box, test_image_bvh_box_hw, test_image_bvh_tri, test_image_bvh_tri_hw: 16/16 OK.
    • python -I tests/test_xdxr_bvh.py: 47/47 OK.
  • Note: verified on NVIDIA Vulkan (not KosmicKrisp/Metal), confirming no regressions and bit-exact results for usel_k across both native and LEONIDA_W64_EMULATE=1 paths.
  • Merge check onto main 7ef2fdd46 (git merge-tree), git diff --check, and scripts/check_no_game_data.py: all clean.

AI-assisted.

@trick-ye

Copy link
Copy Markdown

Tested d657c88d6 merged onto main dde82f27e on AMD Radeon RX 7800 XT (RDNA3), AMD 26.11.2 (Windows driver 32.0.32029.2010), Windows 11 26200: cs_bvh and cs_bvh32 give the same words as on main, with 0 mismatches. The description lists AMD and NVIDIA as not measured and asks for a RADV or NVIDIA run; this is AMD's Windows driver, not RADV.

  • vk_compute_test <spv> 1 bvh on the .spv built by main and by this merge, for both fixtures: bvh out = 00000068 00000048 00000040 ffffffff | c1200000 bf800000 be800000 be800000, 1 groups x 64: 0 mismatches, in all four runs. The .spv files differ between the two builds, as expected.
  • Full scripts/run_gpu_tests.py on this merge: 247 shaders translated, 247 pass spirv-val; 225 of 241 passed, 16 skipped, 0 failed.
  • The same command on main dde82f27e: 224 of 241 passed, 16 skipped, 1 failed (ms_wave_info_s3: at (0,0): got (-1.0000,-1.0000,-1.0000,-1.0000)). That failure did not reproduce in 6 isolated reruns on main, and ms_wave_info_s3.spv is byte-identical in the two builds, so the difference between the two full runs is not a shader change from this PR. No other result differs between the two runs.
  • Like the description says, no GPU test here checks canon()'s NaN word, so this run does not cover that half.
  • Test programs built from main dde82f27e (the PR changes only tools/rdna2spirv.py). MSVC 14.42 (VS 2022), Windows SDK 10.0.26100, Vulkan SDK 1.4.363.0, llvm-mc 23.1.6, Python 3.13, RelWithDebInfo, LEONIDA_VK_DEVICE=7800. Synthetic fixtures only, no game files.

AI-assisted (Claude Code).

@gurvancampion

Copy link
Copy Markdown
Contributor

One point the other checks here do not cover, then a pass on this hardware.

The eight OpSelects that remain. The change rewrites the usel_k call sites, but per image_bvh instruction eight selects still pair 0xFFFFFFFF with a loaded register — four in the canonical words and four in the child indices, in the instance/AABB-node branch (the false target of the is_box branch), from the exec-masked writes of out(k, 0xFFFFFFFF). This PR does not touch that branch and the existing fixtures do not reach it, so nothing in the repo exercises it. If the same mistyping applies to those selects, an instance or AABB node would still return 0x7fc00000 there on the driver the PR is about. Conditional, because I cannot test Metal here — I am flagging it so the coverage is known to be partial, not claiming a defect.

cs_bvh and cs_bvh32 on NVIDIA GeForce RTX 5090 (driver 615.78.08) and the AMD Ryzen 7 9800X3D iGPU (RADV Mesa 26.2.5, ACO), Linux 7.2.15: pass.

  • scripts/run_gpu_tests.py --filter cs_bvh: 2/2 on RADV native, 2/2 native on the 5090, 2/2 with LEONIDA_W64_EMULATE=1. Same three runs for parent 203a348 and main f283b1378: 2/2 each, so nothing changes on these drivers, as the PR says.
  • tests/semantic test_image_bvh_box, _box_hw, _tri, _tri_hw: 16/16 OK in this head, the parent and main.
  • Counts of the emitted module (cs_bvh.spv, parent vs head; cs_bvh32 the same): 135700 -> 136372 bytes, OpSelect 428 -> 436, OpBitwiseAnd 118 -> 126, OpBitwiseOr 105 -> 121. Selects pairing 0xFFFFFFFF/0xFFC00000 with a non-constant: 24 -> 8, i.e. the eight above. Both pass spirv-val.
  • The full semantic suite still fails test_image_atomics_guard and test_image_store_d16 with the same 48 subtests in this head, the parent and main — not from this PR.

Commands: cmake -S runtime -B runtime/build/linux -G Ninja -DVulkan_INCLUDE_DIR=<Vulkan-Headers>/include, cmake --build runtime/build/linux --parallel, then python -I scripts/run_gpu_tests.py --build runtime/build/linux --filter cs_bvh --require-pass with LEONIDA_VK_DEVICE=RADV and =5090. Python 3.14.8, llvm-mc 23.1.3, SPIRV-Tools 2026.4.

No game files. AI-assisted.

@Zombins2

Copy link
Copy Markdown

AI-assisted. No game files used.

Adding AMD Windows results to @Kev-Ball's llvmpipe/NVIDIA comparison: d657c88d against parent 203a348c, RDNA2 iGPU (Ryzen 5 7600X, gfx1036, AMD 26.10.1), Windows 11 build 26200, MSVC 19.50. The device reports a supported subgroup range of 32..64; these logs do not record the selected width. Alongside @trick-ye's RDNA3 run on the same driver family, this adds the canon() NaN half that their stock-scene run notes it does not cover.

The C++ test programs were built once from the parent, since the PR changes only tools/rdna2spirv.py. Each revision's own translator produced the shaders through run_gpu_tests.py --filter cs_bvh. Both revisions passed 2/2, and each SPIR-V module differs between the revisions.

I added @Kev-Ball's NaN-triangle scene to a local copy of vk_compute_test: nine 0x7fc12345 vertex words in the first triangle. Every case below gave the same words in 3 of 3 runs, for both cs_bvh and cs_bvh32:

translator stock scene NaN-triangle scene
parent 203a348c 68 48 40 ffffffff | c1200000 bf800000 be800000 be800000 68 48 40 ffffffff | ff800000 ffc00000 ffc00000 ffc00000
this PR d657c88d same same

The NaN-scene runs retain the stock expected values in the harness, so they exit 1 with four mismatches even for the unmodified translators. The table compares raw readback words, not NaN-scene pass labels.

To check that these runs observe the two constants the PR rewrites, I made four one-line translator mutants, each constant once in the parent and once in the PR:

mutant (parent and PR alike) stock scene NaN-triangle scene
canon() constant 0xFFC00000 → 0x7FC12345 unchanged, still 2/2 7f800000 7fc12345 7fc12345 7fc12345
box-miss constant 0xFFFFFFFF → 0xFFFFFFFE word 3 fffffffe, 0/2 word 3 fffffffe; other words unchanged

For these modules/scenes, the old OpSelect form and the new bitwise form give identical words, and the mutants show that both selected constants reach the readback. Positions are zero-based: the canon() mutant changes only NaN-scene words 4–7 (including the derived infinity's sign), while the miss mutant changes only word 3 in either scene. As @Kev-Ball showed on llvmpipe, the stock fixtures alone don't observe canon()'s constant: that mutant still passes 2/2 here.

A NaN-scene test with its own expected values could pin that output constant. The SPIR-V-level check @kapitche suggests would serve a different purpose: pinning the workaround's generated form, since the unmodified parent and PR are expected to agree on this driver. Neither test is added here.

Scope: synthetic scenes only, no KosmicKrisp/Metal run (the bug this fixes), no validation layer, and the NaN-scene change to vk_compute_test is local and not in either branch. This also does not retest SHADER-985's separate float-min/max NaN issue; these changed selects use integer/bitwise operations. No general equivalence or merge verdict is implied.

@javdc

javdc commented Nov 23, 2026

Copy link
Copy Markdown

Tested d657c88 on Steam Deck LCD (Jupiter), AMD Custom GPU 0405 "Van Gogh", RADV Mesa 26.2.0-devel (git-5c65d4fc31), Vulkan 1.4.350, SteamOS 3.9.5 (holo), kernel 7.2.7-valve2-2-neptune-72-g31504582a073: fail on this RADV setup (regression vs main)

Commands:

  • Main (aa2988cc5 tools/build): python3 -I runtime/test/shaders/check.py <work> /home/deck/opencode/Leonida/runtime/build --filter cs_bvh -> cs_bvh ok, cs_bvh32 ok
  • PR 7595: same command -> cs_bvh exit 1: out[0..7] = 104 72 64 4294967295 3240099840 3212836864 3196059648 3196059648; cs_bvh32 same exit/failure on RADV VANGOGH

The PR targets KosmicKrisp NaN-pattern select typing (#6623); on this RADV Deck it causes the existing cs_bvh/cs_bvh32 GPU checks to fail.

AI-assisted (OpenCode)

@Kev-Ball

Copy link
Copy Markdown

@javdc I checked the eight decimal words from your Deck run against want[8] in vk_compute_test.cpp at d657c88d6. All eight match exactly, including the box miss and the signs on the four triangle words. The exit 1 is worth tracking down before attributing it to a shader result.

Could you run the same vk_compute_test <work>/spirv/cs_bvh.spv 1 bvh binary directly on each revision's module, keeping the subgroup setting from your runner, and share the synthetic fixture's mismatch count, process exit status and any validation diagnostic? The harness prints the mismatch count immediately before the decimal dump. If it says zero but the process exits 1, OptInValidation::exit_status can do that when it counts a Vulkan validation error. Knowing whether LEONIDA_VK_VALIDATION was enabled would distinguish those cases. AI-assisted QA.

@djasdh

djasdh commented Nov 23, 2026

Copy link
Copy Markdown

Tested d657c88d6 on AMD Radeon RX 6900 XT (RDNA2, gfx1030, RADV NAVI21), Mesa 26.3.1, Vulkan 1.4.363, Arch Linux, llvm-mc 23.1.5, SPIRV-Tools 1.4.363.0, Python 3.14.10.

GPU suite (full) — 223/240 passed, 16 skipped, 1 failed (ms_wave_info_s3, same as main)
Translator suite — 446 files, 5951 tests, 2 files failed

Two semantic files fail on this head: test_image_atomics_guard and test_image_store_d16. Both also fail on main (dde82f27e) on this machine with the same counts, so this branch does not introduce them — they are the stale-after-#4473/#6805 pair already tracked in #7284. ms_wave_info_s3 fails in the full GPU suite on main here as well (it passes with --filter ms_wave_info_s3; reported in #6497).

Counts and error classes only; no game data. AI-assisted.

@SamuelHaleDev

Copy link
Copy Markdown

Tested d657c88d6 on Windows 11, AMD Radeon RX 6650 XT (RDNA2, driver 32.0.21045.5002, subgroup 32..64), Vulkan SDK 1.4.363.0, LLVM 21.1.8 (llvm-mc), Python 3.14.7 (no game files): pass.

  • GPU tests (python -I scripts/run_gpu_tests.py --filter bvh --require-pass, LEONIDA_VK_VALIDATION=1):
    • Native: 2/2 translated, 2/2 pass spirv-val; cs_bvh PASS, cs_bvh32 PASS.
    • LEONIDA_W64_EMULATE=1: 2/2 translated, 2/2 pass spirv-val; cs_bvh PASS, cs_bvh32 PASS.
    • The test programs (vk_compute_test, vk_store_test, vk_harness) were built from efc347830, not this head; this PR changes only tools/rdna2spirv.py.
  • CPU: test_image_bvh_box, test_image_bvh_box_hw, test_image_bvh_tri, test_image_bvh_tri_hw: 16/16 OK.
  • Read the diff: both rewritten sites give the same bits as the old OpSelect for every input.
  • This is a discrete RDNA2 card on the AMD Windows driver. A pass here shows no regression on AMD; it cannot confirm the KosmicKrisp fix.

AI-assisted (Claude Code).

@AsgerCode

Copy link
Copy Markdown

Tested d657c88 merged with main dde82f2 on Windows 11 (NTFS), Python 3.12.10 (CPU only, no GPU, no game files): pass

The earlier comments covered the GPU runs, the NaN-triangle scene on GPUs, and the selects that remain. I added a CPU-only check: hand-made NaN bit patterns run through the semantic interpreter, on main and on this PR. I also made three one-line translator mutants to see what the existing CPU tests catch.

What I ran:

  • python -I scripts/run_semantic_tests.py tests/semantic (PR merged with main): 447 files, 5956 tests, 2 files failed, in 765 s: test_image_atomics_guard (47 failures) and test_image_store_d16 (1 failure). Both fail with the same counts with main's translator, so this PR does not cause them.
  • test_image_bvh_tri, _tri_hw, _box, _box_hw: 16 tests, OK on main and on the PR.
  • The semantic files for selects and constants, 14 files: test_cndmask, test_cndmask_sign_mods, test_alu_cndmask_b64, test_alu_cndmask_mix, test_buffer_oob_select, test_scselect_b64_data, test_wave32_lane_select, test_mask_src_sgpr_const, test_pk_mul_lo_const, test_salu_chained_const_prop, test_vop3_const_mods, test_vopc_const_ordered, test_fma_mix_literal and test_float_nan_fract. Result: 214 tests, OK on both.
  • Merge with current main (53 commits ahead; main changed tools/rdna2spirv.py in f6a00fc, rdna2spirv: --fma khr covers the f64 FMAs (v_div_fmas_f64) with OpFmaKHR on doubles #6635): clean.

Hand-made cases on the CPU interpreter (tests/semantic/spirv_mini_interp.py), image_bvh64_intersect_ray. The triangle is TRI0 of the unit quad, with the ray at (0.2, 0.3) along +z. The box is BOX32, where child 2 misses. main and the PR give the same words:

input words (main = PR)
triangle, no NaN bf800000 bf800000 be4ccccd be99999a
triangle, v0.x = 7fc00000 / 7fc00001 / ffc00000 / 7f800001 (sNaN) / ffc12345 ff800000 ffc00000 ffc00000 ffc00000
box, children 7fc00001 ffc00000 7fc00000 7f800001 7fc00001 ffc00000 ffffffff 7f800001

The NaN triangle gives the same words as the llvmpipe and AMD runs above. Child indices with NaN bit patterns pass through the new child | km path unchanged. The interpreter passes OpSelect operands through unchanged and keeps a bitcast float's exact bits. Because of this, it cannot reproduce the KosmicKrisp typing itself. These cases check the integer words only.

Mutants, each in a copy of the PR's translator:

mutant hand-made words the 4 BVH semantic files
canon() constant 0xFFC00000 -> 0x7FC00000 NaN rows -> 7f800000 7fc00000 7fc00000 7fc00000 10 failures (test_image_bvh_tri_hw, rows such as "TRI0 vertex v0.x NaN")
usel_k without the mask (OpBitwiseAnd %uint {x} {ones}) v0.x 7fc00001 -> ffc00001. ffc12345 -> ffc12345. 7fc00000 and ffc00000 unchanged all 16 pass
box call with invert=False hits and misses swapped 299 failures

Two points from this:

  1. A CPU run already catches a wrong canon() constant. The measured NaN rows in test_image_bvh_tri_hw.py fail if it changes, so a GPU run with a NaN scene is not the only check.
  2. The masked branch of usel_k (k != 0xFFFFFFFF, now used only by canon()) has no test. Every NaN input in test_image_bvh_tri_hw.py is 0x7fc00000. u | 0xFFC00000 is 0xFFC00000 for both canonical NaNs, so a usel_k that drops the AND still passes. One CPU-only row with a NaN that carries a payload would catch it, for example v0.x = 0x7fc00001 in test_image_bvh_tri.py, expecting ffc00000 in words 1 to 3, which is the translator's own rule in canon(). This is the non-GPU test that the earlier comments asked for. It is not blocking.

Overlap: #7090 (a16 image_bvh), #5887, #7377 and #7680 merge cleanly with this PR. With #7090 merged as well, its test_image_bvh_a16 and the 4 BVH files pass (22 tests, 1 skipped). #4957 and #4750 also change the BVH lowering, but they already conflict with current main.

AI-assisted (Claude Code).

… NaN words (ItsNotRexed#6623)

Review on ItsNotRexed#7595: every NaN input in the BVH semantic tests was 0x7FC00000, so
a usel_k that dropped its mask still passed. A payload NaN in v0.x catches it
on the CPU.

AI-assisted: yes
@Conrage

Conrage commented Nov 23, 2026

Copy link
Copy Markdown
Author

Thanks, everyone. Two follow-ups:

  • b959fab adds the CPU test that @AsgerCode suggested. A TRI0 vertex holding a payload NaN (0x7FC00001, 0x7F800001, 0xFFC12345) must return ff800000 ffc00000 ffc00000 ffc00000. A usel_k that drops its mask fails it.
  • @gurvancampion's instance/AABB branch: I ran an instance-node variant of cs_bvh (node type 6) on the Apple M5. KosmicKrisp returns ffffffff in all four words, both before and after this PR, and MoltenVK matches. The KosmicKrisp Metal output for that branch has no (NAN). That branch writes only the constant, and nothing float-typed reaches those selects, so it needs no change.

@javdc, all eight words in your Deck output match want[], so the exit 1 looks like a harness or validation exit rather than a wrong result. Could you rerun vk_compute_test directly, as @Kev-Ball asked?

AI-assisted: yes


Generated by Claude Code

@javdc

javdc commented Nov 23, 2026

Copy link
Copy Markdown

Follow-up on Steam Deck LCD (Jupiter), AMD Custom GPU 0405 "Van Gogh", RADV Mesa 26.2.0-devel (git-5c65d4fc31), Vulkan 1.4.350, SteamOS 3.9.5 (holo), kernel 7.2.7-valve2-2-neptune-72-g31504582a073.

LEONIDA_VK_VALIDATION was not set. I ran vk_compute_test <spv> 1 bvh directly (same runtime build, subgroup reported as 32..64) on main-built and PR-built modules:

  • main cs_bvh.spv: exit 0, 1 groups x 64: 0 mismatches, out[0..7] = 72 64 4294967295 4294967295 3240099840 3212836864 3196059648 3196059648
  • PR d657c88d6 cs_bvh.spv: exit 1, 1 groups x 64: 3 mismatches (first at 0: got 0x00000068), out[0..7] = 104 72 64 4294967295 3240099840 3212836864 3196059648 3196059648
  • main cs_bvh32.spv: exit 0, 1 groups x 64: 0 mismatches, same 8 words as main cs_bvh
  • PR d657c88d6 cs_bvh32.spv: exit 1, 1 groups x 64: 3 mismatches (first at 0: got 0x00000068), same 8 words as PR cs_bvh

So on this RADV VANGOGH setup this is a real mismatch (not a validation-exit-only case): the PR changes the stock cs_bvh/cs_bvh32 output words compared to main.

AI-assisted (OpenCode)

@Kev-Ball

Copy link
Copy Markdown

@javdc Thanks for running both modules directly. The three differing words identify a baseline change: dc6068cc6 changed the box-intersection rule, both BVH fixtures and the harness’s expected first three words. Your aa2988cc5 output matches the expectation before that commit; your d657c88d6 output matches the expectation after it. The triangle words agree throughout.

I checked the ancestry: dc6068cc6 is already in #7595’s direct parent 203a348cf and is absent from aa2988cc5. Parent and PR have the same want[8] and this PR changes neither GPU fixture. The Deck measurements therefore reproduce the older expectation change; the three mismatches alone cannot establish a regression in #7595.

The isolating Deck comparison is to rebuild the harness at 203a348cf, build the fixtures separately with 203a348cf and d657c88d6, then run both sets with that one harness. Its expected box words are 68 48 40 ffffffff (hex) for both revisions. AI-assisted QA.

@thehollowedone

Copy link
Copy Markdown

Independent Windows recheck of ac665326 on an RTX 3080 Ti (driver 621.35, MSVC 19.44, Vulkan SDK 1.4.363.0).

I built the harness and both shaders from this revision. run_gpu_tests.py --filter cs_bvh --require-pass passed both the 32-bit and 64-bit node-pointer fixtures with no skips. The eight words matched the current expectations, including the box-intersection results and the ffffffff miss. Both shaders passed spirv-val. Direct reruns with Vulkan core and synchronization validation gave zero diagnostics.

All eight tests in test_image_bvh_tri.py also passed, including payload-NaN canonicalization. This covers the NVIDIA path with synthetic inputs. AI-assisted.

@javdc

javdc commented Nov 23, 2026

Copy link
Copy Markdown

Correction/follow-up on the same Steam Deck LCD (Jupiter), AMD Custom GPU 0405 "Van Gogh", RADV Mesa 26.2.0-devel (git-5c65d4fc31), Vulkan 1.4.350, SteamOS 3.9.5 (holo), kernel 7.2.7-valve2-2-neptune-72-g31504582a073.

After fast-forwarding local main to 67d877390 and rebuilding runtime/build, I retested with the current harness (which includes dc6068cc6, as @Kev-Ball noted):

  • main 67d877390: python3 -I scripts/run_gpu_tests.py --build ... --filter cs_bvh -> 2/2 pass (cs_bvh, cs_bvh32)
  • PR d657c88d6: same command from PR worktree -> 2/2 pass (cs_bvh, cs_bvh32)

My earlier exit-1 report compared against a pre-dc6068cc6 baseline; with the up-to-date harness, I see no cs_bvh/cs_bvh32 regression from this PR on RADV VANGOGH.

AI-assisted (OpenCode)

@ElsCiber

Copy link
Copy Markdown

Windows + NVIDIA regression check of d657c88d: no change against main. AI-assisted, synthetic fixtures only.

  • GPU: NVIDIA GeForce GTX 1660 SUPER (Turing, subgroup 32), driver 621.14, Vulkan 1.4.357
  • CPU: AMD Ryzen 5 3600; OS: Windows 11 Pro 26300
  • Build: MSVC (VS Build Tools 2022) + Ninja, RelWithDebInfo, Windows SDK 10.1.26100.7705, Vulkan SDK 1.4.363.0, llvm-mc 23.1.6

Runtime built from each tree, scripts/run_gpu_tests.py with LEONIDA_VK_VALIDATION=1:

tree default LEONIDA_W64_EMULATE=1
this PR d657c88d 191/240 passed, 48 skipped, 1 failed 222/240 passed, 17 skipped, 1 failed
main dde82f27 192/241 passed, 48 skipped, 1 failed 223/241 passed, 17 skipped, 1 failed

@EmreO33

EmreO33 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested ac665326d on Intel's Windows driver, which this PR doesn't have a result from yet; Intel's compiler is the one that folded NaN compares before #664, so it seemed worth checking that usel_k's bitwise selects keep the NaN and miss words there. Pass, no change, on both GPUs of one laptop (picked with LEONIDA_VK_DEVICE):

GPU Driver cs_bvh cs_bvh32
Intel Raptor Lake-S Mobile iGPU (Xe-LP, subgroup 8..32) 101.7092, Vulkan 1.4.323 PASS PASS
NVIDIA GeForce RTX 5060 Laptop (subgroup 32..32) 621.24, Vulkan 1.4.357 PASS PASS

run_gpu_tests.py --filter bvh (this head's translator, test programs from main 8575d36e, since the PR is Python-only): 2/2 translated, spirv-val valid and passed on each GPU. test_image_bvh_tri: 8 tests OK.

Windows 11 Pro 26300, MSVC 19.44, llvm-mc 21.1.8 (AMDGPU), SPIRV-Tools v2026.4. No game files. AI-assisted (Claude Code).

@zsigisti

Copy link
Copy Markdown

Tested ac665326d on NVIDIA GeForce RTX 5070 (Blackwell, subgroup 32..32), NVIDIA 615.78.08, Vulkan 1.4.351, Arch Linux (kernel 7.3.0-cachyos), GCC 16.2.1, CMake 4.4.5, llvm-mc 23.1.4, Python 3.14.8: pass, no regression.

Code read: usel_k returns k / x correctly in both the plain and invert forms, and the 0xFFFFFFFF shortcut (x | km) agrees with the general form. cs_bvh and cs_bvh32 still pass on NVIDIA.

No game files. AI-assisted (Claude).

@matheusfermiano-source

Copy link
Copy Markdown

Tested ac665326d (the PR's diff applied on main 867d922f0), full python -I scripts/run_gpu_tests.py on both GPUs of one laptop, each compared with main on the same machine and binaries, CachyOS Linux: pass.

GPU Driver main this PR Difference
AMD Radeon 660M (RDNA2 iGPU, gfx1035, Ryzen 5 7535HS), subgroup 32..64 RADV, Mesa 26.3.1 225/241 passed, 16 skipped 225/241 passed, 16 skipped same results as main
NVIDIA GeForce RTX 3050 Laptop (Ampere), subgroup 32 NVIDIA 620.73.04 192/241 passed, 48 skipped 192/241 passed, 48 skipped fails on main too: ms_wave_info_s3 (#6172)

No game files. AI-assisted (Claude Code).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

KosmicKrisp: nir_to_msl emits (NAN) (0x7fc00000) for uint constants (0xffffffff) in cs_bvh / cs_bvh32