fix(agc): move periodic profiling writes off GPU workers #798

Merged
nicolasabosch merged 2 commits from upstream-pr/798 into main 2026-10-06 03:33:37 +00:00
nicolasabosch commented 2026-10-06 02:44:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by nicolasabosch on 2026-10-06T02:44:51Z.


What

Periodic AGC profiling reports currently write to stderr on GPU queue and presentation threads, sometimes while holding GuestMemory::GpuMutex. With APS5_PROFILE_DRAW=1, a slow diagnostic destination can delay submitting otherwise ready GPU work.

Format and copy periodic profiling output into a bounded 4 MiB queue and write it from a separate thread. The writer batches output, drains accepted chunks on shutdown, propagates write failures, and explicitly reports dropped chunks if the destination falls behind. The capacity includes in-flight output. Existing report formats and profiling switches are retained; error and assertion reporting remains synchronous.

Tested

  • Windows 11, MinGW, NVIDIA RTX 4070. Libraries and relinker built successfully.
  • GitHub Actions: 343/343 CTest cases passed on both Linux and Windows with --repeat until-fail:3; all three PR checks passed.
  • 10 distinct focused CTest cases passed: agc_profile_output, agc_register_command_tests, agc_shader_disk_cache, agc_write_tracking, agc_driver, agc_driver_pm4, agc_driver_graphics, agc_driver_flat_store, agc_driver_image_store_packed, agc_driver_lds_atomics.
  • The new writer test covers formatting, shutdown drain, concurrent producers, a deliberately blocked destination, bounded overflow including in-flight output, and failure propagation. It also passed 10 consecutive repetitions before the final integration checks.
  • DOOM Shareware homebrew PPSA99666 01.001.000 was tested in a separate local integration with #683, #684, #685 and #553. These are game prerequisites, not dependencies of this PR.
  • In an earlier controlled prototype experiment using the same instrumented binary, two 25-second synchronous-output runs had maximum late dispatch durations of 282.883 / 333.904 ms; deferring diagnostic output reduced them to 33.863 / 29.935 ms. Individual synchronous writes took up to 106.917 ms. This established the logging-induced CPU stall; it is not an FPS benchmark.
  • Final implementation: a 30-second empty-cache run, a 60-second warm-cache run, and a 45-second warm-cache trace run completed without frame timeouts, CPU scaler fallback or dropped profiling chunks. The traced run contained 1,840 dispatch-to-next-packet intervals after the first two seconds: maximum 0.711 ms, p99 0.577 ms. This interval is a CPU packet-trace observation, not GPU execution time.
  • A further interactive run reached E1M1 and accepted firing input while still using GPU presentation. Fresh screenshots were captured outside the source repository.

Known limits: another interactive run still timed out at frame 112 and switched to the CPU scaler. This PR removes measured diagnostic-output stalls, but does not claim to resolve every frame timeout, improve FPS, or eliminate Vulkan instance/device initialization cost. A pre-existing UCRT invalid-parameter diagnostic also occurs during startup and remains unchanged.

Checklist

  • Based on current main (b10f5701); no other open PR implements the same change
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw; no silent stubs added
  • No notes, investigation files or images added to the repository
  • No new third-party code
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

In-game screenshots

Fresh captures from the final implementation in the separate DOOM integration. The interactive session ran for 213 seconds, completed more than 7,400 dispatches and reported no frame timeouts, CPU fallback or dropped profiling chunks.

E1M1

Firing in E1M1

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4753432874 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/798). Originally posted by [nicolasabosch](https://github.com/nicolasabosch) on 2026-10-06T02:44:51Z. --- ### What Periodic AGC profiling reports currently write to `stderr` on GPU queue and presentation threads, sometimes while holding `GuestMemory::GpuMutex`. With `APS5_PROFILE_DRAW=1`, a slow diagnostic destination can delay submitting otherwise ready GPU work. Format and copy periodic profiling output into a bounded 4 MiB queue and write it from a separate thread. The writer batches output, drains accepted chunks on shutdown, propagates write failures, and explicitly reports dropped chunks if the destination falls behind. The capacity includes in-flight output. Existing report formats and profiling switches are retained; error and assertion reporting remains synchronous. ### Tested - Windows 11, MinGW, NVIDIA RTX 4070. Libraries and relinker built successfully. - GitHub Actions: 343/343 CTest cases passed on both Linux and Windows with `--repeat until-fail:3`; all three PR checks passed. - 10 distinct focused CTest cases passed: `agc_profile_output`, `agc_register_command_tests`, `agc_shader_disk_cache`, `agc_write_tracking`, `agc_driver`, `agc_driver_pm4`, `agc_driver_graphics`, `agc_driver_flat_store`, `agc_driver_image_store_packed`, `agc_driver_lds_atomics`. - The new writer test covers formatting, shutdown drain, concurrent producers, a deliberately blocked destination, bounded overflow including in-flight output, and failure propagation. It also passed 10 consecutive repetitions before the final integration checks. - DOOM Shareware homebrew PPSA99666 01.001.000 was tested in a separate local integration with #683, #684, #685 and #553. These are game prerequisites, not dependencies of this PR. - In an earlier controlled prototype experiment using the same instrumented binary, two 25-second synchronous-output runs had maximum late dispatch durations of 282.883 / 333.904 ms; deferring diagnostic output reduced them to 33.863 / 29.935 ms. Individual synchronous writes took up to 106.917 ms. This established the logging-induced CPU stall; it is not an FPS benchmark. - Final implementation: a 30-second empty-cache run, a 60-second warm-cache run, and a 45-second warm-cache trace run completed without frame timeouts, CPU scaler fallback or dropped profiling chunks. The traced run contained 1,840 dispatch-to-next-packet intervals after the first two seconds: maximum 0.711 ms, p99 0.577 ms. This interval is a CPU packet-trace observation, not GPU execution time. - A further interactive run reached E1M1 and accepted firing input while still using GPU presentation. Fresh screenshots were captured outside the source repository. Known limits: another interactive run still timed out at frame 112 and switched to the CPU scaler. This PR removes measured diagnostic-output stalls, but does not claim to resolve every frame timeout, improve FPS, or eliminate Vulkan instance/device initialization cost. A pre-existing UCRT invalid-parameter diagnostic also occurs during startup and remains unchanged. ### Checklist - [x] Based on current `main` (`b10f5701`); no other open PR implements the same change - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw; no silent stubs added - [x] No notes, investigation files or images added to the repository - [x] No new third-party code - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes ### In-game screenshots Fresh captures from the final implementation in the separate DOOM integration. The interactive session ran for 213 seconds, completed more than 7,400 dispatches and reported no frame timeouts, CPU fallback or dropped profiling chunks. ![E1M1](https://github.com/user-attachments/assets/dfa30551-ad2b-4bb7-8c6c-e62b21ffb356) ![Firing in E1M1](https://github.com/user-attachments/assets/a1cd9d4f-0028-456d-92dd-df861ce73d4f)
github-actions[bot] commented 2026-10-06 03:28:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-06T03:28:22Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#494 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawCacheStatistics.cpp L0-1, L15-17
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6008732679 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/798#issuecomment-6008732679). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-06T03:28:22Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #494 | `core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawCacheStatistics.cpp` [L0-1](https://github.com/boykopovar/AnyPS5/blob/aff8dfb3f3ae4396985c9815ac11d238916add88/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawCacheStatistics.cpp#L0-L1), [L15-17](https://github.com/boykopovar/AnyPS5/blob/aff8dfb3f3ae4396985c9815ac11d238916add88/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawCacheStatistics.cpp#L15-L17) | | |
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!798
No description provided.