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

Merged
adriadam10 merged 3 commits from upstream-pr/495 into main 2026-10-05 05:14:41 +00:00
adriadam10 commented 2026-10-04 09:13:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-04T09:13:55Z.


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

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: #491 (and #390 through it)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4733204837 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/495). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-04T09:13:55Z. --- ### 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 <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: #491 (and #390 through it) - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-04 09:14:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-04T09:14:17Z.


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
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5978423351 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/495#issuecomment-5978423351). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-04T09:14:17Z. --- <!-- progress-report --> ### Progress report (00407df → 183a0f0) 📈 **GPU shader instructions**: 92.28% (+4.12%, +48 implemented instructions) <details> <summary>✅ 48 implemented</summary> | 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` | </details>
adriadam10 commented 2026-10-04 10:08:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-04T10:08:08Z.


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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5978861389 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/495#issuecomment-5978861389). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-04T10:08:08Z. --- 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 commented 2026-10-04 20:36:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-04T20:36:32Z.


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

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5984142765 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/495#issuecomment-5984142765). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-04T20:36:32Z. --- Rebased on current main: the only Windows failure was `guest_audio_in_no_device`, fixed by #532. No other changes.
oneandonlydean commented 2026-10-04 23:09:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T23:09:21Z.


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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5985450715 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/495#issuecomment-5985450715). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-04T23:09:21Z. --- 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.
adriadam10 commented 2026-10-05 03:06:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-05T03:06:45Z.


Rebased: this branch is now #491's new head (038ded63, which carries #390's patch as be866e42) 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5987393533 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/495#issuecomment-5987393533). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-05T03:06:45Z. --- Rebased: this branch is now #491's new head (038ded63, which carries #390's patch as be866e42) 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 commented 2026-10-05 05:04:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T05:04:00Z.


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

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5988441957 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/495#issuecomment-5988441957). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-05T05:04:00Z. --- Gated on PPSA21564 on top of #491: no visual or FPS change.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!495
No description provided.