fix(agc): retain shader memory region vectors #7759

Merged
MarcZX10 merged 1 commit from upstream-pr/7759 into main 2026-10-20 13:48:40 +00:00
MarcZX10 commented 2026-10-19 06:28:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-19T06:28:27Z.


What

Retain the vectors returned by ShaderMemory::Regions() anywhere test requests store them in GuestContext::memory, which is a borrowed span. Fixes all 20 reported sites in ShaderMemory.cpp, including reused request/lambda cases, and the same lifetime bug in the ImageTableCache capture helper. The store lambda now compiles a local request copy so an outer request cannot retain a view into a destroyed vector.

Tested

python3 tools/check_conventions.py --base upstream/main, python3 tools/pr_overlap.py --branch codex/fix-shader-memory-region-lifetimes --base main --repo boykopovar/AnyPS5, and git diff --check pass. No open PR overlap was found.

The focused Linux test build was not completed. The available agc_shader_memory_tests build tree is based on an older branch; compiling the current-main test source against it fails on unrelated SpirvTarget::float32FlushToZero fields absent from that older branch. The temporary source copies were restored immediately. No test pass is claimed.

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
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: #7754
  • Unblocks: none
  • GPUs tested: n/a (test lifetime fix; no GPU test run)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4916828176 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7759). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-19T06:28:27Z. --- ### What Retain the vectors returned by `ShaderMemory::Regions()` anywhere test requests store them in `GuestContext::memory`, which is a borrowed span. Fixes all 20 reported sites in `ShaderMemory.cpp`, including reused request/lambda cases, and the same lifetime bug in the `ImageTableCache` capture helper. The store lambda now compiles a local request copy so an outer request cannot retain a view into a destroyed vector. ### Tested `python3 tools/check_conventions.py --base upstream/main`, `python3 tools/pr_overlap.py --branch codex/fix-shader-memory-region-lifetimes --base main --repo boykopovar/AnyPS5`, and `git diff --check` pass. No open PR overlap was found. The focused Linux test build was not completed. The available `agc_shader_memory_tests` build tree is based on an older branch; compiling the current-main test source against it fails on unrelated `SpirvTarget::float32FlushToZero` fields absent from that older branch. The temporary source copies were restored immediately. No test pass is claimed. ### 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 - [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: #7754 - [x] Unblocks: none - [x] GPUs tested: n/a (test lifetime fix; no GPU test run) - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-19 06:36:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-19T06:36:39Z.


Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 5371 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 5500 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 6177 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 6235 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 6290 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 6412 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 6488 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 6645 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 6683 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 6947 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 7642 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 7684 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 8004 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6261254646 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7759#issuecomment-6261254646). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-19T06:36:39Z. --- <!-- pr-overlap --> Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 5371](https://www.github.com/boykopovar/AnyPS5/pull/5371) | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` | | [PR 5500](https://www.github.com/boykopovar/AnyPS5/pull/5500) | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` | | [PR 6177](https://www.github.com/boykopovar/AnyPS5/pull/6177) | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` | | [PR 6235](https://www.github.com/boykopovar/AnyPS5/pull/6235) | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` | | [PR 6290](https://www.github.com/boykopovar/AnyPS5/pull/6290) | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` | | [PR 6412](https://www.github.com/boykopovar/AnyPS5/pull/6412) | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` | | [PR 6488](https://www.github.com/boykopovar/AnyPS5/pull/6488) | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` | | [PR 6645](https://www.github.com/boykopovar/AnyPS5/pull/6645) | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` | | [PR 6683](https://www.github.com/boykopovar/AnyPS5/pull/6683) | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` | | [PR 6947](https://www.github.com/boykopovar/AnyPS5/pull/6947) | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` | | [PR 7642](https://www.github.com/boykopovar/AnyPS5/pull/7642) | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` | | [PR 7684](https://www.github.com/boykopovar/AnyPS5/pull/7684) | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` | | [PR 8004](https://www.github.com/boykopovar/AnyPS5/pull/8004) | `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp` |
MarcZX10 commented 2026-10-19 06:39:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-19T06:39:36Z.


Manual follow-up to the overlap report: I reviewed the flagged ShaderMemory.cpp diffs. The serializer-related PRs change serializer/version fixtures; the remaining diffs add or adjust separate sRGB, wave-reduction, FMASK, extension-key, volume-array, pointer/image-table or device-table tests. None changes the request Regions() ownership sites in this PR, and none of the flagged PRs changes ImageTableCache.cpp. I found no direct hunk overlap or dependency. The PR is currently mergeable against main.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6261299975 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7759#issuecomment-6261299975). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-19T06:39:36Z. --- Manual follow-up to the overlap report: I reviewed the flagged `ShaderMemory.cpp` diffs. The serializer-related PRs change serializer/version fixtures; the remaining diffs add or adjust separate sRGB, wave-reduction, FMASK, extension-key, volume-array, pointer/image-table or device-table tests. None changes the request `Regions()` ownership sites in this PR, and none of the flagged PRs changes `ImageTableCache.cpp`. I found no direct hunk overlap or dependency. The PR is currently mergeable against `main`.
Amoenus commented 2026-10-19 07:09:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Amoenus on 2026-10-19T07:09:41Z.


Independent validation of exact head 55a3eeb074eae9d50db090ef3584b04ab1066c4d (actual parent/merge base 63e4a63804c4570e5bd7b08b7ee03a780feeb0e6):

  • Windows 11 Enterprise 26200 / supported WinLibs GCC 15.2r7, Release; Ubuntu 24.04 / GCC 13.3, Release, bundled dependencies and SPIRV-Tools enabled. Both matching source checkouts configure and build agc_shader_memory_tests and agc_driver_image_table_cache_tests successfully.
  • 20 fresh-process CPU passes: both agc_shader_memory and agc_driver_image_table_cache, serial, five repetitions each on each OS; shader cache disabled. No skips/timeouts. Longest test: Windows 1.97 s, Linux 1.48 s (30 s limit). These are CPU fixtures, not GPU or title results.
  • Cppcheck 2.20 then clang-tidy 23.1.3 complete for both changed translation units using the Windows compilation database, without parser/configuration failures or timeouts. No danglingTemporaryLifetime / bugprone-dangling-handle diagnostics remain. The unchanged-main comparison at feb74b65c2 had 16 / 20 respectively in ShaderMemory.cpp. Five unrelated advisories remain in that file (two Cppcheck, three clang-tidy); ImageTableCache.cpp has no selected diagnostics. No suppressions or auto-fixes; no whole-project static-clean claim.

Source review: the reused store lambda uses a local request copy, so the outer request does not inherit its temporary region view. The image-table helper retains TakeRecentRegions() in Captured::regions across Recompile; its ShaderMemory starts empty for that capture. I independently reviewed the previously flagged shared-file patches and found no competing repair of these ownership sites.

ASan limitation: I cannot claim a sanitizer pass. A separate ASan run on unmodified main 46f27623c2 and our earlier one-file prototype e3b8707988 aborts before these sites in SPIRV-Tools validation / std::stable_sort with alloc-dealloc-mismatch (operator new vs free), reported as #7765. That is not a run of this exact PR head, and allocation-mismatch checking was not suppressed.

Update: #7781 has since merged the fixture nothrow-allocation correction for #7765. The pinned sanitizer runs above predate it; we have not yet rerun the full combined fixture under ASan on that newer source.

Thanks for taking #7754 forward, including the additional image-table helper. Our one-file prototype remains preserved on the fork; we will use this PR rather than submit a duplicate.

AI-assisted review/report: yes, Codex. No workflow dispatch or merge performed.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6261730747 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7759#issuecomment-6261730747). Originally posted by [Amoenus](https://github.com/Amoenus) on 2026-10-19T07:09:41Z. --- Independent validation of exact head `55a3eeb074eae9d50db090ef3584b04ab1066c4d` (actual parent/merge base `63e4a63804c4570e5bd7b08b7ee03a780feeb0e6`): - Windows 11 Enterprise 26200 / supported WinLibs GCC 15.2r7, Release; Ubuntu 24.04 / GCC 13.3, Release, bundled dependencies and SPIRV-Tools enabled. Both matching source checkouts configure and build `agc_shader_memory_tests` and `agc_driver_image_table_cache_tests` successfully. - **20 fresh-process CPU passes:** both `agc_shader_memory` and `agc_driver_image_table_cache`, serial, five repetitions each on each OS; shader cache disabled. No skips/timeouts. Longest test: Windows 1.97 s, Linux 1.48 s (30 s limit). These are CPU fixtures, not GPU or title results. - Cppcheck 2.20 then clang-tidy 23.1.3 complete for both changed translation units using the Windows compilation database, without parser/configuration failures or timeouts. No `danglingTemporaryLifetime` / `bugprone-dangling-handle` diagnostics remain. The unchanged-main comparison at `feb74b65c2` had 16 / 20 respectively in `ShaderMemory.cpp`. Five unrelated advisories remain in that file (two Cppcheck, three clang-tidy); `ImageTableCache.cpp` has no selected diagnostics. No suppressions or auto-fixes; no whole-project static-clean claim. Source review: the reused store lambda uses a local request copy, so the outer request does not inherit its temporary region view. The image-table helper retains `TakeRecentRegions()` in `Captured::regions` across `Recompile`; its `ShaderMemory` starts empty for that capture. I independently reviewed the previously flagged shared-file patches and found no competing repair of these ownership sites. **ASan limitation:** I cannot claim a sanitizer pass. A separate ASan run on unmodified main `46f27623c2` and our earlier one-file prototype `e3b8707988` aborts before these sites in SPIRV-Tools validation / `std::stable_sort` with `alloc-dealloc-mismatch (operator new vs free)`, reported as #7765. That is not a run of this exact PR head, and allocation-mismatch checking was not suppressed. Update: #7781 has since merged the fixture nothrow-allocation correction for #7765. The pinned sanitizer runs above predate it; we have not yet rerun the full combined fixture under ASan on that newer source. Thanks for taking #7754 forward, including the additional image-table helper. Our one-file prototype remains preserved on the fork; we will use this PR rather than submit a duplicate. AI-assisted review/report: yes, Codex. No workflow dispatch or merge performed.
savvaniss commented 2026-10-19 07:42:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by savvaniss on 2026-10-19T07:42:04Z.


Intel and AMD Windows data: the 16 tests this PR touches pass on an Intel UHD 770 and an AMD RX 9070 XT, with and without the change.

Windows 11 Pro 26300, WinLibs GCC 15.2.0 r7, Release, every execution test built, ANYPS5_NO_SHADER_CACHE=1, serial CTest. Intel UHD Graphics 770 (8086:a780), driver 32.0.101.7088. AMD Radeon RX 9070 XT (1002:7550), driver 32.0.31041.1004, with VkCache emptied first. This head 55a3eeb07 merged into main 6b8228b2b. "Without" means this PR's test files on main 6b8228b2b, with none of its other changes.

Tests, ×3 UHD 770 RX 9070 XT
This head: the 16 tests built from the PR's test files (agc_shader_memory, agc_driver_image_table_cache, agc_shader_bindless and the other shader tests) 16 of 16 pass 16 of 16 pass
Without 16 of 16 pass 16 of 16 pass

So on these two GPUs the tests don't distinguish the change, and they show no regression.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6262232412 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7759#issuecomment-6262232412). Originally posted by [savvaniss](https://github.com/savvaniss) on 2026-10-19T07:42:04Z. --- Intel and AMD Windows data: the 16 tests this PR touches pass on an Intel UHD 770 and an AMD RX 9070 XT, with and without the change. Windows 11 Pro 26300, WinLibs GCC 15.2.0 r7, Release, every execution test built, `ANYPS5_NO_SHADER_CACHE=1`, serial CTest. Intel UHD Graphics 770 (`8086:a780`), driver 32.0.101.7088. AMD Radeon RX 9070 XT (`1002:7550`), driver 32.0.31041.1004, with `VkCache` emptied first. This head `55a3eeb07` merged into `main` `6b8228b2b`. "Without" means this PR's test files on `main` `6b8228b2b`, with none of its other changes. | Tests, ×3 | UHD 770 | RX 9070 XT | |---|---|---| | This head: the 16 tests built from the PR's test files (`agc_shader_memory`, `agc_driver_image_table_cache`, `agc_shader_bindless` and the other shader tests) | 16 of 16 pass | 16 of 16 pass | | Without | 16 of 16 pass | 16 of 16 pass | So on these two GPUs the tests don't distinguish the change, and they show no regression. AI-assisted: yes (Claude Code)
jotitadev commented 2026-10-19 09:00:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-19T09:00:46Z.

Review: COMMENTED


macOS data point: Apple clang already flags these sites in a default build, so this shows up as compiler warnings on macOS. On the tree below without this PR, the build has 20 -Wdangling-assignment-gsl warnings in tests/ShaderMemory.cpp and 1 in tests/execution/ImageTableCache.cpp (object backing the pointer 'request.context.memory' will be destroyed at the end of the full-expression). These are the 20 + 1 sites this PR changes. With the PR there are none, and both tests pass.

Machine: Apple M2 Max, macOS 27.2, x86-64 build under Rosetta. Drivers: MoltenVK 1.4.2 (Vulkan SDK 1.4.363.0) and MoltenVK main + SPIRV-Cross #2704. Head 55a3eeb07, PR diff applied cleanly. Apple clang 21.0.0, Release, default warnings, no extra flags.

Tested: the tree is main a373e85e5 + mugurc's macOS series (ci/macos-series-2) + the PRs needed to build on macOS (#6667, #6668, #7524, #6969, and two files of #7332), not plain main (it doesn't build on macOS yet). Applied together in the same build: #7371, #7535, #7684, #7746 and #7759, plus a test-only patch that lets nine AGC fixtures load the Vulkan loader on macOS (branch jotitadev:fix/agc-tests-vulkan-loader-macos). Base on that tree: 40 ^agc failures with MoltenVK 1.4.2 and 26 with MoltenVK main + #2704, plus agc_driver_pooled_buffer_range and agc_performance_overlay, which only run because of the loader patch.

  • agc_shader_memory and agc_driver_image_table_cache pass 3 of 3 on both drivers with the PR. #7684's new ShaderMemory.cpp cases were in the same build and add no new warnings.
  • The full ^agc suite with the stack has the base failures on both drivers. The only new failure, agc_driver_native_depth_clears, comes from #7371 / #7233. Nothing from this PR.

GPUs tested: Apple M2 Max (MoltenVK 1.4.2; MoltenVK main + SPIRV-Cross #2704)

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5569158194 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7759#pullrequestreview-5569158194). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-19T09:00:46Z. **Review:** COMMENTED --- <!-- head: 55a3eeb07 --> macOS data point: Apple clang already flags these sites in a default build, so this shows up as compiler warnings on macOS. On the tree below without this PR, the build has 20 `-Wdangling-assignment-gsl` warnings in `tests/ShaderMemory.cpp` and 1 in `tests/execution/ImageTableCache.cpp` (`object backing the pointer 'request.context.memory' will be destroyed at the end of the full-expression`). These are the 20 + 1 sites this PR changes. With the PR there are none, and both tests pass. Machine: Apple M2 Max, macOS 27.2, x86-64 build under Rosetta. Drivers: MoltenVK 1.4.2 (Vulkan SDK 1.4.363.0) and MoltenVK main + SPIRV-Cross #2704. Head 55a3eeb07, PR diff applied cleanly. Apple clang 21.0.0, Release, default warnings, no extra flags. **Tested:** the tree is `main` a373e85e5 + mugurc's macOS series (`ci/macos-series-2`) + the PRs needed to build on macOS (#6667, #6668, #7524, #6969, and two files of #7332), not plain `main` (it doesn't build on macOS yet). Applied together in the same build: #7371, #7535, #7684, #7746 and #7759, plus a test-only patch that lets nine AGC fixtures load the Vulkan loader on macOS (branch `jotitadev:fix/agc-tests-vulkan-loader-macos`). Base on that tree: 40 `^agc` failures with MoltenVK 1.4.2 and 26 with MoltenVK main + #2704, plus `agc_driver_pooled_buffer_range` and `agc_performance_overlay`, which only run because of the loader patch. - `agc_shader_memory` and `agc_driver_image_table_cache` pass 3 of 3 on both drivers with the PR. #7684's new `ShaderMemory.cpp` cases were in the same build and add no new warnings. - The full `^agc` suite with the stack has the base failures on both drivers. The only new failure, `agc_driver_native_depth_clears`, comes from #7371 / #7233. Nothing from this PR. GPUs tested: Apple M2 Max (MoltenVK 1.4.2; MoltenVK main + SPIRV-Cross #2704) Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
MarcZX10 commented 2026-10-19 16:52:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-19T16:52:08Z.


Thank you for the cross-platform checks. The Windows and Linux CPU fixture runs, static-analysis results, and AMD/Intel Windows runs show no regression in the tested cases. The 16 Windows tests pass both with and without the change, so those GPU results do not distinguish the fix; the independent 20 fresh-process CPU passes and the compiler warning results provide additional validation for the lifetime issue. I’ll describe those separately rather than treating them as GPU proof.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6272474625 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7759#issuecomment-6272474625). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-19T16:52:08Z. --- Thank you for the cross-platform checks. The Windows and Linux CPU fixture runs, static-analysis results, and AMD/Intel Windows runs show no regression in the tested cases. The 16 Windows tests pass both with and without the change, so those GPU results do not distinguish the fix; the independent 20 fresh-process CPU passes and the compiler warning results provide additional validation for the lifetime issue. I’ll describe those separately rather than treating them as GPU proof.
adriadam10 commented 2026-10-20 13:49:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-20T13:49:49Z.


Rechecked against current main: no temporary Regions() is assigned to context.memory any more (all 21 sites retain the vector), the store lambda compiles a local copy, no logic changes; runs from @Amoenus, @savvaniss and @jotitadev confirm; merged.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6292421623 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7759#issuecomment-6292421623). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-20T13:49:49Z. --- Rechecked against current main: no temporary `Regions()` is assigned to `context.memory` any more (all 21 sites retain the vector), the store lambda compiles a local copy, no logic changes; runs from @Amoenus, @savvaniss and @jotitadev confirm; merged.
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!7759
No description provided.