feat(shader): link callees of calls whose target is loaded from a table #4706
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4706"
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 TripyFox on 2026-10-12T19:28:15Z.
What
Fixes #3274: a compute shader's
s_swappc_b64whose target pair is loaded from a table (s_buffer_load_dwordx4of a buffer whose descriptor comes from user data, indexed by a shifted offset) failed at compile time with "computed/data-dependent s_swappc_b64 call target ... is not statically resolvable".FindTableCalls,LinkCalls, driverReadTableCallees): at dispatch the driver reads the descriptor and the buffer, collects the distinct non-zero targets at the loaded offset plus multiples of the offset's stride, reads each callee the same way user-data callees are read, and links one copy per call after the caller. The call becomes a branch to a compare chain (s_cmp_lg_u32with a literal +s_cbranch_scc1per dword) thats_call_b64s the matching copy. There is one chain per value of SCC at the call, and the chain restores SCC before the callee runs, so the callee sees the caller's SCC. Table contents stay out of the shader and pipeline keys; only the linked code (the target set) is keyed, as with user-data callees.UnlinkedCallfault (target and PC) through the existing fault buffer and stops the invocation, or continues after the call when faults don't stop invocations. The driver reports it like a BDA fault. The linker lists these fallbacks in the request (GuestContext::linkedCallFallbacks, request format 25). Any others_swappc_b64whose target is not resolved is still refused at compile time, as on main.PlanBuilder::Collectwalked the IR recursively and kept visited values in a vector. A linked program with 30 callees (about 29k words) overflowed the stack. The walk now uses an explicit stack and hashed sets, and records reads in the same order.Sources: AMD RDNA 2 ISA reference guide. The compare chain uses
s_cmp_lg_u32/s_cmp_eq_u32(§12.4, opcodes 6 and 7, encoding §13.1),s_cbranch_scc1/s_branch(§4.2, §12.5) ands_call_b64(§12.2), and it keeps SCC as §3.8 describes it. The SGPR-mask width used by the link-pair dataflow comes from three places: §2.1 ("The upper half of EXEC and VCC are ignored for wave32 waves"), §3.9 (in wave32 only the low 32 bits of VCC are used) and §6.2.3 (a VALU mask in SGPRs takes two consecutive SGPRs in wave64). From these, a wave32 VALU mask write is counted as one SGPR. That is an inference from the guide, not a measurement. When the wave size is unknown, the dataflow assumes the narrower overwrite and the wider read. Thes_buffer_loadrange is taken as the descriptor's whole size (stride × num_records, or num_records bytes). That size covers both possible range interpretations. Which one the PS5 uses was not measured, and this is recorded in TechnicalDebt. None of the new behaviour was measured on hardware.s_call_b64itself was already measured on gfx1036, as TechnicalDebt records.Data from R&C (PPSA01474): one table with 348,156 16-byte records
{target, arg}and 30 distinct leaf callees, 85–834 instructions each (about 92 KB in total). Each callee returns throughs_setpc_b64on the link pair and makes no further calls.Tested
ctestonmain23e93c054+ this PR, 1146/1146 passed. New and updated cases are inScalarCall.cpp(matcher, linker layout, CFG of the linked program, translation, unlinked fallbacks, wave32/64 mask writes, link-pair dataflow, jump-table refusal, s_call range),ShaderMemory.cpp(request format 25 and the new field's round trip), and the new execution testComputeTableCalls.cpp(agc_driver_compute_table_calls). That test runs a linked two-record table on Vulkan in wave64 and wave32, with SCC 0 and 1 reaching the callee, and checks that a record past the table reports theUnlinkedCallfault.tools/check_conventions.py --base origin/main: passed.src_private_base(#3803, which needs hardware values; not part of this PR).agc_shader_replayon the captured request, plus a local aperture stub that is not in this PR, the call is found and all 30 callees link (29,266 words). The linked CFG is accepted. Planning then fails in a callee that loads an image descriptor through the per-record pointer, which is a data-dependent descriptor (#757 territory). Front-end and planning took about 28 s on this program, so compile cost is a concern for very large linked sets.storage image access to depth/stencil surface ... is not implemented. Plainmain(d592d54e1) without this PR does the same, so it is not caused by this change.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by kr4y4 on 2026-10-12T22:20:39Z.
A second-vendor run, to go with the RTX 5090 one.
Setup: Windows 11 (26200), WinLibs GCC 15.2.0 r7, Release, CI configure flags, an RTX 4070 Laptop GPU and an Intel Raptor Lake-S iGPU. The head 7c7b22dfe merged into
main584cc4c57.scalar_call,scalar_swappc,agc_driver_scalar_swappcandagc_driver_prepared_shaderspass on both GPUs with--repeat until-fail:3.ctest --timeout 120 --parallel 4): 1018 of 1018 on both GPUs. That includes the user-data callee tests from #3294,agc_driver_compute_user_data_callsand its--registeredmode.Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by Tamalero on 2026-10-13T00:13:13Z.
In-game confirmation on Linux: with this PR, Ratchet & Clank: Rift Apart (PPSA01474) no longer aborts with the #3274 error. It plays the PS logo, the raytraced logo and the Insomniac logo, then compiles about 240 new shaders. It stops about 6 minutes in at the table shape you predicted from the offline replay.
UnlinkedCallfault was reported. The linked programs are big: about 4.5 MB each in the disk cache, with about 230 MB written per 10 s while they compile behind a black screen after the Insomniac logo.src_private_baseon this stack.0x116bb65f00, stage 0:GetImageResource dword 0 is not a valid runtime value. The T# is loaded through a pointer that is read from a buffer at a waterfall index (ReadFirstLaneinside a loop): That matches the per-record pointer you describe. Marvel's Guardians of the Galaxy (PPSA01748) has the same shape in two shaders (pcs0x4378and0x4380), so both titles now wait on it.Details
Setup: CachyOS (Linux 7.2), RTX 4090 (NVIDIA 615.78), GCC 16, Release. The title is relinked with
--to-intelfrom the same tree.Stack: main
90c683946, plus this PR at7c7b22dfe, plus #757 (tv7'srebase/757,8945fe208), plus #758 (cad61e9a7). Local changes on top:Js::OutOfMemoryExceptionduring the raytraced logo on Linux.BLEND_BYPASSfixes.Merge notes against
90c683946:BdaAbi::FaultReason: #757 addsImageTableand this PR addsUnlinkedCallat the same position. I kept both; each is referenced only by name.PlanBuilder::Collect: main already has an iterative walk, so I kept main's version over this PR's second commit.Tests on the combined stack, all passing:
scalar_call,scalar_swappcagc_driver_scalar_swappcand_fetchagc_driver_compute_user_data_callsand_registeredagc_driver_prepared_shadersand itsdeferred,deferred_undecodable,registered_workgroup(_sync),indirect,uncached,debuganddebug_failurevariantsTested and written by Claude (AI assistant) on a contributor's machine.
Imported from boykopovar/AnyPS5. Originally posted by TripyFox on 2026-10-13T06:00:04Z.
Thanks for the second-vendor run. Good to see the user-data callee tests from #3294 pass alongside it, on Intel as well as NVIDIA.
Generated by Claude Code
Imported from boykopovar/AnyPS5. Originally posted by TripyFox on 2026-10-13T06:00:05Z.
Thanks for the in-game run. That confirms the call linking end to end, and that the next wall is the per-record T# (
0x6340loads the image descriptor through the{target, arg}record's pointer). That needs data-dependent descriptor support (#757 territory), so I'm leaving it out of this PR. Good to know Guardians of the Galaxy has the same shape.Two notes on the merge:
FaultReason: agreed, keep both. The value only has to match between the shader and the driver in one build, so whichever of #757 and this PR lands second takes the next value. The BDA ABI version doesn't change.PlanBuilder::Collect: on currentmain(88107b7de) it is still recursive, and it keeps visited values in astd::vectorwith a linear search. The iterative walk you kept is probably from #757/#758 in your stack. On plainmain, the second commit is what stops the 30-callee R&C program from overflowing the stack (it did inagc_shader_replayhere). If #757 lands first with its own iterative walk, I'll drop this commit.On size: about 4.5 MB per linked program matches the ~29k-word programs here. Sharing one copy of a callee across call sites, and keeping copies out of programs that don't reach them, would be follow-ups.
I've rebased onto current
main(88107b7de) to clear the conflict, and retested: the fullctestpasses 1037/1037.Generated by Claude Code
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T15:32:21Z.
Review: DISMISSED
Checked on Linux (RADV, gfx1035): build, ctest of the touched directories and the PR's tests pass. I measured the wave-size assumptions on the hardware oracle (gfx1035): in wave32,
v_cmp_*_e64 sN,v_add_co_u32 ..., sNandvcc_lowrites leavesN+1/vcc_hiuntouched andv_cndmask_b32_e64reads only the low SGPR; in wave64 both are written and read.0xbf068080sets SCC to 1 and0xbf078080to 0. So the link-pair dataflow and the SCC restore match the hardware. Still needed:GraphBuilder.cpp:1506,ControlFlowInstructions.cpp:286). Everys_swappc_b64whose target isn't resolved now compiles, not only a table call whose target misses the linked set. On the usual dispatch path the fault is only logged, and the dispatch carries on.agc_driver_prepared_shaders_deferredprints[gpu] deferred write-back failed: shader stage 4 called address 0x0 ... which no linked callee of that call matchesand passes, wheremainrefused the shader. That turns a refusal into a run with the callee's effects missing. Please keep the refusal for calls that match neither the user-data shape nor the table shape. The fault is reasonable for a table call whose snapshot has gone stale, so keep it for that case.ScalarCall.cpppins the linked words and the CFG, but nothing runs a table call on Vulkan. Please add one alongsidetests/execution/ComputeUserDataCalls.cpp. It should cover:s_cselectof it, to pin "the callee sees the caller's SCC";PreparedShaders.cpp:608:DeferredRegistrationnow passes whether or not the fault is recorded. Please assert that theUnlinkedCallfault is reported, or move this case to the test above.Unlinked callsline is the last one indocs/dev/debt/shader.md(line 116), and #4048 and #4926 already conflict with this PR there. Placing it earlier in the section avoids the next adjacency conflict.Imported from boykopovar/AnyPS5. Originally posted by TripyFox on 2026-10-13T16:52:02Z.
Thanks for measuring the wave-size and SCC assumptions on gfx1035.
Pushed a third commit for the review:
s_swappc_b64it emits. The driver passes them in the request (GuestContext::linkedCallFallbacks); the field is serialized in request format 24 and is part of the recompile cache key.GraphBuilderfaults only at those calls. Every other unresolveds_swappc_b64throws at compile time again, with main's messages, soScalarSwappc.cppandPreparedShaders.cppare back to main's expectations.tests/execution/ComputeTableCalls.cpp(agc_driver_compute_table_calls) runs a linked two-record table on Vulkan in wave64 and wave32:s_cselectof it, so all four record/SCC pairs check that the callee sees the caller's SCC;UnlinkedCallfault is reported (called address 0x0 ... which no linked callee of that call matches) and that no lane stores.Unlinked callsnow opens the Functional section ofdocs/dev/debt/shader.md, away from the lines #4048 and #4926 touch, and it says that only the table fallback faults.Full
ctestpasses 1087/1087 locally (theagc_shader_memoryrequest-format check now expects version 24 and round-trips the new field), and the conventions check passes.Generated by Claude Code
Imported from boykopovar/AnyPS5. Originally posted by tv7 on 2026-10-13T17:54:57Z.
@TripyFox a table-loaded call target this head does not link yet, in case it fits the design. Silent Hill: Townfall (PPSA33286, Unreal Engine), compute shader
0x16402d6e00(wave64;0x1640286900and0x16402b0500have the same code). Windows 11, RTX 3070, main8cf6a0bc3+ #5176 (needed to get past the dispatch first) + this head. The title still stops withcomputed/data-dependent s_swappc_b64 call target at program counter 0x00000134 is not statically resolvable.The difference from #3274 is where the descriptor comes from: a constant address, not user data.
The offsets are immediates, so there is one target per dispatch, and the shader skips the call when it reads 0. I have not checked what the console maps at
0xF_E0040000or what AnyPS5 maps there.🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by Tamalero on 2026-10-13T18:18:22Z.
A run on discrete RDNA2 under RADV with the third commit, to go with the gfx1035 measurements in the review and the NVIDIA and Intel runs.
Setup: Linux (Ubuntu 24.04), GCC 13, Release, AMD Radeon PRO V620 (Navi 21, gfx1030), RADV from Mesa 25.2.8,
VK_ICD_FILENAMESlimited to RADV. The head677e8e7f0merged intomain18c438b10with no conflicts.ctest: 1072 of 1072 pass. 12 are skipped, as on plainmainon this card: the headless video-out tests,agc_driver_ngg_vertex_wave_reduction(RADV reports a subgroup size of 64) andagc_driver_oversized_dispatch.--repeat until-fail:3, 17 of 17 withANYPS5_REQUIRE_VULKAN=1:agc_driver_compute_table_calls,agc_driver_scalar_swappc[_fetch],scalar_swappc,scalar_call,agc_driver_compute_user_data_calls[_registered], theagc_driver_prepared_shaders*family andagc_shader_memory.agc_driver_compute_table_callsruns both widths natively here. The device's default subgroup is 64, and wave32 programs get 32 (Wave32 programs run on subgroups of 32). The record past the table reports the expected fault once per width (called address 0x0 at program counter 0xdc, which no linked callee of that call matches), and the test passes.Tested and written by Claude (AI assistant) on a contributor's machine.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T05:10:33Z.
Please rebase:
core/shader/recompiler/ControlFlow/src/RequestSerializer.cppconflicts with main in the trailer afterversion >= 21u(main now requires the float16 byte from version 22). Main is still on request format 23, so 24 forlinkedCallFallbacksstays free. The Silent Hill: Townfall shape (descriptor at a constant address) is a separate follow-up, not for this PR.Imported from boykopovar/AnyPS5. Originally posted by TripyFox on 2026-10-14T10:34:50Z.
Rebased onto main (
23e93c054). Main took request format 24 in #4201 in the meantime, solinkedCallFallbacksis now format 25; the float16 byte check and the trailing-data check from main are kept. Fullctest1146/1146 on Windows/MinGW, conventions check passes. Agreed on Silent Hill: Townfall, that will be a separate follow-up.Generated by Claude Code
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T12:14:23Z.
Rebased on main: linked call fallbacks moved to request format 26 (25 is now dithered coverage), and the vertex user-data tail link fills
linked.code. Fullctestpasses.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T17:50:57Z.
Rebased onto main again:
UnlinkedCallnow comes afterImageTable, and the SRT walk commit was dropped since main already has the same fix. Fullctestpasses.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-14T17:52:25Z.
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.
main)docs/dev/debt/shader.mdL126-127core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppL2905, L3017, L3133-3135core/shader/recompiler/tests/RequestSerializerTests.cppL205-207, L242-244, L265-266, L387-389, L401, L403core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cppL35core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppL2905, L3017, L3135core/shader/recompiler/tests/RequestSerializerTests.cppL205-207, L242-244, L265-266, L387-388, L401, L403core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppL2905, L3017Imported from boykopovar/AnyPS5. Originally posted by fma-rc on 2026-10-14T18:31:29Z.
1348 Ex Voto (PPSA24249) is a second title with the Silent Hill: Townfall shape. On
main32e810db4with this PR at3c1f43948plus #5176, the call and ordered-append tests pass (18 of 18) and the title stops at 119 s with a warm shader cache:compute shader 0x1680648b00 ... computed/data-dependent s_swappc_b64 call target at program counter 0x00000130 is not statically resolvableFrom the dumped request: the shader loads its descriptor with
s_load_dwordx4from the constant address 0xF_E0040000 (vcc set to 0xe0040000 / 0xf), reads the target withs_buffer_load_dwordx2at offset 0x20, skips the call when that is null, and otherwise calls it withs_swappc_b64. Nothing in AnyPS5 maps that address, so the descriptor is in the title's own memory and could be read when the dispatch is recorded.Is anyone taking the follow-up? If not, I'd like to write it on top of this PR.
Imported from boykopovar/AnyPS5. Originally posted by tv7 on 2026-10-14T18:34:45Z.
@fma-rc that would be great, please go ahead. Silent Hill: Townfall has the same shape at 0x134, and I can test your head on it. One thing to know first: the descriptor isn't in the title's memory. I looked at this for Silent Hill, and 0xF_E0040000 belongs to Sony's
libSceAgc, so reading it at record time onmainreads nothing the title wrote.What the shipped
libSceAgcdoes (from the backport copy that ships with some dumps; I only read it, nothing copied):[Agc] FS Table offset has shifted. This is not survivable.if the table is not at exactly 0xF_E0040000.-pjHhph0ZUcwrites V# sloti(0..5),OXDc0KCnUhsreads it,86rJnbZUpr4writes a qword at 0xF_E0040010 + 8·i, andNbiQSQ-UL+Mreads one. Silent Hill does not import any of them.{routine address, 0}pairs into a 128-byte buffer. It then sets slot 0 to a V# over that buffer (stride 16, 8 records). So the qword at +0x20 that the title loads is one of Sony's routines, not null. The one Silent Hill reaches is 0xd8 bytes long. It starts withs_getreg_b32of HW_ID2 and reads trap temporaries (ttmp7), which AnyPS5's decoder rejects today (unsupported scalar source operand code 115).So on hardware the call does happen. In Silent Hill the shader reads nothing back from it: after the call it builds M0 from its own registers and never reads
s[16:17]. That fits an ordering step beforeds_ordered_count, which #5176's debt entry already lists as not modeled.What I measured on Silent Hill with a local stub that skips the call (details in #5176): with #5176 as it is, the title hangs within minutes. With the counter addressed by
offset0(the review's suggestion), it runs the full 900 s. So skipping this call did not cause the hang; #5176's M0 handling did.A direction that would match this: AnyPS5 commits the table at 0xF_E0040000 itself at init, with slot 0 pointing to a buffer whose routine entries are an AnyPS5-written routine that only returns (
s_setpc_b64 s[14:15]). Your follow-up then links that target like any other table callee. It would be worth adding a debt entry saying the routine's ordering work is not modeled, and possibly the four exports. Your call on the design, of course.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by fma-rc on 2026-10-14T20:30:02Z.
@tv7 thanks, that saved me a lot. I checked it against the PS5 12.00
libSceAgcandlibSceAgcDrivermodules and it matches: the driver allocates 2 MiB of direct memory and maps it at 0xF_E0000000 at init,libSceAgctakes its part throughUm_jkyDy9rIand places the table at 0xF_E0040000 (aborting otherwise), zeroes the six 16-byte slots, and sets slot 0 to a V# with stride 16 over eight{routine, 0}records, the third of which is what the title calls. The slot accessors return0x8a6c000bfor a slot of 6 or more and0x8a6c002fwhen the table is elsewhere.AnyPS5 maps nothing there yet, so the follow-up will map that block, fill the table at init with routines that only return, and link that callee on top of this PR. It is up as #6160 (branch
fma-rc:feat/agc-fs-table-calls). Onmain2559e9623Ex Voto stops at 57 s on this call; with it, no stop in 300 s cold or warm. @tv7 Silent Hill: Townfall on that head would be the second title, if you still have time.Edit: an earlier version of this comment said the block was not at 0xF_E0000000; the driver module shows it is.