tests: cs_fma_fused takes its f16 operands at run time, like its f32 ones (TEST-FMA-FUSED-F16-RUNTIME) #1724

Open
github-bot wants to merge 3 commits from github-bot/gh-1724 into main AGit
Owner

@⁠hugo0024 on GitHub · 2026-11-25 09:46 UTC · original
hugo0024:test-fma-fused-f16-runtime → main · +112 −7 · 5 files · 3 commits · open

Claimed in the coordination issue as: TEST-FMA-FUSED-F16-RUNTIME (claim)

Depends on: #860

It does not build on #860; the two conflict. Both edit neighbouring Known problems rows of docs/testing.md, so whichever merges second needs a rebase that keeps both rows.

What and why

cs_fma_fused fails on a Mac with MoltenVK 1.4.2 in word 7, the v_fma_f16: docs/testing.md has a Known problems row for it and the macOS job lists it in EXPECTED_FAILURES. On an Apple M5 the word reads 0x0000, want 0x7351.

The translation is not what is wrong. The fixture reads the operands of its f32 multiply-adds from s4..s7 "so a driver cannot fold the multiply-adds at compile time", but the three operands of the f16 one were literals, so that whole multiply-add was a compile-time constant, and MoltenVK 1.4.2 gets that constant wrong. Measured on the M5 with the fixture otherwise unchanged:

f16 operands taken at run time word 7
none (as on main) 0x0000
the first, the second or the third alone 0x7351
any two 0x7351
all three 0x7351
  • runtime/test/shaders/cs_fma_fused.asm: the f16 triple is the s4 word XOR a literal each (0x3f800800 ^ 0x3f8064e1 = 0x6ce1, and so on), so it is the same triple at run time, and the header says why.
  • tests/semantic/test_fma_fused_fixture.py: the translated fixture gives the eight words of its header in the interpreter, and every register one of its multiply-adds reads comes from s4..s7, so a literal operand cannot come back unnoticed.
  • docs/testing.md: the Known problems row now says what is left, an f16 multiply-add whose three operands are all constants, and that the fixture no longer has one. tests/semantic/README.md lists the new test.

The translator, check.py and run_gpu_tests.py are not changed: the expected words are the same.

.github/workflows/runtime.yml still lists cs_fma_fused in the macOS job's EXPECTED_FAILURES. I left it: that runner's Metal device is not an M5, and an expected failure that passes only gets a notice there. If this pull request's macOS run shows that notice, the entry can go.

Tested

Apple M5, MoltenVK 1.4.2, llvm-mc 23.1.6, SPIRV-Tools v2026.4. Before is main 626d1281a, after is this branch on 3de22a190 (the fixture, the translator and the two runners are the same at both), with the test programs built from 626d1281a.

Before After
run_gpu_tests.py --filter cs_fma_fused, 5 runs 5 fail: word 7 (f16): got 0x00000000, want 0x00007351 5 pass: 8/8 fused exact (GLSL Fma)
the same with LEONIDA_FMA=exact, 5 runs 5 pass 5 pass
the same with LEONIDA_W64_EMULATE=1 fail, the same word pass
build.py <out> cs_fma_fused, then check.py word 7 (f16): got 0x00000000, want 0x00007351 ok
run_gpu_tests.py, all tests 193/263 passed, 68 skipped; failed cs_fma_fused, cs_imgatomic_ext 193/263 passed, 68 skipped; failed cs_imgatomic_ext, ps_imgatomic
  • In the full run the only verdicts that differ are cs_fma_fused (fail to pass) and ps_imgatomic (pass to fail). The second is the intermittent #543, not this change: its module is byte-identical in both runs, and run alone six times it passes five and fails one in each tree. cs_imgatomic_ext is red on main and claimed by someone else (GPU-IMG-ATOMIC-EXT-VOLUME-TAG).
  • The translation step reports 273 shaders: 272 translated, 272 pass spirv-val in both, and 1 of the 275 modules in the work folder changes: cs_fma_fused.
  • That LEONIDA_FMA=exact passed before is the same effect, not a fix: it changes only how the f32 multiply-adds around the f16 one are translated; the f16 one does not use Fma in either mode (Gen.fma_f16_odd).
  • tests/semantic/test_fma_fused_fixture.py: 3 tests pass; against main's fixture the run-time check fails (['v15', 'v16', 'v17'] != []). With one operand word changed by one bit the eight-word check fails, so it does compare.
  • python3 -I scripts/run_semantic_tests.py tests/semantic: 487 files, 6,279 tests, 0 failed before; 488 files, 6,282 tests, 0 failed after.
  • pytest files: 2 failed, 1908 passed, 18 skipped, before and after alike (the two are tests/test_translate.py on cs_dpp_cmp.asm, #1375's subject; cs_fma_fused.asm assembles and validates there as before).
  • Standard-library loop: 498 files, 4 failed, as on main; none is touched here (#1412, #1561 and #1657 are open for them).
  • tests/test_docs_*.py pass; python3 -I scripts/check_no_game_data.py is clean on the new test and the fixture.

Not tested: any GPU other than the M5, and the macOS runner's device. On a driver that evaluated the constant correctly the only change is that the f16 word is computed at run time.

GPUs tested: Apple M5 (8-core GPU), MoltenVK 1.4.2, macOS 27.2.1 (26B131)

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.

🤖 Generated with Claude Code

**@⁠hugo0024** on GitHub · 2026-11-25 09:46 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1724) `hugo0024:test-fma-fused-f16-runtime` → `main` · +112 −7 · 5 files · 3 commits · open Claimed in the coordination issue as: TEST-FMA-FUSED-F16-RUNTIME ([claim](https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608)) Depends on: #860 It does not build on #860; the two conflict. Both edit neighbouring Known problems rows of `docs/testing.md`, so whichever merges second needs a rebase that keeps both rows. ### What and why `cs_fma_fused` fails on a Mac with MoltenVK 1.4.2 in word 7, the `v_fma_f16`: `docs/testing.md` has a Known problems row for it and the macOS job lists it in `EXPECTED_FAILURES`. On an Apple M5 the word reads `0x0000`, want `0x7351`. The translation is not what is wrong. The fixture reads the operands of its f32 multiply-adds from `s4..s7` "so a driver cannot fold the multiply-adds at compile time", but the three operands of the f16 one were literals, so that whole multiply-add was a compile-time constant, and MoltenVK 1.4.2 gets that constant wrong. Measured on the M5 with the fixture otherwise unchanged: | f16 operands taken at run time | word 7 | |---|---| | none (as on `main`) | `0x0000` | | the first, the second or the third alone | `0x7351` | | any two | `0x7351` | | all three | `0x7351` | - `runtime/test/shaders/cs_fma_fused.asm`: the f16 triple is the `s4` word XOR a literal each (`0x3f800800 ^ 0x3f8064e1 = 0x6ce1`, and so on), so it is the same triple at run time, and the header says why. - `tests/semantic/test_fma_fused_fixture.py`: the translated fixture gives the eight words of its header in the interpreter, and every register one of its multiply-adds reads comes from `s4..s7`, so a literal operand cannot come back unnoticed. - `docs/testing.md`: the Known problems row now says what is left, an f16 multiply-add whose three operands are all constants, and that the fixture no longer has one. `tests/semantic/README.md` lists the new test. The translator, `check.py` and `run_gpu_tests.py` are not changed: the expected words are the same. `.github/workflows/runtime.yml` still lists `cs_fma_fused` in the macOS job's `EXPECTED_FAILURES`. I left it: that runner's Metal device is not an M5, and an expected failure that passes only gets a notice there. If this pull request's macOS run shows that notice, the entry can go. ### Tested Apple M5, MoltenVK 1.4.2, llvm-mc 23.1.6, SPIRV-Tools v2026.4. Before is `main` `626d1281a`, after is this branch on `3de22a190` (the fixture, the translator and the two runners are the same at both), with the test programs built from `626d1281a`. | | Before | After | |---|---|---| | `run_gpu_tests.py --filter cs_fma_fused`, 5 runs | 5 fail: `word 7 (f16): got 0x00000000, want 0x00007351` | 5 pass: `8/8 fused exact (GLSL Fma)` | | the same with `LEONIDA_FMA=exact`, 5 runs | 5 pass | 5 pass | | the same with `LEONIDA_W64_EMULATE=1` | fail, the same word | pass | | `build.py <out> cs_fma_fused`, then `check.py` | `word 7 (f16): got 0x00000000, want 0x00007351` | `ok` | | `run_gpu_tests.py`, all tests | 193/263 passed, 68 skipped; failed `cs_fma_fused`, `cs_imgatomic_ext` | 193/263 passed, 68 skipped; failed `cs_imgatomic_ext`, `ps_imgatomic` | - In the full run the only verdicts that differ are `cs_fma_fused` (fail to pass) and `ps_imgatomic` (pass to fail). The second is the intermittent #543, not this change: its module is byte-identical in both runs, and run alone six times it passes five and fails one in each tree. `cs_imgatomic_ext` is red on `main` and claimed by someone else (GPU-IMG-ATOMIC-EXT-VOLUME-TAG). - The translation step reports `273 shaders: 272 translated, 272 pass spirv-val` in both, and 1 of the 275 modules in the work folder changes: `cs_fma_fused`. - That `LEONIDA_FMA=exact` passed before is the same effect, not a fix: it changes only how the f32 multiply-adds around the f16 one are translated; the f16 one does not use `Fma` in either mode (`Gen.fma_f16_odd`). - `tests/semantic/test_fma_fused_fixture.py`: 3 tests pass; against `main`'s fixture the run-time check fails (`['v15', 'v16', 'v17'] != []`). With one operand word changed by one bit the eight-word check fails, so it does compare. - `python3 -I scripts/run_semantic_tests.py tests/semantic`: 487 files, 6,279 tests, 0 failed before; 488 files, 6,282 tests, 0 failed after. - pytest files: 2 failed, 1908 passed, 18 skipped, before and after alike (the two are `tests/test_translate.py` on `cs_dpp_cmp.asm`, #1375's subject; `cs_fma_fused.asm` assembles and validates there as before). - Standard-library loop: 498 files, 4 failed, as on `main`; none is touched here (#1412, #1561 and #1657 are open for them). - `tests/test_docs_*.py` pass; `python3 -I scripts/check_no_game_data.py` is clean on the new test and the fixture. Not tested: any GPU other than the M5, and the macOS runner's device. On a driver that evaluated the constant correctly the only change is that the f16 word is computed at run time. GPUs tested: Apple M5 (8-core GPU), MoltenVK 1.4.2, macOS 27.2.1 (26B131) 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. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The fixture reads the operands of its f32 multiply-adds from s4..s7 so that a driver has to
compute them at run time. The three operands of its v_fma_f16 were literals, which made the
whole f16 multiply-add a compile-time constant. MoltenVK 1.4.2 gives the wrong constant: word
7 read 0x0000 on an Apple M5 (0x3c00 in the docs' row) where 0x7351 is expected, the
cs_fma_fused failure listed in docs/testing.md and in the macOS job's EXPECTED_FAILURES. The
same translation with any one of the three operands taken at run time gives 0x7351.

The triple is now the s4 word XOR a literal each, so the test checks the translator's
round-to-odd sequence as the GPU runs it. The translator is not changed.

tests/semantic/test_fma_fused_fixture.py runs the fixture in the interpreter against the eight
words of its header and checks that no multiply-add in it reads a register only literals fed.
The Known problems row says what is left: an f16 multiply-add with only constant operands.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Tauwni measured it in the review of #1724 (Apple M3, Mesa 26.3.1, 20 of 20 runs): with
run-time operands the f16 multiply-add comes out as if the product were rounded first, one
step from 0x7351. With literal operands the constant was folded exactly, so the fixture
passed there before. MoltenVK 1.4.2 and llvmpipe give 0x7351 on the same machine.

A Known problems row and a line in the fixture's header; no instruction changes.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
With its f16 operands taken at run time the test passes on the macos-26
runner (Apple Paravirtual device, MoltenVK 1.4.2): the job's last run on
this branch printed "cs_fma_fused passed: drop it from the expected
failures". The Known problems row says where it passes now.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:02:37 +00:00
Author
Owner

@⁠Tauwni on GitHub · 2026-11-25 10:16 UTC · original

Tested on an Apple M3 (macOS 26.5.1), this branch at aebef89d1, test programs built from main 626d1281a:

Driver main this PR
MoltenVK 1.4.2 FAIL, word 7 0x00000000 (20/20) PASS 20/20, "8/8 fused exact"
KosmicKrisp (Mesa 26.3.1) PASS ("1/7 f32 fused, 6/7 split ... f16 exact") FAIL 20/20: word 7 (f16) 0x00007352, want 0x00007351
llvmpipe (Mesa 26.3.1) PASS PASS

So the fix works for MoltenVK, but on KosmicKrisp the f16 multiply-add was only exact while it was a compile-time constant: computed at run time it reads one ulp off, which looks like KosmicKrisp splitting the f16 Fma as it splits six of the seven f32 ones (those the check accepts as split). The macOS job runs MoltenVK only, so CI would not show it. AI-assisted (Claude Code).

**@⁠Tauwni** on GitHub · 2026-11-25 10:16 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1724#issuecomment-7159471153) Tested on an Apple M3 (macOS 26.5.1), this branch at `aebef89d1`, test programs built from `main` `626d1281a`: | Driver | `main` | this PR | |---|---|---| | MoltenVK 1.4.2 | FAIL, word 7 `0x00000000` (20/20) | **PASS** 20/20, "8/8 fused exact" | | KosmicKrisp (Mesa 26.3.1) | PASS ("1/7 f32 fused, 6/7 split ... f16 exact") | **FAIL** 20/20: word 7 (f16) `0x00007352`, want `0x00007351` | | llvmpipe (Mesa 26.3.1) | PASS | PASS | So the fix works for MoltenVK, but on KosmicKrisp the f16 multiply-add was only exact while it was a compile-time constant: computed at run time it reads one ulp off, which looks like KosmicKrisp splitting the f16 `Fma` as it splits six of the seven f32 ones (those the check accepts as split). The macOS job runs MoltenVK only, so CI would not show it. AI-assisted (Claude Code).
Author
Owner

@⁠potatoe0100 on GitHub · 2026-11-25 10:29 UTC · original

Tested aebef89d1 merged onto main 57ba40bd6 (clean), native Windows 11 Pro 26H2 (build 26300), NVIDIA GeForce RTX 4060, driver 621.14, VS 2022 RelWithDebInfo + Ninja, llvm-mc 21.1.8.

run_gpu_tests.py --filter cs_fma_fused:

main this PR
default PASS 8/8 fused exact (GLSL Fma) PASS, same
LEONIDA_FMA=exact PASS 8/8 fused exact (single-rounded FMA: OpFmaKHR or --fma exact)
LEONIDA_W64_EMULATE=1 PASS
LEONIDA_VK_VALIDATION=1 + GPU-AV PASS, 0 VUIDs

So NVIDIA never hit the word 7 zero that MoltenVK did, and the run-time f16 operands don't change anything here. python -I tests/semantic/test_fma_fused_fixture.py: 3 tests OK.

AI-assisted testing (non-developer tester).

**@⁠potatoe0100** on GitHub · 2026-11-25 10:29 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1724#issuecomment-7159765430) Tested `aebef89d1` merged onto `main` `57ba40bd6` (clean), native Windows 11 Pro 26H2 (build 26300), NVIDIA GeForce RTX 4060, driver 621.14, VS 2022 RelWithDebInfo + Ninja, llvm-mc 21.1.8. `run_gpu_tests.py --filter cs_fma_fused`: | | `main` | this PR | |---|---|---| | default | PASS `8/8 fused exact (GLSL Fma)` | PASS, same | | `LEONIDA_FMA=exact` | | PASS `8/8 fused exact (single-rounded FMA: OpFmaKHR or --fma exact)` | | `LEONIDA_W64_EMULATE=1` | | PASS | | `LEONIDA_VK_VALIDATION=1` + GPU-AV | | PASS, 0 VUIDs | So NVIDIA never hit the word 7 zero that MoltenVK did, and the run-time f16 operands don't change anything here. `python -I tests/semantic/test_fma_fused_fixture.py`: 3 tests OK. AI-assisted testing (non-developer tester).
Author
Owner

@⁠lixonik on GitHub · 2026-11-25 10:34 UTC · original · reviewed

Independent CPU check at aebef89d: the three fixture tests passed. With the same test file copied to the merge base 3de22a19, only the runtime-operand check failed, on the original three literal-fed registers.

The f16 operands also let us quantify the one-ULP result Tauwni reported on KosmicKrisp. The exact product is 14988, halfway between binary16 values 14984 (0x7351) and 14992 (0x7352). The addend is -2^-22. A single rounding gives 0x7351; rounding the product first to nearest-even gives 0x7352, and rounding the following sum keeps it there. That matches the reported value under separate rounding.

AI-assisted, CPU-only verification. No independent driver trace or Mac run.

**@⁠lixonik** on GitHub · 2026-11-25 10:34 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1724#pullrequestreview-6055948464) · **reviewed** Independent CPU check at `aebef89d`: the three fixture tests passed. With the same test file copied to the merge base `3de22a19`, only the runtime-operand check failed, on the original three literal-fed registers. The f16 operands also let us quantify the one-ULP result Tauwni reported on KosmicKrisp. The exact product is 14988, halfway between binary16 values 14984 (`0x7351`) and 14992 (`0x7352`). The addend is -2^-22. A single rounding gives `0x7351`; rounding the product first to nearest-even gives `0x7352`, and rounding the following sum keeps it there. That matches the reported value under separate rounding. AI-assisted, CPU-only verification. No independent driver trace or Mac run.
Author
Owner

@⁠abnalstlll-byte on GitHub · 2026-11-25 10:54 UTC · original · approved these changes

### Clean-Room & Technical Verification

  • Mergeability: 3-way merge against upstream main (bcaa13dad) is 100% clean with zero merge conflicts.
  • Clean-Room Compliance: 100% clean-room. Hand-written assembly fixture adjustments only; zero retail code, game data, or keys (check_no_game_data.py clean).
  • Technical Rigor & Hardware Reality:
    • In runtime/test/shaders/cs_fma_fused.asm, replaces hardcoded literals for the v_fma_f16 test case with dynamic run-time registers derived from s4 XOR literals.
    • Fixes MoltenVK 1.4.2 compile-time constant folding bugs on macOS/Metal (Apple Silicon M5/M5 Pro) where compile-time f16 evaluations produced erroneous 0x0000 / 0x3c00 instead of the expected 0x7351 round-to-odd result.
    • Adds regression test tests/semantic/test_fma_fused_fixture.py validating that every multiply-add in the fixture consumes run-time registers rather than folding literals, while verifying correct word generation in spirv_mini_interp.
    • Accurately updates documentation in docs/testing.md.

LGTM! Approved.

**@⁠abnalstlll-byte** on GitHub · 2026-11-25 10:54 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1724#pullrequestreview-6056248923) · **approved these changes** ### Clean-Room & Technical Verification - **Mergeability**: 3-way merge against upstream `main` (`bcaa13dad`) is 100% clean with zero merge conflicts. - **Clean-Room Compliance**: 100% clean-room. Hand-written assembly fixture adjustments only; zero retail code, game data, or keys (`check_no_game_data.py` clean). - **Technical Rigor & Hardware Reality**: - In `runtime/test/shaders/cs_fma_fused.asm`, replaces hardcoded literals for the `v_fma_f16` test case with dynamic run-time registers derived from `s4` XOR literals. - Fixes MoltenVK 1.4.2 compile-time constant folding bugs on macOS/Metal (Apple Silicon M5/M5 Pro) where compile-time f16 evaluations produced erroneous `0x0000` / `0x3c00` instead of the expected `0x7351` round-to-odd result. - Adds regression test `tests/semantic/test_fma_fused_fixture.py` validating that every multiply-add in the fixture consumes run-time registers rather than folding literals, while verifying correct word generation in `spirv_mini_interp`. - Accurately updates documentation in `docs/testing.md`. LGTM! Approved.
Author
Owner

@⁠hugo0024 on GitHub · 2026-11-25 11:25 UTC · original

@⁠Tauwni thank you for the three-driver run. I have no KosmicKrisp here, so yours is the only measurement of it, and @⁠lixonik's arithmetic matches the fixture's header, which gives 0x7352 as the f32-then-f16 value. So on KosmicKrisp the round-to-odd result is lost when the multiply-add is computed on the GPU, and the literal form passed there because the constant was folded exactly.

I kept the run-time operands. With literals the word checks a compiler's constant folder on either driver, and the one-step difference on KosmicKrisp holds for any run-time v_fma_f16, which the fixture did not show before. 0003d3de7 adds a Known problems row for it with your numbers (Apple M3, Mesa 26.3.1, 20 of 20) and a line in the fixture's header; no instruction changes.

Thanks also to @⁠potatoe0100 for the RTX 4060 run. AI-assisted.

**@⁠hugo0024** on GitHub · 2026-11-25 11:25 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1724#issuecomment-7161021059) @⁠Tauwni thank you for the three-driver run. I have no KosmicKrisp here, so yours is the only measurement of it, and @⁠lixonik's arithmetic matches the fixture's header, which gives `0x7352` as the f32-then-f16 value. So on KosmicKrisp the round-to-odd result is lost when the multiply-add is computed on the GPU, and the literal form passed there because the constant was folded exactly. I kept the run-time operands. With literals the word checks a compiler's constant folder on either driver, and the one-step difference on KosmicKrisp holds for any run-time `v_fma_f16`, which the fixture did not show before. `0003d3de7` adds a Known problems row for it with your numbers (Apple M3, Mesa 26.3.1, 20 of 20) and a line in the fixture's header; no instruction changes. Thanks also to @⁠potatoe0100 for the RTX 4060 run. AI-assisted.
Author
Owner

@⁠adrianmjim on GitHub · 2026-11-25 12:00 UTC · original

Tested this PR's diff at 0003d3de7, applied onto main 42537e7b6, on AMD: Radeon RX 7900 XT (RDNA3), driver 32.0.32029.2010 (26.11.2), Windows 11 build 26300, Vulkan SDK 1.4.363.0, llvm-mc 23.1.5, test programs from a main 42537e7b6 build. This is the first AMD run of this branch. With the f16 operands at run time, the driver can no longer fold them at compile time, so word 7 now checks the fma_f16_odd sequence as the GPU runs it, not a value the compiler may have folded. No game files.

--filter cs_fma_fused result
default (GLSL Fma), 5 runs PASS 5/5, 8/8 fused exact (GLSL Fma)
LEONIDA_FMA=exact, 5 runs PASS 5/5, 8/8 fused exact (single-rounded FMA: OpFmaKHR or --fma exact)
LEONIDA_FMA=khr, 5 runs PASS 5/5, the same
LEONIDA_W64_EMULATE=1 PASS, 8/8 fused exact (GLSL Fma)
main's fixture, for comparison PASS, 8/8 fused exact (GLSL Fma)

So on AMD the run-time round-to-odd sequence gives 0x7351 (KosmicKrisp gave 0x7352), and the seven f32 words come out fused in all three modes. Word 7 is the same SPIR-V in every mode, so the repeat runs only confirm the same result.

**@⁠adrianmjim** on GitHub · 2026-11-25 12:00 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1724#issuecomment-7161801833) Tested this PR's diff at `0003d3de7`, applied onto `main` `42537e7b6`, on AMD: Radeon RX 7900 XT (RDNA3), driver 32.0.32029.2010 (26.11.2), Windows 11 build 26300, Vulkan SDK 1.4.363.0, llvm-mc 23.1.5, test programs from a `main` `42537e7b6` build. This is the first AMD run of this branch. With the f16 operands at run time, the driver can no longer fold them at compile time, so word 7 now checks the `fma_f16_odd` sequence as the GPU runs it, not a value the compiler may have folded. No game files. | `--filter cs_fma_fused` | result | |---|---| | default (GLSL `Fma`), 5 runs | PASS 5/5, `8/8 fused exact (GLSL Fma)` | | `LEONIDA_FMA=exact`, 5 runs | PASS 5/5, `8/8 fused exact (single-rounded FMA: OpFmaKHR or --fma exact)` | | `LEONIDA_FMA=khr`, 5 runs | PASS 5/5, the same | | `LEONIDA_W64_EMULATE=1` | PASS, `8/8 fused exact (GLSL Fma)` | | `main`'s fixture, for comparison | PASS, `8/8 fused exact (GLSL Fma)` | So on AMD the run-time round-to-odd sequence gives `0x7351` (KosmicKrisp gave `0x7352`), and the seven f32 words come out fused in all three modes. Word 7 is the same SPIR-V in every mode, so the repeat runs only confirm the same result.
Author
Owner

@⁠EvgHaze on GitHub · 2026-11-25 12:48 UTC · original

Apple check — and this one changes a result on KosmicKrisp, so it may need a decision.

Machine:  Apple M3, 10-core (MacBook Air 13", Mac15,13), macOS 27.0 (26A5406e), arm64
Drivers:  MoltenVK 1.4.2 (Homebrew), ICD loaded directly, driver id 14, core count 10
          KosmicKrisp, Mesa 26.3.1 (Homebrew), through the Vulkan loader, driver id 28
Base:     main `0d80bc5`, this diff applied cleanly

2x2: fixture × driver

main fixture this PR
MoltenVK 1.4.2 FAIL word 7 (f16): got 0x00000000, want 0x00007351 PASS 8/8 fused exact (GLSL Fma)
KosmicKrisp 26.3.1 PASS f16 exact FAIL word 7 (f16): got 0x00007352, want 0x00007351

So on this machine the change does exactly what it says for MoltenVK — the old fixture's constant-folded operand gave 0x00000000 there, and with runtime operands MoltenVK is exact. But the same runtime operand makes KosmicKrisp return 0x7352 where the fixture now wants 0x7351, one ULP off, while the old constant-folded fixture passed on KosmicKrisp.

Two readings, and I cannot tell them apart from a Mac:

  1. KosmicKrisp's own rounding on this f16 FMA differs by one ULP from MoltenVK's, and the new fixture is correct — then this needs a docs/testing.md Known-problems row for KosmicKrisp (like the other rows), not a weaker expectation;
  2. the expected word is right only for the path MoltenVK takes, and worth checking on an AMD card before the fixture is taken as the reference.

What is certain: merging this as-is turns a passing KosmicKrisp run red on an Apple M3, so it should not land without either a known-problems row or a word verified on hardware.

I can run the same 2x2 on a second Mac configuration if that helps narrow it (another M-series machine, or KosmicKrisp built from a newer Mesa).

AI-assisted. No game data: the fixture is hand-written and every number above is test output.

**@⁠EvgHaze** on GitHub · 2026-11-25 12:48 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1724#issuecomment-7162894586) Apple check — and this one changes a result on KosmicKrisp, so it may need a decision. ```text Machine: Apple M3, 10-core (MacBook Air 13", Mac15,13), macOS 27.0 (26A5406e), arm64 Drivers: MoltenVK 1.4.2 (Homebrew), ICD loaded directly, driver id 14, core count 10 KosmicKrisp, Mesa 26.3.1 (Homebrew), through the Vulkan loader, driver id 28 Base: main `0d80bc5`, this diff applied cleanly ``` **2x2: fixture × driver** | | `main` fixture | this PR | |---|---|---| | **MoltenVK 1.4.2** | **FAIL** `word 7 (f16): got 0x00000000, want 0x00007351` | **PASS** `8/8 fused exact (GLSL Fma)` | | **KosmicKrisp 26.3.1** | **PASS** `f16 exact` | **FAIL** `word 7 (f16): got 0x00007352, want 0x00007351` | So on this machine the change does exactly what it says for MoltenVK — the old fixture's constant-folded operand gave `0x00000000` there, and with runtime operands MoltenVK is exact. But the same runtime operand makes KosmicKrisp return **`0x7352` where the fixture now wants `0x7351`**, one ULP off, while the old constant-folded fixture passed on KosmicKrisp. Two readings, and I cannot tell them apart from a Mac: 1. KosmicKrisp's own rounding on this f16 FMA differs by one ULP from MoltenVK's, and the new fixture is correct — then this needs a `docs/testing.md` Known-problems row for KosmicKrisp (like the other rows), not a weaker expectation; 2. the expected word is right only for the path MoltenVK takes, and worth checking on an AMD card before the fixture is taken as the reference. What is certain: merging this as-is turns a passing KosmicKrisp run red on an Apple M3, so it should not land without either a known-problems row or a word verified on hardware. I can run the same 2x2 on a second Mac configuration if that helps narrow it (another M-series machine, or KosmicKrisp built from a newer Mesa). AI-assisted. No game data: the fixture is hand-written and every number above is test output.
Author
Owner

@⁠EvgHaze on GitHub · 2026-11-25 13:19 UTC · original

Correction to my comment above: the head 0003d3de already carries the KosmicKrisp row in docs/testing.md ("cs_fma_fused fails on a Mac with KosmicKrisp: word 7 reads 0x7352, want 0x7351"), and its arithmetic matches what I measured exactly — 0x7352 on an Apple M3 with Mesa 26.3.1, and the rule is that the f16 form does not go through Fma, so --fma glsl does not cover it. So the "needs a known-problems row" half of my earlier comment is answered.

The part that is still open is the runner, not the docs: scripts/run_gpu_tests.py --filter cs_fma_fused with this diff on KosmicKrisp reports

FAIL  cs_fma_fused   word 7 (f16): got 0x00007352, want 0x00007351
0/1 passed

and there is no per-driver allowance in the diff (the four changed files are docs/testing.md, the fixture, the semantic README and the semantic test). On main that test passes on KosmicKrisp because the literals fold exactly, so after this lands an Apple contributor running the GPU suite on KosmicKrisp sees one red test that the docs say is expected.

Is that intended (KK red, documented, no allowance), or should the runner accept the measured KK word the way ps_nan_payload accepts the canonical NaN only for KosmicKrisp? Either way works for me; I only want the expectation stated so the next Apple run is not read as a regression. I can make the runner change and test it on both drivers if you want it.

AI-assisted.

**@⁠EvgHaze** on GitHub · 2026-11-25 13:19 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1724#issuecomment-7163603001) Correction to my comment above: the head `0003d3de` already carries the KosmicKrisp row in `docs/testing.md` ("`cs_fma_fused` fails on a Mac with KosmicKrisp: word 7 reads `0x7352`, want `0x7351`"), and its arithmetic matches what I measured exactly — `0x7352` on an Apple M3 with Mesa 26.3.1, and the rule is that the f16 form does not go through `Fma`, so `--fma glsl` does not cover it. So the "needs a known-problems row" half of my earlier comment is answered. The part that is still open is the runner, not the docs: `scripts/run_gpu_tests.py --filter cs_fma_fused` with this diff on KosmicKrisp reports ```text FAIL cs_fma_fused word 7 (f16): got 0x00007352, want 0x00007351 0/1 passed ``` and there is no per-driver allowance in the diff (the four changed files are `docs/testing.md`, the fixture, the semantic README and the semantic test). On `main` that test passes on KosmicKrisp because the literals fold exactly, so after this lands an Apple contributor running the GPU suite on KosmicKrisp sees one red test that the docs say is expected. Is that intended (KK red, documented, no allowance), or should the runner accept the measured KK word the way `ps_nan_payload` accepts the canonical NaN only for KosmicKrisp? Either way works for me; I only want the expectation stated so the next Apple run is not read as a regression. I can make the runner change and test it on both drivers if you want it. AI-assisted.
Author
Owner

@⁠Tauwni on GitHub · 2026-11-26 06:22 UTC · original

Following up on the KosmicKrisp word 7 (0x7352, want 0x7351): I narrowed it down, and the cause is in the driver's optimiser, not in fma_f16_odd.

Apple M3, macOS 26.5.1. KosmicKrisp and llvmpipe are Mesa 26.3.1 through the loader, MoltenVK is 1.4.2. Scratch fixtures took their operands from s4 = 0x3f800800 through XOR, as #1724 does. They were translated by main a73a57e13 and run with vk_compute_test.

  1. The f16 denormal survives. v_cvt_f32_f16 of 0x8004 gives 0xb4800000 on all three drivers, and so does v_add_f16 of it with itself (0x8008). So this is not a denormal flush.
  2. TwoSum is exact when every step is stored. I rebuilt fma_f16_odd from plain VALU ops (v_mul_f32 p = x·y, v_add_f32 s = p+z, then the four v_sub_f32 and the final v_add_f32), each one a NoContraction op in the SPIR-V. I stored every intermediate. All three drivers give the same words: p = s = 0x466a3000, bb = 0, sb = s, da = 0, db = err = 0xb4800000.
  3. With only err stored, KosmicKrisp returns 0x00000000. It is the same seven ops, still all decorated NoContraction. MoltenVK and llvmpipe return 0xb4800000.

So once the intermediates are dead, KosmicKrisp folds the TwoSum algebraically: (p + z) - p → z, then err → 0. The NoContraction decoration should forbid that, like NIR's exact. With err = 0, fma_f16_odd never makes the f32 sum odd, and the f16 rounding becomes the f32-then-f16 value 0x7352, which is the word measured. Words 0 to 6 are not affected, because they use Fma and not this sequence.

So this supports reading 1 in @⁠EvgHaze's comment: the fixture's 0x7351 is right (AMD gives it too, from @⁠adrianmjim's run), and the KosmicKrisp known-problems row describes a driver bug. That bug probably also affects every other NoContraction error-term sequence on KosmicKrisp (fma_mix_odd, --fma exact), but I have only measured this one.

The err-only probe, for anyone who wants to report it to Mesa:

; group: 1,1,1
; rsrc2: 0x8090
v_mov_b32_e32 v0, s4                 ; VKC_SGPRS=0x3f800800
v_mov_b32_e32 v20, 0
v_xor_b32_e32 v1, 0x3f808804, v0     ; z = 0x8004
v_cvt_f32_f16_e32 v1, v1
v_xor_b32_e32 v3, 0x3f8064e1, v0     ; x = 0x6ce1
v_cvt_f32_f16_e32 v3, v3
v_xor_b32_e32 v4, 0x3f804a00, v0     ; y = 0x4200
v_cvt_f32_f16_e32 v4, v4
v_mul_f32_e32 v5, v3, v4             ; p
v_add_f32_e32 v6, v5, v1             ; s
v_sub_f32_e32 v7, v6, v5             ; bb
v_sub_f32_e32 v8, v6, v7             ; sb
v_sub_f32_e32 v9, v5, v8             ; da
v_sub_f32_e32 v10, v1, v7            ; db
v_add_f32_e32 v11, v9, v10           ; err: 0xb4800000, KosmicKrisp 0x00000000
buffer_store_dword v11, v20, s[0:3], 0 offen
s_endpgm

No change to this PR from me. This is only meant to settle which word is the reference.

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

**@⁠Tauwni** on GitHub · 2026-11-26 06:22 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1724#issuecomment-7184369060) Following up on the KosmicKrisp word 7 (`0x7352`, want `0x7351`): I narrowed it down, and the cause is in the driver's optimiser, not in `fma_f16_odd`. Apple M3, macOS 26.5.1. KosmicKrisp and llvmpipe are Mesa 26.3.1 through the loader, MoltenVK is 1.4.2. Scratch fixtures took their operands from `s4 = 0x3f800800` through XOR, as #1724 does. They were translated by `main` `a73a57e13` and run with `vk_compute_test`. 1. **The f16 denormal survives.** `v_cvt_f32_f16` of `0x8004` gives `0xb4800000` on all three drivers, and so does `v_add_f16` of it with itself (`0x8008`). So this is not a denormal flush. 2. **TwoSum is exact when every step is stored.** I rebuilt `fma_f16_odd` from plain VALU ops (`v_mul_f32` p = x·y, `v_add_f32` s = p+z, then the four `v_sub_f32` and the final `v_add_f32`), each one a `NoContraction` op in the SPIR-V. I stored every intermediate. All three drivers give the same words: p = s = `0x466a3000`, bb = 0, sb = s, da = 0, db = err = `0xb4800000`. 3. **With only `err` stored, KosmicKrisp returns `0x00000000`.** It is the same seven ops, still all decorated `NoContraction`. MoltenVK and llvmpipe return `0xb4800000`. So once the intermediates are dead, KosmicKrisp folds the TwoSum algebraically: `(p + z) - p` → `z`, then `err` → 0. The `NoContraction` decoration should forbid that, like NIR's `exact`. With `err` = 0, `fma_f16_odd` never makes the f32 sum odd, and the f16 rounding becomes the f32-then-f16 value `0x7352`, which is the word measured. Words 0 to 6 are not affected, because they use `Fma` and not this sequence. So this supports reading 1 in @⁠EvgHaze's comment: the fixture's `0x7351` is right (AMD gives it too, from @⁠adrianmjim's run), and the KosmicKrisp known-problems row describes a driver bug. That bug probably also affects every other `NoContraction` error-term sequence on KosmicKrisp (`fma_mix_odd`, `--fma exact`), but I have only measured this one. The `err`-only probe, for anyone who wants to report it to Mesa: ```asm ; group: 1,1,1 ; rsrc2: 0x8090 v_mov_b32_e32 v0, s4 ; VKC_SGPRS=0x3f800800 v_mov_b32_e32 v20, 0 v_xor_b32_e32 v1, 0x3f808804, v0 ; z = 0x8004 v_cvt_f32_f16_e32 v1, v1 v_xor_b32_e32 v3, 0x3f8064e1, v0 ; x = 0x6ce1 v_cvt_f32_f16_e32 v3, v3 v_xor_b32_e32 v4, 0x3f804a00, v0 ; y = 0x4200 v_cvt_f32_f16_e32 v4, v4 v_mul_f32_e32 v5, v3, v4 ; p v_add_f32_e32 v6, v5, v1 ; s v_sub_f32_e32 v7, v6, v5 ; bb v_sub_f32_e32 v8, v6, v7 ; sb v_sub_f32_e32 v9, v5, v8 ; da v_sub_f32_e32 v10, v1, v7 ; db v_add_f32_e32 v11, v9, v10 ; err: 0xb4800000, KosmicKrisp 0x00000000 buffer_store_dword v11, v20, s[0:3], 0 offen s_endpgm ``` No change to this PR from me. This is only meant to settle which word is the reference. AI-assisted (Claude Code). No game data.
Author
Owner

@⁠hugo0024 on GitHub · 2026-11-26 07:37 UTC · original

@⁠EvgHaze thanks for the 2x2 on both drivers and for the correction, and @⁠Tauwni for narrowing it down.

Intended: red on KosmicKrisp, documented, no allowance. That is how the cs_bvh / cs_bvh32 row for KosmicKrisp just above the new one is handled, and it says not to weaken the expected words. 0x7352 is the word the fixture's header gives for rounding to f32 and then to f16, the result word 7 exists to tell apart from the single rounding, and judge_fma_fused says the f16 word "must always be exact". A checker that accepted 0x7352 on KosmicKrisp would stop testing the f16 form there. ps_nan_payload's allowance covers which NaN payload reads back; here the two words are different numbers.

Tauwni's probe puts the cause in the driver: stored step by step the NoContraction TwoSum is exact, and with only err stored KosmicKrisp returns 0. So what would turn the test green is a fix in Mesa, and that probe is ready to go into a report there. I have no KosmicKrisp here and have measured none of this.

Rebased onto main a73a57e13; the conflict was the neighbouring Known problems row #860 added, and both rows are kept. The macOS job of the previous run printed cs_fma_fused passed: drop it from the expected failures, so the runner's MoltenVK agrees with the M5, and 51439f9db takes it out of the macOS job's EXPECTED_FAILURES.

@⁠adrianmjim thanks for the RX 7900 XT run. AI-assisted.

**@⁠hugo0024** on GitHub · 2026-11-26 07:37 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1724#issuecomment-7185654510) @⁠EvgHaze thanks for the 2x2 on both drivers and for the correction, and @⁠Tauwni for narrowing it down. Intended: red on KosmicKrisp, documented, no allowance. That is how the `cs_bvh` / `cs_bvh32` row for KosmicKrisp just above the new one is handled, and it says not to weaken the expected words. `0x7352` is the word the fixture's header gives for rounding to f32 and then to f16, the result word 7 exists to tell apart from the single rounding, and `judge_fma_fused` says the f16 word "must always be exact". A checker that accepted `0x7352` on KosmicKrisp would stop testing the f16 form there. `ps_nan_payload`'s allowance covers which NaN payload reads back; here the two words are different numbers. Tauwni's probe puts the cause in the driver: stored step by step the `NoContraction` TwoSum is exact, and with only `err` stored KosmicKrisp returns 0. So what would turn the test green is a fix in Mesa, and that probe is ready to go into a report there. I have no KosmicKrisp here and have measured none of this. Rebased onto `main` `a73a57e13`; the conflict was the neighbouring Known problems row #860 added, and both rows are kept. The macOS job of the previous run printed `cs_fma_fused passed: drop it from the expected failures`, so the runner's MoltenVK agrees with the M5, and `51439f9db` takes it out of the macOS job's `EXPECTED_FAILURES`. @⁠adrianmjim thanks for the RX 7900 XT run. AI-assisted.
Author
Owner

@⁠Tauwni on GitHub · 2026-11-26 07:44 UTC · original

A correction to my comment above about where the fold happens. It is not in NIR. MESA_KK_DEBUG=msl shows that all seven TwoSum ops reach the Metal source, each one wrapped in #pragma METAL fp math_mode(safe). KosmicKrisp then compiles the library with MTL_MATH_MODE_FAST.

I rebuilt the same kernel in a standalone Metal program (macOS 26.5.1, M3), and Apple's compiler ignores that pragma in a fast or relaxed library: the error term comes out 0, whether the pragma is at block, function or file scope. In a safe library it gives 0xb4800000. The other way round does work: a fast pragma inside a safe library folds it. So this is a KosmicKrisp issue for Mesa (compile safe and relax per op), and the reading above stands: 0x7351 is the reference word.

AI-assisted (Claude Code).

**@⁠Tauwni** on GitHub · 2026-11-26 07:44 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1724#issuecomment-7185788710) A correction to my comment above about where the fold happens. It is not in NIR. `MESA_KK_DEBUG=msl` shows that all seven TwoSum ops reach the Metal source, each one wrapped in `#pragma METAL fp math_mode(safe)`. KosmicKrisp then compiles the library with `MTL_MATH_MODE_FAST`. I rebuilt the same kernel in a standalone Metal program (macOS 26.5.1, M3), and Apple's compiler ignores that pragma in a `fast` or `relaxed` library: the error term comes out 0, whether the pragma is at block, function or file scope. In a `safe` library it gives `0xb4800000`. The other way round does work: a `fast` pragma inside a `safe` library folds it. So this is a KosmicKrisp issue for Mesa (compile `safe` and relax per op), and the reading above stands: `0x7351` is the reference word. AI-assisted (Claude Code).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1724/head:github-bot/gh-1724'
git switch 'github-bot/gh-1724'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1724'
git switch 'github-bot/gh-1724'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1724'
git switch 'github-bot/gh-1724'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1724'
git switch 'main'
git merge --squash 'github-bot/gh-1724'
git switch 'main'
git merge --ff-only 'github-bot/gh-1724'
git switch 'main'
git merge 'github-bot/gh-1724'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.