fix(agc): update snapshot header and bytes on relocated header ABI resolution #2969

Closed
NRAPM wants to merge 1 commit from upstream-pr/2969 into main
NRAPM commented 2026-10-10 18:59:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by NRAPM on 2026-10-10T18:59:53Z.


Fixes #2914.

What

In titles such as Astro's Playroom (PPSA01325), shader ABI resolution calls (ResolveGraphicsStagesAbi, ResolveShaderAbi, ResolveGraphicsAbi) can pass a Shader* whose code pointer matches a registered shader, but whose header is allocated or copied at a different guest address.

When SameHeader validates the relocated header, snapshot.headerAddress and snapshot.header were not updated to the new copy. Because the header contains absolute guest pointers (such as shader.user_data, input semantics) that are relative to the header address, downstream decoders (DecodeVertexStageInfo / _readHeaderPod) compute offsets against the mismatched base address and throw AGC graphics: AGC header pointer is outside the registered shader header.

This change:

  • Declares ShaderSnapshot::headerAddress and ShaderSnapshot::header as mutable.
  • Updates headerAddress and re-reads the header bytes via GuestMemory::CheckRange and memcpy when the resolved shader pointer differs from the registered snapshot address, synchronized under mutex.
  • Expands PreparedShaders.cpp tests with a relocated full header copy.
  • Updates TechnicalDebt.md accordingly.

Tested

  • Ran python tools/check_conventions.py --base origin/main (passed).
  • Ran python -m unittest discover tools/tests (52/52 passed).
  • Verified git diff --check (clean).

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 in TechnicalDebt
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4813681241 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2969). Originally posted by [NRAPM](https://github.com/NRAPM) on 2026-10-10T18:59:53Z. --- Fixes #2914. ### What In titles such as Astro's Playroom (PPSA01325), shader ABI resolution calls (`ResolveGraphicsStagesAbi`, `ResolveShaderAbi`, `ResolveGraphicsAbi`) can pass a `Shader*` whose code pointer matches a registered shader, but whose header is allocated or copied at a different guest address. When `SameHeader` validates the relocated header, `snapshot.headerAddress` and `snapshot.header` were not updated to the new copy. Because the header contains absolute guest pointers (such as `shader.user_data`, input semantics) that are relative to the header address, downstream decoders (`DecodeVertexStageInfo` / `_readHeaderPod`) compute offsets against the mismatched base address and throw `AGC graphics: AGC header pointer is outside the registered shader header`. This change: - Declares `ShaderSnapshot::headerAddress` and `ShaderSnapshot::header` as mutable. - Updates `headerAddress` and re-reads the header bytes via `GuestMemory::CheckRange` and `memcpy` when the resolved shader pointer differs from the registered snapshot address, synchronized under `mutex`. - Expands `PreparedShaders.cpp` tests with a relocated full header copy. - Updates `TechnicalDebt.md` accordingly. ### Tested - Ran `python tools/check_conventions.py --base origin/main` (passed). - Ran `python -m unittest discover tools/tests` (52/52 passed). - Verified `git diff --check` (clean). ### 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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-10 19:05:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-10T19:05:26Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#374 docs/dev/TechnicalDebt.md L280
#425 docs/dev/TechnicalDebt.md L280
#2261 docs/dev/TechnicalDebt.md L280
#2856 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp L209, L684-686, L750-751, L812-813
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6101123937 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2969#issuecomment-6101123937). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-10T19:05:26Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #374 | `docs/dev/TechnicalDebt.md` [L280](https://github.com/boykopovar/AnyPS5/blob/4a747c4872814908702fe81db6a20405a53a07d7/docs/dev/TechnicalDebt.md#L280) | | | | #425 | `docs/dev/TechnicalDebt.md` [L280](https://github.com/boykopovar/AnyPS5/blob/4a747c4872814908702fe81db6a20405a53a07d7/docs/dev/TechnicalDebt.md#L280) | | | | #2261 | `docs/dev/TechnicalDebt.md` [L280](https://github.com/boykopovar/AnyPS5/blob/4a747c4872814908702fe81db6a20405a53a07d7/docs/dev/TechnicalDebt.md#L280) | | | | #2856 | `core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp` [L209](https://github.com/boykopovar/AnyPS5/blob/4a747c4872814908702fe81db6a20405a53a07d7/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp#L209), [L684-686](https://github.com/boykopovar/AnyPS5/blob/4a747c4872814908702fe81db6a20405a53a07d7/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp#L684-L686), [L750-751](https://github.com/boykopovar/AnyPS5/blob/4a747c4872814908702fe81db6a20405a53a07d7/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp#L750-L751), [L812-813](https://github.com/boykopovar/AnyPS5/blob/4a747c4872814908702fe81db6a20405a53a07d7/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp#L812-L813) | | |
github-actions[bot] commented 2026-10-10 19:10:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-10T19:10:26Z.


Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6101167246 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2969#issuecomment-6101167246). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-10T19:10:26Z. --- Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.
oneandonlydean commented 2026-10-11 04:36:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-11T04:36:07Z.


This couldn't be reopened: the branch was force-pushed after the close. The new head (dbdecd93) also doesn't build. UpdateSnapshotHeader is inserted before the closing brace of RegisteredProgram, so it ends up inside it.

Besides the brace: the description says the update is synchronized under mutex, but nothing locks it. Making header/headerAddress mutable and rewriting them in place changes a shared const snapshot that other threads may be reading. Could you publish a new snapshot for the relocated header (or take the registry lock), build it, and add a test that fails on main? Then I'll open it from your branch.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6105486542 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2969#issuecomment-6105486542). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-11T04:36:07Z. --- This couldn't be reopened: the branch was force-pushed after the close. The new head (`dbdecd93`) also doesn't build. `UpdateSnapshotHeader` is inserted before the closing brace of `RegisteredProgram`, so it ends up inside it. Besides the brace: the description says the update is synchronized under `mutex`, but nothing locks it. Making `header`/`headerAddress` `mutable` and rewriting them in place changes a shared `const` snapshot that other threads may be reading. Could you publish a new snapshot for the relocated header (or take the registry lock), build it, and add a test that fails on `main`? Then I'll open it from your branch.
NRAPM commented 2026-10-11 11:55:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by NRAPM on 2026-10-11T11:55:50Z.


Fixed the missing closing brace on RegisteredProgram in 00c6c0b5 — thanks for catching that! Since GitHub prevents reopening after a force-push, feel free to cherry-pick / carry 00c6c0b5 directly, or let me know if you prefer a new PR from a fresh branch.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6108758441 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2969#issuecomment-6108758441). Originally posted by [NRAPM](https://github.com/NRAPM) on 2026-10-11T11:55:50Z. --- Fixed the missing closing brace on `RegisteredProgram` in `00c6c0b5` — thanks for catching that! Since GitHub prevents reopening after a force-push, feel free to cherry-pick / carry `00c6c0b5` directly, or let me know if you prefer a new PR from a fresh branch.
NRAPM commented 2026-10-11 18:52:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by NRAPM on 2026-10-11T18:52:49Z.


Updated in 7fb5b337:

  • Removed mutable from ShaderSnapshot so snapshots remain strictly immutable.
  • RelocateSnapshotHeader publishes a new snapshot for the relocated header via PublishRegisteredShader under mutex at the three resolve sites (ResolveGraphicsStagesAbi, ResolveShaderAbi, ResolveGraphicsAbi).
  • Added test coverage in PreparedShaders.cpp for relocated header copies.
  • Passed tools/check_conventions.py --base origin/main and unittest discover tools/tests.

Ready whenever you want to open it from NRAPM:fix/agc-shader-abi-relocated-header.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6112481602 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2969#issuecomment-6112481602). Originally posted by [NRAPM](https://github.com/NRAPM) on 2026-10-11T18:52:49Z. --- Updated in `7fb5b337`: - Removed `mutable` from `ShaderSnapshot` so snapshots remain strictly immutable. - `RelocateSnapshotHeader` publishes a new snapshot for the relocated header via `PublishRegisteredShader` under `mutex` at the three resolve sites (`ResolveGraphicsStagesAbi`, `ResolveShaderAbi`, `ResolveGraphicsAbi`). - Added test coverage in `PreparedShaders.cpp` for relocated header copies. - Passed `tools/check_conventions.py --base origin/main` and `unittest discover tools/tests`. Ready whenever you want to open it from `NRAPM:fix/agc-shader-abi-relocated-header`.
oneandonlydean commented 2026-10-11 21:16:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-11T21:16:34Z.


Intake is open again, so please open a new PR from NRAPM:fix/agc-shader-abi-relocated-header; a closed PR whose branch has moved can't be reopened.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6113849959 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2969#issuecomment-6113849959). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-11T21:16:34Z. --- Intake is open again, so please open a new PR from `NRAPM:fix/agc-shader-abi-relocated-header`; a closed PR whose branch has moved can't be reopened.
NRAPM commented 2026-10-11 22:02:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by NRAPM on 2026-10-11T22:02:14Z.


Opened #4043 from NRAPM:fix/agc-shader-abi-relocated-header.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6114308971 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2969#issuecomment-6114308971). Originally posted by [NRAPM](https://github.com/NRAPM) on 2026-10-11T22:02:14Z. --- Opened #4043 from `NRAPM:fix/agc-shader-abi-relocated-header`.

Pull request closed

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!2969
No description provided.