feat(agc): report performance timer scopes to Tracy with APS5_ENABLE_TRACY #4607
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4607"
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 EagleBearerYS on 2026-10-12T16:41:25Z.
What
Item 7 of #4477: Tracy as an optional build flag for deep dives, compiled out when off. It complements the trace capture of #4526 with the same
PerformanceTimerscopes, but live in the Tracy profiler, unbounded in time, with its statistics, histograms and frame view.-DAPS5_ENABLE_TRACY=ON(defaultOFF) builds the Tracy 0.14.1 client from the new3rdparty/tracysubmodule as a shared library, so libSceAgcDriver and libSceVideoOut feed one profiler instance. It is written next to the.prxfiles (libs/unpatchedandlibs:libTracyClient.dll,libTracyClient.so.0.14.1on Linux) and is not NID-patched; the patcher only rewrites imports that start withsceor end in_nid_postfix. Without the flag the submodule is not configured andTracyZoneis an empty[[no_unique_address]]member, so the libraries compile to the same code asmain(checked below).PerformanceTimeropens a zone named after its scope and closes it inFinish, the same span as itsFrameTimingmetric: all 41 scopes,Driver.WorkerWait,Driver.Packet,Graphics.Draw,Resources.Prepare,Recorder.Submit,Vulkan.QueuePresent,Shader.Register,VideoOut.Flipand the rest. Source locations are interned per scope name in a fixed table (a lock only on a name's first use), so a zone is two queue items and no allocation, also per packet.Driver::Presentends a frame after it releases the flip. The queue workers and the presenter name their threads with the rolesPinWorkerThreadalready gets (queue worker 0x0,presenter); guest threads keep the names libkernel gives them.TRACY_ON_DEMAND: nothing is recorded or buffered until a profiler connects.TRACY_ONLY_LOCALHOST. No sampling, system tracing, call stacks or code transfer, so a capture holds no code, module paths or other processes of the machine.TRACY_NO_CRASH_HANDLER, because Tracy's handler would take the access violations the emulator handles itself.rocprofiler-sdkis not searched on the system.thread_localobjects before their destructors run (#4029). Tracy keeps each thread's queue producer in athread_localmoodycamel::ProducerToken: its destructor would read the producer from freed memory and write through it, and the queue's destructor writes into the token. On MinGW the client is therefore linked with a no-op__cxa_thread_atexit(cmake/TracyThreadExit.cpp) and built withTRACY_DELAYED_INIT: nothread_localdestructor of the client runs, and its queue lives in a heap object that is never destroyed, so nothing touches a dead token. A thread that emitted a zone and ended keeps its event blocks (2 MiB each) until the process exits. The client'sWINVERand_WIN32_WINNTstay private to it.docs/dev/BUILD.md(Tracy).On top of #4526. Both hook
PerformanceTimer, as #4477 planned ("the same zones would feed both outputs"):Finishfirst closes the Tracy zone, then writes #4526's trace event and theFrameTimingmetrics.Tested
Windows 11 (26300), WinLibs GCC 15.2.0 r7, Release, RTX 3070 Laptop (NVIDIA 617.42). Rebased onto
main3e0e01f35(#4526 merged); the capture table below is frommain2a5eca11c, before #4526, and33ae282e4gave the same results.Title capture. Unpacking (PPSA07117) at its menu, built with
-DAPS5_ENABLE_TRACY=ON, with Tracy 0.14.1'stracy-captureattached after 35 s for 20 s: 1,174 frames in 20.16 s (oneDriver.Presentand oneVideoOut.Flipeach) and 1,095,198 zones of 25 scopes from both libraries, in a 5 MB trace. Largest totals fromtracy-csvexport:Driver.WorkerWaitVideoOut.FlipDriver.PresentVulkan.RetireDriver.PacketDriver.DrawGraphics.DrawRecorder.SubmitShader.ResolveGraphicsStagesAbiVulkan.QueuePresentRecorder.ReapThe game's driver threads are named
queue worker 0x0andpresenter(read back withGetThreadDescription, which Tracy'sSetThreadNamealso sets). Closing the window ends the game with exit code 0, also when it is closed while the profiler is connected; that capture (688 frames, 641,520 zones) ends by itself when the client goes away.With #4526. On
3e0e01f35the 19 tests below andagc_performance_tracepass. One Unpacking run withAPS5_TRACE_FRAMES=1800:600andtracy-captureattached produced both outputs: #4526'saps5-trace-*.json.gzand summary line (600 presents,frame_msp50 17.3 / p90 19.1 / max 21.5,trace_droppedfalse) and a Tracy capture (1,146 frames, 1,069,578 zones in 20.1 s).Driver threads ending while connected. With
tracy-captureattached,video_out_flip_lifetime,_reopen,_controls,_overlay,_unopened,agc_driver_draw_cache_reuse,agc_driver_draw_cache_reuse_offandagc_driver_dword_pattern_fillpass; each records its frames and zones, and its queue workers and presenter end when the driver stops.Tests with the flag on:
patched_libraries,host_thread_local,prx_thread_local_destructors,agc_profile_output,agc_driver_pm4,agc_driver_pm4_failure,agc_driver_draw_cache_reuse,agc_driver_draw_cache_reuse_off,agc_driver_dword_pattern_fill,texture_format_lookup,linear_display_buffer,guest_agc_driver_resources,guest_rendering_waitand the sixvideo_out_flip_*(withANYPS5_VIDEO_OUT_TEST_DRIVER=windows; the offscreen driver skips them on Windows): 19 of 19 pass.Flag off. With
APS5_ENABLE_TRACY=OFFthe objects ofPresentation.cpp,WorkerAffinity.cpp,PacketExecution.cpp(the per-packet timer) and libSceVideoOut'sVideoOutDriver.cppare byte-identical to the ones built frommain's sources.MinGW
thread_localdestructors. A DLLthread_localwhose destructor runsHeapValidateon its own emulated-TLS block, used by threestd::threads of an exe: with this toolchain each thread exit runs the destructor on a freed block; with the no-op__cxa_thread_atexitlinked into the DLL none runs, and__mingw_cxa_thread_atexitis no longer linked. InlibTracyClient.dllthe only registration, the per-thread data ofGetProfilerThreadData, tail-calls the no-op.Linux (Ubuntu 24.04 in WSL2, GCC 13.3, lavapipe, with CI's configure flags and test environment; on a21f9b73f, before the rebase). With
-DAPS5_ENABLE_TRACY=ONthe same tests pass: 13 of 18, with the fivevideo_out_flip_*that need a window skipped as in CI;prx_thread_local_destructorsis MinGW-only.libTracyClient.so.0.14.1is inlibsandlibs/unpatched, and libSceAgcDriver and libSceVideoOut list it asNEEDEDwithRUNPATH $ORIGIN. Tracy 0.14.1's Linuxtracy-capturerecordsagc_driver_draw_cache_reuse(3 frames, 105 zones) andagc_driver_dword_pattern_fill(3 frames, 149 zones), the same counts as on Windows. The default build, with the flag off, passes the same set.Conventions:
tools/check_conventions.py --base origin/mainpasses. Replaying the overlap check lists only #4526.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)Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-12T21:09:18Z.
Reviewed and tested on Linux, now that #4526, #4632 and #4581 are on main:
3rdparty/tracyis at 30997d5ca, thev0.14.1tag of wolfpld/tracy.-DAPS5_ENABLE_TRACY=ON:libTracyClient.so.0.14.1is inlibsandlibs/unpatched.libSceAgcDriver.prxandlibSceVideoOut.prxlist it asNEEDEDwithRUNPATH $ORIGIN.video_out_flip_*are skipped with the offscreen driver, as in CI.APS5_TRACE_FRAMESstill writes its trace and summary line, since both outputs hang offPerformanceTimer. Oneaftergpurun under the validation layer failed its timing check once ("GPU work landed at 0.0 ms"). It didn't happen again in 10 more runs (with and without the trace, with a cold shader cache), and the build without Tracy behaves the same, so I'm putting it down to load on this laptop.main. The full build workflow is green on Linux and Windows (run 38305815614).Merging.