perf(agc): let a CPU buffer fill wait only for the work over its range #18829

Open
DealPotato wants to merge 1 commit from upstream-pr/18829 into main
DealPotato commented 2026-11-12 11:50:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DealPotato on 2026-11-12T11:50:18Z.


What

A buffer fill over a range that no host import covers is stored by the CPU, and that path drained the device first: WaitIdle under the GPU mutex, a recorder sync plus vkDeviceWaitIdle. WWE 2K26 (PPSA34299) issues about a dozen such fills every 10 s in a match, each one draining every queue while the GPU mutex is held.

The CPU store now waits only for the work that can conflict with it, by the rules the CPU side of the copy HLE already applies to its destination:

  • an image result, a unit shadow, a pending label or an in-place reader over the range (or any recorded work while read tracking is off) still drains the device;
  • recorded writers of the range are waited for through SyncThrough;
  • otherwise the store runs at once.

APS5_CPU_FILL_WAIT_IDLE=1 restores the drain (documented in ENVIRONMENT.md). The [fill] line of APS5_PROFILE_DRAW splits the CPU wait from the store and counts the three outcomes.

Tested

Windows 11 Pro (build 26300), NVIDIA GeForce RTX 4070, driver 610.88. Focused tests run with VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, ANYPS5_NO_SHADER_CACHE=1, ANYPS5_REQUIRE_VULKAN=1 and ctest -V on main (3b7f31fa70) and on this change, from one build directory; the loader inserted the validation layer in both runs.

Passed on main and on the change (19 tests): agc_driver_fill_completion_labels and its six variants, agc_driver_copied_writer_copy, agc_driver_pattern_buffer_fill, agc_driver_pipelined_fill (plus _draw_pipeline, _plan_verify), agc_driver_memory_value_fill, agc_driver_gds_dma_fill (plus _private), agc_driver_depth_plane_fill_discard, agc_driver_pipelined_dma (plus _draw_pipeline, _plan_verify). New on the change, passed: agc_driver_cpu_store_settle, agc_driver_cpu_store_settle_wait_idle (APS5_CPU_FILL_WAIT_IDLE=1), agc_driver_cpu_store_settle_untracked_reads (APS5_COPY_READ_TRACKING=0). No log has a VUID- message.

The new test checks each decision on a real device: no wait on an idle device, no drain beside a recorded writer of another range, a wait for a recorded writer of the range (its data lands), and a drain for a pending GPU label or a noted in-place reader; with read tracking off, recorded work drains; with the switch, everything drains.

Performance

WWE 2K26 does not reach a match on main alone; it was measured on a local branch of main (3a0a54bbd8) with #18651, #18652, #18654, #18660 and local workarounds for native multisample depth, with and without this change. Match intro, 10 s windows.

Per fill, from the APS5_PROFILE_DRAW [fill] and [commits] lines:

before after
CPU-stored fills per 10 s ~12 ~16
wait before the store full drain every time 3895 of 3896 none, 1 for the range's writer, 0 drains
GPU mutex hold of those fills per 10 s ~1.1 s ~0.16 s
fill commit on the draw committer ~9.9 ms ~1.0 ms
draw committer, us per commit ~792 ~603

APS5_TRACE_FRAMES=0:30 captures of the same build (dirty: it also held the fix that holds the settle and sparse queues across vkDeviceWaitIdle, opened separately as #18828), with APS5_CPU_FILL_WAIT_IDLE=1 (drain) and without (this change), summary lines below. The two captures did not land on the same scene: the change's run recorded about 20 % more draws on the draw committer (5017 vs 4185) and more GPU time, so its frame times are not a comparison of the change. The committer's Recorder.Sync time fell from 79 to 64 ms per present.

{"commit":"612b7139ea92","dirty":true,"env":{"APS5_CPU_FILL_WAIT_IDLE":"1","APS5_LOG_TIMESTAMPS":"1","APS5_TRACE_DIR":"<path>","APS5_TRACE_FRAMES":"0:30","APS5_TRACE_SUMMARY_EVERY":"10","APS5_TRACE_TRIGGER_FILE":"<path>"},"gpu":"NVIDIA GeForce RTX 4070","driver":"NVIDIA 610.88","os":"Windows 10.0.26300","cpu":"AMD Ryzen 5 7600X 6-Core Processor","cpu_threads":12,"memory_mib":31621,"title_id":"PPSA34299","title":"WWE 2K26","content_version":"01.018.000","resolution":"3840x2160","window":{"spec":"frames 0:30","first_present":2247,"ms":17677.170},"presents":30,"frame_ms":{"p50":591.342,"p90":633.252,"p99":685.843,"max":685.843},"gpu_busy_ms_per_present":190.193,"worker_busy_pct":{"queue worker 0x0":98.852,"queue worker 0x21":0.015,"queue worker 0x20":94.877,"queue worker 0x22":83.358},"top_phases_ms_per_frame":{"Driver.Packet":1598.296,"Driver.Packet.dispatch":608.008,"Driver.Packet.memory_wait":581.675,"Graphics.Draw":420.020,"Graphics.Draw.draw_and_resource_release":385.625,"Driver.Packet.draw":384.028,"Driver.Draw":383.878,"Resources.Complete":229.522},"owned_draw_counts":{},"trace_dropped":false,"trace":"aps5-trace-612b7139ea92-21180.json.gz"}
{"commit":"612b7139ea92","dirty":true,"env":{"APS5_LOG_TIMESTAMPS":"1","APS5_TRACE_DIR":"<path>","APS5_TRACE_FRAMES":"0:30","APS5_TRACE_SUMMARY_EVERY":"10","APS5_TRACE_TRIGGER_FILE":"<path>"},"gpu":"NVIDIA GeForce RTX 4070","driver":"NVIDIA 610.88","os":"Windows 10.0.26300","cpu":"AMD Ryzen 5 7600X 6-Core Processor","cpu_threads":12,"memory_mib":31621,"title_id":"PPSA34299","title":"WWE 2K26","content_version":"01.018.000","resolution":"3840x2160","window":{"spec":"frames 0:30","first_present":2192,"ms":23822.518},"presents":30,"frame_ms":{"p50":792.358,"p90":810.715,"p99":875.434,"max":875.434},"gpu_busy_ms_per_present":208.122,"worker_busy_pct":{"queue worker 0x0":99.096,"queue worker 0x22":86.044,"queue worker 0x21":0.010,"queue worker 0x20":91.075},"top_phases_ms_per_frame":{"Driver.Packet":2156.604,"Driver.Packet.memory_wait":1284.024,"Driver.Packet.draw":667.944,"Driver.Draw":667.767,"Graphics.Draw":637.027,"Graphics.Draw.draw_and_resource_release":601.751,"Resources.Complete":341.170,"Driver.Draw.draw_enqueued":201.892},"owned_draw_counts":{},"trace_dropped":false,"trace":"aps5-trace-612b7139ea92-15864.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 PPSA34299, WWE 2K26)
  • GPUs tested: NVIDIA GeForce RTX 4070, driver 610.88, Windows 11 Pro (build 26300)
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5276851067 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18829). Originally posted by [DealPotato](https://github.com/DealPotato) on 2026-11-12T11:50:18Z. --- ### What A buffer fill over a range that no host import covers is stored by the CPU, and that path drained the device first: `WaitIdle` under the GPU mutex, a recorder sync plus `vkDeviceWaitIdle`. WWE 2K26 (PPSA34299) issues about a dozen such fills every 10 s in a match, each one draining every queue while the GPU mutex is held. The CPU store now waits only for the work that can conflict with it, by the rules the CPU side of the copy HLE already applies to its destination: - an image result, a unit shadow, a pending label or an in-place reader over the range (or any recorded work while read tracking is off) still drains the device; - recorded writers of the range are waited for through `SyncThrough`; - otherwise the store runs at once. `APS5_CPU_FILL_WAIT_IDLE=1` restores the drain (documented in `ENVIRONMENT.md`). The `[fill]` line of `APS5_PROFILE_DRAW` splits the CPU wait from the store and counts the three outcomes. ### Tested Windows 11 Pro (build 26300), NVIDIA GeForce RTX 4070, driver 610.88. Focused tests run with `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, `ANYPS5_NO_SHADER_CACHE=1`, `ANYPS5_REQUIRE_VULKAN=1` and `ctest -V` on `main` (3b7f31fa70) and on this change, from one build directory; the loader inserted the validation layer in both runs. Passed on `main` and on the change (19 tests): `agc_driver_fill_completion_labels` and its six variants, `agc_driver_copied_writer_copy`, `agc_driver_pattern_buffer_fill`, `agc_driver_pipelined_fill` (plus `_draw_pipeline`, `_plan_verify`), `agc_driver_memory_value_fill`, `agc_driver_gds_dma_fill` (plus `_private`), `agc_driver_depth_plane_fill_discard`, `agc_driver_pipelined_dma` (plus `_draw_pipeline`, `_plan_verify`). New on the change, passed: `agc_driver_cpu_store_settle`, `agc_driver_cpu_store_settle_wait_idle` (`APS5_CPU_FILL_WAIT_IDLE=1`), `agc_driver_cpu_store_settle_untracked_reads` (`APS5_COPY_READ_TRACKING=0`). No log has a `VUID-` message. The new test checks each decision on a real device: no wait on an idle device, no drain beside a recorded writer of another range, a wait for a recorded writer of the range (its data lands), and a drain for a pending GPU label or a noted in-place reader; with read tracking off, recorded work drains; with the switch, everything drains. ### Performance WWE 2K26 does not reach a match on `main` alone; it was measured on a local branch of `main` (3a0a54bbd8) with #18651, #18652, #18654, #18660 and local workarounds for native multisample depth, with and without this change. Match intro, 10 s windows. Per fill, from the `APS5_PROFILE_DRAW` `[fill]` and `[commits]` lines: | | before | after | |---|---|---| | CPU-stored fills per 10 s | ~12 | ~16 | | wait before the store | full drain every time | 3895 of 3896 none, 1 for the range's writer, 0 drains | | GPU mutex hold of those fills per 10 s | ~1.1 s | ~0.16 s | | fill commit on the draw committer | ~9.9 ms | ~1.0 ms | | draw committer, us per commit | ~792 | ~603 | `APS5_TRACE_FRAMES=0:30` captures of the same build (`dirty`: it also held the fix that holds the settle and sparse queues across `vkDeviceWaitIdle`, opened separately as #18828), with `APS5_CPU_FILL_WAIT_IDLE=1` (drain) and without (this change), summary lines below. The two captures did not land on the same scene: the change's run recorded about 20 % more draws on the draw committer (5017 vs 4185) and more GPU time, so its frame times are not a comparison of the change. The committer's `Recorder.Sync` time fell from 79 to 64 ms per present. ``` {"commit":"612b7139ea92","dirty":true,"env":{"APS5_CPU_FILL_WAIT_IDLE":"1","APS5_LOG_TIMESTAMPS":"1","APS5_TRACE_DIR":"<path>","APS5_TRACE_FRAMES":"0:30","APS5_TRACE_SUMMARY_EVERY":"10","APS5_TRACE_TRIGGER_FILE":"<path>"},"gpu":"NVIDIA GeForce RTX 4070","driver":"NVIDIA 610.88","os":"Windows 10.0.26300","cpu":"AMD Ryzen 5 7600X 6-Core Processor","cpu_threads":12,"memory_mib":31621,"title_id":"PPSA34299","title":"WWE 2K26","content_version":"01.018.000","resolution":"3840x2160","window":{"spec":"frames 0:30","first_present":2247,"ms":17677.170},"presents":30,"frame_ms":{"p50":591.342,"p90":633.252,"p99":685.843,"max":685.843},"gpu_busy_ms_per_present":190.193,"worker_busy_pct":{"queue worker 0x0":98.852,"queue worker 0x21":0.015,"queue worker 0x20":94.877,"queue worker 0x22":83.358},"top_phases_ms_per_frame":{"Driver.Packet":1598.296,"Driver.Packet.dispatch":608.008,"Driver.Packet.memory_wait":581.675,"Graphics.Draw":420.020,"Graphics.Draw.draw_and_resource_release":385.625,"Driver.Packet.draw":384.028,"Driver.Draw":383.878,"Resources.Complete":229.522},"owned_draw_counts":{},"trace_dropped":false,"trace":"aps5-trace-612b7139ea92-21180.json.gz"} {"commit":"612b7139ea92","dirty":true,"env":{"APS5_LOG_TIMESTAMPS":"1","APS5_TRACE_DIR":"<path>","APS5_TRACE_FRAMES":"0:30","APS5_TRACE_SUMMARY_EVERY":"10","APS5_TRACE_TRIGGER_FILE":"<path>"},"gpu":"NVIDIA GeForce RTX 4070","driver":"NVIDIA 610.88","os":"Windows 10.0.26300","cpu":"AMD Ryzen 5 7600X 6-Core Processor","cpu_threads":12,"memory_mib":31621,"title_id":"PPSA34299","title":"WWE 2K26","content_version":"01.018.000","resolution":"3840x2160","window":{"spec":"frames 0:30","first_present":2192,"ms":23822.518},"presents":30,"frame_ms":{"p50":792.358,"p90":810.715,"p99":875.434,"max":875.434},"gpu_busy_ms_per_present":208.122,"worker_busy_pct":{"queue worker 0x0":99.096,"queue worker 0x22":86.044,"queue worker 0x21":0.010,"queue worker 0x20":91.075},"top_phases_ms_per_frame":{"Driver.Packet":2156.604,"Driver.Packet.memory_wait":1284.024,"Driver.Packet.draw":667.944,"Driver.Draw":667.767,"Graphics.Draw":637.027,"Graphics.Draw.draw_and_resource_release":601.751,"Resources.Complete":341.170,"Driver.Draw.draw_enqueued":201.892},"owned_draw_counts":{},"trace_dropped":false,"trace":"aps5-trace-612b7139ea92-15864.json.gz"} ``` ### 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 PPSA34299, WWE 2K26) - [x] GPUs tested: NVIDIA GeForce RTX 4070, driver 610.88, Windows 11 Pro (build 26300) - [x] AI-assisted: yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-11-14 09:19:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-14T09:19:46Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the inspected implementation and tests support the range-specific CPU store settle behavior.

What I ran

Reviewed head 19442d992ac97afd51949578b817787f43145a52. Read the prepared diff and changed-file contents through repo_read.py; inspected relevant Vulkan device and buffer-fill context. No build or tests were run in this review.

Results

Check Result Note
Diff and targeted context passed Settle branches and callers inspected
Tests not run Results in the description are author-reported

Findings

Blocking

None.

Non-blocking

None.

Not verified

No commands, build, tests, or hardware behavior were independently verified. Read changed files: core/libs/prx/libSceAgcDriver/CMakeLists.txt, core/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp, core/libs/prx/libSceAgcDriver/Execution/src/Driver/Memory/BufferFill.cpp, core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp (targeted ranges), core/libs/prx/libSceAgcDriver/tests/execution/CpuStoreSettle.cpp, and docs/dev/ENVIRONMENT.md. The full VulkanDevice.cpp was excluded from the review folder, so only relevant ranges were read. No other changed files were listed as excluded.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5903391504 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18829#pullrequestreview-5903391504). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-14T09:19:46Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the inspected implementation and tests support the range-specific CPU store settle behavior. ## What I ran Reviewed head `19442d992ac97afd51949578b817787f43145a52`. Read the prepared diff and changed-file contents through `repo_read.py`; inspected relevant Vulkan device and buffer-fill context. No build or tests were run in this review. ## Results | Check | Result | Note | |---|---|---| | Diff and targeted context | passed | Settle branches and callers inspected | | Tests | not run | Results in the description are author-reported | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified No commands, build, tests, or hardware behavior were independently verified. Read changed files: `core/libs/prx/libSceAgcDriver/CMakeLists.txt`, `core/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp`, `core/libs/prx/libSceAgcDriver/Execution/src/Driver/Memory/BufferFill.cpp`, `core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp` (targeted ranges), `core/libs/prx/libSceAgcDriver/tests/execution/CpuStoreSettle.cpp`, and `docs/dev/ENVIRONMENT.md`. The full `VulkanDevice.cpp` was excluded from the review folder, so only relevant ranges were read. No other changed files were listed as excluded. ## To get this to a good state Nothing is required.
ligmaSec commented 2026-12-03 22:17:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T22:17:20Z.

Review: COMMENTED


The trial merge onto a1b75b0947 conflicts in BufferFill.cpp and VulkanDevice.cpp. Please preserve the drain when read tracking is disabled and the full-drain path for pending labels, image writes, or shadows, alongside the range-only writer wait. CpuStoreSettle checks both arms of the decision, so please run the wait-idle and untracked-read cases once the merge is resolved. Any speed claim needs paired trace_digest.py summaries for the same scene and machine.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6179575245 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18829#pullrequestreview-6179575245). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T22:17:20Z. **Review:** COMMENTED --- The trial merge onto `a1b75b0947` conflicts in `BufferFill.cpp` and `VulkanDevice.cpp`. Please preserve the drain when read tracking is disabled and the full-drain path for pending labels, image writes, or shadows, alongside the range-only writer wait. `CpuStoreSettle` checks both arms of the decision, so please run the wait-idle and untracked-read cases once the merge is resolved. Any speed claim needs paired `trace_digest.py` summaries for the same scene and machine. AI-assisted: yes.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/18829:upstream-pr/18829'
git switch 'upstream-pr/18829'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/18829'
git switch 'upstream-pr/18829'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/18829'
git switch 'upstream-pr/18829'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/18829'
git switch 'main'
git merge --squash 'upstream-pr/18829'
git switch 'main'
git merge --ff-only 'upstream-pr/18829'
git switch 'main'
git merge 'upstream-pr/18829'
git push origin 'main'
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!18829
No description provided.