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

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

@⁠GDAgent on GitHub · 2026-11-23 00:55 UTC · original
GDAgent:fix/xshader-vop3p-int16 → main · +150 −13 · 4 files · 1 commits · closed without merging

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
**@⁠GDAgent** on GitHub · 2026-11-23 00:55 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/198) `GDAgent:fix/xshader-vop3p-int16` → `main` · +150 −13 · 4 files · 1 commits · closed without merging **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
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>]". A UE5 Xbox Series title hits
this in a compute shader (v_pk_add_u16 v5, v5, -1 followed by
v_pk_mul_lo_u16) and treats the failed PSO as fatal.

Add names for VOP3P opcodes 0x00-0x0d per the RDNA2 ISA opcode table
(section 12.10) and translate 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 (ISA
section 6.5) 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: decoder names and DXC compile for all 14 ops, refusal checks, and
isa_sweep cases against a reference model for four OPSEL/CLAMP variants
per op plus the title's inline -1 form (WARP).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:13:31 +00:00
github-bot closed this pull request 2026-11-26 06:13:31 +00:00
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-23 01:38 UTC · original

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.

**@⁠omonkeyz** on GitHub · 2026-11-23 01:38 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/198#issuecomment-7089304016) 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

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