fix(agc): accept unaligned shader headers #902

Merged
Celegans12 merged 1 commit from upstream-pr/902 into main 2026-10-07 16:27:47 +00:00
Celegans12 commented 2026-10-06 14:49:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-06T14:49:56Z.


What

On main, Driver::RegisterShader (called by sceAgcCreateShader) throws AGC driver: null or misaligned address for a shader header that is not 8-byte aligned; PPSA26344 v1.008 passes such headers.

  • The header is accepted at any address; null and unreadable ranges still throw. Its fixed fields and traced register lists are copied out with memcpy; the code must still be 256-byte aligned.
  • Later readers use the registered copy (_readHeaderPod, RequestMemoryView) and need no change.
  • The title uses each .xpps pack's data section in place at an aligned base (all_shaders.xpps at 0x8000000000); its compute objects hold a header pointer at +0x30 and a code pointer at +0x38 for sceAgcCreateShader (eboot 0xab5133). In core_common_subcore.core_b1_fx.sprig.xpps, 16 compute headers sit 4 bytes and 16 sit 1 byte past an 8-byte boundary; the run stopped at the first, 0x801e374cc4 = 0x801e200000 + 0x174cc4.
  • Still throws: sceAgcCbSetShRegistersDirect needs a 4-byte aligned register list; the 1 mod 8 headers' lists sit at 1 mod 4 (eboot 0xab4412 passes sh_registers). No public source states the console's rule (TechnicalDebt).
  • #639 (draft) adds the same alignof(Shader) check to its new entry points in this file; the second to land should use one rule.

Tested

  • Windows 11, MinGW-w64 GCC 15.2.0, based on main 148b888c: configure -DBUILD_TESTING=ON, full build, --target libs, ctest:
  • 376/376 tests pass (ctest --output-on-failure)
  • Same build on lavapipe (Mesa 26.2.4 llvmpipe, 8-wide subgroups, VK_DRIVER_FILES): 375/375 pass; agc_driver_flat_store is left out there because it takes several minutes on Windows llvmpipe
  • agc_driver: new testShaderHeaderAlignment registers headers 0, 4 and 1 bytes past an 8-byte boundary and checks the refusals (null, unreadable, misaligned code, wrong version, short header); it fails on main with AGC driver: null or misaligned address.
  • PPSA26344 v1.008: all 32 headers at 4 or 1 mod 8 register.
  • Not tested: Linux (CI), 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
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4760472682 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/902). Originally posted by [Celegans12](https://github.com/Celegans12) on 2026-10-06T14:49:56Z. --- ### What On `main`, `Driver::RegisterShader` (called by `sceAgcCreateShader`) throws `AGC driver: null or misaligned address` for a shader header that is not 8-byte aligned; PPSA26344 v1.008 passes such headers. - The header is accepted at any address; null and unreadable ranges still throw. Its fixed fields and traced register lists are copied out with `memcpy`; the code must still be 256-byte aligned. - Later readers use the registered copy (`_readHeaderPod`, `RequestMemoryView`) and need no change. - The title uses each `.xpps` pack's data section in place at an aligned base (`all_shaders.xpps` at 0x8000000000); its compute objects hold a header pointer at +0x30 and a code pointer at +0x38 for `sceAgcCreateShader` (eboot 0xab5133). In `core_common_subcore.core_b1_fx.sprig.xpps`, 16 compute headers sit 4 bytes and 16 sit 1 byte past an 8-byte boundary; the run stopped at the first, 0x801e374cc4 = 0x801e200000 + 0x174cc4. - **Still throws:** `sceAgcCbSetShRegistersDirect` needs a 4-byte aligned register list; the 1 mod 8 headers' lists sit at 1 mod 4 (eboot 0xab4412 passes `sh_registers`). No public source states the console's rule (TechnicalDebt). - #639 (draft) adds the same `alignof(Shader)` check to its new entry points in this file; the second to land should use one rule. ### Tested - Windows 11, MinGW-w64 GCC 15.2.0, based on `main` 148b888c: configure `-DBUILD_TESTING=ON`, full build, `--target libs`, `ctest`: - 376/376 tests pass (`ctest --output-on-failure`) - Same build on lavapipe (Mesa 26.2.4 llvmpipe, 8-wide subgroups, `VK_DRIVER_FILES`): 375/375 pass; `agc_driver_flat_store` is left out there because it takes several minutes on Windows llvmpipe - `agc_driver`: new `testShaderHeaderAlignment` registers headers 0, 4 and 1 bytes past an 8-byte boundary and checks the refusals (null, unreadable, misaligned code, wrong version, short header); it fails on `main` with `AGC driver: null or misaligned address`. - PPSA26344 v1.008: all 32 headers at 4 or 1 mod 8 register. - Not tested: Linux (CI), console behaviour. ### 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 (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] AI-assisted: yes
adriadam10 commented 2026-10-07 16:27:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-07T16:27:44Z.


Checked on Linux on top of current main: build and full ctest green, agc_driver fails on main with null or misaligned address and passes with the change; the misaligned-code, version and short-header refusals still throw. The pr-overlap hit on #1128 is the repo-wide clang-format change, not a real overlap. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6042187184 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/902#issuecomment-6042187184). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-07T16:27:44Z. --- Checked on Linux on top of current main: build and full ctest green, `agc_driver` fails on main with `null or misaligned address` and passes with the change; the misaligned-code, version and short-header refusals still throw. The pr-overlap hit on #1128 is the repo-wide clang-format change, not a real overlap. 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!902
No description provided.