fix(agc): accept a resource snapshot when only unrelated allocations moved #15465

Merged
mrfelek merged 3 commits from upstream-pr/15465 into main 2026-11-03 21:09:00 +00:00
mrfelek commented 2026-11-03 13:16:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by mrfelek on 2026-11-03T13:16:01Z.


What

ResourceMaterializer::Materialize retries an attempt when the guest allocation generation moved during it, and throws runtime resource snapshot did not stabilize after 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.

  • New SrtRuntime hook imageViewsCurrent: whether the image views a snapshot registered still match their allocations.
  • The driver backs it with CaptureRegisteredViewsCurrent, the check the dispatch cache already uses for its variants.
  • Materialize accepts 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_BUFFER change, 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 case verifyAllocationChurnSnapshot with 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 throws did not stabilize. Negative control: with main's ResourceMaterializer.cpp and the new test, the case fails with runtime resource snapshot did not stabilize.
  • PPSA22408, Linux, RTX 3080 Ti, same menu route into the garage, no APS5_LOOP_GUARD (on main 5cb015caaa + #11346 + #11630 + the jump diff from #11346, plus local offline HTTP/2 stubs):
Tree Runs snapshot did not stabilize Garage
without this change 2 2 of 2, during loading (177 s, 185 s) not reached
with this change 2 0 of 2 loads

Earlier 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

  • 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 (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: PPSA22408 loading with #11346
  • GPUs tested: NVIDIA RTX 3080 Ti, driver 610 (open), Ubuntu 26.10 (game runs); agc_shader_memory needs no GPU
  • AI-assisted: yes

AI-assisted; the runs are from my machine(s).

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5137874874 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15465). Originally posted by [mrfelek](https://github.com/mrfelek) on 2026-11-03T13:16:01Z. --- ### What `ResourceMaterializer::Materialize` retries an attempt when the guest allocation generation moved during it, and throws `runtime resource snapshot did not stabilize` after 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. - New `SrtRuntime` hook `imageViewsCurrent`: whether the image views a snapshot registered still match their allocations. - The driver backs it with `CaptureRegisteredViewsCurrent`, the check the dispatch cache already uses for its variants. - `Materialize` accepts 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_BUFFER` change, 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 case `verifyAllocationChurnSnapshot` with 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 throws `did not stabilize`. Negative control: with `main`'s `ResourceMaterializer.cpp` and the new test, the case fails with `runtime resource snapshot did not stabilize`. - PPSA22408, Linux, RTX 3080 Ti, same menu route into the garage, no `APS5_LOOP_GUARD` (on `main` `5cb015caaa` + #11346 + #11630 + the jump diff from #11346, plus local offline HTTP/2 stubs): | Tree | Runs | `snapshot did not stabilize` | Garage | |---|---|---|---| | without this change | 2 | 2 of 2, during loading (177 s, 185 s) | not reached | | with this change | 2 | 0 of 2 | loads | Earlier 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 - [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 (attach them to this PR) - [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: none - [x] Unblocks: PPSA22408 loading with #11346 - [x] GPUs tested: NVIDIA RTX 3080 Ti, driver 610 (open), Ubuntu 26.10 (game runs); `agc_shader_memory` needs no GPU - [x] AI-assisted: yes AI-assisted; the runs are from my machine(s).
XairRrR commented 2026-11-03 13:38:10 +00:00 (Migrated from github.com)

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 every Materialize, not only when the generation moved. Because of that, agc_driver_image_array_rows_past_layer_limit now fails, and the test passes again once that line is deleted.

What I ran

Head 9e07f78acb5c87f1459ce04326010f42f085859d merged into main 4f41f4c375f5abb487dbd184fbc150f31994d762 (merged tree 14d404c30d5e1dc7dbabea964c931b3b2754ad6a). Release, GCC 14.2.0, Ninja, Debian 13 VM, lavapipe (Mesa 26.1.6, LLVM 19).

git diff --check 4f41f4c375f5abb487dbd184fbc150f31994d762...9e07f78acb5c87f1459ce04326010f42f085859d
python3 tools/check_conventions.py --base 4f41f4c375f5abb487dbd184fbc150f31994d762
ctest --test-dir build --output-on-failure -R '^(agc_driver_image_array_rows_past_layer_limit|agc_shader_memory)$'
# experiment: delete the `nextSnapshot.registeredImages.clear();` line, rebuild, rerun both tests
ninja -C build -j32 -l32
ctest --test-dir build --output-on-failure -R '^(agc_driver_image_array_rows_past_layer_limit|agc_shader_memory)$'
# negative control: main's ResourceMaterializer.cpp, PR's header and test
git show 4f41f4c375f5:core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp > core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp
ninja -C build -j32 -l32
ctest --test-dir build --output-on-failure -R '^agc_shader_memory$'
# restore merged file, rebuild, git status --porcelain (clean)

Results

Check Result
git diff --check clean
check_conventions.py All conventions checks passed
Configure / build / libs OK
Selected tests (2153 run, script) 1 new failure: agc_driver_image_array_rows_past_layer_limit. The 7 known failures also fail on main.
agc_driver_image_array_rows_past_layer_limit, rerun on the merged tree fails (reproduced)
Same test with only the clear() line removed passes
agc_shader_memory on the merged tree, and with clear() removed passes
Validation layer (script, 770 tests, layer loaded in 769, none missing) no new VUID- lines compared with main
New failure output (merged tree)
[Shaders/ShaderRegistry.cpp:901 ReportPreparedAtUse] Compute shader ... was not registered; preparing its artifact at dispatch
AGC graphics: still-rows: capture identity lost original provenance, effective geometry, or the registered extent

The assertion is at core/libs/prx/libSceAgcDriver/tests/execution/ImageArrayRowsPastLayerLimit.cpp:205. It expects capture->snapshot.registeredImages.size() == 1u for a directly bound image.

Negative control

I restored only core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp from main and kept the PR's SrtWalker.hpp, driver hook and test. agc_shader_memory then failed, which matches the author's claim. After restoring the merged file and rebuilding, git status --porcelain was 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

  1. registeredImages.clear() drops directly bound image views, and agc_driver_image_array_rows_past_layer_limit fails. At ResourceMaterializer.cpp:2725, the clear runs after materializeSnapshot has 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:

    • the existing execution test fails on the merged tree;
    • it passes with only that line removed.

    Beyond the test, this has two effects:

    • imageViewsCurrent never sees a direct view whose own allocation moved, so it can accept exactly the snapshot it is meant to reject;
    • draw and dispatch variants lose the recheck of those views before reuse.

    Fix: delete the line. Each continue already goes back through materializeSnapshot, which resets the snapshot, so views do not pile up across attempts.

Non-blocking

  1. 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 real CaptureRegisteredViewsCurrent, with two checks:

    • an unrelated move: the snapshot is accepted and the view is still in registeredImages;
    • a move of the image's own range: the snapshot is rejected.

    With such a case, the regression above would have failed in agc_shader_memory itself.

  2. Descriptor-memory remap remains an open question. The reviewer's second point is that descriptorScope counts 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's descriptorScope always returns 0, so it does not exercise that path.

Not verified

  • The PPSA22408 runs and the RTX 3080 Ti results; I launch no titles and have no GPU.
  • Whether a descriptor remap during capture can produce mixed descriptor words under the new acceptance rule (point 3).
  • Validation-layer behaviour after the clear() removal. The script's comparison covers the merged tree as submitted.

To get this to a good state

  1. Delete nextSnapshot.registeredImages.clear();, then check that agc_driver_image_array_rows_past_layer_limit and agc_shader_memory pass.
  2. Add the directly bound image cases (unrelated move accepted with the view kept; own range moved rejected) through the real driver check.
  3. Answer the descriptor-remap question: keep descriptor mapping stability as its own retry condition, or point to the rule that prevents a remap during capture.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5753119341 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15465#pullrequestreview-5753119341). Originally posted by [XairRrR](https://github.com/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 every `Materialize`, not only when the generation moved. Because of that, `agc_driver_image_array_rows_past_layer_limit` now fails, and the test passes again once that line is deleted. ## What I ran Head `9e07f78acb5c87f1459ce04326010f42f085859d` merged into `main` `4f41f4c375f5abb487dbd184fbc150f31994d762` (merged tree `14d404c30d5e1dc7dbabea964c931b3b2754ad6a`). Release, GCC 14.2.0, Ninja, Debian 13 VM, lavapipe (Mesa 26.1.6, LLVM 19). ``` git diff --check 4f41f4c375f5abb487dbd184fbc150f31994d762...9e07f78acb5c87f1459ce04326010f42f085859d python3 tools/check_conventions.py --base 4f41f4c375f5abb487dbd184fbc150f31994d762 ctest --test-dir build --output-on-failure -R '^(agc_driver_image_array_rows_past_layer_limit|agc_shader_memory)$' # experiment: delete the `nextSnapshot.registeredImages.clear();` line, rebuild, rerun both tests ninja -C build -j32 -l32 ctest --test-dir build --output-on-failure -R '^(agc_driver_image_array_rows_past_layer_limit|agc_shader_memory)$' # negative control: main's ResourceMaterializer.cpp, PR's header and test git show 4f41f4c375f5:core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp > core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp ninja -C build -j32 -l32 ctest --test-dir build --output-on-failure -R '^agc_shader_memory$' # restore merged file, rebuild, git status --porcelain (clean) ``` ## Results | Check | Result | |---|---| | `git diff --check` | clean | | `check_conventions.py` | All conventions checks passed | | Configure / build / libs | OK | | Selected tests (2153 run, script) | 1 new failure: `agc_driver_image_array_rows_past_layer_limit`. The 7 known failures also fail on `main`. | | `agc_driver_image_array_rows_past_layer_limit`, rerun on the merged tree | **fails** (reproduced) | | Same test with only the `clear()` line removed | passes | | `agc_shader_memory` on the merged tree, and with `clear()` removed | passes | | Validation layer (script, 770 tests, layer loaded in 769, none missing) | no new `VUID-` lines compared with `main` | <details><summary>New failure output (merged tree)</summary> ``` [Shaders/ShaderRegistry.cpp:901 ReportPreparedAtUse] Compute shader ... was not registered; preparing its artifact at dispatch AGC graphics: still-rows: capture identity lost original provenance, effective geometry, or the registered extent ``` The assertion is at `core/libs/prx/libSceAgcDriver/tests/execution/ImageArrayRowsPastLayerLimit.cpp:205`. It expects `capture->snapshot.registeredImages.size() == 1u` for a directly bound image. </details> ## Negative control I restored only `core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp` from `main` and kept the PR's `SrtWalker.hpp`, driver hook and test. `agc_shader_memory` then failed, which matches the author's claim. After restoring the merged file and rebuilding, `git status --porcelain` was 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 1. **`registeredImages.clear()` drops directly bound image views, and `agc_driver_image_array_rows_past_layer_limit` fails.** At [ResourceMaterializer.cpp:2725](https://github.com/boykopovar/AnyPS5/blob/9e07f78acb5c87f1459ce04326010f42f085859d/core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp#L2722-L2732), the clear runs after `materializeSnapshot` has reset the snapshot ([:1446](https://github.com/boykopovar/AnyPS5/blob/9e07f78acb5c87f1459ce04326010f42f085859d/core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp#L1446)) and registered the direct image views ([:1525](https://github.com/boykopovar/AnyPS5/blob/9e07f78acb5c87f1459ce04326010f42f085859d/core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp#L1525)). Only the table views are added back. oneandonlydean pointed this out from reading the source in their comment. My test run backs it up: - the existing execution test fails on the merged tree; - it passes with only that line removed. Beyond the test, this has two effects: - `imageViewsCurrent` never sees a direct view whose own allocation moved, so it can accept exactly the snapshot it is meant to reject; - draw and dispatch variants lose the recheck of those views before reuse. Fix: delete the line. Each `continue` already goes back through `materializeSnapshot`, which resets the snapshot, so views do not pile up across attempts. ### Non-blocking 2. **The new test cannot see related moves.** In `verifyAllocationChurnSnapshot` ([tests/ShaderMemory.cpp:2433-2437](https://github.com/boykopovar/AnyPS5/blob/9e07f78acb5c87f1459ce04326010f42f085859d/core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp#L2433-L2437)), 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 real `CaptureRegisteredViewsCurrent`, with two checks: - an unrelated move: the snapshot is accepted and the view is still in `registeredImages`; - a move of the image's own range: the snapshot is rejected. With such a case, the regression above would have failed in `agc_shader_memory` itself. 3. **Descriptor-memory remap remains an open question.** The reviewer's second point is that `descriptorScope` counts 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's `descriptorScope` always returns 0, so it does not exercise that path. ## Not verified - The PPSA22408 runs and the RTX 3080 Ti results; I launch no titles and have no GPU. - Whether a descriptor remap during capture can produce mixed descriptor words under the new acceptance rule (point 3). - Validation-layer behaviour after the `clear()` removal. The script's comparison covers the merged tree as submitted. ## To get this to a good state 1. Delete `nextSnapshot.registeredImages.clear();`, then check that `agc_driver_image_array_rows_past_layer_limit` and `agc_shader_memory` pass. 2. Add the directly bound image cases (unrelated move accepted with the view kept; own range moved rejected) through the real driver check. 3. Answer the descriptor-remap question: keep descriptor mapping stability as its own retry condition, or point to the rule that prevents a remap during capture. <!-- anyps5-bots job=3351 head=9e07f78acb5c87f1459ce04326010f42f085859d -->
XairRrR commented 2026-11-03 16:53:28 +00:00 (Migrated from github.com)

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 0ac232a33a removes nextSnapshot.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

  • One new commit, 0ac232a33a. Compared with 9e07f78acb, the only difference is that the nextSnapshot.registeredImages.clear(); line in ResourceMaterializer.cpp is gone. The test file is unchanged.
  • The author replied. They accept the clear() finding and report local runs: agc_driver_image_array_rows_past_layer_limit and agc_shader_memory pass, 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:
    • a directly bound image case that goes through the real CaptureRegisteredViewsCurrent;
    • a separate descriptor-backing stability condition, with a test that remaps descriptor memory in the middle of a capture.
  • The description and checklist did not change.

What I ran

Head 0ac232a33ac5ebc51e76bea71048c18e0394afc2 merged into main 4f41f4c375f5abb487dbd184fbc150f31994d762 (merged tree 6e8a027e41b63b3061b31e416e6eae561de5016b). Release build with GCC 14.2.0 and Ninja, on a Debian 13 VM with lavapipe (Mesa 26.1.6, LLVM 19).

git diff 9e07f78acb5c87f1459ce04326010f42f085859d 0ac232a33ac5ebc51e76bea71048c18e0394afc2
git diff --check 4f41f4c375f5abb487dbd184fbc150f31994d762...0ac232a33ac5ebc51e76bea71048c18e0394afc2
python3 tools/check_conventions.py --base 4f41f4c375f5abb487dbd184fbc150f31994d762
ctest --test-dir build --output-on-failure -R '^(agc_driver_image_array_rows_past_layer_limit|agc_shader_memory)$'
git status --porcelain
Check Result
git diff --check clean
check_conventions.py All conventions checks passed
Configure, build, libs (script) OK
Selected tests (script, 2153 run) no new failures and no timeouts; the 7 known failures also fail on main
agc_driver_image_array_rows_past_layer_limit passes (2.5 s); it failed at 9e07f78acb
agc_shader_memory passes (8.1 s)
Validation layer (script, 770 tests, layer loaded in 769, none missing) no new VUID- lines compared with main

Negative 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_memory failed with main's ResourceMaterializer.cpp. The only change since then is the removed line, which this test does not reach, because it binds only a buffer.

Previous findings

  1. registeredImages.clear() drops directly bound image views (blocking): Resolved.
    • The line is gone at ResourceMaterializer.cpp:2722-2731.
    • agc_driver_image_array_rows_past_layer_limit passes on the merged tree.
    • The table-view loop is now the only writer of registeredImages after materializeSnapshot, so views do not pile up across attempts.
  2. The new test cannot see related moves (non-blocking): Still open.
    • tests/ShaderMemory.cpp:2433-2437 is unchanged: the case still binds only a buffer, and its hook returns a preset answer.
    • Nothing in agc_shader_memory drives CaptureRegisteredViewsCurrent to a refusal. The author has promised this case.
  3. Descriptor-memory remap (previously non-blocking): Still open, now blocking.
    • The gap is real. The author's reply confirms that the allocation-generation check was the only guard against descriptor memory being remapped during a capture.
    • Why the scope counter does not catch it. descriptorScope in the driver (ShaderMemory.cpp:576-590) returns rawInvalidations, which counts raw-page invalidations, not mapping changes.
    • What the PR does. At ResourceMaterializer.cpp:2728, a moved generation is now accepted whenever the registered image views are still current.
    • Consequence. If the pages descriptors were read from are remapped in the middle of an attempt, and no image view's allocation changes, the attempt is accepted. The snapshot can then hold stale or mixed descriptor words.
    • Why this is now blocking. It is a correctness regression compared with 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

  • The PPSA22408 runs and the RTX 3080 Ti results. I do not launch titles and have no GPU.
  • The author's full local test run (2471/2471 CPU-only, 1339/1340 GPU tests). I accept it as author-reported.
  • Whether a descriptor remap can actually happen during a capture in practice. I did not build a reproducer.

To get this to a good state

  1. 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.

  2. Add the directly bound sampled array image case through the real CaptureRegisteredViewsCurrent:

    • an unrelated move is accepted and the view stays in registeredImages;
    • a move of the image's own range is rejected.

    Keep the existing buffer case as the positive control.

  3. Run the negative control again for each new case, with main's ResourceMaterializer.cpp and driver hook.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5756232339 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15465#pullrequestreview-5756232339). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-11-03T16:53:28Z. **Review:** CHANGES_REQUESTED --- # Re-checked — changes still requested The new commit 0ac232a33a removes `nextSnapshot.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 - **One new commit, `0ac232a33a`.** Compared with `9e07f78acb`, the only difference is that the `nextSnapshot.registeredImages.clear();` line in `ResourceMaterializer.cpp` is gone. The test file is unchanged. - **The author replied.** They accept the `clear()` finding and report local runs: `agc_driver_image_array_rows_past_layer_limit` and `agc_shader_memory` pass, 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: - a directly bound image case that goes through the real `CaptureRegisteredViewsCurrent`; - a separate descriptor-backing stability condition, with a test that remaps descriptor memory in the middle of a capture. - **The description and checklist did not change.** ## What I ran Head `0ac232a33ac5ebc51e76bea71048c18e0394afc2` merged into `main` `4f41f4c375f5abb487dbd184fbc150f31994d762` (merged tree `6e8a027e41b63b3061b31e416e6eae561de5016b`). Release build with GCC 14.2.0 and Ninja, on a Debian 13 VM with lavapipe (Mesa 26.1.6, LLVM 19). ``` git diff 9e07f78acb5c87f1459ce04326010f42f085859d 0ac232a33ac5ebc51e76bea71048c18e0394afc2 git diff --check 4f41f4c375f5abb487dbd184fbc150f31994d762...0ac232a33ac5ebc51e76bea71048c18e0394afc2 python3 tools/check_conventions.py --base 4f41f4c375f5abb487dbd184fbc150f31994d762 ctest --test-dir build --output-on-failure -R '^(agc_driver_image_array_rows_past_layer_limit|agc_shader_memory)$' git status --porcelain ``` | Check | Result | |---|---| | `git diff --check` | clean | | `check_conventions.py` | All conventions checks passed | | Configure, build, libs (script) | OK | | Selected tests (script, 2153 run) | no new failures and no timeouts; the 7 known failures also fail on `main` | | `agc_driver_image_array_rows_past_layer_limit` | passes (2.5 s); it failed at `9e07f78acb` | | `agc_shader_memory` | passes (8.1 s) | | Validation layer (script, 770 tests, layer loaded in 769, none missing) | no new `VUID-` lines compared with `main` | **Negative 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_memory` failed with `main`'s `ResourceMaterializer.cpp`. The only change since then is the removed line, which this test does not reach, because it binds only a buffer. ## Previous findings 1. **`registeredImages.clear()` drops directly bound image views (blocking): Resolved.** - The line is gone at [ResourceMaterializer.cpp:2722-2731](https://github.com/boykopovar/AnyPS5/blob/0ac232a33ac5ebc51e76bea71048c18e0394afc2/core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp#L2722-L2731). - `agc_driver_image_array_rows_past_layer_limit` passes on the merged tree. - The table-view loop is now the only writer of `registeredImages` after `materializeSnapshot`, so views do not pile up across attempts. 2. **The new test cannot see related moves (non-blocking): Still open.** - [tests/ShaderMemory.cpp:2433-2437](https://github.com/boykopovar/AnyPS5/blob/0ac232a33ac5ebc51e76bea71048c18e0394afc2/core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp#L2433-L2437) is unchanged: the case still binds only a buffer, and its hook returns a preset answer. - Nothing in `agc_shader_memory` drives `CaptureRegisteredViewsCurrent` to a refusal. The author has promised this case. 3. **Descriptor-memory remap (previously non-blocking): Still open, now blocking.** - **The gap is real.** The author's reply confirms that the allocation-generation check was the only guard against descriptor memory being remapped during a capture. - **Why the scope counter does not catch it.** `descriptorScope` in the driver ([ShaderMemory.cpp:576-590](https://github.com/boykopovar/AnyPS5/blob/0ac232a33ac5ebc51e76bea71048c18e0394afc2/core/libs/prx/libSceAgcDriver/Execution/src/ShaderMemory.cpp#L576-L590)) returns `rawInvalidations`, which counts raw-page invalidations, not mapping changes. - **What the PR does.** At [ResourceMaterializer.cpp:2728](https://github.com/boykopovar/AnyPS5/blob/0ac232a33ac5ebc51e76bea71048c18e0394afc2/core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp#L2728-L2730), a moved generation is now accepted whenever the registered image views are still current. - **Consequence.** If the pages descriptors were read from are remapped in the middle of an attempt, and no image view's allocation changes, the attempt is accepted. The snapshot can then hold stale or mixed descriptor words. - **Why this is now blocking.** It is a correctness regression compared with `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 - The PPSA22408 runs and the RTX 3080 Ti results. I do not launch titles and have no GPU. - The author's full local test run (2471/2471 CPU-only, 1339/1340 GPU tests). I accept it as author-reported. - Whether a descriptor remap can actually happen during a capture in practice. I did not build a reproducer. ## To get this to a good state 1. **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. 2. **Add the directly bound sampled array image case through the real `CaptureRegisteredViewsCurrent`:** - an unrelated move is accepted and the view stays in `registeredImages`; - a move of the image's own range is rejected. Keep the existing buffer case as the positive control. 3. **Run the negative control again for each new case,** with `main`'s `ResourceMaterializer.cpp` and driver hook. <!-- anyps5-bots job=3452 head=0ac232a33ac5ebc51e76bea71048c18e0394afc2 -->
XairRrR commented 2026-11-03 17:25:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T17:25:58Z.

Review: APPROVED


Re-checked — approved

Commit 5061d3e9ca is new since my last review. It does three things:

  • ShaderMemory now records which guest allocations back each page.
  • When the allocation generation moves, it drops any page whose backing changed and retries the attempt.
  • It adds tests for the directly bound image's own-range move and for a descriptor remap in the middle of a capture.

Both items still open from my last review are resolved.

What changed since my last review

  • New commit 5061d3e9ca.
    • PageBacking hashes the allocation ranges over a page: address, bytes, allocation address, backing serial and access flags.
    • addPage stores this hash in Page::backing.
    • The hook imageViewsCurrent is renamed snapshotCurrent. It first runs pagesCurrent(), which resets and re-prepares every page whose backing changed, then CaptureRegisteredViewsCurrent.
    • preparePage is split out of page() so a reset page goes through the same setup as a new one.
  • Test verifySnapshotAllocationMoves added. It has two parts:
    • A directly bound sampled 1D-array image, checked through the real CaptureRegisteredViewsCurrent, in two cases: an unrelated mapping and a resize of the image's own range.
    • A real ShaderMemory::Capture whose T# page is rewritten and remapped while the second page is read.
  • The author replied with a negative-control table and a full local run: 2471/2471 CPU-only tests and 1339/1340 GPU tests. I take the full run as author-reported. I re-ran the negative controls myself (below).
  • The description was not updated for the third commit: it still names the hook imageViewsCurrent and describes only the view check. The hook is now snapshotCurrent, and the commit message describes it correctly.

What I ran

Head 5061d3e9ca4841422bed9d4b4ac130336b52be23 merged into main 1e658521a0a599872612bb91949311e2956b5283 (merged tree 8416e217939a3d83a10209949b2a93788e04d5cb), Release build with GCC 14.2.0 and Ninja, Debian 13 VM, lavapipe (Mesa 26.1.6, LLVM 19).

git diff --check 1e658521a0a599872612bb91949311e2956b5283...5061d3e9ca4841422bed9d4b4ac130336b52be23
python3 tools/check_conventions.py --base 1e658521a0a599872612bb91949311e2956b5283
ctest --test-dir build --output-on-failure -R "^(agc_shader_memory|agc_driver_image_array_rows_past_layer_limit)$"
# negative controls (each: edit one production line, ninja -C build tests/agc_shader_memory_tests, run, restore from the merged tree)
ninja -C build -j32 -l32 tests/agc_shader_memory_tests
build/tests/agc_shader_memory_tests
git status --porcelain
Check Result
git diff --check clean
check_conventions.py All conventions checks passed
Configure, build, libs (script) OK
Selected tests (script, 2160 run) no new failures, no timeouts. The 7 known failures also fail on main.
agc_shader_memory passes (8.1 s)
agc_driver_image_array_rows_past_layer_limit passes (2.7 s)
Validation layer (script, 772 tests, layer loaded in 771, none missing) no new VUID- lines compared with main
Worktree after the controls git status --porcelain empty, agc_shader_memory passes again

Negative control

The new tests use the new SrtRuntime::snapshotCurrent field, so they do not build against main's files. Instead I changed one production line at a time on the merged tree:

Production change Result
snapshotCurrent ignores pagesCurrent()'s result (view check only) fails: after the page holding T# was remapped during the capture, the snapshot kept the T# read before the remap
Driver sets no snapshotCurrent hook (main's retry-on-any-move rule) fails with the same remap message. This confirms the author's point that the gap was also on main: retries re-read the cached page.
Materialize never consults the hook (always accepts a moved generation) fails: allocation churn: without an image view check, a snapshot taken while the allocation generation moved was accepted
CaptureRegisteredViewsCurrent always returns true fails: an attempt during which the image's own range changed was accepted instead of retried with the new range

I did not re-run the author's "clear() back in" control.

Previous findings

  1. registeredImages.clear() dropped directly bound views (blocking): Resolved. It was resolved in 0ac232a33a. The new unrelated-mapping case now asserts that the view is kept (kept && rangeBytes == RangeBytes).
  2. The test could not see related moves (non-blocking): Resolved.
    • The own-range case drives the real CaptureRegisteredViewsCurrent to a refusal and checks that the retry carries the new range.
    • It fails when that check is forced to true (control above).
    • The buffer churn case is kept as the positive control.
  3. Descriptor-memory remap (blocking): Resolved.
    • ShaderMemory.cpp:496-510 makes page-backing stability its own condition, which is required on top of view currency.
    • A changed page is invalidated, so the retry reads fresh bytes. Before this, main had the same stale-cache hole.
    • The remap test fails when the page check is ignored and when the hook is absent.

New findings

Blocking

None.

Non-blocking

  1. Read marks of a page whose backing changed survive the reset.
    • What happens: pagesCurrent resets valid and raw but not read or recent. collect (ShaderMemory.cpp:967-975) emits page.words for every read mark.
    • Effect: if the accepted retry no longer reads a word that an abandoned attempt read (for example, the new descriptor takes a different branch), Regions() reports the word cached under the old backing.
    • Likely impact: a spurious memory mismatch on later reuse, not a wrong snapshot. The words the accepted attempt read are refreshed.
    • Suggested fix: also reset read/recent for a page whose backing changed, or say why stale marks are harmless there.
  2. The description is out of date. It still names the hook imageViewsCurrent and describes only the view check. It should mention the page-backing condition and the new verifySnapshotAllocationMoves test.

Not verified

  • The PPSA22408 runs and the RTX 3080 Ti results: I do not launch titles and have no GPU.
  • The author's full local run (2471/2471 CPU-only, 1339/1340 GPU tests): author-reported.
  • The cost of the extra allocation lookup on each page's first read: I took no timings.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5756701699 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15465#pullrequestreview-5756701699). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-11-03T17:25:58Z. **Review:** APPROVED --- # Re-checked — approved Commit `5061d3e9ca` is new since my last review. It does three things: - `ShaderMemory` now records which guest allocations back each page. - When the allocation generation moves, it drops any page whose backing changed and retries the attempt. - It adds tests for the directly bound image's own-range move and for a descriptor remap in the middle of a capture. Both items still open from my last review are resolved. ## What changed since my last review - **New commit `5061d3e9ca`.** - `PageBacking` hashes the allocation ranges over a page: address, bytes, allocation address, backing serial and access flags. - `addPage` stores this hash in `Page::backing`. - The hook `imageViewsCurrent` is renamed `snapshotCurrent`. It first runs `pagesCurrent()`, which resets and re-prepares every page whose backing changed, then `CaptureRegisteredViewsCurrent`. - `preparePage` is split out of `page()` so a reset page goes through the same setup as a new one. - **Test `verifySnapshotAllocationMoves` added.** It has two parts: - A directly bound sampled 1D-array image, checked through the real `CaptureRegisteredViewsCurrent`, in two cases: an unrelated mapping and a resize of the image's own range. - A real `ShaderMemory::Capture` whose T# page is rewritten and remapped while the second page is read. - **The author replied** with a negative-control table and a full local run: 2471/2471 CPU-only tests and 1339/1340 GPU tests. I take the full run as author-reported. I re-ran the negative controls myself (below). - The description was not updated for the third commit: it still names the hook `imageViewsCurrent` and describes only the view check. The hook is now `snapshotCurrent`, and the commit message describes it correctly. ## What I ran Head `5061d3e9ca4841422bed9d4b4ac130336b52be23` merged into `main` `1e658521a0a599872612bb91949311e2956b5283` (merged tree `8416e217939a3d83a10209949b2a93788e04d5cb`), Release build with GCC 14.2.0 and Ninja, Debian 13 VM, lavapipe (Mesa 26.1.6, LLVM 19). ``` git diff --check 1e658521a0a599872612bb91949311e2956b5283...5061d3e9ca4841422bed9d4b4ac130336b52be23 python3 tools/check_conventions.py --base 1e658521a0a599872612bb91949311e2956b5283 ctest --test-dir build --output-on-failure -R "^(agc_shader_memory|agc_driver_image_array_rows_past_layer_limit)$" # negative controls (each: edit one production line, ninja -C build tests/agc_shader_memory_tests, run, restore from the merged tree) ninja -C build -j32 -l32 tests/agc_shader_memory_tests build/tests/agc_shader_memory_tests git status --porcelain ``` | Check | Result | |---|---| | `git diff --check` | clean | | `check_conventions.py` | All conventions checks passed | | Configure, build, libs (script) | OK | | Selected tests (script, 2160 run) | no new failures, no timeouts. The 7 known failures also fail on `main`. | | `agc_shader_memory` | passes (8.1 s) | | `agc_driver_image_array_rows_past_layer_limit` | passes (2.7 s) | | Validation layer (script, 772 tests, layer loaded in 771, none missing) | no new `VUID-` lines compared with `main` | | Worktree after the controls | `git status --porcelain` empty, `agc_shader_memory` passes again | ## Negative control The new tests use the new `SrtRuntime::snapshotCurrent` field, so they do not build against `main`'s files. Instead I changed one production line at a time on the merged tree: | Production change | Result | |---|---| | `snapshotCurrent` ignores `pagesCurrent()`'s result (view check only) | fails: `after the page holding T# was remapped during the capture, the snapshot kept the T# read before the remap` | | Driver sets no `snapshotCurrent` hook (`main`'s retry-on-any-move rule) | fails with the same remap message. This confirms the author's point that the gap was also on `main`: retries re-read the cached page. | | `Materialize` never consults the hook (always accepts a moved generation) | fails: `allocation churn: without an image view check, a snapshot taken while the allocation generation moved was accepted` | | `CaptureRegisteredViewsCurrent` always returns true | fails: `an attempt during which the image's own range changed was accepted instead of retried with the new range` | I did not re-run the author's "`clear()` back in" control. ## Previous findings 1. **`registeredImages.clear()` dropped directly bound views (blocking): Resolved.** It was resolved in `0ac232a33a`. The new unrelated-mapping case now asserts that the view is kept (`kept && rangeBytes == RangeBytes`). 2. **The test could not see related moves (non-blocking): Resolved.** - The own-range case drives the real `CaptureRegisteredViewsCurrent` to a refusal and checks that the retry carries the new range. - It fails when that check is forced to true (control above). - The buffer churn case is kept as the positive control. 3. **Descriptor-memory remap (blocking): Resolved.** - [ShaderMemory.cpp:496-510](https://github.com/boykopovar/AnyPS5/blob/5061d3e9ca4841422bed9d4b4ac130336b52be23/core/libs/prx/libSceAgcDriver/Execution/src/ShaderMemory.cpp#L496-L510) makes page-backing stability its own condition, which is required on top of view currency. - A changed page is invalidated, so the retry reads fresh bytes. Before this, `main` had the same stale-cache hole. - The remap test fails when the page check is ignored and when the hook is absent. ## New findings ### Blocking None. ### Non-blocking 1. **Read marks of a page whose backing changed survive the reset.** - **What happens:** `pagesCurrent` resets `valid` and `raw` but not `read` or `recent`. `collect` ([ShaderMemory.cpp:967-975](https://github.com/boykopovar/AnyPS5/blob/5061d3e9ca4841422bed9d4b4ac130336b52be23/core/libs/prx/libSceAgcDriver/Execution/src/ShaderMemory.cpp#L967-L975)) emits `page.words` for every `read` mark. - **Effect:** if the accepted retry no longer reads a word that an abandoned attempt read (for example, the new descriptor takes a different branch), `Regions()` reports the word cached under the old backing. - **Likely impact:** a spurious memory mismatch on later reuse, not a wrong snapshot. The words the accepted attempt read are refreshed. - **Suggested fix:** also reset `read`/`recent` for a page whose backing changed, or say why stale marks are harmless there. 2. **The description is out of date.** It still names the hook `imageViewsCurrent` and describes only the view check. It should mention the page-backing condition and the new `verifySnapshotAllocationMoves` test. ## Not verified - The PPSA22408 runs and the RTX 3080 Ti results: I do not launch titles and have no GPU. - The author's full local run (2471/2471 CPU-only, 1339/1340 GPU tests): author-reported. - The cost of the extra allocation lookup on each page's first read: I took no timings. <!-- anyps5-bots job=3470 head=5061d3e9ca4841422bed9d4b4ac130336b52be23 -->
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!15465
No description provided.