fix(agc): read a merged program's vertex tables past its hidden user words #3738

Merged
Mouad-Scriptz-0 merged 1 commit from upstream-pr/3738 into main 2026-10-11 21:56:46 +00:00
Mouad-Scriptz-0 commented 2026-10-11 16:13:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Mouad-Scriptz-0 on 2026-10-11T16:13:29Z.


What

DecodeVertexStageInfo reads a vertex program's vertex buffer and attribute tables from the user-SGPR words the AGC header names (PtrVertexBufferTable, PtrVertexAttribDescTable, counted from the first user SGPR). For a merged program on the geometry path, DecodeGraphicsPrograms inserts the eight hidden user words of the merged layout at the front of userData (initializeMerged, firstUserSgpr 0), so those reads landed inside the hidden words and found zeros, and the draw threw null vertex buffer table address. The recompiler already maps the registers correctly (EmbeddedVertexFetchAnalyzer adds kEmbeddedFetchRegisterShift = 8), which is why only the host-side table reads were wrong.

  • DecodeVertexStageInfo takes hiddenUserWords (default 0) and adds it to the two table reads and their bounds checks only; fetchBufferReg and fetchAttribReg stay the header's registers.
  • The three callers pass 8 - firstUserSgpr (Draw.cpp, and both static-ABI calls in ShaderRegistry.cpp, where firstUser is already 0 for mesh programs and the plan's user count already includes the eight words).
  • agc_driver_graphics gains a header with tables at registers 4 and 6: the merged layout (eight hidden words, tables at words 12-15) decodes its resource and reports registers 4 and 6, the same layout with no hidden-word offset fails on the null table, and the plain layout still decodes.

Title: Killzone: Liberation (PPSA11142 01.000.004) stopped on its first PSP frame with this message (registers in #3622); with this change the draw decodes and the vertex program compiles. Closes #3622.

#1077 changes the same DecodeVertexStageInfo calls for an unrelated layered-target feature; the conflict is a one-line argument merge on each call.

Tested

Fedora 44 (kernel 7.2.8, GCC 16.2.1, Ninja, Release, BUILD_TESTING=ON, Intel Arc Meteor Lake iGPU), this commit on main a11c8f7f: agc_driver_graphics and agc_driver_pm4 pass; ctest -j4 --timeout 180 without the seven agc_driver_* tests that fail the same way on a clean main build on this iGPU (f64_fma_subnormals, vop1_float_unary, vopc_compare, prepared_shaders, prepared_shaders_indirect, prepared_shaders_uncached, prepared_shaders_debug): 824/825, the one failure (agc_driver_emulated_color_compare, an ANV sRGB sampling limit) failing identically on clean main; tools/check_conventions.py --base origin/main and git diff --check pass. Killzone: Liberation runs past the stop (Linux). Not tested on Windows.

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 (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4820454653 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3738). Originally posted by [Mouad-Scriptz-0](https://github.com/Mouad-Scriptz-0) on 2026-10-11T16:13:29Z. --- ### What `DecodeVertexStageInfo` reads a vertex program's vertex buffer and attribute tables from the user-SGPR words the AGC header names (`PtrVertexBufferTable`, `PtrVertexAttribDescTable`, counted from the first user SGPR). For a merged program on the geometry path, `DecodeGraphicsPrograms` inserts the eight hidden user words of the merged layout at the front of `userData` (`initializeMerged`, `firstUserSgpr` 0), so those reads landed inside the hidden words and found zeros, and the draw threw `null vertex buffer table address`. The recompiler already maps the registers correctly (`EmbeddedVertexFetchAnalyzer` adds `kEmbeddedFetchRegisterShift` = 8), which is why only the host-side table reads were wrong. - `DecodeVertexStageInfo` takes `hiddenUserWords` (default 0) and adds it to the two table reads and their bounds checks only; `fetchBufferReg` and `fetchAttribReg` stay the header's registers. - The three callers pass `8 - firstUserSgpr` (`Draw.cpp`, and both static-ABI calls in `ShaderRegistry.cpp`, where `firstUser` is already 0 for mesh programs and the plan's user count already includes the eight words). - `agc_driver_graphics` gains a header with tables at registers 4 and 6: the merged layout (eight hidden words, tables at words 12-15) decodes its resource and reports registers 4 and 6, the same layout with no hidden-word offset fails on the null table, and the plain layout still decodes. Title: Killzone: Liberation (PPSA11142 01.000.004) stopped on its first PSP frame with this message (registers in #3622); with this change the draw decodes and the vertex program compiles. Closes #3622. #1077 changes the same `DecodeVertexStageInfo` calls for an unrelated layered-target feature; the conflict is a one-line argument merge on each call. ### Tested Fedora 44 (kernel 7.2.8, GCC 16.2.1, Ninja, Release, `BUILD_TESTING=ON`, Intel Arc Meteor Lake iGPU), this commit on `main` a11c8f7f: `agc_driver_graphics` and `agc_driver_pm4` pass; `ctest -j4 --timeout 180` without the seven `agc_driver_*` tests that fail the same way on a clean `main` build on this iGPU (`f64_fma_subnormals`, `vop1_float_unary`, `vopc_compare`, `prepared_shaders`, `prepared_shaders_indirect`, `prepared_shaders_uncached`, `prepared_shaders_debug`): 824/825, the one failure (`agc_driver_emulated_color_compare`, an ANV sRGB sampling limit) failing identically on clean `main`; `tools/check_conventions.py --base origin/main` and `git diff --check` pass. Killzone: Liberation runs past the stop (Linux). Not tested on Windows. ### 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 - [x] AI-assisted: yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
adriadam10 commented 2026-10-11 21:56:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T21:56:42Z.


Checked the three call sites (Draw.cpp, both in ShaderRegistry.cpp) against DecodeGraphicsPrograms/initializeMerged and kEmbeddedFetchRegisterShift: the offset 8 - firstUserSgpr is 8 for merged programs and 0 otherwise. Built and ran the AgcDriver tests on main + this PR (384/384, agc_driver_graphics included); the new test needs the new parameter, so it cannot pass without the change. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6114242356 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3738#issuecomment-6114242356). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T21:56:42Z. --- Checked the three call sites (`Draw.cpp`, both in `ShaderRegistry.cpp`) against `DecodeGraphicsPrograms`/`initializeMerged` and `kEmbeddedFetchRegisterShift`: the offset `8 - firstUserSgpr` is 8 for merged programs and 0 otherwise. Built and ran the AgcDriver tests on `main` + this PR (384/384, `agc_driver_graphics` included); the new test needs the new parameter, so it cannot pass without the change. Merging.
Tamalero commented 2026-10-11 23:53:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Tamalero on 2026-10-11T23:53:23Z.


Confirmed on High on Life (PPSA15388 v01.120.000, Unreal Engine 4). Once #2261 routed its registered NGG culling programs to the mesh path, the run stopped right after the first level loaded with

AGC driver: guest memory is not readable at 0x10001302780aa0 (range 0x10001302780aa0+0x4)

raised from DecodeVertexStageInfo in Driver::draw. The address is the program's V# read as the table pointer, eight words too early, with its stride (16) left in bit 52. With this commit cherry-picked the stop is gone (2 runs), and the title continues into the level.

Tested and written by Claude (AI assistant) on a contributor's machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6115307458 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3738#issuecomment-6115307458). Originally posted by [Tamalero](https://github.com/Tamalero) on 2026-10-11T23:53:23Z. --- Confirmed on High on Life (PPSA15388 v01.120.000, Unreal Engine 4). Once #2261 routed its registered NGG culling programs to the mesh path, the run stopped right after the first level loaded with ``` AGC driver: guest memory is not readable at 0x10001302780aa0 (range 0x10001302780aa0+0x4) ``` raised from `DecodeVertexStageInfo` in `Driver::draw`. The address is the program's V# read as the table pointer, eight words too early, with its stride (16) left in bit 52. With this commit cherry-picked the stop is gone (2 runs), and the title continues into the level. *Tested and written by Claude (AI assistant) on a contributor's machine.*
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!3738
No description provided.