perf(agc): plan a draw's vertex copies in per-thread scratch #18287
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/18287"
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 meh7an on 2026-11-11T03:22:01Z.
What
prepareDrawInputsplanned each draw's vertex fetches in ninestd::vectorlocals, allocated and freed on every draw:fetches,fetchValid,fetchOf,zeroed,isSolo,plannedFetches,plannedOf,rangeHandlesandrangeOffsets. They now live in one per-threadVertexPlanScratchthat keeps its capacity from draw to draw.ExclusiveScratch<T, Tag>(new, inThreadScratch.hpp) lends a thread'sThreadScratchobject to one scope.zeroedholdsshared_ptr<Buffer>s, so an exception cannot leave a zero buffer alive past its draw.assignandresizereplace the sized constructors (fetchOf,zeroed,isSolo,plannedOf), andreservestays where it was. The draw fills and reads them in the same order, so the planned copies, handles and offsets are unchanged.soloHandles,SoloZeroPaddedFetchIndices,PlanVertexCopies(its result lists,orderand thestable_sortbuffer) andDrawInputs' own vectors.VertexPlanScratchState ThreadVertexPlanScratch()(Draw.hpp) reports the calling thread's scratch (busy flag, resting elements, capacity) for the tests. The thread slot is per module, so a test cannot read the driver's scratch itself.PlanVertexCopies,ThreadScratchand the new names. The five PRs too large forgh pr diff(#17613, #12315, #9508, #7642, #5021) were read file by file through the files API: none changes a line with those symbols.rangeFromandVertexCopyStartsright afterplan, next torangeHandles. It is a textual conflict only (tools/pr_overlap.py:Draw.cppL1970-1972); whichever lands second rebases, and #9875's new vector could join the scratch afterwards.fetchValid.push_backline, a one-line textual neighbour.Kept::vertexBuffersand addsInlineList.hpp. It shares no line with this change and does not touch the nine lists.Draw.hppandDraw.cppnext toCommitTrims; the accessor here sits elsewhere, and the two branches merge without conflict.tools/pr_overlap.pyfailed closed. It reports the line conflicts with #9875 and #18174 above, and could not compare 32 PRs that conflict with main and shareDraw.cpporDraw.hpp; the symbol scan covers those.Tested
Windows 11 (10.0.26300), NVIDIA GeForce RTX 2080 Ti (driver 617.14), Sonic Origins (PPSA05324) menu on the S3K page, 3840x2160, default environment.
9e3265259eand this change on top of it (e3222a2db0), both clean builds from one build tree. The commit was then amended tocc90f5506e, which only moves the test accessor inDraw.hppandDraw.cppaway fromCommitTrims(a textual conflict with #18174);git range-diffshows the rest unchanged. The five tests that touch the accessor or the lease (agc_exclusive_scratch,agc_driver_zero_stride_vertex_fetch,agc_vertex_input,agc_vertex_input_validation,agc_graphics_profile_draw) were rerun on the amended build under validation: all pass, noVUID-line.core/libs/prx/libSceAgcDriver, and the branch merges cleanly (git merge-tree).New and extended tests:
agc_exclusive_scratch(new, header-only): the lease reuses its storage and starts empty; a nested lease (also three deep) gets its own object and leaves the outer lists alone; unwinding frees the object, empties it and releases what it held; another thread has its own;VertexPlanScratchempties all nine lists and releases a zero buffer.agc_driver_zero_stride_vertex_fetch(extended): its 20 draws alternate zero-buffer and real fetches on one thread, with the outputs checked per vertex. At the end the thread's vertex plan scratch must be free, empty and in use (capacity != 0).Broken copies of the change, each run against these tests, are all caught (8 of 8):
clear()in the destructor, nobusy = false, nesting that shares the object;VertexPlanScratch::clear()withoutzeroed, withoutisSolo, withoutrangeOffsets(unit test);zeroedmutant, andprepareDrawInputsusing a plain localVertexPlanScratchinstead of the lease (agc_driver_zero_stride_vertex_fetch, library rebuilt).Vulkan validation protocol (
ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ctest -V, same machine and GPU):agc_vertex_input,agc_vertex_input_validation,agc_driver_zero_stride_vertex_fetch,agc_driver_vertex_fetch,agc_embedded_vertex_fetch(+_aliasing),agc_vertex_layer_export,agc_driver_vertex_clip_cull_draw(+_no_key),agc_driver_layered_volume_vertex(+_no_gpl),agc_driver_vertex_target_range_copiedand_imported,agc_driver_draw_offset_indices,agc_driver_indexed_copy,agc_driver_list_restart,agc_driver_quad_list_index_overflow,agc_driver_rect_list_corner,agc_driver_pass_break_reasons,agc_graphics_profile_draw,agc_driver_draw_cache_relocation*(6), and the newagc_exclusive_scratch.9e3265259e(the new test does not exist there).was not found but was requested by env var VK_INSTANCE_LAYERSor aVUID-line.tools/check_conventions.py --base upstream/mainpasses. Full ctest was not run.Sampler (
APS5_SAMPLE_COMMITTERandAPS5_SAMPLE_WORKER, one 60 s window per arm, 3841 and 3843 samples on the draw committer; a sample is about 0.018 ms per frame). Samples whose stack passes through the function:9e3265259ee3222a2db0prepareDrawInputsinclusiveAllocate+operator deleteunderprepareDrawInputsandPlanVertexCopiesAllocate+operator deletecommitDrawinclusive164ac9b078held 83 and 95 there, so the 45 is outside the spread of main. The whole committer's allocation share falls by 15 samples only: other functions (planDraw, for one) moved up by about as much between the two windows, which is the spread between boots (2-8 points on the committer).commitDraw) and, with the GPU, limits the frame. The worker spends 27.2% (main) and 25.6% (PR) of its samples inDrawPipeline::Enqueue, waiting for the committer, so itsworker_busy_pctoverstates its load.Two traced runs per arm (
APS5_TRACE_SECONDS=200:15), in main, PR, PR, main order, both commit IDs in the summaries:9e3265259ee3222a2db0Graphics.Drawper frame (retained events)Graphics.Draw. The sampler boots read 15.53 (main) and 15.54 (PR).Summary lines (
tools/trace_digest.pyJSON summary, one per capture, in the order of the table):seconds 200:15 from present 4415: 206 presents, frame p50 72.6 / p90 77.5 / p99 92.7 / max 102.3 ms, GPU busy 39.0 ms per present
NVIDIA GeForce RTX 2080 Ti, NVIDIA 617.14, Windows 10.0.26300, 3840x2160, commit
9e3265259e, dropped: yesseconds 200:15 from present 4449: 208 presents, frame p50 71.5 / p90 76.3 / p99 93.0 / max 113.9 ms, GPU busy 38.4 ms per present
NVIDIA GeForce RTX 2080 Ti, NVIDIA 617.14, Windows 10.0.26300, 3840x2160, commit e3222a2db0bf, dropped: yes
seconds 200:15 from present 4404: 205 presents, frame p50 72.3 / p90 77.2 / p99 80.3 / max 182.2 ms, GPU busy 39.7 ms per present
NVIDIA GeForce RTX 2080 Ti, NVIDIA 617.14, Windows 10.0.26300, 3840x2160, commit e3222a2db0bf, dropped: yes
seconds 200:15 from present 4451: 188 presents, frame p50 72.4 / p90 104.2 / p99 245.8 / max 297.6 ms, GPU busy 36.2 ms per present
NVIDIA GeForce RTX 2080 Ti, NVIDIA 617.14, Windows 10.0.26300, 3840x2160, commit
9e3265259e, dropped: yesTraces (two runs per zip, each with its
aps5-summary.jsonl): m34-main-traces.zip (main9e3265259e), m34-change-traces.zip (this PR as measured,e3222a2db0).trace_digest.py, main run 1
seconds 200:15 from present 4415: 206 presents, frame p50 72.6 / p90 77.5 / p99 92.7 / max 102.3 ms, GPU busy 39.0 ms per present
NVIDIA GeForce RTX 2080 Ti, NVIDIA 617.14, Windows 10.0.26300, 3840x2160, commit
9e3265259e, dropped: yesIncomplete trace: recorded data was lost. Slice-based timings, waits and batch inventories cover retained events only; missing slices are not idle time. Summary statistics are reported separately.
Slowest frames (largest slices inside each, inclusive)
Persistent spikes (frame time above the fastest frame that separates it from a longer frame; one entry per stall, not per frame)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): batch 38.9, Graphics.Draw 29.9, Graphics.Draw.draw_and_resource_release 21.8, Driver.Packet 17.5, Driver.Packet.draw 13.6, Driver.Draw 13.2, VideoOut.Flip 10.8, Driver.Present 10.7, VideoOut.Flip.present 10.6, Recorder.WaitSerial 10.6
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
trace_digest.py, PR run 1
seconds 200:15 from present 4449: 208 presents, frame p50 71.5 / p90 76.3 / p99 93.0 / max 113.9 ms, GPU busy 38.4 ms per present
NVIDIA GeForce RTX 2080 Ti, NVIDIA 617.14, Windows 10.0.26300, 3840x2160, commit e3222a2db0bf, dropped: yes
Incomplete trace: recorded data was lost. Slice-based timings, waits and batch inventories cover retained events only; missing slices are not idle time. Summary statistics are reported separately.
Slowest frames (largest slices inside each, inclusive)
Persistent spikes (frame time above the fastest frame that separates it from a longer frame; one entry per stall, not per frame)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): batch 38.4, Graphics.Draw 29.3, Graphics.Draw.draw_and_resource_release 21.8, Driver.Packet 17.4, Driver.Packet.draw 13.5, Driver.Draw 13.1, VideoOut.Flip 10.8, VideoOut.Flip.present 10.6, Driver.Present 10.6, Recorder.WaitSerial 10.5
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
trace_digest.py, PR run 2
seconds 200:15 from present 4404: 205 presents, frame p50 72.3 / p90 77.2 / p99 80.3 / max 182.2 ms, GPU busy 39.7 ms per present
NVIDIA GeForce RTX 2080 Ti, NVIDIA 617.14, Windows 10.0.26300, 3840x2160, commit e3222a2db0bf, dropped: yes
Incomplete trace: recorded data was lost. Slice-based timings, waits and batch inventories cover retained events only; missing slices are not idle time. Summary statistics are reported separately.
Slowest frames (largest slices inside each, inclusive)
Persistent spikes (frame time above the fastest frame that separates it from a longer frame; one entry per stall, not per frame)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): batch 39.7, Graphics.Draw 30.1, Graphics.Draw.draw_and_resource_release 22.2, Driver.Packet 17.9, Driver.Packet.draw 14.0, Driver.Draw 13.6, VideoOut.Flip 11.6, Driver.Present 11.4, VideoOut.Flip.present 11.4, Recorder.WaitSerial 11.3
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
trace_digest.py, main run 2
seconds 200:15 from present 4451: 188 presents, frame p50 72.4 / p90 104.2 / p99 245.8 / max 297.6 ms, GPU busy 36.2 ms per present
NVIDIA GeForce RTX 2080 Ti, NVIDIA 617.14, Windows 10.0.26300, 3840x2160, commit
9e3265259e, dropped: yesIncomplete trace: recorded data was lost. Slice-based timings, waits and batch inventories cover retained events only; missing slices are not idle time. Summary statistics are reported separately.
Slowest frames (largest slices inside each, inclusive)
Persistent spikes (frame time above the fastest frame that separates it from a longer frame; one entry per stall, not per frame)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): batch 36.2, Graphics.Draw 34.8, Graphics.Draw.draw_and_resource_release 24.2, Driver.Packet 21.2, Driver.Packet.draw 16.9, Driver.Draw 16.4, VideoOut.Flip 9.2, Driver.Present 9.0, VideoOut.Flip.present 9.0, Recorder.WaitSerial 8.9
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
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-11-12T19:15:13Z.
Review: COMMENTED
Reviewed the vertex-plan scratch change — no blocking findings
Nothing blocks this; the points below are optional.
What I ran
cc90f5506e9108e3bc8257284dba68274da685a0, basemain. The base SHA is not in the run folder, and no merged-preview check was run.diff.patchfor the 7 changed files. Read the changed hunks of each file, plus the head code around the changed calls, with the repository reader. No build was run in this pass.Results
VertexPlanScratch::clearinputsctestFindings
Blocking
None.
Non-blocking
core/libs/prx/libSceAgcDriver/tests/ExclusiveScratch.cpp:119: the zero-buffer check builds itsshared_ptr<Buffer>by aliasingowner.get(), anint*, cast toBuffer*. The pointer is never dereferenced, so the assertion holds, but the test fakes aBufferfrom an unrelated type. Smallest fix: keep the entry as a realshared_ptr<Buffer>owned by the test, or leave the alias and name it in the test as a stand-in.Sources
prepareDrawInputsNot verified
ctest, and the Vulkan validation runs were not run. The author reports 27 of 27 passing on the change and a rerun of five tests on the amended commit. I did not reproduce either.tools/check_conventions.py, the overlap scan against #9875 and #18174, and the conflict claims are author-reported and were not checked.VertexFetchaggregate initialisation in the test ({1, 2, 3, 4, 5}) was not checked; its definition was not read.HostThreadSlotandThreadOwnedwas not read. The per-thread claim rests on the code inThreadScratch, not on those helpers.ThreadScratch.hpp,Draw.cppandZeroStrideVertexFetch.cppwere read as their changed hunks plus the excerpts above. The full text infiles/was not opened.std::threaduse in the new test andconfigure_windows_unwindwere not checked.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-14T10:09:45Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the author-reported tests and measurements support the stated scratch reuse behavior.
What I ran
Reviewed head
afcefa92d562fb9437cfed283cd02a6299c1cee7using the prepared diff andrepo_read.py. No commands or tests were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
I did not independently run builds, tests, validation, convention checks, or performance captures. I read all changed files:
ThreadScratch.hpp,Draw.hpp,VertexPlanScratch.hpp,Draw.cpp,ExclusiveScratch.cpp,agc_exclusive_scratch_tests.cmake, andZeroStrideVertexFetch.cpp. No changed files were excluded from the prepared bundle.To get this to a good state
Nothing is required.