[PR #1301] [CLOSED] rdna2spirv: keep the stored op_sel_hi of a signed-byte dot with an inline integer (SHADER-FFX-PACKED-DOT) #1331

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

📋 Pull Request Information

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

Base: main ← Head: split/shader-ffx-packed-dot


📝 Commits (1)

  • 62e1245 rdna2spirv: keep the stored op_sel_hi of a signed-byte dot with an inline integer (SHADER-FFX-PACKED-DOT)

📊 Changes

3 files changed (+55 additions, -2 deletions)

View changed files

📝 docs/design.md (+3 -0)
📝 tests/semantic/test_printed_encoding.py (+50 -2)
📝 tools/rdna2spirv.py (+2 -0)

📄 Description

Rebased onto bfef489c at 62e1245f. Main already restores the stored selector. This diff limits that recovery to a plain four-operand listing and preserves the encoding regression tests. Nine focused tests passed.

Claimed in the coordination issue as: SHADER-FFX-PACKED-DOT (claim).

Part of the split of #984 into small pull requests.

Depends on: none
Overlaps: #984 is the parent integration. #281 (open, draft) makes tools/shader_disasm.py print the v_dot4_i32_i8 words with op_sel 2 / op_sel_hi 5 that llvm-mc rejects; that half of the integration's packed-dot work is left to #281 and is not repeated here. This pull request is about the words llvm-mc does decode (op_sel 0) and prints without their op_sel_hi, which #281 leaves alone ("a pair llvm-mc accepted is never touched"). The two change different files (#281: tools/shader_disasm.py, docs/fspx.md, two test files; this: tools/rdna2spirv.py, docs/design.md, tests/semantic/test_printed_encoding.py).

What and why

llvm-mc prints no op_sel_hi on v_dot4_i32_i8 and re-encodes the instruction with the default 7. Measured with llvm-mc 23.1.5 for gfx1030 and gfx1036, every op_sel x op_sel_hi combination, with a VGPR, an SGPR, an inline integer and a 32-bit literal as S1:

stored llvm-mc
op_sel 0, op_sel_hi 7 the plain line, printed encoding equal to the stored bytes
op_sel 0, op_sel_hi 0..6 the same plain line, printed encoding with op_sel_hi 7
op_sel 1..7 invalid word (#281 prints the op_sel 2 / op_sel_hi 5 one)

So for a stored op_sel_hi other than 7 the listing shows an instruction the bytes do not hold. The translator already notices: the printed-encoding check refuses it, on a clean listing (a field the disassembler dropped) and on a listing with invalid words (reachable instruction with normalized encoding). That is the right default, because the selector changes the result (docs/design.md, "Signed-byte dot products": op_sel_hi[k] picks the 16-bit half of source k for byte pairs 2..3).

One of these forms is the one #984 repairs, in its notes on the FidelityFX upscaler's FSPX programs (docs/fspx.md): an inline integer S1 with op_sel_hi 5, that is op_sel_hi[1] clear, so byte pairs 2..3 read the low half of S1 again. An inline 10 is then the bytes 10, 0, 10, 0 instead of 10, 0, 0, 0. This pull request repairs exactly that form instead of refusing it (restore_dot4_inline_sel, called from both listing paths):

  • the text is the plain four-operand instruction with no modifier;
  • the stored word has opcode 0x16, no clamp, no neg, op_sel 0, op_sel_hi 5 and an inline integer in SRC1 (0..64, −1..−16);
  • the printed encoding differs from the stored one in word 1 bit 28 and nothing else.

The instruction then takes op_sel_hi:[1,0,1] and goes through the lowering that is already there. Every other dropped selector stays Unsupported, a register S1 with the same selector included.

Not measured on hardware. The half selection on this instruction was measured with a register S1 (op_sel 2 / op_sel_hi 5, the table in tests/semantic/test_alu_dot4_i8.py). That an inline integer is selected from as its 32-bit word is an assumption; the new contract row says so. One raw kernel through tools/hw_oracle (0xCC164008 0x0C0D1501, S0 = 0x00010001, S2 = 0: 20 if the assumption holds, 10 if the selector is ignored) would settle it. How many such words the real programs hold was not counted for this pull request.

Tested

Linux (CachyOS, kernel 7.3.5), Python 3.14, LLVM llvm-mc 23.1.5, SPIRV-Tools v2026.4. One commit on 6293c1c4f.

  • python3 -I tests/semantic/test_printed_encoding.py: 9 tests pass. The new test gives 20 for the stored selector and 10 for the default one (S0 = 0x00010001, S1 = 10, S2 = 0) on a clean listing and on one with an invalid word, and expects Unsupported for a changed S0, stored op_sel_hi 1, 3 and 4, clamp, neg_lo, neg_hi, a register S1 with op_sel_hi 5, and a listing text with clamp or without S2.
  • The same file with the translator of the base commit (LEONIDA_TOOLS_DIR=<export of 6293c1c4f>/tools): 2 errors, the two stored-selector subtests (Unsupported, the two messages quoted above). Everything else in the file passes there too.
  • python3 -I tests/semantic/test_alu_dot4_i8.py: 12 tests pass.
  • A sweep that is not part of the change: for each of the 81 inline integers, tools/shader_disasm.disasm (llvm-mc, gfx1030) made the listing of a five-instruction program with the dot stored with op_sel_hi 5 and with 7, once clean and once followed by an invalid word; each listing was translated against its bytes, run in the interpreter, assembled and validated with spirv-val. 324 of 324 give the expected word here. With the base translator the 162 default-selector listings do and the 162 with op_sel_hi 5 are refused.
  • The Python checks of ci.yml on the committed tree (compileall; each tests/test_*.py outside tests/semantic with python3 -I <file>, or pytest where it has no __main__; python3 -I scripts/run_semantic_tests.py tests/semantic -j 2; the tracked-file guard): one failing file, tests/test_imhex_patterns.py, which fails on the base commit too. Semantic suite: 470 files, 6,169 tests, 0 files failed (base: 470 files, 6,168 tests, 0 failed).
  • python3 -I scripts/check_no_game_data.py: passes.

Not run: a GPU, the hardware oracle, the real FSPX programs, native Windows or macOS, the runtime build (no C++ or build file changes).

GPUs tested: none (CPU interpreter and SPIRV-Tools only).

AI-assisted: yes (Claude Code). The numbers above come from runs on the machine named.

Checklist

  • Based on upstream main 6293c1c4f, one commit.
  • One topic: one repaired form, its test and its contract row.
  • No game data, keys or decryption; the test program and its bytes are hand-written.
  • The rule is in the contract table of docs/design.md ("Signed-byte dot with an inline integer S1"), with how it was checked and what is not measured.

🤖 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/1301 **Author:** [@Moriz82](https://github.com/Moriz82) **Created:** 11/24/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `split/shader-ffx-packed-dot` --- ### 📝 Commits (1) - [`62e1245`](https://github.com/ubiquitarianism/leonida/commit/62e1245ff58311e0de302c68f16e7fa9842b8d5b) rdna2spirv: keep the stored op_sel_hi of a signed-byte dot with an inline integer (SHADER-FFX-PACKED-DOT) ### 📊 Changes **3 files changed** (+55 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `docs/design.md` (+3 -0) 📝 `tests/semantic/test_printed_encoding.py` (+50 -2) 📝 `tools/rdna2spirv.py` (+2 -0) </details> ### 📄 Description **Rebased onto `bfef489c` at `62e1245f`.** Main already restores the stored selector. This diff limits that recovery to a plain four-operand listing and preserves the encoding regression tests. Nine focused tests passed. Claimed in the coordination issue as: SHADER-FFX-PACKED-DOT ([claim](https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7145070821)). Part of the split of #984 into small pull requests. Depends on: none Overlaps: #984 is the parent integration. #281 (open, draft) makes `tools/shader_disasm.py` print the `v_dot4_i32_i8` words with `op_sel` 2 / `op_sel_hi` 5 that llvm-mc rejects; that half of the integration's packed-dot work is left to #281 and is not repeated here. This pull request is about the words llvm-mc does decode (`op_sel` 0) and prints without their `op_sel_hi`, which #281 leaves alone ("a pair llvm-mc accepted is never touched"). The two change different files (#281: `tools/shader_disasm.py`, `docs/fspx.md`, two test files; this: `tools/rdna2spirv.py`, `docs/design.md`, `tests/semantic/test_printed_encoding.py`). ### What and why llvm-mc prints no `op_sel_hi` on `v_dot4_i32_i8` and re-encodes the instruction with the default 7. Measured with llvm-mc 23.1.5 for `gfx1030` and `gfx1036`, every `op_sel` x `op_sel_hi` combination, with a VGPR, an SGPR, an inline integer and a 32-bit literal as S1: | stored | llvm-mc | |---|---| | `op_sel` 0, `op_sel_hi` 7 | the plain line, printed encoding equal to the stored bytes | | `op_sel` 0, `op_sel_hi` 0..6 | the same plain line, printed encoding with `op_sel_hi` 7 | | `op_sel` 1..7 | invalid word (#281 prints the `op_sel` 2 / `op_sel_hi` 5 one) | So for a stored `op_sel_hi` other than 7 the listing shows an instruction the bytes do not hold. The translator already notices: the printed-encoding check refuses it, on a clean listing (`a field the disassembler dropped`) and on a listing with invalid words (`reachable instruction with normalized encoding`). That is the right default, because the selector changes the result (docs/design.md, "Signed-byte dot products": `op_sel_hi[k]` picks the 16-bit half of source k for byte pairs 2..3). One of these forms is the one #984 repairs, in its notes on the FidelityFX upscaler's FSPX programs (`docs/fspx.md`): an inline integer S1 with `op_sel_hi` 5, that is `op_sel_hi[1]` clear, so byte pairs 2..3 read the low half of S1 again. An inline 10 is then the bytes 10, 0, 10, 0 instead of 10, 0, 0, 0. This pull request repairs exactly that form instead of refusing it (`restore_dot4_inline_sel`, called from both listing paths): - the text is the plain four-operand instruction with no modifier; - the stored word has opcode 0x16, no `clamp`, no `neg`, `op_sel` 0, `op_sel_hi` 5 and an inline integer in SRC1 (0..64, −1..−16); - the printed encoding differs from the stored one in word 1 bit 28 and nothing else. The instruction then takes `op_sel_hi:[1,0,1]` and goes through the lowering that is already there. Every other dropped selector stays `Unsupported`, a register S1 with the same selector included. **Not measured on hardware.** The half selection on this instruction was measured with a register S1 (`op_sel` 2 / `op_sel_hi` 5, the table in `tests/semantic/test_alu_dot4_i8.py`). That an inline integer is selected from as its 32-bit word is an assumption; the new contract row says so. One raw kernel through `tools/hw_oracle` (`0xCC164008 0x0C0D1501`, S0 = 0x00010001, S2 = 0: 20 if the assumption holds, 10 if the selector is ignored) would settle it. How many such words the real programs hold was not counted for this pull request. ### Tested Linux (CachyOS, kernel 7.3.5), Python 3.14, LLVM `llvm-mc` 23.1.5, SPIRV-Tools v2026.4. One commit on `6293c1c4f`. - `python3 -I tests/semantic/test_printed_encoding.py`: 9 tests pass. The new test gives 20 for the stored selector and 10 for the default one (S0 = 0x00010001, S1 = 10, S2 = 0) on a clean listing and on one with an invalid word, and expects `Unsupported` for a changed S0, stored `op_sel_hi` 1, 3 and 4, `clamp`, `neg_lo`, `neg_hi`, a register S1 with `op_sel_hi` 5, and a listing text with `clamp` or without S2. - The same file with the translator of the base commit (`LEONIDA_TOOLS_DIR=<export of 6293c1c4f>/tools`): **2 errors**, the two stored-selector subtests (`Unsupported`, the two messages quoted above). Everything else in the file passes there too. - `python3 -I tests/semantic/test_alu_dot4_i8.py`: 12 tests pass. - A sweep that is not part of the change: for each of the 81 inline integers, `tools/shader_disasm.disasm` (llvm-mc, `gfx1030`) made the listing of a five-instruction program with the dot stored with `op_sel_hi` 5 and with 7, once clean and once followed by an invalid word; each listing was translated against its bytes, run in the interpreter, assembled and validated with `spirv-val`. 324 of 324 give the expected word here. With the base translator the 162 default-selector listings do and the 162 with `op_sel_hi` 5 are refused. - The Python checks of `ci.yml` on the committed tree (compileall; each `tests/test_*.py` outside `tests/semantic` with `python3 -I <file>`, or pytest where it has no `__main__`; `python3 -I scripts/run_semantic_tests.py tests/semantic -j 2`; the tracked-file guard): one failing file, `tests/test_imhex_patterns.py`, which fails on the base commit too. Semantic suite: 470 files, 6,169 tests, 0 files failed (base: 470 files, 6,168 tests, 0 failed). - `python3 -I scripts/check_no_game_data.py`: passes. Not run: a GPU, the hardware oracle, the real FSPX programs, native Windows or macOS, the runtime build (no C++ or build file changes). GPUs tested: none (CPU interpreter and SPIRV-Tools only). AI-assisted: yes (Claude Code). The numbers above come from runs on the machine named. ### Checklist - [x] Based on upstream main `6293c1c4f`, one commit. - [x] One topic: one repaired form, its test and its contract row. - [x] No game data, keys or decryption; the test program and its bytes are hand-written. - [x] The rule is in the contract table of `docs/design.md` ("Signed-byte dot with an inline integer S1"), with how it was checked and what is not measured. 🤖 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:20:53 +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#1331
No description provided.