Skip to content

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

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
MarcZX10:codex/fix-shader-memory-region-lifetimes
Oct 20, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
MarcZX10:codex/fix-shader-memory-region-lifetimes

Conversation

@MarcZX10

Copy link
Copy Markdown
Contributor

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: AGC tests: request memory spans outlive temporary Regions() vectors #7754
  • Unblocks: none
  • GPUs tested: n/a (test lifetime fix; no GPU test run)
  • AI-assisted: yes

@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

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

@MarcZX10

Copy link
Copy Markdown
Contributor Author

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

Amoenus commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor

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 jotitadev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 55a3eeb, PR diff applied cleanly. Apple clang 21.0.0, Release, default warnings, no extra flags.

Tested: the tree is main a373e85 + 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

Copy link
Copy Markdown
Contributor Author

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 adriadam10 self-assigned this Oct 19, 2026
@adriadam10
adriadam10 merged commit d0eb3b6 into boykopovar:main Oct 20, 2026
11 checks passed
@adriadam10

Copy link
Copy Markdown
Collaborator

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 up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* fix error Closes an issue (Fixes #N)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AGC tests: request memory spans outlive temporary Regions() vectors

5 participants