Repository navigation
fix(shader): link table callees that read their program counter - #8140
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
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.
|
|
Windows 11 26300, WinLibs GCC 15.2.0, Release,
No title here (no PPSA03671). AI-assisted: yes (Claude Code); results above were run on this machine. |
|
The new #10140 independently increases the |
|
@tv7 since #9068 landed, this branch conflicts with main in To keep your fix on main's layout, I think the program-counter expansion has to happen before |
|
@tv7 a merge-order note for this PR and #10140, which the review of #10140 paired: both change
I'd propose this PR lands first, since it's the older one; after it does, I'll merge AI-assisted: yes (Claude Code) |
# Conflicts: # core/shader/recompiler/ControlFlow/src/GraphBuilder.cpp
|
@oneandonlydean merged main (2fade7e) and reworked it on #9068's layout, as you described:
On the base: the Tests on the merge head (Windows, MinGW GCC 15.2, Release):
AI-assisted: yes (Claude Code) |
|
@tv7 thanks for the rework. Expanding each table callee once before One test-only fix is needed before CI: in const auto caller = TableCaller();
const auto program = RdnaInstructionDecoder{}.Decode(caller);With that change |
RdnaProgram::code is a span, so decoding the temporary TableCaller() left it dangling when LinkCalls copied the caller. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@oneandonlydean thanks, you're right: the decoded program kept a span of the temporary. Pushed aa656b2: AI-assisted: yes (Claude Code) |
ahmadmuj
left a comment
There was a problem hiding this comment.
Reviewed head aa656b2ee5 merged onto main 0119103fa9 (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.- Red:
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.- Extra probe, not part of the PR: a callee where the
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).- Branch remap:
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. - A computed jump off the PC is still refused:
s_setpc_b64through anything but the link throws inUserDataCalleeLength. - Caching: the prepared-entry match compares the full linked code (
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. - User-data callees still refuse
s_getpc_b64(defaultfalse).
One optional thing: in CheckTableCalleeProgramCounter the callee starts with s_branch +1 (0xbf820001), which jumps over the s_getpc. So the expanded s_mov pair is dead code when BuildCode/TranslateCode run 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).
|
Windows re-run of the reworked head
AI-assisted: yes (Claude Code); results above were run on this machine. |
✅ NVIDIA GPU test: passedPR head
Intermittent validation messages (1, seen once in the parallel run, not reproduced when the test was re-run alone 2 times; not counted against this PR)Failing on main too (5, not counted against this PR)Passed on retry (1, failed in the parallel run, passed when re-run with a 360 s timeout; not counted against this PR)Validation IDs already present on main (4 IDs in 405 tests)Skipped (39)ReproduceAutomated build and test on a contributor's NVIDIA machine; it does not replace upstream CI. A new comment is posted for each new push. Full logs. |
MarcZX10
left a comment
There was a problem hiding this comment.
Re-check — changes requested for current-main integration
The new test exercises the table-callee s_getpc_b64 rewrite, 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 main 52c09d5, while current main is aaccd0ba39b7d40fdbf19664575a7e567d8542f7. Current main has since changed GraphBuilder.hpp and GraphBuilder.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.
|
Static review plus an independent Linux/AMD run on both trees per the repo AGENTS shader-recompiler protocol (CachyOS, kernel 7.2.10, GCC 16.2.1, Ninja 1.13.2, Release, What I checked
Focused paired test run (VVL env)
Both logs: 0 Not covered The expansion's address math ( |
✅ NVIDIA GPU test: passedPR head
Unstable on main (1, these also failed in recent main runs on this machine; not counted against this PR)Failing on main too (3, not counted against this PR)Validation IDs already present on main (5 IDs in 480 tests)Skipped (44)ReproduceAutomated build and test on a contributor's NVIDIA machine; it does not replace upstream CI. A new comment is posted for each new push. Full logs. |
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, onmaineb75006, rebased onto 3aa35dc: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.cteston eb75006: everything passes except 8 tests that fail the same way on plain eb75006 on 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 onto 3aa35dc: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, Recompiler: a T# reached through two loads after a dynamically indexed read (pointer → pointer → T#, pointer → V# → buffer → T#) stops Ratchet & Clank (PPSA01474) and Guardians of the Galaxy (PPSA01748) #6191). Not a stock-mainrun: that tree also carries fix(shader): give the frontend's call analysis the dispatch's wave size #7816, fix(recompiler): replay every eight-bit stencil reference a pixel shader may export #7006, fix(agc): resolve indexed indirect draws on a queue that never set INDEX_BUFFER_SIZE #7679 and local changes, so it shows only that this refusal is gone.Checklist
main(3aa35dc); no open PR changesLinkCallscallee copying or thes_getpc_b64refusal.mdfiles or images added🤖 Generated with Claude Code