tombox-xshader: translate s_getpc_b64 + s_add_u32 + s_addc_u32 + s_setpc_b64 as a direct branch #185
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/185"
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 omonkeyz/xbox-emulator. Originally posted by MeNoSkills on 2026-11-22T22:02:33Z.
A branch farther than s_branch's 16-bit range is encoded as s_getpc_b64 s[n:n+1]; s_add_u32 s[n], s[n], K; s_addc_u32 s[n+1], s[n+1], 0; s_setpc_b64 s[n:n+1] with a constant K. The translator rejected the s_setpc_b64 of that sequence ("unsupported SOP1") wherever it was not the last instruction before the end of the program, so any shader that needed a far branch failed to translate.
Change
resolve_far_jumps, run right after the disassembly, recognises the four-instruction pattern on the same register pair (the add's source and destination are s[n], the addc's are s[n+1] with a 0 operand, and the s_setpc_b64 reads s[n]) and turns the s_setpc_b64 into an s_branch whose offset points at (address after the s_getpc_b64) + K. The existing forward/backward branch handling then applies, and a target that is not an instruction start is reported the same way as before. A s_setpc_b64 without that pattern is still refused, and the "return to the chained stage" s_setpc_b64 at the end of a vertex shader is untouched. Only a K that is a multiple of 4 and non-negative is matched.Tests
exec_mem::branch::pc_relative_jumps_are_direct_branches_near_and_beyond_the_16_bit_range: a compute shader that sets v10 = 7, jumps overv_mov v10, 63plus 0, 3, 40 and 40,000 s_nop dwords, then sets v11 = 5; the last case is 160 KB, past the +-128 KB reach of s_branch. All four pass (also with runtime inputs) on an RTX 4070 Ti; without the change all fail with "unsupported SOP1 [s_setpc_b64]".exec_mem::branch::a_jump_through_a_computed_register_is_still_refused.--lib85,--test synthetic22,--test isa_sweep2 (541 mnemonics),--test mesh24,--test exec -- scalar_ branch::16, all passing. pr_gate: 0 problems.Not verified
No real shader with this pattern: I know the sequence only from a description of the retail GTA VI pack, not from a dump. Negative K (a backward far jump through s_sub_u32 or a wrapped add) is not recognised.
Imported from omonkeyz/xbox-emulator. Originally posted by omonkeyz on 2026-11-22T23:23:27Z.
Applied in
cde6015(merged in42511d7) with your authorship kept, thanks.Pull request closed