feat(agc): add the GPU, GPU mutex waits and shader preparation to the trace #4632
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4632"
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 AlxcBTW on 2026-10-12T17:03:58Z.
Step 3 of #4477, on top of #4526. The trace gets a
gputrack (a slice per recorder batch, and withAPS5_PROFILE_GPU=1a slice per command class range), slices for waits on the GPU mutex, and the shader preparation threads. A frame that is GPU-bound then shows as the GPU busy while the presenter waits.What
Recorder::readGpuTiminghands each range it reads toPerformanceTrace::GpuRangewhile a window is open. That is the batch's timestamp pair, which a trace switch already turns on (#4526), and, withAPS5_PROFILE_GPU=1, each command class range under its[gputime]name:draw,copy,fill,storage-upload,present-blit, and so on. Program ranges are left out. The ranges go into a buffer of 262,144 entries under a mutex of their own (reserved when the window opens, so appending never allocates); past that,trace_droppedis set. Outside a windowGpuRangeis one relaxed load.VK_KHR_calibrated_timestamps, or the EXT version, is enabled only when a trace switch is set, and only if the device offers the device domain and the host domain the CPU clock uses: QPC on Windows,CLOCK_MONOTONICelsewhere.VulkanDevice::CalibrateClocktakes a pair when the window opens and another when it closes, and the mapping is linear between them, so the two clocks agree at both ends of the window. Without the extension there is nogputrack, and the[trace]line says so.GpuMutexthat has to wait becomes aGpuMutex.wait.<site>slice. The site is the oneTagGpuLockSitenames for the[lock]line (dispatch,draw,present,flush, ...), now also kept while a window is open. Outside a windowlock()costs one more predictable branch.shader preparewith buffers of 32,768 events. TheirShader.PrepareArtifactand other timers show up in the trace.docs/dev/BUILD.md(Performance trace).Tested
Windows 11 (26200), WinLibs GCC 15.2.0 r7, Release, RTX 5070 Laptop (NVIDIA 616.92).
agc_performance_trace: new case for the clock mapping. Ranges are mapped linearly between two calibrations (here the GPU clock runs at twice the CPU's rate), a range that starts before the window or has no length is dropped, and with one calibration the mapping uses the CPU rate.ctest -E "^agc_driver|^video_out|^guest_video"): 615 of 616 pass on 795dc6b7e, includingagc_performance_traceandprx_thread_local_destructors.log_macrosfails as onmainon that machine.APS5_TRACE_FRAMES=120:120andAPS5_PROFILE_GPU=1: thegputrack has 124,454 slices: 8,087 batches and the class ranges, which nest one level deep inside their batch. No slices overlap partially, and no two batches overlap. The batches cover the whole window and add up to 79.14 ms per present. The summary'sgpu_busy_ms_per_present, from the same timestamps through the[present]accounting, is 79.15 ms. Every batch starts after the start of aRecorder.Submitslice on a queue worker (p1 15 us, median 141 us after the latest one), so the mapped GPU clock does not run ahead of the CPU's. Perfetto's trace processor v58.2 imports the file (3.7 MB) with no errors. A first run with a smaller GPU buffer filled it halfway through and settrace_dropped; the buffer now holds 262,144 ranges. Details are in a comment below.tools/check_conventions.py --base origin/mainpasses.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-12T17:04:04Z.
Capture from a title run: Sword of the Sea (PPSA25344), main menu, RTX 5070 Laptop (NVIDIA 616.92), Windows 11 26200. The build is this PR on our lab branch (with #4526 and #4570), which carries the local patches the title still needs.
APS5_TRACE_FRAMES=120:120 APS5_PROFILE_GPU=1, 150 s run..json.gz(36.4 MB of JSON), 398,575 events,trace_droppedfalse. Threads:queue worker 0x0239,997 slices,queue worker 0x2031,887,presenter1,744,gpu124,454. Tenshader preparethreads are named, but the menu prepared no shaders inside the window, so they have no slices.batchslices, with the class ranges one level inside them. No slices overlap partially and no two batches overlap; the GPU runs one queue. The batches span the whole 14.8 s window and add up to 79.14 ms per present. The summary'sgpu_busy_ms_per_present(the[present]accounting of the same timestamps) is 79.15 ms. Per present, by class:draw12.1 ms,storage-writeback10.1,storage-upload7.7,staging-out2.6,staging-in2.5,shadow-publish1.1,dispatch-trail1.0,label-run0.6.Recorder.Submitslice on a queue worker: the gap to the latest one is 15 us at p1, 141 us at the median and 13.7 ms at p99. A mapping that ran ahead of the CPU clock would put batches before their submit.trace_processor_shellv58.2 imports it with no error instats: 398,202 slices on four thread tracks (depth up to 8 on queue worker 0x0, 1 ongpu), 120presentinstants, and the threefoldedcounters.A first capture with a 65,536-range GPU buffer filled it at 7.5 s and set
trace_dropped, which is what the flag is for. WithAPS5_PROFILE_GPU=1the menu makes about 8,400 ranges a second, so the buffer is now 262,144 ranges, the size of a thread's.The trace itself is not attached because it comes from a title run.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-12T20:16:55Z.
#4526 is merged. I rebased this on main: only this PR's commit is left, and it applied cleanly. I also added ad10d4ffe, which updates the comment in
TagGpuLockSite: the tag is now read inside a trace window too.Tested on Linux (GCC 16.2, Radeon 660M, RADV):
agc_performance_trace,agc_profile_output,agc_stack_walk,agc_driver_present_mode,agc_driver_flip_compute,agc_driver_meshandtrace_digestpass (8/8).APS5_TRACE_FRAMES=1:5. RADV offersVK_KHR_calibrated_timestampswith the device andCLOCK_MONOTONICdomains, so the track is there.batchslices, which don't overlap.Recorder.Submit. The first one was already in flight when the window opened.APS5_PROFILE_GPU=1the class ranges (dispatch-lead,dispatch-trail,label-run) show up under their batch.video_out_flip_testspresent/backtoback/aftergpu.One thing for later, not for this PR: in that short window the summary's
gpu_busy_ms_per_presentcame to 437 ms in total, more than the window's wall time. It comes fromSettleRetired, which settles a retired range after the fact, so a short window with long batches also counts work from before it opened. Over 120 presents that evens out, as your 79.14 / 79.15 shows. Once thegputrack exists, the summary could take the GPU busy time from the track instead.The full build workflow runs next, and I'll merge when it's green.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-12T20:38:15Z.
I dropped ad10d4ffe again:
conventionsdoesn't let a comment change without a TechnicalDebt edit. That leaves the PR aseb8a7255d, the same code the full build above passed on (Linux and Windows green, run 38303183197).