fix(shader): follow a table call's descriptor through a v_writelane/v_readlane spill #24232

Merged
almarzn merged 1 commit from upstream-pr/24232 into main 2026-11-21 02:19:27 +00:00
almarzn commented 2026-11-20 11:29:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by almarzn on 2026-11-20T11:29:29Z.


What

FindTableCalls traced a table call's buffer descriptor back only through scalar writes. When the shader compiler spilled the descriptor to VGPR lanes and restored it with v_readlane_b32 before the call, the call stayed unresolved and the program was refused with computed/data-dependent s_swappc_b64 call target ... is not statically resolvable.

With this change, when the descriptor's writer is a v_readlane_b32, FindTableCalls follows each of the four registers back to the v_writelane_b32 that saved it. From there it continues to the scalar load that produced the value, and the rest of the table-call checks run unchanged from that load. It gives up whenever any of these holds:

  • a restore lane is not an inline constant below 32;
  • the four restores read different VGPRs or non-consecutive lanes;
  • more than one v_writelane_b32 reaches a restore;
  • anything else on a path between save and restore may write the lane's VGPR (v_movrel*/v_swaprel, or a VALU or memory destination whose width covers the register; the memory width includes a TFE dword);
  • the saved registers are not consecutive, or are not all written by the same load.

The backward walk of reachingWriter becomes reachingDefinition, a template that takes the definition test; reachingWriter keeps its behaviour on top of it.

The shape, from PPSA24913 (Ace Combat 8, UE5), compute shader with 5220 code words, wave32, APS5_DUMP_SHADERS=1:

0x0524 s_load_dwordx4 s[4:7], s[0:1], 0x10
0x05fc v_writelane_b32 v81, s7, 23      ; and s6, s5, s4 to lanes 22, 21, 20
...                                     ; s[4:7] reused as scratch
0x08bc v_readfirstlane_b32 vcc_lo, v112 ; waterfall loop head
0x08cc v_readlane_b32 s4, v81, 20       ; s5..s7 from lanes 21..23
0x08fc s_lshl_b32 vcc_lo, vcc_lo, 4
0x0900 s_buffer_load_dwordx4 s[4:7], s[4:7], vcc_lo
0x090c s_mov_b32 s18, s4                ; s19..s21 from s5..s7
0x091c s_swappc_b64 s[18:19], s[18:19]

The program has four such calls (0x91c, 0xe64, 0x2114, 0x2608); FindTableCalls now returns all four as 16-byte table calls through user data s[0:1].

A second shader of the same title (4664 code words, table calls at 0x8c0, 0x1490 and 0x17e8) was refused on main at 0x1490, where the descriptor is spilled the same way. With this change FindTableCalls finds all three calls, and in a later PPSA24913 run the shader was prepared and dumped as an ordinary request with no skipped dispatch.

Tested

Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release, on main at c8eb2aac70.

  • scalar_call_tests: a new case adds a lane spill to the hoisted waterfall shape, for wave32 and wave64. It now finds the call, links it and translates it. Two variants are still refused, both by FindTableCalls and by GraphBuilder (not statically resolvable): restoring from other lanes, and a v_mov_b32 to the spill VGPR inside the loop. Negative control: with GraphBuilder.cpp from main the test fails (scalar call regression).

  • ctest -R "scalar_call|agc_linked_code|table_call" with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1: 47/47 pass. Before the rebase I built three GPU execution tests with -DANYPS5_AGC_EXECUTION_TESTS=ComputeTableCalls;ComputeNestedTableCall;ComputeFsTableCalls; they are among the 47.

  • Validation layer: the LunarG SDK installer needs elevation, which was not available on this machine. I used VkLayer_khronos_validation built from Vulkan-ValidationLayers vulkan-sdk-1.4.363.1 with the same MinGW toolchain, loaded through VK_ADD_LAYER_PATH. I ran scalar_call|agc_linked_code|agc_shader_memory|agc_driver_compute_fs_table_calls|agc_driver_compute_nested_table_call|agc_driver_compute_table_calls with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation and VK_LOADER_DEBUG=layer on main (e825fa1492) and on this change. In both logs:

    • the loader inserts the layer three times (Insert instance layer "VK_LAYER_KHRONOS_validation");
    • there is no was not found but was requested by env var VK_INSTANCE_LAYERS;
    • there are no VUID- lines;
    • 46 of 49 tests pass;
    • the same three GPU table-call tests stop with unhandled exception 0xc0000005.

    The three pass on both without the layer, so I read the crash as coming from this MinGW build of the layer, not from the change. A run with an MSVC-built or SDK layer would settle it; I could not do one here.

  • python3 tools/check_conventions.py --base origin/main: passes.

  • PPSA24913 (relinked with --to-intel, Intel i5-12600KF), with APS5_SKIP_REFUSED_DISPATCHES=1:

    • On main (0626a8334f), the run logged a skipped dispatch for this shader at program counter 0x91c and one for the 0x1490 shader.
    • With this change, the shader was prepared and dumped as an ordinary request. No dispatch was skipped in the 317 s before the run was stopped for host memory. In a later run of 287 s the 0x1490 shader was prepared and dumped as an ordinary request, and no dispatch was skipped either.
    • That build also carried #24158 and a local change to the end-of-pipe and wait-register patch functions, which are needed to get this far.

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: PPSA24913 #21185
  • GPUs tested: NVIDIA GeForce RTX 5070 Ti, driver 621.24 (32.0.16.2124), Windows 11 Pro 26200
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5412583111 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24232). Originally posted by [almarzn](https://github.com/almarzn) on 2026-11-20T11:29:29Z. --- ### What `FindTableCalls` traced a table call's buffer descriptor back only through scalar writes. When the shader compiler spilled the descriptor to VGPR lanes and restored it with `v_readlane_b32` before the call, the call stayed unresolved and the program was refused with `computed/data-dependent s_swappc_b64 call target ... is not statically resolvable`. With this change, when the descriptor's writer is a `v_readlane_b32`, `FindTableCalls` follows each of the four registers back to the `v_writelane_b32` that saved it. From there it continues to the scalar load that produced the value, and the rest of the table-call checks run unchanged from that load. It gives up whenever any of these holds: - a restore lane is not an inline constant below 32; - the four restores read different VGPRs or non-consecutive lanes; - more than one `v_writelane_b32` reaches a restore; - anything else on a path between save and restore may write the lane's VGPR (`v_movrel*`/`v_swaprel`, or a VALU or memory destination whose width covers the register; the memory width includes a TFE dword); - the saved registers are not consecutive, or are not all written by the same load. The backward walk of `reachingWriter` becomes `reachingDefinition`, a template that takes the definition test; `reachingWriter` keeps its behaviour on top of it. The shape, from PPSA24913 (Ace Combat 8, UE5), compute shader with 5220 code words, wave32, `APS5_DUMP_SHADERS=1`: ``` 0x0524 s_load_dwordx4 s[4:7], s[0:1], 0x10 0x05fc v_writelane_b32 v81, s7, 23 ; and s6, s5, s4 to lanes 22, 21, 20 ... ; s[4:7] reused as scratch 0x08bc v_readfirstlane_b32 vcc_lo, v112 ; waterfall loop head 0x08cc v_readlane_b32 s4, v81, 20 ; s5..s7 from lanes 21..23 0x08fc s_lshl_b32 vcc_lo, vcc_lo, 4 0x0900 s_buffer_load_dwordx4 s[4:7], s[4:7], vcc_lo 0x090c s_mov_b32 s18, s4 ; s19..s21 from s5..s7 0x091c s_swappc_b64 s[18:19], s[18:19] ``` The program has four such calls (0x91c, 0xe64, 0x2114, 0x2608); `FindTableCalls` now returns all four as 16-byte table calls through user data `s[0:1]`. A second shader of the same title (4664 code words, table calls at 0x8c0, 0x1490 and 0x17e8) was refused on `main` at 0x1490, where the descriptor is spilled the same way. With this change `FindTableCalls` finds all three calls, and in a later PPSA24913 run the shader was prepared and dumped as an ordinary request with no skipped dispatch. ### Tested Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release, on `main` at c8eb2aac70. - `scalar_call_tests`: a new case adds a lane spill to the hoisted waterfall shape, for wave32 and wave64. It now finds the call, links it and translates it. Two variants are still refused, both by `FindTableCalls` and by `GraphBuilder` (`not statically resolvable`): restoring from other lanes, and a `v_mov_b32` to the spill VGPR inside the loop. Negative control: with `GraphBuilder.cpp` from `main` the test fails (`scalar call regression`). - `ctest -R "scalar_call|agc_linked_code|table_call"` with `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1`: 47/47 pass. Before the rebase I built three GPU execution tests with `-DANYPS5_AGC_EXECUTION_TESTS=ComputeTableCalls;ComputeNestedTableCall;ComputeFsTableCalls`; they are among the 47. - Validation layer: the LunarG SDK installer needs elevation, which was not available on this machine. I used `VkLayer_khronos_validation` built from Vulkan-ValidationLayers `vulkan-sdk-1.4.363.1` with the same MinGW toolchain, loaded through `VK_ADD_LAYER_PATH`. I ran `scalar_call|agc_linked_code|agc_shader_memory|agc_driver_compute_fs_table_calls|agc_driver_compute_nested_table_call|agc_driver_compute_table_calls` with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1`, `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` and `VK_LOADER_DEBUG=layer` on `main` (e825fa1492) and on this change. In both logs: - the loader inserts the layer three times (`Insert instance layer "VK_LAYER_KHRONOS_validation"`); - there is no `was not found but was requested by env var VK_INSTANCE_LAYERS`; - there are no `VUID-` lines; - 46 of 49 tests pass; - the same three GPU table-call tests stop with `unhandled exception 0xc0000005`. The three pass on both without the layer, so I read the crash as coming from this MinGW build of the layer, not from the change. A run with an MSVC-built or SDK layer would settle it; I could not do one here. - `python3 tools/check_conventions.py --base origin/main`: passes. - PPSA24913 (relinked with `--to-intel`, Intel i5-12600KF), with `APS5_SKIP_REFUSED_DISPATCHES=1`: - On `main` (0626a8334f), the run logged a skipped dispatch for this shader at program counter 0x91c and one for the 0x1490 shader. - With this change, the shader was prepared and dumped as an ordinary request. No dispatch was skipped in the 317 s before the run was stopped for host memory. In a later run of 287 s the 0x1490 shader was prepared and dumped as an ordinary request, and no dispatch was skipped either. - That build also carried #24158 and a local change to the end-of-pipe and wait-register patch functions, which are needed to get this far. ### 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: PPSA24913 #21185 - [x] GPUs tested: NVIDIA GeForce RTX 5070 Ti, driver 621.24 (32.0.16.2124), Windows 11 Pro 26200 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-11-20 11:39:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T11:39:47Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the points below are optional.

What I ran

Reviewed head 3f7058bf1ee2100b50a3a59223197e61f97af4fb using the prepared diff and repo_read.py for targeted source ranges. I did not run tests or builds; the test results in the PR description are author-reported.

Results

Check Result Note
Changed-code review passed Both changed files read
Tests and build not run Author reports tests; not independently verified

Findings

Blocking

None.

Non-blocking

None.

Not verified

  • Runtime behavior and test results were not independently verified.
  • Files read: core/libs/tests/ScalarCall.cpp (changed lines 516–548, 670) and core/shader/recompiler/ControlFlow/src/GraphBuilder.cpp (changed code and relevant helpers/call site).
  • Excluded files: none; manifest.json lists both changed files as included, and the review file listing confirms both are available.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5992088561 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/24232#pullrequestreview-5992088561). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-20T11:39:47Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the points below are optional. ## What I ran Reviewed head `3f7058bf1ee2100b50a3a59223197e61f97af4fb` using the prepared diff and `repo_read.py` for targeted source ranges. I did not run tests or builds; the test results in the PR description are author-reported. ## Results | Check | Result | Note | |---|---|---| | Changed-code review | passed | Both changed files read | | Tests and build | not run | Author reports tests; not independently verified | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified - Runtime behavior and test results were not independently verified. - Files read: `core/libs/tests/ScalarCall.cpp` (changed lines 516–548, 670) and `core/shader/recompiler/ControlFlow/src/GraphBuilder.cpp` (changed code and relevant helpers/call site). - Excluded files: none; `manifest.json` lists both changed files as included, and the review file listing confirms both are available. ## To get this to a good state Nothing is required.
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!24232
No description provided.