rdna2_decode: reject DPP and SDWA src0 markers on mandatory-literal VOP2 ops (RDNA2-DECODE-VOP2-LITERAL-DPP-SDWA) #3217

Open
aurelienclosson wants to merge 1 commit from upstream-pr/3217 into main
aurelienclosson commented 2026-12-02 20:06:09 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aurelienclosson on 2026-12-02T20:06:09Z.


Claimed in the coordination issue as: RDNA2-DECODE-VOP2-LITERAL-DPP-SDWA (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7356893555)

What and why

Follows up on the RDNA2 binary decoder finding in https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7354047139.

In tools/rdna2_decode.py, mandatory-literal VOP2 opcodes (_VOP2_MANDATORY_LITERAL: 0x20 v_madmk_f32, 0x21 v_madak_f32, 0x2C v_fmamk_f32, 0x2D v_fmaak_f32, 0x37 v_fmamk_f16, 0x38 v_fmaak_f16) always carry their 32-bit literal constant in word 1 and have no legal DPP16 (src0 == 250), DPP8 (src0 in (233, 234)), or SDWA (src0 == 249) encoding in GFX10 (RDNA2). Previously, rdna2_decode.py entered the DPP/SDWA branch before checking _VOP2_MANDATORY_LITERAL, emitting invalid 3-operand _dpp/_sdwa instructions and consuming 8 bytes instead of 4 (which also desynchronizes the 4-byte alignment of the next word in embedded constant data).

Returning (None, 4) when opc in _VOP2_MANDATORY_LITERAL inside the is_dpp16 or is_dpp8 or is_sdwa check matches LLVM (llvm-mc for gfx1013/gfx1030) and keeps subsequent instructions aligned on their 4-byte boundary.

Tested

  • python -I scripts/red_green.py fix/rdna2-decode-vop2-literal-dpp-sdwa --base origin/main --no-fetch --mutate -> verdict: red then green (test_vop2_mandatory_literal_rejects_dpp_and_sdwa_src0_markers fails on red and passes on green; 24 existing tests pass on both; mutations (1 hunks undone one at a time): 1 caught).
  • python -I tests/test_rdna2_decode.py -> 26 tests (OK, skipped=1), covering all 6 mandatory-literal VOP2 opcodes across all 4 DPP/SDWA src0 markers (233, 234, 249, 250), gfx1013 and gfx1030, wave32 and wave64, trailing s_endpgm alignment at +4, 4-byte EOF truncation, and positive VGPR+literal controls.
  • python -I scripts/run_semantic_tests.py tests/semantic -> 560 files, 6791 tests, 0 files failed.
  • python -I tests/test_text_write_line_endings.py, python -m compileall -q make_game.py tools tests, and python -I scripts/check_no_game_data.py tools/rdna2_decode.py tests/test_rdna2_decode.py -> all green.

GPUs tested: n/a (CPU-only binary RDNA2 decoder; host system: NVIDIA GeForce RTX 5070, driver 621.24, Windows 11)

AI-assisted: yes (Antigravity / Gemini Carbon, including an independent read-only diff, edge-case, red/green, and clean-room review)

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (Decoder invalid-word alignment fix; no translator SPIR-V lowering rule changed.)
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5613812485 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3217). Originally posted by [aurelienclosson](https://github.com/aurelienclosson) on 2026-12-02T20:06:09Z. --- Claimed in the coordination issue as: RDNA2-DECODE-VOP2-LITERAL-DPP-SDWA (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7356893555) ### What and why Follows up on the RDNA2 binary decoder finding in https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7354047139. In `tools/rdna2_decode.py`, mandatory-literal VOP2 opcodes (`_VOP2_MANDATORY_LITERAL`: `0x20` `v_madmk_f32`, `0x21` `v_madak_f32`, `0x2C` `v_fmamk_f32`, `0x2D` `v_fmaak_f32`, `0x37` `v_fmamk_f16`, `0x38` `v_fmaak_f16`) always carry their 32-bit literal constant in word 1 and have no legal DPP16 (`src0 == 250`), DPP8 (`src0 in (233, 234)`), or SDWA (`src0 == 249`) encoding in GFX10 (RDNA2). Previously, `rdna2_decode.py` entered the DPP/SDWA branch before checking `_VOP2_MANDATORY_LITERAL`, emitting invalid 3-operand `_dpp`/`_sdwa` instructions and consuming 8 bytes instead of 4 (which also desynchronizes the 4-byte alignment of the next word in embedded constant data). Returning `(None, 4)` when `opc in _VOP2_MANDATORY_LITERAL` inside the `is_dpp16 or is_dpp8 or is_sdwa` check matches LLVM (`llvm-mc` for `gfx1013`/`gfx1030`) and keeps subsequent instructions aligned on their 4-byte boundary. ### Tested - `python -I scripts/red_green.py fix/rdna2-decode-vop2-literal-dpp-sdwa --base origin/main --no-fetch --mutate` -> `verdict: red then green` (`test_vop2_mandatory_literal_rejects_dpp_and_sdwa_src0_markers` fails on red and passes on green; 24 existing tests pass on both; `mutations (1 hunks undone one at a time): 1 caught`). - `python -I tests/test_rdna2_decode.py` -> 26 tests (`OK, skipped=1`), covering all 6 mandatory-literal VOP2 opcodes across all 4 DPP/SDWA `src0` markers (`233, 234, 249, 250`), `gfx1013` and `gfx1030`, `wave32` and `wave64`, trailing `s_endpgm` alignment at `+4`, 4-byte EOF truncation, and positive VGPR+literal controls. - `python -I scripts/run_semantic_tests.py tests/semantic` -> `560 files, 6791 tests, 0 files failed`. - `python -I tests/test_text_write_line_endings.py`, `python -m compileall -q make_game.py tools tests`, and `python -I scripts/check_no_game_data.py tools/rdna2_decode.py tests/test_rdna2_decode.py` -> all green. GPUs tested: n/a (CPU-only binary RDNA2 decoder; host system: NVIDIA GeForce RTX 5070, driver 621.24, Windows 11) AI-assisted: yes (Antigravity / Gemini Carbon, including an independent read-only diff, edge-case, red/green, and clean-room review) ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (Decoder invalid-word alignment fix; no translator SPIR-V lowering rule changed.)
merzleckeier commented 2026-12-02 20:12:16 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-12-02T20:12:16Z.

Review: COMMENTED


Independent verification on 82b0462bb against main b41763227. With the PR fixture and the baseline decoder, the first case fails as expected (v_madmk_f32, src0 233: 0 invalid words, expected 1). The full tests/test_rdna2_decode.py suite passes on the PR (26/26, no skips). LLVM 23.1.5 independently rejected all 96 synthetic encodings covering the six opcodes, four selectors, gfx1013/gfx1030 and wave32/wave64; in every case it still decoded the trailing s_endpgm. git merge-tree is clean against that base. No findings in the CPU decoder diff. AI-assisted; synthetic fixtures, no GPU or game data.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6158143978 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3217#pullrequestreview-6158143978). Originally posted by [merzleckeier](https://github.com/merzleckeier) on 2026-12-02T20:12:16Z. **Review:** COMMENTED --- Independent verification on `82b0462bb` against `main` `b41763227`. With the PR fixture and the baseline decoder, the first case fails as expected (`v_madmk_f32`, src0 233: 0 invalid words, expected 1). The full `tests/test_rdna2_decode.py` suite passes on the PR (26/26, no skips). LLVM 23.1.5 independently rejected all 96 synthetic encodings covering the six opcodes, four selectors, `gfx1013`/`gfx1030` and wave32/wave64; in every case it still decoded the trailing `s_endpgm`. `git merge-tree` is clean against that base. No findings in the CPU decoder diff. AI-assisted; synthetic fixtures, no GPU or game data.
fiestorra commented 2026-12-02 20:36:32 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-12-02T20:36:32Z.


VERIFY-3217 — Windows nativo, red then green en el decodificador

Head (this PR)
Merge base b41763227 = current main

Ran

python -I tests/test_rdna2_decode.py      Ran 26 tests in 7.8s — OK

Negative control (tools/rdna2_decode.py reverted to main, the PR's tests kept):

FAIL: test_vop2_mandatory_literal_rejects_dpp_and_sdwa_src0_markers
Ran 26 tests — FAILED (failures=1)

The one-line change is the right place: in the DPP/SDWA branch, a VOP2 opcode that carries a mandatory literal takes the literal word in the second dword, so decoding it as a DPP/SDWA control word is reading the literal's low bits as control — refusing (return None, 4) for _VOP2_MANDATORY_LITERAL before the marker path is what the six v_madmk/v_madak/v_fmamk/v_fmaak cases in the test pin (f32 and f16).

What I could not test: the effect on a real shader corpus — the suite is unit-level parsing, and I did not re-run the translated corpus through the decoder. The change only refuses an encoding that the old code silently misread, so the risk is a shader that was being misdecoded and now reports instead; the tests do not count such shaders.

Verdict: red then green on native Windows.

Written with an AI assistant.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7358016473 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3217#issuecomment-7358016473). Originally posted by [fiestorra](https://github.com/fiestorra) on 2026-12-02T20:36:32Z. --- ## VERIFY-3217 — Windows nativo, `red then green` en el decodificador | | | |---|---| | Head | `(this PR)` | | Merge base | `b41763227` = current `main` | **Ran** ``` python -I tests/test_rdna2_decode.py Ran 26 tests in 7.8s — OK ``` **Negative control** (`tools/rdna2_decode.py` reverted to `main`, the PR's tests kept): ``` FAIL: test_vop2_mandatory_literal_rejects_dpp_and_sdwa_src0_markers Ran 26 tests — FAILED (failures=1) ``` **The one-line change is the right place**: in the DPP/SDWA branch, a VOP2 opcode that carries a **mandatory literal** takes the literal word in the second dword, so decoding it as a DPP/SDWA control word is reading the literal's low bits as control — refusing (`return None, 4`) for `_VOP2_MANDATORY_LITERAL` before the marker path is what the six `v_madmk`/`v_madak`/`v_fmamk`/`v_fmaak` cases in the test pin (f32 and f16). **What I could not test**: the effect on a real shader corpus — the suite is unit-level parsing, and I did not re-run the translated corpus through the decoder. The change only refuses an encoding that the old code silently misread, so the risk is a shader that *was* being misdecoded and now reports instead; the tests do not count such shaders. Verdict: **red then green** on native Windows. Written with an AI assistant.
lixonik commented 2026-12-02 22:47:50 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-12-02T22:47:50Z.


Windows native verification (red -> green) -- PASS on head 82b0462bb (merged cleanly via git merge --no-ff onto main 16243cd6e).

Checks (Windows 10 x64, Python 3.12)

  • python -I scripts/check_no_game_data.py -> PASS
  • Green (python -I tests/test_rdna2_decode.py -v on merged head 82b0462bb): Ran 26 tests in 4.404s / OK
  • Red (reverted tools/rdna2_decode.py to main 16243cd6e, keeping the PR's tests/test_rdna2_decode.py): Ran 26 tests in 4.136s / FAILED (failures=1)

AI-assisted: yes (Antigravity -- Gemini 4 Neon).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7361172556 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3217#issuecomment-7361172556). Originally posted by [lixonik](https://github.com/lixonik) on 2026-12-02T22:47:50Z. --- **Windows native verification (`red -> green`) -- PASS** on head `82b0462bb` (merged cleanly via `git merge --no-ff` onto `main` `16243cd6e`). ### Checks (Windows 10 x64, Python 3.12) - `python -I scripts/check_no_game_data.py` -> **PASS** - **Green** (`python -I tests/test_rdna2_decode.py -v` on merged head `82b0462bb`): **Ran 26 tests in 4.404s / OK** - **Red** (reverted `tools/rdna2_decode.py` to `main` `16243cd6e`, keeping the PR's `tests/test_rdna2_decode.py`): **Ran 26 tests in 4.136s / FAILED (failures=1)** AI-assisted: yes (Antigravity -- Gemini 4 Neon).
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3217:upstream-pr/3217'
git switch 'upstream-pr/3217'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3217'
git switch 'upstream-pr/3217'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3217'
git switch 'upstream-pr/3217'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3217'
git switch 'main'
git merge --squash 'upstream-pr/3217'
git switch 'main'
git merge --ff-only 'upstream-pr/3217'
git switch 'main'
git merge 'upstream-pr/3217'
git push origin 'main'
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!3217
No description provided.