Repository navigation
perf(shader): store 8- and 16-bit buffer components as bytes - #4250
Conversation
|
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
Would you like to pick it into #4250, or should I send it as a follow-up once one of the two lands? |
|
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 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
left a comment
There was a problem hiding this comment.
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_u8is 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 with0x80003a6b00; "compute isn't validated" doesn't make it safe for the other stages. Either teach the validator the u8 aliased view (andSPV_KHR_8bit_storagefor 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.cpponly 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 ofagc_driver_formatted_storethat stores 8- and 16-bit components with a misaligned offset and checks the neighbouring bytes, including a store that crosses a dword.- Conflicts with
mainincore/libs/prx/libSceAgcDriver/CMakeLists.txt(test registration next to a new block); please rebase.
2e2392c to
08c1e4d
Compare
|
Thank you for the comment @adriadam10
(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>
08c1e4d to
066a8fb
Compare
adriadam10
left a comment
There was a problem hiding this comment.
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.
|
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.
|
… storage buffer
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.
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 (
writeBufferinSpirvRuntimeBuffer.cpp). Ghost of Yōtei's light-culling compute pass (program0x800038be00, 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): oneOpStoreper byte underStorageBuffer8BitAccess, 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 amainwithbuffers_coherent(#4240 era) the byte view takes part in the sameAliaseddecoration 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
mainceb342b.agc_formatted_buffer_byte_stores(new): compiles a formatted 8_8_8_8 store with and withoutStorageBuffer8BitAccessand checks the byte view, one byte store per component, no compare-exchange loop, and the fallback without the capability. It fails onmain(the module keeps the compare-exchange loop).agc_driver_buffer_formatandagc_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.0x800038be00dispatch 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
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)🤖 Generated with Claude Code