feat(shader): implement the missing 32-bit LDS atomics and fix ds_min/max_f32 #320
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/320"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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_f32take 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 - oldcmpst_b32:old == d0 ? d1 : old;cmpst_f32does the same with an ordered float comparemskor:(old & ~d0) | d1wrap:old >= d0 ? old - d0 : old + d1add_f32: IEEE addmin/max_f32: IEEE minNum/maxNum, so a NaN in memory or data loses to the number, and −0 < +0inc/decreuse the existing ops.Implementation:
SharedAtomicFMin32/FMax32now return the old value (U32) like the other shared atomics, so the_rtnforms share them; they no longer need the scratch-dword workaround. New IR opsSharedAtomicRsub32/FAdd32/Cmpst32/CmpstF32/Mskor32/Wrap32are emitted through the existingAtomicUpdatecompare-exchange loop, with the same workgroup acquire/release barrierAtomic32uses 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_rtnresult. 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.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)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
DS_ADD_F32DS_ADD_RTN_F32DS_CMPST_B32DS_CMPST_F32DS_CMPST_RTN_B32DS_CMPST_RTN_F32DS_DEC_U32DS_INC_U32DS_MAX_RTN_F32DS_MIN_RTN_F32DS_MSKOR_B32DS_MSKOR_RTN_B32DS_NOPDS_RSUB_RTN_U32DS_RSUB_U32DS_WRAP_RTN_B32