fix(shader): link table calls whose descriptor comes from another buffer #14296

Merged
ycbuzi merged 2 commits from upstream-pr/14296 into main 2026-11-14 03:52:06 +00:00
ycbuzi commented 2026-11-01 07:04:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ycbuzi on 2026-11-01T07:04:08Z.


What

FindTableCalls links a compute shader's s_swappc_b64 when its target comes from a call table, but only when the table's descriptor is loaded through a pointer with s_load_dword*. Marvel's Spider-Man Remastered (PPSA01467) loads that descriptor one level deeper, from another buffer, so the call stayed unlinked and the shader was refused (#14168):

s_load_dwordx4        s8,  s[12:13], 0x220   (descriptor A, through the pointer)
s_buffer_load_dwordx4 s72, s[8:11],  0x40    (descriptor B, from A's buffer)
s_lshl_b32            vcc_lo, s8, 4
s_buffer_load_dwordx4 s8,  s[72:75], vcc_lo  (the record)
s_swappc_b64          s[14:15], s[14:15]
  • FindTableCalls now follows that one extra level and records its offset in TableCall::nestedDescriptorOffset. The nested load needs an immediate, dword-aligned offset and no register offset; anything else stays refused as before.
  • ReadTableCallees reads descriptor A, checks that the offset fits inside A's buffer, and reads descriptor B from it. The rest of the linking is unchanged.

The limits are in docs/dev/debt/libSceAgcDriver.md: one level only, and the descriptor is read once at link time.

This is not a full fix for the title. It moves past this stop to later ones, listed under Tested.

Tested

Windows 11, Ryzen 9 7900, Release, WinLibs GCC 15.2.0.

Tests on the commit before this PR and on this PR, same machine, ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, run through ctest -V from a non-elevated process. A control test (agc_driver_vertex_fetch) proved the layer loaded on both sides (43 layer log lines), and no log has the missing-layer line.

Tests: agc_driver_compute_fs_table_calls, agc_driver_compute_table_calls, agc_driver_compute_nested_table_call, agc_driver_prepared_shaders, scalar_call. The new execution test was kept on the base side as a negative control.

GPU Base, without the source change This PR VUID- lines, both sides
NVIDIA RTX 4070 SUPER 4 of 5 pass; agc_driver_compute_nested_table_call fails 5 of 5 pass 0
AMD Radeon iGPU 4 of 5 pass; agc_driver_compute_nested_table_call fails 5 of 5 pass 0

These ran before a final rebase onto current main. After the rebase I reran the same five tests with ANYPS5_REQUIRE_VULKAN=1 on the 4070 only, without the layer, and they pass.

Marvel's Spider-Man Remastered (PPSA01467, 01.008.001), RTX 4070 SUPER, NVIDIA 616.92, APS5_PLAYGO_UNLISTED_CHUNKS=installed, a backport's fake-signed eboot.bin with the game's own data. A script pressed the buttons and nobody played. The only library swapped is libSceAgcDriver.prx.

Run End Frames
Without this PR 60 s: computed/data-dependent s_swappc_b64 call target at program counter 0x0000136c is not statically resolvable 6
This PR, first run 180 s: read-write alias of shared guest memory 0xb126960000+0x40000: a resident run of direct memory extends outside the range 176
This PR, second run 60 s: GetImageResource dword 0 is not a valid runtime value 16

The s_swappc_b64 refusal does not appear in either run with this PR, and it was logged in every earlier run without it. Those two later stops are different from each other, and I have not looked into either. I did not check the picture, and the frame rate is still under 4 FPS.

The game's table contents were not inspected beyond linking succeeding, and no other title with this shape was tested.

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
  • 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
  • Fixes: Fixes #14168
  • Unblocks: none (PPSA01467 moves on to the later stops above)
  • GPUs tested: NVIDIA RTX 4070 SUPER, driver 616.92, Windows 11; AMD Radeon iGPU (Ryzen 9 7900), Windows 11
  • AI-assisted: yes

#8140 changes the same call-linking code (FindTableCalls, LinkCalls and ShaderRegistry.cpp) for a different refusal, a callee that reads its program counter. Whichever lands second will need a small merge.

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5105224966 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14296). Originally posted by [ycbuzi](https://github.com/ycbuzi) on 2026-11-01T07:04:08Z. --- ### What `FindTableCalls` links a compute shader's `s_swappc_b64` when its target comes from a call table, but only when the table's descriptor is loaded through a pointer with `s_load_dword*`. Marvel's Spider-Man Remastered (PPSA01467) loads that descriptor one level deeper, from another buffer, so the call stayed unlinked and the shader was refused (#14168): ``` s_load_dwordx4 s8, s[12:13], 0x220 (descriptor A, through the pointer) s_buffer_load_dwordx4 s72, s[8:11], 0x40 (descriptor B, from A's buffer) s_lshl_b32 vcc_lo, s8, 4 s_buffer_load_dwordx4 s8, s[72:75], vcc_lo (the record) s_swappc_b64 s[14:15], s[14:15] ``` - `FindTableCalls` now follows that one extra level and records its offset in `TableCall::nestedDescriptorOffset`. The nested load needs an immediate, dword-aligned offset and no register offset; anything else stays refused as before. - `ReadTableCallees` reads descriptor A, checks that the offset fits inside A's buffer, and reads descriptor B from it. The rest of the linking is unchanged. The limits are in `docs/dev/debt/libSceAgcDriver.md`: one level only, and the descriptor is read once at link time. This is not a full fix for the title. It moves past this stop to later ones, listed under Tested. ### Tested Windows 11, Ryzen 9 7900, Release, WinLibs GCC 15.2.0. **Tests on the commit before this PR and on this PR**, same machine, `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1`, `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, run through `ctest -V` from a non-elevated process. A control test (`agc_driver_vertex_fetch`) proved the layer loaded on both sides (43 layer log lines), and no log has the missing-layer line. Tests: `agc_driver_compute_fs_table_calls`, `agc_driver_compute_table_calls`, `agc_driver_compute_nested_table_call`, `agc_driver_prepared_shaders`, `scalar_call`. The new execution test was kept on the base side as a negative control. | GPU | Base, without the source change | This PR | `VUID-` lines, both sides | | --- | --- | --- | --- | | NVIDIA RTX 4070 SUPER | 4 of 5 pass; `agc_driver_compute_nested_table_call` fails | 5 of 5 pass | 0 | | AMD Radeon iGPU | 4 of 5 pass; `agc_driver_compute_nested_table_call` fails | 5 of 5 pass | 0 | These ran before a final rebase onto current `main`. After the rebase I reran the same five tests with `ANYPS5_REQUIRE_VULKAN=1` on the 4070 only, without the layer, and they pass. **Marvel's Spider-Man Remastered (PPSA01467, 01.008.001)**, RTX 4070 SUPER, NVIDIA 616.92, `APS5_PLAYGO_UNLISTED_CHUNKS=installed`, a backport's fake-signed `eboot.bin` with the game's own data. A script pressed the buttons and nobody played. The only library swapped is `libSceAgcDriver.prx`. | Run | End | Frames | | --- | --- | --- | | Without this PR | 60 s: `computed/data-dependent s_swappc_b64 call target at program counter 0x0000136c is not statically resolvable` | 6 | | This PR, first run | 180 s: `read-write alias of shared guest memory 0xb126960000+0x40000: a resident run of direct memory extends outside the range` | 176 | | This PR, second run | 60 s: `GetImageResource dword 0 is not a valid runtime value` | 16 | The `s_swappc_b64` refusal does not appear in either run with this PR, and it was logged in every earlier run without it. Those two later stops are different from each other, and I have not looked into either. I did not check the picture, and the frame rate is still under 4 FPS. The game's table contents were not inspected beyond linking succeeding, and no other title with this shape was tested. ### 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) - [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] Fixes: Fixes #14168 - [x] Unblocks: none (PPSA01467 moves on to the later stops above) - [x] GPUs tested: NVIDIA RTX 4070 SUPER, driver 616.92, Windows 11; AMD Radeon iGPU (Ryzen 9 7900), Windows 11 - [x] AI-assisted: yes #8140 changes the same call-linking code (`FindTableCalls`, `LinkCalls` and `ShaderRegistry.cpp`) for a different refusal, a callee that reads its program counter. Whichever lands second will need a small merge. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-11-02 06:37:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-02T06:37:40Z.

Review: COMMENTED


Reviewed — no blocking findings

Table calls whose descriptor is loaded from a buffer, which itself came through the table pointer, are now followed one level: the recompiler's FindTableCalls records a nested descriptor offset, and ReadTableCallees reads the nested descriptor once at link time. The bounds checks I read come before each read. The new unit check and the execution test did not run on this head, so the behaviour is not verified by any run.

What I ran

  • Head 46dc30ea75b06c5f56ba5486c0119d53c7996181; base b41526345185943c53af0c6eee97863df4389c9e. 6 files, +148/-3: ShaderRegistry.cpp (+5: the nested read in ReadTableCallees), ControlFlow/src/GraphBuilder.cpp (+21/-3: the nested descriptor search in FindTableCalls), ControlFlow/include/ControlFlow/GraphBuilder.hpp (+1: a nestedDescriptorOffset field), core/libs/tests/ScalarCall.cpp (+17: CheckNestedTableCall), tests/execution/ComputeNestedTableCall.cpp (+106, not read in full), and docs/dev/debt/libSceAgcDriver.md (+1).
  • Read the production diffs in full. Checked the new bounds: descriptor < innerLoaded is tested before descriptor - innerLoaded; the inner load's size and offset are checked; the outer pointer must be 4-dword aligned; the nested offset is inner.memoryOffset + (descriptor - innerLoaded) * 4; and ReadTableCallees checks that offset against the outer descriptor's size before it reads.
  • Read the new scalar unit check (CheckNestedTableCall) and the debt entry.
  • Not read: findLastWriter, reachingWriter, sameBlock and the execution test. The analysis is not traced beyond the lines in the diff.
  • Hosted: Build, windows and both relinker jobs passed. The Windows CTest run reports one case (100% tests passed, 0 tests failed out of 1), so CheckNestedTableCall and the execution test did not run.
  • Read-only checks from the trusted main checkout: diff check, conventions and PR template, and the stack check all passed. The ABI audit is not applicable.
  • No MarcZX10 review at this head.

Results

Check Result Note
Diff check passed
Conventions and PR template passed conventions check from the main checkout
Mergeability and dependencies passed stack check passed; no declared dependencies
Bounds of the inner load and the outer pointer (read) passed by reading checked before each read or index
Nested descriptor offset and its read in ReadTableCallees (read) passed by reading the offset is checked against the outer descriptor's size
The analysis helpers (findLastWriter, reachingWriter, sameBlock) not verified not read; the nested path relies on them
CheckNestedTableCall (scalar unit check) not run the Windows CTest run reports one case
ComputeNestedTableCall (execution test) not run not in the Windows execution list; not read in full
ABI audit not applicable no export changed
Build and runtime tests (Linux) not run Linux is skipped on pull requests
Negative controls not run no local build
Hosted CI passed (build) Build, windows (one case), both relinker jobs, Conventions, PR intake, PR labels, Progress report and the Emscripten portability job succeeded
Read-only check output

Precheck was not run: no PR-head code is run here. Diff check: passed. Conventions: passed. ABI audit: not applicable. Stack check: passed. Hosted: gh api repos/boykopovar/AnyPS5/commits/46dc30ea75b06c5f56ba5486c0119d53c7996181/check-runs, and the Windows job log.

Negative control

Not run here. A negative control needs a local build and run, and code from this head is not run here.

Findings

Blocking

None, as far as the code read here goes.

Non-blocking

  • No run covers the nested path. CheckNestedTableCall and ComputeNestedTableCall did not run on Windows, and this head has no Linux run. A run of the ScalarCall test (which calls CheckNestedTableCall) and of the execution test on a GPU host would show whether the path works.
  • The debt entry says a deeper chain is refused as not statically resolvable. That claim depends on the analysis helpers, which were not read here.

Sources

Not verified

  • The analysis helpers (findLastWriter, reachingWriter, sameBlock) and whether the nested search is sound on every path.
  • The execution test ComputeNestedTableCall (not read in full).
  • Any run of the nested path.

To get this to a good state

  • Run the scalar unit check and the execution test on a host that runs them, and post the result.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5732877928 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14296#pullrequestreview-5732877928). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-02T06:37:40Z. **Review:** COMMENTED --- # Reviewed — no blocking findings Table calls whose descriptor is loaded from a buffer, which itself came through the table pointer, are now followed one level: the recompiler's `FindTableCalls` records a nested descriptor offset, and `ReadTableCallees` reads the nested descriptor once at link time. The bounds checks I read come before each read. The new unit check and the execution test did not run on this head, so the behaviour is not verified by any run. ## What I ran - Head `46dc30ea75b06c5f56ba5486c0119d53c7996181`; base `b41526345185943c53af0c6eee97863df4389c9e`. 6 files, +148/-3: `ShaderRegistry.cpp` (+5: the nested read in `ReadTableCallees`), `ControlFlow/src/GraphBuilder.cpp` (+21/-3: the nested descriptor search in `FindTableCalls`), `ControlFlow/include/ControlFlow/GraphBuilder.hpp` (+1: a `nestedDescriptorOffset` field), `core/libs/tests/ScalarCall.cpp` (+17: `CheckNestedTableCall`), `tests/execution/ComputeNestedTableCall.cpp` (+106, not read in full), and `docs/dev/debt/libSceAgcDriver.md` (+1). - Read the production diffs in full. Checked the new bounds: `descriptor < innerLoaded` is tested before `descriptor - innerLoaded`; the inner load's size and offset are checked; the outer pointer must be 4-dword aligned; the nested offset is `inner.memoryOffset + (descriptor - innerLoaded) * 4`; and `ReadTableCallees` checks that offset against the outer descriptor's size before it reads. - Read the new scalar unit check (`CheckNestedTableCall`) and the debt entry. - Not read: `findLastWriter`, `reachingWriter`, `sameBlock` and the execution test. The analysis is not traced beyond the lines in the diff. - Hosted: `Build`, `windows` and both `relinker` jobs passed. The Windows CTest run reports one case (`100% tests passed, 0 tests failed out of 1`), so `CheckNestedTableCall` and the execution test did not run. - Read-only checks from the trusted main checkout: diff check, conventions and PR template, and the stack check all passed. The ABI audit is not applicable. - No MarcZX10 review at this head. ## Results | Check | Result | Note | | --- | --- | --- | | Diff check | passed | | | Conventions and PR template | passed | conventions check from the main checkout | | Mergeability and dependencies | passed | stack check passed; no declared dependencies | | Bounds of the inner load and the outer pointer (read) | passed by reading | checked before each read or index | | Nested descriptor offset and its read in `ReadTableCallees` (read) | passed by reading | the offset is checked against the outer descriptor's size | | The analysis helpers (`findLastWriter`, `reachingWriter`, `sameBlock`) | not verified | not read; the nested path relies on them | | `CheckNestedTableCall` (scalar unit check) | not run | the Windows CTest run reports one case | | `ComputeNestedTableCall` (execution test) | not run | not in the Windows execution list; not read in full | | ABI audit | not applicable | no export changed | | Build and runtime tests (Linux) | not run | Linux is skipped on pull requests | | Negative controls | not run | no local build | | Hosted CI | passed (build) | Build, windows (one case), both relinker jobs, Conventions, PR intake, PR labels, Progress report and the Emscripten portability job succeeded | <details><summary>Read-only check output</summary> Precheck was not run: no PR-head code is run here. Diff check: passed. Conventions: passed. ABI audit: not applicable. Stack check: passed. Hosted: `gh api repos/boykopovar/AnyPS5/commits/46dc30ea75b06c5f56ba5486c0119d53c7996181/check-runs`, and the Windows job log. </details> ## Negative control Not run here. A negative control needs a local build and run, and code from this head is not run here. ## Findings **Blocking** None, as far as the code read here goes. **Non-blocking** - No run covers the nested path. `CheckNestedTableCall` and `ComputeNestedTableCall` did not run on Windows, and this head has no Linux run. A run of the `ScalarCall` test (which calls `CheckNestedTableCall`) and of the execution test on a GPU host would show whether the path works. - The debt entry says a deeper chain is refused as not statically resolvable. That claim depends on the analysis helpers, which were not read here. ## Sources - Registry: https://github.com/boykopovar/AnyPS5/blob/46dc30ea75b06c5f56ba5486c0119d53c7996181/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp - Graph builder: https://github.com/boykopovar/AnyPS5/blob/46dc30ea75b06c5f56ba5486c0119d53c7996181/core/shader/recompiler/ControlFlow/src/GraphBuilder.cpp - Scalar unit check: https://github.com/boykopovar/AnyPS5/blob/46dc30ea75b06c5f56ba5486c0119d53c7996181/core/libs/tests/ScalarCall.cpp - Debt entry: https://github.com/boykopovar/AnyPS5/blob/46dc30ea75b06c5f56ba5486c0119d53c7996181/docs/dev/debt/libSceAgcDriver.md - Windows job log: check-run `windows` on 46dc30ea75b06c5f56ba5486c0119d53c7996181 ## Not verified - The analysis helpers (`findLastWriter`, `reachingWriter`, `sameBlock`) and whether the nested search is sound on every path. - The execution test `ComputeNestedTableCall` (not read in full). - Any run of the nested path. ## To get this to a good state - Run the scalar unit check and the execution test on a host that runs them, and post the result.
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!14296
No description provided.