xshader: check RDNA2 opcode tables against gfx1013 references (17 decoder names, 5 GFX7 lowerings corrected) #49

Closed
QuentinDanblon wants to merge 0 commits from upstream-pr/49 into main
QuentinDanblon commented 2026-11-21 20:30:15 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by QuentinDanblon on 2026-11-21T20:30:15Z.


Library / area: tombox-xshader (RDNA2 decoder tables, GCN to RDNA2 lowering)

Exports changed (exports.txt rows): none

Source of the behaviour: LLVM MC test vectors (llvm-project 963ab285f26c, Apache-2.0 WITH LLVM-exception) for gfx1010/1013/1030 and gfx7; AMD machine-readable ISA XML for RDNA1/RDNA2 (2026-02-20, MIT). Where both list an opcode, the names agree.

Rebased on 51f5319

One commit. Dropped since the first version, because main has them now or because they are your data:

  • the f16 FMA renaming and its fused translation (main has v_fmac_f16 / v_fmamk_f16 / v_fmaak_f16); only 4 exec cases where fused and unfused results differ remain;
  • the progress files (mnem_groups.json, mnemonics.txt): not touched;
  • the HLSL prelude: not touched, so shader pack keys stay valid.

What is left

A test that checks the opcode tables against committed references, and the fixes it asks for on main.

  • tests/isa_table.rs with tests/isa_table/gfx1013.txt and gfx7.txt (licence notices and source commit in each header):
    • rdna2_names_match_gfx1013 decodes every opcode of every encoding through rdna2::disassemble, including the generated MIMG names. It fails on a wrong name, or on a named opcode that does not exist in gfx1013, and says when the name is a gfx1030-only instruction.
    • gcn_lowering_keeps_instruction: every GFX7 opcode gcn::to_rdna2 accepts must lower to the same instruction or a listed equivalent.
  • On main 51f5319 the test reports 17 decoder names and 5 lowerings. Fixed here:
    • names given through fallbacks to opcodes that do not exist in gfx1013, now unnamed: VOP3 forms of the VOP2-only madmk / madak / fmamk / fmaak / pk_fmac (0x120, 0x121, 0x12c, 0x12d, 0x137, 0x138, 0x13c), VOP3 v_swap_b32 0x1e5 (the VOP1 form is kept), VINTRP op 3, the generated image_gather4*_d* names at MIMG 0x42-0x5b;
    • GFX7 SMRD 0x1e / 0x1f lowered to each other's instruction (s_dcache_inv_vol and s_memtime swapped);
    • GFX7 MUBUF 0x70 / 0x71 (buffer_wbinvl1_vol / buffer_wbinvl1) passed through to an undefined or partial GFX10 opcode; they now lower to buffer_gl0_inv + buffer_gl1_inv, as LLVM does for a GFX10 acquire;
    • GFX7 MIMG 0x13 (image_atomic_rsub, absent on GFX10) is refused.
  • Docs in mnem.rs / rdna2.rs say GFX10.1 (gfx1013).

Not changed: the gfx1013 opcodes the decoder leaves unnamed (they print with --nocapture). Naming them would change your progress denominator. The flat_* naming for all segments is kept, because the translator relies on it.

Tests

  • cargo test -p tombox-xshader --release --lib --test opcodes --test synthetic --test isa_table --test mixed_table: 60 / 22 / 11 / 3 / 3 pass.

  • --test exec on WARP: 73 pass, 0 fail (same count as main; the new cases are inside existing tests).

  • Not run against a title.

  • cargo test -p tombox-xshader passes

  • No game or console files and no binaries included

  • No fake success; anything not possible is left missing with a note

🤖 Generated with Claude Code

<!-- greyfinch-sync:omonkeyz/xbox-emulator:issue:6534017606 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/49). Originally posted by [QuentinDanblon](https://github.com/QuentinDanblon) on 2026-11-21T20:30:15Z. --- **Library / area:** tombox-xshader (RDNA2 decoder tables, GCN to RDNA2 lowering) **Exports changed (exports.txt rows):** none **Source of the behaviour:** LLVM MC test vectors (llvm-project 963ab285f26c, Apache-2.0 WITH LLVM-exception) for gfx1010/1013/1030 and gfx7; AMD machine-readable ISA XML for RDNA1/RDNA2 (2026-02-20, MIT). Where both list an opcode, the names agree. ### Rebased on 51f5319 One commit. Dropped since the first version, because main has them now or because they are your data: - the f16 FMA renaming and its fused translation (main has `v_fmac_f16` / `v_fmamk_f16` / `v_fmaak_f16`); only 4 exec cases where fused and unfused results differ remain; - the progress files (`mnem_groups.json`, `mnemonics.txt`): not touched; - the HLSL prelude: not touched, so shader pack keys stay valid. ### What is left A test that checks the opcode tables against committed references, and the fixes it asks for on main. - `tests/isa_table.rs` with `tests/isa_table/gfx1013.txt` and `gfx7.txt` (licence notices and source commit in each header): - `rdna2_names_match_gfx1013` decodes every opcode of every encoding through `rdna2::disassemble`, including the generated MIMG names. It fails on a wrong name, or on a named opcode that does not exist in gfx1013, and says when the name is a gfx1030-only instruction. - `gcn_lowering_keeps_instruction`: every GFX7 opcode `gcn::to_rdna2` accepts must lower to the same instruction or a listed equivalent. - On main 51f5319 the test reports 17 decoder names and 5 lowerings. Fixed here: - names given through fallbacks to opcodes that do not exist in gfx1013, now unnamed: VOP3 forms of the VOP2-only madmk / madak / fmamk / fmaak / pk_fmac (0x120, 0x121, 0x12c, 0x12d, 0x137, 0x138, 0x13c), VOP3 `v_swap_b32` 0x1e5 (the VOP1 form is kept), VINTRP op 3, the generated `image_gather4*_d*` names at MIMG 0x42-0x5b; - GFX7 SMRD 0x1e / 0x1f lowered to each other's instruction (`s_dcache_inv_vol` and `s_memtime` swapped); - GFX7 MUBUF 0x70 / 0x71 (`buffer_wbinvl1_vol` / `buffer_wbinvl1`) passed through to an undefined or partial GFX10 opcode; they now lower to `buffer_gl0_inv` + `buffer_gl1_inv`, as LLVM does for a GFX10 acquire; - GFX7 MIMG 0x13 (`image_atomic_rsub`, absent on GFX10) is refused. - Docs in `mnem.rs` / `rdna2.rs` say GFX10.1 (gfx1013). Not changed: the gfx1013 opcodes the decoder leaves unnamed (they print with `--nocapture`). Naming them would change your progress denominator. The `flat_*` naming for all segments is kept, because the translator relies on it. ### Tests - `cargo test -p tombox-xshader --release --lib --test opcodes --test synthetic --test isa_table --test mixed_table`: 60 / 22 / 11 / 3 / 3 pass. - `--test exec` on WARP: 73 pass, 0 fail (same count as main; the new cases are inside existing tests). - Not run against a title. - [x] `cargo test -p tombox-xshader` passes - [x] No game or console files and no binaries included - [x] No fake success; anything not possible is left `missing` with a note 🤖 Generated with [Claude Code](https://claude.com/claude-code)
QuentinDanblon commented 2026-11-21 22:02:50 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by QuentinDanblon on 2026-11-21T22:02:50Z.


Rebased onto 0fc7295, with the targeted tests re-run on the new base. #49 keeps the fused f16 FMA at VOP2 0x36-0x38 (gfx1013 v_fmac/fmamk/fmaak_f16) and updates the upstream ISA-sweep cases to the fused model. #36 adapts to upstream's TB_CEN_Q centroid qualifier. #48 now also includes the 4 regression scenarios from #28, credited.

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7069900894 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/49#issuecomment-7069900894). Originally posted by [QuentinDanblon](https://github.com/QuentinDanblon) on 2026-11-21T22:02:50Z. --- Rebased onto 0fc7295, with the targeted tests re-run on the new base. #49 keeps the fused f16 FMA at VOP2 0x36-0x38 (gfx1013 v_fmac/fmamk/fmaak_f16) and updates the upstream ISA-sweep cases to the fused model. #36 adapts to upstream's TB_CEN_Q centroid qualifier. #48 now also includes the 4 regression scenarios from #28, credited.
QuentinDanblon commented 2026-11-22 00:07:05 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by QuentinDanblon on 2026-11-22T00:07:05Z.


Hardware evidence for the fused reading of VOP2 0x36 / 0x37 / 0x38, which was the open point of this PR against the ISA sweep on main.

@SchmashinPrunes ran the probe kernels of #72 on an RDNA2 GPU (gfx1036 iGPU of a Ryzen 5 9600X, ROCm/HIP 5.7.1): https://github.com/omonkeyz/xbox-emulator/pull/41#issuecomment-7071178837

  • The three opcodes match hardware v_fma_f16 on all 254,891 inputs that separate "fused" from "multiply then add" (three K values), and match v_mul_f16 + v_add_f16 on none of them.
  • Hardware v_fma_f16 matches the exact single-rounding model, 0 mismatches.
  • The upper half of D is preserved, as the sweep on main already models.

So the names and semantics here (v_fmac_f16, v_fmamk_f16, v_fmaak_f16) are what RDNA2 does. Caveat: gfx1036, not the console's gfx1013. LLVM gives both the same GFX10 encodings, and the kernels disassemble identically for the two targets.

The branch is unchanged and still merges cleanly with main (f6b979d).

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7071325743 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/49#issuecomment-7071325743). Originally posted by [QuentinDanblon](https://github.com/QuentinDanblon) on 2026-11-22T00:07:05Z. --- Hardware evidence for the fused reading of VOP2 0x36 / 0x37 / 0x38, which was the open point of this PR against the ISA sweep on main. @SchmashinPrunes ran the probe kernels of #72 on an RDNA2 GPU (gfx1036 iGPU of a Ryzen 5 9600X, ROCm/HIP 5.7.1): https://github.com/omonkeyz/xbox-emulator/pull/41#issuecomment-7071178837 - The three opcodes match hardware `v_fma_f16` on all 254,891 inputs that separate "fused" from "multiply then add" (three K values), and match `v_mul_f16` + `v_add_f16` on none of them. - Hardware `v_fma_f16` matches the exact single-rounding model, 0 mismatches. - The upper half of D is preserved, as the sweep on main already models. So the names and semantics here (`v_fmac_f16`, `v_fmamk_f16`, `v_fmaak_f16`) are what RDNA2 does. Caveat: gfx1036, not the console's gfx1013. LLVM gives both the same GFX10 encodings, and the kernels disassemble identically for the two targets. The branch is unchanged and still merges cleanly with main (`f6b979d`).
omonkeyz commented 2026-11-22 13:12:45 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by omonkeyz on 2026-11-22T13:12:45Z.


Main's history was rewritten, which auto-closed this PR (sorry for the noise). Real fixes. Please rebase on the current main, drop the tools/progress changes and strip comment lines. To resubmit: git fetch this repo, branch from the current main, cherry-pick only your own commits (the old branch is based on the previous history and cannot be merged), and open a new PR.

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7079646991 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/49#issuecomment-7079646991). Originally posted by [omonkeyz](https://github.com/omonkeyz) on 2026-11-22T13:12:45Z. --- Main's history was rewritten, which auto-closed this PR (sorry for the noise). Real fixes. Please rebase on the current main, drop the tools/progress changes and strip comment lines. To resubmit: `git fetch` this repo, branch from the current `main`, cherry-pick only your own commits (the old branch is based on the previous history and cannot be merged), and open a new PR.

Pull request closed

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
omonkeyz/xbox-emulator!49
No description provided.