fix(agc): read user-data callees up to the 1 MiB raw shader program limit #10140

Merged
frankea merged 1 commit from upstream-pr/10140 into main 2026-10-30 00:25:59 +00:00
frankea commented 2026-10-23 10:40:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by frankea on 2026-10-23T10:40:30Z.


What

ReadUserDataCallee (6d9321fc5) reads a compute shader's user-data or table callee from guest memory until it can prove the return, and throws once it has read 16,384 dwords (64 KiB) without one. Persona 3 Reload (PPSA10872) calls a 17,369-dword callee from compute shader 0x2014960000, so the dispatch throws its callee at ... does not return within 65536 bytes before the shader is recompiled; @zaidhawk raised the limit to 32,768 dwords locally to get past it (#9068 comment).

  • The callee window is now 1 MiB, the limit ShaderRegistry already uses for the raw shader program it reads at the same address range (limit = 1024 * 1024 in the snapshot reader). A callee that does not return within it still throws the same message with the new size, and an unreadable page before the return still throws is not readable at.
  • UserDataCalleeLength decodes the callee from its start each time it is asked, and the reader asked after every 4 KiB page, so reading n dwords cost O(n²/1024) decoded dwords. With a window 16 times larger, the reader now asks when the read size has doubled since the last check, at the limit, and when the next page is unreadable, so a callee costs at most about twice its length in decoded dwords. The result is the same: UserDataCalleeLength returns at the first s_setpc_b64 through the link register, so words read past it never change the answer, and the checks before an unreadable page and at the limit keep every callee that returned before.

Tested

Windows 11 (build 26200), NVIDIA GeForce RTX 4090 (driver 616.92), MinGW GCC (WinLibs 15.2) Release build with BUILD_TESTING=ON.

  • New case in agc_driver_compute_user_data_calls (both modes, plain and --registered, wave32 and wave64 where the test runs them): a 20,000-dword callee (v_add_nc_u32 v1, 1, v1, 19,998 s_nop 0, s_setpc_b64 s[14:15]) in 20 committed pages of a reservation whose 21st page is not committed, called with the existing 64-adding callee: every lane gets 3 x (1 + 64). The return lies in the last page, which is read after the last size check, so the case also covers the check before an unreadable page.
  • The 5 ctest entries of agc_driver_compute_user_data_calls (2), agc_driver_compute_table_calls, agc_driver_compute_fs_table_calls and scalar_call:
    • This PR (947329467 on main 513ca7e55): 5/5, each test run three times (ctest --repeat until-fail:3).
    • Control: main 513ca7e55 with only this PR's ComputeUserDataCalls.cpp: both agc_driver_compute_user_data_calls entries fail with main's its callee at 0x1f044a90000 does not return within 65536 bytes; the other three pass.
    • main 513ca7e55: 5/5.
  • Validation layer: VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation (Vulkan SDK 1.4.363.0), ANYPS5_NO_SHADER_CACHE=1 and ANYPS5_REQUIRE_VULKAN=1 with ctest -V, on this PR and on main 513ca7e55: 5/5 each, neither log has was not found but was requested by env var VK_INSTANCE_LAYERS, and neither has a VUID- line or any other validation message.
  • Not run on Linux, and Persona 3 Reload isn't on this machine. tools/check_conventions.py --base origin/main passes.

Checklist

  • Based on current main; no other open PR implements the same functions. #8140 (tv7) also edits ReadUserDataCallee, for a different change (it lets table callees read their program counter); #9068 and #8070 change how callees are linked and matched, not how far one is read.
  • 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: #11442 (agreed with @Sam-mon7: it lands first, and this PR merges main after it and keeps its DrainShaderWrites calls). Also overlaps #8140 in ReadUserDataCallee: proposed order #8140 first, then this PR merges main and passes #8140's allowGetpc through finish to UserDataCalleeLength (asked on #8140).
  • Fixes: none
  • Unblocks: PPSA10872 #9692 (with #9068 and #8070 its 0x2014960000 callees link; with #9701 to #9703 it then prepares before the RenderThread watchdog and stops on #7459, per @zaidhawk's run in #9068)
  • GPUs tested: NVIDIA GeForce RTX 4090, driver 616.92, Windows 11 build 26200
  • AI-assisted: yes (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4981495757 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10140). Originally posted by [frankea](https://github.com/frankea) on 2026-10-23T10:40:30Z. --- ### What `ReadUserDataCallee` (6d9321fc5) reads a compute shader's user-data or table callee from guest memory until it can prove the return, and throws once it has read 16,384 dwords (64 KiB) without one. Persona 3 Reload (PPSA10872) calls a 17,369-dword callee from compute shader 0x2014960000, so the dispatch throws `its callee at ... does not return within 65536 bytes` before the shader is recompiled; @zaidhawk raised the limit to 32,768 dwords locally to get past it ([#9068 comment](https://github.com/boykopovar/AnyPS5/pull/9068#issuecomment-6358922915)). - The callee window is now 1 MiB, the limit `ShaderRegistry` already uses for the raw shader program it reads at the same address range (`limit = 1024 * 1024` in the snapshot reader). A callee that does not return within it still throws the same message with the new size, and an unreadable page before the return still throws `is not readable at`. - `UserDataCalleeLength` decodes the callee from its start each time it is asked, and the reader asked after every 4 KiB page, so reading n dwords cost O(n²/1024) decoded dwords. With a window 16 times larger, the reader now asks when the read size has doubled since the last check, at the limit, and when the next page is unreadable, so a callee costs at most about twice its length in decoded dwords. The result is the same: `UserDataCalleeLength` returns at the first `s_setpc_b64` through the link register, so words read past it never change the answer, and the checks before an unreadable page and at the limit keep every callee that returned before. ### Tested Windows 11 (build 26200), NVIDIA GeForce RTX 4090 (driver 616.92), MinGW GCC (WinLibs 15.2) Release build with `BUILD_TESTING=ON`. - New case in `agc_driver_compute_user_data_calls` (both modes, plain and `--registered`, wave32 and wave64 where the test runs them): a 20,000-dword callee (`v_add_nc_u32 v1, 1, v1`, 19,998 `s_nop 0`, `s_setpc_b64 s[14:15]`) in 20 committed pages of a reservation whose 21st page is not committed, called with the existing 64-adding callee: every lane gets 3 x (1 + 64). The return lies in the last page, which is read after the last size check, so the case also covers the check before an unreadable page. - The 5 ctest entries of `agc_driver_compute_user_data_calls` (2), `agc_driver_compute_table_calls`, `agc_driver_compute_fs_table_calls` and `scalar_call`: - This PR (947329467 on `main` 513ca7e55): 5/5, each test run three times (`ctest --repeat until-fail:3`). - Control: `main` 513ca7e55 with only this PR's `ComputeUserDataCalls.cpp`: both `agc_driver_compute_user_data_calls` entries fail with `main`'s `its callee at 0x1f044a90000 does not return within 65536 bytes`; the other three pass. - `main` 513ca7e55: 5/5. - Validation layer: `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` (Vulkan SDK 1.4.363.0), `ANYPS5_NO_SHADER_CACHE=1` and `ANYPS5_REQUIRE_VULKAN=1` with `ctest -V`, on this PR and on `main` 513ca7e55: 5/5 each, neither log has `was not found but was requested by env var VK_INSTANCE_LAYERS`, and neither has a `VUID-` line or any other validation message. - Not run on Linux, and Persona 3 Reload isn't on this machine. `tools/check_conventions.py --base origin/main` passes. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions. #8140 (tv7) also edits `ReadUserDataCallee`, for a different change (it lets table callees read their program counter); #9068 and #8070 change how callees are linked and matched, not how far one is read. - [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: #11442 (agreed with @Sam-mon7: it lands first, and this PR merges `main` after it and keeps its `DrainShaderWrites` calls). Also overlaps #8140 in `ReadUserDataCallee`: proposed order #8140 first, then this PR merges `main` and passes #8140's `allowGetpc` through `finish` to `UserDataCalleeLength` (asked on #8140). - [x] Fixes: none - [x] Unblocks: PPSA10872 #9692 (with #9068 and #8070 its 0x2014960000 callees link; with #9701 to #9703 it then prepares before the RenderThread watchdog and stops on #7459, per @zaidhawk's run in #9068) - [x] GPUs tested: NVIDIA GeForce RTX 4090, driver 616.92, Windows 11 build 26200 - [x] AI-assisted: yes (Claude Code)
MarcZX10 commented 2026-10-23 10:44:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T10:44:20Z.

Review: APPROVED


The reader change raises the bound to the existing raw-program 1 MiB limit and replaces per-page full rescans with geometric checks; it still checks for a return before reporting an unreadable next page and retains the bounded no-return error. The regression allocates 20,000 dwords across committed pages followed by an unreadable page and checks both registered/unregistered dispatch paths where supported. The author reports repeated focused CTest passes, explicit main-control failures for the new long-callee cases, unchanged-main controls, and validation-layer runs on Windows/RTX 4090. Those runtime results are author-reported; I could not run the GPU test locally, and a local syntax-only compile was blocked by absent decoder/SPIR-V development headers. In the exact worktree, conventions, diff-check, and main-sync checks pass (1 ahead/4 behind current main; merge clean). Hosted eligibility/intake/conventions/labels pass; product jobs are skipped by the workflow.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5627153478 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10140#pullrequestreview-5627153478). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T10:44:20Z. **Review:** APPROVED --- The reader change raises the bound to the existing raw-program 1 MiB limit and replaces per-page full rescans with geometric checks; it still checks for a return before reporting an unreadable next page and retains the bounded no-return error. The regression allocates 20,000 dwords across committed pages followed by an unreadable page and checks both registered/unregistered dispatch paths where supported. The author reports repeated focused CTest passes, explicit main-control failures for the new long-callee cases, unchanged-main controls, and validation-layer runs on Windows/RTX 4090. Those runtime results are author-reported; I could not run the GPU test locally, and a local syntax-only compile was blocked by absent decoder/SPIR-V development headers. In the exact worktree, conventions, diff-check, and main-sync checks pass (1 ahead/4 behind current main; merge clean). Hosted eligibility/intake/conventions/labels pass; product jobs are skipped by the workflow.
MarcZX10 commented 2026-10-23 11:00:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T11:00:33Z.

Review: CHANGES_REQUESTED


A current overlap was missed in the checklist: open #8140 also edits ReadUserDataCallee in ShaderRegistry.cpp (adding the allowGetpc parameter and using it for table callees). I fetched its current head and pairwise git merge-tree reports a content conflict in this same function. The behavior is distinct, but whichever merges second must reconcile both changes; please coordinate the order with #8140’s author and record the integration dependency/overlap in the checklist. This is required by the repository overlap rule. Your local checks and reported RTX 4090 focused runs remain relevant; I did not run a GPU test locally.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5627312277 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10140#pullrequestreview-5627312277). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T11:00:33Z. **Review:** CHANGES_REQUESTED --- A current overlap was missed in the checklist: open #8140 also edits `ReadUserDataCallee` in `ShaderRegistry.cpp` (adding the `allowGetpc` parameter and using it for table callees). I fetched its current head and pairwise `git merge-tree` reports a content conflict in this same function. The behavior is distinct, but whichever merges second must reconcile both changes; please coordinate the order with #8140’s author and record the integration dependency/overlap in the checklist. This is required by the repository overlap rule. Your local checks and reported RTX 4090 focused runs remain relevant; I did not run a GPU test locally.
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!10140
No description provided.