Skip to content

Translator: declare SignedZeroInfNanPreserve so drivers keep NaN, inf and -0 (SHADER-99) - #664

Merged
ItsNotRexed merged 3 commits into
ItsNotRexed:mainfrom
WHOISJARDAS:float-controls-szinp
Nov 22, 2026
Merged

ItsNotRexed merged 3 commits into
ItsNotRexed:mainfrom
WHOISJARDAS:float-controls-szinp

Conversation

@WHOISJARDAS

@WHOISJARDAS WHOISJARDAS commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

What and why

RDNA2 float ops return NaN, ±inf and −0 as computed. Without float controls, Vulkan lets the driver assume none of them occur, and AMD's compiler does. On AMD:

#494 pointed out the missing execution mode and left it out. This PR adds it:

  • tools/rdna2spirv.py. Every module declares the SignedZeroInfNanPreserve capability and OpExecutionMode %main SignedZeroInfNanPreserve 32.
    • The capability is core since SPIR-V 1.4, so no extension is needed at vulkan1.2.
    • The index entry gets "float_controls": ["shaderSignedZeroInfNanPreserveFloat32"].
    • --no-float-controls leaves all of this out.
  • runtime/test/vk_pipeline_check.cpp. It reads float_controls and skips a shader on a device that reports the property false, as it already does for maintenance8.
  • New GPU test runtime/test/shaders/cs_signed_zero_nan.asm. A wave32 dump with the expected words in its header, registered in check.py and scripts/run_gpu_tests.py.
  • Tests. tests/test_translate.py checks the mode, the index entry and the opt-out, in a cs and a ps module. tests/test_shader_checks.py checks which words go unjudged.
  • docs/design.md. A new "Float controls" contract row with the measurements.

f64 (SignedZeroInfNanPreserve 64) is left for later, since nothing here measured it.

According to other testers, this PR also fixes two other reported failures:

Claim: #374 (comment)

Tested

Latest run: head a0e8229 on main 4eb6155.

  • GPU: AMD Radeon RX 9070 XT (RDNA4), AMD proprietary 26.11.2 (LLPC), Windows 11 Pro.
  • Toolchain: MSVC 14.51 (VS 2026), Vulkan SDK 1.4.363.0, llvm-mc 23.1.5 (MSYS2).

Results:

  • cs_signed_zero_nan: 80000000 80000000 80008000 00008000 1 1 1 7c00 with the mode. With --no-float-controls (what main emits), out[4..7] are 0 0 0 0.
  • f16 fuzzer (tools/valu_fuzz.py --family f16 --programs 100), seeds 1–3: 200/200 each, native and --emulate. On an RX 9070, main alone gave 99/100 with FUZZ-42's seed and 399/400 with seed 3; with this PR, 100/100 and 400/400 (2).
  • Shader builds:
    • build.py: 200/200 translated, and all pass spirv-val.
    • check.py: 157/161 pass, 4 skipped (three mesh fixtures, and ps_w64x_readlane).
  • scripts/run_gpu_tests.py: 168/181 pass, 13 skipped, none failed. Same with LEONIDA_W64_EMULATE=1 VKC_SUBGROUP_SIZE=32 VKH_SUBGROUP_SIZE=32.
  • CPU tests:
    • python -m pytest tests/test_translate.py: 503 passed, 2 skipped;
    • tests/test_shader_checks.py: 67 OK;
    • unittest discover -s tests/semantic: 1671 OK;
    • compileall: ok.
  • ctest: 115/116. d3d12_draw fails, as it does on main (fix(test): use monotonic fence value (31) for bundle blend pass in d3d12_draw_test #1807).

Other GPUs and drivers are in the comments: NVIDIA, Intel, AMD (RADV and proprietary), Apple (MoltenVK) and Mesa llvmpipe.

Not tested by me:

  • llvmpipe, apart from the tester's run linked above and the unit tests;
  • a driver that reports shaderSignedZeroInfNanPreserveFloat32 false, so the skip path in vk_pipeline_check hasn't run on hardware.

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.

AI-assisted (Claude Code): it found the issue with the fuzzer, wrote the change and the tests, and ran everything above on the RX 9070 XT.

🤖 Generated with Claude Code

@WHOISJARDAS WHOISJARDAS changed the title Translator: declare SignedZeroInfNanPreserve so drivers keep NaN, inf and -0 Translator: declare SignedZeroInfNanPreserve so drivers keep NaN, inf and -0 (SHADER-99) Nov 22, 2026
@VictorJulianiR

Copy link
Copy Markdown
Contributor

I ran the new fixture and the seed-1 f16 fuzzer on a GitHub-hosted Apple Paravirtual device, MoltenVK 1.4.2, macOS 15.8.2. At 8e3d7ec, the selected device reported shaderSignedZeroInfNanPreserveFloat32 = 1. The pipeline checker built the pipeline both with the mode enabled and with the opt-out.

With default Metal math, enabling the mode changed words 4–6 of cs_signed_zero_nan from zero to one. Those three NaN checks now pass. Words 0, 2 and 3 still contained positive zero where the fixture expects negative-zero bits. Word 1 retained negative zero. With MVK_CONFIG_FAST_MATH_ENABLED=0, the base and opt-out also passed the three NaN checks, while all three sign mismatches remained. The hosted job records the fixture failure.

For seed 1, wave32, 100 programs, c432cdc, #664 on, #664 off, #575 alone, and the clean combination of #575 with #664 each matched 99/100. All 500 modules validated and ran. The only mismatch in each group was program 23: all 64 lanes returned 0x40000000 for v27 against 0x40008000 in the oracle. This is the translated f16 operation from the earlier prefix check. This device exercises the supported-property path.

AI-assisted, synthetic inputs only. Property, fixture words and fuzzer results.

@tylerstraub

Copy link
Copy Markdown
Contributor

Tested 8e3d7ec3a7a0e0b35cc7bea416e2e99953a199c1 on NVIDIA GeForce RTX 5090, 595.99.02 (Linux).

The registered cs_signed_zero_nan GPU fixture passed on the default translation. I then translated the same input with --no-float-controls and dispatched both modules with the same runtime build. Both passed spirv-val for Vulkan 1.2. Disassembly confirmed SignedZeroInfNanPreserve 32 on the default module and its absence on the opt-out.

Both dispatches returned these eight words exactly (hex): 80000000 80000000 80008000 00008000 00000001 00000001 00000001 00007c00. All signed-zero and NaN checks therefore matched in both configurations on this driver. This comparison covers the fixture; the pipeline-checker skip for a device lacking the property remains untested here.

AI-assisted verification.

@IAmNotSiob IAmNotSiob left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

big one, nice find. the mode is declared, the runtime checks the property and skips the shader if it's missing, and there's an opt-out flag. this also covers the -0 v_pk_mul_f16 thing from #551's run. tests pass with main (805). f64 later is fine o7 AI-assisted review (Claude Code).

@rtrexmass

Copy link
Copy Markdown

Tested 8e3d7ec on Intel Arc B580, driver 32.0.101.9175, Windows 11 build 28120: pass.

  • build.py: 83 shaders, 83 translated, 83 pass spirv-val (the new fixture included)
  • run_gpu_tests.py --filter cs_signed_zero_nan: 1/1 passed - 0x80000000 0x80000000 0x80008000 0x8000 0x1 0x1 0x1 0x7c00, so -0 and +inf survive on Intel as well
  • check.py: cs_signed_zero_nan ok; 50 of 79 pass, 27 skipped (the wave64 family, widest subgroup here is 32)

tests/test_translate.py reports 209 skipped here because it needs a work folder; no game files were used. This is a useful second vendor for the float-controls change: the premise is about drivers being free to assume no NaN/inf/-0, and Intel is a different compiler from AMD's. AI-assisted.

@VeTkN

VeTkN commented Nov 22, 2026

Copy link
Copy Markdown

Tested 8e3d7ec on RTX 5070 (Blackwell), NVIDIA 621.01, Windows 11 Pro (10.0.26200): pass.

run_gpu_tests.py:                     60/86 passed, 26 skipped (wave64, 32-wide subgroups)
run_gpu_tests.py, LEONIDA_W64_EMULATE=1: 86/86 passed
cs_signed_zero_nan: 0x80000000 0x80000000 0x80008000 0x8000 0x1 0x1 0x1 0x7c00
valu_fuzz.py --family f16 --programs 100 --seed 1 --wave both: 100/100; --emulate: 200/200

No game files.

AI-assisted (Claude)

@dougmb

dougmb commented Nov 22, 2026

Copy link
Copy Markdown

Tested 8e3d7ec on an NVIDIA RTX 3060, Linux: pass, no regression. NVIDIA keeps NaN, inf and −0 with or without the mode, so this card can't show the fix.

GPU:      NVIDIA GeForce RTX 3060 (Ampere), subgroup 32..32
Driver:   NVIDIA 620.73.04 (Linux proprietary), Vulkan 1.4.357; shaderSignedZeroInfNanPreserveFloat32 = true
OS:       Arch Linux, kernel 6.18.64-1-lts
Tools:    LLVM 23.1.4 (llvm-mc), SPIRV-Tools v2026.4, Python 3.14.10, GCC + Ninja (RelWithDebInfo)
Commits:  main c432cdc vs this PR 8e3d7ec; "#575 + #664" is 6f4bd2a merged with 8e3d7ec locally (only docs/design.md conflicts; the translator merges cleanly)

cs_signed_zero_nan. With the mode, the run gives 80000000 80000000 80008000 00008000 1 1 1 7c00, as expected. With --no-float-controls (main's output) it gives the same words: the x != x checks and the −0 products survive on this driver either way, so the 0s in out[4..7] are AMD-specific.

scripts/run_gpu_tests.py:

main this PR
native 59/85 passed, 26 skipped 60/86 passed, 26 skipped
LEONIDA_W64_EMULATE=1 VKC_SUBGROUP_SIZE=32 VKH_SUBGROUP_SIZE=32 — 86/86 passed

All 26 native skips are "no 64-wide subgroup on this device".

f16 fuzzer (tools/valu_fuzz.py --family f16 --programs 100, the same vk_compute_test build for every column):

seed main this PR #575 + this PR
1, native (wave32) 100/100 100/100 100/100
2, native (wave32) 100/100 100/100 100/100
3, native (wave32) 100/100 100/100 100/100
1, --emulate 200/200 200/200 200/200
2, --emulate 200/200 200/200 200/200
3, --emulate 200/200 200/200 200/200

There were no harness errors, and nothing failed to translate.

Shader tests on this PR:

  • build.py: 83 shaders, 83 translated, 83 pass spirv-val.
  • check.py: 52 of 79 pass and 27 are skipped. 24 skips are "full 64-wide compute subgroups unavailable"; the other 3 are mesh fixtures.
  • vk_pipeline_check on that output: 42 cs, 37 ps and 4 vs modules and pipelines are ok, with none skipped. The device reports the property true, so the new skip path didn't run here either.

Unit tests:

  • pytest tests/test_translate.py: 207 passed and 2 skipped (main: 202 passed, 2 skipped).
  • unittest discover -s tests/semantic: 805 OK.
  • tests/test_shader_checks.py: 25 OK.
  • compileall: ok.
  • ctest: 9/9 (the Linux build has only the Vulkan tools).

AI-assisted (Claude Code). Only the repository's hand-written test shaders and synthetic fuzzer programs were used; no game files.

@matheuskshn

Copy link
Copy Markdown
Contributor

Tested SPIR-V text and metadata at 8e3d7ec on Windows 11 / Python 3.12.14. A synthetic pixel shader emits both the capability and 32-bit execution mode, and shader_meta reports the required property. Disabling FLOAT_CONTROLS removes all three. One integration point: the standard make_game.py path currently has no pass-through for the translator opt-out, so using it from that build path would need a separate setting. CPU-only probe; no Vulkan validation run. AI-assisted.

@Bushyon

Bushyon commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested 8e3d7ec on an AMD Radeon RX 7800 XT (RDNA3), RADV Mesa 26.2.6 (ACO), Vulkan 1.4.354, Fedora 44: pass. As far as I can see, this is the first RADV result here, and RADV needs the fix, unlike the NVIDIA cards above.

cs_signed_zero_nan with and without the mode. Same translator, --no-float-controls for the second line, vk_compute_test ... 1 dump:

  • with the mode: 80000000 80000000 80008000 00008000 1 1 1 7c00 (expected)
  • without it: 80000000 80000000 80008000 00008000 1 1 0 7c00

So ACO folds the f16 x != x NaN check (out[6]) when the mode is missing. The f32 NaN checks, the −0 results and the NaN conversion survive on RADV either way. The PR fixes the one that fails.

Suites at 8e3d7ec (subgroups 32..64, shaderSignedZeroInfNanPreserveFloat32 = true):

GCC 16.2.1, LLVM 22.1.8 (llvm-mc), SPIRV-Tools v2026.1, Python 3.14.10. Only the repository's own tests and fuzzers. AI-assisted (Claude Code): it ran the tests and wrote this comment.

@kotorvr

kotorvr commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested 8e3d7ec on RTX 4090 (driver 621.14, 32-wide subgroups), Windows 11 26200: pass

  • RelWithDebInfo Ninja build of runtime/ (MSVC, Vulkan SDK 1.4.363.0); ctest: 27/27
  • python -I scripts/run_gpu_tests.py: 60/86 passed, 26 skipped (wave64 tests); with LEONIDA_W64_EMULATE=1: 86/86. main c432cdc on the same machine: 59/85 and 85/85. The new cs_signed_zero_nan gives 0x80000000 0x80000000 0x80008000 0x8000 0x1 0x1 0x1 0x7c00 in both modes
  • python -m unittest discover -s tests/semantic: 805 OK
  • python -m pytest tests --ignore=tests/semantic: 2014 passed, 5 skipped, 1 xfailed (main: 2009 passed)

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

@realmalikov

Copy link
Copy Markdown

Tested #664 (8e3d7ec) on an NVIDIA GTX 1060 6GB (Pascal, NVIDIA 582.78, Windows 11 10.0.26200).

cs_signed_zero_nan (1 group x 64): 0 mismatches,
out[0..7] = 0x80000000 0x80000000 0x80008000 0x00008000 1 1 1 0x00007c00

On this driver the same shader translated from main c432cdc also passes, so #664 is neutral here
(NVIDIA 582.78 already keeps -0/NaN) and adds no regression. The discriminating hardware is AMD.
AI-assisted.

@TheHoracio

Copy link
Copy Markdown
Contributor

Independent check on RDNA3: an A/B of the f16 fuzzer with this PR's translator. This PR fixes all 4 mismatches seen on main.

  • Setup: AMD Radeon RX 7800 XT, driver 26.10.1 (32.0.32015.7029), Windows 11 Pro (26300), llvm-mc 21.1.8 (scripts/build_llvm_mc.ps1), Vulkan SDK 1.4.363.0.
  • Method: 8e3d7ec cherry-picked onto main 4a36bb1 (it applied cleanly). Then valu_fuzz.py --family f16 --seed 1 --programs 200 --wave both, with the same build and assembler for both sides.
translator native --emulate
main 4a36bb1 396/400, 4 mismatched 396/400, 4 mismatched
main + this PR 400/400 400/400

The 4 programs are past 100, so a 100-program run doesn't reach them:

  • 160 (w64) and 179 (w64): registers come back as the 0xeeeeeeee fill, i.e. never stored. The model has NaN halves there (0x7e00), from v_ashrrev_i16/v_cvt_pkrtz_f16_f32 in 160 and v_fma_f16 op_sel in 179. This matches the "NaN results that were never stored" in the contract row.
  • 180 (w32) and 191 (w32): v_pk_mul_f16 ... op_sel:[1,0] returns +0 where the model has −0 (0x0000c95c vs 0x8000c95c, 0x00000000 vs 0x80008000).

All of these are f16 results, and only SignedZeroInfNanPreserve 32 is declared. On this driver the 32-bit mode is evidently enough for them. Strictly, the f16 values would need the 16-bit mode too (shaderSignedZeroInfNanPreserveFloat16); this GPU reports it, but I haven't tested a build that declares it. Synthetic programs only. AI-assisted.

@abilliontokens

Copy link
Copy Markdown
Contributor

Tested 8e3d7ec on RTX 5060 Ti (NVIDIA 621.24, Windows 11 26200), llvm-mc 21.1.8, SPIRV-Tools v2026.4, main baseline 067d3e8: native 60 passed/0 failed/26 skipped; LEONIDA_W64_EMULATE=1 86/0/0. The PR's new cs_signed_zero_nan test passes in both forms; otherwise the expected skip profile of its base on a 32-wide-subgroup GPU, no new failures vs baseline. No game files. AI-assisted (omp orchestrator).

@undeadhuman37

Copy link
Copy Markdown
Contributor

Tested on Apple A18 Pro (MacBook Neo), MoltenVK 1.4.2, macOS 26.6.2: NaN part passes, -0 part doesn't (an Apple limit, not this PR).

The PR conflicts with main, so I applied only its tools/rdna2spirv.py change on top of main d3841c0 (kept both sides of the --bary-fallback / --no-float-controls conflict) and used main's runtime build. MoltenVK reports shaderSignedZeroInfNanPreserveFloat16 and Float32 = true.

cs_signed_zero_nan (vk_compute_test ... 1 dump):

out[0..7]
expected 80000000 80000000 80008000 00008000 1 1 1 7c00
this PR 0 80000000 0 0 1 1 1 7c00
without the mode (main) 0 80000000 0 0 0 0 0 7c00

So on Apple the mode fixes the three NaN checks (out[4..6]). The -0 products (out[0], out[2], out[3]) still come back +0, with or without the mode, and also with MVK_CONFIG_FAST_MATH_ENABLED=0. The translator emits a plain OpFMul there, so the sign is lost in MoltenVK/Metal. That matches what I reported in #1203. (-0 + -0 in out[1] is fine.)

Other checks with the PR's translator change:

The check.py expectation for cs_signed_zero_nan would fail on Apple because of out[0], out[2] and out[3]. It may need a skip or a looser check for -0 on MoltenVK.

AI-assisted. No game files.

@Urban225

Copy link
Copy Markdown
Contributor

Tested on AMD hardware: this fixes a -0 mismatch that main still has.

RX 7900 XTX (RDNA3), AMD proprietary 26.10.1 (LLPC), Windows 11, llvm-mc 21.1.8. python -I tools/valu_fuzz.py --family f16 --programs 200 --seed 3, native:

result
main at 426023a 399/400, --show 3:104:64: v_mul_f16_e64 v22, v29, v20 gives 0xc2df0000, want 0xc2df8000 (-0 × positive comes back +0)
main at 426023a + this PR's two translator lines 400/400, 0 not translated

How I applied it: this branch no longer merges into main (conflicts in tools/rdna2spirv.py, tests/test_translate.py, docs/design.md, check.py, run_gpu_tests.py), so I put only the capability and OpExecutionMode %main SignedZeroInfNanPreserve 32 on top of current main, unconditionally. I did not test the --no-float-controls switch, the new cs_signed_zero_nan test or the runtime property check.

So on this driver the declaration is what keeps the sign: the f16 multiply is an f32 OpFMul, and without the mode LLPC drops the sign of zero. Details of the mismatch are in #1203.

AI-assisted (Claude prepared the test branch and read the logs); the runs are from my machine.

@WHOISJARDAS

Copy link
Copy Markdown
Contributor Author

Thanks to everyone who tested this: 13 runs across four vendors. In summary:

  • Needs the mode:
    • AMD RDNA4 on Windows (RX 9070 XT);
    • RDNA3 on Windows (RX 7800 XT, where @TheHoracio saw it fix all 4 f16 mismatches on main);
    • RADV (RX 7800 XT, where @Bushyon found that ACO folds the f16 NaN check without it).
  • Neutral, no regressions: NVIDIA (RTX 5090, 5070, 5060 Ti, 4090, 3060, GTX 1060) and Intel Arc B580 keep NaN, inf and −0 either way.
  • Apple (MoltenVK): the device reports the property and the mode fixes the three NaN checks. −0 products still come back +0 with or without it (valu_fuzz f16: f16 multiply gives +0 instead of -0 on Apple A18 Pro (MoltenVK) #1203, SHADER-182).

Changes since the first version:

  • Rebased on main 426023a. I resolved the conflicts with --bary-fallback, --mesh-compute and the new tests, keeping both sides.
  • New commit: check.py and run_gpu_tests.py don't judge cs_signed_zero_nan's −0 words (0, 2, 3) on an Apple device, as @undeadhuman37 suggested. The other five words still count everywhere, with unit tests in tests/test_shader_checks.py.
  • The docs/design.md row now records the per-vendor results.
  • The make_game.py pass-through (@matheuskshn) is posted as a finding in Coordinating who works on what (5) (moved to #1380) #1218 rather than added here. The other translator fallbacks aren't forwarded either, and no tested device lacks the property.

Re-tested at the new head (84870917) on the RX 9070 XT:

  • ctest 61/61.
  • run_gpu_tests.py 119/119, and 119/119 with LEONIDA_W64_EMULATE=1 and 32 lanes forced.
  • check.py 106 of 110 pass. The one failure, cs_barrier_loop, is the same on main: check.py doesn't pin it to 32 lanes (finding in Coordinating who works on what (5) (moved to #1380) #1218).
  • build.py: 115 of 115 translated and pass spirv-val. vk_pipeline_check: 115 pipelines ok.
  • f16 fuzzer, seeds 1 to 3, native and --emulate: 1200 of 1200.
  • tests/test_translate.py 337 passed, tests/semantic 1139 OK, tests/test_shader_checks.py 40 OK.

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

WHOISJARDAS added a commit to WHOISJARDAS/Leonida that referenced this pull request Nov 22, 2026
…sNotRexed#1203)

MoltenVK returns +0 for -0 products with or without SignedZeroInfNanPreserve,
in out[0] (v_mul_f32), out[2] (v_pk_mul_f16) and out[3] (v_mul_f16). The mode
still fixes the three NaN checks on Apple. Seen on an Apple A18 Pro and an Apple
Paravirtual device in ItsNotRexed#664, tracked as ItsNotRexed#1203 / SHADER-182.

- check.py: judged_words() leaves those three words of cs_signed_zero_nan
  unjudged when vk_compute_test's device line names an Apple GPU, and
  words_match() compares the rest. The other five words still have to match,
  and every other device judges all eight.
- run_gpu_tests.py: uses the same two functions and says which words weren't
  judged.
- tests/test_shader_checks.py: tests for the Apple and non-Apple cases, the
  NaN checks still judged on Apple, and run_gpu_tests' judge_cs_dump.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Dom-in

Dom-in commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

A stronger reason to land this: on AMD's Windows driver, an f16 NaN result without float controls deletes the store that uses it. Measured on an AMD Radeon RX 9070 (RDNA4), AMD 26.11.2 (LLPC), Windows 11.

valu_fuzz.py --family f16 --wave both --seed 101 --programs 200 on main (426023a) gives 399/400. In cs_f16fuzz_s101_85_w64, v20 and v29 read back as the buffer's 0xEEEEEEEE prefill in every thread: the whole dword is unwritten, not just wrong NaN bits.

I minimized it on the GPU to:

v_mov_b32 v22, 0x7dab          ; any f16 NaN, signaling or quiet
v_add_f16_e32 v29, v20, v22    ; v20.lo = 0x3c00
buffer_store_dword v29, ...

Raw v29 for threads 0..3 (--require-wave64; wave32 behaves the same):

program main main + this PR (8487091 merged in)
v_add_f16 of sNaN 0x7dab 0xeeeeeeee ×4 0xb4bc7fab ×4 (quieted, high half kept)
v_add_f16 of qNaN 0x7e00 0xeeeeeeee ×4 0xb4bc7e00 ×4
v_add_f16_e64 of sNaN 0xeeeeeeee ×4 0xb4bc7fab ×4
the fuzz program's 5 ops, NaN operand 0xeeeeeeee ×4 0x87447fab 0x87c47fab 0x88447fab 0x88c47fab
same, non-NaN operand (v21) 0x8744c0f1 ... same

What main emits:

  • the f16 add as UnpackHalf2x16 → OpFAdd %float → an integer repack, all well defined in SPIR-V;
  • no SignedZeroInfNanPreserve, so LLPC appears free to treat the OpFAdd as no-NaN.

A NaN result then becomes poison, flows through the integer repack, and the store is dropped. No OpUndef is involved, and spirv-val passes.

With this PR, valu_fuzz --family f16 --seed 101 --wave both gives 400/400.

So on main a game shader that produces an f16 NaN can lose the whole store, not just its NaN bits. The reproducer is synthetic, no game files.

AI-assisted (Claude Code).

WHOISJARDAS added a commit to WHOISJARDAS/Leonida that referenced this pull request Nov 22, 2026
…sNotRexed#1203)

MoltenVK returns +0 for -0 products with or without SignedZeroInfNanPreserve,
in out[0] (v_mul_f32), out[2] (v_pk_mul_f16) and out[3] (v_mul_f16). The mode
still fixes the three NaN checks on Apple. Seen on an Apple A18 Pro and an Apple
Paravirtual device in ItsNotRexed#664, tracked as ItsNotRexed#1203 / SHADER-182.

- check.py: judged_words() leaves those three words of cs_signed_zero_nan
  unjudged when vk_compute_test's device line names an Apple GPU, and
  words_match() compares the rest. The other five words still have to match,
  and every other device judges all eight.
- run_gpu_tests.py: uses the same two functions and says which words weren't
  judged.
- tests/test_shader_checks.py: tests for the Apple and non-Apple cases, the
  NaN checks still judged on Apple, and run_gpu_tests' judge_cs_dump.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@WHOISJARDAS

Copy link
Copy Markdown
Contributor Author

Rebased on main e7584c5. It merges cleanly again. The only conflict was a new docs/design.md row next to "Known approximations", and I kept both.

Re-tested at 6b09ae4 on the RX 9070 XT:

  • ctest 61/61;
  • run_gpu_tests.py 119/119, and 119/119 with LEONIDA_W64_EMULATE=1 and 32 lanes forced;
  • the f16 fuzzer (seeds 1 to 3, native and --emulate) 1200/1200;
  • cs_signed_zero_nan passes, and gets 0 in out[4..7] with --no-float-controls;
  • vk_pipeline_check 115 ok;
  • tests/test_translate.py 337 passed, tests/semantic 1148 OK.

check.py's one failure, cs_barrier_loop, is on main too (TEST-178).

Thanks @Dom-in for the RX 9070 measurement: the dropped NaN stores match what I saw here with #575.

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

@WHOISJARDAS

Copy link
Copy Markdown
Contributor Author

Rebased onto main 89b047c (head 4799245). The PR merges cleanly again.

@Dom-in, thanks for float-controls-v2. main had already moved past a0acd33, so I rebased onto the newer main myself instead of resetting onto your branch. We resolved the conflicts the same way. The two diffs differ only in list order and one blank line.

Tested on 4799245: AMD Radeon RX 9070 XT (RDNA4), AMD 26.11.2 (LLPC), Windows 11.

  • python -m pytest tests/test_translate.py: 474 passed, 2 skipped. tests/test_shader_checks.py: 62 OK. unittest discover -s tests/semantic: 1450 OK.
  • build.py: 179/179 translated, and all pass spirv-val. check.py: 148/151, 3 skipped.
  • scripts/run_gpu_tests.py: 159/167, 8 skipped, none failed. Same with LEONIDA_W64_EMULATE=1 VKC_SUBGROUP_SIZE=32 VKH_SUBGROUP_SIZE=32.
  • valu_fuzz.py --family f16 --programs 100, seeds 1–3: 200/200 each, native and --emulate.
  • ctest: 100/101. The failure is the new bundle blend check in d3d12_draw (5f7caad): bundle blend pixel (0, 0): got 255,0,0,255, expected red 64. That test's shaders are GLSL, and none of its sources are in this PR. I'll report it separately.

AI-assisted (Claude Code).

@tylerstraub

Copy link
Copy Markdown
Contributor

Tested 479924531dd114cb77dda0824bf2fc4c2e83ef5a on NVIDIA GeForce RTX 5090, 595.99.02 (Linux).

Independent check of the rebased head on Linux 7.0.0-43-generic with LLVM 21.1.8 and SPIRV-Tools 2026.1.

  • RTX 5090, NVIDIA driver 595.99.02 (subgroup 32): cs_signed_zero_nan matched all eight words and ps_vcmpx_forms matched all 4,096 pixels.
  • Mesa llvmpipe (LLVM 21.1.8, subgroup 8): the compute fixture matched seven of eight words. The self-compare of the result of 0 * inf returned 0 in out[5], expected 1. The runner exited 1. A direct dispatch repeated the discrepancy, and it persisted when I removed only the float-control capability and execution mode from the same module. The RTX 5090 matched all eight words in that control.
  • The default module validated, declared SignedZeroInfNanPreserve 32, and carried the matching index requirement. vk_pipeline_check created the compute pipeline on both devices with zero skips; llvmpipe ran without a required subgroup size.

The llvmpipe result is a readback difference that persisted with and without the declaration. The Windows Intel case remains untested here.

AI-assisted verification.

WHOISJARDAS and others added 3 commits November 22, 2026 15:35
… and -0

RDNA2 float ops return NaN, +-inf and -0 as computed. Without float controls,
Vulkan lets the driver assume none of them occur, and AMD's compiler does. On
an RX 9070 XT (26.11.2), x != x NaN checks fold to false and -0 products come
back +0. With integer f16 narrowing (ItsNotRexed#575), NaN results are never stored.

- rdna2spirv.py: every module declares the SignedZeroInfNanPreserve capability
  and OpExecutionMode SignedZeroInfNanPreserve 32. The index entry lists the
  property it needs (float_controls). --no-float-controls leaves both out.
- vk_pipeline_check: reads float_controls and skips a shader on a device
  without shaderSignedZeroInfNanPreserveFloat32.
- GPU test cs_signed_zero_nan (check.py, run_gpu_tests.py): without the mode,
  out[4..7] are 0 on AMD; with it, all eight words match.
- tests/test_translate.py: covers the mode, the index entry and the opt-out.
- docs/design.md: a "Float controls" contract row.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…sNotRexed#1203)

MoltenVK returns +0 for -0 products with or without SignedZeroInfNanPreserve,
in out[0] (v_mul_f32), out[2] (v_pk_mul_f16) and out[3] (v_mul_f16). The mode
still fixes the three NaN checks on Apple. Seen on an Apple A18 Pro and an Apple
Paravirtual device in ItsNotRexed#664, tracked as ItsNotRexed#1203 / SHADER-182.

- check.py: judged_words() leaves those three words of cs_signed_zero_nan
  unjudged when vk_compute_test's device line names an Apple GPU, and
  words_match() compares the rest. The other five words still have to match,
  and every other device judges all eight.
- run_gpu_tests.py: uses the same two functions and says which words weren't
  judged.
- tests/test_shader_checks.py: tests for the Apple and non-Apple cases, the
  NaN checks still judged on Apple, and run_gpu_tests' judge_cs_dump.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Mesa llvmpipe returns 0 for out[5], the NaN check of 0 * inf with an
inline-constant 0, with or without SignedZeroInfNanPreserve, while its
other NaN checks give 1 (a run on ItsNotRexed#664, Mesa with LLVM 21.1.8). The CI
runs scripts/run_gpu_tests.py on llvmpipe, so the test would fail there.

APPLE_UNJUDGED_WORDS becomes UNJUDGED_WORDS, keyed by the first word of
the device name on vk_compute_test's "device:" line. Apple keeps words
0, 2 and 3, and llvmpipe gets word 5. Every other device still judges
all eight words.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@EmreO33

EmreO33 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Corpus count for this PR's head 47992453 against its base 89b047cd, on my own copy of the Xbox package (1.0.2.1). Only counts are posted, nothing from the game.

The shaders were carved and disassembled once with make_game.py --stages shaders (llvm-mc 21.1.8, gfx1013). Then each commit's tools/rdna2spirv.py translated the same disassembly, as make_game.py does: 16 shards with --no-asm --wave64-emulate, then --merge, with SPIRV-Tools v2026.4.

89b047cd (base) 47992453 (this PR)
shaders 26,503 26,503
translated 26,503 26,503
pass spirv-val 26,503 26,503
declare SignedZeroInfNanPreserve 0 26,503

Comparing the two index.json files, every shader's metadata matches except two fields. capabilities gains SignedZeroInfNanPreserve, and float_controls is ["shaderSignedZeroInfNanPreserveFloat32"]. Both differ on all 26,503 shaders and on nothing else. So the change adds the execution mode everywhere and leaves the rest of the translation as it was.

Windows 11 26300, wave64 emulation on (both GPUs here have 32-wide subgroups at most). @WHOISJARDAS, this is the whole-corpus count to go with the GPU results above.

AI-assisted (Claude Code).

@WHOISJARDAS

Copy link
Copy Markdown
Contributor Author

@tylerstraub, thanks for the llvmpipe run. The CI's "GPU tests on llvmpipe" step (.github/workflows/runtime.yml) runs scripts/run_gpu_tests.py on llvmpipe, so this test would have failed there once the workflows were approved.

New commit a0e8229.

  • APPLE_UNJUDGED_WORDS becomes UNJUDGED_WORDS, keyed by the first word of the device name on vk_compute_test's device: line.
  • On llvmpipe, word 5 (the 0 * inf NaN check) isn't judged. Its other seven words still are, and every other device still judges all eight.
  • tests/test_shader_checks.py checks this with the words you got.
  • I have no llvmpipe here (Windows, no Mesa), so until the CI runs, that path is only unit-tested.

Also rebased onto main 4eb6155 (head a0e8229). The PR merges cleanly again.

  • I moved this PR's entries away from the ends of the shared lists, where new tests get appended, so later rebases should conflict less. Behaviour doesn't change.
  • I dropped the clause in "Known approximations": main now has that row three times, and the Float controls row already covers it.

Tested on a0e8229: AMD Radeon RX 9070 XT (RDNA4), AMD 26.11.2 (LLPC), Windows 11.

  • python -m pytest tests/test_translate.py: 503 passed, 2 skipped. The skips are ms_f16_pack, which has no synthetic DXBC.
  • tests/test_shader_checks.py: 67 OK. unittest discover -s tests/semantic: 1671 OK.
  • build.py: 200/200 translated, and all pass spirv-val.
  • check.py: 157/161 pass, 4 skipped (three mesh fixtures, and ps_w64x_readlane).
  • scripts/run_gpu_tests.py: 168/181 pass, 13 skipped, none failed. Same with LEONIDA_W64_EMULATE=1 VKC_SUBGROUP_SIZE=32 VKH_SUBGROUP_SIZE=32.
  • cs_signed_zero_nan: 80000000 80000000 80008000 8000 1 1 1 7c00 with the mode. With --no-float-controls, out[4..7] are 0 0 0 0.
  • valu_fuzz.py --family f16 --programs 100, seeds 1–3: 200/200 each, native and --emulate.
  • ctest: 115/116. d3d12_draw fails as it does on main (fence signal 21 is not above 30), which fix(test): use monotonic fence value (31) for bundle blend pass in d3d12_draw_test #1807 fixes.

For Mac testers: the MoltenVK fast-math row in docs/design.md says MVK_CONFIG_FAST_MATH_ENABLED=2 (on demand) doesn't help, because translated modules don't declare an execution mode that asks for IEEE behaviour. With this PR they declare SignedZeroInfNanPreserve, so =2 may work now. I haven't tested that.

AI-assisted (Claude Code).

@bvtterbroot

Copy link
Copy Markdown

Tested a0e8229's translator on AMD Radeon RX 7900 XTX (RDNA3, Navi 31), AMD driver 26.11.2, Vulkan 1.4.359, Windows 11, with vk_compute_test from main 41f4482: it fixes the #1480 fill-pattern loss on RDNA3 too.

  • valu_fuzz.py --family f16 --wave both --programs 140 --seed 9001
    • main 41f4482: 278/280. cs_f16fuzz_s9001_101_w32: v20 keeps 0xeeeeeeee in all lanes, want 0x7e000000 (f16 NaN, last written by v_add_f16_e64 v20, v29, v29). cs_f16fuzz_s9001_137_w64: v29 keeps 0xeeeeeeee, want 0xa000b367 (v_sub_f16_e64 v29, v24, v34).
    • this PR: 280/280.
  • --wave 64 --emulate, same seed: 140/140.

So the symptom is not only RDNA4: native wave32 and wave64 on gfx1100 show it, and this PR removes it. The rest of a 300-program run on main (f16 598/600, mem 600/600) had no other mismatch.

Tools: llvm-mc 21.1.8 (WSL), Vulkan SDK 1.4.363.0, MSVC 14.44.

@tylerstraub

Copy link
Copy Markdown
Contributor

Tested a0e8229a55196e9143fe6dca7a8b9975c7357745 on NVIDIA GeForce RTX 5090, 595.99.02 (Linux).

Follow-up at a0e8229a55196e9143fe6dca7a8b9975c7357745 on Linux 7.0.0-43-generic, LLVM 21.1.8, and SPIRV-Tools v2026.1. Rebuilt the Vulkan harnesses at this head. AI-assisted, synthetic fixtures only.

  • llvmpipe (LLVM 21.1.8, subgroup 8): cs_signed_zero_nan now passes through the stock runner with only word 5 exempt. Direct dispatch still gives 0 for the 0 * inf NaN check at that index. The other seven words match.
  • RTX 5090 (595.99.02, subgroup 32): all eight words of cs_signed_zero_nan match, including 1 at word 5. ps_vcmpx_forms also matches all 4,096 pixels.

SPIR-V validation and all 67 test_shader_checks.py tests passed. This verifies the device-specific runner behavior on these two Vulkan implementations.

AI-assisted verification.

@alvaro-marquez-cobos

Copy link
Copy Markdown
Contributor

Verified the fix on the original Radeon AI PRO R9700 from #1480, Windows x64, AMD Vulkan 26.11.2 (LLPC), LLVM 23.1.6. Compared main 4eb6155 with PR head a0e8229. Same GPU, harness, generator and seed.

R9700 test main PR PR with --no-float-controls
Reduced three-op case, native wave64 fails passes fails again
Reduced three-op case, emulated wave64 fails passes fails again
Full f16 batch, native 99/100 100/100 not run
Full f16 batch, emulated 99/100 100/100 not run

The negative control changes only the translator flag. It restores the original lane-0 v31 values: 0xeeeeeeee native and zero emulated, with the upper half expected to be 0x3e4e. The integrated Radeon on the same host passes the reduced case on both revisions in both modes.

Full batch: python -I tools/valu_fuzz.py --family f16 --seed 221122 --programs 50, with and without --emulate, pinning LEONIDA_VK_DEVICE=R9700. Only index 23, wave64 failed on main. No skipped programs, translation failures or harness errors in those four batches. The reference model retains the same uncertainty masks on both revisions.

The new cs_signed_zero_nan fixture passes, as do all 67 shader-check unit tests and the 3 targeted translator float-controls tests. Synthetic inputs only. AI-assisted.
Full PR GPU runner on the R9700: 186/186 translated and passed spirv-val, 168 GPU checks passed, 13 skipped, 0 failed.

@ItsNotRexed
ItsNotRexed merged commit ea00498 into ItsNotRexed:main Nov 22, 2026
4 checks passed
Jolymmiles added a commit to Jolymmiles/Leonida that referenced this pull request Nov 22, 2026
… (SHADER-234)

- OpVectorTimesScalar, OpMatrixTimesScalar, OpVectorTimesMatrix,
  OpMatrixTimesVector, OpMatrixTimesMatrix, OpOuterProduct and OpDot fuse
  into an add as OpFMul does: they keep NoContraction when an add or
  subtract uses them. A lane taken with OpCompositeExtract is followed
  like a copy.
- The add or subtract keeps its own NoContraction unless the multiply is a
  decorated OpFMul: MoltenVK 1.4.2's SPIRV-Cross writes only OpFMul as
  spvFMul, and the other multiplies as a plain `*` even when decorated.
- A module is passed through unchanged when its version is not SPIR-V
  1.0 to 1.6, its schema word is not 0, it has no instruction, a result id
  is 0, at or above the bound or defined twice (result positions from the
  SPIR-V 1.6 grammar), an operand of a traced instruction is defined after
  it, an entry point, execution mode or decoration names an id nothing
  defines, or SignedZeroInfNanPreserve has other than one width of 16, 32
  or 64. Operands defined first also mean no chain can loop, so the cycle
  walk is gone and a cyclic module is left as it is.
- vk_compute_test refuses a file of only a header.
- The test runs spirv-val without a shell (fork/execvp, _spawnvp on
  Windows, both searching PATH).
- docs/design.md: the fast-math row gives MoltenVK's default before and
  since 1.4.0 and that translated modules declare SignedZeroInfNanPreserve
  since ItsNotRexed#664.
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.