fix(agc): count depth plane uploads toward the recorder's kept bytes #5344

Merged
fdfawef324 merged 1 commit from upstream-pr/5344 into main 2026-10-14 06:16:36 +00:00
fdfawef324 commented 2026-10-13 17:35:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fdfawef324 on 2026-10-13T17:35:39Z.


What

DepthPlaneCopy::record (core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp) kept each depth-plane upload buffer with recorder->Keep(upload), with no size. So Recorder::BoundKeptBytes, which caps kept bytes at 512 MiB per batch and 1 GiB in flight, never throttled them. When the GPU fell behind, upload buffers piled up in host-visible memory without limit. They are now kept with their byte size, the same way texture uploads are: recorder->Keep(upload, upload->Bytes().size()).

Why it matters

In Demon's Souls (PPSA01342), the loading screen after the opening cinematic exhausted heap 1, the 16 GiB host heap on an RTX 3060, and the title aborted on vkAllocateMemory buffer: allocation=4194304 memoryType=4 ... VK_ERROR_OUT_OF_DEVICE_MEMORY. A local allocation diagnostic showed:

without this change with it
live 4 MiB depth-plane uploads (DepthPlaneCopy::Refresh) up to 8,068 MiB at most 1,536 MiB (three 512 MiB batches)
memory type 4 (host cached) about 9.5 GiB 2.8 GiB peak
heap 1 usage / VK_EXT_memory_budget budget 15.8 / 15.6 GiB, then the failure 8.7 / 15.6 GiB, no failure

With the change, the title gets past the loading screen into character creation.

Tested

  • agc_driver_depth_plane_guest_layers gains a phase that samples a depth-plane array with an active Recorder after its guest layer was written. It requires the open batch's kept bytes to grow by at least the layer's 262,144 bytes.
    • Without the change it fails with added 0 bytes ... less than the 262144 bytes.
    • With it, it passes.
  • agc_recorder_kept_bytes, agc_driver_depth_plane_sampling, agc_driver_depth_compare_copy and the agc_driver_depth_storage* tests pass.
  • tools/check_conventions.py --base upstream/main passes.
  • Windows Server 2025, RTX 3060, MinGW-w64 GCC 15.2.0, Release.

A related spot: GuestBufferMemory::recordGpuCopies also keeps its host-visible input snapshot with Keep(inputSnapshot) and no size. It did not matter in this title, so it is left for a separate PR.

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
  • Unblocks: PPSA01342 (Demon's Souls loading screen after the opening cinematic; next stop is a stencil-export pixel shader on NVIDIA)
  • GPUs tested: NVIDIA GeForce RTX 3060 12 GB, driver 591.86 (32.0.15.9186), Vulkan 1.4.325, Windows Server 2025 10.0.26100
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4847070605 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5344). Originally posted by [fdfawef324](https://github.com/fdfawef324) on 2026-10-13T17:35:39Z. --- ### What `DepthPlaneCopy::record` (core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp) kept each depth-plane upload buffer with `recorder->Keep(upload)`, with no size. So `Recorder::BoundKeptBytes`, which caps kept bytes at 512 MiB per batch and 1 GiB in flight, never throttled them. When the GPU fell behind, upload buffers piled up in host-visible memory without limit. They are now kept with their byte size, the same way texture uploads are: `recorder->Keep(upload, upload->Bytes().size())`. ### Why it matters In Demon's Souls (PPSA01342), the loading screen after the opening cinematic exhausted heap 1, the 16 GiB host heap on an RTX 3060, and the title aborted on `vkAllocateMemory buffer: allocation=4194304 memoryType=4 ... VK_ERROR_OUT_OF_DEVICE_MEMORY`. A local allocation diagnostic showed: | | without this change | with it | |---|---|---| | live 4 MiB depth-plane uploads (`DepthPlaneCopy::Refresh`) | up to 8,068 MiB | at most 1,536 MiB (three 512 MiB batches) | | memory type 4 (host cached) | about 9.5 GiB | 2.8 GiB peak | | heap 1 usage / VK_EXT_memory_budget budget | 15.8 / 15.6 GiB, then the failure | 8.7 / 15.6 GiB, no failure | With the change, the title gets past the loading screen into character creation. ### Tested - `agc_driver_depth_plane_guest_layers` gains a phase that samples a depth-plane array with an active Recorder after its guest layer was written. It requires the open batch's kept bytes to grow by at least the layer's 262,144 bytes. - Without the change it fails with `added 0 bytes ... less than the 262144 bytes`. - With it, it passes. - `agc_recorder_kept_bytes`, `agc_driver_depth_plane_sampling`, `agc_driver_depth_compare_copy` and the `agc_driver_depth_storage*` tests pass. - `tools/check_conventions.py --base upstream/main` passes. - Windows Server 2025, RTX 3060, MinGW-w64 GCC 15.2.0, Release. A related spot: `GuestBufferMemory::recordGpuCopies` also keeps its host-visible input snapshot with `Keep(inputSnapshot)` and no size. It did not matter in this title, so it is left for a separate PR. ### 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] Unblocks: PPSA01342 (Demon's Souls loading screen after the opening cinematic; next stop is a stencil-export pixel shader on NVIDIA) - [x] GPUs tested: NVIDIA GeForce RTX 3060 12 GB, driver 591.86 (32.0.15.9186), Vulkan 1.4.325, Windows Server 2025 10.0.26100 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-13 17:48:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T17:48:17Z.


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
#5054 core/libs/prx/libSceAgcDriver/tests/execution/DepthPlaneGuestLayers.cpp L297, L317
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6151666782 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5344#issuecomment-6151666782). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T17:48:17Z. --- <!-- 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 | |---|---|---|---| | #5054 | `core/libs/prx/libSceAgcDriver/tests/execution/DepthPlaneGuestLayers.cpp` [L297](https://github.com/boykopovar/AnyPS5/blob/7e68acbb29ea08354d78c91805ee42db7e69295e/core/libs/prx/libSceAgcDriver/tests/execution/DepthPlaneGuestLayers.cpp#L297), [L317](https://github.com/boykopovar/AnyPS5/blob/7e68acbb29ea08354d78c91805ee42db7e69295e/core/libs/prx/libSceAgcDriver/tests/execution/DepthPlaneGuestLayers.cpp#L317) | | |
CnRJay commented 2026-10-14 01:08:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-14T01:08:49Z.

Review: COMMENTED


This fix is correct and small: an upload kept without a size is invisible to BoundKeptBytes, so nothing applied backpressure.

The table also points at a follow-up worth flagging. 8 GiB of live 4 MiB depth-plane uploads means DepthPlaneCopy::Refresh re-uploads the same planes from guest memory on every use (RefreshedPerUse) faster than the GPU consumes them. With this change those uploads now hit the 512 MiB-per-batch cap, so the queue worker waits for the GPU at that point. That converts a memory blow-up into a CPU→GPU sync in the same scene. That is the right trade for correctness, but the loading screen will likely be slower than it needs to be.

A depth plane whose guest bytes haven't changed since the last copy (same write generation / NewestStamp, no pending GPU write over it) doesn't need a new upload. Reusing the previous upload buffer, or skipping the copy into a DepthPlaneCopy that already holds those bytes, would remove most of these uploads instead of throttling them. That can be a separate PR. Counting DepthPlaneCopy::Refresh uploads per 10 s against how many of them had unchanged sources would show how much it would save.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5511902480 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5344#pullrequestreview-5511902480). Originally posted by [CnRJay](https://github.com/CnRJay) on 2026-10-14T01:08:49Z. **Review:** COMMENTED --- This fix is correct and small: an upload kept without a size is invisible to `BoundKeptBytes`, so nothing applied backpressure. The table also points at a follow-up worth flagging. 8 GiB of live 4 MiB depth-plane uploads means `DepthPlaneCopy::Refresh` re-uploads the same planes from guest memory on every use (`RefreshedPerUse`) faster than the GPU consumes them. With this change those uploads now hit the 512 MiB-per-batch cap, so the queue worker waits for the GPU at that point. That converts a memory blow-up into a CPU→GPU sync in the same scene. That is the right trade for correctness, but the loading screen will likely be slower than it needs to be. A depth plane whose guest bytes haven't changed since the last copy (same write generation / `NewestStamp`, no pending GPU write over it) doesn't need a new upload. Reusing the previous upload buffer, or skipping the copy into a `DepthPlaneCopy` that already holds those bytes, would remove most of these uploads instead of throttling them. That can be a separate PR. Counting `DepthPlaneCopy::Refresh` uploads per 10 s against how many of them had unchanged sources would show how much it would save.
fdfawef324 commented 2026-10-14 01:20:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fdfawef324 on 2026-10-14T01:20:28Z.


Agreed. I will keep unchanged-source reuse as a separate change. Before allowing reuse, it needs the same guest write generation and no overlapping pending GPU write, plus a regression that changes the source between uses. I will measure total Refresh uploads and unchanged-source opportunities over 10-second windows. That fraction has not been measured yet; this PR establishes bounded retained-upload accounting and backpressure, without a loading-speed claim.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6158738794 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5344#issuecomment-6158738794). Originally posted by [fdfawef324](https://github.com/fdfawef324) on 2026-10-14T01:20:28Z. --- Agreed. I will keep unchanged-source reuse as a separate change. Before allowing reuse, it needs the same guest write generation and no overlapping pending GPU write, plus a regression that changes the source between uses. I will measure total Refresh uploads and unchanged-source opportunities over 10-second windows. That fraction has not been measured yet; this PR establishes bounded retained-upload accounting and backpressure, without a loading-speed claim.
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!5344
No description provided.