feat(shader): add LDS conditional exchange #1198
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1198"
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 Sanjaysrinivas on 2026-10-07T17:20:58Z.
What
Shaders containing
DS_CONDXCHG32_RTN_B64(DS opcode0x7e) fail decoding on main. Add decoding and LDS translation through two existing 32-bit masked atomic updates. Each dword returns its original value and receives the input's low 31 bits only when the input's high bit is set.Add the combined 16-bit instruction offset to the original VGPR address through the shared atomic path. Out-of-range accesses return zero and leave LDS unchanged. The address is not masked to 64 KiB or rounded down. Snapshot both data dwords and the address before writing destinations so overlapping VGPRs work. Preserve inactive EXEC lanes; reject GDS and VGPR pairs extending beyond v255.
Semantics evidence:
amdgpu_isa_rdna1.xmlandamdgpu_isa_rdna2.xml, instructionDS_CONDXCHG32_RTN_B64: encoding, operand widths and the two conditional 32-bit exchanges.TechnicalDebt.mdconfirmed aligned returns, conditional bit clearing, EXEC masking and operand overlap in wave32 and wave64; contended cases passed per-dword conservation checks.Contended lane ordering, pair-wide indivisibility, interaction with locked 64-bit LDS atomics, gfx1013 and allocated-VGPR EXEC nullification remain documented limitations. The recompiler's existing source-version hashing invalidates affected shader caches; no new IR opcode, backend lock or dependency is added.
Related prior work: #897, closed and unmerged. This implementation uses the existing 32-bit atomic path.
Tested
Revision
34d4cf17, Ubuntu 24.04 under WSL2, GCC 13.3, Release withBUILD_TESTING=ON, Mesa llvmpipe (LLVM 20.1.2, subgroup size 8). Vulkan execution required a usable device and disabled the shader cache.0,0x120and0xfff8, aligned in-range/out-of-range addresses, unchanged LDS and guard words, operand overlap, inactive EXEC lanes and per-dword contention. Decoder rejection and v254:v255 boundary checks also pass.lds_addtidrequires subgroups of at least 32 lanes.libstarget passed. Full CTest: 378 passed, 22 skipped, 1 failed out of 401. The sole failure is the previously documentedguest_accessabort with its working directory on the Windows-mounted filesystem; the identical rebuilt executable passes from WSL ext4/tmp. The full suite is not reported as green.agc_driver_flat_storepassed.tools/check_conventions.py --base origin/mainandgit diff --checkpassed. The branch merges cleanly with upstreammainat34c20eed.No game title or console hardware was tested. The gfx1035 evidence above comes from the reviewer's hardware measurements; local regression execution uses Vulkan llvmpipe.
Checklist
main; merges cleanly with currentmainat34c20eed; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repositoryImported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-08T05:44:52Z.
Progress report (
ac951f8→34d4cf1)📈 GPU shader instructions: 97.08% (+0.08%, +1 implemented instructions)
✅ 1 implemented
DS_CONDXCHG32_RTN_B64Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T08:55:43Z.
Review: CHANGES_REQUESTED
Measured on RDNA2 (gfx1035) with our HW oracle. Aligned, in-range rows match bit for bit on all 32 lanes: both old dwords are returned, each dword is written with its low 31 bits only when bit 31 is set (0, 0x7fffffff, 0x80000000 and 0xffffffff included), and the 16-bit offset combines correctly (0x120, 0xfff8). Build and ctest pass on the merge with main, and the new test fails without the change. One thing doesn't match:
SharedMemoryInstructions.cpp:235: the& 0xfff8mask wraps the address at 64 KiB. On hardware,vaddr + offset >= 0x10000is out of range: both returns are 0 and the LDS is left unchanged. That is the same asds_read_b64at 0x10000. With the mask, the address wraps around and the PR writes into the LDS. All 32 lanes differ for vaddr 0x10000, vaddr 0x10008, vaddr 8 + offset 0xfff8, and vaddr 0xfee0 + offset 0x120. The shared-atomic path on main already returns 0 and skips the write outside the LDS (EmitAtomicAccess). Dropping the mask and passing the offset the waydsAtomic64does (memory.offset= instruction offset, +4 for the second dword) should give the hardware result.ds_condxchg32_rtn_b64at an address that isn't 8-byte aligned (+1, +2, +4) faults the wave, asds_add_rtn_u32at +2 andds_add_rtn_u64/ds_wrxchg_rtn_b64at +4 do. The recompiler can't model that, so the test shouldn't pin a result for it.LdsCondxchg.cpp:107:in[5]pins both the 64 KiB wrap (+ 0x10000) and the alignment (tid & 7). Please replace them with an out-of-range row (returns 0, guard words unchanged) and keep only 8-byte aligned addresses.TechnicalDebt.md:250: the in-range semantics are now measured on gfx1035, so the line can say so and drop the "address mask follows RDNA3" part. Contended ordering and gfx1013 are still unmeasured.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T09:34:29Z.
Review: APPROVED
Checked the fix for the 64 KiB wrap:
vaddr + offset >= 0x10000now returns 0 and leaves LDS untouched, matching what we measured on gfx1035. Build and ctest pass on the merge with main, and the new test fails without the change (negative check). Merging once CI is green.