fix(agc): accept a resource snapshot when only unrelated allocations moved #15465
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15465"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by mrfelek on 2026-11-03T13:16:01Z.
What
ResourceMaterializer::Materializeretries an attempt when the guest allocation generation moved during it, and throwsruntime resource snapshot did not stabilizeafter three attempts. Any allocation change moves that generation, so a title that maps memory while it loads can move it during every attempt and abort.SrtRuntimehookimageViewsCurrent: whether the image views a snapshot registered still match their allocations.CaptureRegisteredViewsCurrent, the check the dispatch cache already uses for its variants.Materializeaccepts an attempt whose generation moved when that check passes. It retries as before when the check fails or no hook is set. A descriptor scope change still retries as before.Found while testing #11346 on PPSA22408 (Hot Wheels Infinite Rush): with #11346 and its
COND_INDIRECT_BUFFERchange, the title aborted during loading in 2 of 2 runs; with this change added it loaded in 2 of 2. #11346 will list this PR under Depends on.Tested
agc_shader_memory: new caseverifyAllocationChurnSnapshotwith a runtime whose allocation generation moves on every read. With the hook reporting the views current, the snapshot is accepted on the first pass. With no hook, or a hook reporting them stale, it still throwsdid not stabilize. Negative control: withmain'sResourceMaterializer.cppand the new test, the case fails withruntime resource snapshot did not stabilize.APS5_LOOP_GUARD(onmain5cb015caaa+ #11346 + #11630 + the jump diff from #11346, plus local offline HTTP/2 stubs):snapshot did not stabilizeEarlier runs with the same change on top of other local work: 4 of 4 without the abort, where about 1 in 3 aborted before.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)agc_shader_memoryneeds no GPUAI-assisted; the runs are from my machine(s).
Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T13:38:10Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The new
nextSnapshot.registeredImages.clear()throws away the views of directly bound images on everyMaterialize, not only when the generation moved. Because of that,agc_driver_image_array_rows_past_layer_limitnow fails, and the test passes again once that line is deleted.What I ran
Head
9e07f78acb5c87f1459ce04326010f42f085859dmerged intomain4f41f4c375f5abb487dbd184fbc150f31994d762(merged tree14d404c30d5e1dc7dbabea964c931b3b2754ad6a). Release, GCC 14.2.0, Ninja, Debian 13 VM, lavapipe (Mesa 26.1.6, LLVM 19).Results
git diff --checkcheck_conventions.pyagc_driver_image_array_rows_past_layer_limit. The 7 known failures also fail onmain.agc_driver_image_array_rows_past_layer_limit, rerun on the merged treeclear()line removedagc_shader_memoryon the merged tree, and withclear()removedVUID-lines compared withmainNew failure output (merged tree)
The assertion is at
core/libs/prx/libSceAgcDriver/tests/execution/ImageArrayRowsPastLayerLimit.cpp:205. It expectscapture->snapshot.registeredImages.size() == 1ufor a directly bound image.Negative control
I restored only
core/shader/recompiler/Optimization/src/ResourceMaterializer.cppfrommainand kept the PR'sSrtWalker.hpp, driver hook and test.agc_shader_memorythen failed, which matches the author's claim. After restoring the merged file and rebuilding,git status --porcelainwas clean.The new case does not cover the regression below: it binds only a buffer, and its hook ignores the views it receives.
Findings
Blocking
registeredImages.clear()drops directly bound image views, andagc_driver_image_array_rows_past_layer_limitfails. At ResourceMaterializer.cpp:2725, the clear runs aftermaterializeSnapshothas reset the snapshot (:1446) and registered the direct image views (:1525). Only the table views are added back. oneandonlydean pointed this out from reading the source in their comment. My test run backs it up:Beyond the test, this has two effects:
imageViewsCurrentnever sees a direct view whose own allocation moved, so it can accept exactly the snapshot it is meant to reject;Fix: delete the line. Each
continuealready goes back throughmaterializeSnapshot, which resets the snapshot, so views do not pile up across attempts.Non-blocking
The new test cannot see related moves. In
verifyAllocationChurnSnapshot(tests/ShaderMemory.cpp:2433-2437), the hook returns a preset answer and the plan binds a buffer only. I agree with the reviewer's request to add a directly bound image case that goes through the realCaptureRegisteredViewsCurrent, with two checks:registeredImages;With such a case, the regression above would have failed in
agc_shader_memoryitself.Descriptor-memory remap remains an open question. The reviewer's second point is that
descriptorScopecounts raw-page invalidations, while acceptance now relies only on image allocation identity. That point is still unanswered. I did not reproduce it. The new test'sdescriptorScopealways returns 0, so it does not exercise that path.Not verified
clear()removal. The script's comparison covers the merged tree as submitted.To get this to a good state
nextSnapshot.registeredImages.clear();, then check thatagc_driver_image_array_rows_past_layer_limitandagc_shader_memorypass.Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T16:53:28Z.
Review: CHANGES_REQUESTED
Re-checked — changes still requested
The new commit
0ac232a33aremovesnextSnapshot.registeredImages.clear(), which fixes the regression I flagged last time. One problem is still open: the change removes the only guard against descriptor memory being remapped during a capture, and nothing replaces it yet. The author agreed this is needed.What changed since my last review
0ac232a33a. Compared with9e07f78acb, the only difference is that thenextSnapshot.registeredImages.clear();line inResourceMaterializer.cppis gone. The test file is unchanged.clear()finding and report local runs:agc_driver_image_array_rows_past_layer_limitandagc_shader_memorypass, 2471 of 2471 CPU-only tests pass, and 1339 of 1340 GPU tests pass with the validation layer on. The one failure,agc_driver_scattered_runs, they attribute to their machine's udmabuf limit. I take these numbers as author-reported. For a later push they promise:CaptureRegisteredViewsCurrent;What I ran
Head
0ac232a33ac5ebc51e76bea71048c18e0394afc2merged intomain4f41f4c375f5abb487dbd184fbc150f31994d762(merged tree6e8a027e41b63b3061b31e416e6eae561de5016b). Release build with GCC 14.2.0 and Ninja, on a Debian 13 VM with lavapipe (Mesa 26.1.6, LLVM 19).git diff --checkcheck_conventions.pymainagc_driver_image_array_rows_past_layer_limit9e07f78acbagc_shader_memoryVUID-lines compared withmainNegative control: I did not run it again. The test file and the code it exercises are the same as in my last review, where
agc_shader_memoryfailed withmain'sResourceMaterializer.cpp. The only change since then is the removed line, which this test does not reach, because it binds only a buffer.Previous findings
registeredImages.clear()drops directly bound image views (blocking): Resolved.agc_driver_image_array_rows_past_layer_limitpasses on the merged tree.registeredImagesaftermaterializeSnapshot, so views do not pile up across attempts.agc_shader_memorydrivesCaptureRegisteredViewsCurrentto a refusal. The author has promised this case.descriptorScopein the driver (ShaderMemory.cpp:576-590) returnsrawInvalidations, which counts raw-page invalidations, not mapping changes.main, and both the author and oneandonlydean agree it must be handled.New findings
Blocking
None beyond finding 3 above.
Non-blocking
None.
Not verified
To get this to a good state
Make descriptor-memory backing stability its own acceptance condition. It should not depend on whether image views are current. As the author proposes, accept an attempt only if the pages its descriptors were read from still have the same backing. Add a deterministic test that remaps descriptor memory in the middle of a capture and checks that the retry reads the new bytes.
Add the directly bound sampled array image case through the real
CaptureRegisteredViewsCurrent:registeredImages;Keep the existing buffer case as the positive control.
Run the negative control again for each new case, with
main'sResourceMaterializer.cppand driver hook.Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T17:25:58Z.
Review: APPROVED
Re-checked — approved
Commit
5061d3e9cais new since my last review. It does three things:ShaderMemorynow records which guest allocations back each page.Both items still open from my last review are resolved.
What changed since my last review
5061d3e9ca.PageBackinghashes the allocation ranges over a page: address, bytes, allocation address, backing serial and access flags.addPagestores this hash inPage::backing.imageViewsCurrentis renamedsnapshotCurrent. It first runspagesCurrent(), which resets and re-prepares every page whose backing changed, thenCaptureRegisteredViewsCurrent.preparePageis split out ofpage()so a reset page goes through the same setup as a new one.verifySnapshotAllocationMovesadded. It has two parts:CaptureRegisteredViewsCurrent, in two cases: an unrelated mapping and a resize of the image's own range.ShaderMemory::Capturewhose T# page is rewritten and remapped while the second page is read.imageViewsCurrentand describes only the view check. The hook is nowsnapshotCurrent, and the commit message describes it correctly.What I ran
Head
5061d3e9ca4841422bed9d4b4ac130336b52be23merged intomain1e658521a0a599872612bb91949311e2956b5283(merged tree8416e217939a3d83a10209949b2a93788e04d5cb), Release build with GCC 14.2.0 and Ninja, Debian 13 VM, lavapipe (Mesa 26.1.6, LLVM 19).git diff --checkcheck_conventions.pymain.agc_shader_memoryagc_driver_image_array_rows_past_layer_limitVUID-lines compared withmaingit status --porcelainempty,agc_shader_memorypasses againNegative control
The new tests use the new
SrtRuntime::snapshotCurrentfield, so they do not build againstmain's files. Instead I changed one production line at a time on the merged tree:snapshotCurrentignorespagesCurrent()'s result (view check only)after the page holding T# was remapped during the capture, the snapshot kept the T# read before the remapsnapshotCurrenthook (main's retry-on-any-move rule)main: retries re-read the cached page.Materializenever consults the hook (always accepts a moved generation)allocation churn: without an image view check, a snapshot taken while the allocation generation moved was acceptedCaptureRegisteredViewsCurrentalways returns truean attempt during which the image's own range changed was accepted instead of retried with the new rangeI did not re-run the author's "
clear()back in" control.Previous findings
registeredImages.clear()dropped directly bound views (blocking): Resolved. It was resolved in0ac232a33a. The new unrelated-mapping case now asserts that the view is kept (kept && rangeBytes == RangeBytes).CaptureRegisteredViewsCurrentto a refusal and checks that the retry carries the new range.mainhad the same stale-cache hole.New findings
Blocking
None.
Non-blocking
pagesCurrentresetsvalidandrawbut notreadorrecent.collect(ShaderMemory.cpp:967-975) emitspage.wordsfor everyreadmark.Regions()reports the word cached under the old backing.read/recentfor a page whose backing changed, or say why stale marks are harmless there.imageViewsCurrentand describes only the view check. It should mention the page-backing condition and the newverifySnapshotAllocationMovestest.Not verified