Skip to content

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

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
shahulmubeen-a:perf/shader-byte-buffer-stores
Oct 13, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
shahulmubeen-a:perf/shader-byte-buffer-stores

Conversation

@shahulmubeen-a

Copy link
Copy Markdown
Contributor

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 c92ae6e 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 ceb342b.

  • 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

@Celegans12

Copy link
Copy Markdown
Contributor

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-Ghost-of-Yotei@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

Copy link
Copy Markdown
Contributor Author

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.)

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

@adriadam10 adriadam10 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
shahulmubeen-a force-pushed the perf/shader-byte-buffer-stores branch from 2e2392c to 08c1e4d Compare October 13, 2026 14:12
@shahulmubeen-a

shahulmubeen-a commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor Author

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.)

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 Yotei'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.

Compute 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, and in every other stage, the
compare-exchange path remains: the draw-time validator accepts only
u32 and u64 aliased views. Loads, dword stores and stores through
GPU-selected descriptors (BDA) are unchanged.

Ghost of Yotei (PPSA26344 02.002.000), Windows 11, RTX 4070 Ti SUPER,
logo phase: that dispatch 426 -> 10.7 ms of GPU time, 1.9 -> 11 fps.

agc_formatted_buffer_byte_stores compiles a formatted 8_8_8_8 store
as compute with and without StorageBuffer8BitAccess and as a vertex
shader with it, and checks the byte view, the byte stores, the
compare-exchange loops and the fallbacks. agc_driver_formatted_store_unaligned
executes 8- and 16-bit formatted stores at misaligned offsets,
including stores that cross a dword, and checks every byte of the
output including the untouched neighbours.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@adriadam10
adriadam10 force-pushed the perf/shader-byte-buffer-stores branch from 08c1e4d to 066a8fb Compare October 13, 2026 14:42

@adriadam10 adriadam10 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

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

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 13, 2026
@adriadam10
adriadam10 merged commit 67e86d9 into boykopovar:main Oct 13, 2026
8 checks passed
TheBlenDed pushed a commit to TheBlenDed/AnyPS5 that referenced this pull request Oct 25, 2026
TheBlenDed pushed a commit to TheBlenDed/AnyPS5 that referenced this pull request Oct 25, 2026
The SPIR-V emitter declares extra views of the guest buffers binding
when a shader needs them: buffers_coherent for GLC or DLC accesses,
buffers_u64 for 64-bit atomics and buffers_u8 for 8- and 16-bit
formatted stores (boykopovar#4250). Each view is another StorageBuffer variable
on the same set and binding, and all of them are decorated Aliased.
Vulkan allows several variables on one binding when their types fit
the descriptor.

ShaderValidation, which checks the stages of every draw (not compute
dispatches), accepted one StorageBuffer variable per binding with u32
elements only, and SPV_KHR_8bit_storage only in shaders with a fault
buffer. Ghost of Yotei's pixel shader 0x80003a6b00 with a byte store
was refused at use with "duplicate SPIR-V resource binding", which
aborted the game.

A second variable on a binding is now accepted when the binding is the
guest buffers array and every variable on it is Aliased; an aliased
view may hold u8 or u64 elements. SPV_KHR_8bit_storage is accepted like
its StorageBuffer8BitAccess capability, which the shader device
profile requires. Other duplicates are still refused.

agc_driver_graphics recompiles pixel shaders with a byte store, a GLC
store, both, and a 64-bit atomic, validates them, and checks that the
same modules without Aliased are refused.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* build shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants