perf(shader): emit one wide store for multi-dword and 8-byte typed buffer stores #22071
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/22071"
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 nicolasabosch on 2026-11-17T03:55:09Z.
What
A compute shader's
buffer_store_dwordx2/x4was emitted as separateu32stores, and a typed store of an 8- or 16-byte format (for example 16_16_16_16) or of a 4-byte format with several components as one store per component through the byte view.When the V# base is dword aligned, the address is aligned to the store size, the V# is not swizzled and every word is inside the range, the words are now written with one
u64,uvec4or dword store through an aliasedbuffers_u64/buffers_u32x4view of the same binding. Every other lane takes the existing per-component path, chosen at run time, so out-of-bounds, misaligned and swizzled stores behave as before; the stored bytes are the same, no instruction semantics change.x3stores keep per-component stores, and loads are unchanged.SpirvTarget::wideBufferStoresis set whenminStorageBufferOffsetAlignmentis a multiple of 16; theu64view also needsInt64. The flag is part of the shader cache key.APS5_NO_WIDE_BUFFER_STORES=1keeps the per-component stores;agc_shader_replay --wide-buffer-storesreplays with the flag set.docs/dev/debt/changesfragment forshader.A coherent
dwordx2store takes the 64-bit atomic path only when the module requires the atomic U64 view (bufferU64View), so the view an ordinary wide pair store creates on a target withInt64but noInt64Atomicsdoes not turn a later coherent pair store into a 64-bit atomic store.RequestSerializerwriteswideBufferStoresin request format 63 and reads it from 63 on, so a captured request replays with the wide stores it was compiled with; older captures read it as off, andagc_shader_replay --wide-buffer-storesstays for them. The format number is a placeholder for the maintainers to confirm against other open PRs that bump it.agc_driver_buffer_wide_stores(45 cases, plus adwordx2store followed by a coherent one compiled for a target withoutInt64Atomics, which must emit no atomic store;dwordx2,dwordx3,dwordx4and typed stores at aligned and unaligned offsets, strides and V# bases, with lanes partly or wholly past the records, anddwordx2anddwordx4stores over a swizzled V#, which must take the per-component path) compares the stored bytes with the expected ones, with the flag on and, asagc_driver_buffer_wide_stores_opt_out, off.Tested
Windows 11 Pro, MinGW-w64 GCC (WinLibs), Release, no title. Focused tests passed (37/37 at
4cd14a81ed, withrequest_serializer_tests; 34/34 atd6d4d0c481after mergingmaina72186d3cf;agc_shader_replay*included). With the coherent-pair gate reverted to checking only that the U64 view exists, the new case fails (a coherent dwordx2 store emitted an atomic store through the wide view on a target without Int64Atomics):agc_driver_buffer_wide_stores,agc_driver_buffer_wide_stores_opt_out,agc_driver_runtime_buffer_spans*,agc_driver_formatted_store*,agc_driver_runtime_formatted_store*,agc_driver_format_d16_store,agc_driver_tbuffer_format_d16,agc_driver_d16_memory,agc_driver_buffer_atomics*,agc_driver_buffer_atomic_unaligned,agc_formatted_buffer_byte_stores,agc_formatted_buffer_onceandagc_shader_disk_cache, which checks that the flag changes the cache key.Validation layer: the same tests on
main(be4613dd73, the base before this branch was rebased) and on this branch withVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,VK_LOADER_DEBUG=layer,ANYPS5_NO_SHADER_CACHE=1andANYPS5_REQUIRE_VULKAN=1throughctest -V(Khronos validation layer 1.4.363.1): every log showsInsert instance layer "VK_LAYER_KHRONOS_validation", none reportswas not found but was requested by env var VK_INSTANCE_LAYERS, and neither run logs aVUID-error.agc_driver_buffer_wide_storesand its opt-out, with the swizzled-V# cases, were run again the same way atd6d4d0c481: noVUID-error. With the swizzle check removed from the wide-store condition, thedwordx2, swizzled V#case fails (the wide module's memory differs from the narrow module's).Performance: one 60 s capture each with
APS5_TRACE_SECONDS=660:60, same machine and session (NVIDIA GeForce RTX 4070 Laptop GPU, driver 616.92, Intel Core i9-14900HX, Windows 11 Pro 26300), warm shader caches, in the same scripted scene of EA SPORTS UFC 6 (PPSA23566, 01.004.000): the first practice fight of the tutorial ("LAND 5 PUNCHES"), reached through the menus withAPS5_PAD_SCRIPT. Both builds aremain2a8a0d1fc3plus the pad-script commit of #22064, which only injects the scripted input; that build is 241bfd31f250, the commit in themainsummary line. The change build adds this PR's first commit on top (66ef00667064). The later review follow-up only drops duplicated address code from the per-component fallback and was not captured again.mainseconds 660:60 from present 11012: 55 presents, frame p50 1004.2 / p90 1086.4 / p99 5716.0 / max 5716.0 ms, GPU busy 288.6 ms per presentseconds 660:60 from present 11801: 65 presents, frame p50 937.4 / p90 967.0 / p99 980.2 / max 980.2 ms, GPU busy 164.1 ms per presentGPU busy time per present falls by 43 % and presents rise by 18 %; the frame stays bound by queue 0 on the CPU, so frame time falls less than GPU time. Both traces report
trace_droppedafter the queue-worker event buffer fills; the summary lines are complete. Traces andtrace_digest.pyoutputs:main: trace, digest; this change: trace, digest.aps5-summary.jsonllinesmain:
this change:
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
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-17T04:29:49Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this; the points below are optional.
What I ran
cb396cfa72bdce0b83137eac68413ba0c30a2a52, basemain.Reader commands
Results
Findings
Blocking
None. The widening conditions match the description: unswizzled V#, aligned address, every word in range, and other lanes keep the per-component path. Stores with
x3, coherent, GPU-descriptor or graphics-stage access are left unchanged. The new test and its opt-out fragment are picked up by the existing globs.Non-blocking
core/shader/recompiler/SpirvBackend/src/SpirvRuntimeBuffer.cpp:414: the swizzled-V# check has no case inBufferWideStores.cpp. The debt fragment lists a swizzled-V# case as still open.core/shader/recompiler/SpirvBackend/src/SpirvRuntimeBuffer.cpp:1211: whenwideStorereturns nothing, the dword path has already computedaccesses, andwriteComponentscomputes the same addresses again. The emitted module carries the duplicate address code.core/libs/prx/libSceAgcDriver/tests/execution/BufferWideStores.cpp:211: the test usesstd::nulloptandstd::sizewithout<optional>or<iterator>. Whether it compiles without them is not verified.Not verified
be4613dd73(validation),2a8a0d1fc33(performance) and241bfd31f250(summary line). Which base produced the numbers is unclear.minStorageBufferOffsetAlignment. Not verified.core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppis too large for the review folder. I read its changed line (4749) through the reader and its diff hunk only.BufferWideStores.cpp(Require,OpenVulkanTestDevice, theRecompileRequestlayout, the includes) were not read.files/were not opened, so no whole file was read.Checked by reading:
core/libs/prx/libSceAgcDriver/CMakeLists.txt:695and:819globtests/execution/*.cppandtests/cmake/*.cmake, so the new names resolve. The test has 43 cases, as the description says. ThemarkBufferAliasedguard matches the conditions that create the variables (core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvEmitterHelpers.cpp:524-525).To get this to a good state
Nothing is required.
The event stays
COMMENT: approval needs the hosted checks for this head to have passed, and I did not read them. The three non-blocking points above are optional.Sources
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-17T04:36:25Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this; the points below are optional.
What I ran
No build and no tests in this review. I read the change from the run folder (description, commits, manifest, diff) and checked the pinned head
923bbe2cf247through the reader:Files:
files.jsonlists 17 reviewed files and no excluded ones. All 17 were read as their changed hunks indiff.patch. None was read in full.Execution/src/VulkanDevice.cppis too large for the review folder, so only lines 4738–4760 were read through the reader.Results
.cmakefileFindings
Blocking
None. I checked the store path against the head: the alignment check (
address & 7,address & 15), the element index withbyteOffset, the array length used for the bounds check (dword view, rounds down), and themarkBufferAliasedrefactor, which keeps the oldAliaseddecoration rules. I found no concrete defect in the code I read.Non-blocking
None verified against a changed line in
diff.patch.Sources
Pinned at head
923bbe2cf247:Not verified
agc_driver_buffer_wide_stores_testsand the testagc_driver_buffer_wide_storesare not in the diff. The name appears in the tree only in the new opt-out.cmakefile, and I did not find how the other test.cmakefiles are registered. Not verified.formatted()function,ResourceForDescriptor, andTypeU32Vector.66ef00667064(change) and241bfd31f250(main). The reviewed head is923bbe2cf247, and the description names main as2a8a0d1fc33in one place andbe4613dd73in another. I could not confirm through the reader that these commits match the head. The numbers are the author's.minStorageBufferOffsetAlignmentof 4, swizzled V# and loads are not covered by the tests, as the debt fragment states. Not verified.COMMENT, notAPPROVE. The files were read only as changed hunks and reader ranges, and no build or test was run, so a formal approval is not justified.To get this to a good state
Nothing is required.
Optional:
923bbe2cf247or say why the measured commit is equivalent.923bbe2cf247and show thatagc_driver_buffer_wide_storesis registered in the test list.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-17T05:00:03Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this; the points below are optional.
What I ran
d6d4d0c481be159edea1a2cca2175c26182fa85f, basemain. No merge preview.diff.patchfrom the review folder, then the house-rule sections, then head context through the reader:The review is COMMENT, not APPROVE, because the tests, traces and build are the author's and were not rerun here.
Results
Findings
Blocking
None verified.
Non-blocking
None verified.
Checked and ruled out:
inBoundsguard, so every byte it writes is inside the records (SpirvRuntimeBuffer.cpp L538–L554).access.lengthis anOpArrayLength, so a partial trailing dword fails thefitstest and takes the per-component path (SpirvRuntimeBuffer.cpp L238–L265).markBufferAliasedchange replaces the old variable-existence check with requirement flags. The flags are what create those variables, so the behaviour is the same (SpirvEmitterHelpers.cpp L524–L525).Sources
d6d4d0c481be159edea1a2cca2175c26182fa85f.Not verified
agc_driver_buffer_wide_storesrun and its opt-out, and the validation-layer runs. The author reports them; I did not run them.agc_driver_buffer_wide_storesname. How it is discovered was not confirmed.OpenVulkanTestDevice,Dispatch,WaitIdleand the SPIR-V parsing inStoresThroughwere not read, so the test code has not been checked against them.minStorageBufferOffsetAlignmentof 4 was not checked.core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppis excluded from the review folder as too large, and was read only at its changed hunk (head lines 4738–4756). No file was read in full.To get this to a good state
Nothing is required.
Optional:
minStorageBufferOffsetAlignmentvalue in the debt fragment.agc_driver_buffer_wide_storestest is registered, so the 45-case run is easy to find.Imported from boykopovar/AnyPS5. Originally posted by kurexw on 2026-11-17T09:35:19Z.
Review: COMMENTED
Tested on macOS 27.2 on an Apple M4. This is an x86-64 build under Rosetta with Apple clang 21.0.0, on MoltenVK 1.4.2 from the LunarG Vulkan SDK 1.4.363.1.
The M4 takes the new path.
agc_driver_buffer_wide_storesreports45 cases, device wide stores on, so MoltenVK meets both conditions:minStorageBufferOffsetAlignmentis a multiple of 16, andInt64is available.Method. The base was
mainata72186d3cfplus #22056 and #22074, which fix the macOS build of two other targets; both have since merged. I built the base and this PR merged onto it (a clean merge) in two separate build directories. I ran them alternately, base then PR, three times each, withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validationandVK_LOADER_DEBUG=layer:agc_driver_buffer_wide_stores(wide stores on)agc_driver_buffer_wide_stores_opt_out(wide stores off)buffer_format,formatted_store*,runtime_formatted_store*,runtime_buffer_spans*,tbuffer_format_d16,agc_shader_disk_cache*andagc_shader_replay_requests/_toolwas not found but was requestedVUID-linesAll runs gave the same results.
Not tested: the speed claim. I have no title or capture here, so I didn't measure GPU time with and without the change on MoltenVK.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-18T14:23:34Z.
Review: COMMENTED
Reviewed — no blocking findings
The reviewed code shows no concrete blocking defect, but I did not read every reviewed file, so a formal approval is not justified.
What I ran
Reviewed the prepared diff and targeted source at head
3b088b98df788bda80a7d2436ce7db7cde0f493busingrepo_read.py. I ran no tests; the test results in the PR description are author-reported.Results
Findings
Blocking
None identified in the code inspected.
Non-blocking
None.
Sources
Reviewed the prepared diff and targeted code for
SpirvRuntimeBuffer.cpp,VulkanDevice.cpp, andRequestSerializer.cppat the stated head.Not verified
I read the review description, commit list, manifest, and diff, plus targeted sections of the three source files above. I did not read the full text of all changed files. In particular,
VulkanDevice.cppandShaderMemory.cppwere excluded from the review folder for size; I read only the targetedVulkanDevice.cppsection through the reader. Other changed files were not read in full. No tests, build, or runtime checks were performed.To get this to a good state
Nothing is required. Optional: complete a full read of the remaining changed files and run the focused checks on this exact head before issuing a formal decision.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-18T15:24:31Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the reviewed code and supplied test and performance reports support merging.
What I ran
Reviewed head
cc43fbd0605bc2bd3ae04fb7ac4ed88b77835acbusingrepo_read.pyto inspect the prepared diff and source context. No commands or tests were run in this review.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The full text of
VulkanDevice.cppandShaderMemory.cppwas excluded from the review folder and was not read through the reader. Their changed hunks were inspected indiff.patch, but surrounding source context was not verified. No tests, validation layers, or performance captures were run by this review. Reported testing and performance captures indescription.mdare author-provided.repo_read.pyexposed the prepared review documents and changed source, not a way to write the requested draft files; this response contains the draft instead.Files read:
description.md,commits.md,manifest.json,diff.patch; source ranges inRequestSerializer.cpp,SpirvRuntimeBuffer.cpp, andSpirvTypes.cpp. Excluded changed files:VulkanDevice.cpp,ShaderMemory.cpp(too large for the review folder; not read through the reader).To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T22:13:33Z.
Review: COMMENTED
The trial merge onto
a1b75b0947conflicts inShaderMemory.cpp,ShaderReplay.cpp,RequestSerializer.cpp,SpirvRuntimeBuffer.cpp, andRequestSerializerTests.cpp. Please reconcile the replay payload and shader key with the store lowerer in the same revision. The wide path needs the existing typed fallback for misalignment, swizzle, and accesses outside the proven span. Re-run the wide-store execution fixture with the serializer and shader-memory controls once the head merges.AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.