fix(agc): disturb a snapshot attempt by guest mappings only when its image views changed #15399
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15399"
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 JJenkx on 2026-11-03T05:17:50Z.
What
A further empty-view case is now handled: when a capture contains neither registered image views nor table-view identities, unrelated generation churn no longer forces a stable-generation recheck. Descriptor-source identity is still checked first; a remap of descriptor backing still disturbs the attempt. Captures containing any view keep the generation bracket and all view checks. This follow-up is B-Howell's
63c8907c7942c27199e114c9c8808895bf67631d, adopted with their authorship and co-author attribution preserved.A runtime resource snapshot is taken up to three times, and an attempt counts as disturbed when the image-view generation moves during it. That generation is
GuestAllocationsGeneration, which every guest map or unmap anywhere advances, including ordinary heap traffic: the application heap's defaultmalloc/free/realloc(ApplicationHeap.cpp) go throughGuestHeap, whose every allocation and free opens aGuestAllocations::Mutation. A title that maps or unmaps memory while a snapshot is taken therefore disturbs every attempt, even when none of the image views the snapshot captured were touched, and the title ends withruntime resource snapshot did not stabilize.Seen in Code Violet (PPSA26528) on
main128b5c49bawith per-attempt logging (a local diagnostic, not part of this PR): all three attempts were disturbed by the image generation alone, with the descriptor scope unchanged:Each captured image view already records the result of the
GuestAllocationsLookupit was normalized from (range, allocation, backing serial, access flags). This adds an optionalSrtRuntime::imageViewCurrentcallback;ShaderMemoryimplements it by repeating that lookup and comparing every recorded field (a view captured without a range must still have none). When the generation moved during an attempt,Materializenow counts the attempt as disturbed only if one of the image views it captured, inregisteredImagesor in a table'sresourceViews, is no longer current. A runtime without the callback keeps the old rule, and the exception path is unchanged. This matches how the recompile cache already keys a snapshot (Recompiler.cpp): it mixes every per-view lookup field and leaves the generation out. The recheck runs in a pass the generation must hold across, like the registered-view checks in the dispatch cache and graphics resources: if the generation moves during the pass, the pass runs once more, and if it moves again the attempt counts as disturbed. The snapshot keeps the generation of the pass that confirmed its views.Descriptor memory is checked the same way. Every page the capture reads keeps the identity (address, size,
backingSerial) of the guest allocation it was read from, andSrtRuntime::sourcesCurrent(ShaderMemory::sourcesCurrent) rechecks them at the start of each recheck pass: pages whose allocation changed are dropped from the capture's cache and the attempt is disturbed, so a retry reads fresh descriptor words. Allocations no read touched still do not disturb it.Scope: the old rule also treated any unrelated mapping change as a disturbance. Reads of memory that is unmapped during an attempt still fail through
readWordsand the exception path, which keeps the generation check.Tested
Current-main refresh: head
44498d7819bc7877520bb33a56391bed24a09024is the four original PR commits rebased onto main086c0686c8adff3ee648fdbe34e0b0b647e1d511, followed by B-Howell's empty-view fix/test. The original four patches are unchanged by rebase (range-diff attached).Linux 7.2.11, GCC 16.2.1 Release: test-only negative
5f8ca565223e6930c5a6310201f764710ffd20b0uses the same rebased old production code plus the new fixture. Bothagc_shader_memoryandagc_shader_type_zero_image_materializationfail withruntime resource snapshot did not stabilize. On the new head both pass with the ICD disabled, including the source-remap refusal and existing changed-view/backing-remap assertions. The no-view case verifies that source checks still run, no view checks run, the T# is retained, and no image-allocation generation is bound.The same focused 15-case Vulkan suite passes 15/15 on main
086c068and on this head, withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1, the real Khronos validation layer, and the same profiling environment on the same RX 6650 XT/RADV 26.2.6 host. Layer insertion and GPU selection are confirmed; no skips or VUIDs, source/library hashes unchanged. Patch, raw paired logs, negative/positive fixtures and rebase proof, SHA-256c330b2cd390cdc6ea240466bccac7cf4237c5edb4d4c30ab395f5c0ff8f0ef5a(internal manifest and upload digest verified). The negative fixture is also fetchable atJJenkx:evidence/pr15399-zero-view-negative-20261103. Conventions and whitespace checks pass.These are new Linux host/GPU checks, not new Windows, God of War Ragnarök or FPS results. B-Howell's broader Windows/title observations remain attributed to their comment and original pins. Earlier title results and reviewer approvals below retain their original heads. Existing documented limitations are unchanged.
tests/ShaderMemory.cppadds a capture whose pending-write query maps and unmaps an unrelated 64-byte guest allocation on every read, so the generation moves during every attempt while the captured views stay current. It must stabilize and capture the descriptor. Onmain7feb37ee3ewith only this test, the capture throwsruntime resource snapshot did not stabilize; with this change all ofagc_shader_memory_testspasses (Linux, GCC 16.2.1, Release).verifyImageViewChangeDuringRecheckdrivesCaptureResourceswith a hand-builtSrtRuntimewhose first view check replaces the view's mapping before the recheck ends; the kept snapshot must hold the replaced mapping's identity and the current generation. On the previous head6835d3db96with only this test it fails (image view recheck: a snapshot kept a view whose mapping changed while the views were rechecked); with the changeagc_shader_memory_testspasses.A further block registers the SRT page as a guest allocation, reads it word by word, and once all eight T# words have been read rewrites the T# to another image and remaps the SRT's backing; the image allocations stay current. The kept snapshot must hold the new T# and not the old one. On the previous head
9391c9f155with only this block it fails (descriptor backing: a capture kept descriptor words read before their memory was remapped); with the changeagc_shader_memory_testspasses.Code Violet (PPSA26528), same machine, scripted input,
APS5_PROFILE_DRAW=1(the profiler slows the snapshot, so profiled runs abort more often), 110 s per run,mainand this change alternating:runtime resource snapshot did not stabilizemain128b5c49bacv-ic-main3, exit 134)main7feb37ee3e7feb37ee3eis128b5c49baplus 237maincommits, none of which changesResourceMaterializer.cpp,SrtWalker.hpporShaderMemory.cpp. The abort is intermittent, so these counts alone are weak evidence. A local diagnostic build of this change (not part of this PR) counted the attempts in profiled runs: in two runs, 73,728 and 94,208 attempts, the guest allocation generation moved during 22 and 36 of them. Every one of those attempts still had all its captured image views current (0 views changed), somainwould have retried each of them, and three in a row end the title. Neither run aborted. That is the case this change accepts andmainretries.No claim is made for Mortal Shell II (PPSA34008); its one snapshot abort could not be attributed.
Related AGC GPU tests on this change at
7a9ecdc365(ctest -R "^agc_.*(snapshot|srt|descriptor|materializ|capture|shader_|bindless|resource|image|layer|registered)|^agc_driver_graphics$", withVK_LAYER_KHRONOS_validation,ANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1, AMD Radeon RX 6650 XT): 204 of 204 pass, the layer is inserted in 122 of them, and there are noVUID-lines. On the previous head9391c9f155with only the new descriptor-backing block, the same set failsagc_shader_memoryandagc_shader_type_zero_image_materialization; both run the function that holds the new tests.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)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-03T05:22:46Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The post-capture image-view validation can miss a mapping change that occurs during its own lookup pass, allowing a stale snapshot to be accepted.
What I ran
Reviewed all four changed files at head
6835d3db96406fffbe19d7111202e3fb29cda4f8, against PR based1ae628bc2f62459cce1e9872ba5632c938c71f2. The no-build merge preview against that base was clean. Environment: Debian Linux x86_64, Python 3.11.2, GCC 12.2.0; no compiler or build was run.Results
agc_shader_memory_teststarget includes this source.Precheck checks and raw output
Precheck output:
Hosted check snapshot at final refresh:
Negative control
The author reports that the new regression fails on
maincommit7feb37ee3ewhen run without this change, and that 204 focused tests passed on an AMD Radeon RX 6650 XT. I did not independently reproduce either result because both require building and running the C++ tests.Findings
Blocking
At the end of the capture,
afterImageGenerationis sampled before theimageViewCurrentcallbacks run. If a captured image mapping changes after its identity was checked but before the lookup pass finishes,imagesMoved()can still return false and the snapshot is accepted even though that view is stale. The adjacent repository checks for registered views bracket their lookup loops with generation reads; this path does not. Please make the validation safe against a registry change during the revalidation pass, and add a regression where a captured view changes during that pass.Non-blocking
None.
Sources
Not verified
I did not run a local build, CTest, GPU or console test, or an independent negative control. All six hosted policy checks were pending when last checked; no hosted AGC/shader test run was available. The optional ABI and test-quality helper scripts could not run in the isolated PR snapshot.
To get this to a good state
Ensure a relevant mapping change cannot slip past the view-validation pass, and add a regression that exercises a captured-view change during validation. I will rerun the no-build precheck and inspect the full diff on the new head; the focused C++/GPU checks should also be rerun there.
Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T07:18:18Z.
Review: APPROVED
Reviewed — approved
The merged tree builds and the selected tests show no new failures. Both new regressions fail when their production change is reverted, which confirms the earlier blocking finding (a view changing during the recheck) is fixed.
What I ran
Head
9391c9f15503043d80c7a88f252386d38337d91c,maind1ae628bc2f62459cce1e9872ba5632c938c71f2, merged with--no-ffin a clean worktree (merged tree0849c9523cb8a7877a46d6fa836e1e03f6cf8a1c). Machine: Debian 13 VM, 32 vCPU (two Intel Xeon Gold 6136, AVX2/FMA), GCC 14.2.0, Release, Ninja, Vulkan through lavapipe (Mesa 26.1.6, LLVM 19), no GPU.Results
git diff --checkcheck_conventions.pylibs(script)check_skips.py), 0 new failures, 0 timeouts. 7 failures are also onmain:agc_driver_division,agc_driver_f32_denormal_flush,agc_driver_f64_div_scale_denormal_modes,agc_driver_f64_fma_denormal_modes,agc_driver_mullit_f32_denormal_modes,unwrap_self_..._group,vector_constant_factor_tininessmain(script, lavapipe)VUID-linesagc_shader_memory,agc_shader_type_zero_image_materialization(merged tree)git status --porcelainempty; both tests pass again after the rebuildNegative control
The two new checks run from
verifyTypeZeroImageMaterialization, so they run underagc_shader_type_zero_image_materialization.Execution/src/ShaderMemory.cppfrommain(noimageViewCurrentcallback, so the old rule applies)runtime resource snapshot did not stabilize(the unrelated-churn capture)ResourceMaterializer.cppfrom the previous head6835d3db96(recheck without the generation bracket)image view recheck: a snapshot kept a view whose mapping changed while the views were recheckedResourceMaterializer.cppfrommainruntime resource snapshot did not stabilizeControl B confirms the author's claim. It also shows that the blocking finding in MarcZX10's review of
6835d3db96is fixed by335dc0429b. I did not revertSrtWalker.hpp: the test sets the new field, so the test would not compile without it.Control outputs
Findings
Blocking
None.
Non-blocking
maineither.descriptorScopeonly returnsrawInvalidations(ShaderMemory.cpp L579-L593). Those count pending-write invalidations, not mapping changes. So when descriptor memory is remapped while all captured image identities stay current, the attempt is now accepted (ResourceMaterializer.cpp L2728-L2743).ShaderMemorypage cache persists across the three attempts of one capture:page->words(L546-L547);main, a retry caused by the generation alone mostly re-reads the same cached descriptor bytes. It does not reliably get fresh ones.Not verified
6835d3d, not9391c9f.SrtRuntimeproducers should also setimageViewCurrent. Those without it keep the old rule, which is safe.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-03T07:39:52Z.
Review: APPROVED
Re-checked — new head, looks good
The generation-bracketed image recheck and deterministic regression address my prior blocker; applicable hosted checks and the independent exact-head build/test report pass.
What I ran
Reviewed the complete 68-line delta from previously reviewed head
6835d3db96406fffbe19d7111202e3fb29cda4f8to current head9391c9f15503043d80c7a88f252386d38337d91c, against based1ae628bc2f62459cce1e9872ba5632c938c71f2;git diff --checkpassed. I inspected the image-generation bracket, callback implementation, regression, descriptor read caching and exact-head hosted checks. Environment: Debian Linux x86_64, Python 3.11.2, GCC 12.2.0. I did not build or run CTest locally.Results
Unedited hosted check output
Negative control
I did not run a negative control. The author and independent reviewer report that reverting the image-generation bracket makes the new regression fail; the independent report also says reverting the relevant
ShaderMemory.cpp/ResourceMaterializer.cppvariants fails the test. These are reported results, not runs I performed.Findings
Blocking
None found in this head. The new generation bracket addresses the stale image-view validation race from my prior review.
Non-blocking
Descriptor backing remaps during capture remain a separate consistency question.
descriptorScopereports raw-page invalidations, while the image-view generation covers guest-allocation layout changes; descriptor pages may remain cached through a retry. The previous generation-only retry therefore did not itself prove fresh descriptor bytes were reread. I do not consider this a regression introduced by the current change or a blocker for this approval. If capture must guarantee consistency across descriptor remaps, handle that separately by invalidating affected cached descriptor ranges and adding a deterministic test.Sources
Not verified
I did not independently compile, run the lavapipe tests, execute negative controls, run on a physical GPU or test console behavior. The independent reviewer reports Debian 13, GCC 14.2.0 and lavapipe; the author's AMD hardware run is separate reported evidence.
To get this to a good state
No change is requested for this head. If descriptor-remap consistency is pursued, add it as a separate change with a targeted cache-invalidation regression. I will rerun the no-build checks and review any new head.
Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T08:05:53Z.
Review: APPROVED
Re-checked — approved
The new commit
7a9ecdc365makes a remap of the memory that descriptor words were read from disturb the snapshot attempt and drop those cached pages. Its regression fails without the change and passes with it. Two non-blocking gaps remain in how far this guard reaches.What changed since my last review
7a9ecdc365. Commits 1–3 are unchanged (the range-diff shows them as equal).ShaderMemory::Pagenow records the guest allocation (address, size,backingSerial) found at the page base when the page is created.SrtRuntime::sourcesCurrentcallback (ShaderMemory::sourcesCurrent) rechecks those records. It drops pages whose allocation changed and reports the attempt as disturbed.ResourceMaterializercalls it at the start of each generation-bracketed recheck pass.What I ran
Head
7a9ecdc3652c481d545de4726a15be0995beaaf5,maind1ae628bc2f62459cce1e9872ba5632c938c71f2, merged with--no-ffin a clean worktree (merged treecbbf0d4df8c529f5a44f818c319c5f206e3d7c1b). Machine: Debian 13 VM, 32 vCPU (two Intel Xeon Gold 6136), GCC 14.2.0, Release, Ninja, Vulkan through lavapipe (Mesa 26.1.6, LLVM 19), no GPU.git diff --checkcheck_conventions.pylibs(script)check_skips.py), 0 new failures, 0 timeouts. The 7 failures (agc_driver_division, the four denormal-mode tests,unwrap_self_..._group,vector_constant_factor_tininess) also fail onmain.main(script, lavapipe)VUID-linesagc_shader_memory/agc_shader_type_zero_image_materializationdescriptor backing: a capture kept descriptor words read before their memory was remappedgit status --porcelainempty; both tests pass again (8.90 s total)Control E shows that the new test fails because
sourcesCurrentis not called. The newPagefields alone do not make it pass.Previous findings
New findings
Blocking
None.
Non-blocking
GuestAllocationskeeps one flat range per allocation. Heap blocks are registered one by one (GuestHeap.cpp L302-L303), so a 4 KiBShaderMemorypage can hold several ranges.GuestAllocationsLookup(base). A descriptor table in an allocation that starts inside the page is not covered: removing and re-adding that allocation is not seen, because the lookup at the page base returns the same range, or none, as before.sourcesCurrentruns only insideimagesMoved().imagesMoved()is short-circuited when thedescriptorScopecondition is already true.rawInvalidationsalso disturbed. The pages are not dropped. The next attempt samplesbeforeImageGenerationafter the remap, so its generation does not move and the stale cached words are accepted.mainhas the same page-cache staleness on a generation retry, so this is not a regression.sourcesCurrentwhenever the generation moved, before or independently of thedescriptorScopecheck.Not verified
7a9ecdc365are the author's.6835d3dand9391c9f, not this head.sourcesCurrent(one locked registry lookup per cached page, on each recheck pass of an attempt whose generation moved) under a title load.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-03T08:09:08Z.
Review: APPROVED
Re-checked — new head, approved
The descriptor-source identity check and regression for remapping those source pages address the prior blocker, and the exact-head Windows tests pass.
What I ran
Reviewed PR #15399 at head
7a9ecdc3652c481d545de4726a15be0995beaaf5, against based1ae628bc2f62459cce1e9872ba5632c938c71f2. I inspected the complete 69-line delta across five files since the previously reviewed head; the precheck reports a clean merge preview. Environment: Debian Linux x86_64, Python 3.11.2, GCC 12.2.0, Git 2.39.5. GitHub Actions built the changed AGC test target and ran the Windows CTest selection. I did not build or run CTest locally.Results
Unedited check output
Precheck statuses:
The local test-quality heuristic also flagged
ShaderMemory.cppas possibly unregistered. I inspected the exact-head CMake fragment and confirmed it is compiled intoagc_shader_memory_testsand its CTest target is registered; the warning is a false positive.Windows CTest excerpts:
Applicable hosted checks on the exact head: Windows, conventions, eligibility, intake, labels, library portability, report and relinker jobs passed; Linux and specialized jobs were skipped by workflow filters. The PR description reports its RX 6650 XT focused run with validation enabled, 204/204 passing and no
VUID-lines. That hardware run was not independently reproduced here.Negative control
9391c9f155and on this head.7a9ecdc365. I did not reproduce this locally.Findings
Blocking
None found in the reviewed source and test delta.
Non-blocking
The focused AMD/Vulkan run is author-reported; this review independently confirms the exact-head Windows build and tests, not the AMD hardware result or console behavior.
Sources
Not verified
I did not run local compilation, CTest, the AMD/Vulkan validation suite, or console behavior. The attached independent AMD log describes the previous head
9391c9f155, so I did not count it as evidence for the new head; the exact-head AMD results are the author's report in the PR discussion.To get this to a good state
No code change is requested for this head. If it changes, I will review the new delta and rerun the applicable checks.
Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T20:50:57Z.
Review: APPROVED
Re-checked — approved
The new commit
44498d7819lets a recheck pass accept an attempt that captured no image view as soon as its descriptor sources are current, without waiting for the generation to hold. Its new test fails without the change and passes with it. No blocking issue remains.What changed since my last review
main086c068with no changes (delta.patch shows=for all four).44498d7819(B-Howell's63c8907c79, adopted):ResourceMaterializer.cpp(+4):imagesMoved()computesviewsCaptured, which is true whenregisteredImagesor any tableresourceViewsentry has identities. When nothing was captured, the pass returns "not moved" right aftersourcesCurrentsucceeds, so the generation bracket no longer applies.tests/ShaderMemory.cpp: newverifyUnviewedSnapshotDuringMappingChurn. The generation moves on every read. With sources current, the capture must be accepted with no view checks,imageAllocationGeneration == 0and the T# kept. With sources stale, it must end withdid not stabilizeafter 3 source checks.What I ran
Head
44498d7819bc7877520bb33a56391bed24a09024,main086c0686c8adff3ee648fdbe34e0b0b647e1d511, merged with--no-ffin a clean worktree (merged treec4e529728923afee0c33f1b5e156f8c7ccd5844b). Machine: Debian 13 VM, 32 vCPU (two Intel Xeon Gold 6136), GCC 14.2.0, Release, Ninja, Vulkan through lavapipe (Mesa 26.1.6, LLVM 19), no GPU.git diff --checkcheck_conventions.pylibs(script)check_skips.py). 0 new failures, 0 timeouts. The 7 failures also fail onmain.agc_driver_alpha_to_coverage_sample_mask_exportpassed on rerun.main(script)agc_driver_image_gather_volume, was flagged with newVKSamplerCreateInfo-addressMode*VUIDs marked "test not run on main".main086c068main(the baseline was older), not from this PR.git status --porcelainis empty.agc_shader_memory(8.4 s) andagc_shader_type_zero_image_materialization(0.02 s) pass.Negative control output
The negative control used only
ResourceMaterializer.cppfrom the previous head, because the new test needs the callbacks from the earlier commits to compile. It confirms the author's and B-Howell's reported result.Previous findings
ShaderMemory.cppis unchanged by the new commit: L332-L336 still records onlyGuestAllocationsLookup(base).sourcesCurrentis the only check left once the generation moves.maindoes not re-read cached pages on a generation retry either.imagesMoved()(and sosourcesCurrent) is still skipped when thedescriptorScopecondition is already true.New findings
Blocking
None.
Non-blocking
place()carry no page identity, or a stale one (B-Howell raised this in the discussion; I confirm it by reading the code, and the author's reply does not address it).addPageL293-L316 resets the masks but nothasRange,rangeAddress,rangeBytesorbackingSerial.page()sets them, at L330-L336.place()creates is reached fromspilland from thepaged || overlappingbranch ofsupplyWords. Such a page keeps whatever identity the pooled page had, orhasRange = falseif the page is new.sourcesCurrentcan then drop that page and report the attempt as disturbed even though nothing was remapped.Unwritten, ResourceMaterializer.cpp L1311-L1316). So I expect the effect to be an extra retry under churn, not stale data. That retry is the failure mode this PR is meant to remove.page()intoaddPage(), so every cached page records the allocation at its base. Add a test that spills a supplied block under generation churn.Not verified
place()finding comes from reading the code. I wrote no test for it.sourcesCurrentpasses under title load.Pull request closed