fix(shader): link table callees that together exceed s_call_b64 range #9068
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9068"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by frankea on 2026-10-21T11:34:11Z.
What
Gran Turismo 7's World Map dispatches a compute shader whose
s_swappc_b64calls through a table of about 35 material functions, about 40,000 dwords in all. Linking it threwthe table callees of the call at program counter 0x00000ae4 land out of s_call_b64 range. Once it linked, the call model refused it withscalar 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.LinkCallsappended every table callee after a single block of call sites, so a callee'ss_call_b64had 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, ans_call_b64with offset 1, a returns_branch, then the copy. A mismatch branches over the copy to the next target's compares. A return goes back ones_branchper 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.overwritesScalarcounted only the first destination dword of SOP2 results and of SOP1 results other thans_mov_b64ands_getpc_b64. In the GT7 shader,s_andn2_b64 s[14:15], s[6:7], s[4:5]overwrites a link pair ands_nor_b64 vcc, s[14:15], vccthen reads it. The escape check still marked s15 as holding a return address and refused the read. It now uses the decoder'sdataDwordCount, which is 2 for the 64-bit results. The conditional and partial writers (s_cmov,s_bitset,s_movreld,s_movrelsd_2) ands_swappc/s_setpcare still not counted as overwrites. The escape check is the only caller.LinkCallsleaves a pair ofs_branchrelays 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.s_call_b64range limit.Tested
main0db47b263(head daef563d8; no conflicts), RTX 4090 (NVIDIA 616.92, Windows 11): the 33 ctest entries ofscalar_call,agc_shader_control_flow,agc_driver_graphicsandagc_driver_compute_table_callspass 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 noVUID-line; the layer reports nothing on this head.main0db47b263passes the union of the refreshed sets, 115/115, under the same layer settings with noVUID-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 bys_andn2_b64over the link pair and a 64-bit read builds; withs_and_b32over 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 throwslands out of the 16-bit branch range.scalar_call,agc_shader_control_flow(all three variants) andagc_driver_graphicspass.FindTableCallsdoesn't match (its descriptor comes from ans_load_dwordx8through a loaded pointer), which this PR doesn't touch.agc_shader_replaynow stops in the resource tracker onGetImageResource 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
main; no other open PR implements the same functions. Overlap: #8140 (tv7) rewrites the line inLinkCallsthat appends a table callee, so that a callee'ss_getpc_b64is expanded into twos_mov_b32s, which makes the copy longer than the callee. Whichever PR lands second has to size each segment from the expanded copy. #8070 changes only how table calls are found.NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-21T15:45:46Z.
Title data point for this PR (data only).
Title: PPSA03685, 300 s through the runner,
ANYPS5_GPU=4080; both.outlogs showSelected 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,
main50efb5c405(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 base80565c5942) merged locally intomain47fa6eecf8(run_164357.err lines 440-441; the earlier head84eb444119gave the same result in run_151642.err): the first call is no longer refused, but the same shader stops at another table call:The new message comes from
branchWord, not from thes_call_b64check. From readingLinkCallson the PR head,linked[word] = branchWord(0xbf820000u, word, linked.size(), ...)jumps from the originals_swappc_b64to 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).
Imported from boykopovar/AnyPS5. Originally posted by frankea on 2026-10-21T20:55:44Z.
@xXPBSXx thanks, your reading is right.
LinkCallsappended 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.e5a02bd48 (pushed here) removes it. Before the first of an earlier call's copies and after each one,
LinkCallsnow leaves a pair ofs_branchrelays 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 throwsthe table callees of the call at program counter 0x0000004c lands out of the 16-bit branch range.scalar_call,agc_shader_control_flow(all three variants) andagc_driver_graphicspass.FindTableCallsdoesn't take that one: its table's descriptor is the first four dwords of ans_load_dwordx8 s[88:95], s[0:1]whose pointer pair is itself loaded, and the matcher accepts only ans_load_dwordx4from a user-data or literal pointer pair. So the graph builder throwscomputed/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)
Imported from boykopovar/AnyPS5. Originally posted by frankea on 2026-10-22T01:20:12Z.
@klosixgaming-arch credit where it's due: on #7413 (comment) you proposed inserting intermediate
s_branchrelay hops, instead of far calls, whenever a callee or dispatch target is out of branch range. The relays in e5a02bd48 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)