RDNA2 691/721: LDS atomics (sub/rsub/inc/dec/min_i32/max_i32/cmpst/wrxchg) #23

Closed
SchmashinPrunes wants to merge 0 commits from upstream-pr/23 into main
SchmashinPrunes commented 2026-11-21 17:59:20 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by SchmashinPrunes on 2026-11-21T17:59:20Z.


Library / area: tombox-xshader (RDNA2 shader translator) / progress map (RDNA2 instructions). Part of #17.

Exports changed (exports.txt rows): none

Source of the behaviour: RDNA2 ISA DS semantics as encoded by LLVM's AMDGPU backend for GFX10 (llvm/lib/Target/AMDGPU/DSInstructions.td, LangRef atomicrmw). The same semantics are already used and tested by the GDS path (src/hlsl/gds.rs, tests/exec_mem/gds.rs). No console files used.

What changed

The LDS (group-shared) path only lowered ds_add/min_u32/max_u32/and/or/xor. The rest of the DS atomics were lowered for GDS only, so they never counted as verified. This lowers them for LDS too:

  • Interlocked*: ds_sub_u32, ds_wrxchg_rtn_b32, ds_cmpst_b32.
  • Compare-exchange loop (same shape as the GDS path): ds_rsub_u32, ds_inc_u32, ds_dec_u32, ds_min_i32, ds_max_i32. tb_lds is uint, so the signed min/max don't rely on DXC picking a signed InterlockedMin/Max overload.
  • All of the above plus their _rtn forms: 15 mnemonics.

Semantics worth calling out:

  • ds_inc/ds_dec are uinc_wrap/udec_wrap: old u>= data ? 0 : old+1 and (old == 0 || old u> data) ? data : old-1.
  • On GFX10, ds_cmpst takes data0 = compare value, data1 = value stored on a match. LLVM: "the order of src and cmp is the opposite of BUFFER_ATOMIC_CMPSWAP"; GFX11 swaps them back as ds_cmpstore.

Tests

New tests/exec_mem/ds.rs ds_lds_atomics_ext: 106 cases, each also rerun with runtime inputs.

  • One dword per thread, read back by the neighbour thread, so the order-dependent ops have fixed results. Inputs hit the edges: old == data, old == 0, neighbouring small values, negative vs positive (signed vs unsigned), and cmpst match / no match.
  • All 64 threads on one dword for the order-independent ops (sub, signed min/max, inc/dec that never wrap), to exercise the retry loop under contention.
  • Mutation check: swapping the cmpst operands, or making ds_min_i32 compare unsigned, makes the test fail (26 failing cases).
TOMBOX_DXC_DIR=<dxc 1.9.2609>\bin\x64 cargo test -p tombox-xshader --release --test exec ds_
test result: ok. 8 passed; 0 failed
ds_lds_ext: 15 mnemonics verified, 0 failing, 106 cases, 106 rerun with runtime inputs

python tools/progress/gen.py: RDNA2 instructions 676/721 → 691/721 (rebased onto 8cd153d; the code was unchanged by the rebase and upstream has not touched tombox-xshader since the original test run). Only the instruction metric changes in LIBRARY_MAP / MILESTONES / summary / badges. Touches the same generated progress files as other open RDNA2 PRs; whichever merges later just reruns gen.py.

Full cargo test -p tombox-xshader --release (Windows 11 LTSC, WARP)

No new failures. Failures that are identical on unpatched main (fef9a6e):

  • exec: vop::basic::{salu,vop1,vop2,vop3}_basic, the same 4 that #15 reports.

  • amp / fixtures / mesh: 11 tests that need analysis/shaders/... dump fixtures (#13 makes these skip).

  • mesh::mesh_refusals_are_explicit: panics at mesh.rs:247 (expect("refusal")) on unpatched main too.

  • cargo test -p tombox-xshader passes for the changed area. Remaining failures are pre-existing, listed above.

  • No game or console files and no binaries included

  • No fake success; anything not possible is left missing with a note

🤖 Generated with Claude Code

<!-- greyfinch-sync:omonkeyz/xbox-emulator:issue:6532450288 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/23). Originally posted by [SchmashinPrunes](https://github.com/SchmashinPrunes) on 2026-11-21T17:59:20Z. --- **Library / area:** tombox-xshader (RDNA2 shader translator) / progress map (RDNA2 instructions). Part of #17. **Exports changed (exports.txt rows):** none **Source of the behaviour:** RDNA2 ISA DS semantics as encoded by LLVM's AMDGPU backend for GFX10 (`llvm/lib/Target/AMDGPU/DSInstructions.td`, LangRef `atomicrmw`). The same semantics are already used and tested by the GDS path (`src/hlsl/gds.rs`, `tests/exec_mem/gds.rs`). No console files used. ### What changed The LDS (group-shared) path only lowered `ds_add/min_u32/max_u32/and/or/xor`. The rest of the DS atomics were lowered for GDS only, so they never counted as verified. This lowers them for LDS too: - **Interlocked\*:** `ds_sub_u32`, `ds_wrxchg_rtn_b32`, `ds_cmpst_b32`. - **Compare-exchange loop** (same shape as the GDS path): `ds_rsub_u32`, `ds_inc_u32`, `ds_dec_u32`, `ds_min_i32`, `ds_max_i32`. `tb_lds` is `uint`, so the signed min/max don't rely on DXC picking a signed `InterlockedMin/Max` overload. - All of the above plus their `_rtn` forms: 15 mnemonics. Semantics worth calling out: - `ds_inc`/`ds_dec` are `uinc_wrap`/`udec_wrap`: `old u>= data ? 0 : old+1` and `(old == 0 || old u> data) ? data : old-1`. - On GFX10, `ds_cmpst` takes **data0 = compare value, data1 = value stored on a match**. LLVM: "the order of src and cmp is the *opposite* of BUFFER_ATOMIC_CMPSWAP"; GFX11 swaps them back as `ds_cmpstore`. ### Tests New `tests/exec_mem/ds.rs` `ds_lds_atomics_ext`: 106 cases, each also rerun with runtime inputs. - **One dword per thread**, read back by the neighbour thread, so the order-dependent ops have fixed results. Inputs hit the edges: old == data, old == 0, neighbouring small values, negative vs positive (signed vs unsigned), and cmpst match / no match. - **All 64 threads on one dword** for the order-independent ops (sub, signed min/max, inc/dec that never wrap), to exercise the retry loop under contention. - **Mutation check:** swapping the cmpst operands, or making `ds_min_i32` compare unsigned, makes the test fail (26 failing cases). ``` TOMBOX_DXC_DIR=<dxc 1.9.2609>\bin\x64 cargo test -p tombox-xshader --release --test exec ds_ test result: ok. 8 passed; 0 failed ds_lds_ext: 15 mnemonics verified, 0 failing, 106 cases, 106 rerun with runtime inputs ``` `python tools/progress/gen.py`: **RDNA2 instructions 676/721 → 691/721** (rebased onto 8cd153d; the code was unchanged by the rebase and upstream has not touched tombox-xshader since the original test run). Only the instruction metric changes in LIBRARY_MAP / MILESTONES / summary / badges. Touches the same generated progress files as other open RDNA2 PRs; whichever merges later just reruns `gen.py`. ### Full `cargo test -p tombox-xshader --release` (Windows 11 LTSC, WARP) No new failures. Failures that are identical on unpatched `main` (fef9a6e): - `exec`: `vop::basic::{salu,vop1,vop2,vop3}_basic`, the same 4 that #15 reports. - `amp` / `fixtures` / `mesh`: 11 tests that need `analysis/shaders/...` dump fixtures (#13 makes these skip). - `mesh::mesh_refusals_are_explicit`: panics at `mesh.rs:247` (`expect("refusal")`) on unpatched `main` too. - [x] `cargo test -p tombox-xshader` passes for the changed area. Remaining failures are pre-existing, listed above. - [x] No game or console files and no binaries included - [x] No fake success; anything not possible is left `missing` with a note 🤖 Generated with [Claude Code](https://claude.com/claude-code)
QuentinDanblon commented 2026-11-21 18:30:16 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by QuentinDanblon on 2026-11-21T18:30:16Z.


FYI: #25 included LDS atomics too, written before I saw your claim in #17. I've removed them from #25 so it doesn't overlap this PR. One thing to check: #21 changes the GDS base to M0[31:16] (RDNA2 ISA §3.7/§10.5). That only touches hlsl/gds.rs and shouldn't affect your LDS path.

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7067302724 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/23#issuecomment-7067302724). Originally posted by [QuentinDanblon](https://github.com/QuentinDanblon) on 2026-11-21T18:30:16Z. --- FYI: #25 included LDS atomics too, written before I saw your claim in #17. I've removed them from #25 so it doesn't overlap this PR. One thing to check: #21 changes the GDS base to M0[31:16] (RDNA2 ISA §3.7/§10.5). That only touches `hlsl/gds.rs` and shouldn't affect your LDS path.
SchmashinPrunes commented 2026-11-21 18:55:14 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by SchmashinPrunes on 2026-11-21T18:55:14Z.


Thanks for the heads-up. I checked #21 against this branch: its hlsl.rs hunk is only the loop-order sort (around line 2230, far from the LDS atomic arm), and the gds.rs change is addressing only (M0[31:16] base plus the size check). The LDS path here doesn't read M0, which matches RDNA2 (no M0 requirement for LDS on GFX9+), so there's no interaction. A test merge of #21 with this branch is clean too.

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7067613985 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/23#issuecomment-7067613985). Originally posted by [SchmashinPrunes](https://github.com/SchmashinPrunes) on 2026-11-21T18:55:14Z. --- Thanks for the heads-up. I checked #21 against this branch: its `hlsl.rs` hunk is only the loop-order sort (around line 2230, far from the LDS atomic arm), and the `gds.rs` change is addressing only (`M0[31:16]` base plus the size check). The LDS path here doesn't read M0, which matches RDNA2 (no M0 requirement for LDS on GFX9+), so there's no interaction. A test merge of #21 with this branch is clean too.
SchmashinPrunes commented 2026-11-21 22:12:10 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by SchmashinPrunes on 2026-11-21T22:12:10Z.


Closing: this landed on main in 1159c96 (the LDS atomic arm in hlsl.rs and ds_lds_atomics_ext in tests/exec_mem/ds.rs match this branch apart from comments). Thanks!

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7070012039 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/23#issuecomment-7070012039). Originally posted by [SchmashinPrunes](https://github.com/SchmashinPrunes) on 2026-11-21T22:12:10Z. --- Closing: this landed on main in 1159c96 (the LDS atomic arm in `hlsl.rs` and `ds_lds_atomics_ext` in `tests/exec_mem/ds.rs` match this branch apart from comments). Thanks!

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