perf(agc): skip an address space's pending CPU write scan when none are pending #8895

Merged
teepean merged 1 commit from upstream-pr/8895 into main 2026-10-23 22:19:55 +00:00
teepean commented 2026-10-21 04:59:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by teepean on 2026-10-21T04:59:23Z.


What

An address-based build that reuses the cached address space runs GuestBufferMemory::completeSpaceWrites in UploadFinish. It copies every pending write range of the open and in-flight batches (Recorder::PendingWriteRanges), searches each in the space's sorted regions (OverlappedRanges), sorts and deduplicates the hits, and asks CompletePendingCpuWrites about each overlapped region. That call returns false at once when no copied writer (the context's or DrawCopiedWriters) and no completion label is pending, so in that case the scan finds nothing, however many pending writes and regions there are.

The scan now starts only when one of them is pending: AnyPendingCpuWrites (new, next to CompletePendingCpuWrites) makes the same test, once per build. When something is pending, the scan runs as before. Nothing else changes: the loop's only other work is the search, which records nothing.

On Stray (PPSA02100) every address-based build in gameplay skipped it (18,758 of 18,758 per 10 s in a profiled run of my stack, where I timed the scan). On that stack, where the draw committer bounds the frame, OverlappedRanges under completeSpaceWrites was about 5 % of the committer's samples, and this change, with a one-line early return for an empty map elsewhere, was worth +2.4 % FPS there (16.57 to 16.98, four balanced rounds, all four won).

Tested

Linux (CachyOS, kernel 7.2.10, scx_lavd), Ryzen 9 9950X, RTX 3090 (NVIDIA 615.78.08), GCC 16.2.1, Release.

  • With VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, ANYPS5_REQUIRE_VULKAN=1 and ANYPS5_NO_SHADER_CACHE=1, these pass with no VUIDs: agc_driver_bda_device_tests, agc_driver_bda_span_reads_tests, agc_driver_bda_anchor_reads_tests, agc_driver_copied_writer_copy_tests, agc_driver_address_passes_tests and agc_host_import_retire_tests. No test is added: with nothing pending the scan found nothing, so the change has no other effect.
  • tools/check_conventions.py --base origin/main passes. tools/pr_overlap.py --branch finds no overlap. Of the pull requests it could not compare (they conflict with main), none changes completeSpaceWrites or CompletePendingCpuWrites; #6340 adds calls to the latter.

Stray at the start of Dead City, stock engine.ini, glibc, one run at a time, four rounds of main 7e95bde794 and this change in alternating order, with only APS5_TRACE_SECONDS=185:20 set:

round main 7e95bde794 this change
1 (main first) 160.7 / 51.0 / 47.0 167.6 / 53.5 / 48.3
2 172.3 / 55.1 / 48.6 166.2 / 54.3 / 47.6
3 (main first) 170.2 / 54.1 / 48.5 169.3 / 52.5 / 48.5
4 left out 167.1 / 52.6 / 46.8
mean 167.7 / 53.4 / 48.0 167.6 / 53.2 / 47.8

Each cell is frame p50 / GPU busy per present / the draw committer's busy time per frame, in ms, from tools/trace_digest.py. Round 4's main run stayed at 1.0 FPS for its whole window (frame p50 962 ms, the committer 83 % busy). That state is not from this change: it shows up on plain main now and then, and a run of another candidate fell into it the same night.

On main, Stray in this scene is bound by queue worker 0 (97-98 % busy), and the committer is busy about 48 ms of a ~168 ms frame. So the change can't show in the frame time here, and the committer's time stays within the spread between runs. It pays where the committer bounds the frame.

Traces, summaries and digests: https://github.com/teepean/AnyPS5/releases/tag/perf-space-scan-skip-20261021 (every run's aps5-summary.jsonl and digest.md, and three traces: one run of each build close to the means and the 1.0 FPS main run).

Summary lines of two runs close to the means

main 7e95bde794:

{"commit":"7e95bde794ae","dirty":false,"env":{"APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"185:20"},"gpu":"NVIDIA GeForce RTX 3090","driver":"NVIDIA 615.78.08","os":"Linux 7.2.10-1-cachyos","cpu":"AMD Ryzen 9 9950X 16-Core Processor","cpu_threads":32,"memory_mib":126359,"title_id":"PPSA02100","title":"Stray","content_version":"01.005.000","resolution":"3840x2160","window":{"spec":"seconds 185:20","first_present":3701,"ms":20058.075},"presents":118,"frame_ms":{"p50":170.239,"p90":206.277,"p99":215.829,"max":217.136},"gpu_busy_ms_per_present":54.079,"worker_busy_pct":{"queue worker 0x0":97.778,"queue worker 0x20":99.108},"top_phases_ms_per_frame":{"Driver.Packet":334.067,"Driver.Packet.memory_wait":167.935,"Driver.Packet.draw":103.553,"Driver.Draw":102.862,"Graphics.Draw":79.050,"Graphics.Draw.draw_and_resource_release":68.216,"Driver.Draw.shader_compile_and_link":67.746,"Shader.DrawStage":59.254},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":4.566,"events_lost":858901,"totals_full":false},"draw committer":{"events_full_after_s":19.473,"events_lost":6528,"totals_full":false}},"trace":"aps5-trace-7e95bde794ae-1135647.json.gz"}

this change:

{"commit":"b456725205d5","dirty":false,"env":{"APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"185:20"},"gpu":"NVIDIA GeForce RTX 3090","driver":"NVIDIA 615.78.08","os":"Linux 7.2.10-1-cachyos","cpu":"AMD Ryzen 9 9950X 16-Core Processor","cpu_threads":32,"memory_mib":126359,"title_id":"PPSA02100","title":"Stray","content_version":"01.005.000","resolution":"3840x2160","window":{"spec":"seconds 185:20","first_present":3218,"ms":20054.928},"presents":119,"frame_ms":{"p50":167.634,"p90":208.628,"p99":217.732,"max":219.686},"gpu_busy_ms_per_present":53.476,"worker_busy_pct":{"queue worker 0x0":97.671,"queue worker 0x20":99.126},"top_phases_ms_per_frame":{"Driver.Packet":331.092,"Driver.Packet.memory_wait":166.586,"Driver.Packet.draw":103.086,"Driver.Draw":102.371,"Graphics.Draw":78.746,"Driver.Draw.shader_compile_and_link":68.682,"Graphics.Draw.draw_and_resource_release":68.170,"Shader.DrawStage":59.799},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":4.692,"events_lost":861279,"totals_full":false},"draw committer":{"events_full_after_s":20.010,"events_lost":842,"totals_full":false}},"trace":"aps5-trace-b456725205d5-1110475.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 (performance of PPSA02100, #2461)
  • GPUs tested: NVIDIA GeForce RTX 3090, driver 615.78.08, Linux (CachyOS, kernel 7.2.10)
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4946636130 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8895). Originally posted by [teepean](https://github.com/teepean) on 2026-10-21T04:59:23Z. --- ### What An address-based build that reuses the cached address space runs `GuestBufferMemory::completeSpaceWrites` in `UploadFinish`. It copies every pending write range of the open and in-flight batches (`Recorder::PendingWriteRanges`), searches each in the space's sorted regions (`OverlappedRanges`), sorts and deduplicates the hits, and asks `CompletePendingCpuWrites` about each overlapped region. That call returns false at once when no copied writer (the context's or `DrawCopiedWriters`) and no completion label is pending, so in that case the scan finds nothing, however many pending writes and regions there are. The scan now starts only when one of them is pending: `AnyPendingCpuWrites` (new, next to `CompletePendingCpuWrites`) makes the same test, once per build. When something is pending, the scan runs as before. Nothing else changes: the loop's only other work is the search, which records nothing. On Stray (PPSA02100) every address-based build in gameplay skipped it (18,758 of 18,758 per 10 s in a profiled run of my stack, where I timed the scan). On that stack, where the draw committer bounds the frame, `OverlappedRanges` under `completeSpaceWrites` was about 5 % of the committer's samples, and this change, with a one-line early return for an empty map elsewhere, was worth +2.4 % FPS there (16.57 to 16.98, four balanced rounds, all four won). ### Tested Linux (CachyOS, kernel 7.2.10, scx_lavd), Ryzen 9 9950X, RTX 3090 (NVIDIA 615.78.08), GCC 16.2.1, Release. - With `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, `ANYPS5_REQUIRE_VULKAN=1` and `ANYPS5_NO_SHADER_CACHE=1`, these pass with no VUIDs: `agc_driver_bda_device_tests`, `agc_driver_bda_span_reads_tests`, `agc_driver_bda_anchor_reads_tests`, `agc_driver_copied_writer_copy_tests`, `agc_driver_address_passes_tests` and `agc_host_import_retire_tests`. No test is added: with nothing pending the scan found nothing, so the change has no other effect. - `tools/check_conventions.py --base origin/main` passes. `tools/pr_overlap.py --branch` finds no overlap. Of the pull requests it could not compare (they conflict with `main`), none changes `completeSpaceWrites` or `CompletePendingCpuWrites`; #6340 adds calls to the latter. Stray at the start of Dead City, stock `engine.ini`, glibc, one run at a time, four rounds of `main` 7e95bde794 and this change in alternating order, with only `APS5_TRACE_SECONDS=185:20` set: | round | `main` 7e95bde794 | this change | |---|---|---| | 1 (`main` first) | 160.7 / 51.0 / 47.0 | 167.6 / 53.5 / 48.3 | | 2 | 172.3 / 55.1 / 48.6 | 166.2 / 54.3 / 47.6 | | 3 (`main` first) | 170.2 / 54.1 / 48.5 | 169.3 / 52.5 / 48.5 | | 4 | left out | 167.1 / 52.6 / 46.8 | | mean | 167.7 / 53.4 / 48.0 | 167.6 / 53.2 / 47.8 | Each cell is frame p50 / GPU busy per present / the draw committer's busy time per frame, in ms, from `tools/trace_digest.py`. Round 4's `main` run stayed at 1.0 FPS for its whole window (frame p50 962 ms, the committer 83 % busy). That state is not from this change: it shows up on plain `main` now and then, and a run of another candidate fell into it the same night. On `main`, Stray in this scene is bound by queue worker 0 (97-98 % busy), and the committer is busy about 48 ms of a ~168 ms frame. So the change can't show in the frame time here, and the committer's time stays within the spread between runs. It pays where the committer bounds the frame. Traces, summaries and digests: https://github.com/teepean/AnyPS5/releases/tag/perf-space-scan-skip-20261021 (every run's `aps5-summary.jsonl` and `digest.md`, and three traces: one run of each build close to the means and the 1.0 FPS `main` run). <details> <summary>Summary lines of two runs close to the means</summary> `main` 7e95bde794: ```json {"commit":"7e95bde794ae","dirty":false,"env":{"APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"185:20"},"gpu":"NVIDIA GeForce RTX 3090","driver":"NVIDIA 615.78.08","os":"Linux 7.2.10-1-cachyos","cpu":"AMD Ryzen 9 9950X 16-Core Processor","cpu_threads":32,"memory_mib":126359,"title_id":"PPSA02100","title":"Stray","content_version":"01.005.000","resolution":"3840x2160","window":{"spec":"seconds 185:20","first_present":3701,"ms":20058.075},"presents":118,"frame_ms":{"p50":170.239,"p90":206.277,"p99":215.829,"max":217.136},"gpu_busy_ms_per_present":54.079,"worker_busy_pct":{"queue worker 0x0":97.778,"queue worker 0x20":99.108},"top_phases_ms_per_frame":{"Driver.Packet":334.067,"Driver.Packet.memory_wait":167.935,"Driver.Packet.draw":103.553,"Driver.Draw":102.862,"Graphics.Draw":79.050,"Graphics.Draw.draw_and_resource_release":68.216,"Driver.Draw.shader_compile_and_link":67.746,"Shader.DrawStage":59.254},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":4.566,"events_lost":858901,"totals_full":false},"draw committer":{"events_full_after_s":19.473,"events_lost":6528,"totals_full":false}},"trace":"aps5-trace-7e95bde794ae-1135647.json.gz"} ``` this change: ```json {"commit":"b456725205d5","dirty":false,"env":{"APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"185:20"},"gpu":"NVIDIA GeForce RTX 3090","driver":"NVIDIA 615.78.08","os":"Linux 7.2.10-1-cachyos","cpu":"AMD Ryzen 9 9950X 16-Core Processor","cpu_threads":32,"memory_mib":126359,"title_id":"PPSA02100","title":"Stray","content_version":"01.005.000","resolution":"3840x2160","window":{"spec":"seconds 185:20","first_present":3218,"ms":20054.928},"presents":119,"frame_ms":{"p50":167.634,"p90":208.628,"p99":217.732,"max":219.686},"gpu_busy_ms_per_present":53.476,"worker_busy_pct":{"queue worker 0x0":97.671,"queue worker 0x20":99.126},"top_phases_ms_per_frame":{"Driver.Packet":331.092,"Driver.Packet.memory_wait":166.586,"Driver.Packet.draw":103.086,"Driver.Draw":102.371,"Graphics.Draw":78.746,"Driver.Draw.shader_compile_and_link":68.682,"Graphics.Draw.draw_and_resource_release":68.170,"Shader.DrawStage":59.799},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":4.692,"events_lost":861279,"totals_full":false},"draw committer":{"events_full_after_s":20.010,"events_lost":842,"totals_full":false}},"trace":"aps5-trace-b456725205d5-1110475.json.gz"} ``` </details> ### Checklist - [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 (performance of PPSA02100, #2461) - [x] GPUs tested: NVIDIA GeForce RTX 3090, driver 615.78.08, Linux (CachyOS, kernel 7.2.10) - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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!8895
No description provided.