feat(agc): select storage dumps by shape and store them at each flip #3956

Merged
GustavoGamarra95 merged 3 commits from upstream-pr/3956 into main 2026-10-12 10:51:32 +00:00
GustavoGamarra95 commented 2026-10-11 19:48:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by GustavoGamarra95 on 2026-10-11T19:48:41Z.


What

APS5_DUMP_STORAGE took only a hex address and saved the first mip of the first layer after a write-back through the CPU. Two changes:

  • It also takes <width>x<height>x<layers>[:<format>], which selects images by shape (and guest format) for allocations whose address changes from run to run. The dump now holds the first mip of every layer or 3D slice, one plane after another, after the same three-word header (row pitch in texels, height, VkFormat).
  • At each flip, the pending images the selection picks are stored, so an image whose results stay on the GPU reaches the dump. APS5_STORE_AT_FLIP=1 does this for every pending image, which ran a 4 GB device out of memory at 3840x2160.

The dump is still written only on the CPU write-back path; an image in host-imported memory needs APS5_NO_HOST_IMPORT=1.

Context: it dumped the 32x32x32 color-grading LUT of Beast of Reincarnation (PPSA29343), which had only slice 0 written; the cause is the dynamic rendering layer count that #3763 fixes. We are still analyzing the remaining rendering issues of that title and an improvement for GPUs with little VRAM (it runs a 4 GB RTX 3050 out of device memory at the title screen).

Tested

Linux (CachyOS, kernel 7.2), Ryzen 5 7535HS, RTX 3050 Laptop 4 GB (NVIDIA 615.78.08) and Radeon 660M (RADV), GCC, Release.

  • Built on current main; tools/check_conventions.py passes.
  • agc_driver_storage_cache_budget, agc_driver_storage_one_slice_alias, agc_driver_pending_exact_surface and agc_driver_image_xor_swizzle_volume pass on the RTX 3050.
  • With the layered volume draw test of #1077 (not on main) on the Radeon 660M, APS5_NO_HOST_IMPORT=1 APS5_DUMP_STORAGE=48x16x4 wrote one file with 4 planes: slice 0 untouched and one band in each of slices 1 to 3, as the test expects.
  • PPSA29343: APS5_NO_HOST_IMPORT=1 APS5_DUMP_STORAGE=32x32x32:50 dumped the LUT (32 planes).

No automated test is added: it is a debug aid, inactive unless the variable is set.

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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4821847105 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3956). Originally posted by [GustavoGamarra95](https://github.com/GustavoGamarra95) on 2026-10-11T19:48:41Z. --- ### What `APS5_DUMP_STORAGE` took only a hex address and saved the first mip of the first layer after a write-back through the CPU. Two changes: - It also takes `<width>x<height>x<layers>[:<format>]`, which selects images by shape (and guest format) for allocations whose address changes from run to run. The dump now holds the first mip of every layer or 3D slice, one plane after another, after the same three-word header (row pitch in texels, height, VkFormat). - At each flip, the pending images the selection picks are stored, so an image whose results stay on the GPU reaches the dump. `APS5_STORE_AT_FLIP=1` does this for every pending image, which ran a 4 GB device out of memory at 3840x2160. The dump is still written only on the CPU write-back path; an image in host-imported memory needs `APS5_NO_HOST_IMPORT=1`. Context: it dumped the 32x32x32 color-grading LUT of Beast of Reincarnation (PPSA29343), which had only slice 0 written; the cause is the dynamic rendering layer count that #3763 fixes. We are still analyzing the remaining rendering issues of that title and an improvement for GPUs with little VRAM (it runs a 4 GB RTX 3050 out of device memory at the title screen). ### Tested Linux (CachyOS, kernel 7.2), Ryzen 5 7535HS, RTX 3050 Laptop 4 GB (NVIDIA 615.78.08) and Radeon 660M (RADV), GCC, Release. - Built on current `main`; `tools/check_conventions.py` passes. - `agc_driver_storage_cache_budget`, `agc_driver_storage_one_slice_alias`, `agc_driver_pending_exact_surface` and `agc_driver_image_xor_swizzle_volume` pass on the RTX 3050. - With the layered volume draw test of #1077 (not on `main`) on the Radeon 660M, `APS5_NO_HOST_IMPORT=1 APS5_DUMP_STORAGE=48x16x4` wrote one file with 4 planes: slice 0 untouched and one band in each of slices 1 to 3, as the test expects. - PPSA29343: `APS5_NO_HOST_IMPORT=1 APS5_DUMP_STORAGE=32x32x32:50` dumped the LUT (32 planes). No automated test is added: it is a debug aid, inactive unless the variable is set. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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
Dextroid17 commented 2026-10-12 00:50:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-12T00:50:03Z.


Both PRs touch Texture.cpp in the storage/texture allocation path, so reviewing together — only #4108 also touches Context.hpp:

  • #4108's AllocateDeviceMemory is additive: it always makes the same first device-local attempt and returns its VkResult unless it is exactly VK_ERROR_OUT_OF_DEVICE_MEMORY, so every other result (success or any other error) passes through unchanged. That's a transparent substitution, not a new regression surface on the existing success path.
  • #3956's new debug code path (FlushDumpSelected) runs only when APS5_DUMP_STORAGE is set AND APS5_STORE_AT_FLIP is NOT set — the two debug knobs are mutually exclusive by construction (the else in PresentDisplayBuffer), so there's no double-flush.
  • The two PRs do not conflict: #4108 edits only the Texture and StorageTexture constructors, where #3956's writeBackLayers and the new FlushDumpSelected/dump-selector code sit roughly 2000 lines away in different functions.
  • One real defect in #3956, independent of the above: parsed.anyFormat = std::strchr(text, ':') == nullptr; means a shape string with a trailing colon and no format digits (e.g. 512x512x1:) is read as "match format 0" instead of "match any format" — the colon is present, so anyFormat is set false even though nothing was parsed into format. Checking the actual field count sscanf returns (>= 4 means a format was given) rather than the presence of a colon would avoid that.
  • Neither PR adds an automated test, which the bodies state plainly; for #4108 that's reasonable for the real-OOM part, though the memory-type selection loop itself doesn't need a real GPU — the existing BufferPool.cpp test already mocks a Context with a VK_ERROR_OUT_OF_DEVICE_MEMORY-returning allocator, and the same mock would exercise AllocateDeviceMemory directly. For #3956 it's a debug aid gated behind an env var, genuinely hard to test meaningfully in CI.

Written with AI assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6115796154 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3956#issuecomment-6115796154). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-12T00:50:03Z. --- Both PRs touch `Texture.cpp` in the storage/texture allocation path, so reviewing together — only #4108 also touches `Context.hpp`: - #4108's `AllocateDeviceMemory` is additive: it always makes the same first device-local attempt and returns its `VkResult` unless it is exactly `VK_ERROR_OUT_OF_DEVICE_MEMORY`, so every other result (success or any other error) passes through unchanged. That's a transparent substitution, not a new regression surface on the existing success path. - #3956's new debug code path (`FlushDumpSelected`) runs only when `APS5_DUMP_STORAGE` is set AND `APS5_STORE_AT_FLIP` is NOT set — the two debug knobs are mutually exclusive by construction (the `else` in `PresentDisplayBuffer`), so there's no double-flush. - The two PRs do not conflict: #4108 edits only the `Texture` and `StorageTexture` constructors, where #3956's `writeBackLayers` and the new `FlushDumpSelected`/dump-selector code sit roughly 2000 lines away in different functions. - One real defect in #3956, independent of the above: `parsed.anyFormat = std::strchr(text, ':') == nullptr;` means a shape string with a trailing colon and no format digits (e.g. `512x512x1:`) is read as "match format 0" instead of "match any format" — the colon is present, so `anyFormat` is set false even though nothing was parsed into `format`. Checking the actual field count `sscanf` returns (`>= 4` means a format was given) rather than the presence of a colon would avoid that. - Neither PR adds an automated test, which the bodies state plainly; for #4108 that's reasonable for the real-OOM part, though the memory-type selection loop itself doesn't need a real GPU — the existing `BufferPool.cpp` test already mocks a `Context` with a `VK_ERROR_OUT_OF_DEVICE_MEMORY`-returning allocator, and the same mock would exercise `AllocateDeviceMemory` directly. For #3956 it's a debug aid gated behind an env var, genuinely hard to test meaningfully in CI. Written with AI assistance.
GustavoGamarra95 commented 2026-10-12 03:01:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by GustavoGamarra95 on 2026-10-12T03:01:05Z.


Thanks for the review. Fixed in bff955a: the format filter now applies only when sscanf reads all four fields, so 512x512x1: matches any format, like 512x512x1. Checked with 512x512x1, 512x512x1:, 512x512x1:50 and a hex address.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6116963501 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3956#issuecomment-6116963501). Originally posted by [GustavoGamarra95](https://github.com/GustavoGamarra95) on 2026-10-12T03:01:05Z. --- Thanks for the review. Fixed in bff955a: the format filter now applies only when sscanf reads all four fields, so `512x512x1:` matches any format, like `512x512x1`. Checked with `512x512x1`, `512x512x1:`, `512x512x1:50` and a hex address.
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!3956
No description provided.