fix(agc): publish relocated shader snapshot on ABI resolution #4043

Closed
NRAPM wants to merge 1 commit from upstream-pr/4043 into main
NRAPM commented 2026-10-11 22:01:13 +00:00 (Migrated from github.com)

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


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 matches the relocated header, the snapshot was not published for the new address. When decoders resolve stage info against the registered snapshot, pointer offsets are computed against the original base address instead of the relocated copy, leading to out-of-bounds header offsets.

This change:

  • Clones and publishes a new snapshot for the relocated header via RelocateSnapshotHeader and PublishRegisteredShader under mutex at the three resolve sites (ResolveGraphicsStagesAbi, ResolveShaderAbi, ResolveGraphicsAbi).
  • Keeps ShaderSnapshot strictly immutable without mutable members.
  • Expands PreparedShaders.cpp tests with relocated header copies.

Tested

  • Ran python tools/check_conventions.py --base origin/main (passed).
  • Ran python -m unittest discover tools/tests (60 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:4822697507 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4043). Originally posted by [NRAPM](https://github.com/NRAPM) on 2026-10-11T22:01:13Z. --- 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` matches the relocated header, the snapshot was not published for the new address. When decoders resolve stage info against the registered snapshot, pointer offsets are computed against the original base address instead of the relocated copy, leading to out-of-bounds header offsets. This change: - Clones and publishes a new snapshot for the relocated header via `RelocateSnapshotHeader` and `PublishRegisteredShader` under `mutex` at the three resolve sites (`ResolveGraphicsStagesAbi`, `ResolveShaderAbi`, `ResolveGraphicsAbi`). - Keeps `ShaderSnapshot` strictly immutable without `mutable` members. - Expands `PreparedShaders.cpp` tests with relocated header copies. ### Tested - Ran `python tools/check_conventions.py --base origin/main` (passed). - Ran `python -m unittest discover tools/tests` (60 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
oneandonlydean commented 2026-10-11 23:20:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-11T23:20:50Z.


Which line does PPSA01325 stop at on current main? Please post the log from an unpatched build. Two things I can't match with the description:

  • On main RegisteredHeader returns the registered snapshot with its own headerAddress and header bytes, and nothing rewrites them, so _readHeaderPod reads a consistent header. The stale-header case in #2914 comes from 9ad1b82a, which isn't on main.
  • RelocateSnapshotHeader copies header_size bytes from the pointer it is given. A caller that copies only the Shader struct has nothing behind it (Shader copy = header.shader in PreparedShaders.cpp, Registration), and every new copy address clones the registry and adds a snapshot.

Do the two added resolves fail without the change? The Tested section lists no build or ctest run.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6115041955 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4043#issuecomment-6115041955). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-11T23:20:50Z. --- Which line does PPSA01325 stop at on current main? Please post the log from an unpatched build. Two things I can't match with the description: - On main `RegisteredHeader` returns the registered snapshot with its own `headerAddress` and header bytes, and nothing rewrites them, so `_readHeaderPod` reads a consistent header. The stale-header case in #2914 comes from `9ad1b82a`, which isn't on main. - `RelocateSnapshotHeader` copies `header_size` bytes from the pointer it is given. A caller that copies only the `Shader` struct has nothing behind it (`Shader copy = header.shader` in `PreparedShaders.cpp`, `Registration`), and every new copy address clones the registry and adds a snapshot. Do the two added resolves fail without the change? The Tested section lists no build or ctest run.
blawesom commented 2026-10-12 07:05:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-12T07:05:58Z.


Pre-review found a deterministic test regression on Linux — flagging early since full CI doesn't run automatically on PRs.

Independent pre-review (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, BUILD_TESTING=ON, AMD RX 9070 XT / RADV):

  • The PR builds and tools/check_conventions.py passes.
  • 4 tests fail deterministically with the same assertion:
agc_driver_prepared_shaders
agc_driver_prepared_shaders_indirect
agc_driver_prepared_shaders_uncached
agc_driver_prepared_shaders_debug

Each fails fast with AGC graphics: missing AGC user-data header.

Negative control: the same 7-test family passes 100% at this branch's own merge base (ad3369236) on the same machine — so the regression is introduced by the branch's changes, not the environment or the base.

Separately: this branch is ~1364 commits behind main and will need a rebase before review regardless. Reproduce with:

ctest -R agc_driver_prepared_shaders --output-on-failure

Happy to provide the full output if useful.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6119437100 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4043#issuecomment-6119437100). Originally posted by [blawesom](https://github.com/blawesom) on 2026-10-12T07:05:58Z. --- **Pre-review found a deterministic test regression on Linux** — flagging early since full CI doesn't run automatically on PRs. Independent pre-review (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, `BUILD_TESTING=ON`, AMD RX 9070 XT / RADV): - The PR builds and `tools/check_conventions.py` passes. - **4 tests fail deterministically** with the same assertion: ``` agc_driver_prepared_shaders agc_driver_prepared_shaders_indirect agc_driver_prepared_shaders_uncached agc_driver_prepared_shaders_debug ``` Each fails fast with `AGC graphics: missing AGC user-data header`. **Negative control:** the same 7-test family passes 100% at this branch's own merge base (`ad3369236`) on the same machine — so the regression is introduced by the branch's changes, not the environment or the base. Separately: this branch is ~1364 commits behind `main` and will need a rebase before review regardless. Reproduce with: ``` ctest -R agc_driver_prepared_shaders --output-on-failure ``` Happy to provide the full output if useful.
oneandonlydean commented 2026-10-13 02:44:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T02:44:08Z.


Closing: with this branch agc_driver_prepared_shaders, _indirect, _uncached and _debug fail with missing AGC user-data header (blawesom's run above), and the questions from 10-11 are still open. Please reopen with a build and ctest run and the line PPSA01325 stops at on unpatched main.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6137051571 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4043#issuecomment-6137051571). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-13T02:44:08Z. --- Closing: with this branch `agc_driver_prepared_shaders`, `_indirect`, `_uncached` and `_debug` fail with `missing AGC user-data header` (blawesom's run above), and the questions from 10-11 are still open. Please reopen with a build and ctest run and the line PPSA01325 stops at on unpatched main.

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