Repository navigation
Conversation
… vcc from the blob when llvm-mc rejects them llvm-mc skips the first word of s_buffer_load_dwordx8 into s[100:107], an image resource in s[100:107] or a buffer resource in s[104:107] and leaves the second word as junk, so translate() refused those shaders (reachable instruction with normalized encoding) or translated them without the load. restore_vcc_tuples reads the uncovered words of the code range with rdna2_decode and keeps only instructions whose operands hold a VCCTuple list, the form the translator already takes. Other undecodable words are unchanged.
|
I compared six synthetic gfx1013 FSPX programs with real llvm-mc 19.1.7 and 23.1.5. LLVM 23 printed the explicit VCC register lists and preserved their bytes. LLVM 19 exposed a missing case in the submitted patch. After rejecting a scalar load, it can decode the second dword as I published a follow-up that recovers that successor and keeps variable-length image recovery inside the declared code range. All six modules validated for Vulkan 1.2 under both toolchains. The five buffer cases returned the expected words on an RTX 4070 Ti. The image case verified descriptor lookup and module validity. I did not measure the retail corpus. Fixture, measured outputs and patch instructions. The second mailbox commit applies on top of tedin7’s change. |
|
Measured on a real
This branch is based on 976 of the 2,684 listings have invalid words. In a sample of 40 refused programs, the invalid words I decoded by hand are SMEM loads whose tuple runs into vcc: I'm happy to rerun on the real corpus if you push changes. AI-assisted (Claude Code). |
|
Follow-up on top of this PR, for you to take if useful: Tyrannys@07f4dd738 (branch
Numbers, 1.0.2.1 pipeline library (2,684 programs, Suite: Left in the library after both: 91 "CS thread-group-size SGPR", 73 "s_load_dwordx4 operands sgpr vcc", 51 "fall-through into undecodable words", 28 AI-assisted (Claude Code). |
|
Tested
|
|
A follow-up measured on top of this branch (063f14d), Windows 11, llvm-mc 21.1.8, What still fails, and why. Of the library programs this branch still refuses, nearly all report Suggested change: after restoring, decode from the end of each restored instruction with diff --git a/tools/rdna2spirv.py b/tools/rdna2spirv.py
index 71317aeac..056584e55 100644
--- a/tools/rdna2spirv.py
+++ b/tools/rdna2spirv.py
@@ -17025,7 +17025,26 @@ def restore_vcc_tuples(insns, blob, code_start, code_end):
return insns
spans = [(r["pc"], r["pc"] + len(r["enc"]) // 2) for r in restored]
kept = [i for i in insns if not any(i["pc"] < hi and i["pc"] + len(i["enc"]) // 2 > lo for lo, hi in spans)]
- return sorted(kept + restored, key=lambda i: i["pc"])
+ # The junk llvm-mc printed from a restored instruction's second word can run past it and swallow the next real
+ # instruction's words; those words were "covered" only by the dropped junk. Decode from the end of each restored
+ # instruction until the stream meets the start of a kept instruction again.
+ starts = {i["pc"] for i in kept}
+ kept_words = set()
+ for i in kept:
+ kept_words.update(range(i["pc"], i["pc"] + len(i["enc"]) // 2, 4))
+ refill = []
+ restored_pcs = {r["pc"] for r in restored}
+ for lo, hi in spans:
+ at = hi
+ while at + 4 <= stop and at not in starts and at not in kept_words and at not in restored_pcs:
+ got = rdna2_decode.decode_bytes(blob[at:at + 20])["insns"][:1]
+ if not got or got[0]["pc"] != 0:
+ break
+ ins = got[0]
+ ins["pc"] = at
+ refill.append(ins)
+ at += len(ins["enc"]) // 2
+ return sorted(kept + restored + refill, key=lambda i: i["pc"])
def output_signature(path, name):Measured: two random samples of the programs this branch still refuses, 40 and 120 programs: 8/40 and 11/120 now translate, all passing What the rest is. Every remaining failure in both samples falls through right after an AI-assisted (Claude Code); measured on our copy, nothing of the game posted. |
|
Tested
With LLVM 23.1.5 listings the change has no effect on either base. The listings are identical and so is the output.
On 23.1.5, main still refuses 76 programs, and none of the refusals is a vcc tuple. So whatever this PR still adds would show up only with older AI-assisted. |
After undecodable words, translate() put each printed instruction back at its blob offset by searching forward for its printed bytes. A data word llvm-mc printed as a copy of a later instruction (printed bytes are not the bytes read) took that later instruction's place, and every instruction after it lost its place: "undecodable words (cannot re-anchor)". shader_ir.parse_file now reads the byte offset of each rejected word from the llvm-mc messages (shader_disasm.py feeds one line of "0xNN " bytes, five characters a byte) as info["invalid_at"]. When there is one offset per rejected word, the translator skips exactly those words and searches nothing; a listed word whose bytes are the next instruction is not skipped, so a listing with wrong or hand-written messages reads as before. On the 1.0.2.1 pipeline library, with #327's vcc-tuple decoding, 36 compute programs that stopped at "cannot re-anchor" now translate and pass spirv-val; none that translated before is lost. AI-assisted (Claude Code). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Original description (mentions and
#Nreferences are disabled; the numbers refer to the old repository):What
tools/rdna2spirv.py: a scalar-memory, image or buffer instruction whose register tuple runs intovcc(SGPRs 106 and 107) is now decoded from the shader blob when llvm-mc rejects it. Newrestore_vcc_tuplesreads the blob dwords of the code range that no matched instruction covers with the existing pure-Pythonrdna2_decode, keeps an instruction only if one of its operands is a[s100,...,vcc_lo,vcc_hi]list (the form the translator already takes), and drops the junk instructions llvm-mc printed inside its two words. Every other undecodable word behaves as before.Why
docs/shader_library.mdsection 5 lists this as the largest refusal in the pipeline library: "reachable instruction with normalized encoding",s_load_dwordx8/x4/x16intos[100:107]/s[104:107]/s[92:107], and image or buffer resources in those tuples (about 2,533 programs per that document; I cannot measure the realshaders.rpfand did not try). llvm-mc skips the first word as invalid and prints the second as junk, sotranslate()refused the shader, or, when the junk matched the blob, translated it with the load silently missing.Tested
Synthetic words only, no game files.
tests/semantic/test_vcc_tuple_fallback.py(new): llvm-mc 19 encodings with the register field patched into vcc, run on the CPU interpreter. Three shapes, each with the three ways the listing can show the rejected words (both invalid, second word printed as a matching junk instruction, second word printed with another encoding):s_buffer_load_dwordx8 [s100..s105,vcc_lo,vcc_hi]: the store of s100, s105, vcc_lo, vcc_hi gives the four expected words (9 sub-cases across the file, 4 tests).[s104,s105,vcc_lo,vcc_hi]read bys_buffer_load_dwordand bybuffer_load_dword: loads 0xCAFE1234 and 0xBEEF5678.image_loadwith the T# in[s100..vcc_hi]: translates through the descriptor lookup.Results: the new file 4 tests, 9 translations also pass
spirv-as+spirv-val --target-env vulkan1.2(0 errors). Neighbours:test_fspx_rules.py9 OK,test_printed_encoding.py7 OK,tests/test_rdna2spirv_decode.py25 OK,tests/test_rdna2_decode.py17 OK (1 skipped),test_fma_mix_literal.py18 OK,tests/test_shader_library.py13 OK, fivetest_docs_*files OK.Negative control: with the one-line call to
restore_vcc_tuplesremoved (that is the behaviour of main), 9 sub-cases fail: "fall-through into undecodable words" for the two listings with no or matching junk and "reachable instruction with normalized encoding" for the third, the message the doc reports.Not verified: llvm-mc 23 is not available here (only 19, which rejects these words as invalid), so a listing where llvm-mc 23 prints the tuple one lower with another encoding (not "invalid") goes through
check_printed_encodingsand is not covered by this PR. The translated shaders were not run on a GPU. The real library counts were not re-measured.Lane:
tools/rdna2spirv.pyand a doc sentence only.