rdna2spirv: re-anchor from llvm-mc's own offsets of the rejected words (SHADER-REANCHOR-LLVM-OFFSETS) #985

Merged
Tyrannys merged 1 commit from upstream-pr/985 into main 2026-11-24 23:42:48 +00:00
Tyrannys commented 2026-11-24 16:25:06 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Tyrannys on 2026-11-24T16:25:06Z.


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 with undecodable words (cannot re-anchor).

Fix. llvm-mc already says where it rejected each word. tools/shader_disasm.py feeds it one line of 0xNN bytes (5 characters a byte), so the message column gives the byte offset.

  • tools/shader_ir.py: parse_file returns invalid_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):

  • new tests/semantic/test_reanchor_llvm_offsets.py: parse_file reads 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 raises cannot re-anchor on 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.
  • Full suite on this branch: 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 on main without this change.

AI-assisted (Claude Code). Windows 11, RTX 4070 SUPER; CPU-only checks.

🤖 Generated with Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5476122407 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/985). Originally posted by [Tyrannys](https://github.com/Tyrannys) on 2026-11-24T16:25:06Z. --- 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 with `undecodable words (cannot re-anchor)`. **Fix.** llvm-mc already says where it rejected each word. `tools/shader_disasm.py` feeds it one line of `0xNN ` bytes (5 characters a byte), so the message column gives the byte offset. - `tools/shader_ir.py`: `parse_file` returns `invalid_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): - new `tests/semantic/test_reanchor_llvm_offsets.py`: `parse_file` reads 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 raises `cannot re-anchor` on 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. - Full suite on this branch: `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 on `main` without this change. AI-assisted (Claude Code). Windows 11, RTX 4070 SUPER; CPU-only checks. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
morodirule commented 2026-11-24 16:29:41 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by morodirule on 2026-11-24T16:29:41Z.


Independent Linux check (no game files, no GPU, stdlib only): the new tests/semantic/test_reanchor_llvm_offsets.py passes 3/3 on head 2f5b49c4e. 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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7137752469 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/985#issuecomment-7137752469). Originally posted by [morodirule](https://github.com/morodirule) on 2026-11-24T16:29:41Z. --- Independent Linux check (no game files, no GPU, stdlib only): the new tests/semantic/test_reanchor_llvm_offsets.py passes 3/3 on head 2f5b49c4e. 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 commented 2026-11-24 16:35:19 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by KernelSmoker on 2026-11-24T16:35:19Z.

Review: APPROVED


Reviewed exact head 2f5b49c4e0. Cherry-picked onto current upstream main 42d705c85b 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.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6043362151 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/985#pullrequestreview-6043362151). Originally posted by [KernelSmoker](https://github.com/KernelSmoker) on 2026-11-24T16:35:19Z. **Review:** APPROVED --- Reviewed exact head 2f5b49c4e03c6a1fb09098c4eaf54fe4e732907a. Cherry-picked onto current upstream main 42d705c85bdb4a8450c2e576bca7bee8d6770c93 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.
towade commented 2026-11-24 17:24:05 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by towade on 2026-11-24T17:24:05Z.


checked: 2f5b49c4e merged with #674 (688674095) on the full 1.0.2.1 pipeline library (2,684 compute programs), Windows 11, llvm-mc 21.1.8, spirv-val (Vulkan SDK 1.4.363), --wave64-emulate. Counts only.

  • #674 alone: 2,599 translated, all pass spirv-val.
  • #674 + this PR: 2,608, all pass spirv-val. That is 9 more, and none that #674 translates is lost. The 1,685 that main translates stay byte-identical.
  • In a retail boot on an RX 9070 XT, 9 of the 1,142 library programs the title asks for that a main library lacks are covered only with this PR: 1,061 with #674 alone, 1,070 with both. Details on #674.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7139137841 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/985#issuecomment-7139137841). Originally posted by [towade](https://github.com/towade) on 2026-11-24T17:24:05Z. --- checked: `2f5b49c4e` merged with #674 (`688674095`) on the full 1.0.2.1 pipeline library (2,684 compute programs), Windows 11, `llvm-mc` 21.1.8, `spirv-val` (Vulkan SDK 1.4.363), `--wave64-emulate`. Counts only. - #674 alone: 2,599 translated, all pass `spirv-val`. - #674 + this PR: **2,608**, all pass `spirv-val`. That is 9 more, and none that #674 translates is lost. The 1,685 that `main` translates stay byte-identical. - In a retail boot on an RX 9070 XT, 9 of the 1,142 library programs the title asks for that a `main` library lacks are covered only with this PR: 1,061 with #674 alone, 1,070 with both. Details on [#674](https://github.com/ubiquitarianism/leonida/pull/674). AI-assisted (Claude Code).
madhyn commented 2026-11-24 22:45:11 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by madhyn on 2026-11-24T22:45:11Z.


Tested 2f5b49c4e on Arch Linux (CPU):

  • python3 -m unittest tests/semantic/test_reanchor_llvm_offsets.py -v: 3/3 passed (0.006 s).
  • git diff --check origin/main...HEAD: clean.

Not tested: GPU / full corpus. AI-assisted: yes

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7146602923 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/985#issuecomment-7146602923). Originally posted by [madhyn](https://github.com/madhyn) on 2026-11-24T22:45:11Z. --- Tested `2f5b49c4e` on Arch Linux (CPU): - `python3 -m unittest tests/semantic/test_reanchor_llvm_offsets.py -v`: **3/3 passed** (0.006 s). - `git diff --check origin/main...HEAD`: clean. Not tested: GPU / full corpus. AI-assisted: yes
QemmHD commented 2026-11-24 23:42:45 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by QemmHD on 2026-11-24T23:42:45Z.


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:

  • morodirule: 2 of the 3 new cases fail on the old translator;
  • KernelSmoker: semantic suite 471 files / 6168 tests, 0 failed;
  • towade: on a full pipeline library, 2,608 programs translate versus 2,599 before, all pass spirv-val, and none are lost;
  • madhyn: 3/3.

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 e0b08c77d: 476 files / 6219 tests. The single failing file is test_image_cube_store_glc, which also fails on main (475 / 6216) because llvm-mc is given a Windows path here (#837). So the only difference is this PR's own new file, and nothing regressed. Its own tests: 3 passed. The repo-consistency set gives 578 passed / 5 skipped / 0 failed, and full ctest on the cumulative build is 317/318 (only the pre-existing d3d12_depth_resolve). git merge-tree against current main: no conflicts. Security read: no new tools file, no binaries, downloads or CI changes.

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7147710099 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/985#issuecomment-7147710099). Originally posted by [QemmHD](https://github.com/QemmHD) on 2026-11-24T23:42:45Z. --- 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: - morodirule: 2 of the 3 new cases fail on the old translator; - KernelSmoker: semantic suite 471 files / 6168 tests, 0 failed; - towade: on a full pipeline library, 2,608 programs translate versus 2,599 before, all pass spirv-val, and none are lost; - madhyn: 3/3. **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 e0b08c77d: 476 files / 6219 tests. The single failing file is `test_image_cube_store_glc`, which also fails on main (475 / 6216) because llvm-mc is given a Windows path here (#837). So the only difference is this PR's own new file, and nothing regressed. Its own tests: 3 passed. The repo-consistency set gives 578 passed / 5 skipped / 0 failed, and full ctest on the cumulative build is 317/318 (only the pre-existing d3d12_depth_resolve). git merge-tree against current main: no conflicts. Security read: no new tools file, no binaries, downloads or CI changes. AI-assisted (Claude Code, Claude Opus 5.5).
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!985
No description provided.