feat(shader): split and continue table calls that cannot be linked #22359

Merged
Remi-Bon merged 6 commits from upstream-pr/22359 into main 2026-11-20 09:59:17 +00:00
Remi-Bon commented 2026-11-17 12:47:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Remi-Bon on 2026-11-17T12:47:50Z.


What

A compute shader that calls through a table is linked today by copying every callee at the call site. That fails for two kinds of program in PPSA01317 (Gran Turismo 7):

  • a table call in a waterfall loop with hundreds of callees, whose linked shader reaches 3.8-4.9 M SPIR-V words (more than 15 min per pipeline in the Vulkan driver);
  • a table call that is not in a waterfall loop and whose table holds up to 375 targets (over the 64 linked targets), so the dispatch is refused and skipped.

The second case makes the game lose the device. The skipped dispatch, material writer 0x120aed7f00, leaves its classifier records zero. A counter program then writes 1.41 M threads into an indirect argument slot, and the waterfall dispatch 0x120aea4f00 that reads it never converges. In the photo scenes the game shows after a few minutes idle on the world map, the image freezes, then Windows resets the GPU (TDR) and the game ends.

With APS5_SPLIT_TABLE_CALLS, such a program runs as several compute pipelines instead:

  • Split (SplitTableCall, BuildSplitTableCallPrograms), for a call in an LLVM-style waterfall loop. An entry part runs to the end of the loop and saves each lane's target and registers instead of calling. One part per callee replays the loop with only that callee linked. A resume part reloads the end state and runs the rest.
  • Continuation (ContinueTableCall, BuildTableCallContinuation), for a call in any other loop that no branch enters from before it. The entry part stops each wave at the call and stores its target. Callee parts replay the code before the loop, reload the saved state, run the callee and save again. The driver repeats rounds until no lane calls, at most 2^12 rounds.
  • Scalar registers that only callees write are compiled as the value from before the loop. A lane whose saved value differs records a SplitState fault instead of running on (new IR op SplitStateGuard).
  • State lives per lane in a storage buffer at descriptor set 3, laid out by SplitStateAbi. Dispatches run in slices of APS5_SPLIT_STATE_LANES lanes (default 2^18). An indirect dispatch runs APS5_SPLIT_SLICES slices (default 8), with counts copied from the GPU argument buffer.
  • The driver reads the targets back after the entry part. It then compiles (in parallel) and runs only the callee parts a lane selects, so a table of hundreds of callees does not build hundreds of pipelines.
  • Every split part has the loop guard (2^12 loop exits per invocation). A waterfall the replay cannot end is then a reported fault, not a device loss.

A program that qualifies for neither path keeps the linked path. Without the variable nothing changes. Limits are listed under Split table calls and Continued table calls in docs/dev/debt/libSceAgcDriver.md.

Known limits:

  • Speed. In the photo scenes a continued dispatch takes about 450 ms per frame (1.5 FPS, about 22 rounds). The café scene spends about 30 s in one (about 110 rounds, about 110 ms per part dispatch), which is 0.03 FPS. The cost per part dispatch was not measured further.
  • The callee and resume parts re-run the code before the loop, so its loads must read what they read the first time.
  • The callees of the 26 sibling material shaders make split parts of up to 278k SPIR-V words that compile very slowly.

Tested

Windows 11 Pro 26300, RX 9070.

  • scalar_call: split and continuation structure, IR and refusals.
  • agc_split_table_call_tests: full recompilation of every part, with SPIR-V validated.
  • agc_driver_split_table_call_run: a wave32 waterfall with 3 callees, run linked, split direct with slices, and split indirect including an empty slice.
  • With ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer, ctest -R "^(agc_driver_(dispatch|indirect|compute|table|user_data|storage_flush)[a-z_]*|agc_driver_split_table_call_run|scalar_call)$" -V: main 35/35 passed (no agc_driver_split_table_call_run there); this PR, rebased on main 9504fbb964, 36/36 passed. Both logs show the loader inserting VK_LAYER_KHRONOS_validation, neither has was not found but was requested, and neither has a VUID- error.
  • PPSA01317: the photo scenes that lost the device run without DEVICE_LOST, at the speeds above. This ran on a development branch whose split code matches this PR line for line, except the 3 lines that adapt to main's ReadTableCallees dependencies argument. On main alone the title stops before its menu (layered rendering with a depth target is unsupported, which #7256 handles), so it was not rerun on this branch. The material writer runs, the counter writes 0 groups, and the waterfall gets no lanes.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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: none
  • Fixes: none
  • Unblocks: PPSA01317 #4697
  • GPUs tested: AMD Radeon RX 9070, driver 32.0.32015.7029, Windows 11 Pro 26300
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5357108022 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22359). Originally posted by [Remi-Bon](https://github.com/Remi-Bon) on 2026-11-17T12:47:50Z. --- ### What A compute shader that calls through a table is linked today by copying every callee at the call site. That fails for two kinds of program in PPSA01317 (Gran Turismo 7): - a table call in a waterfall loop with hundreds of callees, whose linked shader reaches 3.8-4.9 M SPIR-V words (more than 15 min per pipeline in the Vulkan driver); - a table call that is not in a waterfall loop and whose table holds up to 375 targets (over the 64 linked targets), so the dispatch is refused and skipped. The second case makes the game lose the device. The skipped dispatch, material writer 0x120aed7f00, leaves its classifier records zero. A counter program then writes 1.41 M threads into an indirect argument slot, and the waterfall dispatch 0x120aea4f00 that reads it never converges. In the photo scenes the game shows after a few minutes idle on the world map, the image freezes, then Windows resets the GPU (TDR) and the game ends. With `APS5_SPLIT_TABLE_CALLS`, such a program runs as several compute pipelines instead: - **Split** (`SplitTableCall`, `BuildSplitTableCallPrograms`), for a call in an LLVM-style waterfall loop. An entry part runs to the end of the loop and saves each lane's target and registers instead of calling. One part per callee replays the loop with only that callee linked. A resume part reloads the end state and runs the rest. - **Continuation** (`ContinueTableCall`, `BuildTableCallContinuation`), for a call in any other loop that no branch enters from before it. The entry part stops each wave at the call and stores its target. Callee parts replay the code before the loop, reload the saved state, run the callee and save again. The driver repeats rounds until no lane calls, at most 2^12 rounds. - Scalar registers that only callees write are compiled as the value from before the loop. A lane whose saved value differs records a `SplitState` fault instead of running on (new IR op `SplitStateGuard`). - State lives per lane in a storage buffer at descriptor set 3, laid out by `SplitStateAbi`. Dispatches run in slices of `APS5_SPLIT_STATE_LANES` lanes (default 2^18). An indirect dispatch runs `APS5_SPLIT_SLICES` slices (default 8), with counts copied from the GPU argument buffer. - The driver reads the targets back after the entry part. It then compiles (in parallel) and runs only the callee parts a lane selects, so a table of hundreds of callees does not build hundreds of pipelines. - Every split part has the loop guard (2^12 loop exits per invocation). A waterfall the replay cannot end is then a reported fault, not a device loss. A program that qualifies for neither path keeps the linked path. Without the variable nothing changes. Limits are listed under Split table calls and Continued table calls in `docs/dev/debt/libSceAgcDriver.md`. Known limits: - Speed. In the photo scenes a continued dispatch takes about 450 ms per frame (1.5 FPS, about 22 rounds). The café scene spends about 30 s in one (about 110 rounds, about 110 ms per part dispatch), which is 0.03 FPS. The cost per part dispatch was not measured further. - The callee and resume parts re-run the code before the loop, so its loads must read what they read the first time. - The callees of the 26 sibling material shaders make split parts of up to 278k SPIR-V words that compile very slowly. ### Tested Windows 11 Pro 26300, RX 9070. - `scalar_call`: split and continuation structure, IR and refusals. - `agc_split_table_call_tests`: full recompilation of every part, with SPIR-V validated. - `agc_driver_split_table_call_run`: a wave32 waterfall with 3 callees, run linked, split direct with slices, and split indirect including an empty slice. - With `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer`, `ctest -R "^(agc_driver_(dispatch|indirect|compute|table|user_data|storage_flush)[a-z_]*|agc_driver_split_table_call_run|scalar_call)$" -V`: main 35/35 passed (no `agc_driver_split_table_call_run` there); this PR, rebased on main 9504fbb964, 36/36 passed. Both logs show the loader inserting `VK_LAYER_KHRONOS_validation`, neither has `was not found but was requested`, and neither has a `VUID-` error. - PPSA01317: the photo scenes that lost the device run without DEVICE_LOST, at the speeds above. This ran on a development branch whose split code matches this PR line for line, except the 3 lines that adapt to `main`'s `ReadTableCallees` dependencies argument. On `main` alone the title stops before its menu (`layered rendering with a depth target is unsupported`, which #7256 handles), so it was not rerun on this branch. The material writer runs, the counter writes 0 groups, and the waterfall gets no lanes. ### 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) and the licence notice of code adapted from upstream (see AGENTS.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: none - [x] Fixes: none - [x] Unblocks: PPSA01317 #4697 - [x] GPUs tested: AMD Radeon RX 9070, driver 32.0.32015.7029, Windows 11 Pro 26300 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-11-19 10:14:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-19T10:14:50Z.

Review: COMMENTED


Reviewed — no blocking findings

Nothing blocks this review from a formal decision, but the review is incomplete because most changed files were not read.

What I ran

  • Reviewed the prepared bundle for head 20c99cc94d89acbf2e3503d0090897bbc01764a6.
  • No tests or programmatic checks were run.

Results

Check Result Note
Bundle inspection passed Description, commits and initial diff read
Tests not run Author-reported results only
Full code review not run Most changed code remains unread

Findings

Blocking

None verified in the portions inspected.

Non-blocking

None.

Not verified

The review is incomplete. Only the description, commits, first 599 lines of the diff, and one line of the oversized VulkanDevice.cpp were read. The remaining diff and most changed code were not inspected; therefore no conclusion about their correctness is supported. The description's test and game-run results are author-reported, not independently run. The prepared file listing indicates the changed file set, but review/files.json was unavailable through the reader.

To get this to a good state

Complete inspection of the remaining changed code and run applicable checks before a formal review decision.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5973067068 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22359#pullrequestreview-5973067068). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-19T10:14:50Z. **Review:** COMMENTED --- # Reviewed — no blocking findings Nothing blocks this review from a formal decision, but the review is incomplete because most changed files were not read. ## What I ran - Reviewed the prepared bundle for head `20c99cc94d89acbf2e3503d0090897bbc01764a6`. - No tests or programmatic checks were run. ## Results | Check | Result | Note | |---|---|---| | Bundle inspection | passed | Description, commits and initial diff read | | Tests | not run | Author-reported results only | | Full code review | not run | Most changed code remains unread | ## Findings ### Blocking None verified in the portions inspected. ### Non-blocking None. ## Not verified The review is incomplete. Only the description, commits, first 599 lines of the diff, and one line of the oversized `VulkanDevice.cpp` were read. The remaining diff and most changed code were not inspected; therefore no conclusion about their correctness is supported. The description's test and game-run results are author-reported, not independently run. The prepared file listing indicates the changed file set, but `review/files.json` was unavailable through the reader. ## To get this to a good state Complete inspection of the remaining changed code and run applicable checks before a formal review decision.
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!22359
No description provided.