rdna2spirv: take a v_fma_mix literal from the printed encoding when only the text is cut (SHADER-FMA-MIX-TEXT-CUT-LITERAL) #2142
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs rebase
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!2142
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2142"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@DadaCap on GitHub · 2026-11-25 22:59 UTC · original
DadaCap:mix-literal-text-cut→main· +31 −1 · 3 files · 2 commits · merged 2026-11-26 16:25 UTCClaimed in the coordination issue as: SHADER-FMA-MIX-TEXT-CUT-LITERAL (#1608)
Depends on: nothing
What and why
llvm-mc 21.1.8 can print a
v_fma_mix*literal cut to its low 16 bits in the text only, while the printed encoding keeps all 32 bits. With the test's own values: the stored literal is0x40004200(low half 3.0, high half 2.0), the text says0x4200, and the printed encoding ends in00 42 00 40.same_encoding) passes, because the printed bytes are the stored ones.mix_literal(for an encoding that is cut too), never runs.restore_text_cut_mix_literaltakes the literal from the printed encoding when the text names only its low half and the high half is not zero. It runs on both the clean-listing path (check_printed_encodings) and the re-anchoring path (listings with undecodable words). The samerestore_mix_literalas before gives the 32 bits to every source the bytes encode as the literal.Counts over 1.0.2.1 (one work folder's listings, llvm-mc 21.1.8)
The FSPX program is the upscaler's history pass: one resampling weight lost its high half, so the weights summed to more than 1 and the history grew each frame.
Measured in the game
That one upscaler program retranslated with this change; RTX 5080, NVIDIA 621.24, Windows 11, a local tree with other open work:
That run had other local changes too, so it is not a clean A/B. The whole library retranslated with this change: 2,479 of 2,479 programs translate as before, none lost.
Tested
tests/semantic/test_fma_mix_literal.py: newtest_text_cut_but_printed_encoding_whole(clean and re-anchoring paths). It fails without the change (6.0 instead of 8.0) and passes with it; the file's other 18 tests pass.tests/test_docs_*.py,scripts/check_no_game_data.pyon the changed files.spirv-val.GPUs tested: NVIDIA GeForce RTX 5080, driver 621.24, Windows 11 (the game run above; the hand-written GPU tests were not run)
AI-assisted: yes (Claude Code, Claude Opus 5.5 wrote the change, the test and this text)
Checklist
mainand merges cleanly.docs/design.md, with how it was confirmed.🤖 Generated with Claude Code
@ecox982745 on GitHub · 2026-11-25 23:16 UTC · original
On an RTX 4090, the parent rendered 8/24 synthetic draws correctly and this head rendered 24/24. I compared
d3b67a704witha449806dcon Windows 11, NVIDIA 616.64. All 24 fragment modules per revision passedspirv-val --target-env vulkan1.2. Each draw covered 64 × 64 pixels in an RGBA32 float target. Every channel of every pixel matched the reference on the head.I exercised the first two rows on all three destinations,
v_fma_mix_f32,v_fma_mixlo_f16andv_fma_mixhi_f16, converting the selected f16 result back to f32 for readback. Each input went through both the clean-listing and re-anchoring paths. The zero-high-half and full-text controls passed on both revisions.To reproduce the inputs, I extended the PR's
test_fma_mix_literal.pyfixture with the same short printed operand and full literal bytes in both the printed encoding and synthetic blob. This isolates the translation error on a second GPU. Whether the change alone fixes the white world frames still needs a controlled game run.AI-assisted with OpenAI Codex (
gpt-6.2-astra).@JordanWebDev on GitHub · 2026-11-25 23:41 UTC · original · approved these changes
@DadaCap on GitHub · 2026-11-26 00:26 UTC · original
@ecox982745 thank you for running it on a GPU: 24/24 against 8/24 is the check I could not do here. AI-assisted (Claude Code, Claude Opus 5.5).
@MoonEyes on GitHub · 2026-11-26 06:54 UTC · original
Verdict: ready to merge. This agrees with JordanWebDev's approval and ecox982745's GPU run. It adds a check with llvm-mc 21.1.8 itself, two mutations and a corpus sample. Three suggestions below, none blocking.
Setup: PR head
a449806dc(checked again just before writing), on its based3b67a704. Main isa73a57e13, 146 commits later. I merged main into the head locally (992543f60, no conflicts, no push). The merge differs from main only in the PR's 3 files. Windows 11 Pro 10.0.26300, Python 3.14.0.llvm-mc --versionthrough WSL:Ubuntu LLVM version 21.1.8(/usr/bin/llvm-mc-21, and the same version forLLVM_MC, which points at/usr/lib/llvm-21/bin/llvm-mc). SPIRV-Tools v2026.4 from Vulkan SDK 1.4.363.0. The tests run on the CPU SPIR-V interpreter; no GPU was involved. I ran nothing in the game.Tests
tests/semantic/test_fma_mix_literal.pyon main: 18/18 pass. On the merge: 19/19 pass.test_printed_encoding8/8,test_reanchor_llvm_offsets3/3,tests/test_rdna2spirv_decode.py25/25.tests/test_docs_*.pyon the merge: 13 files, 52 tests, all pass.tests/semantic/test_lds_src2.pyfails on main and on the merge alike (5 tests, 63 failures): llvm-mc reportsNo such file or directoryfor the test's temporary input file. My llvm-mc runs through WSL and cannot see the Windows temp folder. This is unrelated to the PR, and #1733 fixes it.scripts/check_no_game_data.pyon the 3 changed files: exit 0, no output.llvm-mc 21.1.8 check of the fixture. I gave the test's 12 stored bytes (
01 60 20 cc ff 04 fe 0b 00 42 00 40) to llvm-mc 21.1.8, for-mcpu=gfx1013andgfx1030. Both print the textv_fma_mix_f32 v1, 0x4200, v2, 0x4200 op_sel:[0,0,1] op_sel_hi:[1,0,1], and the printed encoding ends in0x00,0x42,0x00,0x40. So the shape the new test builds (listing(STORED)) is exactly what this llvm-mc prints. I then fed llvm-mc 21.1.8's own text and encoding for 5 hand-made words into the translator, on both listing paths (10 runs):0x40490fdb), src2 the high halfnegon src0The PR matches all 10 runs; main matches none. The f32 row confirms the doc's "an f32 source a denormal": llvm-mc prints it as
0xfdb.Mutation
tools/rdna2spirv.py: 1 of 19 fails,test_text_cut_but_printed_encoding_whole, attests/semantic/test_fma_mix_literal.py:83:Lists differ: [1086324736, ...] != [1090519040, ...], which is 6.0 instead of 8.0.check_printed_encodingsremoved (tools/rdna2spirv.py:18054in the merge): the same test fails at:83.:18204): the same test fails at:84. So each call site is pinned by its own assertion.restore_text_cut_mix_literal(:17669and:17672) replaced by an always-true condition: 19/19 still pass. See suggestion 2.Corpus sample (local only, counts only)
--shard 0/9, 299 listings), translated with main and with the merge. Both: 298 translated, 298 passspirv-val. The 1 left is the sames_sethaltrefusal on both.spirv-val. 1 changes, the one with the 6 instructions.Safety
enc[3] == 0xCC)v_fma_mix*whose literal has a non-zero high half, and only when a source in the text is an immediate equal to the low half.restore_mix_literalchanges only sources whose SRC field is0xff. So an inline constant that happens to equal the low half (for example a 0 next to a literal whose low half is 0) is left alone.mix_inline_literal) returns at once (len(enc) != 12). The latermix_literalandmix_inline_literalrepairs still run after it and work from the blob, so they win when the bytes differ.lit(V), does not match the low-half test. Setting the same 32 bits again would be harmless anyway.Suggestions (non-blocking)
docs/design.mdtext (line 316) says "A third shape needs no blob". The function needs no blob, but it is only called fromcheck_printed_encodingsafter its early returns (tools/rdna2spirv.py:18039,:18042,:18045). So a clean listing with nofssm/orfspx/blob next to it, or a header-only blob, still reads the high half as +0.0. I checked:listing(STORED)with no blob gives 6.0 on the PR. The re-anchoring path without a blob fails withFileNotFoundErroron main too. Either move the call before those returns, or change the doc to say it needs the printed encoding but runs only where the blob check runs. The game's pipeline has the blobs, so this does not affect the counts above.restore_text_cut_mix_literal. Replacing each withTruekeeps 19/19 passing. One refused case would pin the text-match guard: av_fma_mixwhose text shows an immediate that is not the literal's low half. The name check may be unreachable with llvm-mc 21.1.8 output: it prints av_pk_fma_f16literal in full (0x40004200), so the low-half test already fails there.Not covered by this review
op_selis still not measured on AMD, as the doc says.AI-assisted: yes (Claude Code, Claude Opus 5.5, ran the tests and wrote this; a second agent checked this text)
@DadaCap on GitHub · 2026-11-26 07:50 UTC · original
Thank you for the review and for checking the fixture against llvm-mc 21.1.8 directly. All three suggestions are in
abcccefd7(plain push on the same branch, no rebase; it still merges cleanly with currentmain):check_printed_encodingsnow runsrestore_text_cut_mix_literalover every instruction with a printed encoding before its early returns for a missing or header-only blob, so "needs no blob" holds. The old call in the blob loop is gone; the re-anchoring call is unchanged.test_text_cut_but_printed_encoding_wholenow also checkslisting(STORED)with no blob next to it (8.0).test_text_immediate_other_than_the_low_half_is_left_alone: the text shows an immediate that is not the literal's low half, and the result is what the text says. Replacing the low-half guard withTruenow fails it (8.0 instead of 4.0); removing the moved call fails the test in 1. Theliteral >> 16guard is still not pinned: with a high half of 0 the restore writes back the value the text already holds, so no result can tell it apart. It stays as a shortcut that skips work, not a correctness guard.Ran
test_fma_mix_literal.py(20),test_printed_encoding.py,test_reanchor_llvm_offsets.py,tests/test_rdna2spirv_decode.py, the 13tests/test_docs_*.pyfiles,check_no_game_data.pyon the changed files: all pass. Not run: the full semantic suite or a corpus slice with this commit.(Reply written with Claude Code.)
@ecox982745 on GitHub · 2026-11-26 08:19 UTC · original
I checked the new listing-only path at
abcccefd7against its parenta449806dc. The full CPU semantic suite ran 6,320 tests across 493 files with zero failing files on the unmodified head (Windows build 26300, Python 3.13.18, native llvm-mc 23.1.6).RTX 4090, driver 616.64. I ran seven synthetic cases twice, once without an FSSM file and once with only its 256-byte header. The parent produced the expected pixels on 4/14 draws and the new head on 14/14. This covered positive and negative high halves, the low- and high-f16 destinations, an inline neighbor, genuinely truncated printed bytes, and the PR's text-mismatch control. Each SPIR-V module passed validation for Vulkan 1.2, and I checked every RGBA channel of each 64 × 64 draw.
I found one edge case where an unrelated inline source satisfies the low-half comparison. This is a hand-written inconsistent listing, in the spirit of the new negative test. Whether LLVM emits this input in practice is unknown. These lines reproduce it with the PR's
test_fma_mix_literal.pyhelpers.Here src1 is the inline integer 1, while src2 is the only encoded literal (selector
0xff). Its text specifies a high half of 2.0. The parent rendered 2.0. The new head rendered 1.0 because src1 matched the low half and triggered replacement of src2. Both file layouts gave that result.In a local control I required the same source to have selector
0xffand an immediate equal to the printed low half before replacing it. All 16 GPU draws then matched, including both edge-case draws, and all 20 existingtest_fma_mix_literal.pycases passed.@MoonEyes on GitHub · 2026-11-26 11:16 UTC · original
Independent confirmation, from another work copy of 1.0.2.1.
Setup: the pipeline library, 2,684 compute programs, the same translator (main
a73a57e13), only llvm-mc changes. 2,683 modules translate on both sides.v_fma_mix_f32, 16v_fma_mixlo_f16) whose literal is printed cut to its low 16 bits in the text while the printed encoding equals the stored bytes. Checked in the SPIR-V disassembly of 3 modules.Not covered: no GPU run. My count differs from the one in this PR (47,910 in 1,218 listings); I do not know why.
AI-assisted: yes (Claude Code. Claude Fable 5.2 ran the comparison through sub-agents; a separate agent replayed the counts on other modules and wrote this wording.)
@DadaCap on GitHub · 2026-11-26 11:44 UTC · original
Thank you for the independent check. On the count difference, here is exactly what the PR's figure counts, recounted over my local listings with the PR's own parser and the exact test
restore_text_cut_mix_literalapplies (counts only):v_fma_mix*v_fma_mix_f3247,849,v_fma_mixlo_f1661)FSPX: 6 in 1 listing; the game's own 25,734 listings: 0. In these listings every literal-carrying
v_fma_mix*is printed cut, and each of the 47,910 feeds a read that sees more than the low half (an f32 source, or an f16 source withop_selset), so none of them is harmless.So the two numbers measure different things: the PR counts instructions printed cut by llvm-mc 21, yours counts what differs between an llvm-mc 21 and an llvm-mc 23 translation. I can't reproduce your side here (no llvm-mc 23 on this machine), so I don't know why only 1,674 instructions / 383 modules differ in your comparison; one possibility, not checked, is that some of what 23 prints still translates to the same module. If you can share how many of your 383 modules fall within the 1,218 listings above, that would tell the two apart.
On @Zalthor's batch listing #2142 as no longer applying: at head
abcccefd7it merges with currentmain(a73a57e13) without conflict (git merge-treeclean; GitHub reports it mergeable), so a patch applied todocs/design.mdmay have hit moved context rather than a real conflict.(Reply written with Claude Code.)
@Tauwni on GitHub · 2026-11-26 13:55 UTC · original
Tested
abcccefd7merged ontomaina73a57e13(it merges cleanly), on an Apple M3 (macOS 26.5.1). I ran the fullscripts/run_gpu_tests.pyin auto mode, with test programs built frommain. I tested the merge rather than the branch alone because a branch from before9f98dcc61failsps_texagainstmain'svk_bindless_test(the tagged descriptor table), which says nothing about this change.mainmain+ this PRLEONIDA_W64_EMULATE=1The counts are identical to
mainon all three. No new failure. The ones left are the same on both sides:cs_fma_fused(#1724),ps_ssharp(#1774) andcs_imgatomic_ext(#1518) on MoltenVK; KosmicKrisp's(NAN)-constant fixtures (#2229) andcs_imgatomic_extthere.AI-assisted (Claude Code). No game data.
@aslan2142 on GitHub · 2026-11-26 16:25 UTC · original
Merging.
v_fma_mix*literal that llvm-mc 21 cuts to its low half in the text is now taken from the printed encoding, and thedocs/design.mdrow records the rule.main56bdd7e88+ this PR (abcccefd7):check_no_game_data.pyis clean on the changed files.test_fma_mix_literal.pyfails onmain(1 of 20) and passes with the PR (20/20).test_ci_registration.py, the docs tests, the line-ending test,compileallandmake_game.py --helppass.Thanks @DadaCap, @MoonEyes for the review, @JordanWebDev for the approval, and @ecox982745 and @Tauwni for the runs.
AI-assisted (Claude Code, Claude Opus 5.5 and Claude Fable 5.2)
@ecox982745 on GitHub · 2026-11-26 16:51 UTC · original
I implemented the operand-specific follow-up from the merge review. An adjacent inline
1could trigger a rewrite of a different operand, even when that operand printed a full literal. The patch checks the immediate and the encoded source selector on the same operand. Three-file patch against main935a2cd5b6· Coordination claimOn a physical RTX 4090 (Windows 11, NVIDIA 616.64), 14/18 synthetic draws matched the expected pixels on main and 18/18 matched with the patch. The inline-neighbor case changed from 1.0 to the expected 2.0. When two sources selected the literal and only one printed the cut value, the result changed from 8.0 to the expected 10.0. Both cases were run with the native shader file absent and with a header only. All 18 translated modules on each revision passed Vulkan 1.2 SPIR-V validation. Both new inputs are hand-written inconsistent listings. Their frequency in compiler output is unknown.
The full CPU translator suite passed all 6,369 tests across 500 files. The fork's branch is behind upstream workflow changes and GitHub rejected the branch sync with the current credentials. The linked patch is available for review or cherry-picking while the follow-up PR is pending.
AI-assisted with OpenAI Codex (GPT-6).