perf(shader): store 8- and 16-bit buffer components as bytes #4250

Merged
shahulmubeen-a merged 1 commit from upstream-pr/4250 into main 2026-10-13 15:47:55 +00:00
shahulmubeen-a commented 2026-10-12 02:22:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by shahulmubeen-a on 2026-10-12T02:22:22Z.


What

A formatted store of an 8- or 16-bit component into a bound buffer patched the dword around it with a compare-exchange loop (writeBuffer in SpirvRuntimeBuffer.cpp). Ghost of Yōtei's light-culling compute pass (program 0x800038be00, 240x135 groups per frame) stores millions of such components per dispatch and took 426 ms of GPU time per dispatch on an RTX 4070 Ti SUPER, which held the logo phase at 1.9 fps.

Such stores now go through a byte view of the bound buffers (buffers_u8, an aliased declaration of the buffers binding, defined on the first narrow store): one OpStore per byte under StorageBuffer8BitAccess, which the shader device profile already requires. Without the capability the compare-exchange path remains. Loads, dword stores and stores through GPU-selected descriptors (BDA) are unchanged. On a main with buffers_coherent (#4240 era) the byte view takes part in the same Aliased decoration set.

Discussed in #675: @Celegans12 took commit c92ae6e5 of this branch into their Yōtei build, it passed their focused checks there, and they asked for it as a PR.

Tested

Windows 11 Pro, AMD Ryzen 9 7950X, NVIDIA RTX 4070 Ti SUPER (Vulkan 1.4, subgroup 32), MinGW-w64 GCC 15.2.0, Release, rebased on main ceb342b94.

  • agc_formatted_buffer_byte_stores (new): compiles a formatted 8_8_8_8 store with and without StorageBuffer8BitAccess and checks the byte view, one byte store per component, no compare-exchange loop, and the fallback without the capability. It fails on main (the module keeps the compare-exchange loop).
  • agc_driver_buffer_format and agc_driver_formatted_store: 8- and 16-bit formatted stores executed on the device, untouched neighbouring bytes checked.
  • tools/check_conventions.py --base origin/main: passes.
  • Ghost of Yōtei (PPSA26344 02.002.000), logo phase, same machine: the 0x800038be00 dispatch 426 -> 10.7 ms of GPU time, 1.9 -> 11 fps (APS5_PROFILE_GPU=1); the title then runs through its loading, first-boot menus and into the intro cutscene with further local work.

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: none
  • AI-assisted: yes (written with Claude Code; every line reviewed by the author)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4824175636 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4250). Originally posted by [shahulmubeen-a](https://github.com/shahulmubeen-a) on 2026-10-12T02:22:22Z. --- ### What A formatted store of an 8- or 16-bit component into a bound buffer patched the dword around it with a compare-exchange loop (`writeBuffer` in `SpirvRuntimeBuffer.cpp`). Ghost of Yōtei's light-culling compute pass (program `0x800038be00`, 240x135 groups per frame) stores millions of such components per dispatch and took 426 ms of GPU time per dispatch on an RTX 4070 Ti SUPER, which held the logo phase at 1.9 fps. Such stores now go through a byte view of the bound buffers (`buffers_u8`, an aliased declaration of the buffers binding, defined on the first narrow store): one `OpStore` per byte under `StorageBuffer8BitAccess`, which the shader device profile already requires. Without the capability the compare-exchange path remains. Loads, dword stores and stores through GPU-selected descriptors (BDA) are unchanged. On a `main` with `buffers_coherent` (#4240 era) the byte view takes part in the same `Aliased` decoration set. Discussed in #675: @Celegans12 took commit c92ae6e5 of this branch into their Yōtei build, it passed their focused checks there, and they asked for it as a PR. ### Tested Windows 11 Pro, AMD Ryzen 9 7950X, NVIDIA RTX 4070 Ti SUPER (Vulkan 1.4, subgroup 32), MinGW-w64 GCC 15.2.0, Release, rebased on `main` ceb342b94. - `agc_formatted_buffer_byte_stores` (new): compiles a formatted 8_8_8_8 store with and without `StorageBuffer8BitAccess` and checks the byte view, one byte store per component, no compare-exchange loop, and the fallback without the capability. It fails on `main` (the module keeps the compare-exchange loop). - `agc_driver_buffer_format` and `agc_driver_formatted_store`: 8- and 16-bit formatted stores executed on the device, untouched neighbouring bytes checked. - `tools/check_conventions.py --base origin/main`: passes. - Ghost of Yōtei (PPSA26344 02.002.000), logo phase, same machine: the `0x800038be00` dispatch 426 -> 10.7 ms of GPU time, 1.9 -> 11 fps (`APS5_PROFILE_GPU=1`); the title then runs through its loading, first-boot menus and into the intro cutscene with further local work. ### Checklist - [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 - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in TechnicalDebt - [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: none - [x] AI-assisted: yes (written with Claude Code; every line reviewed by the author) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Celegans12 commented 2026-10-12 08:26:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-12T08:26:16Z.


I tried #4250 in Yotei and the new byte view runs into the draw-time validator. A pixel shader with a byte store (0x80003a6b00) declares buffers_u8 next to buffers, and ShaderValidation refuses it with "duplicate SPIR-V resource binding". It also only accepts SPV_KHR_8bit_storage in shaders with a fault buffer. Compute isn't validated, which is probably why the tests here didn't catch it.

main has the same problem with the views it already emits (buffers_coherent for GLC, buffers_u64 for 64-bit atomics), so I've opened #4381 for those. The u8 part only makes sense with your view, so I kept it as one commit on top of your head and #4381's commit: Celegans12/AnyPS5@f61a578af2 (branch topics/agc-aliased-buffer-views-4250). It accepts the extension like its StorageBuffer8BitAccess capability, lets an aliased guest buffer view hold u8 elements, and adds two pixel-shader cases to agc_driver_graphics: a byte store, and a GLC byte store next to a plain load. Those fail with #4250 alone and with #4381 alone, and pass with both.

Would you like to pick it into #4250, or should I send it as a follow-up once one of the two lands?

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6120551289 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4250#issuecomment-6120551289). Originally posted by [Celegans12](https://github.com/Celegans12) on 2026-10-12T08:26:16Z. --- I tried #4250 in Yotei and the new byte view runs into the draw-time validator. A pixel shader with a byte store (0x80003a6b00) declares `buffers_u8` next to `buffers`, and `ShaderValidation` refuses it with "duplicate SPIR-V resource binding". It also only accepts `SPV_KHR_8bit_storage` in shaders with a fault buffer. Compute isn't validated, which is probably why the tests here didn't catch it. `main` has the same problem with the views it already emits (`buffers_coherent` for GLC, `buffers_u64` for 64-bit atomics), so I've opened #4381 for those. The u8 part only makes sense with your view, so I kept it as one commit on top of your head and #4381's commit: Celegans12/AnyPS5@f61a578af2 (branch `topics/agc-aliased-buffer-views-4250`). It accepts the extension like its `StorageBuffer8BitAccess` capability, lets an aliased guest buffer view hold u8 elements, and adds two pixel-shader cases to `agc_driver_graphics`: a byte store, and a GLC byte store next to a plain load. Those fail with #4250 alone and with #4381 alone, and pass with both. Would you like to pick it into #4250, or should I send it as a follow-up once one of the two lands?
shahulmubeen-a commented 2026-10-12 14:10:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by shahulmubeen-a on 2026-10-12T14:10:13Z.


Thanks for catching that, and for #4381.

Let's go with option B: keep #4250 as is and have your u8 extension land as a follow-up once #4250 and #4381 are both in. Picking your commit into #4250 now would make it depend on #4381 to merge, and #4250 would stop being single-topic (byte/short stores, no validator changes) — easier to review and merge as is. Nothing about #4250 needs it either: it only touches compute dispatches, which ShaderValidation doesn't check, so the duplicate-binding refusal you found never fires on the path #4250 covers.

Go ahead and open yours whenever suits you; happy to rebase #4250 on top if #4381 lands first and you'd rather sequence it that way.

(AI-assisted: written with Claude.)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6125982412 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4250#issuecomment-6125982412). Originally posted by [shahulmubeen-a](https://github.com/shahulmubeen-a) on 2026-10-12T14:10:13Z. --- Thanks for catching that, and for #4381. Let's go with option B: keep #4250 as is and have your u8 extension land as a follow-up once #4250 and #4381 are both in. Picking your commit into #4250 now would make it depend on #4381 to merge, and #4250 would stop being single-topic (byte/short stores, no validator changes) — easier to review and merge as is. Nothing about #4250 needs it either: it only touches compute dispatches, which `ShaderValidation` doesn't check, so the duplicate-binding refusal you found never fires on the path #4250 covers. Go ahead and open yours whenever suits you; happy to rebase #4250 on top if #4381 lands first and you'd rather sequence it that way. (AI-assisted: written with Claude.)
adriadam10 commented 2026-10-13 13:34:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T13:34:57Z.

Review: CHANGES_REQUESTED


Thanks for the profile numbers. Two things block this, plus a conflict:

  • ShaderValidation.cpp (main, after #4381 merged): an aliased view is accepted only if its elements are u32, or u64 in an aliased guest buffer view (the "descriptor block member must be a runtime array of u32, or of u64..." check). buffers_u8 is still refused, so any vertex/tessellation/pixel shader with an 8/16-bit formatted store is rejected at draw time, where it used to work through the compare-exchange path. This is the case @Celegans12 hit with 0x80003a6b00; "compute isn't validated" doesn't make it safe for the other stages. Either teach the validator the u8 aliased view (and SPV_KHR_8bit_storage for those stages) in this PR, or only emit the byte view for compute and keep the compare-exchange path elsewhere, with a test for each stage.
  • FormattedBufferByteStores.cpp only counts SPIR-V instructions (byte stores, no compare-exchange), so it pins the IR shape, not values. Please add an execution test in the style of agc_driver_formatted_store that stores 8- and 16-bit components with a misaligned offset and checks the neighbouring bytes, including a store that crosses a dword.
  • Conflicts with main in core/libs/prx/libSceAgcDriver/CMakeLists.txt (test registration next to a new block); please rebase.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5504347358 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4250#pullrequestreview-5504347358). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-13T13:34:57Z. **Review:** CHANGES_REQUESTED --- Thanks for the profile numbers. Two things block this, plus a conflict: - `ShaderValidation.cpp` (main, after #4381 merged): an aliased view is accepted only if its elements are u32, or u64 in an aliased guest buffer view (the "descriptor block member must be a runtime array of u32, or of u64..." check). `buffers_u8` is still refused, so any vertex/tessellation/pixel shader with an 8/16-bit formatted store is rejected at draw time, where it used to work through the compare-exchange path. This is the case @Celegans12 hit with `0x80003a6b00`; "compute isn't validated" doesn't make it safe for the other stages. Either teach the validator the u8 aliased view (and `SPV_KHR_8bit_storage` for those stages) in this PR, or only emit the byte view for compute and keep the compare-exchange path elsewhere, with a test for each stage. - `FormattedBufferByteStores.cpp` only counts SPIR-V instructions (byte stores, no compare-exchange), so it pins the IR shape, not values. Please add an execution test in the style of `agc_driver_formatted_store` that stores 8- and 16-bit components with a misaligned offset and checks the neighbouring bytes, including a store that crosses a dword. - Conflicts with `main` in `core/libs/prx/libSceAgcDriver/CMakeLists.txt` (test registration next to a new block); please rebase.
shahulmubeen-a commented 2026-10-13 14:13:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by shahulmubeen-a on 2026-10-13T14:13:42Z.


Thank you for the comment @adriadam10

  • Rebased onto main (the conflict was the test registration in CMakeLists.txt). Took the second option from the review: the byte view is now emitted only for compute, and every other stage keeps the compare-exchange path, so the validator never sees buffers_u8.
  • agc_formatted_buffer_byte_stores now also compiles a vertex shader and checks it keeps the dword patch (no buffers_u8, no 8-bit capability)
  • New execution test agc_driver_formatted_store_unaligned stores 8- and 16-bit components at misaligned offsets, including stores that cross a dword, and checks every output byte including the untouched neighbours.
  • Teaching the validator the u8 view for the other stages stays with @Celegans12 's follow-up.

(AI-assisted: written with Claude.)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6147549162 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4250#issuecomment-6147549162). Originally posted by [shahulmubeen-a](https://github.com/shahulmubeen-a) on 2026-10-13T14:13:42Z. --- Thank you for the comment @adriadam10 - Rebased onto `main` (the conflict was the test registration in `CMakeLists.txt`). Took the second option from the review: the byte view is now emitted only for compute, and every other stage keeps the compare-exchange path, so the validator never sees `buffers_u8`. - `agc_formatted_buffer_byte_stores` now also compiles a vertex shader and checks it keeps the dword patch (no `buffers_u8`, no 8-bit capability) - New execution test `agc_driver_formatted_store_unaligned` stores 8- and 16-bit components at misaligned offsets, including stores that cross a dword, and checks every output byte including the untouched neighbours. - Teaching the validator the u8 view for the other stages stays with @Celegans12 's follow-up. (AI-assisted: written with Claude.)
adriadam10 commented 2026-10-13 14:42:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T14:42:46Z.

Review: APPROVED


Rebased onto current main (only conflict: the test registration list in libSceAgcDriver/CMakeLists.txt), no logic changes. agc_formatted_buffer_byte_stores and agc_driver_formatted_store_unaligned pass on the rebased tree; the only failure in the scoped ctest run is agc_driver_tessellation (segfault inside RADV's pipeline-library link, a graphics path this PR doesn't touch). Merging once the full Build is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5505323751 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4250#pullrequestreview-5505323751). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-13T14:42:46Z. **Review:** APPROVED --- Rebased onto current `main` (only conflict: the test registration list in `libSceAgcDriver/CMakeLists.txt`), no logic changes. `agc_formatted_buffer_byte_stores` and `agc_driver_formatted_store_unaligned` pass on the rebased tree; the only failure in the scoped ctest run is `agc_driver_tessellation` (segfault inside RADV's pipeline-library link, a graphics path this PR doesn't touch). Merging once the full Build is green.
github-actions[bot] commented 2026-10-13 14:45:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T14:45:33Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#4085 core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterHelpers.hpp L35
core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvTypes.cpp L115
core/shader/recompiler/SpirvBackend/src/SpirvRuntimeBuffer.cpp L199-200
#4964 core/libs/prx/libSceAgcDriver/CMakeLists.txt L1215
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6148209588 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4250#issuecomment-6148209588). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T14:45:33Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #4085 | `core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterHelpers.hpp` [L35](https://github.com/boykopovar/AnyPS5/blob/c7beafd21a70503b6050766ad60263bc064ee5c2/core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterHelpers.hpp#L35)<br>`core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvTypes.cpp` [L115](https://github.com/boykopovar/AnyPS5/blob/c7beafd21a70503b6050766ad60263bc064ee5c2/core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvTypes.cpp#L115)<br>`core/shader/recompiler/SpirvBackend/src/SpirvRuntimeBuffer.cpp` [L199-200](https://github.com/boykopovar/AnyPS5/blob/c7beafd21a70503b6050766ad60263bc064ee5c2/core/shader/recompiler/SpirvBackend/src/SpirvRuntimeBuffer.cpp#L199-L200) | | | | #4964 | `core/libs/prx/libSceAgcDriver/CMakeLists.txt` [L1215](https://github.com/boykopovar/AnyPS5/blob/c7beafd21a70503b6050766ad60263bc064ee5c2/core/libs/prx/libSceAgcDriver/CMakeLists.txt#L1215) | | |
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!4250
No description provided.