fix(agc): stop draining for GPU-clock COPY_DATA #7963

Merged
MuteRex merged 3 commits from upstream-pr/7963 into main 2026-11-14 03:25:06 +00:00
MuteRex commented 2026-10-19 16:18:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MuteRex on 2026-10-19T16:18:11Z.


What

A COPY_DATA (0x40) whose source is the GPU clock (source 18) drained work it never depended on:

  • In keepsDrawPipeline it was not a keeping opcode, so every one drained the pipelined draw queue. It now keeps the pipeline unless its destination overlaps a pending range, in which case it still drains.
  • In PacketMemory, a clock copy into memory that is not imported while the recorder was busy (reason 3) drained the whole device before the store. It is now stored on the CPU, as with an idle recorder, unless the device has a store pending over the destination.

The clock value is read when the packet runs, before either drain, so the drains only stalled the queue. PPSA16833 issues these copies every frame for GPU timing.

Tested

Linux 7.0, AMD Radeon RX 9060 XT (RADV, Mesa 26.0.8).

  • New agc_driver case testGpuClockCopyBehindGpuWork: a 128 KiB GPU copy followed by two clock copies into host memory. It checks the copy landed, the clocks increase, no device drain happened, and both stores went to the CPU. It fails on main with "a GPU-clock COPY_DATA into host memory behind GPU work drained the device".
  • New agc_driver_pipelined_clock_copy: with APS5_PIPELINED_DRAWS=1 and the pipeline held over a pending range, it checks that clock copies elsewhere do not drain it and that a clock copy onto the held range still drains once. It fails on main with "a GPU-clock COPY_DATA off the pending range drained the pipeline".
  • Both passed 30/30 and 10/10 repeated runs.
  • VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 ctest --test-dir build -R '^(agc_driver|agc_driver_pipelined_clock_copy|agc_driver_pipelined_dma|agc_driver_pm4)$' -V:
    • change: 4/4 pass;
    • main: the two new tests fail;
    • both logs: no was not found but was requested by env var VK_INSTANCE_LAYERS, and no VUID- messages.
  • Full ctest: all pass except agc_driver_image_table_vouched_lookups and agc_driver_guest_memory_lifetime, which fail the same way on main.

Performance, PPSA16833 (LEGO Batman: Legacy of the Dark Knight) main menu, 3840x2160, warm caches, APS5_TRACE_SECONDS=180:30, same machine and session. Traces attached.

main this PR
presents 112 113
frame p50 / p90 / p99 / max (ms) 267.9 / 275.2 / 295.4 / 302.9 265.1 / 270.9 / 287.0 / 289.1
GPU busy per present (ms) 113.7 113.2
queue worker 0x0 busy / wait (ms per frame) 262.3 / 5.7 177.7 / 86.7
Driver.Packet.device_lock (ms per frame) 173.9 not in the top phases

Frame time at this scene is unchanged within noise. The queue worker that ran the clock copies spends about 85 ms less per frame busy, mostly the removed device drain. The frame here is bound elsewhere: the second queue worker waits in Driver.Packet.memory_wait and the draw committer in Recorder.Sync. Both builds carry the same local window-placement change, which is why the summaries say dirty. 315f1a99fd4b is this change on c017549dc; this PR's commit is the same change rebased onto 10 later commits of main, none of which touches libSceAgcDriver. The main capture reverted the two driver files to main.

main:

{"commit":"315f1a99fd4b","dirty":true,"env":{"APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"180:30"},"gpu":"AMD Radeon RX 9060 XT (RADV GFX1200)","driver":"radv Mesa 26.0.8-1ubuntu0.3","os":"Linux 7.0.0-38-generic","resolution":"3840x2160","window":{"spec":"seconds 180:30","first_present":1436,"ms":30161.106},"presents":112,"frame_ms":{"p50":267.922,"p90":275.207,"p99":295.449,"max":302.908},"gpu_busy_ms_per_present":113.678,"worker_busy_pct":{"queue worker 0x0":99.881,"queue worker 0x20":96.099},"top_phases_ms_per_frame":{"Driver.Packet":527.219,"Driver.Packet.memory_wait":224.507,"Driver.Packet.device_lock":173.858,"Recorder.Sync":128.804,"Resources.Complete":107.409,"Driver.Packet.dispatch":94.176,"Driver.Dispatch":93.408,"Vulkan.Dispatch":83.002},"trace_dropped":false,"trace":"aps5-trace-315f1a99fd4b-1113523.json.gz"}

this PR:

{"commit":"315f1a99fd4b","dirty":true,"env":{"APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"180:30"},"gpu":"AMD Radeon RX 9060 XT (RADV GFX1200)","driver":"radv Mesa 26.0.8-1ubuntu0.3","os":"Linux 7.0.0-38-generic","resolution":"3840x2160","window":{"spec":"seconds 180:30","first_present":733,"ms":30039.493},"presents":113,"frame_ms":{"p50":265.1,"p90":270.88,"p99":287.004,"max":289.107},"gpu_busy_ms_per_present":113.241,"worker_busy_pct":{"queue worker 0x0":99.897,"queue worker 0x20":97.04},"top_phases_ms_per_frame":{"Driver.Packet":523.113,"Driver.Packet.memory_wait":223.019,"Driver.Packet.dispatch":182.407,"Recorder.Sync":128.071,"Driver.Dispatch":124.245,"Resources.Complete":106.868,"GpuMutex.wait.label":106.481,"Driver.Packet.prepare_memory":106.471},"trace_dropped":false,"trace":"aps5-trace-315f1a99fd4b-1118384.json.gz"}

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 9060 XT, RADV (Mesa 26.0.8), Linux 7.0.0-38
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4923970040 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7963). Originally posted by [MuteRex](https://github.com/MuteRex) on 2026-10-19T16:18:11Z. --- ### What A `COPY_DATA` (0x40) whose source is the GPU clock (source 18) drained work it never depended on: - In `keepsDrawPipeline` it was not a keeping opcode, so every one drained the pipelined draw queue. It now keeps the pipeline unless its destination overlaps a pending range, in which case it still drains. - In `PacketMemory`, a clock copy into memory that is not imported while the recorder was busy (reason 3) drained the whole device before the store. It is now stored on the CPU, as with an idle recorder, unless the device has a store pending over the destination. The clock value is read when the packet runs, before either drain, so the drains only stalled the queue. PPSA16833 issues these copies every frame for GPU timing. ### Tested Linux 7.0, AMD Radeon RX 9060 XT (RADV, Mesa 26.0.8). - New `agc_driver` case `testGpuClockCopyBehindGpuWork`: a 128 KiB GPU copy followed by two clock copies into host memory. It checks the copy landed, the clocks increase, no device drain happened, and both stores went to the CPU. It fails on `main` with "a GPU-clock COPY_DATA into host memory behind GPU work drained the device". - New `agc_driver_pipelined_clock_copy`: with `APS5_PIPELINED_DRAWS=1` and the pipeline held over a pending range, it checks that clock copies elsewhere do not drain it and that a clock copy onto the held range still drains once. It fails on `main` with "a GPU-clock COPY_DATA off the pending range drained the pipeline". - Both passed 30/30 and 10/10 repeated runs. - `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 ctest --test-dir build -R '^(agc_driver|agc_driver_pipelined_clock_copy|agc_driver_pipelined_dma|agc_driver_pm4)$' -V`: - change: 4/4 pass; - `main`: the two new tests fail; - both logs: no `was not found but was requested by env var VK_INSTANCE_LAYERS`, and no `VUID-` messages. - Full `ctest`: all pass except `agc_driver_image_table_vouched_lookups` and `agc_driver_guest_memory_lifetime`, which fail the same way on `main`. Performance, PPSA16833 (LEGO Batman: Legacy of the Dark Knight) main menu, 3840x2160, warm caches, `APS5_TRACE_SECONDS=180:30`, same machine and session. Traces attached. | | main | this PR | |---|---|---| | presents | 112 | 113 | | frame p50 / p90 / p99 / max (ms) | 267.9 / 275.2 / 295.4 / 302.9 | 265.1 / 270.9 / 287.0 / 289.1 | | GPU busy per present (ms) | 113.7 | 113.2 | | queue worker 0x0 busy / wait (ms per frame) | 262.3 / 5.7 | 177.7 / 86.7 | | `Driver.Packet.device_lock` (ms per frame) | 173.9 | not in the top phases | Frame time at this scene is unchanged within noise. The queue worker that ran the clock copies spends about 85 ms less per frame busy, mostly the removed device drain. The frame here is bound elsewhere: the second queue worker waits in `Driver.Packet.memory_wait` and the draw committer in `Recorder.Sync`. Both builds carry the same local window-placement change, which is why the summaries say `dirty`. `315f1a99fd4b` is this change on `c017549dc`; this PR's commit is the same change rebased onto 10 later commits of `main`, none of which touches `libSceAgcDriver`. The main capture reverted the two driver files to `main`. main: ```json {"commit":"315f1a99fd4b","dirty":true,"env":{"APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"180:30"},"gpu":"AMD Radeon RX 9060 XT (RADV GFX1200)","driver":"radv Mesa 26.0.8-1ubuntu0.3","os":"Linux 7.0.0-38-generic","resolution":"3840x2160","window":{"spec":"seconds 180:30","first_present":1436,"ms":30161.106},"presents":112,"frame_ms":{"p50":267.922,"p90":275.207,"p99":295.449,"max":302.908},"gpu_busy_ms_per_present":113.678,"worker_busy_pct":{"queue worker 0x0":99.881,"queue worker 0x20":96.099},"top_phases_ms_per_frame":{"Driver.Packet":527.219,"Driver.Packet.memory_wait":224.507,"Driver.Packet.device_lock":173.858,"Recorder.Sync":128.804,"Resources.Complete":107.409,"Driver.Packet.dispatch":94.176,"Driver.Dispatch":93.408,"Vulkan.Dispatch":83.002},"trace_dropped":false,"trace":"aps5-trace-315f1a99fd4b-1113523.json.gz"} ``` this PR: ```json {"commit":"315f1a99fd4b","dirty":true,"env":{"APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"180:30"},"gpu":"AMD Radeon RX 9060 XT (RADV GFX1200)","driver":"radv Mesa 26.0.8-1ubuntu0.3","os":"Linux 7.0.0-38-generic","resolution":"3840x2160","window":{"spec":"seconds 180:30","first_present":733,"ms":30039.493},"presents":113,"frame_ms":{"p50":265.1,"p90":270.88,"p99":287.004,"max":289.107},"gpu_busy_ms_per_present":113.241,"worker_busy_pct":{"queue worker 0x0":99.897,"queue worker 0x20":97.04},"top_phases_ms_per_frame":{"Driver.Packet":523.113,"Driver.Packet.memory_wait":223.019,"Driver.Packet.dispatch":182.407,"Recorder.Sync":128.071,"Driver.Dispatch":124.245,"Resources.Complete":106.868,"GpuMutex.wait.label":106.481,"Driver.Packet.prepare_memory":106.471},"trace_dropped":false,"trace":"aps5-trace-315f1a99fd4b-1118384.json.gz"} ``` ### 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 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: AMD Radeon RX 9060 XT, RADV (Mesa 26.0.8), Linux 7.0.0-38 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MuteRex commented 2026-10-19 16:22:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MuteRex on 2026-10-19T16:22:43Z.


pr7963-traces.zip

Traces for the summary lines above: main-aps5-trace-315f1a99fd4b-1113523.json.gz is main, fix-aps5-trace-315f1a99fd4b-1118384.json.gz is this PR (GitHub does not accept .gz attachments, so both are in the zip).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6271907692 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7963#issuecomment-6271907692). Originally posted by [MuteRex](https://github.com/MuteRex) on 2026-10-19T16:22:43Z. --- [pr7963-traces.zip](https://github.com/user-attachments/files/33675347/pr7963-traces.zip) Traces for the summary lines above: `main-aps5-trace-315f1a99fd4b-1113523.json.gz` is main, `fix-aps5-trace-315f1a99fd4b-1118384.json.gz` is this PR (GitHub does not accept .gz attachments, so both are in the zip).
blawesom commented 2026-10-20 08:17:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-20T08:17:54Z.


Rebase handoff — rebased onto current main (3fd1cc393, authorship unchanged). One test-call conflict: main's testSmallCopyBehindPendingSource and your testGpuClockCopyBehindGpuWork now both run.

Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, BUILD_TESTING=ON, AMD RX 9070 XT / RADV): builds; 1673/1676 — green apart from the three known main failures (#7584 BDA, #7784 guest-memory, tessellation), none from this PR; conventions pass.

To pick it up:

git fetch https://github.com/blawesom/AnyPS5 rebase/7963
git checkout <your branch>
git merge --ff-only FETCH_HEAD

Head is a6f0732f6.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6286621007 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7963#issuecomment-6286621007). Originally posted by [blawesom](https://github.com/blawesom) on 2026-10-20T08:17:54Z. --- **Rebase handoff** — rebased onto current `main` (`3fd1cc393`, authorship unchanged). One test-call conflict: `main`'s `testSmallCopyBehindPendingSource` and your `testGpuClockCopyBehindGpuWork` now both run. Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, `BUILD_TESTING=ON`, AMD RX 9070 XT / RADV): builds; **1673/1676 — green apart from the three known `main` failures** (#7584 BDA, #7784 guest-memory, tessellation), none from this PR; conventions pass. **To pick it up:** ``` git fetch https://github.com/blawesom/AnyPS5 rebase/7963 git checkout <your branch> git merge --ff-only FETCH_HEAD ``` Head is `a6f0732f6`.
MuteRex commented 2026-10-20 17:55:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MuteRex on 2026-10-20T17:55:30Z.


Thanks @blawesom for the rebase and the test run! Picked it up: the branch is now at a6f0732f6 and the PR is mergeable again. (git merge --ff-only refused because the rebase rewrote the commit, so I force-pushed your commit instead.)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6297518471 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7963#issuecomment-6297518471). Originally posted by [MuteRex](https://github.com/MuteRex) on 2026-10-20T17:55:30Z. --- Thanks @blawesom for the rebase and the test run! Picked it up: the branch is now at `a6f0732f6` and the PR is mergeable again. (`git merge --ff-only` refused because the rebase rewrote the commit, so I force-pushed your commit instead.)
milescoviello commented 2026-10-20 19:08:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-20T19:08:37Z.


A second title with these copies: MGS4 (PPSA18194, Master Collection), in Act 1's first gameplay scene. The route is the launcher, then Game Selection, Start Game, New Game and Liquid Easy, skipping the opening cutscene. Linux 6.8, RTX 4070 Ti (595.99.02), release libs, APS5_PROFILE_DRAW=1. Each column below is the same two consecutive 10 s windows.

main 8727ddb29e + this PR (a6f0732f60)
draw pipeline packet drains 4208 / 4316 (2449 / 2543 ms) 10 / 23 (0.3 / 1.2 ms)
drains by opcode 0x40 ×4207 / ×4313, 0x15 ×1 / ×3 0x15 ×10 / ×23
commits per 10 s, cost on the committer 204110 / 209862 at 31.7 / 32.2 µs 215149 / 213434 at 28.9 / 28.8 µs
presents per 10 s 79 / 85 77 / 75

So every COPY_DATA drain in this scene is a clock copy, and this PR removes them all. As in your LEGO Batman measurement, the frame rate doesn't change. The frame is bound by per-draw CPU work: about 2,800 draws per frame at about 28 µs to record and 29 µs to commit, with the GPU busy about 31–37 ms of each frame.

One note: my first launch on this build crashed in the launcher at 23 s (EXIT-139, no message). Three more runs on the same build didn't repeat it (two 60 s runs and the long run above), and main didn't crash in four runs, so I don't think it's related.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6298993421 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7963#issuecomment-6298993421). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-20T19:08:37Z. --- A second title with these copies: MGS4 (PPSA18194, Master Collection), in Act 1's first gameplay scene. The route is the launcher, then Game Selection, Start Game, New Game and Liquid Easy, skipping the opening cutscene. Linux 6.8, RTX 4070 Ti (595.99.02), release libs, `APS5_PROFILE_DRAW=1`. Each column below is the same two consecutive 10 s windows. | | `main` 8727ddb29e | + this PR (a6f0732f60) | |---|---|---| | draw pipeline packet drains | 4208 / 4316 (2449 / 2543 ms) | 10 / 23 (0.3 / 1.2 ms) | | drains by opcode | `0x40` ×4207 / ×4313, `0x15` ×1 / ×3 | `0x15` ×10 / ×23 | | commits per 10 s, cost on the committer | 204110 / 209862 at 31.7 / 32.2 µs | 215149 / 213434 at 28.9 / 28.8 µs | | presents per 10 s | 79 / 85 | 77 / 75 | So every `COPY_DATA` drain in this scene is a clock copy, and this PR removes them all. As in your LEGO Batman measurement, the frame rate doesn't change. The frame is bound by per-draw CPU work: about 2,800 draws per frame at about 28 µs to record and 29 µs to commit, with the GPU busy about 31–37 ms of each frame. One note: my first launch on this build crashed in the launcher at 23 s (EXIT-139, no message). Three more runs on the same build didn't repeat it (two 60 s runs and the long run above), and `main` didn't crash in four runs, so I don't think it's related. AI-assisted: yes (Claude Code)
MuteRex commented 2026-10-20 20:27:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MuteRex on 2026-10-20T20:27:09Z.


Thanks @milescoviello for testing a second title! Good to see every COPY_DATA drain was a clock copy there too, and that the PR removes them on NVIDIA as well. Agreed on the frame rate: it is bound elsewhere in both games, so this PR removes overhead rather than raising FPS. Thanks also for checking the launcher crash with the extra runs.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6300741093 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7963#issuecomment-6300741093). Originally posted by [MuteRex](https://github.com/MuteRex) on 2026-10-20T20:27:09Z. --- Thanks @milescoviello for testing a second title! Good to see every `COPY_DATA` drain was a clock copy there too, and that the PR removes them on NVIDIA as well. Agreed on the frame rate: it is bound elsewhere in both games, so this PR removes overhead rather than raising FPS. Thanks also for checking the launcher crash with the extra runs.
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!7963
No description provided.