Skip to content

Recompiler: keep far jumps indirect when a branch enters after s_getpc_b64 - #1632

Closed
AlpPesen wants to merge 1 commit into
xcl-dev:mainfrom
AlpPesen:fix/far-jump-incoming-branches
Closed

AlpPesen wants to merge 1 commit into
xcl-dev:mainfrom
AlpPesen:fix/far-jump-incoming-branches

Conversation

@AlpPesen

@AlpPesen AlpPesen commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Fixes rdna2::resolve_far_jumps so a four-instruction s_getpc_b64 / s_add_u32+s_addc_u32 (or s_sub_u32+s_subb_u32) / s_setpc_b64 sequence is left indirect (far_target = None) whenever any direct branch or prospective far jump targets one of its interior instructions (lo, hi, or set), bypassing s_getpc_b64.

Fixes #863.

What is in it

  • crates/xcl/src/gpu/rdna2.rs:
    • Reset prior far_target annotations at the start of resolve_far_jumps so repeated calls are idempotent.
    • Collect all direct branch targets (branch_target) plus all prospective far-jump targets before publishing far_target, and verify PC contiguity across [get, lo, hi, set].
    • Publish insts[k].far_target = Some(target) only when none of lo.pc, hi.pc, or set.pc is in the collected target set (branches targeting get.pc itself still execute the full sequence and stay direct).
  • crates/xcl/src/gpu/recomp/tests.rs:
    • Add far_jumps_stay_indirect_when_branched_into covering:
      • direct conditional branches targeting get.pc (stays direct) vs lo.pc, hi.pc, and set.pc (stays indirect) for both add and subtract forms;
      • a far-to-far edge where sequence A resolves into the interior (lo.pc) of sequence B (A stays direct, B stays indirect).
    • Verified that the new test fails on unmodified main (b7aa9f3) at sub=false simm16=1 (Some(24) instead of None) and passes with this fix.

Regression run

Baseline (main, warm shader/PSO cache):

xcl-smoke v1
commit: 09940bb87fa11bc394fd9e5de570c2b7cfd16323
gpu: AMD Radeon RX 6800
title: YouKnowWho
seconds: 60
exit: 0x0
frames shown: 405 (PresentX 405)
presents per 2 s (last 3): 11 12 11
device removals: 0
crashes: 0
peak commit: 15870 MB

This PR (fix/far-jump-incoming-branches, warm shader/PSO cache):

xcl-smoke v1
commit: 99e113c14bbca4138bc076084a5719186a81c0fa
gpu: AMD Radeon RX 6800
title: YouKnowWho
seconds: 60
exit: 0x0
frames shown: 391 (PresentX 391)
presents per 2 s (last 3): 16 16 16
device removals: 0
crashes: 0
peak commit: 15867 MB

Tested

Hardware: Windows 11 Pro for Workstations (Build 26300), Intel Core i9-9900K, 32 GB RAM, AMD Radeon RX 6800 (16337 MiB VRAM, Driver 32.0.21045.29003), rustc 1.100.0 (0ef1bc386 2026-11-09).

  • cargo test -p xcl --lib far_jumps: 2 passed; 0 failed; 0 ignored; 0 skipped.
  • XCL_REQUIRE_GPU=wave64,mesh cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4: 768 passed; 3 failed; 41 ignored; 0 skipped. All 3 failures are the pre-existing RDNA2 placed_title_textures_share_vram_and_preserve_pixels + 2 VRAM_TEST_LOCK PoisonError cascades on unmodified main (tracked in D3D12.X: map a one-slice title texture's packed mips where D3D12 addresses them #470).
  • .\scripts\smoke.ps1 -Game '<game folder>\YouKnowWho' on 99e113c14bbca4138bc076084a5719186a81c0fa (see Regression run above).

Not tested

  • Non-AMD GPUs and Linux / Wine.

AI use

Antigravity (Gemini 4 Neon) implemented the incoming-branch check in crates/xcl/src/gpu/rdna2.rs, added the regression test in crates/xcl/src/gpu/recomp/tests.rs, and ran the test suite and smoke run.

…c_b64

Collect all direct branch targets and prospective far-jump targets before annotating ar_target in 
dna2::resolve_far_jumps, and leave any four-instruction GETPC/add/addc/SETPC (or sub/subb) sequence indirect if any branch targets its lo, hi, or set instruction (bypassing s_getpc_b64). Also verify contiguity across the four instructions and clear prior annotations so 
esolve_far_jumps is idempotent.

Fixes xcl-dev#863.

Assisted-by: Antigravity (Gemini 4 Neon)
anoyarou added a commit to anoyarou/xcl that referenced this pull request Nov 24, 2026
…c_b64 (xcl-dev#1632)

Fixes rdna2::resolve_far_jumps so a four-instruction s_getpc_b64 /
s_add_u32+s_addc_u32 / s_setpc_b64 sequence is left indirect
(far_target = None) whenever any direct branch or prospective far jump
targets one of its interior instructions (lo, hi, or set).

Assisted-by: Antigravity
@upipibi

upipibi commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Duplicate note: #863 already has two open PRs with the same rule. #865 (opened first) and #942 both collect the direct branch targets plus every candidate far jump's target, and keep the s_setpc_b64 indirect when any of lo / hi / set is a target. #942 also resets far_target first, as this PR does. The earlier comparison on #942 found that each passes the other's tests. All three edit resolve_far_jumps, so only one can land. If this one has a case the others miss, a test that fails on #865's or #942's head would show it. Comparison of the diffs only: I haven't run them.

AI use: Claude Code (Claude Opus 5.5) compared the diffs and wrote this.

@AlpPesen

Copy link
Copy Markdown
Contributor Author

Closing in favor of the earlier open PRs #865 and #942 for #863 to keep triage clean. Thanks @upipibi for flagging!

@AlpPesen AlpPesen closed this Nov 24, 2026
@AlpPesen
AlpPesen deleted the fix/far-jump-incoming-branches branch November 24, 2026 20:21
@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~22 ignored. (Intermittent single-test flake under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified main.)

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Recompiler: far jumps ignore incoming branches into the address calculation

3 participants