perf(shader): store 8- and 16-bit buffer components as bytes in graphics stages #27371
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/27371"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by DerKarussellbremser on 2026-11-26T00:10:00Z.
What
A formatted store of an 8- or 16-bit component into a bound buffer goes through the byte view of the buffers (
buffers_u8, #4250) only in compute shaders. Every other stage still patches the dword around the component with a compare-exchange loop (writeBufferinSpirvRuntimeBuffer.cpp), because the draw-time validator refused the byte view when #4250 was written. A pixel shader that stores bytes from every covered pixel then spends its time in those loops: all its invocations contend for the same dwords.Assassin's Creed Black Flag Resynced (PPSA28183, 01.006.038) does this in its first menu, Image Calibration. One draw there has a pixel shader with 2,168 code words that stores 8- or 16-bit components with formatted buffer stores; its module holds 294 compare-exchange loops, and each execution of the draw takes about 1.7 s of GPU time on an RTX 2060 at 1920x1080. The menu presents once every 2.7 s.
With this change:
byteBuffersdeclares the byte view in every stage. It uses the descriptor set that the stage's other buffer views use (RuntimeAbi::FragmentDescriptorSetfor a pixel shader with a fragment set), where it had set 0 fixed.ShaderValidationaccepts the view: u8 elements in an aliased view of the guest buffers, next to u32 and u64, andSPV_KHR_8bit_storagein a shader without a fault buffer. TheStorageBuffer8BitAccesscapability was already accepted for every shader, and the shader device profile requires it.Loads, dword stores and stores through GPU-selected descriptors (BDA) are unchanged. Without the capability the compare-exchange path remains.
This also fixes a wrong result in graphics stages. The compare-exchange path shifts the component mask inside one dword, so a 16-bit component whose two bytes straddle a dword loses its high byte. The byte view stores both bytes. The new execution test shows it (below). The fallback path itself still has that defect; it is a separate change.
Tested
Windows 11 Home 10.0.26200, i7-10750H, 16 GB, NVIDIA GeForce RTX 2060 6 GB, driver 610.91, WinLibs GCC 15.2.0 r7 UCRT, Release, on
main63b2e14408.aliasedBufferViewTests(agc_driver_graphics): a pixel shader with a formatted 8_8_8_8 store declaresbuffersandbuffers_u8, passesValidateShaders, and is refused withduplicate SPIR-V resource bindingonce theAliaseddecorations are replaced. Red on the base: withSpirvRuntimeBuffer.cppandShaderValidation.cppas onmainit fails withthe pixel shader declared the guest buffers as buffers, not as the expected 2 aliased variables.agc_driver_pixel_formatted_store_unaligned: a 64x32 draw whose pixel shader runs the eight stores ofagc_driver_formatted_store_unaligned(8- and 16-bit components at misaligned offsets, some of them across a dword) into a 64-byte lane per pixel, as wave64 and wave32, and checks all 131,072 output bytes including the untouched neighbours. Red on the base:wave64 pixel (0, 0) byte 4 is 170, expected 239, the high byte of the 16-bit store at offset 3. Green here.agc_driver_formatted_store,agc_driver_formatted_store_unaligned,agc_driver_runtime_formatted_store,agc_formatted_buffer_byte_storesandagc_driver_graphicspass.VK_LAYER_KHRONOS_validation, its loading confirmed withVK_LOADER_DEBUG=layer):agc_driver_pixel_formatted_store_unaligned,agc_driver_formatted_store_unaligned,agc_driver_formatted_storeandagc_driver_runtime_formatted_storerun without a validation message.tools/check_conventions.py --base origin/mainpasses.tools/pr_overlap.py --branch perf/graphics-byte-stores: 111 open pull requests share files. 66 were compared and do not overlap. 45 conflict withmainand could not be compared; I searched their diffs forbyteBuffers,buffers_u8, the 8-bit extension and capability, the aliased-view checks andaliasedBufferViewTests. None declares the byte view outside compute or changes which buffer views the validator accepts. #9356, #9387, #10193, #13928, #13929 and #15548 edit the same one-line extension check for other extensions and will need a textual merge there.writeBufferpath, but no test here executes a store in them).Black Flag, Image Calibration menu. Same machine, same session, warm caches (each build ran the scene before its capture), fresh profile and the same scripted input,
APS5_TRACE_SECONDS=420:30with no profile switch and the log not redirected. The window lies in the menu for both builds; the title reaches the menu 110 to 190 s after its first present.main63b2e1440872c61e439dDriver.Packet.memory_waitper frameVulkan.Dispatchper frameIn separate runs with
APS5_PROFILE_GPU=1andAPS5_PROFILE_GPU_DRAWS=1(on6b59b8f5e7, the base this was developed on), the draw of that pixel shader took 6,849 to 7,044 ms of GPU time for 4 executions per 10 s before, and 8 ms for 13 executions after. A frame dump of the menu from each build matches except for the animated parts (97.4 % identical pixels at 480x270).What limits the menu now is a second draw at about 72 ms of GPU time per execution, unchanged by this PR, and queue 0x20, whose worker is busy 99.7 % of the window.
Summary lines
The two traces (
aps5-trace-63b2e14408f9-1056.json.gz,aps5-trace-72c61e439d6e-36496.json.gz) follow in a comment.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
https://claude.ai/code/session_011TXsSW8zeAgKgHLCFsYwM3
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-26T00:24:18Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this; the points below are optional.
What I ran
Reviewed head
72c61e439d6e22244a2dcd4a4a73a7ce202e1dadusing the prepared diff and pinned repository reader. No build or runtime commands were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
core/libs/prx/libSceAgcDriver/tests/Graphics.cppwas excluded from the review bundle because it is too large; I read the relevant added test lines through the repository reader. I did not run checks or verify behavior on other platforms, GPUs, or shader stages. Other changes listed in the manifest were read:core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cpp,core/libs/prx/libSceAgcDriver/tests/execution/PixelFormattedStoreUnaligned.cpp, andcore/shader/recompiler/SpirvBackend/src/SpirvRuntimeBuffer.cpp.To get this to a good state
Nothing is required.