feat(shader): implement S_SCRATCH_LOAD_DWORD, S_SCRATCH_LOAD_DWORDX2 and S_SCRATCH_LOAD_DWORDX4 #766
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/766"
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 Kikoarl on 2026-10-05T22:16:54Z.
What
Implement RDNA 2 SMEM scratch load instructions:
S_SCRATCH_LOAD_DWORD,S_SCRATCH_LOAD_DWORDX2andS_SCRATCH_LOAD_DWORDX4.Tested
Linux x86_64, unit test
scalar_scratch_load_testsverifying decoding and IR translation for 1, 2, and 4 dwords.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 oneandonlydean on 2026-10-05T22:56:53Z.
Thanks for this. The decoding looks right to me: SMEM opcodes 5 to 7 are the scalar scratch loads in the GFX10.1 encoding. The translation has a semantic problem, though.
sScratchLoademitsLoadAddressU32on theScratchresource, which the SPIR-V backend lowers to the invocation's ownFunctionvariable. So each lane reads its own private copy at that byte offset, and the destination SGPR can end up with a different value in every lane. On the console a scalar load returns one dword for the whole wave, read from the wave's scratch memory. As far as I know, vector scratch accesses are swizzled per lane there (consecutive dwords of one lane are a lane stride apart), while a scalar access uses the plain address. So a dword written by a vectorscratch_store_dwordin lane L is not the dword thats_scratch_load_dwordreads at the same offset, and a lane-private read can't model either layout.Two smaller points:
readU32(inst.source0)); the high dword is ignored without a check.scalar_scratch_loadchecks the decode and counts theLoadAddressU32s, but nothing runs the result, so the test would pass with any address or layout.Which title needs these instructions? If it only reads back values that its own
s_scratch_storewrote, a wave-uniform scratch array would do; otherwise the swizzled layout has to be modelled. Until then, I think the loads should keep throwing, or the limitation should be listed indocs/dev/TechnicalDebt.md.Imported from boykopovar/AnyPS5. Originally posted by Kikoarl on 2026-10-05T23:06:45Z.
Thanks for the detailed review and architectural explanation.
These instructions were implemented to complete SMEM coverage from the RDNA 2 ISA specification rather than from a specific title trace, so there is no immediate title demanding them yet.
Given that, I agree that having
s_scratch_loadthrow an explicit exception during translation (while keeping the GFX10.1 decoding and opcode definitions in place) is the cleanest and safest approach. That way, we complete the decoder without risking silent data corruption across lanes until the wave-uniform/swizzled scratch layout is modelled.I will update the PR to have the translation throw, adjust the test accordingly, and check the
SBASEregister. Thanks again.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-05T23:37:34Z.
Progress report (
a4bc492→9ac108b)📈 GPU shader instructions: 96.4% (+0.26%, +3 implemented instructions)
✅ 3 implemented
S_SCRATCH_LOAD_DWORDS_SCRATCH_LOAD_DWORDX2S_SCRATCH_LOAD_DWORDX4