fix(agc): synchronize ResourceCache index on list node eviction #9592

Open
christophermonterocortes-cr wants to merge 1 commit from upstream-pr/9592 into main
christophermonterocortes-cr commented 2026-10-22 03:41:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by christophermonterocortes-cr on 2026-10-22T03:41:26Z.


What

In core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp, ensure ResourceCache index entries are always synchronized and erased when list nodes are evicted.

  • Implements eraseEntry(iterator) helper that erases the corresponding index entry for a list node, falling back to iterator matching across the index map if the key lookup misses.
  • Uses eraseEntry across all node eviction paths: capacity eviction, table-element budget eviction, RemoveImage, and dropReleasedTextures.
  • Prevents use-after-free and dangling list node pointers in index when list nodes are deallocated, fixing the SIGSEGV crash in ResourceCache::Find during MXGP 26 (PPSA30839) loading (#9497).
  • Updates docs/dev/debt/libSceAgcDriver.md with technical debt notes.

Tested

  • python tools/check_conventions.py --base upstream/main: All conventions checks passed.
  • python -m unittest discover -s tools/tests -p "test_check_conventions*.py": all passed.

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: #9497
  • Unblocks: PPSA30839
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4961745404 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9592). Originally posted by [christophermonterocortes-cr](https://github.com/christophermonterocortes-cr) on 2026-10-22T03:41:26Z. --- ### What In `core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp`, ensure `ResourceCache` index entries are always synchronized and erased when list nodes are evicted. - Implements `eraseEntry(iterator)` helper that erases the corresponding index entry for a list node, falling back to iterator matching across the index map if the key lookup misses. - Uses `eraseEntry` across all node eviction paths: capacity eviction, table-element budget eviction, `RemoveImage`, and `dropReleasedTextures`. - Prevents use-after-free and dangling list node pointers in `index` when list nodes are deallocated, fixing the `SIGSEGV` crash in `ResourceCache::Find` during *MXGP 26* (PPSA30839) loading (#9497). - Updates `docs/dev/debt/libSceAgcDriver.md` with technical debt notes. ### Tested - `python tools/check_conventions.py --base upstream/main`: All conventions checks passed. - `python -m unittest discover -s tools/tests -p "test_check_conventions*.py"`: all passed. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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: #9497 - [x] Unblocks: PPSA30839 - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-22 04:09:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T04:09:56Z.

Review: CHANGES_REQUESTED


This PR addresses the dangling-index failure described in #9497, but it is not ready to approve under the repository contribution rules. The generated overlap report lists many open PRs touching ShaderResources.hpp/.cpp (including #6192, #6194, #6202, #6223, #6292, #6412, #6481, #6615, #7642, #7689, #7800, #8672, #9012 and #9508); for these files the report says the comparison could not complete because their branches conflict with the base. Please manually resolve the implementation overlap and coordinate ordering with the relevant authors, recording Depends on: #N where a prerequisite exists. The same-key erase and iterator-fallback change may interact with those cache edits, so the debt-file overlap alone does not settle this.

The checklist also says Unblocks: PPSA30839 without a Game bring-up discussion number. Please link the applicable discussion or use none if this is not a title unblock. Lastly, this is an AGC driver change; the reported issue reproduction is valuable, but the PR currently reports only convention checks. Please attach same-machine/same-GPU focused ctest -V runs for current main and this head with the required validation-layer environment, verify layer loading, compare VUIDs, and state GPU/driver/OS. The reported reproducer uses main a6dcea9279, which is not current main.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5609153271 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9592#pullrequestreview-5609153271). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T04:09:56Z. **Review:** CHANGES_REQUESTED --- This PR addresses the dangling-index failure described in #9497, but it is not ready to approve under the repository contribution rules. The generated overlap report lists many open PRs touching ShaderResources.hpp/.cpp (including #6192, #6194, #6202, #6223, #6292, #6412, #6481, #6615, #7642, #7689, #7800, #8672, #9012 and #9508); for these files the report says the comparison could not complete because their branches conflict with the base. Please manually resolve the implementation overlap and coordinate ordering with the relevant authors, recording `Depends on: #N` where a prerequisite exists. The same-key erase and iterator-fallback change may interact with those cache edits, so the debt-file overlap alone does not settle this. The checklist also says `Unblocks: PPSA30839` without a Game bring-up discussion number. Please link the applicable discussion or use `none` if this is not a title unblock. Lastly, this is an AGC driver change; the reported issue reproduction is valuable, but the PR currently reports only convention checks. Please attach same-machine/same-GPU focused ctest -V runs for current main and this head with the required validation-layer environment, verify layer loading, compare VUIDs, and state GPU/driver/OS. The reported reproducer uses main a6dcea9279, which is not current main.
MarcZX10 commented 2026-10-22 10:01:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T10:01:04Z.

Review: CHANGES_REQUESTED


I inspected the exact helper and found an edge in the failure case this PR is intended to tolerate. eraseEntry(it) erases index.find(it->first) whenever that key exists, without checking that the map value is it. If the corrupted list key now equals another live entry's key, lookup succeeds and removes the other node's index mapping; the current node's map entry can still point at its freed list node. Please require found->second == it before erasing by key, and otherwise take the iterator-matching fallback. Add focused coverage for a key miss and a collision with another live key if the cache test seam permits it.

The focused bug report and fix are important, but the current validation is still incomplete: this branch is 100 commits behind current main; the linked MXGP reproduction is from a6dcea9279; and hosted product/relinker jobs are skipped. Please rebase, reproduce the issue or run a focused ResourceCache regression on current main and this head, then provide the paired AGC validation-layer/no-cache ctest -V results required by CONTRIBUTING (layer loaded, compare VUIDs, GPU/driver/OS).

The overlap bot cannot compare multiple open PRs changing ShaderResources.hpp/.cpp; manually compare the relevant cache changes and agree merge order/dependencies with their authors. The #9497 report is a bug issue, not a Game bring-up discussion. Since the checklist says Unblocks: PPSA30839, please locate/create the title's Game bring-up discussion, list this PR there, and use the required PPSA30839 #<discussion> form. Keep Fixes: #9497 if this fix continues to address that issue.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5612454996 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9592#pullrequestreview-5612454996). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T10:01:04Z. **Review:** CHANGES_REQUESTED --- I inspected the exact helper and found an edge in the failure case this PR is intended to tolerate. `eraseEntry(it)` erases `index.find(it->first)` whenever that key exists, without checking that the map value is `it`. If the corrupted list key now equals another live entry's key, lookup succeeds and removes the other node's index mapping; the current node's map entry can still point at its freed list node. Please require `found->second == it` before erasing by key, and otherwise take the iterator-matching fallback. Add focused coverage for a key miss and a collision with another live key if the cache test seam permits it. The focused bug report and fix are important, but the current validation is still incomplete: this branch is 100 commits behind current main; the linked MXGP reproduction is from `a6dcea9279`; and hosted product/relinker jobs are skipped. Please rebase, reproduce the issue or run a focused ResourceCache regression on current main and this head, then provide the paired AGC validation-layer/no-cache `ctest -V` results required by CONTRIBUTING (layer loaded, compare VUIDs, GPU/driver/OS). The overlap bot cannot compare multiple open PRs changing `ShaderResources.hpp/.cpp`; manually compare the relevant cache changes and agree merge order/dependencies with their authors. The #9497 report is a bug issue, not a Game bring-up discussion. Since the checklist says `Unblocks: PPSA30839`, please locate/create the title's Game bring-up discussion, list this PR there, and use the required `PPSA30839 #<discussion>` form. Keep `Fixes: #9497` if this fix continues to address that issue.
adriadam10 commented 2026-10-22 18:55:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-22T18:55:39Z.

Review: CHANGES_REQUESTED


Thanks for the patch. Changes needed before this can merge:

  • ShaderResources.cpp:3937-3941: eraseEntry erases index.find(it->first) without checking found->second == it. If the list key is the corrupted copy and collides with another live entry's key, this removes that entry's mapping and leaves the current node's mapping pointing at the freed node. Require found->second == it, otherwise take the iterator scan.
  • ShaderResources.cpp:3942-3947: the fallback only runs once a node's key and its index entry have already diverged, so it hides the inconsistency instead of fixing where it starts, and each miss is an O(n) scan on the eviction path. #9497 is still being diagnosed (key copies compared before each erase); the fix should target whatever corrupts or desynchronizes the key (an Insert/erase(key) path leaving a map entry on a replaced node), not tolerate it.
  • No test: Tested lists only convention checks. Add a focused test that fails without the change (key miss and key collision cases), or show the reproduction.
  • docs/dev/debt/libSceAgcDriver.md:238: this describes the patch, not a known gap; drop it or state the actual open gap (unknown writer of the key).
  • The body's Depends on: none conflicts with the many open PRs touching ShaderResources.cpp/.hpp listed in the overlap report (see MarcZX10's review); please check ordering with them.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5619344242 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9592#pullrequestreview-5619344242). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-22T18:55:39Z. **Review:** CHANGES_REQUESTED --- Thanks for the patch. Changes needed before this can merge: - `ShaderResources.cpp:3937-3941`: `eraseEntry` erases `index.find(it->first)` without checking `found->second == it`. If the list key is the corrupted copy and collides with another live entry's key, this removes that entry's mapping and leaves the current node's mapping pointing at the freed node. Require `found->second == it`, otherwise take the iterator scan. - `ShaderResources.cpp:3942-3947`: the fallback only runs once a node's key and its index entry have already diverged, so it hides the inconsistency instead of fixing where it starts, and each miss is an O(n) scan on the eviction path. #9497 is still being diagnosed (key copies compared before each erase); the fix should target whatever corrupts or desynchronizes the key (an `Insert`/`erase(key)` path leaving a map entry on a replaced node), not tolerate it. - No test: `Tested` lists only convention checks. Add a focused test that fails without the change (key miss and key collision cases), or show the reproduction. - `docs/dev/debt/libSceAgcDriver.md:238`: this describes the patch, not a known gap; drop it or state the actual open gap (unknown writer of the key). - The body's `Depends on: none` conflicts with the many open PRs touching `ShaderResources.cpp/.hpp` listed in the overlap report (see MarcZX10's review); please check ordering with them.
adriadam10 commented 2026-10-24 02:26:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-24T02:26:08Z.

Review: CHANGES_REQUESTED


Still needs changes; nothing was pushed since the last review and these points need a decision from you, not a mechanical fix:

  • ShaderResources.cpp:4125-4129: eraseEntry erases index.find(it->first) without checking found->second == it. A corrupted list key that collides with another live entry removes that entry's mapping and leaves this node's mapping pointing at the freed node. Check found->second == it and otherwise take the iterator scan.
  • ShaderResources.cpp:4130-4135: the fallback only runs after the key and the index entry have already diverged, so it hides the corruption instead of removing it, and every miss is an O(n) scan on the eviction path. The root cause in #9497 is still being diagnosed; a fix should either remove the dependence on re-reading the key (e.g. the node holds the map iterator and erases through it) or target the writer once found.
  • No test. Add one that fails without the change (key miss and key collision), or show the reproduction.
  • docs/dev/debt/libSceAgcDriver.md:260 describes the patch, not a known gap. Drop it, or state the open gap (unknown writer of the key).
  • Depends on: none conflicts with the many open PRs touching ShaderResources.cpp/.hpp; check the ordering and list them.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5636416033 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9592#pullrequestreview-5636416033). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-24T02:26:08Z. **Review:** CHANGES_REQUESTED --- Still needs changes; nothing was pushed since the last review and these points need a decision from you, not a mechanical fix: - `ShaderResources.cpp:4125-4129`: `eraseEntry` erases `index.find(it->first)` without checking `found->second == it`. A corrupted list key that collides with another live entry removes that entry's mapping and leaves this node's mapping pointing at the freed node. Check `found->second == it` and otherwise take the iterator scan. - `ShaderResources.cpp:4130-4135`: the fallback only runs after the key and the index entry have already diverged, so it hides the corruption instead of removing it, and every miss is an O(n) scan on the eviction path. The root cause in #9497 is still being diagnosed; a fix should either remove the dependence on re-reading the key (e.g. the node holds the map iterator and erases through it) or target the writer once found. - No test. Add one that fails without the change (key miss and key collision), or show the reproduction. - `docs/dev/debt/libSceAgcDriver.md:260` describes the patch, not a known gap. Drop it, or state the open gap (unknown writer of the key). - `Depends on: none` conflicts with the many open PRs touching `ShaderResources.cpp/.hpp`; check the ordering and list them.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/9592:upstream-pr/9592'
git switch 'upstream-pr/9592'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/9592'
git switch 'upstream-pr/9592'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/9592'
git switch 'upstream-pr/9592'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/9592'
git switch 'main'
git merge --squash 'upstream-pr/9592'
git switch 'main'
git merge --ff-only 'upstream-pr/9592'
git switch 'main'
git merge 'upstream-pr/9592'
git push origin 'main'
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!9592
No description provided.