perf(agc): retry the draw pipeline and draw finisher mutexes before blocking #18226
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/18226"
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 Nesyth on 2026-11-10T22:20:33Z.
What
The queue-0 worker hands every pipelined draw to the draw committer, and to the draw finisher when it runs, through two queues guarded by a
std::mutex. The worker also takes these mutexes for most packets to look up held writes, labels, reads and draw keys. Each holder keeps a mutex for only a short time, but with MinGW a contendedstd::mutexsleeps in the kernel at once, and the unlock that wakes it costs another kernel transition. A handoff that collides then costs more in the sleep and the wake than in the critical section, on the worker and the committer alike.try_lockfor up to 20 us, then blocks as before. This covers enqueues, the committer's and the finisher's take and retire, drains, settles and the held-write, label, read and key lookups.APS5_HANDOFF_SPIN_US=0, the threads block at once.APS5_NO_SPIN_HANDOFFmakes the threads block at once again. It is a runtime switch, soAPS5_ABcan toggle it within one run. The committer's mutex is used in both modes and the finisher's only withAPS5_DRAW_PIPELINE, so the switch can be measured with and without the finisher.agc_driver_draw_handoff_spintest runs in the default and draw pipeline modes, each with the retry on, off and toggled every 50 us. It checks that commits and finisher jobs keep their order under lookup contention, that queued labels read back their own values, and that settles, drains and an enqueue waiting for room wake when the finisher empties.Tested
Windows 11 Pro 26300, Radeon RX 7900 XTX (AMD Software 26.10.1), Ryzen 7 7800X3D, Release, MinGW-w64 GCC 15.2.
An open-world, draw-heavy title on main
56c80b0917, the same save and scene in every boot. Every boot runs main's pipelined configuration:APS5_PIPELINED_DRAWS=32APS5_PIPELINE_DISPATCH=1APS5_DRAW_PIPELINE=1.In-run A/B on the PR build (
APS5_AB=30:APS5_NO_SPIN_HANDOFF, phases of 30 s from 190 s after the first present, 10 pairs, read withtools/ab_split.py):APS5_NO_SPIN_HANDOFFset (as before)Separate boots with
APS5_TRACE_SECONDS=300:30:56c80b091754e4d6d3fc)Traces, both captured on the same machine in one session: main 56c80b0917, this PR.
No boot had a fatal error or a lost device. Both traces are incomplete: threads filled their buffers inside the 30 s window, as the digests say. The summary lines are complete.
Tests: every target builds;
agc_driver_draw_handoff_spinin its default, draw pipeline and plan verify variants andagc_runtime_switchespass (5 of 5);tools/check_conventions.pypasses.trace_digest: main
56c80b0917seconds 300:30 from present 4482: 254 presents, frame p50 117.1 / p90 123.8 / p99 144.7 / max 162.8 ms, GPU busy 33.0 ms per present
AMD Radeon RX 7900 XTX, AMD proprietary driver 26.10.1 (LLPC), Windows 10.0.26300, 3840x2160, commit
56c80b0917, 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 32.9, Graphics.Draw 25.8, Driver.DrawFinish 24.2, Graphics.Draw.draw_and_resource_release 20.4, Driver.Packet 14.5, Driver.Packet.draw 11.0, Driver.Draw 10.8, Driver.DrawFinish.draw_enqueued 10.7, VideoOut.Flip 7.8, Driver.Present 7.7
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
trace_digest: this PR
seconds 300:30 from present 4499: 272 presents, frame p50 110.2 / p90 116.0 / p99 119.5 / max 130.1 ms, GPU busy 31.7 ms per present
AMD Radeon RX 7900 XTX, AMD proprietary driver 26.10.1 (LLPC), Windows 10.0.26300, 3840x2160, commit
54e4d6d3fc, 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 31.6, Graphics.Draw 24.2, Driver.DrawFinish 22.1, Graphics.Draw.draw_and_resource_release 19.0, Driver.Packet 13.6, Driver.Packet.draw 10.0, Driver.Draw 9.9, Driver.DrawFinish.draw_enqueued 9.7, VideoOut.Flip 7.6, Driver.Present 7.5
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-10T22:31:43Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The performance evidence does not meet the repository's capture requirements: the main and PR runs were separate boots, and the required trace attachments and identifiable title/scene are missing.
What I ran
Reviewed all eight changed files at head
54e4d6d3fcab72c7133999dd503de2cab6be5456against currentmaintip1d13b559c20a1f11ec001090e7ab443c426957b6; the merge preview is clean. Environment: Linux 6.1 x86_64, Python 3.11.2, GCC 12.2.0.The PR description also reports Windows 11/GCC 15.2 tests and GPU captures; those are author-provided results, not runs I performed.
Results
main.Commands and recorded output
pr_precheck.py:The report records
diff_check,conventions_and_pr_template,live_dependency_and_mergeability_check, andtest_quality_heuristicsas passed. It marks compilation and build-dependent C++ tests as not run. The test-quality heuristic says the new C++ test path was not found literally in CMake; I checked the registration macro and the new CMake fragment callsagc_add_draw_pipeline_test(agc_driver_draw_handoff_spin), so this warning is a false positive.The audit and convention output:
The stack report says:
Hosted status snapshot: conventions, eligibility, intake, labels, library-portability and report passed; Windows was pending; edge-watch, Linux, pipe-write, register-context, relinker, relinker-asan and write-watch were skipped.
Negative control
Not run; no exact-head test binary was built in this initial no-build pass.
Findings
Blocking
The PR includes summary lines and digests, but the summaries mark the game title and ID as withheld, and the scene is described only as “an open-world, draw-heavy title.” The two trace filenames appear in the text, but I found no downloadable
.json.gztrace attachments or links. The main and PR summary captures are also explicitly described as separate boots; the in-run A/B toggles a runtime switch in the PR build and is not a same-session capture of the base and changed builds. The performance report form requires an identifiable title and scene, the base and change captured on the same machine in the same session, and both trace files.Please provide the title ID and enough scene detail to reproduce the capture, attach both raw traces, and provide matched base/change captures following the form. The included in-run A/B is useful supplementary evidence; it does not replace that base/change pair. Both trace digests report dropped events, so the available traces also cannot support inspection of all recorded slices.
Non-blocking
None found in the source-level review.
Sources
Not verified
To get this to a good state
Add the reproducible scene description and trace files, and capture base and change in the same session. On the updated head I will rerun the no-build precheck, refresh hosted statuses, and check the focused draw-handoff tests if build evidence is needed.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T22:33:21Z.
Review: COMMENTED
The trial merge onto
c1601e56d5conflicts inDrawPipeline.cppand the runtime-switch header and implementation. When resolving it, retain the blocking fallback and the order/drain assertions in the contended fixture. In particular, keep the full-finisher case, which exercises backpressure independently of label ordering. The timed result should use the repository’s paired main/change traces from the same scene and machine.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.