fix(shader): link table callees that read their program counter #8140
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8140"
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 tv7 on 2026-10-19T23:56:50Z.
What
A compute shader that calls through a table (
FindTableCalls/LinkCalls) is refused when one of the table's callees reads its program counter:LinkCallscopies each callee into the caller, so ans_getpc_b64inside the copy would return the copy's address instead of the callee's. For a table callee the original address is known (TableCallee::target), so the copy can keep the value the instruction reads on hardware:LinkCallsexpands eachs_getpc_b64 s[n:n+1]of a table callee intos_mov_b32 s[n], loands_mov_b32 s[n+1], hioftarget + offset + 4, the address the instruction returns at its original place. The callee's direct branches are re-targeted to the moved instructions, so the copy stays inside its call region.UserDataCalleeLengthtakesallowGetpc;ReadTableCalleespasses it, so table callees withs_getpc_b64are read instead of refused. User-data callees (no fixed address at link time) are still refused as before.s_getpc_b64writes something other than an SGPR pair, or that branches outside its own instructions, is refused with its own message.Tested
BUILD_TESTING=ON, onmaineb7500680, rebased onto3aa35dc01:scalar_callgainsCheckTableCalleeProgramCounter: a callees_branch +1; s_getpc_b64 s[16:17]; s_setpc_b64 s[14:15]at0x1122334400links tos_branch +4; s_mov_b32 s16, 0x22334408; s_mov_b32 s17, 0x11; s_setpc_b64 s[14:15], the linked program builds its call graph and translates; a callee withouts_getpc_b64is copied unchanged;s_getpc_b64 vccis refused.ctestoneb7500680: everything passes except 8 tests that fail the same way on plaineb7500680on this machine (shader_cache_runtime_sourcescannot find Ninja,patched_librariescannot load the MinGW runtime,agc_driver_msaa_dcc_clear_4,agc_driver_indirect_arguments_pending_producer,agc_driver_pass_input_hazard,agc_shader_replay_tool,agc_driver_pm4_replay_tool,guest_memory). After the rebase onto3aa35dc01:scalar_calland every table/user-data call, swappc and shader-memory test pass.0x11d049aa00, table call at0x2470, callee offset0xe34) stops the title after its intro movies. With this change the shader links and translates; its next stop is a separate one (a sampler read through a data-dependent pointer chain, #6191). Not a stock-mainrun: that tree also carries #7816, #7006, #7679 and local changes, so it shows only that this refusal is gone.Checklist
main(3aa35dc01); no open PR changesLinkCallscallee copying or thes_getpc_b64refusal.mdfiles or images added🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-20T12:31:41Z.
Windows 11 26300, WinLibs GCC 15.2.0, Release,
BUILD_TESTING=ON,main02fb1ce53with this PR (9a0bdcdde) merged. RTX 5070 Ti (617.42) and AMD Radeon iGPU1002:13c0(RDNA 2, AMD Windows driver 32.0.21042.62),ANYPS5_REQUIRE_VULKAN=1.S_GETPC_B64isD.u64 = PC + 4, and the expansion writestarget + offset + 4.scalar_calland the other call/swappc/user-data/shader-memory tests (ctest -R "scalar_call|swappc|user_data_call|table_call|shader_memory"): 9/9 pass. WithLinkCallsinserting the callee unchanged (the expansion disabled, everything else from the PR kept),scalar_callfails.s_getpc_b64 s[16:17]; s_cbranch_scc0 -2; s_setpc_b64 s[14:15]at0x1122334400. Linked throughTableCaller(), it givess_mov_b32 s16, 0x22334404; s_mov_b32 s17, 0x11; s_cbranch_scc0 -5; s_setpc_b64 s[14:15](0xbf84fffb): the branch lands on the firsts_mov_b32, andBuildCodeandTranslateCodeaccept it.ctest -R "agc|shader|spirv|recomp|scalar_call" -j6, 834 tests: RTX, onlyagc_driver_pass_input_hazardfails, as onmainhere. iGPU:agc_driver_mul_lo_u16_high_halfandagc_driver_sgpr_pattern_fill_keysfail as onmain, plusagc_driver_queued_index_read_order, which passed 3 of 3 when run alone. No new failures.No title here (no PPSA03671).
AI-assisted: yes (Claude Code); results above were run on this machine.
Imported from boykopovar/AnyPS5. Originally posted by ahmadmuj on 2026-10-25T16:45:07Z.
Review: APPROVED
Reviewed head
aa656b2ee5merged onto main0119103fa9(clean merge). Linux x86_64 (WSL2), GCC 13.3, Release, lavapipe (llvmpipe, LLVM 20.1.2).What I ran:
scalar_call,scalar_swappc,agc_shader_control_flow(plus_iteration_selection_offand_forced_fallback),agc_driver_compute_table_calls,agc_driver_compute_fs_table_calls,agc_driver_compute_user_data_calls(plus_registered),agc_driver_scalar_swappc: 10/10 pass. The driver table-call tests really ran on lavapipe, not skipped.LinkCallswithcodestaken straight fromcallee.code(expansion off, rest of the PR kept):scalar_callfails. Back to the PR: passes.tools/check_conventions.py --base 0119103fa9: pass.s_getpcactually runs and feeds a PC-relative load,s_getpc_b64 s[16:17]; s_add_u32 s16, s16, 0x40; s_addc_u32 s17, s17, 0; s_load_dword s20, s[16:17], 0; s_waitcnt lgkmcnt(0); s_setpc_b64 s[14:15]at0x1122334400, throughTableCaller(). It links tos_mov_b32 s16, 0x22334404; s_mov_b32 s17, 0x11; ..., andBuildCode/TranslateCodeaccept it. The IR loads throughGetAddressResource(s16, s17)after the add, so it reads guest0x1122334444, same as on hardware.Code walk:
target + pc + 4matches the recompiler's owns_getpc_b64model (sGetpcB64: shader base + pc + 4).moved[]only marks instruction starts, so a branch into a literal throws, andbranchWordgets expanded offsets on both ends. A branch past the return is already refused byUserDataCalleeLength.s_setpc_b64through anything but the link throws inUserDataCalleeLength.ShaderRegistry.cpp,std::ranges::equal(..., linked.code)), and the baked literal is part of it, so same-byte callees at different addresses don't share a translation.s_getpc_b64(defaultfalse).One optional thing: in
CheckTableCalleeProgramCounterthe callee starts withs_branch +1(0xbf820001), which jumps over thes_getpc. So the expandeds_movpair is dead code whenBuildCode/TranslateCoderun on it. The word check and the red run still pin the expansion. If you want the translate step to cover a live expanded read too, a callee like the probe above would do:{0xbe901f00, 0x8010ff10, 0x00000040, 0x82118011, 0xf4000508, 0xfa000000, 0xbf8cc07f, 0xbe80200e}.Not checked: the title (no PPSA03671), and the AMD ISA PDF itself (wachi35676 quoted it above; I compared against the existing translation instead).
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T09:44:14Z.
Review: CHANGES_REQUESTED
Re-check — changes requested for current-main integration
The new test exercises the table-callee
s_getpc_b64rewrite, verifies the materialized address and remapped direct branch, and retains rejection of unsupported VCC destinations. I found no new source-level defect in that scoped change.The reported NVIDIA run is on the PR head merged with
main52c09d5, while currentmainisaaccd0ba39b7d40fdbf19664575a7e567d8542f7. Current main has since changedGraphBuilder.hppandGraphBuilder.cpp, which this PR also modifies. The current merge preview is clean, but the old-base GPU/test run does not validate the resulting integration.Please refresh the branch onto current main, preserve the new table-callee behavior alongside main's GraphBuilder changes, and rerun the focused scalar-call/recompiler tests and the relevant GPU/validation checks on that exact head. The current hosted product jobs are skipped. I did not run these tests locally.