perf(agc): copy moved draw words into the draw upload ring #11142
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/11142"
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 imellag on 2026-10-25T19:30:46Z.
What
ShaderResources::PrepareDrawBindingscopies a draw's moved words into a slice of the recorder's draw upload ring (Recorder::DrawUpload) instead of aBufferof their own.movedWordBufferscache made a newBuffer(VK_BUFFER_USAGE_STORAGE_BUFFER_BIT). The buffer pool usually hands back a slot whoseVkBufferhas another size, so the constructor destroys it and binds a new one (BindExactBuffer), and the buffer is destroyed again when the draw retires.movedWordBufferscache goes away: a ring slice is only written once, but caching it perShaderResourceswould keep its 1 MiB chunk alive for as long as the entry lives.agc_driver_graphicschecked that a moved-word descriptor starts at offset 0; it now checks the snapshot's offset and reads the words from there.Why: with #11130's mimalloc on, the draw committer paces Planet of Lana on macOS. In a 15 s Time Profiler capture it spends 626 samples in
Buffer::Bufferand 471 invkDestroyBuffercalled from it, out of 10,921, all from this call site.Tested
macOS 27, M4 Pro, Rosetta 2, MoltenVK 1.4.2.
maindoes not boot a title on macOS yet, so both sides aremain61fc572ceeplus the macOS changes needed to build and boot one: open macOS PRs (among them #10366, #10552, #7631, #7804, #10889, #10898, #11047, #11048 and #11049) and, for the AGC driver files and a few tests that no open PR covers yet, local patches taken from #8658's branch. #11130 is on both sides, withAPS5_MIMALLOC=1; the change side adds this PR. The base commit below is that whole tree, so its exact diff againstmainis public.Planet of Lana (PPSA19450), village gameplay from New Game with the same scripted pad input, 120 s per run, fps from 85 s, runs alternated in one session. These fps runs were on the same PRs uncommitted, plus a local experiment active on both sides (a
DrawTailpool, neutral when measured), which the clean commits below leave out:Every run with this PR is above every base run.
Driver.Packetgoes from 21 to 22 ms per frame to 19 ms.tools/trace_digest.pyofAPS5_TRACE_SECONDS=95:10 APS5_TRACE_EVENTS=1048576captures, same machine and scene, from two clean commits:7f2e300c68dc:main61fc572ceewith the macOS changes described above and #11130, committed as one tree;84cf9d0f359e: that commit plus this PR's diff.aps5-summary.jsonllinesbase:
this PR:
Driver.Packetgoes from 21.7 to 19.2 ms per frame andGraphics.Drawfrom 16.2 to 13.0; the draw committer's busy time goes from 9.4 to 5.3 ms, andVideoOut.Flipgrows from 7.2 to 9.2 ms, since the frame now waits on the GPU. A second capture of this PR's commit gave 342 presents and p50 29.0 ms; the base capture before it was not written because Rosetta was still translating the new libraries when the window opened.AGC tests, same machine and GPU, base and this PR, with
ANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation(Vulkan SDK 1.4.363),ctest -R 'agc_draw_snapshot|agc_driver_graphics$|agc_recorder|agc_pending_write_snapshot|agc_shader_table_snapshot|agc_driver_partially_resident_snapshot|agc_snapshot|agc_driver_prepared_graphics' -V:agc_driver_prepared_graphics_prebuild_*).was not found but was requested by env var VK_INSTANCE_LAYERS.VUID-VkDeviceCreateInfo-pProperties-04451(MoltenVK's portability subset at device creation) and no otherVUID-.agc_driver_graphicsfails at the offset check described above.Full
ctest -R '^agc_' -j6withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1and the validation layer, on the base and on this PR with44c6919b64: the same 44 of 992 fail on both sides and the same 80 skip; no test fails only with this PR. An earlier run withoutANYPS5_REQUIRE_VULKAN=1had skippedagc_draw_descriptors, which SeaSunPT found failing on Windows;44c6919b64fixes its expectation.Not built on Linux or Windows.
pr_overlap.pyreports #8963 and #9508, which edit lines next to the removedmovedWordBuffersmembers inShaderResources.hpp. #8913 changes how the buffer pool picks a slot and helps the old path (33.91 fps on the same bench); after this PR that call site no longer makes buffers, and #8913 still applies to the other callers.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)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T19:34:56Z.
Review: DISMISSED
The ring-slice change and descriptor offset handling look consistent in the PR-specific diff. I am requesting changes only for the required performance-report provenance.
Both pasted
aps5-summary.jsonlrecords identify commit61fc572ceef8and setdirty:true; only their trace filenames/window values differ.CONTRIBUTING.mdrequires two valid summary lines from different commits, one onmainand one with the change. As written, these records do not identify a clean base commit and a clean commit containing this PR, so the automatedperf numbers missinglabel is correct even though the traces compare two configurations.Please provide clean, different base/change commit summaries and the associated traces/digests, or ask maintainers to decide whether this dependency-stack/toggle comparison is an accepted exception and update the classification accordingly. I did not rerun the reported hardware Vulkan suite because this host has no matching macOS/MoltenVK GPU setup; the PR reports the required same-machine base/change validation runs.
Imported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-10-25T21:45:38Z.
Review: COMMENTED
Reviewed head
159007bd43by reading the diff and the existing review thread. I did not build or run this, so everything below is from the code, not from a test of mine.What it does. Moved-word snapshots no longer go through the per-
ShaderResources8-slotmovedWordBufferscache. They are copied into the recorder's draw upload ring withrecorder.DrawUpload(size), and the descriptor uses the slice's own buffer and offset. The tests are adjusted for a non-zero offset (item.offset,.subspan(offset)), which is the right place to touch them.What I checked.
DrawUploadaligns tomax(minStorageBufferOffsetAlignment, 16), so a storage-buffer descriptor at that offset is legal, and thestd::shared_ptr<Buffer>in the slice keeps the ring buffer alive for the draw. Removing the mutable cache fromShaderResourcesalso removes shared mutable state from aconstmethod, which is a good thing independent of speed.Concerns:
DrawUploadcall site is guarded byDrawUploadLimit()(4096 bytes by default). The moved-word path has no such limit, andDrawUploadallocates a freshmax(1 MiB, bytes)buffer whenever the ring is full or the request does not fit. The old code bounded this to 8 retained buffers. Ifoverride->sizecan be large, one draw per frame can now allocate a dedicated buffer where it used to reuse one. Please state the maximumoverride->sizeor add the same limit and fallback.allocation,sizeand words were equal, so a repeated draw with identical moved data created no new buffer. Now every such draw copies the words again. The perf numbers in the thread are what justifies that trade, and I can't verify them. They come from the author's captures and MarcZX10 has asked for clean base and change commits, which the author supplied. I take them as given.patch.adjustmentis still written as a single byte (static_cast<std::byte>). That is carried over unchanged, so I'm not blaming this PR.Leaving a comment: point 1 is a question I'd like answered; the rest is fine.
AI-assisted: yes. Written with AI assistance and reviewed by me.