fix(agc): retain storage textures during initial uploads #3813

Merged
jweidenh merged 4 commits from upstream-pr/3813 into main 2026-10-11 22:05:54 +00:00
jweidenh commented 2026-10-11 17:02:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jweidenh on 2026-10-11T17:02:12Z.


What

Initial StorageTexture uploads can record a DCC clear or detiler dispatch before the constructor returns. At that point weak_from_this() has no owner, so the upload's recorder keep is empty. A later image-view creation failure, or release of the caller's last reference, can destroy resources still referenced by recorded GPU commands.

Create storage textures through StorageTexture::Create: allocate first, establish shared ownership, then upload and create the default view. Publish to the live registry only after initialization succeeds. Allocation failures still use the constructor cleanup; failures after recording keep the object alive until the recorder releases its completed batch. Update all callers to the factory.

Add two bounded Vulkan regressions covering immediate caller release and injected VK_ERROR_OUT_OF_DEVICE_MEMORY during default-view creation after recording a clear. Both read back all 64×64 cleared texels and verify eventual resource release. The test intercepts premature destroy requests and defers native destruction until recorder drain, so the failing baseline never submits dangling Vulkan resources.

Tested

  • Unchanged production baseline plus the same tests: 4545f6648f53a0debe6b7db072099e35848006cf.
  • Fixed revision: 804fcb41e3c971433e3a688592f18ff3b17ae34e.
  • Windows 11, NVIDIA RTX 5090, driver 617.42, GCC 15.2.0 Release: both baseline regressions fail at the intended lifetime assertions after GPU readback. The fixed revision passes both regressions (2.14 s / 0.20 s), agc_driver_storage_cache_budget (0.93 s), and agc_driver_storage_one_slice_alias (0.98 s), with the app shader cache disabled. The existing alias test does not check watched-import device reuse on Windows because imported memory uses comparisons; its shader/readback assertions pass.
  • Linux, local self-hosted runner, lavapipe (LLVM 20.1.2), GCC 13.3 Release: both baseline lifetime assertions reproduced. The fixed revision passes agc_storage_upload_lifetime (0.056 s), agc_storage_upload_failure (0.052 s), agc_storage_baseline_settled, agc_unchanged_cpu_stamps, agc_host_import_unmap, and agc_driver_storage_cache_budget, all below 0.4 s with fresh app/Mesa cache directories and no skipped assertions. agc_driver_storage_one_slice_alias also passes its pixel assertions (0.32 s), with the same compared-import device-reuse limitation as Windows. The unit-shadow control was excluded because it requires retained import write watching.
  • git diff --check and the repository conventions checker pass.

These are synthetic Vulkan regressions and existing storage tests. No retail title, startup latency, or frame-rate improvement was measured. No workflow changes are included in this 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 in TechnicalDebt
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes; source review and native/local-runner validation described above
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4820769504 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3813). Originally posted by [jweidenh](https://github.com/jweidenh) on 2026-10-11T17:02:12Z. --- ### What Initial `StorageTexture` uploads can record a DCC clear or detiler dispatch before the constructor returns. At that point `weak_from_this()` has no owner, so the upload's recorder keep is empty. A later image-view creation failure, or release of the caller's last reference, can destroy resources still referenced by recorded GPU commands. Create storage textures through `StorageTexture::Create`: allocate first, establish shared ownership, then upload and create the default view. Publish to the live registry only after initialization succeeds. Allocation failures still use the constructor cleanup; failures after recording keep the object alive until the recorder releases its completed batch. Update all callers to the factory. Add two bounded Vulkan regressions covering immediate caller release and injected `VK_ERROR_OUT_OF_DEVICE_MEMORY` during default-view creation after recording a clear. Both read back all 64×64 cleared texels and verify eventual resource release. The test intercepts premature destroy requests and defers native destruction until recorder drain, so the failing baseline never submits dangling Vulkan resources. ### Tested - Unchanged production baseline plus the same tests: `4545f6648f53a0debe6b7db072099e35848006cf`. - Fixed revision: `804fcb41e3c971433e3a688592f18ff3b17ae34e`. - Windows 11, NVIDIA RTX 5090, driver 617.42, GCC 15.2.0 Release: both baseline regressions fail at the intended lifetime assertions after GPU readback. The fixed revision passes both regressions (2.14 s / 0.20 s), `agc_driver_storage_cache_budget` (0.93 s), and `agc_driver_storage_one_slice_alias` (0.98 s), with the app shader cache disabled. The existing alias test does not check watched-import device reuse on Windows because imported memory uses comparisons; its shader/readback assertions pass. - Linux, local self-hosted runner, lavapipe (LLVM 20.1.2), GCC 13.3 Release: both baseline lifetime assertions reproduced. The fixed revision passes `agc_storage_upload_lifetime` (0.056 s), `agc_storage_upload_failure` (0.052 s), `agc_storage_baseline_settled`, `agc_unchanged_cpu_stamps`, `agc_host_import_unmap`, and `agc_driver_storage_cache_budget`, all below 0.4 s with fresh app/Mesa cache directories and no skipped assertions. `agc_driver_storage_one_slice_alias` also passes its pixel assertions (0.32 s), with the same compared-import device-reuse limitation as Windows. The unit-shadow control was excluded because it requires retained import write watching. - `git diff --check` and the repository conventions checker pass. These are synthetic Vulkan regressions and existing storage tests. No retail title, startup latency, or frame-rate improvement was measured. No workflow changes are included in this 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 - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in TechnicalDebt - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes; source review and native/local-runner validation described above
adriadam10 commented 2026-10-11 22:05:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T22:05:50Z.


Checked the factory change against all callers (ShaderResources.cpp and the tests), the destructor path for an object that never reached the live registry (safe), and ran the PR merged onto main: libSceAgcDriver build and ctest 392/392 pass, including agc_storage_upload_lifetime and agc_storage_upload_failure. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6114357110 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3813#issuecomment-6114357110). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T22:05:50Z. --- Checked the factory change against all callers (`ShaderResources.cpp` and the tests), the destructor path for an object that never reached the live registry (safe), and ran the PR merged onto main: libSceAgcDriver build and ctest 392/392 pass, including `agc_storage_upload_lifetime` and `agc_storage_upload_failure`. 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!3813
No description provided.