Skip to content

llvm-mc 23.1.0 is the minimum: LLVM 21 and 22 misdecode or misprint packed-math words the FSPX programs use (SHADER-804) - #4843

Open
tedin7 wants to merge 8 commits into
ItsNotRexed:mainfrom
tedin7:shader-804
Open

tedin7 wants to merge 8 commits into
ItsNotRexed:mainfrom
tedin7:shader-804

Conversation

@tedin7

@tedin7 tedin7 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: #4683 (comment)

Update (after review): the floor is LLVM 23.1.0, not 22

kacper-serewis measured that 22.1.2 and 22.1.8 still fail the five programs, and abilliontokens found why on the real DLL. Both were right, and my first explanation was wrong.

The cause of the five programs' exp (thanks to abilliontokens). They classified all 322 invalid words that llvm-mc 21.1.8 reports on the 29 programs:

The junk exp right after each invalid word in 05, 06, 08, 09 and 28 comes from the scalar load. Program 05 at 0x2120 has 16 17 30 f4 70 d0 01 fa. 23.1.6 reads it as s_buffer_load_dwordx16 [s92..s105,vcc_lo,vcc_hi], s[44:47], 0x1d070. 21.1.8 reads it as an invalid word, then exp mrt7. That also accounts for 322 against 89: the 233 vcc-tuple words decode on 23, and the 87 + 2 stay.

Which versions decode that scalar load (measured on a pod, gfx1013 and gfx1030):

llvm-mc 21.1.8 22.1.0 22.1.2 22.1.8 23.1.0 23.1.6
16 17 30 f4 70 d0 01 fa 2 invalid words 2 invalid words 2 invalid words 2 invalid words right right

The fix is llvm-project 1cd28beb7755 (#173870, "Have VCC as a first-class member of the SGPR pool"). It is in llvmorg-23.1.0-rc1 and later, and in no 22.x tag. So 22.x can never be enough for these programs.

Further reasons for 23, from a sweep of about 580,000 encodings with llvm-mc 21.1.8, 22.1.0, 22.1.1, 22.1.2, 22.1.8, 23.1.0 and 23.1.6. The sweep covered every VOP3P and VOP3 opcode for gfx1010 and gfx1030, literals in each source slot with each modifier, inline constants, unused source fields of 0 and 0x80, and 200,000 random words:

Family 21.1.8 22.1.0 22.1.1–22.1.8 23.1.0, 23.1.6
VOP3P/VOP3/VOPC with an unused source field of 0x80 (as LLVM 23's assembler writes it) invalid word invalid word printed encoding differs (field shown as 0) right
float inline constant in a 16-bit integer operand (v_add_nc_u16 v0, 0.5, v2) 12 bytes printed for 8 same same right

Those fixes are ef0680ba54f7 (#175753) and d7ee01c0fa31 (#200944), also only in 23. 22.1.1 got only the decode half of the first (8099e127cde2, backported as fef02d48c08d).

What changed in this PR.

  • shader_disasm.require_exact_decoding sends 4 instructions in one cached llvm-mc call:

    • 161730f470d001fa (the scalar load, first)
    • 004010cc01ff011a003cfffb
    • 000008d501050202
    • 000003d7f0040202

    Each must come back as one instruction whose printed encoding equals its bytes. The output is matched to the checks by byte offset, so a misread one does not hide the others. The error names the scalar load first, as the cause of the junk exp, then each other family that is wrong, what came out, and the release and LLVM commit that fix it. It refuses 21.1.8 and every 22.x, and accepts 23.1.0 and 23.1.6.

  • Docs (with the table above), CI (llvm-23), build_llvm_mc.ps1 (23.1.6), the preflight messages and the 11 quickstarts now say 23.

  • tests/fake_llvm_mc.py replays the outputs measured for 21.1.8, 22.1.2 and 23.1.6. A fake 22.1.2 is refused, with the scalar load named first.

  • make_game.py's disassembly signature includes a fixed check revision. A work folder disassembled with an older llvm-mc is disassembled again, and a test pins this.

Not covered.

  • The three programs that fail even with 23 (03, 18, 27), likely the v_dot4_i32_i8 op_sel words. Separately, v_fma_mix* with a 32-bit literal prints only the low 16 bits in its encoding, in every version from 21.1.8 to 23.1.6.

The original analysis below is superseded where it blames the v_pk_* literal for the exp or says 22 is enough: on the real programs the exp comes from the scalar loads above.

Why

SHADER-804: with llvm-mc 21.1.8, five FidelityFX FSPX programs (05, 06, 08, 09, 28) fail to translate ("reachable instruction with normalized encoding", one exp in each); with llvm-mc 23 they translate, and rafaelpssz found that 23's listing has no exp at all.

The exp is not an EXP encoding problem. Measured on a pod (gfx1010/gfx1030/gfx1013; llvm-mc 21.1.8, 22.1.8, 23.1.6; no game files):

  • The 64-bit EXP space (every en, target 0..63, compr, done, vm, each reserved bit 13..25 alone and all together, four vsrc patterns; 89,157 words per CPU, plus 20,000 random words with top bits 0xF8..0xFF): 21, 22 and 23 decode the same words as EXP. Only the text differs (exp mrt0 off, ... in 21/22, exp mrt0, off, ... in 23). All three re-encode the reserved bits and the vsrc of disabled channels as 0. Nothing 21 prints as exp is a different opcode family, and the top-6-bit 0xFC.. words are invalid in all three. So (a) and (b) have nothing to handle.
  • What differs is the instruction before it. LLVM 21 cannot decode a packed-math (VOP3P) instruction with a 32-bit literal: v_pk_mul_f16 v0, v1, 0xfbff3c00 (bytes 00 40 10 cc 01 ff 01 1a 00 3c ff fb) is an invalid instruction encoding; it skips 4 bytes, reads the second word as v_dot4c_i32_i8 and the literal as exp mrt0 off, off, off, off done compr vm. A literal whose top byte is 0xF8..0xFB does that, such as an f16 pair with -65504 (0xFBFF) in the high half. Same for v_pk_add_f16, v_pk_max_f16, v_pk_min_f16, v_pk_add_u16, v_pk_lshlrev_b16, v_pk_mul_lo_u16 ... 22.1.8 and 23.1.6 decode all of them, on gfx1010, gfx1013, gfx1030 and gfx1036.
  • Counted with canonical operands and a literal in each source slot (gfx1030): of the 71 VOP3P opcode/slot forms that 23 decodes as a 12-byte literal instruction, 41 differ under 21 (19 mnemonics: 16 v_pk_*, v_fma_mix_f32, v_fma_mixhi_f16, v_fma_mixlo_f16); 22 matches 23 on all 71. For VOP3 the same count is 563 of 732 differ under 21 (22 matches 23 on all). Random words (150,000, gfx1030) also show 21 rejecting src_flat_scratch_base_lo/hi operands, which 22/23 accept.
  • 22 and 23 differ from each other in this sweep only in the exp comma and in 23 accepting register tuples that run past s105 ([s104,s105,vcc_lo,vcc_hi]); 22 prints the stored 0 in unused VOP3 source fields like 21, 23 prints 0x80 (already handled, Translator: accept LLVM 23's 0x80 in unused VOP3 source fields; check for a .NET SDK #223).

The rejected instruction is lost from the listing (the translator re-anchors only what LLVM printed), so no translator rule can recover it: the choice is (c), raise the documented minimum, and make the tool enforce it. Related: #4595 refuses a reachable fall-through into undecodable words; this PR keeps such listings from being produced in the first place. It does not conflict with #4697, #2038, #2323.

What

  • tools/shader_disasm.py: require_packed_literals(mcpu) disassembles v_pk_mul_f16 v0, v1, 0xfbff3c00 once per process (cached) and stops, naming the llvm-mc's LLVM version and the fix, when llvm-mc reports an invalid instruction or prints an exp. It runs inside probe() (shader_disasm) and in fspx_unpack.py --disasm, after its output-folder checks. An llvm-mc that fails for another reason is left to the existing per-shader reporting. The one extra llvm-mc run adds about 15 ms once.
  • Documented minimum LLVM 22: README.md, docs/design.md (also explains the cause), docs/i18n/*/quickstart.md (11 files), make_game.py preflight message, tools/mc_command.py and shader_disasm.py examples, scripts/run_gpu_tests.py and runtime/test/shaders/build.py examples, scripts/build_llvm_mc.ps1 default -Version 21.1.8 to 22.1.8 (tag llvmorg-22.1.8 exists; the script was not run, no Windows here). The conda route in README has no version pin (docs/testing.md already used 23.1.6).
  • .github/workflows/ci.yml (translator-tests): installs llvm-22 from apt.llvm.org/noble (the 22 repo answers 200 for noble and jammy) and checks LLVM version 22.. runtime.yml uses llvm-18 only to assemble GPU fixtures, which this does not touch.
  • CI: the translator-tests job (LLVM 22) now also runs tests/test_shader_disasm.py::PackedLiteralTest, so the real-llvm-mc decode test runs there instead of being skipped.
  • Tests: tests/test_shader_disasm.py (LLVM-21-like fake is refused with "LLVM 21.1.8" and "LLVM 22 or newer", no listing written; a real llvm-mc decodes the packed literal with 0 invalid words, skipped when no AMDGPU llvm-mc), tests/test_fspx_unpack.py (same refusal for --disasm, one fake adjusted so it only warns on shader input), tests/test_make_game_pipeline_preflight.py (message text).

Tested with numbers

On a RunPod pod (Ubuntu 22.04, Python 3.13, no GPU needed), fresh copy of the tree each time:

  • New tests against main's tools (LLVM_MC = 22.1.8): 2 failed (test_llvm_21_is_refused_with_its_version_and_the_fix, test_llvm_21_losing_packed_literals_stops_before_any_listing), 53 passed. With this change: 92 passed, 3 skipped (shader_disasm, fspx_unpack, fspx_unpack_out, mc_command, fspx_shaders_stage); with 23.1.6: 55 passed, 1 skipped.
  • Negative control, llvm-mc 21.1.8: shader_disasm.py on a one-shader FSSM with the packed literal exits 1 with "'/usr/lib/llvm-21/bin/llvm-mc' is LLVM 21.1.8: it cannot decode a packed-math (VOP3P) instruction ... Use LLVM 22 or newer"; the real-llvm-mc test fails on 21 as intended; with 22.1.8 the same file gives v_pk_mul_f16 v0, v1, 0xfbff3c00, 0 invalid words.
  • 19 test files that use the disassembler or its messages, LLVM 22.1.8: main 2 failed / 300 passed; this branch 2 failed / 309 passed, the same two failures (test_skip_assets_preflight_reduces_disk_space_requirement: posixpath.isjunction; test_parity_with_llvm_mc_on_shader_fixtures, exp null, TEST-1010: rdna2_decode: exp null is a special operand, as shader_ir parses it #4697), not touched here.

Follow-up after review, RunPod pod, LLVM_MC = 22.1.8: test_make_game_preflight 80 passed (the two "LLVM 22+" message checks were red before), test_make_game_pipeline_preflight 15, test_shader_disasm 28, test_fspx_unpack 27, test_ci_registration 11, test_docs_links 6 passed. pytest tests/test_shader_disasm.py::PackedLiteralTest (what translator-tests now runs): 8 passed, the real decode test not skipped; with llvm-mc 21.1.8 the same command fails on the real decode test.

Not covered

Thanks to VeTkN for the report and rafaelpssz for the clue that 23.1.3 lists no exp at all.

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

…d shows the literal as an exp (SHADER-804)

LLVM 21.1.8 cannot decode v_pk_* / v_fma_mix* with a 32-bit literal: it prints an invalid word and reads the instruction's second word and the literal as other instructions, an exp when the literal's top byte is 0xF8..0xFB. 22.1.8 and 23.1.6 decode them. shader_disasm and fspx_unpack --disasm now stop, naming the version, when a packed literal is lost; docs, CI and build_llvm_mc.ps1 move to LLVM 22.
…l packed-literal decode test, testing.md on LLVM 22

@kacper-serewis kacper-serewis 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.

At 401ac9c, LLVM 22.1.2 passes the new preflight but all five affected FSPX programs still fail via the normal entry point. All 29 cached exports were freshly disassembled for gfx1030. LLVM 22.1.2 translated and validated 21/29; diagnostic LLVM 21.1.8 (preflight bypassed) and the historical cache both gave 22/29. One additional program fails printed-encoding parity on 22.1.2. Please narrow the version claim and verify any proposed floor against the affected programs. This does not establish the minimum working version. AI-assisted CPU review.

@rafaelpssz

rafaelpssz commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

A no-regression check with llvm-mc 23 (I have the DLL, not llvm-mc 21), on my own 1.0.2.1 copy, Windows, --wave64-emulate. fspx_unpack.py --disasm then rdna2spirv.py on amd_fidelityfx_upscaler_xbox.dll, with main af70fc78 and with 401ac9c1:

main #4843
programs 29 29
translated / pass spirv-val 26 / 26 26 / 26
reachable instruction with normalized encoding 2 2
listings – byte-identical to main
SPIR-V of the 26 – byte-identical to main

So under LLVM 23 the change is a no-op for these programs, as it should be. The remaining 3 failures are the ones LLVM 23 already had (03 and 18, the v_dot4_i32_i8 op_sel case, and 27), so the llvm-mc 21 side still needs @VeTkN's or @0xmp3's run.

@kacper-serewis kacper-serewis 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.

SHADER-804 follow-up at 401ac9c on the same 29 cached FSPX exports through the normal pipeline. LLVM 22.1.8: 29 listings, 322 invalid words in 11 listings, 21 translated and Vulkan-valid. LLVM 23.1.6: 29 listings, 89 invalid words in eight listings, 26 translated and valid. It retained every 22.1.8 success. This directly checks the requested 22.1.8 release; 23.1.6 is the better of the tested versions, and three programs remain unvalidated. AI-assisted CPU only.

@tedin7

tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @kacper-serewis, that is a real gap in my claim: I measured the packed-literal decode on hand-built words with 22.1.8 and 23, never on 22.1.2 or on the real programs. I will (1) find the LLVM change that fixed VOP3P-with-literal decoding and the first release that has it, (2) run the probe words through every 22.1.x I can get, and (3) make the floor whatever that shows (a point release, or 23) with the probe checking the exact behaviour rather than the major version. Could you share which instruction the five programs fail on under 22.1.2 (the line before the exp, or the "normalized encoding" word), and which program fails printed-encoding parity? That tells me whether 22.1.2 has the same decode gap or a second one. Thanks @rafaelpssz for the 23 no-regression run.

…gs (SHADER-804)

The FidelityFX FSPX programs encode unused VALU source fields as 0x80
(inline 0). LLVM 21 and 22.1.0 reject those words and misread the rest
(the literal 0xfbff3c00 as an exp). 22.1.1 to 22.1.8 decode them but
print the field as 0, so the printed-encoding check refuses the listing,
and print a float inline constant in a 16-bit integer operand as a
12-byte literal. 23.1.0 has both fixes (llvm-project ef0680ba54f7,
d7ee01c0fa31); no 22.x release has either.

shader_disasm.py now decodes one instruction per family in one cached
llvm-mc run and refuses any whose printed encoding is not its input,
naming the version, each family and the release that fixes it. Docs,
i18n quickstarts, CI (llvm-23), build_llvm_mc.ps1 (23.1.6) and the
preflight messages say 23. Tests: fakes answer the check as measured
21.1.8, 22.1.2 and 23.1.6 did; the real-llvm-mc test expects refusal
before 23.1.0 and exact listings from it.
… test fake answers the check (SHADER-804)

make_game.py signs a disassembly with the llvm-mc command, its --version
output and DISASSEMBLY_CHECK, the revision of shader_disasm.py's decoding
check. A work folder disassembled before the check (e.g. by LLVM 22.1.2)
no longer matches, so its listings are redone and the check runs.

test_fspx_shaders_stage's retried-disassembly fake now answers the check
as LLVM 23.1.6 does (fake_llvm_mc.GOOD), so it fails and passes for its
own reasons again. Bug report placeholder names LLVM 23.1.6.
@tedin7 tedin7 changed the title llvm-mc 22 is the minimum: LLVM 21 loses packed-math literals and shows the literal as an exp (SHADER-804) llvm-mc 23.1.0 is the minimum: LLVM 21 and 22 misdecode or misprint packed-math words the FSPX programs use (SHADER-804) Nov 23, 2026
@tedin7

tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

@kacper-serewis thanks, you were right: no 22.x is enough. Head is now 593e3598, and the floor is 23.1.0. The full table is in the description. In short:

  • 22.1.1–22.1.8 read the FSPX packed-math words but print a different encoding, because the unused 0x80 source fields come out as 0. 21.1.8 and 22.1.0 reject them.
  • All 22.x also mis-print inline float constants on i16 operands.
  • The LLVM fixes (ef0680ba54f7, d7ee01c0fa31) are only in 23.x.

The probe now checks exactly those families with 3 instructions, and it refuses every 22.x. A work folder disassembled with an older llvm-mc is now disassembled again. Your 23.1.6 result (26/29, keeping every 22.1.8 success) matches. The remaining three (03, 18, 27) are outside this PR. One lead for one of them: v_fma_mix* with a literal prints only 16 bits of it in every version.

@abilliontokens

Copy link
Copy Markdown
Contributor

Data point from the retail amd_fidelityfx_upscaler_xbox.dll (Xbox 1.0.2.1), Windows, llvm-mc 21.1.8 vs 23.1.6 (conda-forge llvm-tools), translator at main 64b45d0. Counts and instruction classes only.

The five programs' invalid words are not VOP3P-literal words. I took every invalid instruction encoding warning in the 21.1.8 listings (the warning column gives the byte offset), decoded those bytes with 23.1.6, and classified all 322 distinct offsets:

class words programs
s_buffer_load_dwordx16 with a register list running past s105 into vcc_lo,vcc_hi 220 03, 05, 06, 07, 08, 09, 28
s_buffer_load_dwordx8 / x4, same list shape 3 07, 03, 08
buffer_load_dwordx4 / buffer_store_dwordx4, same list shape 10 05, 08
v_dot4_i32_i8 … op_sel/op_sel_hi — 23.1.6 cannot decode these either 87 03, 04, 05, 06, 09, 12, 15, 18
window returned no output 2 06

Zero v_pk_*/v_fma_mix* literal words among the invalid offsets. Your 22.1.8 count of 322 matches my 21.1.8 count exactly, consistent with the floor being decided by the s105-tuple change your sweep already lists ("23 accepting register tuples that run past s105"), not the VOP3P-literal change.

Example, program 05 at 0x2120: blob 16 17 30 f4 70 d0 01 fa is s_buffer_load_dwordx16 [s92,s93,…,s105,vcc_lo,vcc_hi], s[44:47], 0x1d070 on 23.1.6; 21.1.8 prints invalid instruction encoding, skips, and the next printed instruction is the junk exp mrt7 off, off, off, off vm — the reachable normalized instruction your refusal names. The same pattern holds for the reachable exp in each of 05, 06, 08, 09, 28 (targets mrt7/prim/param28/param4/mrtz).

Hand-built check, no game data: 34 00 30 f4 00 00 00 fa assembles as s_buffer_load_dwordx4 s[0:3], [s104,s105,vcc_lo,vcc_hi], 0 only on 23.1.6 (21.1.8: "registers in a list must be of the same kind"); disassembling those bytes, 21.1.8 prints invalid instruction encoding + exp mrt0 off, off, off, off, 23.1.6 prints the SMEM load.

Even with 23.1.6 listings, main still ships silently truncated modules for 6 of the 26 "translated" programs. The remaining 87 undecodable words are v_dot4_i32_i8 op_sel (#3372's class) on reachable fall-through paths — exactly the six programs #4595 refuses on 23-listings (04, 05, 06, 09, 12, 15). SPIR-V asm line counts, llvm-mc 23.1.6 listings vs listings written by tools/rdna2_decode.disasm_bytes (the pure-Python decoder already on main via #1901):

prog llvm 23.1.6 python backend
04 39,463 55,539
05 81,399 107,834
06 88,453 273,954
09 89,230 177,571
12 27,541 29,112
15 27,083 68,619

Programs 07, 08, 28 come out identical under both (the SMEM class was their only loss); program 00's python-backend module is 48 asm lines shorter than the llvm-mc one, a decode-format edge I did not chase. With python-backend listings for all 29 programs, rdna2spirv.py on main translates 29/29 and all pass spirv-val — versus 22/29 on 21.1.8 listings and 26/29 (six truncated) on 23.1.6 listings. Whether the dot4 path's codegen is correct is #3372/#2323's scope; the disassembly-side gap is what this measures.

So the floor bump is still worth having (it removes the SMEM class and the junk exp), but it does not by itself deliver correct modules for these programs — the dot4 words need #3372 or the #2323 backend.

AI-assisted (omp orchestrator). Retail DLL read-only; counts and synthetic encodings only, no game data committed.

@tedin7

tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @abilliontokens, this corrects my explanation. The exp in the five programs comes from the SMEM class: s_buffer_load_dwordx16 with a register list running past s105 into vcc_lo,vcc_hi. It does not come from VOP3P literals. Your hand-built word (34 00 30 f4 00 00 00 fa) shows it without game data.

The floor stays 23, for this reason first. The VOP3P 0x80-field and i16 inline-constant families are further reasons.

I am adding that SMEM shape to the decoding check, so the error names it, and correcting the design table and the description, with credit to you. The 87 v_dot4_i32_i8 op_sel words that 23.1.6 cannot decode either are #3372 / #2323's scope. #4595 makes them a refusal instead of a silently cut module, which your 23.1.6 numbers on 04, 05, 06, 09, 12 and 15 show it does.

…PX exp (SHADER-804)

abilliontokens classified the 322 words llvm-mc 21.1.8 rejects on the
real FidelityFX DLL: 233 are scalar and buffer loads whose register list
runs past s105 into vcc_lo/vcc_hi, 87 v_dot4_i32_i8 op_sel words (also
undecodable on 23), 2 others, and no v_pk_*/v_fma_mix literal. The junk
exp in programs 05, 06, 08, 09 and 28 is the scalar load's second word.
Measured on conda-forge llvm-tools: 21.1.8, 22.1.0, 22.1.2 and 22.1.8 all
reject 16 17 30 f4 70 d0 01 fa; 23.1.0 and 23.1.6 decode it. The fix is
llvm-project 1cd28beb7755 (#173870), first in llvmorg-23.1.0-rc1.

require_exact_decoding now sends that scalar load first, among the four
checks in one cached call, and matches the output to the checks by byte
offset (invalid-word columns and printed lengths), so the error names the
scalar load first and still reports the families after it, or says that
the misread ran into them. fake_llvm_mc.py replays the measured 21.1.8,
22.1.2 and 23.1.6 outputs; docs/design.md and testing.md name the scalar
loads as the cause and keep the VALU families as further reasons for 23.
@tedin7

tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Pushed 31956403.

  • Which versions decode it: 16 17 30 f4 70 d0 01 fa, the program-05 word, decodes only from 23.1.0. On 21.1.8, 22.1.0, 22.1.2 and 22.1.8 it gives two invalid words, then exp mrt7.
  • The LLVM fix: 1cd28beb7755 (#173870, "Have VCC as a first-class member of the SGPR pool"). It is in llvmorg-23.1.0-rc1 and later, and in no 22.x tag.
  • The check: it now probes this scalar load first and names it as the cause of the junk exp. It matches the output by byte offset, because a misread load swallows the next instruction.
  • Docs: the design table and the description are corrected, with credit to @abilliontokens.

One detail: on 23.x your hand-built 34 00 30 f4 00 00 00 fa reads as s_buffer_load_dwordx16 s[0:15], [s104,s105,vcc_lo,vcc_hi], null, a dwordx16 with the vcc tuple as the base. Same class.

@chpeu

chpeu commented Nov 23, 2026

Copy link
Copy Markdown

Tested 593e3598 on Linux (Linux Mint 22), Python 3.12.3, NVIDIA GeForce RTX 3080, driver 615.71.09, llvm-mc 20.1.2 (the Ubuntu 24.04 distro package): CPU side pass, GPU side unchanged — and this box is exactly the case the new floor rejects.

Their own tests run here — the six tests/ files the PR changes, plain python3 -I:

file result
tests/test_fspx_shaders_stage.py 14 tests, OK
tests/test_fspx_unpack.py 28 tests, OK (1 skipped)
tests/test_make_game_pipeline_preflight.py 15 tests, OK
tests/test_make_game_preflight.py 81 tests, OK (1 skipped)
tests/test_shader_disasm.py 29 tests, OK
tests/test_shader_stage_resume.py 45 tests, OK

212 tests, 0 failures. The new tests/fake_llvm_mc.py answers the decoding check here, so test_fspx_shaders_stage.py passes without a real LLVM 23 on the machine.

Translator suite (the 28 pytest-marked files, as CI runs them): branch 1637 passed, 37 skipped, 108 subtests passed — identical to main measured in the same session.

Merged state (this branch's base de671352 is older than main): git merge --no-commit --no-ff onto 594f3485 is clean, the build is clean, and the full GPU battery does not move:

Tree run_gpu_tests.py with LEONIDA_W64_EMULATE=1 failures
main 594f3485 170/217 (47 skipped) 201/217 (16 skipped) 0
main + this branch 170/217 (47 skipped) 201/217 (16 skipped) 0

The floor, measured on the distro llvm-mc. Ubuntu 24.04 puts /usr/lib/llvm-20/bin/llvm-mc (20.1.2) on the machine from its own package, and docs/testing.md now says a distro llvm-mc is enough "if it is 23.1.0 or newer". Calling require_exact_decoding("gfx1013") from this branch against our 20.1.2 stops with your message, naming the version and the family:

ERROR: '/usr/lib/llvm-20/bin/llvm-mc' is LLVM 20.1.2, whose AMDGPU disassembler misreads:
  - packed math (VOP3P) with a 32-bit literal and an unused source field set to inline 0:
    v_pk_mul_f16 v0, v1, 0xfbff3c00 came out as exp mrt0 off, off, off, off done compr vm [00 1c 00 f8 00 00 08 d5]

llvm-mc itself prints invalid instruction encoding at byte offsets 1, 10 and 21 of the 28-byte probe stream. Two things I noticed while running that:

  • This is a clean refusal that names the version and the instruction family — a lot better than a fixture that llvm-mc cannot assemble, which stops the whole battery at 0/N with no hint (that is what an op_sel fixture on a 16-bit operand did to us in rdna2spirv: widen packed f16 sources with integer ops, not UnpackHalf2x16 (SHADER-777 follow-up, RDNA4) #4779).
  • decoder_faults() stops at the first entry whose printed encoding has a different length, so on LLVM 20 only the first of your three probes is reported and the other two are not judged. The raw output suggests they fail as well, but the check does not say so — worth a sentence if someone reads this as "only one family is broken on LLVM 20".

What the floor does not gate on this machine: require_exact_decoding is called from tools/shader_disasm.py::probe() and tools/fspx_unpack.py, not from scripts/run_gpu_tests.py. So a box with LLVM 20 still runs the GPU battery and can report the numbers above; only the listing/make_game.py path refuses it. That matches what I measured, it is only a note about who gets stopped.

Second card: the RTX 5080 in this box is holding other work right now, so it was not launched this pass — no second-card number, and that is not a failure.

@tedin7

tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @chpeu. Your LLVM 20.1.2 run is a useful extra point below the floor.

On decoder_faults() stopping at the first length mismatch: you were right for 593e3598. The head is now 31956403, which matches the output to the probes by byte offset, not by order, because one misread instruction swallows the next. It reports each family it can judge, and says so when a misread ran into the following probe. That head also adds the scalar-load-into-vcc probe, which is the real cause of the junk exp in the FSPX programs (see abilliontokens above).

On who gets stopped: yes, that is deliberate. The GPU battery assembles its own fixtures and does not depend on the disassembler. Only the listing and make_game.py path reads llvm-mc's decode, so only that path refuses an old version.

@gertify

gertify commented Nov 23, 2026

Copy link
Copy Markdown

Tested 3195640 on CachyOS Linux with the real llvm-mc (LLVM version 23.1.5), CPU only: pass.

  • pytest tests/test_shader_disasm.py tests/test_fspx_unpack.py tests/test_make_game_pipeline_preflight.py tests/test_make_game_preflight.py tests/test_ci_registration.py: 162 passed, 2 skipped, 39 subtests passed. Both skips are Windows-only (the exclusive-lock repro and NTFS junctions).
  • DecoderCheckTest::test_the_llvm_mc_on_this_machine_is_used_from_23_1_0_and_refused_before runs against the installed llvm-mc and passes. The LLVM 21 and 22.1.2 refusal tests pass with their fake llvm-mc.
  • tests/test_docs_*.py: Ran 30 tests, OK.

The PR text names PackedLiteralTest; at this head the class is DecoderCheckTest. Real llvm-mc 21 and 22 were not run here.

AI-assisted.

@dcastell1

Copy link
Copy Markdown
Contributor

Code read + CPU tests, 3195640: pass (tests/test_shader_disasm.py tests/test_build_llvm_mc_batch.py → 28 passed, 2 skipped, 6 subtests).

The LLVM 21/22 misdecode of scalar loads into VCC is the kind of thing that only shows as a wrong instruction later, so pinning the minimum to 23.1.0 with this test is worth the inconvenience. Note this box runs LLVM 21.1.8, so the tests pass because the version gate refuses to use it — which is the intended path.

@kapitche

Copy link
Copy Markdown
Contributor

Tested 3195640 merged with main 3faac55 on Windows 11 native with Python 3.13.1 and 3.12.16 (real llvm-mc 23.1.6 with the AMDGPU target) and on Linux (WSL2 Ubuntu, kernel 5.15) Python 3.12.16 (no llvm-mc there, fake_llvm_mc only): pass.

  • Python tests (test_fspx_shaders_stage, test_fspx_unpack, test_make_game_pipeline_preflight, test_make_game_preflight, test_shader_disasm, test_shader_stage_resume, test_mc_command) plus tests/test_docs_*.py (10 files): 262 run, 262 passed, 0 failed on each Windows interpreter, no skips (test_the_llvm_mc_on_this_machine_is_used_from_23_1_0_and_refused_before ran against the real 23.1.6 and passed); on Linux 262 run, 262 passed, 0 failed, 5 skipped (the real-llvm-mc test and others that need an AMDGPU llvm-mc).
  • Negative control: tools/shader_disasm.py, tools/mc_command.py, tools/fspx_unpack.py and make_game.py checked out from main, the PR's tests kept: Linux 7 failures across 5 files (test_fspx_unpack 1, test_make_game_pipeline_preflight 1, test_make_game_preflight 2, test_shader_disasm 2, test_shader_stage_resume 1); Windows on both Pythons 6 failures across 4 files (test_fspx_unpack 1, test_make_game_preflight 2, test_shader_disasm 2, test_shader_stage_resume 1; pipeline_preflight not in that run). The failing tests are the llvm 21 / 22.1.2 refusal tests, the preflight wording tests and the resume-after-check test.
  • Not run: LLVM 21/22 binaries (only the fakes for those), the CI job change (apt.llvm.org llvm-toolchain-noble-23 and the ::DecoderCheckTest selection), scripts/build_llvm_mc.ps1 with the new default 23.1.6, a real make_game run.

@KkelebekK

Copy link
Copy Markdown

Tested 31956403 (merge base 98fa503f; merges cleanly into main 3faac557) on CachyOS Linux 7.3.4 (Python 3.14.10), with the real llvm-mc 23.1.4 and, for the refusal, llvm-mc 21.1.8 side by side; GPU suite on AMD Radeon 780M (RADV PHOENIX, gfx1103, Mesa 26.2.6) and NVIDIA GeForce RTX 4070 Laptop (620.70.06): pass.

  • Independent decoding check with the real tools. The four byte strings in DECODER_CHECKS (161730f470d001fa, 004010cc01ff011a003cfffb, 000008d501050202, 000003d7f0040202) through llvm-mc --disassemble -triple=amdgcn--amdpal -mcpu=gfx1030 -show-encoding (and gfx1013):
    • 23.1.4: each is one instruction whose printed encoding equals its bytes (the first is s_buffer_load_dwordx16 [s92..s105,vcc_lo,vcc_hi], s[44:47], 0x1d070). Assembling the three textual forms back with 23.1.4 gives the same bytes.
    • 21.1.8: the first word is "invalid instruction encoding", then exp mrt7 off, off, off, off vm and v_dot4c_i32_i8 ...; v_add_nc_u16 v0, 0.5, v2 comes out as an invalid word plus v_cndmask_b32_e32 v1, 0.5, .... When 21.1.8 assembles v_pk_mul_f16 v0, v1, 0xfbff3c00 it writes the unused source field as 0x18, 23.1.4 as 0x1a, which is the 0x80-field difference the PR describes. This confirms the table rows for 21.1.8 and 23.x; 22.x was not available here.
  • shader_disasm.require_exact_decoding('gfx1030'): accepts 23.1.4; with MC set to 21.1.8 it refuses with exit 1 and lists all four families, naming the scalar load first with the junk exp.
  • Python: test_fspx_shaders_stage, test_fspx_unpack, test_make_game_pipeline_preflight, test_make_game_preflight, test_shader_disasm, test_shader_stage_resume, test_run_gpu_tests, test_docs_*: 281 passed, 2 skipped (one is the Windows-only exclusive-lock repro), 92 subtests passed. The same with LLVM_MC pointing at 21.1.8 (these tests use tests/fake_llvm_mc.py): 281 passed, 2 skipped. On the merged tree: 281 passed, 2 skipped.
  • GPU suite, as a regression check (it only assembles with llvm-mc): 780M 202/217 passed, 15 skipped; 4070 170/217, 47 skipped; 4070 with LEONIDA_W64_EMULATE=1 201/217, 16 skipped; 0 failed, the same counts as main 3faac557 here.
  • Nit: docs/testing.md now says LLVM 23+ for the tools but still says, a few lines down, that llvm-18 runs run_gpu_tests.py; true for the GPU suite, but worth one clause so the two statements do not read as contradicting.
  • No runtime C++ changes; reused the runtime/build/linux build of af70fc78.

Not run: llvm-mc 22.x and 23.1.0/23.1.6, Windows (build_llvm_mc.ps1, CI), the FSPX programs themselves (no game data), so the claim that programs 05, 06, 08, 09 and 28 translate is not checked here.

Synthetic inputs only, no game data. AI-assisted.

@memorypressure

Copy link
Copy Markdown

Verified against main 3faac55: merges cleanly; compileall passes and all changed suites (test_shader_disasm 29, test_fspx_unpack, test_fspx_shaders_stage, both preflight tests, test_shader_stage_resume) pass under python -I. The new decoding gate was executed here against host llvm-mc: it passes silently and decoder_faults reports nothing, matching the stated minimum. The LLVM 21/22 misdecode evidence cannot be reproduced on this host (no 21/22 builds); fixtures are hand-written words, no corpus data. The branch currently reports no CI checks — please re-trigger. Two reviewer notes: it collides with #4845 in the same testing.md paragraph (verified conflict), and pending #4204 pins LLVM 21 in a Runtime workflow, which is a policy direction this PRs 23.1.0 minimum should agree with. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

@tedin7

tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @memorypressure. On your two notes:

  • docs: Homebrew's llvm is keg-only, so llvm-mc needs PATH on macOS #4845: it touches the same docs/testing.md paragraph. That is a text-only conflict, and whichever lands second rebases it. Its Homebrew PATH advice still holds with 23.
  • CI: use LLVM 21 for llvmpipe GPU tests in the Runtime workflow #4204: it does not contradict the floor. The 23.1.0 minimum gates only the disassembly path (shader_disasm and fspx_unpack, which read llvm-mc's decode). The GPU battery and the llvmpipe tests assemble their own fixtures and are not gated, as chpeu measured above with LLVM 20. So LLVM 21 in that workflow stays fine. The CI job this PR changes is the one that disassembles, and it now installs llvm-23.

CI on fork PRs runs once a maintainer approves the workflow run, so I can't re-trigger it from here.

@Atomic258

Copy link
Copy Markdown
Contributor

Tested 3195640 on Windows Server 2022, CPython 3.13.12: pass

  • python -I tests/test_fspx_unpack.py -> OK; python -I tests/test_make_game_pipeline_preflight.py -> OK
  • shader_disasm changes covered by the fspx pipeline tests.

git diff --check clean; python -m compileall -q exit 0. No game files, no GPU. AI-assisted (Devin).

@tedin7

tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @KkelebekK. Commit 1e5f42b fixes the sentence below the LLVM 23+ line in docs/testing.md. It now says an older llvm-mc is not enough for the disassembly tools but still runs run_gpu_tests.py, the mem fuzzer and lds_fuzz.py (the llvm-18 case). Docs only, nothing to run. AI-assisted.

@VeTkN VeTkN left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Tested 3195640 on the machine where SHADER-804 was found: Windows 11 Pro 26200, Visual Studio 2026 Build Tools 18.10 (MSVC 14.51.36231), Python 3.14.7, SPIRV-Tools v2026.4, my own 1.0.2.1 FidelityFX DLL: pass. The refusal, the 23.1.6 listings and the three leftover programs were re-checked on the current head 1e5f42b, with the same results.

  • scripts/build_llvm_mc.ps1 -NoEnv -Dest : built llvm-mc 23.1.6 (1,035 build steps) with VS 2026 in 8 minutes, source clone included, exit 0.
  • fspx_unpack.py --disasm with the real llvm-mc 21.1.8: refused (exit 1, no listings), 4 families named, the scalar load into vcc_lo/vcc_hi first, and "Use LLVM 23.1.0 or newer".
  • The same with the new llvm-mc 23.1.6: accepted, 29 listings.
  • rdna2spirv.py --wave64-emulate (this head's translator) on the 29 programs: 22 translated and valid from my 21.1.8 listings (made yesterday, before this check existed), 26 from the 23.1.6 ones. 05, 06, 08, 09 and 28 now translate.
  • The three left with 23, each translated alone: 03 and 18 stop with "reachable instruction with normalized encoding"; 27 stops at a v_fma_mix_f32 whose printed encoding lacks a field the disassembler dropped, so not at a v_dot4 word. 27 was valid from the 21.1.8 listings.
  • test_shader_disasm.py (29) and test_fspx_unpack.py (28): OK with both real llvm-mc builds.

Both 3195640 and 1e5f42b conflict with main 561b65a, in docs and CI only: .github/workflows/ci.yml, README.md, docs/testing.md and six docs/i18n quickstarts.

Counts only, no game data.

AI-assisted (Claude).

@chpeu

chpeu commented Nov 23, 2026

Copy link
Copy Markdown

Row for a machine below the new minimum: this box runs llvm-mc 20.1.2 (Ubuntu), while this PR makes LLVM
23.1.0 the requirement. Head 1e5f42b47, RTX 3080, driver 615.71.09, Vulkan 1.4.351, no game files.

What still runs here, end to end:

  • LEONIDA_W64_EMULATE=1 python -I scripts/run_gpu_tests.py --build runtime/build/linux --llvm-mc /usr/lib/llvm-20/bin/llvm-mc
    → 201/217 passed, 16 skipped, 0 failed
  • without the variable → 170/217 passed, 47 skipped, 0 failed
  • main 3faac557 on this same box (measured earlier today): 201/217 and 170/217, 0 failed — identical.
  • The build itself is clean with GCC 13.3 (cmake --build runtime/build/linux → built, no errors).

So the LLVM 23 floor does not come from anything that breaks the existing programs on an LLVM 20 box: the whole
217-program suite still assembles, draws and matches here, with nothing skipped that main does not already skip.
What LLVM 20 cannot do, and what I reported on #4779 earlier today, is assemble the new 16-bit listings carrying a
three-component op_sel (v_max_i16_e64 v20, v2, v3 op_sel:[0,0,1] → not a valid operand); at that time the whole
suite stopped before drawing anything, and the rewrite in 415f6f90 is what made 201/217 reachable on LLVM 20 again.

One thing the PR still needs before merge, from this side: the branch no longer merges cleanly onto current main
— git merge --no-ff --no-commit stops with conflicts in tests/test_shader_disasm.py,
tests/test_shader_stage_resume.py and tools/shader_disasm.py. I am deliberately not publishing a merged-state
test count for this head, because there is no merged state to measure; it needs a rebase first.

Machine: Linux Mint 22 (Ubuntu 24.04 base), LLVM 20.1.2, SPIRV-Tools 2025.1~rc1, GCC 13.3, Python 3.12.3 with pytest
9.2.0 and numpy 2.5.5, built with cmake -S runtime -B runtime/build/linux -DLEONIDA_VULKAN_HEADERS_FETCH=ON. The
RTX 5080 was not used (186 MiB free, another job holds the card). AI-assisted testing, counts read through by hand.

…d apt key-check text; require LLVM 23 (llvm-23, noble-23) where main still said 21
@tedin7

tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @chpeu. That matches the intent: LLVM 23 is the floor for the disassembly tools (fspx_unpack.py --disasm and shader_disasm.py), where 21 and older drop fields, as @VeTkN measured on the SHADER-804 machine. docs/testing.md says the GPU suite, the mem fuzzer and lds_fuzz.py still run with an older llvm-mc, and your 201/217 and 170/217 on LLVM 20 confirm it. The merge with main is being resolved now. AI-assisted.

@chpeu

chpeu commented Nov 23, 2026

Copy link
Copy Markdown

Follow-up on the merge problem I reported this morning: at the new head 1638a759a the conflicts are gone.

  • git merge --no-ff --no-commit onto current main 561b65a83 → clean, no conflicts (this morning it stopped
    on tests/test_shader_disasm.py, tests/test_shader_stage_resume.py, tools/shader_disasm.py).
  • The translator pytest set measured on that merged tree: 1750 passed, 47 skipped, 116 subtests, 0 failed
    (33 marked files) — and main alone, measured right after in the same session: the same 1750 / 47 / 116,
    0 failed
    . So the merged state is exactly main.

Scope of this note: it is a merge-and-Python check. My GPU row for this PR (201/217 with LEONIDA_W64_EMULATE=1,
170/217 without, 0 failed on the RTX 3080 with the old llvm-mc 20.1.2) was measured at the earlier head
1e5f42b47, not at this one; this head is docs/CI-only on my side, so I did not redraw 217 programs for it.
Machine: Linux Mint 22 (Ubuntu 24.04 base), llvm-mc 20.1.2, SPIRV-Tools 2025.1~rc1, Python 3.12.3 with pytest 9.2.0
and numpy 2.5.5. AI-assisted testing, counts read through by hand.

@itsonlysimbo

Copy link
Copy Markdown
Contributor

Tested 1638a759 on RTX 4070, NVIDIA 621.14, Windows 11 (10.0.26300), Vulkan SDK 1.4.363, llvm-mc 23.1.6, test programs from main 561b65a8: pass.

AI-assisted (Claude Code).

@kapitche

Copy link
Copy Markdown
Contributor

Tested 94e3c87 merged with main 8575d36 on Linux (WSL2) / Python 3.12.16: concern
The real merge conflicts in docs/i18n/ru/quickstart.md: main has a where.exe llvm-mc / Where-Object note and llvm-21 in the WSL step, and this PR changes the same lines to llvm-23. Every other file auto-merges; it needs a rebase.
With only that file resolved to main's side to run the tests, these pass: test_shader_disasm, test_fspx_unpack, test_fspx_shaders_stage, test_make_game_pipeline_preflight, test_make_game_preflight, test_shader_stage_resume, test_build_llvm_mc_batch, test_docs_table_rows (the tests that need a real llvm-mc skip here).
Negative control: with tools/shader_disasm.py, make_game.py, tools/mc_command.py, tools/fspx_unpack.py, runtime/test/shaders/build.py and scripts/run_gpu_tests.py reverted to main, test_shader_disasm fails (2), test_fspx_unpack (1), test_make_game_preflight (2), test_make_game_pipeline_preflight (1), test_shader_stage_resume (1); restored afterwards.

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.