[PR #327] [CLOSED] fix: rdna2spirv decodes scalar, image and buffer tuples that run into vcc, so the pipeline-library shaders translate #379

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

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/327
Author: @Andretuta
Created: 11/24/2026
Status: ❌ Closed

Base: main ← Head: old-pr/10062


📝 Commits (1)

  • 063f14d fix: rdna2spirv decodes scalar, image and buffer tuples that run into vcc from the blob when llvm-mc rejects them

📊 Changes

3 files changed (+190 additions, -3 deletions)

View changed files

📝 docs/shader_library.md (+5 -3)
➕ tests/semantic/test_vcc_tuple_fallback.py (+149 -0)
📝 tools/rdna2spirv.py (+36 -0)

📄 Description

Carried over from old PR 10062 by tedin7 in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch old-pr/10062, exactly that PR's last commit. All carried-over PRs are listed in #17.
Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it.
tedin7: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one.


Original description (mentions and #N references are disabled; the numbers refer to the old repository):

What

tools/rdna2spirv.py: a scalar-memory, image or buffer instruction whose register tuple runs into vcc (SGPRs 106 and 107) is now decoded from the shader blob when llvm-mc rejects it. New restore_vcc_tuples reads the blob dwords of the code range that no matched instruction covers with the existing pure-Python rdna2_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.md section 5 lists this as the largest refusal in the pipeline library: "reachable instruction with normalized encoding", s_load_dwordx8/x4/x16 into s[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 real shaders.rpf and did not try). llvm-mc skips the first word as invalid and prints the second as junk, so translate() 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).
  • V# in [s104,s105,vcc_lo,vcc_hi] read by s_buffer_load_dword and by buffer_load_dword: loads 0xCAFE1234 and 0xBEEF5678.
  • image_load with the T# in [s100..vcc_hi]: translates through the descriptor lookup.
  • A rejected word that is not a tuple into vcc is still refused ("fall-through into undecodable words").

Results: the new file 4 tests, 9 translations also pass spirv-as + spirv-val --target-env vulkan1.2 (0 errors). Neighbours: test_fspx_rules.py 9 OK, test_printed_encoding.py 7 OK, tests/test_rdna2spirv_decode.py 25 OK, tests/test_rdna2_decode.py 17 OK (1 skipped), test_fma_mix_literal.py 18 OK, tests/test_shader_library.py 13 OK, five test_docs_* files OK.

Negative control: with the one-line call to restore_vcc_tuples removed (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_encodings and 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.py and a doc sentence only.


🔄 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/327 **Author:** [@Andretuta](https://github.com/Andretuta) **Created:** 11/24/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `old-pr/10062` --- ### 📝 Commits (1) - [`063f14d`](https://github.com/ubiquitarianism/leonida/commit/063f14dcd944170efb6cf907cdb9cd5ca57d8da9) fix: rdna2spirv decodes scalar, image and buffer tuples that run into vcc from the blob when llvm-mc rejects them ### 📊 Changes **3 files changed** (+190 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `docs/shader_library.md` (+5 -3) ➕ `tests/semantic/test_vcc_tuple_fallback.py` (+149 -0) 📝 `tools/rdna2spirv.py` (+36 -0) </details> ### 📄 Description > Carried over from **old PR 10062** by `tedin7` in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch `old-pr/10062`, exactly that PR's last commit. All carried-over PRs are listed in #17. > Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it. > `tedin7`: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one. --- Original description (mentions and `#N` references are disabled; the numbers refer to the old repository): ## What `tools/rdna2spirv.py`: a scalar-memory, image or buffer instruction whose register tuple runs into `vcc` (SGPRs 106 and 107) is now decoded from the shader blob when llvm-mc rejects it. New `restore_vcc_tuples` reads the blob dwords of the code range that no matched instruction covers with the existing pure-Python `rdna2_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.md` section 5 lists this as the largest refusal in the pipeline library: "reachable instruction with normalized encoding", `s_load_dwordx8/x4/x16` into `s[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 real `shaders.rpf` and did not try). llvm-mc skips the first word as invalid and prints the second as junk, so `translate()` 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). - V# in `[s104,s105,vcc_lo,vcc_hi]` read by `s_buffer_load_dword` and by `buffer_load_dword`: loads 0xCAFE1234 and 0xBEEF5678. - `image_load` with the T# in `[s100..vcc_hi]`: translates through the descriptor lookup. - A rejected word that is not a tuple into vcc is still refused ("fall-through into undecodable words"). Results: the new file 4 tests, 9 translations also pass `spirv-as` + `spirv-val --target-env vulkan1.2` (0 errors). Neighbours: `test_fspx_rules.py` 9 OK, `test_printed_encoding.py` 7 OK, `tests/test_rdna2spirv_decode.py` 25 OK, `tests/test_rdna2_decode.py` 17 OK (1 skipped), `test_fma_mix_literal.py` 18 OK, `tests/test_shader_library.py` 13 OK, five `test_docs_*` files OK. **Negative control**: with the one-line call to `restore_vcc_tuples` removed (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_encodings` and 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.py` and a doc sentence only. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:17:41 +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#379
No description provided.