Skip to content

feat(shader): accept the glc, slc and dlc cache bits on flat, global and scratch - #495

Merged
oneandonlydean merged 3 commits into
boykopovar:mainfrom
adriadam10:feat/flat-cache-bits
Oct 5, 2026
Merged

oneandonlydean merged 3 commits into
boykopovar:mainfrom
adriadam10:feat/flat-cache-bits

Conversation

@adriadam10

Copy link
Copy Markdown
Collaborator

What

FLAT, GLOBAL and SCRATCH loads, stores and atomics now accept the glc, slc and dlc cache bits. Before this, the decoder threw unsupported FLAT modifiers or segment for any of them, except glc on atomics. Found by the modifier sweep over decoded opcodes: every flat_*/global_*/scratch_* with any of the three bits throws on main. Compilers emit glc dlc on coherent loads and slc on streaming stores, so these show up whenever a shader uses global memory.

This follows what MUBUF/MTBUF already do (bufferLoad/bufferStore):

  • Loads and stores: coherent = glc || dlc. The BDA read and write paths already turn that into Volatile accesses (BdaAccessMask).
  • slc is a cache-streaming hint and changes no result. MUBUF ignores it the same way.
  • Atomics: glc still selects the pre-op return. slc/dlc are hints there too, and the atomics are device-coherent anyway.
  • Scratch is per-lane private memory, so the bits can't change a value there. Scratch loads and stores accept them, with no other change.
  • Still throwing: lds, segment 3, scratch atomics.

Encodings checked with llvm-mc -mcpu=gfx1013 -show-encoding: dlc is word0 bit 12, glc bit 16, slc bit 17, and every combination assembles on loads, stores, atomics and scratch.

Depends on #491 (integer flat/global atomics), which depends on #390 (DotDebian, stores through FLAT/GLOBAL addresses). Both commits are included here so the stores and atomics can be tested with the bits; only the last commit is this PR. Both PRs rewrite the same decoder condition.

Behaviour measured on HW

The test kernel ran on a Radeon 660M (gfx1035, same VMEM encoding as gfx1013) over 32 lanes of edge values plus random rows. It does global_load_dword with glc, slc, dlc and all three; global_load_dwordx2 glc dlc; global_load_ubyte slc and global_load_sbyte glc dlc (sign extension); global_store_dword glc slc dlc; global_store_byte slc; returning global_atomic_add glc slc dlc; non-returning global_atomic_sub slc dlc; and flat_load/store/atomic_xor through a 64-bit VGPR address with glc/slc/dlc mixes. All 32 rows (16 results each) match a model where the bits change nothing. The returning atomic gives the pre-op value, and the non-returning one leaves its VGPRs alone.

Tested

Arch Linux, RADV (Radeon 660M) plus lavapipe (local Mesa and the CI version, Ubuntu Mesa 25.2.8). New execution test FlatCacheBits runs the same kernel as the HW measurement on a guest block. 64 threads run as wave32 and wave64. It checks the 16 results per lane against the HW rows, the final 16 bytes per lane, and that nothing else in the 64 KiB block changes.

Negative checks: the test fails if the bits still throw, if slc drops the atomic return, or if a dlc store is skipped.
Full Release build plus ctest: 177/178. The one failure, agc_driver_pixel_helper_lanes, also fails on main on local RADV since #305. FlatCacheBits takes ~105 s on CI's lavapipe (18 BDA instructions per dispatch, two dispatches; BDA lookups are slow there, as with FlatStore), and under a second on RADV.

Checklist

@github-actions

github-actions Bot commented Oct 4, 2026 •

Copy link
Copy Markdown

Progress report (00407df → 183a0f0)

📈 GPU shader instructions: 92.28% (+4.12%, +48 implemented instructions)

✅ 48 implemented
Encoding Name
FLAT FLAT_ATOMIC_ADD
FLAT FLAT_ATOMIC_ADD_X2
FLAT FLAT_ATOMIC_AND
FLAT FLAT_ATOMIC_AND_X2
FLAT FLAT_ATOMIC_CMPSWAP
FLAT FLAT_ATOMIC_CMPSWAP_X2
FLAT FLAT_ATOMIC_DEC
FLAT FLAT_ATOMIC_INC
FLAT FLAT_ATOMIC_OR
FLAT FLAT_ATOMIC_OR_X2
FLAT FLAT_ATOMIC_SMAX
FLAT FLAT_ATOMIC_SMAX_X2
FLAT FLAT_ATOMIC_SMIN
FLAT FLAT_ATOMIC_SMIN_X2
FLAT FLAT_ATOMIC_SUB
FLAT FLAT_ATOMIC_SUB_X2
FLAT FLAT_ATOMIC_SWAP
FLAT FLAT_ATOMIC_SWAP_X2
FLAT FLAT_ATOMIC_UMAX
FLAT FLAT_ATOMIC_UMAX_X2
FLAT FLAT_ATOMIC_UMIN
FLAT FLAT_ATOMIC_UMIN_X2
FLAT FLAT_ATOMIC_XOR
FLAT FLAT_ATOMIC_XOR_X2
GLOBAL GLOBAL_ATOMIC_ADD
GLOBAL GLOBAL_ATOMIC_ADD_X2
GLOBAL GLOBAL_ATOMIC_AND
GLOBAL GLOBAL_ATOMIC_AND_X2
GLOBAL GLOBAL_ATOMIC_CMPSWAP
GLOBAL GLOBAL_ATOMIC_CMPSWAP_X2
GLOBAL GLOBAL_ATOMIC_DEC
GLOBAL GLOBAL_ATOMIC_INC
GLOBAL GLOBAL_ATOMIC_OR
GLOBAL GLOBAL_ATOMIC_OR_X2
GLOBAL GLOBAL_ATOMIC_SMAX
GLOBAL GLOBAL_ATOMIC_SMAX_X2
GLOBAL GLOBAL_ATOMIC_SMIN
GLOBAL GLOBAL_ATOMIC_SMIN_X2
GLOBAL GLOBAL_ATOMIC_SUB
GLOBAL GLOBAL_ATOMIC_SUB_X2
GLOBAL GLOBAL_ATOMIC_SWAP
GLOBAL GLOBAL_ATOMIC_SWAP_X2
GLOBAL GLOBAL_ATOMIC_UMAX
GLOBAL GLOBAL_ATOMIC_UMAX_X2
GLOBAL GLOBAL_ATOMIC_UMIN
GLOBAL GLOBAL_ATOMIC_UMIN_X2
GLOBAL GLOBAL_ATOMIC_XOR
GLOBAL GLOBAL_ATOMIC_XOR_X2

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 4, 2026
@adriadam10

Copy link
Copy Markdown
Collaborator Author

Rebased on current main on top of the rebased #491 (no conflicts in this PR's own commit). FlatCacheBits, GlobalAtomics and D16Memory pass on RADV and lavapipe.

@adriadam10

Copy link
Copy Markdown
Collaborator Author

Rebased on current main: the only Windows failure was guest_audio_in_no_device, fixed by #532. No other changes.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Thanks. I reviewed only the last commit (e6bc02a); the #390 and #491 commits are patch-identical to those PRs.

The change matches what MUBUF does: loads and stores get coherent = glc || dlc, which the BDA paths already turn into Volatile, and slc is ignored. Atomics keep glc as the return bit, and lds, segment 3 and scratch atomics still throw. llvm-mc agrees on the bit positions (dlc 12, glc 16, slc 17), and the test kernel disassembles to the forms the description lists.

agc_driver_flat_cache_bits passes on my machine at this head. On the commit below yours (#390 + #491 only) it fails with "unsupported FLAT modifiers or segment". None of my PPSA21564 shader dumps uses FLAT/GLOBAL with these bits, so this doesn't change my runs.

The only issue is the stack. Each branch carries its own rebased copy of the base commits, so merging the heads in order conflicts: this PR on top of #390's head conflicts in ResourceTracker.cpp, SpirvBda.hpp and SpirvBdaRead.cpp, and on top of #491's head in RdnaMemoryOpDecoder.cpp, the condition both rewrite. #569 also conflicts with it in the same BDA files. Once #390 and #491 are in, could you rebase so only this commit is left? It's good to merge from my side after that.

DotDebian and others added 3 commits October 5, 2026 05:05
flat_store_* and global_store_* decoded and translated, but a store whose
segment is not scratch was refused when the SPIR-V was emitted ("writable
FLAT/GLOBAL addresses require GPU ownership tracking").

Such a store now goes through the BDA page table like a store through a
GPU-selected V#: the write lookup needs Write permission, which only a
writable registered range imported in place has, and the written page is
noted for the host to mark GPU-written. Byte and short stores, and dword
stores to an address that is not dword aligned, are stored byte by byte.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
…and scratch

Loads and stores with glc or dlc are coherent, as MUBUF already does; slc
is a cache hint and changes no result. Atomics keep glc as the return bit.
lds, segment 3 and scratch atomics still throw.

Co-Authored-By: Claude <noreply@anthropic.com>
@adriadam10
adriadam10 force-pushed the feat/flat-cache-bits branch from e6bc02a to 183a0f0 Compare October 5, 2026 03:06
@adriadam10

Copy link
Copy Markdown
Collaborator Author

Rebased: this branch is now #491's new head (038ded6, which carries #390's patch as be866e4) plus only this commit, unchanged. #390 → #491 → this one merges cleanly at every step (checked with git merge-tree), and agc_driver_flat_cache_bits passes on RADV and lavapipe. Once #390 and #491 are in, only this commit is left.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Gated on PPSA21564 on top of #491: no visual or FPS change.

@oneandonlydean
oneandonlydean merged commit 2afc403 into boykopovar:main Oct 5, 2026
3 checks passed
@adriadam10
adriadam10 deleted the feat/flat-cache-bits branch October 5, 2026 06:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants