perf(agc): write the draw profile reports through the asynchronous profile output #9373
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9373"
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 thuanquang on 2026-10-21T19:35:21Z.
What
With
APS5_PROFILE_DRAW=1, three 10 s reports were still written withstd::fprintf(stderr)on the threads that run draws:[draws]report and its[rescache] draws:line inreportDraw(Graphics/src/Draw.cpp), on the draw committer, withDrawProfile's mutex held;[draw] pipelinedline inDrawPipeline::report, on the queue worker, with the pipeline mutex held;[finisher] drawsline that #6946 added, innoteFinisherHandOff(Execution/src/Driver/Draw/Draw.cpp), on the queue worker in the draw path.The draw committer also holds
GuestMemory::GpuMutexaround the draw (Execution/src/Driver/Draw/Draw.cpp:1048). So the report write held up every user of the GPU lock, not only the callers ofDrawProfile's mutex.The CRT's stderr is unbuffered. When it is not a console, a printf-family call writes it one byte per
WriteFile, so a 1 KB[draws]line costs about 1000 writes. All three now go throughProfilePrint_nid_no_patch, as the other periodic reports have since #798. It formats on the caller and writes from its own thread with onefwrite. The text of the lines is unchanged.Why
In a profiled game run with stderr redirected by
Start-Process -RedirectStandardError(how our scripts start the game), every 10 s window had one frame of 134 to 177 ms. That frame comes from the profiler, not the game, so the p99 and max of profiled runs could not be trusted. #798 measured up to 107 ms for single synchronous writes; this report was not part of that change.A micro-benchmark shows the cost of one call. Stderr was redirected to a file on D: the same way
run.ps1starts the game, with the project's compile flags and its force-includedHostStandardStreams.hpp, 50 calls each:[draws]length)WriteFilesstd::fprintf(stderr, "%s\n", line)[draws]+[rescache]pairstd::fwriteof the lineProfilePrint_nid_no_patch, caller sideHow much one write costs depends on how stderr is opened:
Start-Process -RedirectStandardErroropens the file write-through (FileModeInformation0x22). OneWriteFileon it takes 0.11 to 0.39 ms, so the pair costs about 134 ms. That is the setup of the table above and of the game runs below.Tested
Rebased again onto
main513ca7e558(head09b9bf9afa) after #6292 addedMutex.hppto the same include list inGraphics/src/Draw.cpp: both includes kept, nothing else changed (git range-diffshows only that context line). On this head, built clean: the 23 tests below, 3 rounds, all pass; under the Khronos validation layer 23 of 23 pass with 0VUID-lines, the layer inserted 51 times, no "was not found" line. The measurements further down are from04a63e9d8d, whose code is the same apart from that include.Rebased onto
main0db47b263d(head04a63e9d8d), after #6946 merged into the same[draw] pipelinedline, which now also reports the lock wait and the committer wakes. The rebase keepsmain's line and only switches its write toProfilePrint_nid_no_patch, as before; the[draws]and[rescache]changes applied unchanged. #6946 also added the[finisher]report, written the same way, so this head moves that line too (one call and its include).ProfilePrint_nid_no_patchhas no switch of its own, so the line still appears withAPS5_PIPELINE_STATSalone. On this head and onmain0db47b263d, both built clean, with the tests listed below plusagc_driver_prepared_shadersitself (23 in all):VUID-lines on both sides.VK_LOADER_DEBUG=layershows the layer inserted 51 times onmainand 51 times on this head, with no "was not found" line.Before the rebase, on
main7e2ba73e4cand head64e264f8dd:Tests that turn on
APS5_PROFILE_DRAW(none of them parses the report text):agc_driver_address_passes,agc_driver_address_passes_targets_split,agc_driver_dispatch_differing_value_sets,agc_driver_rect_list_indirect, andagc_driver_prepared_shaders_debugand_debug_failure, run together with the other 16agc_driver_prepared_shaders_*modes.main7e2ba73e4cand on this PR, 22 of 22 pass with 0VUID-lines on both sides.VK_LOADER_DEBUG=layershows the layer inserted 48 times on each side, with no "was not found" line.agc_profile_output, which this PR does not change.tools/trace_digest.pyandtools/performance_compare.pyread the JSON trace and summaries.PPSA14363 on
main0db47b263d, rerun for this head (METAL GEAR SOLID Master Collection Vol. 1, own dump), RX 6700 XT:APS5_PROFILE_DRAW=1,APS5_TRACE_SUMMARY_EVERY=10and a 20 s trace window at 100 s (APS5_TRACE_SECONDS=100:20), no frame dumps.dirty: false):main0db47b263dand this head04a63e9d8d, with onlylibSceAgcDriver.prxswapped.main, 15:12main, 15:22main, 15:35mainrun at 15:25, during which something outside the emulator slowed the PC (373 to 590 presents, frames of 1 to 4 s, the queue worker waiting indraw_enqueued); this head was not run then. Also two runs of this head's code at 15:15 and 15:19 from a build made before the commit was amended, so their summaries saydirty: true; they read the same (600 presents, max 17.4 to 18.8 ms).Summary lines of the five trace windows (100 to 120 s), in the table's order
PPSA14363 (METAL GEAR SOLID Master Collection Vol. 1, own dump), RX 6700 XT, measured before the rebase:
APS5_PROFILE_DRAW=1,APS5_TRACE_SUMMARY_EVERY=10and a 20 s trace window at 100 s (APS5_TRACE_SECONDS=100:20), no frame dumps.main7e2ba73e4cand this PR's head64e264f8dd, each with #9115's trophy fix (which gets past stop 1), with onlylibSceAgcDriver.prxswapped.main7e2ba73e4c64e264f8ddAn earlier A/B on
main1896871ba7read the same, and showed that without theDrawPipeline.cppline the max stays at 45 to 75 ms (one 103 ms).Summary lines of the trace window, 100 to 120 s. First
main, then this PR:tools/performance_compare.pyon these two lines and thetools/trace_digest.pytables of both runs are in this comment. Traces are not attached, because these runs come from a commercial title.tools/check_conventions.pypasses.Not tested: other GPUs, Linux. The same synchronous write remains in a few rarer reports (
[indirect],[fill],[fill-cover]/[fill-clear],[dispatch-item], none of which this title prints; and #6946's[finisher-held]and[epoch-proofs]lines, which print at power-of-two counts) and in the[gpu] frame_NNN.bmpline ofAPS5_DUMP_FRAMES, which #8807 works near. So is the per-draw[draw]line ofAPS5_TRACE_DRAWS, which stays synchronous so it keeps its order with the same draw's other trace lines. They are left for a follow-up.Overlap:
[draw] pipelinedline, and this PR now carries its extended version. #7642 and #1896 (drafts) and #9508 edit that line too; all three conflict withmainnow. #6947 was closed.ProfileOutputstarts its thread. It does not conflict with this PR.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 github-actions[bot] on 2026-10-21T19:35:36Z.
This pull request is labeled
perf, so it needs the summary line of a capture onmainand one with the change, from the same title, scene and machine, as the Performance report form asks. Please paste bothaps5-summary.jsonllines, attach the two traces and add the output oftools/trace_digest.py.Imported from boykopovar/AnyPS5. Originally posted by thuanquang on 2026-10-21T19:37:19Z.
Summary lines for the bot's request, one 10 s window per side (70-80 s), same title, scene and machine as the table in the body.
main1896871ba7plus #9115's trophy fix:This PR, same setup. It was built while the
DrawPipeline.cppchange was still uncommitted on top ofa40fd382d3, so the line saysa40fd382d362anddirty; the source equals this PR's head5b04afb32e:tools/trace_digest.pyover each run'saps5-summary.jsonl,mainfirst:This PR:
I am not attaching traces, because these runs come from a commercial title. Both sides are summary-only runs (
APS5_TRACE_SUMMARY_EVERY=10) without a trace window.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T06:48:08Z.
Review: DISMISSED
The change is narrowly focused on moving the two periodic diagnostic reports off the draw/queue workers. The reported 3.5 us caller-side enqueue cost and the PPSA14363 A/B data make the intended benefit plausible; I did not find a correctness defect in the two call-site substitutions.
There are several required validation/readiness items before merge:
main. The report compares commit1896871ba7plus #9115 against a dirty build based ona40fd382d3. This PR head is 514 commits behind currentmain(d6eafa54d046), so please rebase and repeat the same title/scene/machine comparison on currentmainand the rebased PR. The existing summary windows and digest table are useful, but do not describe currentmain.perfcheck andCONTRIBUTING.mdrequest both captures andtools/trace_digest.pyoutput; the summaries/digest table are present, but trace files are not. Please attach them if they can be shared, or ask a maintainer to confirm that summary-only evidence is acceptable for this title.CONTRIBUTING.mdasks for the same focused tests onmainand the change with Vulkan validation, and a comparison of newVUID-lines. The PR reports the validation run on this PR only. Please run the focused set on both refreshed commits and report the comparison.DrawPipeline.cppoverlaps. My pairwise merge-tree check finds content conflicts with #6946 and #9508 on the[draw] pipelinedreport, and with #1896; #7642 also has broad pipeline conflicts. #9508 is a newer overlap than the original overlap report. Agree with the affected authors which change goes first, preserve the added report fields, and updateDepends onif the agreed order requires it.Local checks: conventions and
git diff --checkpass; merge-tree with currentmainis clean. Hosted conventions, eligibility, labels and report pass, while product jobs skip by path filters. I could not run the GPU tests here: this host has no available GPU, full configuration is blocked by the missing SDL2 submodule/XRandR support, and my GitHub permission is read-only so I cannot dispatch the manual build workflow. The author reports 22 focused tests passing in three rounds on an RX 6700 XT, including a validation-layer run on the PR; I have not independently reproduced those results.Imported from boykopovar/AnyPS5. Originally posted by thuanquang on 2026-10-22T09:38:13Z.
Thanks. Point by point:
main7e2ba73e4c(head64e264f8dd), and the A/B is rerun on thatmainand on the rebased head, same machine and scene, both built clean (dirty: false). Both sides have #9115's trophy fix, which gets the title past stop 1, and onlylibSceAgcDriver.prxis swapped between them. Launcher title, 150 s,APS5_PROFILE_DRAW=1,APS5_TRACE_SUMMARY_EVERY=10and a 20 s trace window at 100 s (APS5_TRACE_SECONDS=100:20), with the GPU and build locks held so no other job ran. Per 10 s window from 20 s on, leaving out 110 to 120 s on both sides, because its last frame writes the trace (239.7 ms onmain, 115.4 ms with this PR):main7e2ba73e4c64e264f8ddThe summary lines of the trace window (100 to 120 s),
mainfirst:tools/performance_compare.pyon these two lines. The only configuration difference it reports iswindow.first_present(5865 and 5944), the present at which the 100 s window opened:mainframe_ms.p50frame_ms.p90frame_ms.p99frame_ms.maxmean_frame_msgpu_busy_ms_per_presentIn its top phases,
Driver.Packetgoes from 0.714 to 0.403 ms per frame andGraphics.Drawfrom 0.473 to 0.241.tools/trace_digest.pyon both runs' summary filesmain7e2ba73e4c:14 intervals, 0.0 to 140.3 s, 8232 presents
AMD Radeon RX 6700 XT, AMD proprietary driver 26.10.1 (AMD proprietary shader compiler), Windows 10.0.26200, 1920x1080, commit
7e2ba73e4cThis PR
64e264f8dd:14 intervals, 0.0 to 140.2 s, 8344 presents
AMD Radeon RX 6700 XT, AMD proprietary driver 26.10.1 (AMD proprietary shader compiler), Windows 10.0.26200, 1920x1080, commit 64e264f8ddfc
Traces. These runs come from a commercial title, so the trace files stay local, and the description and this comment carry the summary lines and the tools' output instead. @adriadam10 @oneandonlydean, is summary-only evidence acceptable for a title whose trace files we can't share?
Validation-layer A/B. The 22 focused tests ran on
main7e2ba73e4cand on the rebased head, each 3 rounds without the layer and once with it (ANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1, implicit layers disabled):VUID-linesmain7e2ba73e4c64e264f8ddThe tests are
agc_driver_address_passesand_targets_split,agc_driver_dispatch_differing_value_sets,agc_driver_rect_list_indirectand the 18agc_driver_prepared_shaders_*modes, among them the two that turn onAPS5_PROFILE_DRAW.[draw] pipelinedline. #6946 and #9508 (@Raghav314) change its text and fields, and #1896 (@fisherjoey, draft) adds a field. #7642 (@EagleBearerYS, draft) conflicts more broadly inDrawPipeline.cpp. This PR only replaces thestd::fprintf(stderr, ...)call withAgcDriver::ProfilePrint_nid_no_patch(...)and keeps the format string and arguments, so whichever lands second keeps the other's fields with theProfilePrintcall, a one-line resolution. I'm fine with this one going after any of them and will rebase it then; tell me if you prefer the other order.Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-22T09:42:08Z.
Either order is fine for #1896. It's a draft, and I'm restacking it onto main anyway, so if this lands first I'll keep the
ProfilePrintcall and add our field when I rebase.AI-assisted: yes