Repository navigation
rdna2spirv: re-anchor from llvm-mc's own offsets of the rejected words (SHADER-REANCHOR-LLVM-OFFSETS) - #985
Conversation
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 ProjectLeonida#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>
|
Independent Linux check (no game files, no GPU, stdlib only): the new tests/semantic/test_reanchor_llvm_offsets.py passes 3/3 on head 2f5b49c. The same test file against the unmodified translator fails 2/3 — Unsupported("undecodable words (cannot re-anchor)") plus a missing info["invalid_at"] key — so the test exercises the change and the old code path reads as before. Hand-built encodings only. Not claiming; review evidence. |
KernelSmoker
left a comment
There was a problem hiding this comment.
Reviewed exact head 2f5b49c. Cherry-picked onto current upstream main 42d705c without conflicts. The new llvm-offset regression suite passed 3/3; full semantic suite passed 471 files / 6,168 tests / 0 failures in Fedora 45 with SPIRV-Tools. Python compile, docs-design rows 5/5, docs links 16/16, no-game-data scan and diff check passed. Synthetic shader bytes only; no GPU/game-data validation is claimed. Hosted checks were queued when checked.
|
checked:
AI-assisted (Claude Code). |
|
Tested
Not tested: GPU / full corpus. AI-assisted: yes |
|
Merging. Why merged: SHADER-REANCHOR-LLVM-OFFSETS: shader_ir parses llvm-mc's "invalid instruction encoding" column offsets. rdna2spirv anchors on those exact offsets only when every rejected word has a parsed offset; otherwise it keeps the old forward search. Reviewers:
Why it's good: this changes translator output, so I held it for the full semantic suite. On Windows 11, cumulative with this batch on main e0b08c7: 476 files / 6219 tests. The single failing file is AI-assisted (Claude Code, Claude Opus 5.5). |
Item: SHADER-REANCHOR-LLVM-OFFSETS (claimed in #14).
Problem. After undecodable words,
translate()puts each printed instruction back at its offset in the blob by searching forward for its printed bytes. A data word that llvm-mc printed as a copy of a later instruction (its printed bytes are not the bytes it read) matches that later instruction, takes its place, and every instruction after it loses its place. The shader then fails withundecodable words (cannot re-anchor).Fix. llvm-mc already says where it rejected each word.
tools/shader_disasm.pyfeeds it one line of0xNNbytes (5 characters a byte), so the message column gives the byte offset.tools/shader_ir.py:parse_filereturnsinvalid_at, the sorted offsets (code_start + (column - 1) // 5).tools/rdna2spirv.py: when there is one offset per rejected word, re-anchoring skips exactly those words and never searches forward. The literal-restoring paths (mix_literal,mix_inline_literal) are kept. A listed offset whose bytes are the next instruction is not skipped, so a listing whose messages do not match its blob (or hand-written tests with a placeholder message) reads as before. Without offsets, the old search runs unchanged.Effect. On the 1.0.2.1 pipeline library (2,684 compute programs), with #327 / #596's vcc-tuple decoding applied: 36 programs that stopped at "cannot re-anchor" now translate and pass
spirv-val, and none that translated before is lost. With #596 and #647 as well, the library goes from 2,396 to 2,560 translated in our runs (that total includes #583's 49). Several of these are compute programs the retail boot creates through slot 67.Tests (synthetic, no game data):
tests/semantic/test_reanchor_llvm_offsets.py:parse_filereads the offset; a data word printed as a copy of the next real instruction (behind a branch) no longer displaces it, and the pixel shader writes the expected value (the old search raisescannot re-anchoron the same listing); a message that names the instruction's own bytes falls back to the old behaviour.docs/design.md: the "Code-embedded data" row says how re-anchoring uses the offsets, with the count.python -I scripts/run_semantic_tests.py tests/semantic: 465 files, 6,108 tests; 1 file fails,test_image_cube_store_glc, which fails the same onmainwithout this change.AI-assisted (Claude Code). Windows 11, RTX 4070 SUPER; CPU-only checks.
🤖 Generated with Claude Code