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

Closed
azerioxfr wants to merge 1 commit from upstream-pr/245 into main
azerioxfr commented 2026-11-23 07:16:53 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by azerioxfr on 2026-11-23T07:16:53Z.


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
<!-- greyfinch-sync:omonkeyz/xbox-emulator:issue:6554296268 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/245). Originally posted by [azerioxfr](https://github.com/azerioxfr) on 2026-11-23T07:16:53Z. --- **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
omonkeyz commented 2026-11-23 14:08:35 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by omonkeyz on 2026-11-23T14:08:35Z.


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.

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7103544123 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/245#issuecomment-7103544123). Originally posted by [omonkeyz](https://github.com/omonkeyz) on 2026-11-23T14:08:35Z. --- 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.
SchmashinPrunes commented 2026-11-24 13:20:10 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by SchmashinPrunes on 2026-11-24T13:20:10Z.


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.)

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7132682978 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/245#issuecomment-7132682978). Originally posted by [SchmashinPrunes](https://github.com/SchmashinPrunes) on 2026-11-24T13:20:10Z. --- 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.)
omonkeyz commented 2026-11-25 13:08:58 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by omonkeyz on 2026-11-25T13:08:58Z.


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

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7163360460 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/245#issuecomment-7163360460). Originally posted by [omonkeyz](https://github.com/omonkeyz) on 2026-11-25T13:08:58Z. --- 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

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