Skip to content

Recompiler: keep far jumps indirect when entered after s_getpc_b64 (#863) - #942

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

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

Conversation

@Youssefrah16

@Youssefrah16 Youssefrah16 commented Nov 24, 2026 •

Copy link
Copy Markdown

Fixes #863.

What changed

  • crates/xcl/src/gpu/rdna2.rs (resolve_far_jumps):
    • Clear any existing far_target before scanning so branch_target only inspects direct branches.
    • Collect all candidate 4-instruction far-jump sequences (S_GETPC_B64 / S_ADD_U32+S_ADDC_U32 or S_SUB_U32+S_SUBB_U32 / S_SETPC_B64) first (returning immediately with no allocation when there are none).
    • Gather all direct branch targets plus all prospective far-jump targets, and publish far_target only when none of the sequence's post-S_GETPC_B64 instructions (lo, hi, set) is targeted. Entering at S_GETPC_B64 itself still resolves as a direct far jump.
  • crates/xcl/src/gpu/recomp/tests.rs (far_jumps_stay_indirect_when_entered_after_getpc):
    • Covers direct conditional branches into get, lo, hi, and set for both add and subtract forms, verifying far_target and that translate keeps s_setpc_b64 indirect when s_getpc_b64 is bypassed.
    • Covers far-to-far edges targeting get, lo, hi, and set of a second far-jump sequence.

Tested

  • Windows 11 x64, Ryzen 7 7735HS, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.9.2602.17 (Windows SDK 10.0.26100.0), debug build, no game data:
    • NVIDIA GeForce RTX 4060 Laptop GPU (wave32, default adapter):
      • cargo test -p xcl --lib far_jump: 3 passed, 0 failed.
      • cargo test -p xcl --lib gpu:: -- --test-threads=4: 284 passed, 0 failed, 18 ignored (SKIPPED: no wave64 on 2 tests).
    • AMD Radeon 680M (RDNA2, native wave64, XCL_ADAPTER=radeon):
      • cargo test -p xcl --lib far_jump: 3 passed, 0 failed.
      • cargo test -p xcl --lib gpu:: -- --test-threads=4: 284 passed, 0 failed, 18 ignored (SKIPPED: no mesh shaders on 2 tests).
  • Independently verified in the comments below by @dcastell1 (RTX 5090, cargo test --workspace -- --test-threads=4: 714 passed, 0 failed, 41 ignored) and @eizispark (RX 9070 XT).

Regression run

main (beaa245):

xcl-smoke v1
commit: beaa245ca04e212f064efc7cafcdce104bc5c0a2
gpu: AMD Radeon RX 9070 XT
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1660 (PresentX 1660)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14862 MB

PR (a527eb3):

xcl-smoke v1
commit: a527eb364b7c53b4155ebc5b207dffab54e3602b
gpu: AMD Radeon RX 9070 XT
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1658 (PresentX 1658)
presents per 2 s (last 3): 60 60 61
device removals: 0
crashes: 0
peak commit: 14730 MB

Not tested

  • A retail title on my machine (I have no retail files; the regression run above is @eizispark's).
  • Gameplay past the menus, Intel GPUs, Linux/Wine.

AI use

  • Antigravity (Gemini) wrote the fix and regression tests, ran the local dual-GPU tests, and drafted this PR description.

@dcastell1

Copy link
Copy Markdown

Verified on Windows 11 10.0.26300, NVIDIA GeForce RTX 5090 (driver 621.24), Rust 1.100.0 MSVC 14.44.35207, debug build, on clean main@beaa245 (713 passed, 0 failed, 41 ignored on this box):

patch -p1 < this PR            # clean, no fuzz
cargo test --workspace -- --test-threads=4
714 passed; 0 failed; 41 ignored   (exit 0)

One more passing test than main: keeping entered far jumps indirect after s_getpc is exercised and green.

Tree restored afterwards (md5 and a full diff against a clean checkout), hardware adapter, no Wine, no game data. AI-assisted (opencode): applied the patch to a built tree, ran the suite, reverted it.

@eizispark

Copy link
Copy Markdown

Hardware check of a527eb364b7c53b4155ebc5b207dffab54e3602b (verified clean merge with main 077ce40): pass.

Tested

  • Hardware: AMD Radeon RX 9070 XT (RDNA4, driver 32.0.32015.16001), AMD Ryzen 7 9800X3D, 32 GB RAM, Windows 11, rustc 1.100.0 (0ef1bc386 2026-11-09), release + test profile
  • cargo test --workspace -- --test-threads=4: 714 passed, 3 failed, 41 ignored (GPU tests skipped on this adapter: none; the 3 failures under --test-threads=4 are the known concurrent global extra_pages counter race in hle::d3d12x::title_textures::tests::placed_title_textures_share_vram_and_preserve_pixels and 2 downstream PoisonErrors)
  • cargo test -p xcl --lib hle::d3d12x -- --test-threads=1: 115 passed, 0 failed, 1 ignored
  • far_jumps_stay_indirect_when_entered_after_getpc, far_jumps_are_direct_branches, a_far_jump_is_a_branch_not_an_unknown_jump, and native wave64 + mesh-shader GPU tests (gpu_dispatch_matches_native_wave64_reference, paired_halves_match_independent_native_wave64_references, dxc_mesh_shader_probe, gpu_mesh_mode_two_passes, gpu_mesh_mode_reads_memory_windows, retail_mesh_pipelines_through_the_hook, console_wave64_compute_through_the_pso_hook_dispatch_and_read_back, gpu_wave64_ps_whole_wave_reductions, gpu_wave64_vs_spill_slots_and_identity, gpu_wave64_ps_spill_slots): all ok (0 skips)

Regression run
main (beaa245):

xcl-smoke v1
commit: beaa245ca04e212f064efc7cafcdce104bc5c0a2
gpu: AMD Radeon RX 9070 XT
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1660 (PresentX 1660)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14862 MB

PR (a527eb3):

xcl-smoke v1
commit: a527eb364b7c53b4155ebc5b207dffab54e3602b
gpu: AMD Radeon RX 9070 XT
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1658 (PresentX 1658)
presents per 2 s (last 3): 60 60 61
device removals: 0
crashes: 0
peak commit: 14730 MB

Not tested

  • wave32-only GPUs (NVIDIA / Intel); gameplay past the menus

AI use

  • Antigravity (Gemini 4 Carbon) ran the build, test suite, and scripts/smoke.ps1 harness on this machine and formatted this report.

@SlopTart

Copy link
Copy Markdown

Linux / AMD RDNA3 datapoint.

Merged state: head a527eb3 onto main 9aec53d, clean merge.

Full suite, cargo test --workspace --release --no-fail-fast --target x86_64-pc-windows-gnu -- --test-threads=4: 718 passed, 7 failed, 41 ignored; failures are the known Wine-lane set from my #42 rows. far-jump-indirect-after-s_getpc green.

Not tested: retail titles (none here), Windows, RDNA4.
Counts only, no game data.

Machine: RX 7900 XT (RADV NAVI31), Mesa 26.2.5, kernel 7.2 (Arch), Proton Experimental (wine-11.0), patched vkd3d-proton v3.1, Rust cross x86_64-pc-windows-gnu, XCL_NETWORK=0, release profile, --test-threads=4. My Linux rows: #42 / #718.

AI use: Hermes agent (local Qwen-class) ran the suite and drafted this; I checked it before posting.

@guinpereira

Copy link
Copy Markdown

Test report: NVIDIA RTX 5060 Ti (wave32), head a527eb3: 719 passed, 0 failed, 41 ignored; the new test passes

Tested

  • NVIDIA GeForce RTX 5060 Ti 16 GB, driver 32.0.16.1714, 32-lane waves only. Ryzen 7 5700X, 32 GB RAM. Windows 11 Pro 25H2 (26200.9974), Rust 1.99.1 stable-x86_64-pc-windows-msvc, DXC 1.8.2502.11 (Windows SDK 10.0.26100.0). Debug build, no XCL_SAMPLE_*.
  • PR head a527eb3 as is (base 077ce40, not rebased on current main), clean tree.
  • cargo build --workspace: ok.
  • cargo test --workspace --no-fail-fast -- --test-threads=4: 719 passed, 0 failed, 41 ignored (lib: 676 passed, 21 ignored). SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware, the same as on main.
  • New test far_jumps_stay_indirect_when_entered_after_getpc passes; the existing GPU test far_jumps_are_direct_branches also passes.
  • Note: Recompiler: keep entered far-jump sequences indirect #865 changes the same lines of resolve_far_jumps for the same issue (Recompiler: far jumps ignore incoming branches into the address calculation #863), so the two will conflict.

Not tested

  • A retail title / scripts/smoke.ps1 (no title on this machine).
  • The PR rebased on current main.

AI use: Claude Code (Claude Opus 5.5) ran the commands above and wrote this report. No code changes.

@DavidM1911

Copy link
Copy Markdown
Contributor

Independent verification, merged onto current main 384f7f7 locally (clean merge).

Machine: Windows 11, Ryzen 9 7900X + RTX 3060 Ti; Rust stable MSVC, debug; DXC 1.8.2502.11.

AI use: test runs by Devin (Cognition, SWE-2); no code changes.

@upipibi

upipibi commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

This and #865 (opened about two hours earlier) fix #863 the same way, so CONTRIBUTING's "one of several PRs for the same problem" applies. I cross-ran their tests to give the maintainer something to choose on.

The rule is the same in both. Every candidate far jump is resolved first. All direct branch targets plus all candidate far targets go into one set. A sequence keeps its fixed target only if none of its add/sub, addc/subb or setpc is in that set. The differences:

  • This PR clears every far_target first and returns early when there is no candidate. On main every caller passes freshly decoded instructions, so the reset changes nothing today; it only matters if a list is ever resolved twice after an edit.
  • Recompiler: keep entered far-jump sequences indirect #865 also adds two sentences about far jumps to the README's feature table.

Tested (Windows 11 Pro 26100, Rust 1.100.0 MSVC, debug; CPU-only tests)

So each PR passes the other's tests, and the two edit the same lines of resolve_far_jumps, so only one can land. #865 already has the smoke pair. If this PR is the one kept, #865's tests would be worth carrying over: they cover a jump into the addc and the subtract form through rdna2 alone.

AI-assisted (Claude Code).

@throny

throny commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

Two contributors checked independently and found that this PR makes the same change as #865 #1632 (for #863): #1607, group D31. They suggest keeping #865. If you agree, closing this PR or joining the other one would save the maintainers a review. If the two differ in a way the checks missed, a note in #1607 helps.

This is a hint, not a request from the maintainers; nobody from the project has adopted #1607 so far.

AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.

@ivall

ivall commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

Closing this as a duplicate: #865 makes the same change and was opened first (a far jump entered after its s_getpc_b64 stays indirect). It stays open and is the one that will be reviewed and merged.

This says nothing about the quality of the code here. I compared the two diffs; the pair was also found by independent checks in #1607. If this PR covers a case #865 does not, or #865 is closed without being merged, say so and I'll reopen it. A test that is only here is welcome on #865.

Thank you for the work.

AI use: Claude Code (Claude Opus 5.5) compared the diffs and wrote this comment; the decision is the maintainer's.

@ivall ivall closed this Nov 24, 2026
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

10 participants