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

Closed
opened 2026-11-26 20:19:49 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/985
Author: @Tyrannys
Created: 11/24/2026
Status: ✅ Merged
Merged: 11/25/2026
Merged by: @QemmHD

Base: main ← Head: fix/reanchor-from-llvm-offsets


📝 Commits (1)

  • 2f5b49c rdna2spirv: re-anchor from llvm-mc's own offsets of the rejected words

📊 Changes

4 files changed (+115 additions, -1 deletions)

View changed files

📝 docs/design.md (+1 -1)
➕ tests/semantic/test_reanchor_llvm_offsets.py (+84 -0)
📝 tools/rdna2spirv.py (+26 -0)
📝 tools/shader_ir.py (+4 -0)

📄 Description

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


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/985 **Author:** [@Tyrannys](https://github.com/Tyrannys) **Created:** 11/24/2026 **Status:** ✅ Merged **Merged:** 11/25/2026 **Merged by:** [@QemmHD](https://github.com/QemmHD) **Base:** `main` ← **Head:** `fix/reanchor-from-llvm-offsets` --- ### 📝 Commits (1) - [`2f5b49c`](https://github.com/ubiquitarianism/leonida/commit/2f5b49c4e03c6a1fb09098c4eaf54fe4e732907a) rdna2spirv: re-anchor from llvm-mc's own offsets of the rejected words ### 📊 Changes **4 files changed** (+115 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `docs/design.md` (+1 -1) ➕ `tests/semantic/test_reanchor_llvm_offsets.py` (+84 -0) 📝 `tools/rdna2spirv.py` (+26 -0) 📝 `tools/shader_ir.py` (+4 -0) </details> ### 📄 Description 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) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:19:49 +01:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#1020
No description provided.