fix(agc): retain registered headers sharing shader code #2856

Merged
CouchRiv merged 2 commits from upstream-pr/2856 into main 2026-10-10 23:18:38 +00:00
CouchRiv commented 2026-10-10 16:41:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by CouchRiv on 2026-10-10T16:41:57Z.


What

AGC driver: graphics ABI refers to a replaced shader header

Registering another header for the same code address replaces the first snapshot on main. An ABI that still refers to the first registered header then fails, even when both headers were explicitly registered with different binary types.

Retain each registered header and its prepared state for unchanged code. ABI resolution finds the matching registered header; draws and dispatches select the registered binary type for their stage. Within a type, the last registered header wins as before. Re-registering an identical earlier header makes its original snapshot current again without preparing it again. Changed code invalidates the older registrations.

Unregistered header differences still throw. A geometry front entry matching both type 2 and type 4 is rejected as ambiguous. Main selected the last registration's type instead. HeaderSelection tests this new lookup refusal. Registration and static ABI preparation keep their existing timing; this adds no preparation fallback at draw.

Retained headers live until code replacement or driver shutdown. Keeping their snapshots increases memory use and requires scanning the headers for a code address. Reordering an earlier registration also invalidates the registry's ABI and draw caches, while retaining the prepared artifacts.

Public report #2700 records this refusal in Ghost of Yōtei (PPSA26344, 01.008) on Linux with lavapipe. It describes relocated pointer fields without a changed type. This change addresses explicitly registered headers; it does not accept an unregistered relocated copy or establish that the reported title is fixed. Ghost of Yōtei was not run here.

#1837 remains the rule for bound copies differing only in user_data or padding. This retains #639's registration and static ABI preparation.

Tested

CachyOS Linux, GCC Release build, RTX 4070 Ti (NVIDIA 615.78.08), AMD integrated GPU (RADV RAPHAEL_MENDOCINO), and Mesa lavapipe (llvmpipe, LLVM 23.1.1).

  • SharedCodeHeaders in agc_driver_prepared_shaders registers one synthetic program as type 2 and type 4, resolves the first header and submits two draws. A third draw uses a newly registered type-2 header with distinct metadata pointers; a fourth follows re-registration of the original header. All complete without an exception. On main de5e541d8 with lavapipe, the two-draw fixture fails at ABI resolution with the replaced-header refusal, before its first draw.
  • agc_driver_prepared_publication asserts snapshot selection and lifetime, identical re-registration order, changed-code invalidation and ambiguous type rejection. The prepared shader, graphics, publication and export group passes 10/10 on all three drivers. The draw checks establish successful submission; they do not measure compilation counts.
  • Full AGC driver suites (253 selected each): RADV 253 passed; NVIDIA 252 passed and agc_driver_dcc_keys_first_write failed; lavapipe 225 passed, 27 feature skips and agc_driver_f64_fma_subnormals failed. Both failures reproduce with the same error on an isolated build of main de5e541d8.
  • A prior RADV run segfaulted in agc_driver; the same test segfaulted on isolated main. The final full RADV run passed it.
  • Full build, test-registration check (558 executables, none unregistered), tools/check_conventions.py --base origin/main and git diff --check pass.
  • Not tested: Ghost of Yōtei, Windows, console behaviour.

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 (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 (textual overlap only with #1732, #1825, #2261 and #2363, which change other behaviour; I rebase on whichever merges first)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4812811982 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2856). Originally posted by [CouchRiv](https://github.com/CouchRiv) on 2026-10-10T16:41:57Z. --- ### What ```text AGC driver: graphics ABI refers to a replaced shader header ``` Registering another header for the same code address replaces the first snapshot on main. An ABI that still refers to the first registered header then fails, even when both headers were explicitly registered with different binary types. Retain each registered header and its prepared state for unchanged code. ABI resolution finds the matching registered header; draws and dispatches select the registered binary type for their stage. Within a type, the last registered header wins as before. Re-registering an identical earlier header makes its original snapshot current again without preparing it again. Changed code invalidates the older registrations. Unregistered header differences still throw. A geometry front entry matching both type 2 and type 4 is rejected as ambiguous. Main selected the last registration's type instead. `HeaderSelection` tests this new lookup refusal. Registration and static ABI preparation keep their existing timing; this adds no preparation fallback at draw. Retained headers live until code replacement or driver shutdown. Keeping their snapshots increases memory use and requires scanning the headers for a code address. Reordering an earlier registration also invalidates the registry's ABI and draw caches, while retaining the prepared artifacts. ### Related public report [Public report #2700](https://github.com/boykopovar/AnyPS5/pull/2700) records this refusal in Ghost of Yōtei (PPSA26344, 01.008) on Linux with lavapipe. It describes relocated pointer fields without a changed type. This change addresses explicitly registered headers; it does not accept an unregistered relocated copy or establish that the reported title is fixed. Ghost of Yōtei was not run here. [#1837](https://github.com/boykopovar/AnyPS5/pull/1837) remains the rule for bound copies differing only in user_data or padding. This retains [#639's registration and static ABI preparation](https://github.com/boykopovar/AnyPS5/pull/639#issuecomment-6063503837). ### Tested CachyOS Linux, GCC Release build, RTX 4070 Ti (NVIDIA 615.78.08), AMD integrated GPU (RADV RAPHAEL_MENDOCINO), and Mesa lavapipe (llvmpipe, LLVM 23.1.1). - `SharedCodeHeaders` in `agc_driver_prepared_shaders` registers one synthetic program as type 2 and type 4, resolves the first header and submits two draws. A third draw uses a newly registered type-2 header with distinct metadata pointers; a fourth follows re-registration of the original header. All complete without an exception. On main `de5e541d8` with lavapipe, the two-draw fixture fails at ABI resolution with the replaced-header refusal, before its first draw. - `agc_driver_prepared_publication` asserts snapshot selection and lifetime, identical re-registration order, changed-code invalidation and ambiguous type rejection. The prepared shader, graphics, publication and export group passes 10/10 on all three drivers. The draw checks establish successful submission; they do not measure compilation counts. - Full AGC driver suites (253 selected each): RADV 253 passed; NVIDIA 252 passed and `agc_driver_dcc_keys_first_write` failed; lavapipe 225 passed, 27 feature skips and `agc_driver_f64_fma_subnormals` failed. Both failures reproduce with the same error on an isolated build of main `de5e541d8`. - A prior RADV run segfaulted in `agc_driver`; the same test segfaulted on isolated main. The final full RADV run passed it. - Full build, test-registration check (558 executables, none unregistered), `tools/check_conventions.py --base origin/main` and `git diff --check` pass. - Not tested: Ghost of Yōtei, Windows, console behaviour. ### 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 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 (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 (textual overlap only with #1732, #1825, #2261 and #2363, which change other behaviour; I rebase on whichever merges first) - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-10 19:33:17 +00:00 (Migrated from github.com)

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


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
#2976 core/libs/prx/libSceAgcDriver/Execution/include/Driver/Shaders/ShaderRegistry.hpp L12, L91-92
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6101379785 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2856#issuecomment-6101379785). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-10T19:33:17Z. --- <!-- 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 | |---|---|---|---| | #2976 | `core/libs/prx/libSceAgcDriver/Execution/include/Driver/Shaders/ShaderRegistry.hpp` [L12](https://github.com/boykopovar/AnyPS5/blob/53924632bb2d58011dafedc13b809e31cddbdb5c/core/libs/prx/libSceAgcDriver/Execution/include/Driver/Shaders/ShaderRegistry.hpp#L12), [L91-92](https://github.com/boykopovar/AnyPS5/blob/53924632bb2d58011dafedc13b809e31cddbdb5c/core/libs/prx/libSceAgcDriver/Execution/include/Driver/Shaders/ShaderRegistry.hpp#L91-L92) | | |
adriadam10 commented 2026-10-10 23:06:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T23:06:11Z.


Checked the diff, prepared_graphics/prepared_publication/prepared_shaders (20 repeats) and the AGC driver ctest scope on current main; all pass, and the new tests don't build without the change.

Added one commit: a bullet in docs/dev/ARCHITECTURE.md describing the per-code header registry (header selection for ABI vs. by binary type for draws, last-wins within a type, invalidation on changed code), since this changes the registry's ownership model.

Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6103148918 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2856#issuecomment-6103148918). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T23:06:11Z. --- Checked the diff, `prepared_graphics`/`prepared_publication`/`prepared_shaders` (20 repeats) and the AGC driver ctest scope on current main; all pass, and the new tests don't build without the change. Added one commit: a bullet in `docs/dev/ARCHITECTURE.md` describing the per-code header registry (header selection for ABI vs. by binary type for draws, last-wins within a type, invalidation on changed code), since this changes the registry's ownership model. Merging.
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!2856
No description provided.