fix(shader): refuse s_setpc_b64 after s_sub with the immediate first #607
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/607"
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 adriadam10 on 2026-10-05T02:46:33Z.
What
s_setpc_b64only works in the patternsGraphBuilderresolves at build time:s_getpc_b64+ ones_add/s_subwith an immediate +s_setpc_b64(static target), and the bounded PC-relative jump table from1571ec69. Neither had an execution test.One case gave a wrong target instead of throwing:
s_sub_u32 sN, imm, sN(immediate first) computesimm - pcon hardware, butresolveSetpcTargetjumped topc - imm. Subtractions are now only resolved when the PC register is src0. Any other operand order falls through to the existing "unsupported dynamic s_setpc_b64" error.New test
agc_driver_scalar_setpc(ScalarSetpc.cpp). It loops over the lanes, reads each lane's inputs withv_readlane, runs the scalar code and writes the result back withv_writelane. It covers:s_min_u32bound 3: indices 0-4, 5, 7, 8, 16, 0x7fffffff, 0x80000000, 0xfffffff8, 0xffffffff (all past 3 clamp to the last case)s_load_dwordx2 ..., s8 offset:0x8, displacement reduced by 8)s_add_u32over two instructionss_add_i32and a negative literal, run 1-8 timess_sub_u32, run 1-4 timess_sub_u32formIt runs in wave32, native wave64 and wave64 split into two wave32 halves (
ComputeTarget(32)).Behaviour measured on HW
Run on gfx1035 (RDNA2), wave32 and wave64, 3 random input sets per wave size: the hardware output matched the model for every form above, with no differences. The test's expected values are the hardware output.
s_getpc_b64returns the address of the instruction right after it. That is whygetpcdirectly followed bysetpcloops forever on hardware (and in the recompiler, which models it the same way). The test doesn't include that form.Tested
Linux, RADV (Mesa 26.2) and lavapipe (local and CI's Mesa 25.2.8): the new test passes in all three wave modes. It doesn't depend on subgroup size, so it also runs on lavapipe. Cold run on CI's lavapipe: under 1 s. Full Release ctest: everything passes except
agc_driver_pixel_helper_lanes, which also fails on local RADV onmain.Negative checks: the test fails when the code is mutated in any of these ways:
main's behaviour (reverseds_subaccepted): refusal check failsloop_subs_getpc_b64address instead of the next instruction:skip_forwardjump_table_offsetjump_tablejump_tableChecklist
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)Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T03:09:20Z.
Thanks, this checks out. I disassembled the kernels with
llvm-mc -mcpu=gfx1013: the two jump tables (bound 3, and bound 2 withoffset:0x8), the forward skip, both backward loops and the reverseds_sub_u32 s16, 64, s16all decode as described; the words afters_endpgmare the table data.Requiring the PC register as src0 for a subtraction is the right fix, since
imm - pccan't be resolved to a static target, and the reversed form now falls through to the existing "unsupported dynamics_setpc_b64" error. The new test fails on main on exactly that check ("was not refused") and passes with the fix.PPSA21564 has only one
s_setpc_b64, afters_sub_u32 s52, s52, s36(register operand), which this change doesn't touch. It merges cleanly with the other open PRs that touchGraphBuilder.cpp. Ready to merge from my side.