fix(libSceAgc): fuse geometry halves with the back half's register lists #10048

Merged
hypermoist merged 6 commits from upstream-pr/10048 into main 2026-11-01 04:38:29 +00:00
hypermoist commented 2026-10-23 06:21:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by hypermoist on 2026-10-23T06:21:23Z.


What

For geometry halves, sceAgcFuseShaderHalves_0200 wrote the back half's SH registers into the caller's memory plus every front-half SH register the back half lacks (except the front checksum). sceAgcGetFusedShaderSize_0080 reported that longer list. The fused context register list merged in the front half's context registers the same way.

The decrypted PS5 13.60 libSceAgc.sprx (read from disassembly, not measured on a console) does neither:

  • Fuse (sceAgcFuseShaderHalves, 0xf7d0): for both pair types (4 with 6, and 5 with 7) it copies the back half's 0x60-byte header into the result and sets the fused type. When memory is passed, it copies back->num_sh_registers × 8 bytes of the back half's registers there and points the result at them. It then patches those registers in place. Its only writes to the result header are that copy, the type byte and the SH register pointer, so the fused header keeps the back half's SH count and the back half's context register pointer and count. No front register is added to either list, and the context registers are not patched.
  • Size (_0080, 0xf750): both pair types report back->num_sh_registers × 8, alignment 4.

This brings us in line:

  • The fused geometry SH list is now the back half's registers, with the resource and program-address patches as before.
  • The fused context register list is now the back half's, unchanged.
  • The size query reports eight bytes per back register for geometry halves too. It still runs the geometry layout first, so halves the fusion cannot handle throw at the size query, as before.

Why it matters: a title that sizes the memory from the size query was fine before, because both sides used the longer list. But on the console that memory only ever holds the back half's list. A front-only register would therefore make our fusion write past a buffer sized the console's way. The test shows this: with the old list restored, the fusion writes past the reported size.

Unchanged and recorded in the new debt entry: the fused program is still rebuilt in memory libSceAgc owns, so the header's tables are copies beside the fused code rather than the back half's own. Hull halves are not changed.

The code is written from the observed behaviour; nothing from the module is copied.

Tested

agc_shader_fusion now checks:

  • the geometry size is the back half's six registers;
  • the fused register count equals the back half's;
  • the front-only register 0x0B2 is not in the fused list;
  • the context registers are the back half's one register, and the front-only 0x2D5 is dropped;
  • nothing is written past the reported size (an existing check).

Restoring the old SH register loop makes the test fail ("fusion wrote past the reported size"), and so does restoring the old context register merge ("fused register counts are wrong"). The rejection cases (no final jump, no trailer, embedded constants) still throw from the size query.

  • Linux (CachyOS, GCC 16.2.1, Release): agc_shader_fusion passes; the NID-patched libSceAgc.prx builds.
  • Windows build: cross-built with WinLibs GCC 15.2.0 and run under Wine; agc_shader_fusion passes and the NID-patched prx builds.
  • Validation layer: ctest -V -R '^agc_shader_fusion$' with VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, ANYPS5_NO_SHADER_CACHE=1 and ANYPS5_REQUIRE_VULKAN=1, on main 0a0ed72167 and on this change (fd6782a638), on the same machine and GPU (NVIDIA GeForce RTX 3060, driver 615.78.08, CachyOS Linux 7.2.9, vulkan-validation-layers 1.4.363). Both pass. Neither log reports the missing-layer warning, the loader's layer debug output shows the layer inserted at instance and device level in both, and neither log has a VUID- error or any other validation message. Logs are in the review reply.
  • Not run: a title. PPSA02100 and PPSA21564, the titles behind the current design (d6f67d1be2, 258e4d526d), were not run.

tools/check_conventions.py is clean. Overlap (tools/pr_overlap.py):

  • #8314 (ours) adds lines right after the geometry size check in tests/ShaderFusion.cpp. Its new assertions compare with size.m_size and hold with this change, so whichever lands second only needs that hunk merged.
  • #1060 touches docs/dev/debt/libSceAgc.md and could not be compared.

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: #8314 (both edit ShaderFusion.cpp; this lands second and keeps both assertions)
  • Fixes: none
  • Unblocks: none known
  • GPUs tested: NVIDIA GeForce RTX 3060, driver 615.78.08, CachyOS Linux 7.2.9 (focused test with the validation layer; no title run)
  • AI-assisted: yes

Assisted With AI: Yes. All tests were run locally on computer hardware (AMD Ryzen 5 5600G, 32 GB RAM, NVIDIA GeForce RTX 3060, CachyOS Linux 7.3, GCC 16.2), not on an actual console.

https://claude.ai/code/session_01SNqSvnFwRBz3D76n476yw6

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4978739938 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10048). Originally posted by [hypermoist](https://github.com/hypermoist) on 2026-10-23T06:21:23Z. --- ### What For geometry halves, `sceAgcFuseShaderHalves_0200` wrote the back half's SH registers into the caller's memory plus every front-half SH register the back half lacks (except the front checksum). `sceAgcGetFusedShaderSize_0080` reported that longer list. The fused context register list merged in the front half's context registers the same way. The decrypted PS5 13.60 `libSceAgc.sprx` (read from disassembly, not measured on a console) does neither: - **Fuse** (`sceAgcFuseShaderHalves`, 0xf7d0): for both pair types (4 with 6, and 5 with 7) it copies the back half's 0x60-byte header into the result and sets the fused type. When memory is passed, it copies `back->num_sh_registers` × 8 bytes of the back half's registers there and points the result at them. It then patches those registers in place. Its only writes to the result header are that copy, the type byte and the SH register pointer, so the fused header keeps the back half's SH count and the back half's context register pointer and count. No front register is added to either list, and the context registers are not patched. - **Size** (`_0080`, 0xf750): both pair types report `back->num_sh_registers` × 8, alignment 4. This brings us in line: - The fused geometry SH list is now the back half's registers, with the resource and program-address patches as before. - The fused context register list is now the back half's, unchanged. - The size query reports eight bytes per back register for geometry halves too. It still runs the geometry layout first, so halves the fusion cannot handle throw at the size query, as before. Why it matters: a title that sizes the memory from the size query was fine before, because both sides used the longer list. But on the console that memory only ever holds the back half's list. A front-only register would therefore make our fusion write past a buffer sized the console's way. The test shows this: with the old list restored, the fusion writes past the reported size. Unchanged and recorded in the new debt entry: the fused program is still rebuilt in memory libSceAgc owns, so the header's tables are copies beside the fused code rather than the back half's own. Hull halves are not changed. The code is written from the observed behaviour; nothing from the module is copied. ### Tested `agc_shader_fusion` now checks: - the geometry size is the back half's six registers; - the fused register count equals the back half's; - the front-only register 0x0B2 is not in the fused list; - the context registers are the back half's one register, and the front-only 0x2D5 is dropped; - nothing is written past the reported size (an existing check). Restoring the old SH register loop makes the test fail ("fusion wrote past the reported size"), and so does restoring the old context register merge ("fused register counts are wrong"). The rejection cases (no final jump, no trailer, embedded constants) still throw from the size query. - **Linux** (CachyOS, GCC 16.2.1, Release): `agc_shader_fusion` passes; the NID-patched `libSceAgc.prx` builds. - **Windows build:** cross-built with WinLibs GCC 15.2.0 and run under Wine; `agc_shader_fusion` passes and the NID-patched prx builds. - **Validation layer:** `ctest -V -R '^agc_shader_fusion$'` with `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, `ANYPS5_NO_SHADER_CACHE=1` and `ANYPS5_REQUIRE_VULKAN=1`, on `main` 0a0ed72167 and on this change (fd6782a638), on the same machine and GPU (NVIDIA GeForce RTX 3060, driver 615.78.08, CachyOS Linux 7.2.9, vulkan-validation-layers 1.4.363). Both pass. Neither log reports the missing-layer warning, the loader's layer debug output shows the layer inserted at instance and device level in both, and neither log has a `VUID-` error or any other validation message. Logs are in the review reply. - **Not run:** a title. PPSA02100 and PPSA21564, the titles behind the current design (d6f67d1be2, 258e4d526d), were not run. `tools/check_conventions.py` is clean. Overlap (`tools/pr_overlap.py`): - #8314 (ours) adds lines right after the geometry size check in `tests/ShaderFusion.cpp`. Its new assertions compare with `size.m_size` and hold with this change, so whichever lands second only needs that hunk merged. - #1060 touches `docs/dev/debt/libSceAgc.md` and could not be compared. ### 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 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: #8314 (both edit `ShaderFusion.cpp`; this lands second and keeps both assertions) - [x] Fixes: none - [x] Unblocks: none known - [x] GPUs tested: NVIDIA GeForce RTX 3060, driver 615.78.08, CachyOS Linux 7.2.9 (focused test with the validation layer; no title run) - [x] AI-assisted: yes Assisted With AI: Yes. All tests were run locally on computer hardware (AMD Ryzen 5 5600G, 32 GB RAM, NVIDIA GeForce RTX 3060, CachyOS Linux 7.3, GCC 16.2), not on an actual console. https://claude.ai/code/session_01SNqSvnFwRBz3D76n476yw6
MarcZX10 commented 2026-10-23 06:25:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T06:25:03Z.

Review: CHANGES_REQUESTED


The SH-list change is consistent with the described 12.00 disassembly: the fused geometry header and caller buffer now use the back half's count, while resource and program-address patches are retained. I also checked that ComputeGeometryLayout still validates the unsupported geometry layouts before the size query returns, and that the revised test keeps the reported-size boundary assertion.

I could not run agc_shader_fusion locally: the available checkout is a source snapshot without Git metadata or a configured AnyPS5 build, and the repository checkout has no configured build tree. The reported GCC/Linux and Windows/Wine runs are useful, and the current hosted PR checks report success for eligibility, conventions, intake, labels and progress report; the hosted product build jobs are skipped.

Before approval, please attach the repository-required matched main and change agc_shader_fusion runs with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1 and VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, from the same machine and GPU. Please include the GPU vendor/model/driver/OS and confirm the logs contain no missing-layer warning and no new VUID- errors. The PR currently describes an RTX 3060 test device but no validation-layer comparison or title run. Also, the branch is 2 commits behind current main; please refresh it and rerun the focused checks so the review covers the current base. The reported #8314 test overlap appears manageable as described, but should be rechecked after the refresh.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5624694787 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10048#pullrequestreview-5624694787). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T06:25:03Z. **Review:** CHANGES_REQUESTED --- The SH-list change is consistent with the described 12.00 disassembly: the fused geometry header and caller buffer now use the back half's count, while resource and program-address patches are retained. I also checked that `ComputeGeometryLayout` still validates the unsupported geometry layouts before the size query returns, and that the revised test keeps the reported-size boundary assertion. I could not run `agc_shader_fusion` locally: the available checkout is a source snapshot without Git metadata or a configured AnyPS5 build, and the repository checkout has no configured build tree. The reported GCC/Linux and Windows/Wine runs are useful, and the current hosted PR checks report success for eligibility, conventions, intake, labels and progress report; the hosted product build jobs are skipped. Before approval, please attach the repository-required matched `main` and change `agc_shader_fusion` runs with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1` and `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, from the same machine and GPU. Please include the GPU vendor/model/driver/OS and confirm the logs contain no missing-layer warning and no new `VUID-` errors. The PR currently describes an RTX 3060 test device but no validation-layer comparison or title run. Also, the branch is 2 commits behind current `main`; please refresh it and rerun the focused checks so the review covers the current base. The reported #8314 test overlap appears manageable as described, but should be rechecked after the refresh.
MarcZX10 commented 2026-10-23 06:28:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T06:28:05Z.

Review: CHANGES_REQUESTED


Re-reviewed exact head f6483c444400a6be0b42ffdc471a1c3a1c9fe9eb. The added context-register change is consistent with the PR's described header behavior: ComputeGeometryLayout now retains the back half's SH and CX lists, while the existing geometry code/resource patching remains. The updated regression checks that the front-only context register is absent. Local git diff --check and tools/check_conventions.py --base upstream/main --head HEAD pass; tools/check_main_sync.py reports 2 commits ahead / 20 behind current upstream/main, with a clean merge.

The outstanding validation request remains: the repo requires matched agc_shader_fusion runs on main and the change using ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, and VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, from the same GPU/machine, including a VUID comparison. The reported Linux and Windows/Wine focused tests are useful but do not include that baseline/head validation evidence. Hosted eligibility, conventions, labels, and report checks pass; hosted product build jobs are skipped. No configured local build is available here, so I did not run the focused runtime test. Please refresh against current main, rerun the required matched checks on the resulting head, and recheck the #8314 test overlap after the refresh.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5624717385 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10048#pullrequestreview-5624717385). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T06:28:05Z. **Review:** CHANGES_REQUESTED --- Re-reviewed exact head `f6483c444400a6be0b42ffdc471a1c3a1c9fe9eb`. The added context-register change is consistent with the PR's described header behavior: `ComputeGeometryLayout` now retains the back half's SH and CX lists, while the existing geometry code/resource patching remains. The updated regression checks that the front-only context register is absent. Local `git diff --check` and `tools/check_conventions.py --base upstream/main --head HEAD` pass; `tools/check_main_sync.py` reports 2 commits ahead / 20 behind current `upstream/main`, with a clean merge. The outstanding validation request remains: the repo requires matched `agc_shader_fusion` runs on main and the change using `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1`, and `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, from the same GPU/machine, including a VUID comparison. The reported Linux and Windows/Wine focused tests are useful but do not include that baseline/head validation evidence. Hosted eligibility, conventions, labels, and report checks pass; hosted product build jobs are skipped. No configured local build is available here, so I did not run the focused runtime test. Please refresh against current main, rerun the required matched checks on the resulting head, and recheck the #8314 test overlap after the refresh.
MarcZX10 commented 2026-10-23 13:24:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T13:24:12Z.

Review: CHANGES_REQUESTED


Re-reviewed exact head cb3bfca6dd6bf2556dcc0e7459c4c3b07f5037e9. The author has supplied the required matched agc_shader_fusion main/head validation-layer runs on the same RTX 3060 machine: both pass, the layer is present, no missing-layer warning or VUID appears, and the description records the GPU. A direct merge preview with open #8314 now reports a content conflict in core/libs/prx/libSceAgc/tests/ShaderFusion.cpp; both checklists say Depends on: none. Please agree the landing order with #8314’s author and declare it with Depends on if needed, preserving both assertions after rebase. This is a keep-both sequencing requirement, not a closure request.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5628849485 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10048#pullrequestreview-5628849485). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T13:24:12Z. **Review:** CHANGES_REQUESTED --- Re-reviewed exact head `cb3bfca6dd6bf2556dcc0e7459c4c3b07f5037e9`. The author has supplied the required matched `agc_shader_fusion` main/head validation-layer runs on the same RTX 3060 machine: both pass, the layer is present, no missing-layer warning or VUID appears, and the description records the GPU. A direct merge preview with open #8314 now reports a content conflict in `core/libs/prx/libSceAgc/tests/ShaderFusion.cpp`; both checklists say `Depends on: none`. Please agree the landing order with #8314’s author and declare it with `Depends on` if needed, preserving both assertions after rebase. This is a keep-both sequencing requirement, not a closure request.
MarcZX10 commented 2026-10-29 08:23:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T08:23:43Z.

Review: APPROVED


Re-reviewed exact head be777913bd7f9b781082e9c4b668f3ab65f46baa against live main 4c7d275bef89d309313d16bc2bc05d37a1b50be2.

The earlier #8314 sequencing blocker is resolved: #8314's author confirmed it lands first, and this PR records Depends on: #8314, preserving both test assertions on rebase. The separate #10919 debt ordering is also resolved because #10919 merged first and this branch retains both debt entries.

The geometry fusion change still validates back-half register counts and bounds writes to the queried size. The reported negative controls fail for the intended reasons. The same-machine validation-layer A/B run on the earlier feature revision showed agc_shader_fusion passing on both main and the change, the layer loaded in both logs, and no VUIDs. The subsequent changes do not alter the shader fusion source or test; the latest post-rebase report says the focused test and full Linux AGC suite passed, with the expected GPU-less skip behavior.

Current-main checks:

  • Merge preview is clean (40a6f192387b79ab9f7c5cb2ed06e29e48bc999a).
  • git diff --check and current-main conventions pass.
  • Main changed only the shared debt file since the PR base; the PR keeps the current entry.

I did not run GPU tests locally. No blocking finding remains.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5694720790 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10048#pullrequestreview-5694720790). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-29T08:23:43Z. **Review:** APPROVED --- Re-reviewed exact head `be777913bd7f9b781082e9c4b668f3ab65f46baa` against live `main` `4c7d275bef89d309313d16bc2bc05d37a1b50be2`. The earlier #8314 sequencing blocker is resolved: #8314's author confirmed it lands first, and this PR records `Depends on: #8314`, preserving both test assertions on rebase. The separate #10919 debt ordering is also resolved because #10919 merged first and this branch retains both debt entries. The geometry fusion change still validates back-half register counts and bounds writes to the queried size. The reported negative controls fail for the intended reasons. The same-machine validation-layer A/B run on the earlier feature revision showed `agc_shader_fusion` passing on both main and the change, the layer loaded in both logs, and no VUIDs. The subsequent changes do not alter the shader fusion source or test; the latest post-rebase report says the focused test and full Linux AGC suite passed, with the expected GPU-less skip behavior. Current-main checks: - Merge preview is clean (`40a6f192387b79ab9f7c5cb2ed06e29e48bc999a`). - `git diff --check` and current-main conventions pass. - Main changed only the shared debt file since the PR base; the PR keeps the current entry. I did not run GPU tests locally. No blocking finding remains.
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!10048
No description provided.