fix(shader): link a table call whose descriptor load sits before its loop #7413
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7413"
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 thuanquang on 2026-10-18T05:12:29Z.
What
Little Nightmares Enhanced Edition (PPSA10737) stops before its first frame in 3 of 3 runs on
main(@zaryabzip, discussion #6275):The shader calls a function from a table once per lane, in a waterfall loop. Its
agc_shader_replay --asmlisting in #6275 shows the shape:s_load_dwordx4 s[96:99], s[0:1], 0x10at 0x0c08, well before the loop;s_buffer_load_dwordx4 s[16:19], s[96:99], vcc_lo;s_swappc_b64at 0x1034.FindTableCalls(#4706) links a table call only when thes_load_dwordx4that defines the V# is in the call's own block:findLastWriterstops at the first branch, andsameBlockrejects any label in between. The loop header is always such a label, so the call is never linked, and the shader is compiled with the raw computed call, which throws.The same-block rule is still tried first, so every call
mainlinks is linked the same way. When it fails, the descriptor is now looked for with a reaching-definition walk (reachingWriter). It goes back from the record load over every predecessor of each instruction: the previous instruction unless it iss_branch,s_endpgm,s_code_endors_setpc_b64, every direct branch to it, and everys_setpc_b64whose targetresolveSetpcTargetresolves to it (the long-branch forms the control flow analysis already follows). Each path stops at the first write of any of the four descriptor registers. The search fails, and the call stays unlinked as onmain, if:s_call_b64or a statically resolved call, whose callee is not modelled;s_call_b64target). The callers' paths are not followed, so this fails even when the instruction before the entry falls through into it;The paths may run through any
s_swappc_b64that is not resolved statically, including the table call itself through the loop's back edge. Its callee is assumed to keep the descriptor registers. If it doesn't, nothing wrong runs: the linked compare chain compares the target each iteration actually loads with the address of each linked copy. A miss takes theUnlinkedCallfault (#4706), so the worst case is that fault, never a wrong callee. Every other check is unchanged:s_load_dwordx4from an unchanged user-data pointer or, since #6160, from a constant pointer that twos_mov_b32set in the writer's block;s_lshl_b32must be in the call's block.Overlap: #6160, since merged, changed the same line of
FindTableCalls(it added areaderargument to thefindLastWritercall this replaces). This branch is rebased onto it, and the two are independent:The reporter wrote that #6160 does not fix this stop.
Tested
Windows 11 26200, AMD Radeon RX 6700 XT (gfx1031), driver 32.0.21045.5002, WinLibs GCC 15.2.0 r7, Release,
BUILD_TESTING=ON,ANYPS5_REQUIRE_VULKAN=1:scalar_callhas a newCheckHoistedTableCalls, built from the #6275 listing, run for wave32 and wave64.s_cbranch_scc0past the call.s_mov_b32of 0xe0040000 and 15 intos[106:107], #6160's FS-table form) must link with that constant pointer and descriptor offset 0.s96on one branch arm;s97rewritten after the call inside the loop;s_call_b64to an in-program function on the branch arm;s_getpc_b64/s_sub_u32/s_setpc_b64long branch.s_call_b64with two paths to the record load, one through a second V# load, must stay unlinked;s_call_b64and the call in one block must link as onmain;s_call_b64target) that the code above it falls into, with the V# loaded in that code, must stay unlinked.main'sGraphBuilder.cppthe hoisted shapes find no table call, so the test fails.agc_driver_compute_table_callshas a second caller whose V# is loaded before a conditional branch. On this GPU, records 0 and 1 must call their callees (16 and 33 in every lane) in wave32 and wave64.main'sGraphBuilder.cppthe dispatch stops with the title's message:computed/data-dependent s_swappc_b64 call target at program counter 0x00000038 is not statically resolvable.mainc34e9d855after #6160, which lets the same-block search cross a forward branch past the call; the same-block check keeps that, andreachingWriterfollows every predecessor already.scalar_call,agc_driver_compute_table_callsandagc_driver_compute_fs_table_callspass 3 of 3 on the rebased head. WithGraphBuilder.cppatc34e9d855, the first two fail as onmain(computed/data-dependent s_swappc_b64 call target at program counter 0x00000038 is not statically resolvable) and #6160's test passes.cc6901685, after an independent review of the walk. Each new check fails without its half of the change and passes with it:s_setpc_b64edges, the long-branch shape links the 0x10 table, and the linked program translates (wave32, local probe). Lanes that took the long branch would then reach their targets only through theUnlinkedCallfault. With the edges, the search finds both loads and leaves the call unlinked.FindTableCallsreturns the fall-through program's call.GraphBuilderthen rejects the linked program (unclosable scalar call/return pairing at program counter 0x00000004: control flow enters the call region from program counter 0x0000000c). With the check, the error staysmain'snot statically resolvable. So this check changes no compiled shader; it keeps the driver from reading a table through a V# that the call path never loads.scalar_call,agc_driver_compute_table_callsandagc_driver_compute_fs_table_callspass 3 of 3 oncc6901685.ctest --parallel 4 --timeout 120onmainbb2624a53with this change: 1469 tests. The failures all happen without it too:agc_driver_address_passes(broken on Windows GPUs by #6678, fixed onmainby #7476),agc_driver_lds_mixed_width_atomics(#6976),agc_driver_lds_lock_budget(#7344) andagc_driver_layered_volume_vertex_no_gpl(#4768).python tools/check_conventions.py --base origin/mainwith this title and body passes.cc6901685on an RTX 5090. No[gpu] driver failurefor a computeds_swappc_b64target. The title then stopped in the same compute shader 0x2010fa0000 on a separate gap,GetImageResource dword 0 is not a valid runtime value(reported on #7395). With a local fix for that, the shader compiles with the call at 0x1034 linked by this PR. The title then stops in shader 0x200c340000, whose table calls take their V# from 4-dword slices of ans_load_dwordx8. That shape is not part of this PR (see below).1002:13c0, 32.0.21042.62), at d622a55dc andcc6901685.scalar_callandagc_driver_compute_table_callspass on both, and fail with the title's message withGraphBuilder.cppfrom the base. 728 of 728 pass in theagc_|shader|recompiler|scalar_callset on NVIDIA. On AMD onlymain's three known failures fail.cc6901685ona373e85e5. Both tests pass, and both fail onmainwith only this PR's test files.cc6901685merged into07377573f. Both tests pass 3 of 3, and fail onmain(lane 0 is 3405691582, expected 16).s_swappccalls).Next stops seen in the title, not addressed here:
s_load_dwordx8/x16, whichFindTableCallsdoes not accept;LinkCallsappends each call's dispatch chain and its own callee copies in call order. The copies can't be shared between calls, because a callee region reached from twos_call_b64sites is rejected (is shared with another call). So linking all six calls of that shader needs far calls from the chains, which have to keep SCC for the callee.Checklist
main; no other open PR implements the same functionsNotImplemented_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)1002:13c0(@wachi35676), RTX 5090 (@klosixgaming-arch), Intel UHD 770 and AMD RX 9070 XT (@savvaniss)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-18T05:33:21Z.
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.
docs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/tests/ScalarCall.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/shader/recompiler/ControlFlow/src/GraphBuilder.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdImported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-18T14:57:50Z.
Second-GPU run on head
d622a55dc, Windows 11 Pro 26220, NVIDIA GeForce RTX 4070 (596.21), WinLibs MinGW-w64 GCC 15.2, Release. Stacked on maina62c724c3together with #7381 (f405b7cae); the two merge cleanly and share no file. Targeted build (relinker, libs and the shader andagc_driver_*image/sample/shader/table test executables), not a full build.scalar_callandagc_driver_compute_table_callspass 3 of 3. The latter ran on the RTX 4070 (no skip) and covers the hoisted caller for records 0 and 1 in wave32 and wave64.GraphBuilder.cppset back to main with the tests kept.agc_driver_compute_table_callsfails with[gpu] driver failure: ... computed/data-dependent s_swappc_b64 call target at program counter 0x00000038 is not statically resolvableandthe first record's callee through a descriptor loaded before a branch (wave64): lane 0 is 3405691582, expected 16.scalar_callfails too. Restored, both pass.ctest -j1 --timeout 300 -R '^(agc_driver_(shader|table|descriptor|sample|image|volume|3d)|shader_|agc_shader_|scalar_call)': 81 of 81 pass.check_conventions.py --base origin/mainpasses andgit diff --checkis clean.3e3e8b905) against the stack: no stop line, no driver failure and the same dump content on both. These titles do not reach a computed call, so this says nothing about the change itself. PPSA10737 is not available to me, so the title is not tested.Not checked: PPSA10737, the full
^agc_driver_pass and the non-GPU suite, SPIR-V validation withspirv-val, AMD/Intel, Linux.Written with Claude Code assistance (validation by a subagent, reviewed in this session).
Imported from boykopovar/AnyPS5. Originally posted by hugodearaujo on 2026-10-18T16:46:20Z.
EA SPORTS FC 25 (PPSA20049) needs this too. On
maine5f18ea99with #6343 and #7606 it stops 230 s after start on compute shader0x1184ca4400(computed/data-dependent s_swappc_b64 call target at program counter 0x000004c4 is not statically resolvable); its table V# is loaded at 0xa0, before the waterfall loop. With this PR's head (d622a55dc) merged on top, it reaches its main menu and stays there until the 620 s run ends (#7607).Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-19T00:13:12Z.
Tested on Windows 11 (GCC 15.2.0, Release) on an RTX 5070 Ti (617.42) and an AMD Radeon iGPU, RDNA2 (
1002:13c0, 32.0.21042.62,ANYPS5_GPU=AMD), atd622a55dcand again atcc6901685.scalar_callandagc_driver_compute_table_callspass on both GPUs.GraphBuilder.cppset back to the base, both fail on both GPUs withcomputed/data-dependent s_swappc_b64 call target at program counter 0x00000038 is not statically resolvable.agc_|shader|recompiler|scalar_callset atcc6901685passes 728/728 on NVIDIA. On AMD it has only the three failuresmainhas there (lds_mixed_width_atomics,lds_lock_budget,layered_volume_vertex_no_gpl).AI-assisted: yes (Claude Code); results above were run on this machine.
Imported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-10-19T00:54:38Z.
Review: APPROVED
Tested on Windows 11, MinGW-w64 GCC 15.2.0, NVIDIA GeForce RTX 5090 (driver 617.42), Ryzen 9 9950X3D. Head
cc6901685merged onto currentmain(a373e85e5); clean merge.agc_driver_compute_table_callsandscalar_callpass with the change.mainwith only this PR's test files both fail, so the new cases do need the fix.reachingWriter: the old same-block search is still tried first, so the callsmainlinks today are linked the same way. The new walk goes back over predecessors and gives up (returns false, so the call stays unlinked as before) if it reaches a call ors_swappc_b64, or finds two different writers of the descriptor registers. That is the conservative direction. Reading the diff, I did not find a path where it links a call it should not (I did not fuzz it).Not tested: Little Nightmares Enhanced Edition (PPSA10737); I have no dump, so the title claim is the author's.
AI-assisted: yes. Written with AI assistance and reviewed by me.
Imported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-10-19T01:52:11Z.
Tested on a PC with a real title, Little Nightmares Enhanced Edition (PPSA10737, version 01.004.000), running the PR head (
cc6901685) as built, relinked and launched on Windows (RTX 5090).The relinked game started and ran for about 2 minutes 46 s before it stopped. The log shows the shaders that call
s_swappc_b64through a computed target being deferred to first use ("could not be prepared at registration ... preparing it when it is used"), and the run went on to create compute pipelines (for example 170624 SPIR-V words in 1089 ms) and to record draws and dispatches. There was no[gpu] driver failurefor a computeds_swappc_b64target. I did not run main on this dump in this session, so I am not claiming a before and after measurement here.The game then stopped on a different shader: compute shader 0x2010fa0000, stage 0,
ShaderRecompiler::Recompile: GetImageResource dword 0 is not a valid runtime value(the address chain goes through nested Phi nodes, Ballot and ReadFirstLane), then SIGABRT, exit 0xC0000409. That looks like a separate recompiler gap and not something this PR should fix. Only 3 presents were logged before it, so no frame was shown. The ctest target I ran (agc_write_tracking) passed.AI-assisted: yes. Written with AI assistance and reviewed by me.
Imported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-10-19T04:43:42Z.
Follow-up on Little Nightmares Enhanced Edition (PPSA10737, version 01.004.000) on Windows 11 / RTX 5090 at
cc6901685:With a local fix in
TryMakeIndirectColumnfor theGetImageResource dword 0stop on compute shader0x2010fa0000(where thes_swappc_b64at0x1034is linked by this PR),0x2010fa0000compiles ([dispatch] created a pipeline for 414421 SPIR-V words in 26173 ms (program 0x2010fa0000)).The title then advances to compute shader
0x200c340000(2,572 words,firstUser=0,userCount=14,wave=32) and stops at:Inspecting
0x200c340000shows 6 table calls (0x0460,0x08b4,0x0c7c,0x0d2c,0x16a0,0x1990):0x0460and0x0c7cread froms[4:7](loaded bys_load_dwordx4 s[4:7], s[0:1], 0x0at0x0204) and are linked byFindTableCallsoncc6901685.0x08b4,0x0d2c,0x16a0, and0x1990read froms[88:91]ands[92:95], which are loaded before the loops by a singles_load_dwordx8 s[88:95], s[0:1], 0x10at0x04c0(0xf40c1600 0xfa000010), sotable.op != RdnaOpcode::SLoadDwordx4skips them.SLoadDwordx8/SLoadDwordx16inFindTableCallslinks0x0460,0x08b4, and0x0c7c, and then stops inLinkCallson the 4th call (0x0d2c) withcompute shader 0x200c340000: the table callees of the call at program counter 0x00000d2c lands out of the 16-bit branch range.AI-assisted: yes. Written with AI assistance and reviewed by me.
Imported from boykopovar/AnyPS5. Originally posted by savvaniss on 2026-10-19T06:35:52Z.
Intel and AMD Windows data: both tests fail on
mainand pass with this PR, on an Intel UHD 770 and an AMD RX 9070 XT.Windows 11 Pro 26300, WinLibs GCC 15.2.0 r7, Release, every execution test built,
ANYPS5_NO_SHADER_CACHE=1, serial CTest. Intel UHD Graphics 770 (8086:a780), driver 32.0.101.7088. AMD Radeon RX 9070 XT (1002:7550), driver 32.0.31041.1004, withVkCacheemptied first. This headcc6901685merged intomain07377573f. "Without" means this PR's test files onmain07377573f, with none of its other changes.agc_driver_compute_table_calls,scalar_callcompute_table_calls:the first record's callee through a descriptor loaded before a branch (wave64): lane 0 is 3405691582, expected 16I also ran full CTest with this PR and the 13 other open AGC and shader PRs I tested in the same batch merged together (#7668, #7659, #7504, #7432, #7426, #7480, #7465, #7466, #7464, #7449, #7489, #7673, #7560). Neither GPU showed a failure beyond
main's own: the five image-table tests (#6647) andagc_driver_sample_multisample_target(#6957) on the UHD 770, andagc_driver_layered_volume_vertex_no_gpl(#4768) on the RX 9070 XT.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by thuanquang on 2026-10-19T07:37:59Z.
Thanks @klosixgaming-arch for the title runs and for tracking the next two stops. @wachi35676 and @savvaniss, thanks for the runs too. The description now lists all of them.
On shader 0x200c340000:
s_load_dwordx8/x16inFindTableCallsis small: the V# is read atmemoryOffset + 16 * slice.LinkCallsappending each table call's dispatch chain and its own callee copies in call order, so later chains drift past the 16-bits_branchreach. The copies can't be shared between calls:GraphBuilderrejects a callee region reached from twos_call_b64sites (is shared with another call, pinned inScalarCall).resolveSetpcTargetalready resolvess_getpc_b64,s_add_u32 imm,s_swappc_b64on the link pair, which the call overwrites anyway. The catch is SCC: the chain hands the caller's SCC to the callee unchanged, and thes_add_u32must sit right before thes_swappc_b64. Restoring SCC at the callee would need two entries into one copy, which the call model rejects. So it needs a way to carry SCC across a far call, or two copies per callee.That's a follow-up after this PR and #7395, not something to add here. Do you plan to open the x8/x16 part, since you have it locally? If not, I can open it with a
ScalarCallcase for the slice offsets.Imported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-10-19T12:10:39Z.
@thuanquang Thanks! On the far-call / SCC issue in \LinkCalls: we found that we don't need \s_swappc_b64\ far calls at all. Instead, we can insert intermediate \s_branch\ relay hops whenever a callee or dispatch target exceeds \
Imported from boykopovar/AnyPS5. Originally posted by DavidAmsellem on 2026-10-19T17:22:06Z.
First AMD-on-Linux (RADV) run of this PR that I could find. Merged onto
maindbac9fa15(clean merge), built in full and compared with the samemain, on the same machine.AMD Radeon RX 7900 XT (RADV NAVI31, gfx1100), Mesa 25.2.8, Linux Mint 22.3 (Ubuntu 24.04 base), kernel 7.0.0-38, GCC 13.3, Release.
Full suite (
ANYPS5_REQUIRE_VULKAN=1 ctest -j8): 1638/1640 with this PR, against 1638/1640 onmain. The failures are the same two on both, so this PR adds none:agc_driver_image_table_vouched_lookups(#7766, fixed by #7916) andagc_driver_guest_memory_lifetime(#7784).agc_driver_compute_table_callsandscalar_callrun and pass. The PR adds no new ctest entry, and no test is skipped or removed compared withmain.GPUs tested: AMD Radeon RX 7900 XT (RADV NAVI31, gfx1100), Mesa 25.2.8, Linux Mint 22.3 / kernel 7.0.0-38
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by DavidAmsellem on 2026-10-19T18:16:52Z.
First AMD-on-Linux (RADV) run of this PR. Merged onto
maindbac9fa15(clean merge), built in full and compared with the samemain, on the same machine.AMD Radeon RX 7900 XT (RADV NAVI31, gfx1100), Mesa 25.2.8, Linux Mint 22.3 (Ubuntu 24.04 base), kernel 7.0.0-38, GCC 13.3, Release.
Full suite (
ANYPS5_REQUIRE_VULKAN=1 ctest -j8) at4c9469bc9: 1638/1640 with this PR, against 1638/1640 onmain. The two failures are the same on both, so this PR adds none:agc_driver_image_table_vouched_lookups(#7766, fixed by #7916) andagc_driver_guest_memory_lifetime(#7784).Comparing the JUnit output with
main: this PR adds no ctest entry, and none is skipped or removed.This checks correctness only; I did not measure performance.
GPUs tested: AMD Radeon RX 7900 XT (RADV NAVI31, gfx1100), Mesa 25.2.8, Linux Mint 22.3 / kernel 7.0.0-38
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T19:51:07Z.
Checked
reachingWriteragainst the diff: the same-block search still runs first, so every callmainlinks is linked as before; the new walk fails (call stays unlinked) ons_call_b64, a function entry, the program start or an unreachable instruction, and a callee that clobbers the descriptor can only end in theUnlinkedCallfault, not a wrong callee. The newscalar_callshapes and the hoistedagc_driver_compute_table_callscaller pin casesmaindoes not link, and the TechnicalDebt line is updated. Also confirmed by the runs of @klosixgaming-arch, @wachi35676, @screamm, @savvaniss and @hugodearaujo; merged.