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

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

@⁠QuentinDanblon on GitHub · 2026-11-21 20:30 UTC · original
QuentinDanblon:test/isa-table-audit → main · +3085 −16 · 7 files · 104 commits · closed without merging

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

**@⁠QuentinDanblon** on GitHub · 2026-11-21 20:30 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/49) `QuentinDanblon:test/isa-table-audit` → `main` · +3085 −16 · 7 files · 104 commits · closed without merging **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)
Add tests/isa_table.rs with committed references derived from LLVM MC test
vectors (llvm-project 963ab285f26c, Apache-2.0 WITH LLVM-exception) and AMD's
machine-readable RDNA1/RDNA2 ISA XML (MIT): every opcode the decoder names must
exist in gfx1013 (GFX10.1 + BVH) under that name, and every GFX7 instruction
the GCN lowering accepts must land on the same (or a documented equivalent)
GFX10 instruction.

Fixes found by the check:
- VOP2 0x36/0x37/0x38 (VOP3 0x136) are v_fmac_f16 / v_fmamk_f16 / v_fmaak_f16
  on GFX10, not v_mac_f16 / v_madmk_f16 / v_madak_f16. Translate them as fused
  f16 FMAs that keep denormals, rounded once like v_fma_f16 (tb_rto), default
  and MODE paths; this replaces the MAD lowering with f16 denormal flushing
  (tb_hz/tb_hzb) and the isa_sweep v_mac_f16/v_madmk_f16/v_madak_f16 cases now
  check v_fmac_f16/v_fmamk_f16/v_fmaak_f16 against hfma.
- VOP3 no longer names VOP2/VOP1-only opcodes (madmk/madak/fmamk/fmaak,
  v_pk_fmac_f16, v_swap_b32); VINTRP op 3 is undefined; MIMG gather4 has no
  _d/_d_cl forms.
- GCN SMRD: s_memtime is 0x1e and s_dcache_inv 0x1f on GFX7 (0x1d, the
  volatile invalidate, maps to s_dcache_inv); buffer_wbinvl1(_vol) lowers to
  buffer_gl0_inv + buffer_gl1_inv; image_atomic_rsub is refused.

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

@⁠QuentinDanblon on GitHub · 2026-11-21 22:02 UTC · original

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** on GitHub · 2026-11-21 22:02 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/49#issuecomment-7069900894) 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.
Author
Owner

@⁠QuentinDanblon on GitHub · 2026-11-22 00:07 UTC · original

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): #41

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

**@⁠QuentinDanblon** on GitHub · 2026-11-22 00:07 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/49#issuecomment-7071325743) 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://git.gtahub.st/github/omonkeyz--xbox-emulator/pulls/41 - 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`).
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-22 13:12 UTC · original

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.

**@⁠omonkeyz** on GitHub · 2026-11-22 13:12 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/49#issuecomment-7079646991) 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

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