tombox-xshader: decode and lower the DS src2 read-modify-write ops #264

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

@⁠azerioxfr on GitHub · 2026-11-23 08:35 UTC · original
azerioxfr:xshader-ds-src2-ops → main · +103 −0 · 3 files · 1 commits · closed without merging

Library / area: tombox-xshader, compute LDS *_src2_* ops (hlsl.rs next to the other LDS read-modify-write ops)

Exports changed (exports.txt rows): none

Source of the behaviour: opcodes from tests/isa_table/gfx1013.txt (DS 0x80..0x8b, 0x8d). The address rule is from the AMD ISA description of the src2 ops: A = ADDR_BASE; B = A + 4 * (offset1[7] ? {A[31], A[31:17]} : {offset1[6], offset1[6:0], offset0}); MEM[A] = MEM[A] OP MEM[B].

One topic, +103: 5 lines in rdna2/mnem.rs, 57 in hlsl.rs, 41 lines of test.

What was missing

tests/isa_table.rs lists these 13 under "ds: gfx1013 opcodes not named by the decoder".

The change

ops lowering
ds_add/min_u32/max_u32/and/or/xor/write_src2_* Interlocked{Add,Min,Max,And,Or,Xor,Exchange} on tb_lds[A] with the value read from tb_lds[B]
ds_sub/rsub/inc/dec_src2_u32, ds_min/max_src2_i32 the compare-exchange loop the other LDS read-modify-write ops use

A is the base address without the offset, and B uses the sign-extended 15-bit field above. The src2 value is read once, before the atomic update of A.

Tests

New exec_mem::ds::ds_lds_src2_compute: all 13 ops in both address forms (offset1[7] clear with offset0 0x40 and 0x7fc0, offset1[7] set with A[31:17] = 64 and 0x7fc0).

run (WARP, --release, DXC 1.9.2609) result
ds_lds_src2_compute 13 mnemonics verified, 0 failing, 52 cases
mutation: the ×4 byte scaling of B dropped every case fails
all exec_mem::ds tests (regression) 10 passed (ds_lds 32, ds_lds_ext 15, ds_lds_mskor_wrxchg2 4 mnemonics)
--test isa_table / --test opcodes 3 / 26 passed

Run on x86_64-pc-windows-gnu (no MSVC linker here). Integer only. The 64-bit and float src2 forms are left out.

  • tests pass
  • No game or console files and no binaries included
  • No fake success; anything not possible is left missing with a note
**@⁠azerioxfr** on GitHub · 2026-11-23 08:35 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/264) `azerioxfr:xshader-ds-src2-ops` → `main` · +103 −0 · 3 files · 1 commits · closed without merging **Library / area:** tombox-xshader, compute LDS `*_src2_*` ops (`hlsl.rs` next to the other LDS read-modify-write ops) **Exports changed (exports.txt rows):** none **Source of the behaviour:** opcodes from `tests/isa_table/gfx1013.txt` (DS 0x80..0x8b, 0x8d). The address rule is from the AMD ISA description of the src2 ops: `A = ADDR_BASE; B = A + 4 * (offset1[7] ? {A[31], A[31:17]} : {offset1[6], offset1[6:0], offset0}); MEM[A] = MEM[A] OP MEM[B]`. One topic, +103: 5 lines in `rdna2/mnem.rs`, 57 in `hlsl.rs`, 41 lines of test. ### What was missing `tests/isa_table.rs` lists these 13 under "ds: gfx1013 opcodes not named by the decoder". ### The change | ops | lowering | |---|---| | `ds_add/min_u32/max_u32/and/or/xor/write_src2_*` | `Interlocked{Add,Min,Max,And,Or,Xor,Exchange}` on `tb_lds[A]` with the value read from `tb_lds[B]` | | `ds_sub/rsub/inc/dec_src2_u32`, `ds_min/max_src2_i32` | the compare-exchange loop the other LDS read-modify-write ops use | A is the base address without the offset, and B uses the sign-extended 15-bit field above. The src2 value is read once, before the atomic update of A. ### Tests New `exec_mem::ds::ds_lds_src2_compute`: all 13 ops in both address forms (offset1[7] clear with offset0 0x40 and 0x7fc0, offset1[7] set with A[31:17] = 64 and 0x7fc0). | run (WARP, `--release`, DXC 1.9.2609) | result | |---|---| | `ds_lds_src2_compute` | **13 mnemonics verified, 0 failing, 52 cases** | | mutation: the ×4 byte scaling of B dropped | every case fails | | all `exec_mem::ds` tests (regression) | 10 passed (`ds_lds` 32, `ds_lds_ext` 15, `ds_lds_mskor_wrxchg2` 4 mnemonics) | | `--test isa_table` / `--test opcodes` | 3 / 26 passed | Run on `x86_64-pc-windows-gnu` (no MSVC linker here). Integer only. The 64-bit and float src2 forms are left out. - [x] tests pass - [x] No game or console files and no binaries included - [x] No fake success; anything not possible is left `missing` with a note
DS opcodes 0x80..0x8b and 0x8d were not named (unsupported encoding [ds<0x80>]) and had no compute-shader lowering. They read a second LDS location and combine it with the first under one atomic update: ds[A] = ds[A] OP ds[B], with the src2 value read once (not atomic with the update, matching the hardware).

The second address follows the CDNA1/RDNA DS rule: B = A + 4 * (offset1[7] ? sext15(A[31:17]) : sext15(offset1[6:0]<<8 | offset0)).

Each op reuses the LDS read-modify-write of the other atomics: InterlockedAdd/Min/Max/And/Or/Xor/Exchange for the direct forms, and the InterlockedCompareExchange loop for sub, rsub, i32 min/max, inc and dec.

Tests: tests/exec_mem/ds.rs ds_lds_src2_compute covers all 13 opcodes in both address forms (offset1[7] clear with offset0 0x40 and 0x7fc0, offset1[7] set with A[31:17] = 64 and 0x7fc0). A mutation that drops the *4 byte scaling fails every case.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:16:27 +00:00
github-bot closed this pull request 2026-11-26 06:16:27 +00:00
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-23 14:08 UTC · original

Applied locally on main with your authorship kept (cherry-picked, 6361ba0); the tombox-xshader suite passes in a sandbox (exec 155/155 on WARP). It ships in the next release; this PR will be closed when that is pushed. Thanks.

**@⁠omonkeyz** on GitHub · 2026-11-23 14:08 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/264#issuecomment-7103533200) Applied locally on main with your authorship kept (cherry-picked, 6361ba0); the tombox-xshader suite passes in a sandbox (exec 155/155 on WARP). It ships in the next release; this PR will be closed when that is pushed. Thanks.
Author
Owner

@⁠SchmashinPrunes on GitHub · 2026-11-24 13:20 UTC · original

A note in case someone plans a silicon check of this PR. The ds_*_src2_* ops can't be verified on gfx103x (RDNA2.x) hardware.

  • LLVM 18 assembles them for gfx1010 and gfx1013 but rejects them for gfx1036 ("instruction not supported on this GPU").
  • I ran them as raw encodings (DS opcode 0x80 and up) on a gfx1036 iGPU. The wave hangs, and the driver resets the GPU.
  • So they exist on the console's gfx10.1 but not on later RDNA2 parts. The address rule here, including the offset1[7] form, needs a gfx101x GPU (RX 5000 series) to check.

(Checked with an AI assistant, Claude.)

**@⁠SchmashinPrunes** on GitHub · 2026-11-24 13:20 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/264#issuecomment-7132683857) A note in case someone plans a silicon check of this PR. The `ds_*_src2_*` ops can't be verified on gfx103x (RDNA2.x) hardware. - LLVM 18 assembles them for gfx1010 and gfx1013 but rejects them for gfx1036 ("instruction not supported on this GPU"). - I ran them as raw encodings (DS opcode 0x80 and up) on a gfx1036 iGPU. The wave hangs, and the driver resets the GPU. - So they exist on the console's gfx10.1 but not on later RDNA2 parts. The address rule here, including the offset1[7] form, needs a gfx101x GPU (RX 5000 series) to check. (Checked with an AI assistant, Claude.)
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-25 13:08 UTC · original

Applied on main in 6361ba0 (cherry-picked onto the current history with your authorship kept; comment lines stripped per CONTRIBUTING). Thank you.

**@⁠omonkeyz** on GitHub · 2026-11-25 13:08 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/264#issuecomment-7163340661) Applied on main in 6361ba0 (cherry-picked onto the current history with your authorship kept; comment lines stripped per CONTRIBUTING). Thank you.

Pull request closed

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