Skip to content

rdna2spirv: check every printed encoding against its blob, not only re-anchored listings (EGEN-PRINTED-ENCODING-CHECK) - #2026

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
Vonsek:vonsek3/printed-encoding-check
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
Vonsek:vonsek3/printed-encoding-check

Conversation

@Vonsek

@Vonsek Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Item: EGEN-PRINTED-ENCODING-CHECK (Vonsek3); finding and claim, following the VOPC op_sel finding.

Problem

A listing is LLVM's text for the instruction it decoded, not the bytes it read. translate() compared the printed encodings with the FSSM bytes only for listings with undecodable words (the re-anchoring path, 1,473 shaders). The other 25,030 were translated from the text alone. A field the disassembler drops would therefore be translated as 0 without a word, and llvm-mc does drop at least one: its gfx1013 decoder (LLVM 21.1.8) prints 0a 08 a9 d4 01 05 02 00 (v_cmp_lt_u16_e64 with VOP3 op_sel:[1,0]) as plain v_cmp_lt_u16_e64 s10, v1, v2 and re-encodes it with the bits cleared. The SRC1/SRC2 re-encoding that LLVM 23 brought in was caught only because it hit the re-anchored listings.

Change

  • check_printed_encodings() in tools/rdna2spirv.py runs for every listing without undecodable words whose header names its code range (shader_disasm.py's code 0x…..0x…) and whose fssm/ (or fspx/) blob holds that range. Each instruction's printed encoding must be the bytes at its offset, with same_encoding's existing exceptions. A difference raises Unsupported naming the instruction, its offset and both byte strings.
  • Not checked: hand-written listings (no code range), run_gpu_tests.py's code 0x0..0x0 (synthetic) listings, and a blob that doesn't hold the range (the tests' header-only FSSM). So no fixture or test path changes.
  • New docs/design.md contract row "Printed encodings", next to "Code-embedded data".

Tested

Windows 11, Python 3.12, SPIRV-Tools from the Vulkan SDK tools, llvm-mc 21.1.8.

  • New test tests/semantic/test_printed_encoding.py, 6 cases: a dropped VOPC op_sel, a difference in a later instruction, same_encoding's SRC2 exception, the unchecked cases, and no blob. With the change: 6/6 OK. Against main's tools/ (LEONIDA_TOOLS_DIR): 2 fail, because the two dropped-field cases translate.
  • python -I -m unittest discover -s tests/semantic: 1,644 tests OK. Every tests/test_*.py was run too, 210 files plus 1,270 pytest cases. The script-run files that fail are the ones failing on main and already being fixed: test_cf_ref/test_world_names (test_cf_ref: drop exec_hi from the Unsupported list now that cf_ref models it #1852, world_names test: check the overwrite diagnostic for the path as printed #1848) and the pytest-only files run without pytest. test_shader_meta.py passes (15/15); it uses a code-range header with a header-only blob, which is why that case is skipped.
  • Corpus, my own Xbox Series 1.0.2.1 copy (counts only):
    • Compared every printed encoding of the 25,030 clean listings with its blob: 30,335,381 instructions, 0 differ beyond same_encoding's exceptions (754). The 166 16-bit VOPC compares (154 shaders, all f16) have op_sel clear in the raw bytes.
    • Full translation with this change (--wave64-emulate, 16 shards): 26,487 of 26,503 translated, 26,487 pass spirv-val. The only error class is the 16 image_gather4_l address mode 6 (border) shaders from perf(translator): track s_mov_b64, s_movk_i32 and SGPR copies in sgpr_imm #1567 (@throny's finding, SHADER-348), the same count as main before this change. The new check refuses 0 shaders.
  • python -m compileall -q make_game.py tools tests: clean.

AI disclosure

AI-assisted (Claude Code, Claude Opus 5.5), operated by the account owner. No GPU involved in this change. The machine has an NVIDIA RTX 5080 (616.92) and an AMD RDNA2 iGPU.

🤖 Generated with Claude Code

…e-anchored listings

A listing is LLVM's text for the instruction it decoded, not the bytes it
read. translate() compared the two only for listings with undecodable words
(the re-anchoring path); a clean listing was translated from the text alone,
so a field the disassembler drops would be translated as 0 without a word.
llvm-mc's gfx1013 decoder does drop the VOP3 op_sel bits (14:11) of 16-bit
VOPC compares and re-encodes them as 0.

check_printed_encodings() runs for every other listing whose header names
its code range and whose fssm/ or fspx/ blob holds that range: each
instruction's printed encoding must be the bytes at its offset, with
same_encoding's exceptions, or the shader is Unsupported. Hand-written
listings, run_gpu_tests.py's synthetic listings and the tests' header-only
blobs are not checked.

On the 1.0.2.1 corpus the 25,030 clean listings hold 30,335,381
instructions and none differs (754 fall under same_encoding's exceptions);
the 166 16-bit VOPC compares have op_sel clear.

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

Copy link
Copy Markdown
Contributor

Independent Linux CPU check at cc283495e620eefd69d4b2a34c439f9d5c967c8a, Pop!_OS 22.04 / Python 3.12. python -I tests/semantic/test_printed_encoding.py passed all 6 cases. The identical test against 4eb6155d's tools via LEONIDA_TOOLS_DIR fails exactly the two rejection cases (dropped VOPC op_sel, mismatch in a later instruction); the four controls still pass. Synthetic inputs only. No corpus or GPU run. AI-assisted verification.

@borislisandro

Copy link
Copy Markdown

Tested cc283495 on Linux x86_64 (Python 3.x, pytest in a venv; CPU only, no game files): pass.

  • python -I tests/semantic/test_printed_encoding.py: 6 tests, OK.
  • pytest tests/semantic tests/test_translate.py tests/test_rdna2spirv_cli.py on this branch: all passed (no failures, exit 0), so the new check does not reject any hand-written fixture in those suites.

Code read of check_printed_encodings (tools/rdna2spirv.py): it only runs for listings whose first line is a shader_disasm.py header with a non-empty code range, with a blob next to it that is long enough for that range, and it compares each instruction's printed enc with the blob bytes at its pc through same_encoding. The synthetic and header-only cases (code 0x0..0x0) are skipped, as the docstring says. A mismatch raises Unsupported, so a shader the old code translated from the text alone is now refused if LLVM dropped a field; that is the point, and it fits "fix, don't disable" only if the refusals are then given rules. The count that matters (30,335,381 instructions over 25,030 listings all matching) needs the corpus; I cannot reproduce it. The PR should say how many shaders the new check refuses on the 1.0.2.1 corpus (the description implies none), since that number is what turns a quiet translation into a refusal.

AI-assisted review.

@Impre-visible

Copy link
Copy Markdown

Tested cc28349 on NVIDIA GeForce GTX 1660 (Turing, TU116, subgroup 32..32), driver 620.73.04 (proprietary, Vulkan 1.4.357), Arch Linux (kernel 6.18), llvm-mc 23.1.5, SPIRV-Tools v2026.4: pass, including a first slice of the real corpus (my own 1.0.2.1 copy, counts only).

  • Corpus slice, --limit 200 (disassembly made by make_game.py at main 4eb6155 with llvm-mc 23.1.5, 26,503 listings; --wave64-emulate off for both sides):
    • main 4eb6155: 200 translated, 200 pass spirv-val
    • this head: 200 translated, 200 pass spirv-val, and all 200 modules byte-identical to main's
    • so the new check refuses none of these 200 and changes no output. The full 26,503 are not run yet: my first full translation of the corpus is still in progress, and I will post the whole-corpus counts for this head here when it is free.
  • Repository test shaders, native build of runtime/ from this head: build.py 199 translated, 199 pass spirv-val; check.py 125 of 160 pass, 35 skipped
  • run_gpu_tests.py: 185/185 translated and pass spirv-val; 136/180 passed, 44 skipped, 0 failed; with LEONIDA_W64_EMULATE=1: 167/180 passed, 13 skipped (12 fixtures run by the d3d12 tests, 1 needs a 64-wide fragment subgroup), 0 failed
  • tests/semantic/test_printed_encoding.py: 6 tests OK; tests/semantic: 1677 OK

AI-assisted run (Claude). Counts only; nothing from the game leaves this machine.

@ItsNotRexed
ItsNotRexed merged commit 8b11bc8 into ItsNotRexed:main Nov 22, 2026
4 checks passed
@Impre-visible

Copy link
Copy Markdown

The whole-corpus counts I promised above, at cc28349, from my own 1.0.2.1 copy (counts only). The new check refuses no corpus shader and changes no output.

Setup: the disassembly make_game.py made at main 4eb6155 with llvm-mc 23.1.5 (26,503 listings: 25,030 clean, 1,473 with invalid words), translated with --wave64-emulate, SPIRV-Tools v2026.4, 8 shards then --merge.

main 4eb6155 this PR cc283495
translated 26,487 26,487
pass spirv-val 26,487 26,487
refused 16 16
refusal reasons image_gather4_l address mode 6 (border) x16 the same x16

AI-assisted run (Claude). Counts only; nothing from the game leaves this machine.

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.

5 participants