feat(agc): count replayed frames as presents for the performance trace #13984

Merged
thuanquang merged 2 commits from upstream-pr/13984 into main 2026-11-08 07:17:50 +00:00
thuanquang commented 2026-10-31 14:28:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by thuanquang on 2026-10-31T14:28:14Z.


What

agc_frame_replay never presents, so the performance trace never started in a replay: APS5_TRACE_FRAMES, APS5_TRACE_SECONDS and APS5_TRACE_SUMMARY_EVERY wrote nothing. The trace session, its window and its summary intervals start and count in PerformanceTrace::Present (Execution/src/PerformanceTrace.cpp). On main its only caller outside tests is Driver::Present (Execution/src/Driver/Presentation.cpp), which runs when VideoOut presents a title's frame. A replayed flip ends in ReplayFlip::GpuReady (tools/FrameReplay.cpp), which only records the frame's time.

  • Driver::TracePresent(width, height) counts one present for the performance trace, as the first line of Driver::Present does, and nothing else; with no trace switch set it returns at once. It passes the driver's own device, so when the driver already has its device as the window opens, the trace gets its gpu track and the summary its gpu and driver fields, as in a title run. agc_frame_replay reaches it through a new export, AgcDriverTracePresent, as it already reaches AgcDriverSerialProgress and AgcDriverAwaitedWaits.
  • Frames::MarkReady calls it for each flip the driver reports ready, before it takes the frame's time, with the size of the first display buffer the capture stored, or 0x0 when the capture stored none.
  • agc_driver_frame_replay_trace_window, a new mode of the frame replay state test, replays three flips with APS5_TRACE_DIR=<capture>-trace and APS5_TRACE_FRAMES=0:2 and expects the window's line in aps5-summary.jsonl with "presents":2. Like the other trace-window tests, it unsets APS5_TRACE_SECONDS and APS5_TRACE_SUMMARY_EVERY.
  • docs/dev/BUILD.md, Performance trace: what a present is in a replay.

A replay's trace differs from a title's in three ways:

  • A present is counted when the driver reports the flip ready, on the thread that reports it: the queue worker running the submission, or the submitting thread for a CPU flip the driver completes at once. That thread formats the trace when the window closes, and there are no Driver.Present slices.
  • resolution comes from the capture, not from a video output.
  • gpu_busy_ms_per_present is 0, because that time is counted as presentations retire. The gpu track has the GPU time.

As in a title run, a window that is still open at the end writes nothing, so a frame window needs more than <start> + <count> replayed flips.

This is not the in-flight-depth change discussed on #12568, which stays a separate PR stacked on #12568.

Tested

Windows 11 26200, AMD Radeon RX 6700 XT (gfx1031), driver 32.0.21045.16010, Ryzen 5 5600X, WinLibs GCC 15.2.0 r7, Release.

This head fcdddc9899 is 373b38a1ec with main b11c7bf84f merged in, and the merge had no conflicts. The lines git diff b11c7bf84f fcdddc9899 adds and removes are exactly those of 373b38a1ec's own patch. Full builds of both trees, with submodules at their pins:

Tree frame_(replay|capture) tests passed, 3 runs Skipped VUID- lines Missing-layer message
main b11c7bf84f 14/14, 14/14, 14/14 0 0 none
fcdddc9899 15/15, 15/15, 15/15 0 0 none

The one extra row is agc_driver_frame_replay_trace_window.

Red on main b11c7bf84f: I put main's copies of Execution/include/Driver.hpp, Execution/include/Driver/Driver.hpp, Execution/src/Driver/EntryPoints.cpp, Execution/src/Driver/Presentation.cpp and tools/FrameReplay.cpp into fcdddc9899, keeping this PR's test and registration. agc_driver_frame_replay_trace_window then failed in 3 of 3 runs with replayed frames did not open and close the trace window.

Earlier revisions. 373b38a1ec was rebased onto main dc9dc7eaae for #12862's split of the test registration, with the same patch otherwise. It passed 12/12 in each of 3 runs, with 0 VUID- lines; main was not rerun for it. The previous head 0de943f892 on main 50843f45d9:

Tree frame_(replay|capture) tests passed, 3 runs VUID- lines Missing-layer message
main 50843f45d9 11/11, 11/11, 11/11 0 none
0de943f892 12/12, 12/12, 12/12 0 none

All arms ran ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer ctest --test-dir build -R "frame_(replay|capture)" -V. Neither log has a layer insertion line, because none of these tests creates a Vulkan instance.

  • Red on main 50843f45d9 (head 0de943f892): with main's Execution/include/Driver.hpp, Execution/include/Driver/Driver.hpp, Execution/src/Driver/EntryPoints.cpp, Execution/src/Driver/Presentation.cpp and tools/FrameReplay.cpp, and this PR's test and registration, agc_driver_frame_replay_trace_window failed in 3 of 3 runs with replayed frames did not open and close the trace window. With this PR it passed in 3 of 3.
  • A title, on the earlier revision dc8621f997 (the same production code at other insertion points, on main 50843f45d9): four replays of a 20-frame capture of PPSA05110 with APS5_TRACE_FRAMES=2:16 each printed [trace] recording frames 2:16 from present 2 and [trace] closed at present 18, writing aps5-trace-dc8621f99705-<pid>.json.gz ..., wrote the trace and its summary line ("resolution":"3840x2160", "gpu":"AMD Radeon RX 6700 XT", "presents":16, "gpu_busy_ms_per_present":0.000, "trace_dropped":false) and exited 0. A fifth was stopped at the tool's pacing gave up message before its window opened. tools/trace_digest.py reads the first trace (rows for title, queue worker 0x0, draw committer and gpu). In the three replays that ran without a build beside them, the replay's JSON interval ending at the closing flip was 406, 444 and 393 ms against medians of 195, 199 and 194 ms. Over the window, the JSON intervals add up to 192-252 ms more than the trace's window: that is about the time spent formatting 9.6-10.3 MB of trace JSON at the close, which the trace's own frame times leave out.
  • Linux, WSL2 Ubuntu 24.04 (kernel 5.15), lavapipe (Mesa 25.2.8), GCC 13, Release build of 0de943f892 from an archive with submodules at their pins: agc_driver_frame_replay_trace_window passed 6 of 6 (3 runs with the default import path, 3 with APS5_WRITE_WATCH_IMPORTS=unwatch). The capture-based tests in the set could not run there: this kernel has no asynchronous userfaultfd write protection, so the guest write watch is unavailable and agc_driver_frame_capture_eop stops with the guest write watch is unavailable; the linux CI job covers them.
  • Not tested: macOS (no CI job builds the driver there), other GPUs, and #11435's --repeat together with this change.

Overlap

  • No merge order is needed. 373b38a1ec merged without conflicts with the current heads of #12318 (d3faa75d4a), #12565 (f360a4575c), #12567 (1126a888d9), #12568 (0e3d922b76) and #12696 (9f770fd8d1). #11435 (9392228b5c), #11436 (752958c135) and #12871 (ca858917b0) conflict only with main's split of libSceAgcDriver/CMakeLists.txt, not with this PR's files.
  • #14137 (mine) adds an include and test modes at the same two places of tests/FrameReplayState.cpp; whichever lands second keeps both.
  • #11435 adds --repeat, which replays the capture several times in one process and reports every pass's flips to the same Frames. With both PRs, every pass's flips count as presents, so a window can include the warm-up pass and the memory restore before each later pass. With F flips per pass, a frame window inside one later pass (<start> ≥ F and (<start> mod F) + <count> < F) leaves both out. I can add that to BUILD.md once #11435 has merged.
  • #11436's APS5_TRACE_GPU and --trace-serials print submission serials on stderr and do not start the performance trace, so this PR complements them.
  • #12696 relaunches the replay in a child process before replaying anything. The child inherits the trace switches and writes the trace; its summary env also lists APS5_FRAME_REPLAY_ATTEMPT.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: AMD Radeon RX 6700 XT, driver 32.0.21045.16010, Windows 11 26200; lavapipe (llvmpipe, Mesa 25.2.8), WSL2 Ubuntu 24.04
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5098431643 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13984). Originally posted by [thuanquang](https://github.com/thuanquang) on 2026-10-31T14:28:14Z. --- ### What `agc_frame_replay` never presents, so the performance trace never started in a replay: `APS5_TRACE_FRAMES`, `APS5_TRACE_SECONDS` and `APS5_TRACE_SUMMARY_EVERY` wrote nothing. The trace session, its window and its summary intervals start and count in `PerformanceTrace::Present` (`Execution/src/PerformanceTrace.cpp`). On `main` its only caller outside tests is `Driver::Present` (`Execution/src/Driver/Presentation.cpp`), which runs when VideoOut presents a title's frame. A replayed flip ends in `ReplayFlip::GpuReady` (`tools/FrameReplay.cpp`), which only records the frame's time. - `Driver::TracePresent(width, height)` counts one present for the performance trace, as the first line of `Driver::Present` does, and nothing else; with no trace switch set it returns at once. It passes the driver's own device, so when the driver already has its device as the window opens, the trace gets its `gpu` track and the summary its `gpu` and `driver` fields, as in a title run. `agc_frame_replay` reaches it through a new export, `AgcDriverTracePresent`, as it already reaches `AgcDriverSerialProgress` and `AgcDriverAwaitedWaits`. - `Frames::MarkReady` calls it for each flip the driver reports ready, before it takes the frame's time, with the size of the first display buffer the capture stored, or 0x0 when the capture stored none. - `agc_driver_frame_replay_trace_window`, a new mode of the frame replay state test, replays three flips with `APS5_TRACE_DIR=<capture>-trace` and `APS5_TRACE_FRAMES=0:2` and expects the window's line in `aps5-summary.jsonl` with `"presents":2`. Like the other trace-window tests, it unsets `APS5_TRACE_SECONDS` and `APS5_TRACE_SUMMARY_EVERY`. - `docs/dev/BUILD.md`, Performance trace: what a present is in a replay. A replay's trace differs from a title's in three ways: - A present is counted when the driver reports the flip ready, on the thread that reports it: the queue worker running the submission, or the submitting thread for a CPU flip the driver completes at once. That thread formats the trace when the window closes, and there are no `Driver.Present` slices. - `resolution` comes from the capture, not from a video output. - `gpu_busy_ms_per_present` is 0, because that time is counted as presentations retire. The `gpu` track has the GPU time. As in a title run, a window that is still open at the end writes nothing, so a frame window needs more than `<start>` + `<count>` replayed flips. This is not the in-flight-depth change discussed on #12568, which stays a separate PR stacked on #12568. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Windows 11 26200, AMD Radeon RX 6700 XT (gfx1031), driver 32.0.21045.16010, Ryzen 5 5600X, WinLibs GCC 15.2.0 r7, Release. **This head `fcdddc9899`** is `373b38a1ec` with `main` `b11c7bf84f` merged in, and the merge had no conflicts. The lines `git diff b11c7bf84f fcdddc9899` adds and removes are exactly those of `373b38a1ec`'s own patch. Full builds of both trees, with submodules at their pins: | Tree | `frame_(replay\|capture)` tests passed, 3 runs | Skipped | `VUID-` lines | Missing-layer message | |---|---|---|---|---| | `main` `b11c7bf84f` | 14/14, 14/14, 14/14 | 0 | 0 | none | | `fcdddc9899` | 15/15, 15/15, 15/15 | 0 | 0 | none | The one extra row is `agc_driver_frame_replay_trace_window`. Red on `main` `b11c7bf84f`: I put `main`'s copies of `Execution/include/Driver.hpp`, `Execution/include/Driver/Driver.hpp`, `Execution/src/Driver/EntryPoints.cpp`, `Execution/src/Driver/Presentation.cpp` and `tools/FrameReplay.cpp` into `fcdddc9899`, keeping this PR's test and registration. `agc_driver_frame_replay_trace_window` then failed in 3 of 3 runs with `replayed frames did not open and close the trace window`. **Earlier revisions.** `373b38a1ec` was rebased onto `main` `dc9dc7eaae` for #12862's split of the test registration, with the same patch otherwise. It passed 12/12 in each of 3 runs, with 0 `VUID-` lines; `main` was not rerun for it. The previous head `0de943f892` on `main` `50843f45d9`: | Tree | `frame_(replay\|capture)` tests passed, 3 runs | `VUID-` lines | Missing-layer message | |---|---|---|---| | `main` `50843f45d9` | 11/11, 11/11, 11/11 | 0 | none | | `0de943f892` | 12/12, 12/12, 12/12 | 0 | none | All arms ran `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer ctest --test-dir build -R "frame_(replay|capture)" -V`. Neither log has a layer insertion line, because none of these tests creates a Vulkan instance. - Red on `main` `50843f45d9` (head `0de943f892`): with `main`'s `Execution/include/Driver.hpp`, `Execution/include/Driver/Driver.hpp`, `Execution/src/Driver/EntryPoints.cpp`, `Execution/src/Driver/Presentation.cpp` and `tools/FrameReplay.cpp`, and this PR's test and registration, `agc_driver_frame_replay_trace_window` failed in 3 of 3 runs with `replayed frames did not open and close the trace window`. With this PR it passed in 3 of 3. - A title, on the earlier revision `dc8621f997` (the same production code at other insertion points, on `main` `50843f45d9`): four replays of a 20-frame capture of PPSA05110 with `APS5_TRACE_FRAMES=2:16` each printed `[trace] recording frames 2:16 from present 2` and `[trace] closed at present 18, writing aps5-trace-dc8621f99705-<pid>.json.gz ...`, wrote the trace and its summary line (`"resolution":"3840x2160"`, `"gpu":"AMD Radeon RX 6700 XT"`, `"presents":16`, `"gpu_busy_ms_per_present":0.000`, `"trace_dropped":false`) and exited 0. A fifth was stopped at the tool's `pacing gave up` message before its window opened. `tools/trace_digest.py` reads the first trace (rows for `title`, `queue worker 0x0`, `draw committer` and `gpu`). In the three replays that ran without a build beside them, the replay's JSON interval ending at the closing flip was 406, 444 and 393 ms against medians of 195, 199 and 194 ms. Over the window, the JSON intervals add up to 192-252 ms more than the trace's window: that is about the time spent formatting 9.6-10.3 MB of trace JSON at the close, which the trace's own frame times leave out. - Linux, WSL2 Ubuntu 24.04 (kernel 5.15), lavapipe (Mesa 25.2.8), GCC 13, Release build of `0de943f892` from an archive with submodules at their pins: `agc_driver_frame_replay_trace_window` passed 6 of 6 (3 runs with the default import path, 3 with `APS5_WRITE_WATCH_IMPORTS=unwatch`). The capture-based tests in the set could not run there: this kernel has no asynchronous userfaultfd write protection, so the guest write watch is unavailable and `agc_driver_frame_capture_eop` stops with `the guest write watch is unavailable`; the `linux` CI job covers them. - Not tested: macOS (no CI job builds the driver there), other GPUs, and #11435's `--repeat` together with this change. ### Overlap - No merge order is needed. `373b38a1ec` merged without conflicts with the current heads of #12318 (`d3faa75d4a`), #12565 (`f360a4575c`), #12567 (`1126a888d9`), #12568 (`0e3d922b76`) and #12696 (`9f770fd8d1`). #11435 (`9392228b5c`), #11436 (`752958c135`) and #12871 (`ca858917b0`) conflict only with `main`'s split of `libSceAgcDriver/CMakeLists.txt`, not with this PR's files. - #14137 (mine) adds an include and test modes at the same two places of `tests/FrameReplayState.cpp`; whichever lands second keeps both. - #11435 adds `--repeat`, which replays the capture several times in one process and reports every pass's flips to the same `Frames`. With both PRs, every pass's flips count as presents, so a window can include the warm-up pass and the memory restore before each later pass. With F flips per pass, a frame window inside one later pass (`<start>` ≥ F and (`<start>` mod F) + `<count>` < F) leaves both out. I can add that to `BUILD.md` once #11435 has merged. - #11436's `APS5_TRACE_GPU` and `--trace-serials` print submission serials on stderr and do not start the performance trace, so this PR complements them. - #12696 relaunches the replay in a child process before replaying anything. The child inherits the trace switches and writes the trace; its summary `env` also lists `APS5_FRAME_REPLAY_ATTEMPT`. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: AMD Radeon RX 6700 XT, driver 32.0.21045.16010, Windows 11 26200; lavapipe (llvmpipe, Mesa 25.2.8), WSL2 Ubuntu 24.04 <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes (Claude Code) <!-- yes / no --> 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-10-31 14:52:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-31T14:52:49Z.

Review: APPROVED


Reviewed — looks good

The exact head 0de943f8926ac967416209424b5122e72ddd42e3 counts replayed flips when the driver reports them ready and includes a focused trace-window regression test.

Locally, git diff --check and the repository convention check passed; the no-build precheck also confirmed a clean merge preview and unchanged head/base. Its ABI and test-quality helper steps could not run because those private local helper scripts are absent from the PR checkout, so those are unavailable checks rather than source failures. The hosted Windows job built and passed agc_driver_frame_replay_trace_window (run). The author reports the replay-window test passing 6/6 on WSL/Linux; I did not run that test locally. No local build or macOS test was run.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5723398537 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/13984#pullrequestreview-5723398537). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-31T14:52:49Z. **Review:** APPROVED --- # Reviewed — looks good The exact head `0de943f8926ac967416209424b5122e72ddd42e3` counts replayed flips when the driver reports them ready and includes a focused trace-window regression test. Locally, `git diff --check` and the repository convention check passed; the no-build precheck also confirmed a clean merge preview and unchanged head/base. Its ABI and test-quality helper steps could not run because those private local helper scripts are absent from the PR checkout, so those are unavailable checks rather than source failures. The hosted Windows job built and passed `agc_driver_frame_replay_trace_window` ([run](https://github.com/boykopovar/AnyPS5/actions/runs/41210266564/job/124563635082)). The author reports the replay-window test passing 6/6 on WSL/Linux; I did not run that test locally. No local build or macOS test was run.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!13984
No description provided.