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

Closed
github-bot wants to merge 1 commit from gh-pr/1301/head into gh-pr/1301/base
Owner

@⁠Moriz82 on GitHub · 2026-11-24 21:32 UTC · original
split/shader-ffx-packed-dot → main · +55 −2 · 3 files · 1 commits · closed without merging

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

**@⁠Moriz82** on GitHub · 2026-11-24 21:32 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1301) `split/shader-ffx-packed-dot` → `main` · +55 −2 · 3 files · 1 commits · closed without merging **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://git.gtahub.st/github/ubiquitarianism--leonida/issues/14)). 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)
llvm-mc prints no op_sel_hi on v_dot4_i32_i8 and re-encodes it with the
default 7. A listing whose bytes store another selector is therefore
refused by the printed-encoding check, on a clean listing and on one
with invalid words alike.

Repair one form instead of refusing it: no clamp, no neg, op_sel 0,
stored op_sel_hi 5 and an inline integer S1, when the printed encoding
differs from the stored one only in word 1 bit 28. The instruction takes
op_sel_hi:[1,0,1] and the existing half-selection lowering, so byte
pairs 2..3 read the low half of S1 again (an inline 10 is the bytes
10, 0, 10, 0). Every other dropped selector, a register S1 included,
stays Unsupported. That the hardware selects halves of an inline integer
as it does of a register is not measured; the contract row says so.

tests/semantic/test_printed_encoding.py: S0 0x00010001, S1 10, S2 0
gives 20 with the stored selector and 10 with the default one, on both
listing paths; seven other stored forms and a register S1 are refused.
With the translator of the base commit the two stored-selector subtests
fail (Unsupported). Listings made by llvm-mc 23.1.5 for all 81 inline
integers translate, give the expected word and pass spirv-val. The
semantic suite and the Python CI files add no failing file.

AI-assisted (Claude Code).

Co-authored-by: Plaaasma <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:46:36 +00:00
github-bot closed this pull request 2026-11-26 09:46:36 +00:00
Author
Owner

@⁠PierreEbele on GitHub · 2026-11-25 14:55 UTC · original

Reviewed 62e1245ff: ran tests/semantic/test_printed_encoding.py (9 OK) and the dot4 semantic family on both trees, plus a handwritten probe. The new guard cases reproduce main's defects (a "clamp" listing translated without the clamp, mrt0 0x80000013; a dropped-operand text crashing with IndexError); the PR refuses both, and the repaired stored form still translates (mrt0 0x14) on both trees. Found: docs/design.md gains two duplicate contract rows with stale content - a second "| Compute shaders |" saying TG_SIZE_EN shaders are "rejected for now" and a second "| Signed-byte dot products |" missing the recovery sentence; delete the stale copies and keep only the new inline-integer row. Also, the commit message says the stored-selector subtests fail on the base commit; on main they pass, only the clamp/3-arg variants do not. AI-assisted review.

Recommendation: Fix first

**@⁠PierreEbele** on GitHub · 2026-11-25 14:55 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1301#issuecomment-7166040111) Reviewed 62e1245ff: ran tests/semantic/test_printed_encoding.py (9 OK) and the dot4 semantic family on both trees, plus a handwritten probe. The new guard cases reproduce main's defects (a "clamp" listing translated without the clamp, mrt0 0x80000013; a dropped-operand text crashing with IndexError); the PR refuses both, and the repaired stored form still translates (mrt0 0x14) on both trees. Found: docs/design.md gains two duplicate contract rows with stale content - a second "| Compute shaders |" saying TG_SIZE_EN shaders are "rejected for now" and a second "| Signed-byte dot products |" missing the recovery sentence; delete the stale copies and keep only the new inline-integer row. Also, the commit message says the stored-selector subtests fail on the base commit; on main they pass, only the clamp/3-arg variants do not. AI-assisted review. **Recommendation:** Fix first

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.