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

Closed
github-bot wants to merge 1 commit from gh-pr/1632/head into gh-pr/1632/base
Owner

@⁠AlpPesen on GitHub · 2026-11-24 18:26 UTC · original
AlpPesen:fix/far-jump-incoming-branches → main · +100 −1 · 2 files · 1 commits · closed without merging

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 #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.

**@⁠AlpPesen** on GitHub · 2026-11-24 18:26 UTC · [original](https://github.com/xcl-dev/xcl/pull/1632) `AlpPesen:fix/far-jump-incoming-branches` → `main` · +100 −1 · 2 files · 1 commits · closed without merging 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 #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.
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 #863.

Assisted-by: Antigravity (Gemini 4 Neon)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:00:02 +00:00
github-bot closed this pull request 2026-11-26 05:00:02 +00:00
Author
Owner

@⁠upipibi on GitHub · 2026-11-24 18:57 UTC · original

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.

**@⁠upipibi** on GitHub · 2026-11-24 18:57 UTC · [original](https://github.com/xcl-dev/xcl/pull/1632#issuecomment-7141383578) 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.
Author
Owner

@⁠AlpPesen on GitHub · 2026-11-24 20:21 UTC · original

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

**@⁠AlpPesen** on GitHub · 2026-11-24 20:21 UTC · [original](https://github.com/xcl-dev/xcl/pull/1632#issuecomment-7143422599) Closing in favor of the earlier open PRs #865 and #942 for #863 to keep triage clean. Thanks @⁠upipibi for flagging!
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 20:46 UTC · original

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!

**@⁠DavidM1911** on GitHub · 2026-11-24 20:46 UTC · [original](https://github.com/xcl-dev/xcl/pull/1632#issuecomment-7144044307) 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!

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.