Skip to content

fix(shader): link table callees that together exceed s_call_b64 range - #9068

Merged
adriadam10 merged 3 commits into
boykopovar:mainfrom
frankea:table-callee-range
Oct 23, 2026
Merged

adriadam10 merged 3 commits into
boykopovar:mainfrom
frankea:table-callee-range

Conversation

@frankea

@frankea frankea commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

What

Gran Turismo 7's World Map dispatches a compute shader whose s_swappc_b64 calls through a table of about 35 material functions, about 40,000 dwords in all. Linking it threw the table callees of the call at program counter 0x00000ae4 land out of s_call_b64 range. Once it linked, the call model refused it with scalar call link register s[14] written at program counter 0x000018e4 escapes the constant-offset call/return model (used at program counter 0x000009f0). This PR fixes both.

  • LinkCalls appended every table callee after a single block of call sites, so a callee's s_call_b64 had to reach past all the callees before it. SIMM16 is a signed dword offset, so it reaches at most 0x7fff dwords forward (AMD RDNA2 ISA 3.6.3, S_CALL_B64). Each callee now gets its own segment: its compares for SCC 0, its compares for SCC 1, an s_call_b64 with offset 1, a return s_branch, then the copy. A mismatch branches over the copy to the next target's compares. A return goes back one s_branch per earlier copy to the instruction after the original call. No branch or call spans more than one copy, and a copy is at most 16,384 dwords (ReadUserDataCallee's limit). SCC handling is unchanged: one chain per SCC value at the call, and SCC is set back to that value before the callee or the unlinked call runs.
  • overwritesScalar counted only the first destination dword of SOP2 results and of SOP1 results other than s_mov_b64 and s_getpc_b64. In the GT7 shader, s_andn2_b64 s[14:15], s[6:7], s[4:5] overwrites a link pair and s_nor_b64 vcc, s[14:15], vcc then reads it. The escape check still marked s15 as holding a return address and refused the read. It now uses the decoder's dataDwordCount, which is 2 for the 64-bit results. The conditional and partial writers (s_cmov, s_bitset, s_movreld, s_movrelsd_2) and s_swappc/s_setpc are still not counted as overwrites. The escape check is the only caller.
  • A second table call in the same shader (Ghostrunner's 0x200c520000, reported in the comments) had to branch past every copy already appended for the earlier call. Before the first of an earlier call's copies and after each one, LinkCalls leaves a pair of s_branch relays for every later call, one toward its chain and one back toward the instruction after it, so those branches also span at most one copy. A shader with a single table call links as before.
  • Still throws: a call more than 0x7fff dwords before the end of the program and its user-data callees. The debt entry says so instead of the old s_call_b64 range limit.

Tested

  • Refreshed onto main 0db47b2 (head daef563; no conflicts), RTX 4090 (NVIDIA 616.92, Windows 11): the 33 ctest entries of scalar_call, agc_shader_control_flow, agc_driver_graphics and agc_driver_compute_table_calls pass 33/33, each test run three times, and 33/33 under the validation layer (VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, ANYPS5_NO_SHADER_CACHE=1, ANYPS5_REQUIRE_VULKAN=1, ctest -V), with no VUID- line; the layer reports nothing on this head. main 0db47b2 passes the union of the refreshed sets, 115/115, under the same layer settings with no VUID- line.
  • ScalarCall: the two-callee table now checks the interleaved layout word for word, plus the call and return edges of the graph built from it. Three 0x3001-dword callees and a small one link, which the old layout refused, and the last callee's call goes to its own copy and returns to its hop. A 0x8000-dword copy throws the 16-bit branch-range error. A call followed by s_andn2_b64 over the link pair and a 64-bit read builds; with s_and_b32 over only the low dword, the read of the high dword still throws.
  • ScalarCall: two table calls, the first with 36,890 dwords of copies: the second call reaches its chain and returns through the relays, and the graph built from the linked code has its call and return edges. Without the relays this case throws lands out of the 16-bit branch range.
  • RTX 4090 (NVIDIA 616.92, Windows 11, WinLibs GCC 15.2), head e5a02bd: scalar_call, agc_shader_control_flow (all three variants) and agc_driver_graphics pass.
  • Ghostrunner (PPSA03685 01.000.005) on the RTX 4090, same integration branch: shader 0x200c520000 links its table calls at 0x434 and 0xc84, then stops on a third call at 0x89c that FindTableCalls doesn't match (its descriptor comes from an s_load_dwordx8 through a loaded pointer), which this PR doesn't touch.
  • Gran Turismo 7 (PPSA01317 01.710.000) on the RTX 4090, with these two commits on a local integration branch (feat(agc): blend into 11_11_10 float color targets in the pixel shader #9020, fix(agc): raise no end-of-pipe event from flips and carry the release's interrupt context #7978, fix(agc): write a replace blend into a packed color target without blending #7243, feat(agc): render layered draws into a depth view of several slices #7256, fix(shader): answer image_get_resinfo on any T# dimension #7550): the World Map shader 0x120aed7f00 links and passes the call model. Its request replayed with agc_shader_replay now stops in the resource tracker on GetImageResource dword 0 is not a valid runtime value: the table's V# is loop-carried through callees that use those registers as scratch, which this PR doesn't touch.

Checklist

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 8140 core/shader/recompiler/ControlFlow/src/GraphBuilder.cpp L1621-1628
PR 10179 docs/dev/debt/libSceAgcDriver.md L223-224
PR 10420 docs/dev/debt/libSceAgcDriver.md L223-225

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 2434 docs/dev/debt/libSceAgcDriver.md
PR 4448 docs/dev/debt/libSceAgcDriver.md
PR 5058 docs/dev/debt/libSceAgcDriver.md
PR 5925 docs/dev/debt/libSceAgcDriver.md
PR 6044 core/libs/tests/ScalarCall.cpp
PR 6186 docs/dev/debt/libSceAgcDriver.md
PR 6194 docs/dev/debt/libSceAgcDriver.md
PR 6223 docs/dev/debt/libSceAgcDriver.md
PR 6273 docs/dev/debt/libSceAgcDriver.md
PR 6280 docs/dev/debt/libSceAgcDriver.md
PR 6300 docs/dev/debt/libSceAgcDriver.md
PR 6412 docs/dev/debt/libSceAgcDriver.md
PR 6481 docs/dev/debt/libSceAgcDriver.md
PR 6498 docs/dev/debt/libSceAgcDriver.md
PR 6548 docs/dev/debt/libSceAgcDriver.md
PR 6549 docs/dev/debt/libSceAgcDriver.md
PR 6808 docs/dev/debt/libSceAgcDriver.md
PR 6867 docs/dev/debt/libSceAgcDriver.md
PR 6959 docs/dev/debt/libSceAgcDriver.md
PR 6977 docs/dev/debt/libSceAgcDriver.md
PR 7002 docs/dev/debt/libSceAgcDriver.md
PR 7256 docs/dev/debt/libSceAgcDriver.md
PR 7307 docs/dev/debt/libSceAgcDriver.md
PR 7449 docs/dev/debt/libSceAgcDriver.md
PR 7604 docs/dev/debt/libSceAgcDriver.md
PR 7618 docs/dev/debt/libSceAgcDriver.md
PR 7642 docs/dev/debt/libSceAgcDriver.md
PR 7844 docs/dev/debt/libSceAgcDriver.md
PR 7893 docs/dev/debt/libSceAgcDriver.md
PR 7910 docs/dev/debt/libSceAgcDriver.md
PR 8014 docs/dev/debt/libSceAgcDriver.md
PR 8223 docs/dev/debt/libSceAgcDriver.md
PR 8319 docs/dev/debt/libSceAgcDriver.md
PR 8365 docs/dev/debt/libSceAgcDriver.md
PR 8419 docs/dev/debt/libSceAgcDriver.md
PR 8426 docs/dev/debt/libSceAgcDriver.md
PR 8542 docs/dev/debt/libSceAgcDriver.md
PR 8592 docs/dev/debt/libSceAgcDriver.md
PR 9186 docs/dev/debt/libSceAgcDriver.md
PR 9348 docs/dev/debt/libSceAgcDriver.md
PR 9356 docs/dev/debt/libSceAgcDriver.md
PR 9387 docs/dev/debt/libSceAgcDriver.md
PR 9393 docs/dev/debt/libSceAgcDriver.md
PR 9431 docs/dev/debt/libSceAgcDriver.md
PR 9432 docs/dev/debt/libSceAgcDriver.md
PR 9508 docs/dev/debt/libSceAgcDriver.md
PR 9592 docs/dev/debt/libSceAgcDriver.md
PR 9672 docs/dev/debt/libSceAgcDriver.md
PR 9673 docs/dev/debt/libSceAgcDriver.md
PR 9674 docs/dev/debt/libSceAgcDriver.md
PR 9675 docs/dev/debt/libSceAgcDriver.md
PR 9676 docs/dev/debt/libSceAgcDriver.md
PR 9748 docs/dev/debt/libSceAgcDriver.md
PR 9842 docs/dev/debt/libSceAgcDriver.md
PR 9891 docs/dev/debt/libSceAgcDriver.md
PR 9892 docs/dev/debt/libSceAgcDriver.md
PR 9893 docs/dev/debt/libSceAgcDriver.md
PR 9895 docs/dev/debt/libSceAgcDriver.md
PR 9898 docs/dev/debt/libSceAgcDriver.md
PR 9904 docs/dev/debt/libSceAgcDriver.md
PR 9905 docs/dev/debt/libSceAgcDriver.md
PR 9906 docs/dev/debt/libSceAgcDriver.md
PR 9941 docs/dev/debt/libSceAgcDriver.md
PR 10064 docs/dev/debt/libSceAgcDriver.md
PR 10193 docs/dev/debt/libSceAgcDriver.md
PR 10359 docs/dev/debt/libSceAgcDriver.md

@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed and removed needs rebase Conflicts with main, rebase needed labels Oct 21, 2026
@xXPBSXx

xXPBSXx commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Title data point for this PR (data only).

Title: PPSA03685, 300 s through the runner, ANYPS5_GPU=4080; both .out logs show Selected GPU name=NVIDIA GeForce RTX 4080 SUPER vendor=0x10de device=0x2702 subgroup=32. Windows 10 Pro 10.0.19045, WinLibs GCC 15.2.0, Release, relinker and all libs built from one tree.

Baseline, main 50efb5c405 (run_131429.err line 442, with a local print of the callee sizes added in the throw): compute shader 0x200c520000: the table callees of the call at program counter 0x00000434 land out of s_call_b64 range, callee 35 of 40, offset 33134; the 40 callees together are 36988 dwords (3 to 1724 each).

This PR (head 96e20522e6, PR base 80565c5942) merged locally into main 47fa6eecf8 (run_164357.err lines 440-441; the earlier head 84eb444119 gave the same result in run_151642.err): the first call is no longer refused, but the same shader stops at another table call:

what():  compute shader 0x200c520000: the table callees of the call at program counter 0x00000c84 lands out of the 16-bit branch range

The new message comes from branchWord, not from the s_call_b64 check. From reading LinkCalls on the PR head, linked[word] = branchWord(0xbf820000u, word, linked.size(), ...) jumps from the original s_swappc_b64 to the table's segments, which are appended at the end of the program, so a second large table call (0xc84) sits far from its dispatch once the first table's copies are in front of it. I did not print the sizes on the PR head to confirm that, so this is the likely reading, not a measurement.

One run per state. I did not look at the picture and I did not run the PR's tests on this machine for this comment.

Not run: the PR's tests, other GPUs for this title, the console.

AI-assisted (Claude Code).

@frankea

frankea commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

@xXPBSXx thanks, your reading is right. LinkCalls appended each table call's chain and copies after the previous call's, so the second call's branch to its chain, and its return, had to cross all of the first call's copies (about 37K dwords in your shader). That is the limit the description listed as still throwing.

e5a02bd (pushed here) removes it. Before the first of an earlier call's copies and after each one, LinkCalls now leaves a pair of s_branch relays for every later call: one forward toward that call's chain, one back toward the instruction after the call. A later call reaches its chain and returns in hops that each span at most one copy, the same bound the copies already have between them. A shader with a single table call links word for word as before.

  • ScalarCall: two table calls, the first with three 0x3001-dword copies and a small one (36,890 dwords). The second call reaches its chain through the 5 relays of the first call's copies, returns to the instruction after it the same way, and the graph built from the linked code has its call and return edges. Without the fix the same case throws the table callees of the call at program counter 0x0000004c lands out of the 16-bit branch range.
  • RTX 4090 (NVIDIA 616.92, Windows 11, WinLibs GCC 15.2), head e5a02bd: scalar_call, agc_shader_control_flow (all three variants) and agc_driver_graphics pass.
  • Ghostrunner (PPSA03685 01.000.005) on the RTX 4090, with this commit on my local integration branch (the tree from the description): shader 0x200c520000 now links both table calls you hit, at 0x434 and 0xc84, and stops on a third call at 0x89c. FindTableCalls doesn't take that one: its table's descriptor is the first four dwords of an s_load_dwordx8 s[88:95], s[0:1] whose pointer pair is itself loaded, and the matcher accepts only an s_load_dwordx4 from a user-data or literal pointer pair. So the graph builder throws computed/data-dependent s_swappc_b64 call target at program counter 0x0000089c is not statically resolvable, which the range errors hid until now. That shape is a separate change from this PR.

AI-assisted: yes (Claude Code)

@frankea

frankea commented Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

@klosixgaming-arch credit where it's due: on #7413 (comment) you proposed inserting intermediate s_branch relay hops, instead of far calls, whenever a callee or dispatch target is out of branch range. The relays in e5a02bd are that idea, applied to a later table call's branch to its chain and its return. I only found your comment after writing them. Thanks.

AI-assisted: yes (Claude Code)

@zaidhawk

Copy link
Copy Markdown
Contributor

Another title with this stop: Persona 3 Reload (PPSA10872), thread #9692. Compute shader 0x2014960000, run when entering the Iwatodai Station strip mall. Windows 11, RTX 5090 (NVIDIA 617.42), main b27924d + #7048, then this PR's head e5a02bd applied (clean).

Is the 16,384-dword copy limit something this layout can raise, now that each relay only crosses one copy? Separately, is preparation time expected to grow this steeply with shader size? I can rerun this title on any head.

@klosixgaming-arch

Copy link
Copy Markdown
Contributor

Tested #9068 on Little Nightmares (PPSA, ln), on top of main 1a745ae38e plus #9439 for tracing. Two stacks:

A. #8939 stack + #8070 + #9068: the branch-range stop is gone and the run gets further than without #9068. At about 64 s it stops in compute shader 0x200c340000:
GetImageResource dword 0 is not a valid runtime value; chain: LoadAddressU32@pc=0x0000a0e8(GetAddressResource(Phi(Phi(ReadConstBuffer@pc=0x00000444(...
So the next blocker is another Phi-pointer chain feeding an image resource, the same family as the earlier stops.

B. #7880 + #8070 + #9068, without #7395/#8939: stops earlier, at about 27 s, in 0x2010fa0000 with LoadAddressU32@pc=0x00003288(GetAddressResource(Phi(Phi(Phi(Phi(ReadConstBuffer..., a deeper chain than #7880 alone handles on this main.

Also, #7880 and the #7395 stack conflict in ResourceTracker.cpp (TryMakeIndirectColumn: UnwrapTableRead/AvailableAt versus PointerRecordPairs/SameRecordColumn), so I could only test them separately.

I did not test #9068 alone on a clean main. Logs available if useful.

AI-assisted: yes. Written with AI assistance and reviewed by me.

@frankea

frankea commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

@klosixgaming-arch thank you for the Little Nightmares runs, and for testing both stacks.

In stack A the branch-range stop is gone, which is the part #9068 covers. The next stop, GetImageResource dword 0 is not a valid runtime value on a Phi chain from ReadConstBuffer, is the refusal #7459 tracks; Ghostrunner reaches the same one next with #9068 and #8070. This PR doesn't change how descriptor reads are resolved, so it can't move that stop.

Stack B's deeper Phi chain and the TryMakeIndirectColumn conflict between #7880 and #7395 are for those two PRs. Your logs of the 0x200c340000 and 0x2010fa0000 chains would likely help there.

AI-assisted: yes (Claude Code)

@frankea

frankea commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

@zaidhawk thank you for the Persona 3 Reload runs, and for measuring the callee.

The 16,384-dword limit is the read window of ReadUserDataCallee on main, not part of this PR. In this PR's layout, every relay hop and every branch of a call's dispatch chain crosses at most one callee copy, so the s_branch range (a signed 16-bit dword offset) would allow copies up to about 32,700 dwords. A larger window is a separate change. A copy that no branch can cross would still throw in branchWord instead of linking wrongly, and the same goes for a user-data s_call_b64 pushed out of range. I can open it as a follow-up if your 17,369-dword callee is the only thing in the way.

Preparation time: yes, it grows steeply on graphs this size. Ghostrunner's 104,136-dword shader (PPSA03685, linked with this PR and #8070) spent 173 s in the structurizer, past the same 120 s render-thread watchdog. #9702 brings that to about 19 s in the title. It is stacked on #9701, and #9703 on it, so this PR + #8070 + #9703's branch with your raised limit would show whether your 92K-word shader then prepares in time.

AI-assisted: yes (Claude Code)

@zaidhawk

Copy link
Copy Markdown
Contributor

@frankea thanks. I ran the stack you suggested on Persona 3 Reload (PPSA10872): the strip-mall shader now prepares before the watchdog, and the next stop is #7459.

Setup: Windows 11, RTX 5090 (NVIDIA 617.42), Ryzen 7 9800X3D, WinLibs GCC 15.2.0, Release. Tree A: main 9d6adeb + #7048 (da9f0ea) + this PR (e5a02bd) + #8070 (73c9c2a), with ReadUserDataCallee's limit raised to 32,768 dwords locally. Tree B: tree A + #9703's branch (958f3f9, which carries #9701 and #9702). Same app.exe and app0/ for both.

Offline: from a run on tree A I captured the request for compute shader 0x2014960000 just before its preparation (a local dump, not proposed): 119,922 words with all three table calls linked. agc_shader_replay --prepare, one run each, ANYPS5_NO_SHADER_CACHE=1:

Replay tool Wall time Result
Tree A 355.0 s GetImageResource dword 0 is not a valid runtime value
Tree B 32.6 s same message, identical output
Tree B, APS5_NO_PERF_DOMINATOR_TREE=1 75.7 s same message, identical output

In game, entering the Iwatodai Station strip mall:

  • Tree A: no presents, then GameThread timed out waiting for RenderThread after 120.00 secs.
  • Tree B: the queue 0 packet report that covers the stall has DISPATCH_DIRECT x1497 35200ms (316 to 688 ms in the reports before it) and there is no watchdog. The driver then aborts:
compute shader 0x2014960000: shader 0x2014960000 stage 0: ShaderRecompiler::Recompile: GetImageResource dword 0 is not a valid runtime value; chain: LoadAddressU32@pc=0x000036f8(GetAddressResource(Phi(Phi(ReadConstBuffer@pc=0x000003f4(...

The chain has Ballot masks further in, like the Ghostrunner one, so this looks like the descriptor-Phi case of #7459.

So for this title the 17,369-dword callee isn't the only thing in the way: with a larger window and #9703's stack, the next stop is #7459. I can rerun on new heads of any of these.

Not covered: other GPUs, more than one run per state, anything past the strip mall.

@github-actions github-actions Bot added the unblocks title Names a title ID on the Unblocks line label Oct 23, 2026
@frankea

frankea commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

@zaidhawk thank you, that settles both questions for Persona 3 Reload: with this PR and #8070 the strip-mall shader links, and with #9701 to #9703 its 119,922-word preparation drops from 355.0 s to 32.6 s and the RenderThread watchdog no longer fires. I've added your replay and in-game result to #9702's Tested section and PPSA10872 to its Unblocks line.

The 16,384-dword window you raised is main's ReadUserDataCallee limit (6d9321f), not something this PR or #8070 sets, so I've opened #10140 for it: the window becomes the 1 MiB that ShaderRegistry already allows for a raw shader program, and the reader checks at doubling sizes so a long callee isn't decoded once per page. Its test links a 20,000-dword callee, which main refuses with the same does not return within 65536 bytes. With #10140, this PR and #8070, your tree B setup should reach #7459 without the local change.

AI-assisted: yes (Claude Code)

@TheSovietWaffle

Copy link
Copy Markdown
Contributor

Test report: Ghostrunner (PPSA03685) on Windows 10 22H2, NVIDIA GeForce RTX 3080 (driver 617.42), MinGW GCC Release build, 2026-10-23. Relinked with relinker --windows, run with APS5_PLAYGO_UNLISTED_CHUNKS=absent (with =installed, Unreal runs out of memory).

So on this title the PR does what it says, and Ghostrunner joins Persona 3 Reload on the #7459 stop. agc_shader_replay --prepare reproduces that stop offline from the dumped shader_200c520000.prepare.req; I can attach it if it helps.

AI-assisted: yes (Claude Code).

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 23, 2026
@adriadam10 adriadam10 self-assigned this Oct 23, 2026
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 23, 2026
@adriadam10
adriadam10 merged commit 798c908 into boykopovar:main Oct 23, 2026
9 checks passed
@adriadam10

Copy link
Copy Markdown
Collaborator

Checked the segment layout and the relays word for word against the new ScalarCall cases (call and return edges, the 0x8000-dword throw, two table calls, the 64-bit link-pair overwrite and its s_and_b32 negative). Rebased onto current main: the only conflict was the Table callees line in docs/dev/debt/libSceAgcDriver.md (#8070's s_load_dwordx8/x16 slice), merged keeping both texts. Build and ctest green on the rebased head; merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs shader core/shader unblocks title Names a title ID on the Unblocks line

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants