feat(shader): implement ds_wrxchg2_rtn_b32 and ds_wrxchg2st64_rtn_b32 #385
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/385"
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 DotDebian on 2026-10-02T17:02:03Z.
What
ds_wrxchg2_rtn_b32(DS 0x2e) andds_wrxchg2st64_rtn_b32(DS 0x2f) threwDS opcode is not supported.Both swap
data0with the dword ataddr + offset0 * Sanddata1with the dword ataddr + offset1 * S, and return the two previous values invdstandvdst + 1.Sis 4 bytes, or 256 bytes for the st64 form, as fords_read2_b32/ds_read2st64_b32.Sources: AMD's machine-readable RDNA2 ISA specification (description, operand shape: 64-bit
VDST,ADDR,DATA0,DATA1) and LLVM'sDSInstructions.td(encodings,v[n:n+1], addr, data0, data1 offset0 offset1).Implementation: no new IR. The translation emits one
SharedAtomicSwap32per location, the opds_wrxchg_rtn_b32already uses, so EXEC masking, bounds and the LDS barrier are the existing ones. All three sources are read before the destination is written.Rejected at decode time instead of guessed:
offset0 == offset1: the specification does not say what the two results and the final memory value are when both offsets name the same location.vdst == 255: the second result has no register.The 64-bit forms (
ds_wrxchg_rtn_b64,ds_wrxchg2_rtn_b64,ds_wrxchg2st64_rtn_b64) are not in this PR: LDS is an array of dwords here, and two 32-bit swaps are not a 64-bit atomic exchange.Not measured on hardware. The swaps of the two locations are two separate atomics, not one atomic pair.
Test
agc_driver_ds_wrxchg2: one wave32 compute shader, every lane on its own LDS dwords. It checks both returned values and both memory locations for:ds_wrxchg2_rtn_b32withoffset0 < offset1ds_wrxchg2st64_rtn_b32withoffset0 > offset1v_cmpx_gt_u32on the thread id so that it does not depend on the host subgroup size: inactive lanes keep their registers and their memoryIt also checks the two rejections by their message.
Tested
Windows 11, MinGW-w64 GCC 15.2.0, full
ctest: 109/109 pass.agc_driver_ds_wrxchg2fails withDS opcode is not supported.data0anddata1swapped in the translation it fails withlane 0 ds_wrxchg2_rtn_b32 offset0 memory is 0x40000003, expected 0x30000002.No title was run.
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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-02T17:03:03Z.
Progress report (
5b35909→12008dc)📈 GPU shader instructions: 96.66% (+0.18%, +2 implemented instructions)
✅ 2 implemented
DS_WRXCHG2ST64_RTN_B32DS_WRXCHG2_RTN_B32Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T07:10:12Z.
@boykopovar this one needs your call: is it OK to implement
ds_wrxchg2_rtn_b32andds_wrxchg2st64_rtn_b32as two separate 32-bit atomic swaps? Within one wave the results are right: the encodings match LLVM'sDSInstructions.td, and the test covers EXEC and a destination that aliases the data registers. Between waves, another wave can see one location swapped and the other not yet. Whether the hardware makes the pair atomic isn't documented, and only code racing across waves could tell, so this is about how strict exact-or-throw should be rather than a bug. The author states the gap in the PR body and kept the 64-bit forms out for a similar reason.My read: acceptable, as long as the gap goes into TechnicalDebt (CONTRIBUTING asks for known gaps there, and right now it's only in the PR body).
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-06T08:05:29Z.
@oneandonlydean measured on RDNA2 hardware (gfx1035), for the open question here:
ds_wrxchg2_rtn_b32andds_wrxchg2st64_rtn_b32behave as described: vdst gets the old dword at offset0 * S, vdst + 1 the old dword at offset1 * S, memory ends with data0/data1, S = 4 or 256 bytes.offset0 == offset1is well defined on hardware: the two swaps happen in order, so vdst = old value, vdst + 1 = data0, and memory ends as data1. Throwing for it is exact-or-throw, so not a blocker; but it could be translated as two sequential swaps.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-06T20:48:52Z.
Rebased on main and added the TechnicalDebt line @oneandonlydean asked for (
12008dc), with what we measured on gfx1035: hardware does every lane's first exchange before any lane's second one, so two atomics per invocation can differ when lanes overlap addresses. Build and full ctest green on RADV;agc_driver_ds_wrxchg2also passes on CI's lavapipe (0.44 s cold). Merging once CI is green.