shader: support returning 32-bit LDS compare-exchange (DS_CMPST_RTN_B32) #1578
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!1578
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1578/head"
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?
@Nawid3333 on GitHub · 2026-10-17 02:05 UTC · original
Nawid3333:shader/ds-cmpst-rtn-b32→main· +97 −3 · 10 files · 2 commits · merged 2026-10-17 02:37 UTCAssassin's Creed Valhalla (PPSA01490) stops on DS_CMPST_RTN_B32 (DS opcode 0x30), reported by Crispy81 in #281 on build
5dec523:Change: decode 0x30 and lower it to a new
SharedAtomicCmpSwap32, the 32-bit sibling of yourSharedAtomicCmpSwap64, through the existing 32-bit LDS atomic path (EmitAtomic32). As in the 64-bit form, DS compares DATA and stores DATA2, the opposite of BUFFER_ATOMIC_CMPSWAP, soEmitAtomicOperationswaps the two for this opcode. Sources for the order: the RDNA2 ISA guide ("the order of src and cmp are the opposite of BUFFER_ATOMIC_CMPSWAP"), LLVM (DSAtomicCmpXChgSwappedfor GFX6-GFX10 passes$cmp, $swap), and ACO (swaps the operands ofds_cmpst_rtn_b32only for GFX11+).Tests
DsCompareStoreReturn32uses the captured instruction words (ADDR and VDst are both v4). Cases:DsAtomicReturn64.TestDsCompareStore32Decoderchecks the captured words decode with DATA insrc1and DATA2 insrc2.DsCompareStoreReturn32passes natively and with the harness forced to 32-wide subgroups (a local switch), with no validation-layer messages, and natively with LDS as a storage buffer. With the operand swap removed it fails in all four configurations.42bb0da5.If you'd like this done differently, tell me and I'll change it.
Written with Claude Code (AI): it wrote the change and ran the tests on my PC (driver 26.8.1, Windows 11). I reviewed the diff and this description before opening the PR.
🤖 Generated with Claude Code
@coderabbitai[bot] on GitHub · 2026-10-17 02:10 UTC · original
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
ae80047e-2d34-4853-897c-dab1eb20bebb📥 Commits
Reviewing files that changed from the base of the PR and between
42bb0da520and8f40aeb700.📒 Files selected for processing: 10
src/graphics/shader/recompiler/backend/spirv/spirvEmitterInstructions.hsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterMemoryHelpers.cppsrc/graphics/shader/recompiler/frontend/decode/MemoryOps.cppsrc/graphics/shader/recompiler/frontend/decode/ShaderDecoder.cppsrc/graphics/shader/recompiler/frontend/decode/ShaderDecoder.hsrc/graphics/shader/recompiler/frontend/translate/Memory.cppsrc/graphics/shader/recompiler/ir/opcodes/ValueOpcodes.cppsrc/graphics/shader/recompiler/ir/opcodes/ValueOpcodes.inctests/ShaderRecompilerComputeTests.cpptests/shaderCfgTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
📝 Walkthrough
The decoder now recognizes
DS_CMPST_RTN_B32and classifies it as a three-source DS atomic. Translation maps it to a returning shared 32-bit compare-and-swap operation. SPIR-V emission usesOpAtomicCompareExchangeand adjusts operand order for this operation. Decoder and compute tests cover the new instruction and its behavior.Suggested reviewers:
nmzikPriority: ➖ Normal
Change: Bug fix
Merge Risk: ⚪ Minimal · up to
8f40aThis adds support for a previously unsupported shader instruction and is covered by decoder and compute tests. No actionable merge-blocking risk was found.
Pre-merge checks:
4 ·
1
Full details: Docstring Coverage
Explanation
Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 7 files. (3 skipped: 1 unsupported, 2 too large.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share
Comment
@coderabbitai helpto get the list of available commands.@Nawid3333 on GitHub · 2026-10-17 02:45 UTC · original
@Nmzik thanks for merging this, and for adding the GDS rejection. From now on I'll mark encodings the tests don't cover as unsupported myself.
On your fewer-instructions idea from #1534: #1554, #1565, #1566, #1567 and #1568 are open, each measured against the old form on both GPUs here (RX 9070 XT and Ryzen 7600X iGPU). #1570, #1573, #1576 and #1579 fix wrong results. Is this the direction you had in mind, and what would help you most next? Three things I could take, if any of them is useful to you:
PackHalf2x16compiles tov_cvt_pkrtzand rounds toward zero (see #1575), so a converted f16 result can end one step toward zero from what the PS5 gives. Exact round-to-nearest-even would need extra instructions per f16 result. Do you want that, or leave it as it is?DsAppendAllocatesAcrossWaves32andBufferStoreFormatXAddTidUsesLaneIndexfail on both GPUs here because the harness does not request a subgroup size (production does, inshaders.cpp). With 32-wide subgroups they pass. Would you take a harness change for that, or should it stay local?DownloadImageMemorystill exits when an image does not fit the 64 MiB reusable download buffer, as in Red Dead Redemption (#191). I'm preparing the same fallback you added for buffers in18a5f04d.Or tell me a game or issue you'd rather have me look at.
Written with Claude Code (AI); I read this comment before posting it.