perf(agc): list a dispatch or draw as a copied writer only while it has a CPU write-back #2792

Merged
alfalfa-star merged 1 commit from upstream-pr/2792 into main 2026-10-10 22:46:04 +00:00
alfalfa-star commented 2026-10-10 15:13:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by alfalfa-star on 2026-10-10T15:13:42Z.


What

A recorded dispatch or draw whose use needs completion work is listed as a copied writer (VulkanDevice copiedWriters, DrawCopiedWriters). Fills, CopyBuffer and indirect argument reads treat every write of a listed object as a store the CPU makes when its batch is reaped, and wait for that batch (SyncThrough).

Completion work is also needed for the BDA fault check alone (NeedsCompletion is bda != nullptr || HasCopiedWrites()). The written sub-ranges of GPU copies are copied back by the GPU in RecordCopyBacks, which MarkGpuWrites runs before the listing. Such an object has no CPU write-back (HasCopiedWrites() is false), and its stores are ordered by the barriers like direct writes, yet it was listed and its writes waited for. For draws, listed was decided before MarkGpuWrites, so a draw whose copied regions the GPU copies back was listed too.

Both lists now take an object only when HasCopiedWrites() holds after MarkGpuWrites. The completion action still runs, so the fault check is unchanged.

New execution test agc_driver_copied_writer_copy: it records a dispatch that reads through global (BDA) loads and stores through a bound buffer into registered memory, then calls VulkanDevice::CopyBuffer on that output before the batch runs. It checks that the copy is a transfer between the host imports (path 1) without a sync, and that the copied bytes match what the dispatch stored. Without this change it fails ("... waited for its batch, although no CPU write-back follows it"). It skips (77) without a Vulkan device or host imports.

Tested

Linux (Arch), RX 9070 XT, RADV, Release:

  • Full ctest: 699/699.
  • PPSA14632 (LEGO Horizon Adventures), on my test branch (main db343a93 plus #1157, #425, #2699, #423/#1077, #2791 and local stand-ins needed to reach gameplay). With a temporary counter, all of about 1,400 DMA_DATA copy waits over 75 s came from listed writers without a CPU write-back. Per 10 s, steady state:
queue 0 GPU-mutex hold for copies presents
without ~3.5 s ~102
with this PR ~30 ms ~109

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 in TechnicalDebt
  • 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
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4812225698 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2792). Originally posted by [alfalfa-star](https://github.com/alfalfa-star) on 2026-10-10T15:13:42Z. --- ### What A recorded dispatch or draw whose use needs completion work is listed as a copied writer (`VulkanDevice` `copiedWriters`, `DrawCopiedWriters`). Fills, `CopyBuffer` and indirect argument reads treat every write of a listed object as a store the CPU makes when its batch is reaped, and wait for that batch (`SyncThrough`). Completion work is also needed for the BDA fault check alone (`NeedsCompletion` is `bda != nullptr || HasCopiedWrites()`). The written sub-ranges of GPU copies are copied back by the GPU in `RecordCopyBacks`, which `MarkGpuWrites` runs before the listing. Such an object has no CPU write-back (`HasCopiedWrites()` is false), and its stores are ordered by the barriers like direct writes, yet it was listed and its writes waited for. For draws, `listed` was decided before `MarkGpuWrites`, so a draw whose copied regions the GPU copies back was listed too. Both lists now take an object only when `HasCopiedWrites()` holds after `MarkGpuWrites`. The completion action still runs, so the fault check is unchanged. New execution test `agc_driver_copied_writer_copy`: it records a dispatch that reads through global (BDA) loads and stores through a bound buffer into registered memory, then calls `VulkanDevice::CopyBuffer` on that output before the batch runs. It checks that the copy is a transfer between the host imports (path 1) without a sync, and that the copied bytes match what the dispatch stored. Without this change it fails ("... waited for its batch, although no CPU write-back follows it"). It skips (77) without a Vulkan device or host imports. ### Tested Linux (Arch), RX 9070 XT, RADV, Release: - Full ctest: 699/699. - PPSA14632 (LEGO Horizon Adventures), on my test branch (`main` db343a93 plus #1157, #425, #2699, #423/#1077, #2791 and local stand-ins needed to reach gameplay). With a temporary counter, all of about 1,400 DMA_DATA copy waits over 75 s came from listed writers without a CPU write-back. Per 10 s, steady state: | | queue 0 GPU-mutex hold for copies | presents | |---|---|---| | without | ~3.5 s | ~102 | | with this PR | ~30 ms | ~109 | ### 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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
popcoder565 commented 2026-10-10 15:57:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-10T15:57:49Z.


Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), RTX 3060 Laptop (NVIDIA 616.92), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head 127e0288, merged onto main 57f96fd2b in one build with 4 other new PRs.

  • This PR's test passes: agc_driver_copied_writer_copy.
  • Full ctest in that build: 711 of 711.

No title was run.

🤖 Addressed by Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6099395555 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2792#issuecomment-6099395555). Originally posted by [popcoder565](https://github.com/popcoder565) on 2026-10-10T15:57:49Z. --- Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), RTX 3060 Laptop (NVIDIA 616.92), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head `127e0288`, merged onto `main` 57f96fd2b in one build with 4 other new PRs. - This PR's test passes: `agc_driver_copied_writer_copy`. - Full ctest in that build: 711 of 711. No title was run. _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_
Dextroid17 commented 2026-10-10 22:07:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-10T22:07:31Z.

Review: COMMENTED


Read against the consumers rather than the summary: the change is right, and there are three things I would want settled — none of them blocking.

The completion path is untouched, which is the claim that mattered. The new guard sits inside if (resources.NeedsCompletion()) — the block that registers the write-back — so the OnComplete action (erase from the list, then WriteBackBuffers) still runs for the same objects; only the listing changed. The BDA fault check therefore sees what it saw before, as the description says.

The two halves are consistent, and the ordering fix on the draw side is real. On the dispatch side MarkGpuWrites(recorder) already ran before the listing, so asking HasCopiedWrites() there is well-defined. On the draw side listed was decided before MarkGpuWrites, which is why that side needed the extra condition rather than a reordering to match.

The one consumer that is not a wait. Some of the places that read these lists (VulkanDevice.cpp:1618 and :1822) only decide whether to sync — waiting is a cost, and not paying it is the point of the change. The indirect-argument decision (std::any_of(... WritesOverlap(arguments, 12) ...)) is different in kind: it chooses whether the CPU reads the arguments or the GPU reads them in place. Dropping an entry there changes that choice, and what makes it safe — the GPU copies those regions back, so the barriers order them like direct writes — is the part I cannot see tested. The new case asserts the CopyBuffer path (a transfer between host imports with no sync) and that the copied bytes match, which is the sync consequence, not the argument-read one. It would help to say explicitly which of the two the change intends to affect, and whether a case for the other is easy to add.

A cross-PR note, since both are open at the same time: #2990 moves this same decision from the other side — it stops the look-ahead before an indirect dispatch whose arguments an earlier dispatch may write, precisely because once the CPU has read them it is too late. The two probably compose, but they are reasoning about the same CPU-read choice, and merging them with that in mind seems worth a sentence.

The cost this removes is already instrumented. The [indirect] report carries copied-writer lists scanned per decision: dispatch avg … (max …), draw avg … — writersScanned and maxWriters for the dispatch pair, drawWritersScanned for the draw average. A before/after on that figure would put a number on the win, which otherwise is argued rather than shown — and it is the honest way to see whether the conservatism is narrower than the change suggests.

Written with AI assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5480974023 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2792#pullrequestreview-5480974023). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-10T22:07:31Z. **Review:** COMMENTED --- Read against the consumers rather than the summary: the change is right, and there are three things I would want settled — none of them blocking. **The completion path is untouched, which is the claim that mattered.** The new guard sits *inside* `if (resources.NeedsCompletion())` — the block that registers the write-back — so the `OnComplete` action (erase from the list, then `WriteBackBuffers`) still runs for the same objects; only the listing changed. The BDA fault check therefore sees what it saw before, as the description says. **The two halves are consistent, and the ordering fix on the draw side is real.** On the dispatch side `MarkGpuWrites(recorder)` already ran before the listing, so asking `HasCopiedWrites()` there is well-defined. On the draw side `listed` was decided *before* `MarkGpuWrites`, which is why that side needed the extra condition rather than a reordering to match. **The one consumer that is not a wait.** Some of the places that read these lists (`VulkanDevice.cpp:1618` and `:1822`) only decide whether to **sync** — waiting is a cost, and not paying it is the point of the change. The indirect-argument decision (`std::any_of(... WritesOverlap(arguments, 12) ...)`) is different in kind: it chooses whether the **CPU reads the arguments** or the GPU reads them in place. Dropping an entry there changes that choice, and what makes it safe — the GPU copies those regions back, so the barriers order them like direct writes — is the part I cannot see tested. The new case asserts the `CopyBuffer` path (a transfer between host imports with no sync) and that the copied bytes match, which is the sync consequence, not the argument-read one. It would help to say explicitly which of the two the change intends to affect, and whether a case for the other is easy to add. **A cross-PR note, since both are open at the same time**: #2990 moves this same decision from the other side — it stops the *look-ahead* before an indirect dispatch whose arguments an earlier dispatch may write, precisely because once the CPU has read them it is too late. The two probably compose, but they are reasoning about the same CPU-read choice, and merging them with that in mind seems worth a sentence. **The cost this removes is already instrumented.** The `[indirect]` report carries `copied-writer lists scanned per decision: dispatch avg … (max …), draw avg …` — `writersScanned` and `maxWriters` for the dispatch pair, `drawWritersScanned` for the draw average. A before/after on that figure would put a number on the win, which otherwise is argued rather than shown — and it is the honest way to see whether the conservatism is narrower than the change suggests. Written with AI assistance.
adriadam10 commented 2026-10-10 22:46:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T22:46:01Z.


Checked on the PR merged onto current main: agc_driver_copied_writer_copy passes on RADV and fails with the two source changes reverted; the libSceAgcDriver ctest scope is green. Confirmed by @popcoder565 on Windows (RTX 3060, ctest 711/711).

On the indirect-arguments point raised in review: the GPU copy-back in GuestBufferMemory.cpp ends with a barrier that includes VK_ACCESS_INDIRECT_COMMAND_READ_BIT, so an object with no CPU write-back stays ordered for a GPU read of the arguments. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6102994415 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2792#issuecomment-6102994415). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T22:46:01Z. --- Checked on the PR merged onto current `main`: `agc_driver_copied_writer_copy` passes on RADV and fails with the two source changes reverted; the libSceAgcDriver ctest scope is green. Confirmed by @popcoder565 on Windows (RTX 3060, ctest 711/711). On the indirect-arguments point raised in review: the GPU copy-back in `GuestBufferMemory.cpp` ends with a barrier that includes `VK_ACCESS_INDIRECT_COMMAND_READ_BIT`, so an object with no CPU write-back stays ordered for a GPU read of the arguments. Merging.
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!2792
No description provided.