Skip to content

llvm-mc 22 is the minimum: LLVM 21 loses packed-math literals and shows the literal as an exp (SHADER-804) - #4843

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

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

Conversation

@tedin7

@tedin7 tedin7 commented Nov 23, 2026

Copy link
Copy Markdown

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

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

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.

3 participants