tooling: decode the VOP3 binary16 interpolation forms in disasm_rdna2 #963

Merged
MasterDomino merged 1 commit from upstream-pr/970 into main 2026-11-23 19:31:47 +00:00
MasterDomino commented 2026-11-23 19:15:45 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-23T19:15:45Z.


Change

Step 2 of #938, scoped as claimed there: tools/disasm_rdna2.py decodes the VOP3 binary16 interpolation forms v_interp_p1ll_f16, v_interp_p1lv_f16 and v_interp_p2_f16 (opcodes 0x342, 0x343, 0x35a) as LLVM 15 prints them for gfx1013. Before, they printed as v_vop3_342/v_vop3_343/v_vop3_35a with three register operands, so tools/scan_unsupported_shaders.py reported them as unrecognized opcodes in the VALU category.

Encoding. These are the encodings LLVM 15.0.7 produces for gfx1013, checked field by field with llvm-mc.

  • SRC0 holds the attribute (bits 5:0), the channel xyzw (bits 7:6) and the high-half select (bit 8, printed high).
  • SRC1 and, for p1lv/p2, SRC2 are the data sources, with the usual abs/neg bits.
  • clamp and the output modifier (mul:2, mul:4, div:2) follow.
  • The printed form is vdst, src1, attrN.c[, src2][ high][ clamp][ omod].

Encodings LLVM 15 refuses keep their eight-byte record and decode as <name>_unsupported / <name> <unsupported VOP3 encoding>, as v_readfirstlane_b32's VOP3A word already does:

  • an abs or neg bit on the attribute operand;
  • a nonzero p1ll third source or its modifier bits;
  • an output modifier on p2;
  • source codes 209-234, 249, 250 and 255 (literal).

op_sel bits are ignored, as LLVM ignores them.

Inline-constant sources. LLVM 15 accepts them but prints /*invalid immediate*/, with a lone negation as neg(/*invalid immediate*/). The decoder prints the same text, so its output stays identical to LLVM's.

Not in this PR:

  • the instruction-boundary and s_endpgm work from #951/#956;
  • step 3 (SDWA VOPC, image_atomic_*, v_add_co_ci_u32_e32);
  • the VOP3 v_interp_*_f32_e64 forms;
  • scanner support for these instructions, which pixel_aot does not lower (#711/#713).

Refs #938

Verification

Upstream main at 6f111ed, Fedora 45 x86_64, Python 3.15.2, LLVM 15.0.7.

P=/usr/lib64/llvm15
LLVM_LIB=$P/lib/libLLVM-15.so LLVM_MC=$P/bin/llvm-mc LLVM_OBJCOPY=$P/bin/llvm-objcopy \
  python -B tests/rdna2_tools_check.py
python -B tests/rdna2_tools_check.py

With LLVM, the suite exits OK. Without it, OK with the LLVM-gated tests skipped. The 26 platform-independent checks, tests/pixel_aot_check.py binary and tests/form_coverage_check.py also exit 0.

New tests:

  • test_interp_f16_uses_llvm_spelling (pure Python).
    • Eight encodings with llvm-mc 15.0.7's text as the expected value. They cover each opcode, high, clamp, each output modifier, abs/neg/-|x|, SGPR and special-register sources, attributes 0-63, and both inline-constant spellings.
    • Five refused encodings, one per refusal rule, must decode as _unsupported with the following s_endpgm still at offset 8. Every vector was checked against pixel_aot.disassemble.
  • test_interp_f16_llvm_round_trip (LLVM 15).
    • 14 lines are assembled by llvm-mc and decoded. The text must equal LLVM's, and must re-assemble to the same bytes.
    • Neighbouring lines differ in one field (attribute, channel, high, SGPR source, swapped sources, modifiers, clamp, output modifier), so a dropped or swapped field changes the bytes.
  • test_binary_scan_recognizes_decoded_interp_f16 (pure Python, source-built scan case).
    • scan_directory_or_files runs on a .bin of llvm-mc output.
    • Expected: the opcodes are recognized, attributed to VINTRP, and classified opcode_recognized_translator_rejected, with no v_vop3_* names.

Negative control. With tools/disasm_rdna2.py reverted to 6f111ed: FAILED (failures=15). That is 13 spelling subtests, the round trip and the scan case. Restoring the change passes all of them.

Exhaustive comparison (local, not part of the suite) against LLVM 15's LLVMDisasmInstruction for gfx1013, 77,920 encodings of the three opcodes:

  • every source code (0-511) in each source slot with every abs/neg combination;
  • every attribute/channel/high value;
  • the full abs × neg × output-modifier × clamp × high grid with and without op_sel bits;
  • 60,000 random encodings.

Results: 17,561 decode to exactly LLVM's text, LLVM and the decoder both refuse the other 60,359, and none differ.

Evidence and follow-up

Effect on one local input (the 12,101 PS records from #932; aggregates only), using tools/scan_unsupported_shaders.py:

Measurement Before After
Records containing v_vop3_342/343/35a 4,774 0
Records containing the named binary16 interpolation forms 0 4,774 (117,756 instructions)
Records with a refused interpolation encoding — 0

The per-record compatibility categories don't change. Those records still contain other misdecoded instructions, which are step 3 of #938.

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 capability or build requirement changed.)
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted.

🤖 Generated with Claude Code

https://claude.ai/code/session_01B48PpcRN2Er51keRf2DsS5

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6566920801 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/970). Originally posted by [MasterDomino](https://github.com/MasterDomino) on 2026-11-23T19:15:45Z. --- ## Change Step 2 of #938, scoped as claimed there: `tools/disasm_rdna2.py` decodes the VOP3 binary16 interpolation forms `v_interp_p1ll_f16`, `v_interp_p1lv_f16` and `v_interp_p2_f16` (opcodes 0x342, 0x343, 0x35a) as LLVM 15 prints them for gfx1013. Before, they printed as `v_vop3_342`/`v_vop3_343`/`v_vop3_35a` with three register operands, so `tools/scan_unsupported_shaders.py` reported them as unrecognized opcodes in the VALU category. **Encoding.** These are the encodings LLVM 15.0.7 produces for gfx1013, checked field by field with `llvm-mc`. - `SRC0` holds the attribute (bits 5:0), the channel `xyzw` (bits 7:6) and the high-half select (bit 8, printed `high`). - `SRC1` and, for `p1lv`/`p2`, `SRC2` are the data sources, with the usual `abs`/`neg` bits. - `clamp` and the output modifier (`mul:2`, `mul:4`, `div:2`) follow. - The printed form is `vdst, src1, attrN.c[, src2][ high][ clamp][ omod]`. **Encodings LLVM 15 refuses** keep their eight-byte record and decode as `<name>_unsupported` / `<name> <unsupported VOP3 encoding>`, as `v_readfirstlane_b32`'s VOP3A word already does: - an `abs` or `neg` bit on the attribute operand; - a nonzero `p1ll` third source or its modifier bits; - an output modifier on `p2`; - source codes 209-234, 249, 250 and 255 (literal). **`op_sel` bits** are ignored, as LLVM ignores them. **Inline-constant sources.** LLVM 15 accepts them but prints `/*invalid immediate*/`, with a lone negation as `neg(/*invalid immediate*/)`. The decoder prints the same text, so its output stays identical to LLVM's. Not in this PR: - the instruction-boundary and `s_endpgm` work from #951/#956; - step 3 (SDWA VOPC, `image_atomic_*`, `v_add_co_ci_u32_e32`); - the VOP3 `v_interp_*_f32_e64` forms; - scanner support for these instructions, which `pixel_aot` does not lower (#711/#713). Refs #938 ## Verification Upstream `main` at `6f111ed`, Fedora 45 x86_64, Python 3.15.2, LLVM 15.0.7. ```sh P=/usr/lib64/llvm15 LLVM_LIB=$P/lib/libLLVM-15.so LLVM_MC=$P/bin/llvm-mc LLVM_OBJCOPY=$P/bin/llvm-objcopy \ python -B tests/rdna2_tools_check.py python -B tests/rdna2_tools_check.py ``` With LLVM, the suite exits `OK`. Without it, `OK` with the LLVM-gated tests skipped. The 26 platform-independent checks, `tests/pixel_aot_check.py binary` and `tests/form_coverage_check.py` also exit 0. New tests: - **`test_interp_f16_uses_llvm_spelling`** (pure Python). - Eight encodings with llvm-mc 15.0.7's text as the expected value. They cover each opcode, `high`, `clamp`, each output modifier, `abs`/`neg`/`-|x|`, SGPR and special-register sources, attributes 0-63, and both inline-constant spellings. - Five refused encodings, one per refusal rule, must decode as `_unsupported` with the following `s_endpgm` still at offset 8. Every vector was checked against `pixel_aot.disassemble`. - **`test_interp_f16_llvm_round_trip`** (LLVM 15). - 14 lines are assembled by llvm-mc and decoded. The text must equal LLVM's, and must re-assemble to the same bytes. - Neighbouring lines differ in one field (attribute, channel, `high`, SGPR source, swapped sources, modifiers, `clamp`, output modifier), so a dropped or swapped field changes the bytes. - **`test_binary_scan_recognizes_decoded_interp_f16`** (pure Python, source-built scan case). - `scan_directory_or_files` runs on a `.bin` of llvm-mc output. - Expected: the opcodes are recognized, attributed to VINTRP, and classified `opcode_recognized_translator_rejected`, with no `v_vop3_*` names. **Negative control.** With `tools/disasm_rdna2.py` reverted to `6f111ed`: `FAILED (failures=15)`. That is 13 spelling subtests, the round trip and the scan case. Restoring the change passes all of them. **Exhaustive comparison (local, not part of the suite)** against LLVM 15's `LLVMDisasmInstruction` for gfx1013, 77,920 encodings of the three opcodes: - every source code (0-511) in each source slot with every `abs`/`neg` combination; - every attribute/channel/`high` value; - the full `abs` × `neg` × output-modifier × `clamp` × `high` grid with and without `op_sel` bits; - 60,000 random encodings. Results: 17,561 decode to exactly LLVM's text, LLVM and the decoder both refuse the other 60,359, and none differ. ## Evidence and follow-up **Effect on one local input** (the 12,101 PS records from #932; aggregates only), using `tools/scan_unsupported_shaders.py`: | Measurement | Before | After | |---|---|---| | Records containing `v_vop3_342`/`343`/`35a` | 4,774 | 0 | | Records containing the named binary16 interpolation forms | 0 | 4,774 (117,756 instructions) | | Records with a refused interpolation encoding | — | 0 | The per-record compatibility categories don't change. Those records still contain other misdecoded instructions, which are step 3 of #938. ## 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 capability or build requirement changed.) - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01B48PpcRN2Er51keRf2DsS5
upstream-sync closed this pull request 2026-11-24 06:45:38 +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!963
No description provided.