shader: decode backward far jumps (signed offset literal) #80

Merged
tedin7 merged 1 commit from upstream-pr/80 into main 2026-11-24 00:37:01 +00:00
tedin7 commented 2026-11-24 00:17:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by tedin7 on 2026-11-24T00:17:03Z.


What
The far-jump resolver in the GFX10 decoder read the 32-bit literal of s_add_u32 sn, sn, literal as unsigned. It now reads it as a signed offset.

Why
Compilers reach past a branch's +-128 KB range with s_getpc_b64, s_add_u32 (low dword of a signed 64-bit offset), s_addc_u32 (high dword), s_setpc_b64. A backward far jump has a negative low dword (for example 0xFFFFFFF8) and a high dword of -1. The old code turned that into a target about 4 GB ahead, found it outside the code, and failed the whole shader with far jump target outside the code. So a shader with a loop body over 128 KB could not be translated. Forward jumps behave as before (the literal is small and positive), and so does the s_sub_u32 form.

Tested
Linux x86_64 only:

  • New test gfx10::tests::follows_far_jumps_backward (synthetic words in memory, no game data). Before the fix it fails with Isa { offset: 24, reason: "far jump target outside the code" }; after the fix it passes.
  • cargo test -j4 -p victory-shader: 52 passed, 0 failed.
  • cargo clippy -j4 -p victory-shader --tests: no new warnings (one existing dead_code warning for a Windows-only helper).
  • rustfmt --check --edition 2024 on the touched file: clean.

Not run: Windows runtime, GPU, or any real console shader. The encoding of the backward jump follows how LLVM-style compilers emit it; I did not have a real shader to confirm the console compiler does the same.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6571643797 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/80). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T00:17:03Z. --- **What** The far-jump resolver in the GFX10 decoder read the 32-bit literal of `s_add_u32 sn, sn, literal` as unsigned. It now reads it as a signed offset. **Why** Compilers reach past a branch's +-128 KB range with `s_getpc_b64`, `s_add_u32` (low dword of a signed 64-bit offset), `s_addc_u32` (high dword), `s_setpc_b64`. A backward far jump has a negative low dword (for example 0xFFFFFFF8) and a high dword of -1. The old code turned that into a target about 4 GB ahead, found it outside the code, and failed the whole shader with `far jump target outside the code`. So a shader with a loop body over 128 KB could not be translated. Forward jumps behave as before (the literal is small and positive), and so does the `s_sub_u32` form. **Tested** Linux x86_64 only: - New test `gfx10::tests::follows_far_jumps_backward` (synthetic words in memory, no game data). Before the fix it fails with `Isa { offset: 24, reason: "far jump target outside the code" }`; after the fix it passes. - `cargo test -j4 -p victory-shader`: 52 passed, 0 failed. - `cargo clippy -j4 -p victory-shader --tests`: no new warnings (one existing dead_code warning for a Windows-only helper). - `rustfmt --check --edition 2024` on the touched file: clean. Not run: Windows runtime, GPU, or any real console shader. The encoding of the backward jump follows how LLVM-style compilers emit it; I did not have a real shader to confirm the console compiler does the same.
upstream-sync closed this pull request 2026-11-24 06:51:13 +00:00
DaviTostes commented 2026-11-24 06:54:38 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DaviTostes on 2026-11-24T00:23:21Z.


Tested c963b71 stacked on #39 on Arch Linux x86_64, rustc 1.98.1: pass.

  • cargo test --workspace: 156 passed, 0 failed, 3 ignored; merge with #39 clean.
  • The PR adds 4 #[test]s (the signed far-jump decode cases), included in that run.
  • No game data used.

AI-assisted (DeepSeek V4.1 Flash coding agent).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7118016200 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/80#issuecomment-7118016200). Originally posted by [DaviTostes](https://github.com/DaviTostes) on 2026-11-24T00:23:21Z. --- Tested `c963b71` stacked on **#39** on **Arch Linux x86_64, rustc 1.98.1**: **pass**. - `cargo test --workspace`: **156 passed, 0 failed, 3 ignored**; merge with #39 clean. - The PR adds 4 `#[test]`s (the signed far-jump decode cases), included in that run. - No game data used. AI-assisted (DeepSeek V4.1 Flash coding agent).
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Marvisak/VIctory!80
No description provided.