tombox-xshader: decode and translate ds_wrap_rtn_b32 on compute LDS #245

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

@⁠azerioxfr on GitHub · 2026-11-23 07:16 UTC · original
azerioxfr:xshader-ds-wrap-rtn → main · +16 −1 · 3 files · 1 commits · closed without merging

Library / area: tombox-xshader, compute LDS read-modify-write ops

Exports changed (exports.txt rows): none

Source of the behaviour: opcode from tests/isa_table/gfx1013.txt (DS 0x34). Semantics from the RDNA2 ISA description of DS_WRAP_RTN_B32.

One topic, +16 / -1: 1 line in rdna2/mnem.rs, 2 in hlsl.rs, 13 lines of test.

What was missing

tests/isa_table.rs lists DS 0x34 under "ds: gfx1013 opcodes not named by the decoder".

The change

opcode lowering
ds_wrap_rtn_b32 (0x34) tmp = MEM[addr]; MEM[addr] = tmp >= DATA ? tmp - DATA : tmp + DATA2 (unsigned compare, wrapping); vdst = tmp

It uses the same compare-exchange loop as ds_inc_u32 / ds_mskor_b32, so the update is atomic.

Tests

ds_lds_mskor_wrxchg2 gains six ds_wrap_rtn_b32 cases at offsets 0 and 0x104, read back through the neighbouring lane. They cover both branches and tmp == DATA (which gives 0).

run (WARP, --release, DXC 1.9.2609) result
exec_mem::ds::ds_lds_mskor_wrxchg2 5 mnemonics verified, 0 failing, 31 cases
mutation: > instead of >= 4 verified, 1 failing
--test isa_table / --test opcodes 3 / 26 passed

Run on x86_64-pc-windows-gnu (no MSVC linker here). Integer only.

  • cargo test -p tombox-xshader --test exec -- --exact exec_mem::ds::ds_lds_mskor_wrxchg2 passes
  • 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 07:16 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/245) `azerioxfr:xshader-ds-wrap-rtn` → `main` · +16 −1 · 3 files · 1 commits · closed without merging **Library / area:** tombox-xshader, compute LDS read-modify-write ops **Exports changed (exports.txt rows):** none **Source of the behaviour:** opcode from `tests/isa_table/gfx1013.txt` (DS 0x34). Semantics from the RDNA2 ISA description of `DS_WRAP_RTN_B32`. One topic, +16 / -1: 1 line in `rdna2/mnem.rs`, 2 in `hlsl.rs`, 13 lines of test. ### What was missing `tests/isa_table.rs` lists DS 0x34 under "ds: gfx1013 opcodes not named by the decoder". ### The change | opcode | lowering | |---|---| | `ds_wrap_rtn_b32` (0x34) | `tmp = MEM[addr]; MEM[addr] = tmp >= DATA ? tmp - DATA : tmp + DATA2` (unsigned compare, wrapping); `vdst = tmp` | It uses the same compare-exchange loop as `ds_inc_u32` / `ds_mskor_b32`, so the update is atomic. ### Tests `ds_lds_mskor_wrxchg2` gains six `ds_wrap_rtn_b32` cases at offsets 0 and 0x104, read back through the neighbouring lane. They cover both branches and `tmp == DATA` (which gives 0). | run (WARP, `--release`, DXC 1.9.2609) | result | |---|---| | `exec_mem::ds::ds_lds_mskor_wrxchg2` | **5 mnemonics verified, 0 failing, 31 cases** | | mutation: `>` instead of `>=` | 4 verified, 1 failing | | `--test isa_table` / `--test opcodes` | 3 / 26 passed | Run on `x86_64-pc-windows-gnu` (no MSVC linker here). Integer only. - [x] `cargo test -p tombox-xshader --test exec -- --exact exec_mem::ds::ds_lds_mskor_wrxchg2` passes - [x] No game or console files and no binaries included - [x] No fake success; anything not possible is left `missing` with a note
DS opcode 0x34 was not decoded (the isa_table test lists it under "ds:
gfx1013 opcodes not named by the decoder"). It now decodes and is
lowered with the compare-exchange loop the other read-modify-write LDS
ops use (ds_inc_u32, ds_mskor_b32), so the update is atomic:
tmp = MEM[addr]; MEM[addr] = tmp >= DATA ? tmp - DATA : tmp + DATA2
(unsigned compare, wrapping arithmetic); vdst = tmp. Semantics from the
RDNA2 ISA description.

Tests: ds_lds_mskor_wrxchg2 gains six ds_wrap_rtn_b32 cases (offsets 0
and 0x104) read back through the neighbouring lane, covering both
branches and equal values (tmp == DATA gives 0): 5 mnemonics verified,
0 failing, 31 cases on WARP. Using > instead of >= fails the op.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:15:37 +00:00
github-bot closed this pull request 2026-11-26 06:15:37 +00:00
Author
Owner

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

Applied locally on main with your authorship kept (cherry-picked, a1d04e8); 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/245#issuecomment-7103544123) Applied locally on main with your authorship kept (cherry-picked, a1d04e8); 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

I checked ds_wrap_rtn_b32 on RDNA2 silicon: a gfx1036 iGPU (Ryzen 5 9600X), ROCm/HIP 5.7.1, one wave32 workgroup with 64 KiB of LDS. That's RDNA2, not gfx1013.

  • Offset 0: 8,192 cases with random old values. d0 was often equal to old or old ± 1, to hit the >= edge. The returned value and the stored value match old >= d0 ? old - d0 : old + d1 on all cases.
  • Offset 0x104: the returned value is the old word at addr + offset, so the offset is added as in the other DS ops.
  • Out of range: with offset 0xfffc, every tested address lands at or past the end of the 64 KiB allocation, and all 8,192 return 0 instead of wrapping. The translator's 32 KiB LDS mirror (& 8191) wraps such addresses instead. That predates this PR and matters only for out-of-range accesses.

(Measured with an AI assistant, Claude.)

**@⁠SchmashinPrunes** on GitHub · 2026-11-24 13:20 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/245#issuecomment-7132682978) I checked `ds_wrap_rtn_b32` on RDNA2 silicon: a gfx1036 iGPU (Ryzen 5 9600X), ROCm/HIP 5.7.1, one wave32 workgroup with 64 KiB of LDS. That's RDNA2, not gfx1013. - **Offset 0:** 8,192 cases with random old values. `d0` was often equal to old or old ± 1, to hit the `>=` edge. The returned value and the stored value match `old >= d0 ? old - d0 : old + d1` on all cases. - **Offset 0x104:** the returned value is the old word at `addr + offset`, so the offset is added as in the other DS ops. - **Out of range:** with offset 0xfffc, every tested address lands at or past the end of the 64 KiB allocation, and all 8,192 return 0 instead of wrapping. The translator's 32 KiB LDS mirror (`& 8191`) wraps such addresses instead. That predates this PR and matters only for out-of-range accesses. (Measured with an AI assistant, Claude.)
Author
Owner

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

Applied on main in a1d04e8 (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/245#issuecomment-7163360460) Applied on main in a1d04e8 (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.