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

Code

Clone this repository

Checkout

From your project repository, check out a new branch and test the changes.

git fetch -u origin "github-pr/3217:github-pr/3217"
git switch "github-pr/3217"
Open
leonida/mandy
aurelienclosson wants to merge 1 commit from github-pr/3217 into main

This branch is out-of-date with the base branch

Conversation
Reviewers 0 approvals
  • No reviewers
Details
This pull request is blocked because it's outdated.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'github-pr/3217:github-pr/3217'
git switch 'github-pr/3217'
aurelienclosson commented 2026-12-02 20:06:09 +00:00

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.)
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 reviewed 2026-12-02 20:12:16 +00:00
merzleckeier left a comment
No description provided.
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

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.

## 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

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).

**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).
Sign in to join this conversation.
No description provided.