disasm_rdna2: consume the second dword of DPP, SDWA and literal-K forms #687

Merged
roansystemlabs merged 1 commit from upstream-pr/693 into main 2026-11-22 21:29:01 +00:00
roansystemlabs commented 2026-11-22 20:38:46 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by roansystemlabs on 2026-11-22T20:38:46Z.


Change

tools/disasm_rdna2.py returns 4 bytes for several 32-bit encodings that carry a second dword, so the next record starts inside the instruction. scan_unsupported_shaders.py uses this decoder for .bin inputs, so a shader that contains one of these forms is split into phantom instructions.

Form GFX10 marker Second dword
VOP1/VOP2 DPP8 SRC0 = 233, or 234 with FI lane selectors
VOP1/VOP2 SDWA SRC0 = 249 real SRC0 and sub-dword selects
VOP1/VOP2 DPP16 SRC0 = 250 real SRC0 and DPP control
v_fmamk_f16, v_fmaak_f16 (VOP2 0x37, 0x38) opcode 16-bit K literal
s_setreg_imm32_b32 (SOPK 0x15) opcode 32-bit literal

Example on main (3b9bb1a): v_mov_b32_dpp v5, v1 dpp8:[0,1,2,3,4,5,6,7] followed by s_endpgm (e9020a7e 0188c6fa 000081bf) decodes as v_mov_b32_e32 v5, s233 and then an 8-byte exp built from the selector word and the s_endpgm. The program end is never seen. The scanner also reports the first record, v_mov_b32_e32 v5, s233, as supported, because s233 matches its register pattern; the same happens with s249 (SDWA) and s250 (DPP16). On this branch these records are reported as unsupported.

This PR returns each of these forms as one 8-byte record:

  • DPP8, DPP16 and SDWA: opcode vop1_dpp8, vop2_sdwa, … and assembly <mnemonic>_dpp <unsupported DPP8> / <mnemonic>_sdwa <unsupported SDWA>, with the mnemonic LLVM uses for that form. Operands are not decoded yet. This follows what the decoder already does for VOPC SDWA (vopc_sdwa, <unsupported SDWA>).
  • v_fmamk_f16 / v_fmaak_f16: decoded like v_fmamk_f32 / v_fmaak_f32, with the K literal.
  • s_setreg_imm32_b32: s_setreg_imm32_b32 0x<simm16>, 0x<literal> (raw hwreg field, no symbolic name).
  • A truncated form returns a 4-byte *_truncated record, as the literal forms already do.

VOP3 encodings are out of scope: their lengths are the subject of #576.

Verification

Windows 11 (build 26200), Python 3.12 venv from requirements-dev.txt, branch 1e30f79 on 3b9bb1a.

New test test_second_dword_forms_keep_the_stream_aligned in tests/rdna2_tools_check.py. Ten encodings copied from the LLVM 15.0.7 MC fixtures (gfx10_asm_vop1.s, gfx10_asm_vop2.s, gfx10_asm_dpp8.s, gfx10_asm_sop.s), each followed by s_endpgm: the test checks one 8-byte record, then s_endpgm at offset 8, the assembly text and the truncated case. A control checks that the neighbouring SRC0 codes 232, 235, 248, 251 and 256 still give a 4-byte v_mov_b32_e32.

python -B tests/rdna2_tools_check.py
ctest --preset dev --no-tests=error -R "^rdna2_tools_check$" -V
  • rdna2_tools_check.py: 53 tests OK, 1 skipped (test_llvm_comparison, needs LLVM_LIB; CI runs it on Linux).
  • The new test on main's disasm_rdna2.py fails for all ten encodings (for example [(0, 4, 'v_mov_b32_e32'), (4, 8, 'exp')] for DPP8).
  • The 20 pure-Python checks listed in AGENTS.md: all exit 0.

Differential length audit (not added to the repository). Every instruction/encoding pair in ten LLVM 15.0.7 GFX10 MC fixtures (gfx10_asm_vop1, vop2, vopc, vopcx, vopc_sdwa, dpp8, dpp16, sop, sopp-gfx10, smem) was decoded with decode_instruction. The decoded length was compared with the fixture's encoding length. Each encoding was then followed by s_endpgm to check that the next record starts on it.

Non-VOP3 encodings (20,375) main 3b9bb1a this branch
length differs from LLVM 5,341 0
next s_endpgm not found at its offset 479 0

The 5,341 broke down as 1,622 VOP1 SDWA, 1,442 VOP2 SDWA, 1,350 VOP1 DPP16, 738 VOP2 DPP16, 167 DPP8, 18 v_fmamk_f16/v_fmaak_f16 and 4 s_setreg_imm32_b32. The 4,890 VOP3 encodings in the same files are unchanged (#576). With this branch merged locally with #576 (git merge-tree, no conflict), all 25,265 encodings decode to the LLVM length and rdna2_tools_check.py passes. The branch also merges without conflict with #621 and passes the same file.

Negative controls. Each mutation was applied to a scratch copy of tools/ and tests/ and the new test was run. All eight fail:

Mutation Result
SRC0 249 (SDWA) not treated as an extension fails
SRC0 250 (DPP16) not treated as an extension fails
SRC0 234 (DPP8 with FI) not treated as an extension fails
SRC0 248 also treated as an extension fails (control)
extension record returns 4 bytes fails
VOP2 skips the extension check fails
v_fmamk_f16/v_fmaak_f16 without the literal fails
s_setreg_imm32_b32 literal not consumed fails

Full suite. The change is Python-only and touches no GPU path. I ran the full suite anyway, on an earlier revision of this branch that differed only in where the helper and the test sit in their files, on an RTX 3070 (driver 32.0.16.2101, 621.01) and WARP, debug layer as configured by the dev preset: ctest --preset dev --no-tests=error --timeout 300 -j 4 gave 293 passed, 4 capability skips (bvh_wave64_hardware, bvh_wave64_warp, wave_shuffle_warp, cpu_aot_crypto_sha) and 0 failed. On main the same command once hit the 60 s timeout in pixel_aot_predicate_rounding_hardware (#448). That test does not use this decoder. GPU load during the runs (nvidia-smi): 0–6 % utilization, about 5.6 GB VRAM used by resident local services.

Evidence and follow-up

  • The fixture encodings come from LLVM's MC tests (llvm/test/MC/AMDGPU, tag llvmorg-15.0.7, Apache-2.0 WITH LLVM-exception), used as independent reference bytes, as the existing VOPC test already does.
  • I could not run llvm-mc for AMDGPU locally: the official Windows LLVM build ships only the x86 target. The reference is the fixture bytes, not a local LLVM run.
  • Not done here: decoding the DPP and SDWA operands in LLVM syntax, so the scanner can match them against the lowered DPP/SDWA patterns. Also not done: the symbolic hwreg(...) operand of s_setreg_imm32_b32, and the s_waitcnt field split (GFX10 vmcnt is simm16[3:0] plus [15:14], and expcnt is [6:4]; the decoder reads vmcnt from [7:4]). Each can be a separate PR.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed. (No README or build change. The census now counts these forms as single records.)
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted: yes. Prepared with an AI coding agent; I checked the results above.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6547493957 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/693). Originally posted by [roansystemlabs](https://github.com/roansystemlabs) on 2026-11-22T20:38:46Z. --- ## Change `tools/disasm_rdna2.py` returns 4 bytes for several 32-bit encodings that carry a second dword, so the next record starts inside the instruction. `scan_unsupported_shaders.py` uses this decoder for `.bin` inputs, so a shader that contains one of these forms is split into phantom instructions. | Form | GFX10 marker | Second dword | |---|---|---| | VOP1/VOP2 DPP8 | SRC0 = 233, or 234 with FI | lane selectors | | VOP1/VOP2 SDWA | SRC0 = 249 | real SRC0 and sub-dword selects | | VOP1/VOP2 DPP16 | SRC0 = 250 | real SRC0 and DPP control | | `v_fmamk_f16`, `v_fmaak_f16` (VOP2 0x37, 0x38) | opcode | 16-bit K literal | | `s_setreg_imm32_b32` (SOPK 0x15) | opcode | 32-bit literal | Example on `main` (`3b9bb1a`): `v_mov_b32_dpp v5, v1 dpp8:[0,1,2,3,4,5,6,7]` followed by `s_endpgm` (`e9020a7e 0188c6fa 000081bf`) decodes as `v_mov_b32_e32 v5, s233` and then an 8-byte `exp` built from the selector word and the `s_endpgm`. The program end is never seen. The scanner also reports the first record, `v_mov_b32_e32 v5, s233`, as supported, because `s233` matches its register pattern; the same happens with `s249` (SDWA) and `s250` (DPP16). On this branch these records are reported as unsupported. This PR returns each of these forms as one 8-byte record: - DPP8, DPP16 and SDWA: opcode `vop1_dpp8`, `vop2_sdwa`, … and assembly `<mnemonic>_dpp <unsupported DPP8>` / `<mnemonic>_sdwa <unsupported SDWA>`, with the mnemonic LLVM uses for that form. Operands are not decoded yet. This follows what the decoder already does for VOPC SDWA (`vopc_sdwa`, `<unsupported SDWA>`). - `v_fmamk_f16` / `v_fmaak_f16`: decoded like `v_fmamk_f32` / `v_fmaak_f32`, with the K literal. - `s_setreg_imm32_b32`: `s_setreg_imm32_b32 0x<simm16>, 0x<literal>` (raw hwreg field, no symbolic name). - A truncated form returns a 4-byte `*_truncated` record, as the literal forms already do. VOP3 encodings are out of scope: their lengths are the subject of #576. ## Verification Windows 11 (build 26200), Python 3.12 venv from `requirements-dev.txt`, branch `1e30f79` on `3b9bb1a`. **New test** `test_second_dword_forms_keep_the_stream_aligned` in `tests/rdna2_tools_check.py`. Ten encodings copied from the LLVM 15.0.7 MC fixtures (`gfx10_asm_vop1.s`, `gfx10_asm_vop2.s`, `gfx10_asm_dpp8.s`, `gfx10_asm_sop.s`), each followed by `s_endpgm`: the test checks one 8-byte record, then `s_endpgm` at offset 8, the assembly text and the truncated case. A control checks that the neighbouring SRC0 codes 232, 235, 248, 251 and 256 still give a 4-byte `v_mov_b32_e32`. ```powershell python -B tests/rdna2_tools_check.py ctest --preset dev --no-tests=error -R "^rdna2_tools_check$" -V ``` - `rdna2_tools_check.py`: 53 tests OK, 1 skipped (`test_llvm_comparison`, needs `LLVM_LIB`; CI runs it on Linux). - The new test on `main`'s `disasm_rdna2.py` fails for all ten encodings (for example `[(0, 4, 'v_mov_b32_e32'), (4, 8, 'exp')]` for DPP8). - The 20 pure-Python checks listed in `AGENTS.md`: all exit 0. **Differential length audit (not added to the repository).** Every instruction/encoding pair in ten LLVM 15.0.7 GFX10 MC fixtures (`gfx10_asm_vop1`, `vop2`, `vopc`, `vopcx`, `vopc_sdwa`, `dpp8`, `dpp16`, `sop`, `sopp-gfx10`, `smem`) was decoded with `decode_instruction`. The decoded length was compared with the fixture's encoding length. Each encoding was then followed by `s_endpgm` to check that the next record starts on it. | Non-VOP3 encodings (20,375) | `main` `3b9bb1a` | this branch | |---|---:|---:| | length differs from LLVM | 5,341 | 0 | | next `s_endpgm` not found at its offset | 479 | 0 | The 5,341 broke down as 1,622 VOP1 SDWA, 1,442 VOP2 SDWA, 1,350 VOP1 DPP16, 738 VOP2 DPP16, 167 DPP8, 18 `v_fmamk_f16`/`v_fmaak_f16` and 4 `s_setreg_imm32_b32`. The 4,890 VOP3 encodings in the same files are unchanged (#576). With this branch merged locally with #576 (`git merge-tree`, no conflict), all 25,265 encodings decode to the LLVM length and `rdna2_tools_check.py` passes. The branch also merges without conflict with #621 and passes the same file. **Negative controls.** Each mutation was applied to a scratch copy of `tools/` and `tests/` and the new test was run. All eight fail: | Mutation | Result | |---|---| | SRC0 249 (SDWA) not treated as an extension | fails | | SRC0 250 (DPP16) not treated as an extension | fails | | SRC0 234 (DPP8 with FI) not treated as an extension | fails | | SRC0 248 also treated as an extension | fails (control) | | extension record returns 4 bytes | fails | | VOP2 skips the extension check | fails | | `v_fmamk_f16`/`v_fmaak_f16` without the literal | fails | | `s_setreg_imm32_b32` literal not consumed | fails | **Full suite.** The change is Python-only and touches no GPU path. I ran the full suite anyway, on an earlier revision of this branch that differed only in where the helper and the test sit in their files, on an RTX 3070 (driver 32.0.16.2101, 621.01) and WARP, debug layer as configured by the `dev` preset: `ctest --preset dev --no-tests=error --timeout 300 -j 4` gave 293 passed, 4 capability skips (`bvh_wave64_hardware`, `bvh_wave64_warp`, `wave_shuffle_warp`, `cpu_aot_crypto_sha`) and 0 failed. On `main` the same command once hit the 60 s timeout in `pixel_aot_predicate_rounding_hardware` (#448). That test does not use this decoder. GPU load during the runs (`nvidia-smi`): 0–6 % utilization, about 5.6 GB VRAM used by resident local services. ## Evidence and follow-up - The fixture encodings come from LLVM's MC tests (`llvm/test/MC/AMDGPU`, tag `llvmorg-15.0.7`, Apache-2.0 WITH LLVM-exception), used as independent reference bytes, as the existing VOPC test already does. - I could not run `llvm-mc` for AMDGPU locally: the official Windows LLVM build ships only the x86 target. The reference is the fixture bytes, not a local LLVM run. - Not done here: decoding the DPP and SDWA operands in LLVM syntax, so the scanner can match them against the lowered DPP/SDWA patterns. Also not done: the symbolic `hwreg(...)` operand of `s_setreg_imm32_b32`, and the `s_waitcnt` field split (GFX10 `vmcnt` is `simm16[3:0]` plus `[15:14]`, and `expcnt` is `[6:4]`; the decoder reads `vmcnt` from `[7:4]`). Each can be a separate PR. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. (No README or build change. The census now counts these forms as single records.) - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted: yes. Prepared with an AI coding agent; I checked the results above.
upstream-sync closed this pull request 2026-11-24 06:44:22 +00:00
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
R0Y00/Xbox2Windows!687
No description provided.