rdna2spirv: refuse a line with too few operands before lowering (D3D12-TRANSLATOR-MISSING-OPERAND) #3266
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3266"
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?
Imported from ubiquitarianism/leonida. Originally posted by RussianSanta12 on 2026-12-02T23:29:30Z.
Claimed in the coordination issue as: D3D12-TRANSLATOR-MISSING-OPERAND (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7353400606), from @imShangLi's finding.
What and why
A hand-written listing line with too few operands (a fixture typo) made
tools/rdna2spirv.pyend in a Python traceback (IndexError,ValueErrorfrom unpacking,TypeError) at whichever operand read came first, because theexcept (IndexError, TypeError)at the end ofGen.insnonly turned the no-operand case intoUnsupported. AnIndexErrorcarries no index, so widening thatexceptwould also hide real translator bugs; this adds an operand-count check instead.MIN_OPERANDSis built once at import from the decoder's ISA tables (tools/rdna2_isa_tables.py, already a translator dependency intranslator_deps.cmakeandmake_game.TRANSLATION_SOURCES), one operand per field, keyed by(mnemonic, encoding family):_e64-> VOP3/VOP3B,_e32/_sdwa/_dpp-> VOP1/VOP2/VOPC, an unsuffixed mnemonic -> the fewest over its encodings. ~1,900 entries, ~1-3 ms at import.v_cmpxdestination (EXEC), the implicit VCC operands of VOP2/VOPC short forms (v_cndmask_b32 vD, s0, s1,v_add_co_ci_u32_e32 vD, vcc, s0, s1,v_cmp_class_f32_e32 s0, s1), the VDST of a FLAT-family atomic withoutglc(or withlds), and the VDATA of a buffer/FLAT-family load withlds(LLVM printsbuffer_load_dword v0, s[4:7], 0 offen lds).NOOPSand mnemonics outside the tables are not checked.Gen.insn, i.e. only for instructions that are actually lowered: words afters_endpgm(embedded constant tables, which can decode into short lines) are untouched, as onmain. Cost: one or two dict lookups per lowered instruction (~0.5 us).Unsupported("<op>: expects N operands, got M");test_insn_no_operands.py's expected message changes accordingly (v_add_f32: expects 3 operands, got 0).Note: the first commit's message says LLVM always prints every operand; that is not quite true (the MUBUF
ldsform above), which the second commit handles and documents. Squash on merge if preferred.No
docs/design.mdcontract row: this is input validation and changes no emitted SPIR-V (the previous no-operand conversion had none either).Tested
tests/semantic/test_insn_operand_count.py: 11 short lines across the reported crash sites (Gen._insn,v_max3/v_med3unpacking,compare,sop2_b32_srcs,holds_lane_mask,scalar_load,buffer_address,lds_op, a shortglobal_load_dword,v_cndmask_b32_e64with 3 operands) assert the exact message; complete lines and the short assembler forms still translate; an LLVMldsbuffer load keeps itsbuffer_load_dword formrejection; short junk afters_endpgmstill translates.tools/rdna2spirv.pyrestored frommain): the new file fails 11 subtests (IndexError/ValueError, andv_cndmask_b32_e64 v0, v1, v2silently translating). Reproduced independently by the reviewer agent in a throwaway worktree.test_insn_no_operands,test_wave64_halves_soundness,test_valu_f32_class_rndne,test_sdwa_carry,test_scalar_noop_waitcntpass.python -I scripts/run_semantic_tests.py tests/semantic-> 561 files, 6758 tests, 0 files failed.off,lds, atomics with/without glc), GLOBAL/SCRATCH/FLAT, DS (gds, swizzle), MIMG (bvh, msaa, bracketed addresses): 0 rejected. 1.6M random encodings throughrdna2_decode->format_insn->parse_line-> the check: only the decoder's VOP2madak/madmk/fmaak/fmamk_dpp/_sdwaforms, which LLVM rejects as invalid encodings (posted as a separate finding; they are only checked if actually lowered). All 16,456 instruction lines of the repo's 393.asmfiles pass, except a branch to a label nameddonethat never reachesGen.insn(separate finding:MODWORDSstripsdone).python -m compileall -q make_game.py tools tests;python -m unittest discover -s tests -p "test_docs_*.py"(57 OK);python -I scripts/check_no_game_data.py.GPUs tested: n/a (translator input validation; no SPIR-V change, CPU-only tests)
AI-assisted: yes. Implementation: Claude Opus 5.5 (Claude Code). Independent read-only reviewer agent: Claude Opus 5.5 - first pass "changes needed" (check ran on unreachable code;
ldsloads mislabelled; shortglobal_loadstill crashed; encoding-blind minimum), all addressed in the second commit; second pass approve, remaining nits applied or noted here.Follow-up noted by the reviewer (not in this PR):
explicit_carry_vccexpands a 3-operandv_*_co_ci_u32_e64line as if it were the VOP2 short form, so that malformed_e64line still translates (same asmain).Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a: input validation, no new lowering rule)🤖 Generated with Claude Code
Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-12-02T23:36:41Z.
Review: COMMENTED
Two paths still bypass the new operand check on
31b96e3bmerged withmainat81efe4566. I reproduced both throughsupport.translate_lines()with a synthetic pixel shader.s_setreg_imm32_b32ands_setreg_b32with zero operands raiseIndexErrorin the rounding-mode scan attools/rdna2spirv.py:22498. The direct count check already gives “expects 2 operands, got 0”, but translation indexesargs[0]before it reaches that check.v_add_co_ci_u32_e64 v0, v1, v2and the corresponding sub instruction translate silently.explicit_carry_vcc()at line 21151 inserts both VCC operands beforeGen.insn()validates the count. The raw count check gives “expects 5 operands, got 3”. LLVMllvm-mcforgfx1010rejects the short_e64spelling and assembles the five-operand form. LLVM GFX10 instruction syntaxIn a scratch copy, checking that the rounding-mode scan has an operand and restricting implicit VCC expansion to the unsuffixed or short encodings made all four inputs produce the intended
Unsupporteddiagnostic. The complete_e64and short_e32forms still emitted byte-identical SPIR-V, and 13 focused tests passed. AI-assisted.Imported from ubiquitarianism/leonida. Originally posted by DeadlyChirp on 2026-12-02T23:45:11Z.
Independent Windows reproduction on PR head
31b96e3ba3c4c9b35c5dd92a50c6a5cc07a600f5(Windows 11, Python 3.12.10):test_dpp_invalid_opcodes_and_boundary_modifiersfails at line 307: the “Missing DPP control” case callsGen.insnwith zero operands, so the new operand check raisesv_mov_b32_dpp: expects 2 operands, got 0before the DPP-control validation; the expectedDPP controlregex therefore does not match. This matches the failingtests/test_rdna2spirv_decode.pycheck in CI. Supplying two synthetic VGPR operands in this case would let it exercise the DPP-control path, while the separate operand-count test continues covering zero operands. No game data or GPU used.Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-12-03T00:03:27Z.
VERIFY-3266 — Windows nativo:
red then greenen los dos ficheros de test8cdd86ac1—tests/semantic/test_insn_operand_count.py(+19),tests/test_rdna2spirv_decode.py(10),tools/rdna2spirv.pyRan at the head
Negative control: the commit's own hunk does not revert cleanly (the branch carries a merged
main), so I putmain'stools/rdna2spirv.pyback and re-ran both:Three bite, and they are the two halves of the change: the message names the op, and a line that is short but not empty is not "no operands".
What the change is, and it is a good distinction: before, any instruction whose operands could not be read raised
Unsupported("<op>: no operands")— including a line that had operands, just fewer than its ISA table entry expects. Nowcheck_operand_countssays"<op>: expects N operands, got 0"for a mnemonic in the ISA tables, andGen.insnkeeps"no operands"for another mnemonic — soindex.json, which is built from these, points at the right instruction for the right reason.And the exemption list is the part that shows it was thought through:
s_endpgm,v_nop,v_clrexcp,ds_nop,s_barrierin compute stay untouched — "their ISA table entries have no operands and they never fail an operand read". A rule that says "zero operands is an error" would have flagged every one of them, and the comment says why they are not.What I could not test
Written with an AI assistant.
Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-12-03T00:05:17Z.
Review: COMMENTED
Rechecked
8cdd86acmerged ontomainat81efe4566. All six newly covered cases fail with the prior translator (31b96e3b) and pass with this head. That covers the two emptys_setregforms, the three short_e64carry forms, and the empty vertex export. The valid rounding-mode write, full_e64carry and short_e32carry still produce identical SPIR-V in the focused comparison.The DPP fixture now reaches the intended modifier diagnostics. All 25 decoder tests pass, and the full Linux semantic run completed 6,796 tests across 561 files with zero file failures.
I also checked the integration with the symbolic-branch parser fix #3215 (
d0fc19927). The heads merge cleanly. The parser, decoder, operand-count and control-flow branch suites all passed on the combined tree (68 tests). All checks here used synthetic fixtures. AI-assisted.Imported from ubiquitarianism/leonida. Originally posted by aegish-zagi on 2026-12-03T04:48:10Z.
VERIFY-3266 — PASS
PR #3266 | head
8cdd86ac19| merged cleanly with current main (d9b618f10) in a scratch worktree, no conflictsTests run: tests/semantic/test_insn_no_operands.py, tests/semantic/test_insn_operand_count.py, tests/test_rdna2spirv_decode.py (python -I, stdlib unittest)
Red on main: all three files FAILED on main code with the PR's tests (failures=1, failures=17, failures=1) — MEASURED
Green on PR: all three files OK after merge (4 + 5 + 25 tests) — MEASURED
Diff audit: 4 files, tools/rdna2spirv.py + 3 test files only; operand-count refusal before lowering, no game data (check_no_game_data.py clean on the touched files) — READ IN CODE
Platform: Linux, Python 3.12.3, no GPU
AI-assisted: yes (Muse Wonder, Muse by Meta)
Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-12-03T06:31:00Z.
Windows native verification (
red -> green) -- PASS on head8cdd86ac1(merged cleanly viagit merge --no-ffontomaind9b618f10).Checks (Windows 10 x64, Python 3.12, PowerShell 5.1)
python -I scripts/check_no_game_data.py-> PASSpython -I tests/test_rdna2spirv_decode.py -v-> Ran 25 tests in 0.088s / OKpython -I tests/semantic/test_insn_no_operands.py -v-> Ran 4 tests in 0.134s / OKpython -I tests/semantic/test_insn_operand_count.py -v-> Ran 5 tests in 0.194s / OKtools/rdna2spirv.pytomaind9b618f10, keeping the PR's tests):tests/test_rdna2spirv_decode.py-> Ran 25 tests in 0.081s / FAILED (failures=1) (exit1)tests/semantic/test_insn_no_operands.py-> Ran 4 tests in 0.088s / FAILED (failures=1) (exit1)tests/semantic/test_insn_operand_count.py-> Ran 5 tests in 0.188s / FAILED (failures=17) (exit1)AI-assisted: yes (Antigravity -- Gemini 4 Neon).