tombox-xshader: translate the RDNA2 VOP3P packed 16-bit integer ops #198

Closed
GDAgent wants to merge 1 commit from upstream-pr/198 into main
GDAgent commented 2026-11-23 00:55:17 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by GDAgent on 2026-11-23T00:55:17Z.


Library / area: tombox-xshader (rdna2 VOP3P decoder names, hlsl.rs packed integer ops, tests/opcodes.rs, isa_sweep)

Exports changed (exports.txt rows): none

Source of the behaviour: RDNA2 ISA: VOP3P opcode table (section 12.10) for opcodes 0x00-0x0d, OPSEL/OPSEL_HI source-half selection, and CLAMP saturation for packed integer add/sub (section 6.5).

The decoder named only the two packed shifts among the VOP3P integer opcodes, so v_pk_add_u16 (0x0a) and the rest of the family were refused as unsupported vector op [vop3<0x40a>]. The Matrix Awakens hits this in a compute shader (v_pk_add_u16 v5, v5, -1 followed by v_pk_mul_lo_u16), and the failed compute PSO is fatal for it.

Changes:

  • Names for VOP3P opcodes 0x00-0x0d.
  • All 14 integer ops through one helper: v_pk_mad_i16/u16, v_pk_mul_lo_u16, v_pk_add/sub_i16/u16, v_pk_lshlrev/lshrrev_b16, v_pk_ashrrev_i16, v_pk_max/min_i16/u16. OPSEL/OPSEL_HI pick the source halves for each result half; signed ops sign-extend each half; shift counts are the low 4 bits of the selected source-0 half.
  • CLAMP saturates add/sub to the signed or unsigned 16-bit range and is accepted on min/max, where it cannot change the result. CLAMP on mad/mul/shifts, NEG/NEG_HI and inline float constants have no defined integer behaviour in the ISA and are refused with a message naming the op. The two packed shifts keep their previous output.

Tests:

  • tests/opcodes.rs: decoder names and a DXC compile for all 14 ops, and the refusal checks.
  • isa_sweep cases against a reference model: four OPSEL/CLAMP variants per op plus the title's inline -1 form (WARP).
  • cargo test -p tombox-xshader --no-fail-fast on current main: 293 passed, 0 failed (WARP).
  • Native Windows 11; not run under Proton.

Not verified in a title: in The Matrix Awakens the compute shader that was refused before (vop3<0x40a>, PSO creation E_FAIL) now translates and compiles, and a later run logged no translation failures. Whether that shader's output is correct in the title was not checked; the packed-op results themselves are checked against the reference model on WARP, not on console hardware.

  • 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
<!-- greyfinch-sync:omonkeyz/xbox-emulator:issue:6550071322 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/198). Originally posted by [GDAgent](https://github.com/GDAgent) on 2026-11-23T00:55:17Z. --- **Library / area:** `tombox-xshader` (`rdna2` VOP3P decoder names, `hlsl.rs` packed integer ops, `tests/opcodes.rs`, `isa_sweep`) **Exports changed (exports.txt rows):** none **Source of the behaviour:** RDNA2 ISA: VOP3P opcode table (section 12.10) for opcodes 0x00-0x0d, OPSEL/OPSEL_HI source-half selection, and CLAMP saturation for packed integer add/sub (section 6.5). The decoder named only the two packed shifts among the VOP3P integer opcodes, so `v_pk_add_u16` (0x0a) and the rest of the family were refused as `unsupported vector op [vop3<0x40a>]`. The Matrix Awakens hits this in a compute shader (`v_pk_add_u16 v5, v5, -1` followed by `v_pk_mul_lo_u16`), and the failed compute PSO is fatal for it. Changes: - Names for VOP3P opcodes 0x00-0x0d. - All 14 integer ops through one helper: `v_pk_mad_i16/u16`, `v_pk_mul_lo_u16`, `v_pk_add/sub_i16/u16`, `v_pk_lshlrev/lshrrev_b16`, `v_pk_ashrrev_i16`, `v_pk_max/min_i16/u16`. OPSEL/OPSEL_HI pick the source halves for each result half; signed ops sign-extend each half; shift counts are the low 4 bits of the selected source-0 half. - CLAMP saturates add/sub to the signed or unsigned 16-bit range and is accepted on min/max, where it cannot change the result. CLAMP on mad/mul/shifts, NEG/NEG_HI and inline float constants have no defined integer behaviour in the ISA and are refused with a message naming the op. The two packed shifts keep their previous output. Tests: - `tests/opcodes.rs`: decoder names and a DXC compile for all 14 ops, and the refusal checks. - `isa_sweep` cases against a reference model: four OPSEL/CLAMP variants per op plus the title's inline `-1` form (WARP). - `cargo test -p tombox-xshader --no-fail-fast` on current `main`: 293 passed, 0 failed (WARP). - Native Windows 11; not run under Proton. **Not verified in a title:** in The Matrix Awakens the compute shader that was refused before (`vop3<0x40a>`, PSO creation `E_FAIL`) now translates and compiles, and a later run logged no translation failures. Whether that shader's output is correct in the title was not checked; the packed-op results themselves are checked against the reference model on WARP, not on console hardware. - [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
omonkeyz commented 2026-11-23 01:38:37 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by omonkeyz on 2026-11-23T01:38:37Z.


Applied in 54db2e3 (merged in 24e6c10) with your authorship kept, thanks. It conflicted with #202, since both add helpers after sat_int; I resolved it by keeping both.

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7089304016 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/198#issuecomment-7089304016). Originally posted by [omonkeyz](https://github.com/omonkeyz) on 2026-11-23T01:38:37Z. --- Applied in 54db2e3 (merged in 24e6c10) with your authorship kept, thanks. It conflicted with #202, since both add helpers after sat_int; I resolved it by keeping both.

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!198
No description provided.