feat(shader): implement the missing 32-bit LDS atomics and fix ds_min/max_f32 #320

Merged
adriadam10 merged 2 commits from upstream-pr/320 into main 2026-10-03 07:13:33 +00:00
adriadam10 commented 2026-10-02 05:11:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-02T05:11:53Z.


What

New (these threw "DS opcode is not supported"): ds_rsub_u32, ds_rsub_rtn_u32, ds_inc_u32, ds_dec_u32, ds_mskor_b32, ds_mskor_rtn_b32, ds_cmpst_b32, ds_cmpst_rtn_b32, ds_cmpst_f32, ds_cmpst_rtn_f32, ds_add_f32, ds_add_rtn_f32, ds_min_rtn_f32, ds_max_rtn_f32, ds_wrap_rtn_b32, ds_nop.

Fix: ds_min_f32 / ds_max_f32 take a single data operand on gfx10, but the translation read a second one (source2, the unused data1 field, which is usually v0) and stored data0 when that compared below/above memory. They now keep min/max(memory, data).

The reference emulators don't implement these, so the semantics were measured on an RDNA2 GPU (Radeon 660M, gfx1035) with raw kernels through ROCm HSA. A Python model of all eight forms matched 512/512 hardware results (old = memory before, d0/d1 = data0/data1):

  • rsub: d0 - old
  • cmpst_b32: old == d0 ? d1 : old; cmpst_f32 does the same with an ordered float compare
  • mskor: (old & ~d0) | d1
  • wrap: old >= d0 ? old - d0 : old + d1
  • add_f32: IEEE add
  • min/max_f32: IEEE minNum/maxNum, so a NaN in memory or data loses to the number, and −0 < +0

inc/dec reuse the existing ops.

Implementation: SharedAtomicFMin32/FMax32 now return the old value (U32) like the other shared atomics, so the _rtn forms share them; they no longer need the scratch-dword workaround. New IR ops SharedAtomicRsub32/FAdd32/Cmpst32/CmpstF32/Mskor32/Wrap32 are emitted through the existing AtomicUpdate compare-exchange loop, with the same workgroup acquire/release barrier Atomic32 uses for LDS.

Test agc_driver_lds_atomics: one wave32 shader, each of the 17 ops on its own LDS dword per lane. It checks the memory afterwards and every _rtn result. Inputs are random words, small integers (inc/dec/wrap/rsub edges), float specials (±0, ±1, NaN, inf), and equal/unequal pairs for cmpst. The expected values come from a C++ model of the hardware semantics above. Float ops are not checked on lanes with f32 denormals, since those follow the driver's float controls.

Tested

Linux, full ctest (99) passes.

  • RADV (Radeon 660M) and lavapipe: the test passes.
  • Without the change it fails with "DS opcode is not supported".

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: #251 (test harness); review only the last commit
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4712934771 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/320). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-02T05:11:53Z. --- ### What **New** (these threw "DS opcode is not supported"): `ds_rsub_u32`, `ds_rsub_rtn_u32`, `ds_inc_u32`, `ds_dec_u32`, `ds_mskor_b32`, `ds_mskor_rtn_b32`, `ds_cmpst_b32`, `ds_cmpst_rtn_b32`, `ds_cmpst_f32`, `ds_cmpst_rtn_f32`, `ds_add_f32`, `ds_add_rtn_f32`, `ds_min_rtn_f32`, `ds_max_rtn_f32`, `ds_wrap_rtn_b32`, `ds_nop`. **Fix**: `ds_min_f32` / `ds_max_f32` take a single data operand on gfx10, but the translation read a second one (`source2`, the unused data1 field, which is usually v0) and stored data0 when *that* compared below/above memory. They now keep min/max(memory, data). The reference emulators don't implement these, so the semantics were measured on an RDNA2 GPU (Radeon 660M, gfx1035) with raw kernels through ROCm HSA. A Python model of all eight forms matched **512/512** hardware results (`old` = memory before, `d0`/`d1` = data0/data1): - `rsub`: `d0 - old` - `cmpst_b32`: `old == d0 ? d1 : old`; `cmpst_f32` does the same with an ordered float compare - `mskor`: `(old & ~d0) | d1` - `wrap`: `old >= d0 ? old - d0 : old + d1` - `add_f32`: IEEE add - `min/max_f32`: IEEE minNum/maxNum, so a NaN in memory or data loses to the number, and **−0 < +0** `inc`/`dec` reuse the existing ops. Implementation: `SharedAtomicFMin32/FMax32` now return the old value (U32) like the other shared atomics, so the `_rtn` forms share them; they no longer need the scratch-dword workaround. New IR ops `SharedAtomicRsub32/FAdd32/Cmpst32/CmpstF32/Mskor32/Wrap32` are emitted through the existing `AtomicUpdate` compare-exchange loop, with the same workgroup acquire/release barrier `Atomic32` uses for LDS. Test `agc_driver_lds_atomics`: one wave32 shader, each of the 17 ops on its own LDS dword per lane. It checks the memory afterwards and every `_rtn` result. Inputs are random words, small integers (inc/dec/wrap/rsub edges), float specials (±0, ±1, NaN, inf), and equal/unequal pairs for cmpst. The expected values come from a C++ model of the hardware semantics above. Float ops are not checked on lanes with f32 denormals, since those follow the driver's float controls. ### Tested Linux, full ctest (99) passes. - RADV (Radeon 660M) and lavapipe: the test passes. - Without the change it fails with "DS opcode is not supported". ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: #251 (test harness); review only the last commit - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-02 05:12:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-02T05:12:14Z.


Progress report (709d7fe → c8af889)

📈 GPU shader instructions: 54.03% (+1.37%, +16 implemented instructions)

✅ 16 implemented
Encoding Name
DS DS_ADD_F32
DS DS_ADD_RTN_F32
DS DS_CMPST_B32
DS DS_CMPST_F32
DS DS_CMPST_RTN_B32
DS DS_CMPST_RTN_F32
DS DS_DEC_U32
DS DS_INC_U32
DS DS_MAX_RTN_F32
DS DS_MIN_RTN_F32
DS DS_MSKOR_B32
DS DS_MSKOR_RTN_B32
DS DS_NOP
DS DS_RSUB_RTN_U32
DS DS_RSUB_U32
DS DS_WRAP_RTN_B32
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5945995120 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/320#issuecomment-5945995120). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-02T05:12:14Z. --- <!-- progress-report --> ### Progress report (709d7fe → c8af889) 📈 **GPU shader instructions**: 54.03% (+1.37%, +16 implemented instructions) <details> <summary>✅ 16 implemented</summary> | Encoding | Name | | - | - | | DS | `DS_ADD_F32` | | DS | `DS_ADD_RTN_F32` | | DS | `DS_CMPST_B32` | | DS | `DS_CMPST_F32` | | DS | `DS_CMPST_RTN_B32` | | DS | `DS_CMPST_RTN_F32` | | DS | `DS_DEC_U32` | | DS | `DS_INC_U32` | | DS | `DS_MAX_RTN_F32` | | DS | `DS_MIN_RTN_F32` | | DS | `DS_MSKOR_B32` | | DS | `DS_MSKOR_RTN_B32` | | DS | `DS_NOP` | | DS | `DS_RSUB_RTN_U32` | | DS | `DS_RSUB_U32` | | DS | `DS_WRAP_RTN_B32` | </details>
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
boykopovar/AnyPS5!320
No description provided.