shader: inline s_call_b64 with its s_setpc_b64 return in pixel_aot #2181

Merged
JB2WIN merged 1 commit from upstream-pr/2189 into main 2026-11-25 03:35:28 +00:00
JB2WIN commented 2026-11-25 03:26:20 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-25T03:26:20Z.


Refs #1786

Change

This is the first slice proposed in #1786. tools/pixel_aot.py inlines a forward s_call_b64 whose callee returns with s_setpc_b64 of the unmodified saved pair. This covers s_call_b64 (SOPK) and the matching s_setpc_b64 (SOP1). It is opened as a PR so the scope can be reviewed on the code. If you want it narrower, I'll cut it down.

Semantics. The AMD RDNA 2 ISA (30 November 2020) gives, in section 12.2 (SOPK opcode 22), D.u64 = PC + 4; PC = PC + signext(SIMM16 * 4) + 4, and in section 4.2 SGPR_pair = PC+4. The saved return address is therefore the instruction after the call, and that is where the inlined body continues. The target is computed like an s_branch: in LLVM 15.0.7 both use the same fixup_si_sopp_br, measured with llvm-mc.

Shape accepted:

  • The callee is a straight-line block behind the program's s_endpgm.
  • Its last instruction is s_setpc_b64 of the same pair.
  • inline_calls() runs as a pre-pass in lower() and does nothing for programs without s_call_b64.
  • The call stays in place as a marker and is followed by the callee body without its s_setpc_b64. Offsets keep the real instruction sizes.
  • After the marker, the pair is opaque: any later line that names either word is refused, writes included.

Refused:

  • a second call, and a backward or nested call;
  • a branch in the callee, a branch that crosses the call or jumps into the callee;
  • a callee without s_setpc_b64, or code after the callee;
  • reading or writing the pair in the callee or after the return;
  • s_setpc_b64 of another pair, or without a call;
  • s_swappc_b64, s_getpc_b64, and a call in a masked region (the existing region gate).

The only change to existing control flow is the refusal of branches across the call, and it applies only to programs that contain s_call_b64.

Not included: s_subvector_loop_begin/_end. The ISA defines them (opcodes 27/28), but how they read EXEC_HI in the wave32 profile is not stated. The question is in #1786.

Test

New mode draw-s-call, registered as pixel_aot_s_call_hardware and _warp (60 s timeout, skip code 77, its own FORM_COVERAGE_RECORD). form_coverage_check.py counts s_call_b64 and s_setpc_b64 as covered and asserts that s_swappc_b64, s_getpc_b64 and s_subvector_loop_* stay refused.

  • Draw: a program with a call whose callee does ALU work on values used before and after the call must export exactly the same words as the same body without the call.
  • Wrong references: the callee skipped or run twice.
  • Controls: about 45 refusals, each checked with its message.
  • Encodings: check_scall_binary pins 0xbb1e0000 | dwords for the call and be80201e for s_setpc_b64 s[30:31].
    The generic round-trip list expects a container that ends in s_endpgm, so this program is checked there instead of in that list.
  • Mutations: each makes the checks fail: callee not executed, return to the wrong place, and accepting a read of the pair.
  • Against main: with main's tools/pixel_aot.py the program fails with Unsupported instruction 22: s_call_b64 s[30:31], 4.

Run on e779b736, rebased on 65f8ef9d, with an NVIDIA GeForce RTX 3080 (driver 32.0.16.2124), WARP 10.0.26100.9818 and Windows 11 build 26200:

ctest --preset dev --no-tests=error -R '^pixel_aot_(s_call|scc_skip|exec_regions|cmpx_regions)_'   # 8/8 passed
ctest --preset dev --no-tests=error                                                              # 1400/1400 passed; 25 capability skips, none from this change

The pure checks and the LLVM 15.0.7 binary round trip pass. tools/scan_unsupported_shaders.py is unchanged, because a static scan cannot see whether the narrow shape is met.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6596493912 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2189). Originally posted by [JB2WIN](https://github.com/JB2WIN) on 2026-11-25T03:26:20Z. --- Refs #1786 ## Change This is the first slice proposed in #1786. `tools/pixel_aot.py` inlines a forward `s_call_b64` whose callee returns with `s_setpc_b64` of the unmodified saved pair. This covers `s_call_b64` (SOPK) and the matching `s_setpc_b64` (SOP1). It is opened as a PR so the scope can be reviewed on the code. If you want it narrower, I'll cut it down. **Semantics.** The AMD RDNA 2 ISA (30 November 2020) gives, in section 12.2 (SOPK opcode 22), `D.u64 = PC + 4; PC = PC + signext(SIMM16 * 4) + 4`, and in section 4.2 `SGPR_pair = PC+4`. The saved return address is therefore the instruction after the call, and that is where the inlined body continues. The target is computed like an `s_branch`: in LLVM 15.0.7 both use the same `fixup_si_sopp_br`, measured with llvm-mc. **Shape accepted:** - The callee is a straight-line block behind the program's `s_endpgm`. - Its last instruction is `s_setpc_b64` of the same pair. - `inline_calls()` runs as a pre-pass in `lower()` and does nothing for programs without `s_call_b64`. - The call stays in place as a marker and is followed by the callee body without its `s_setpc_b64`. Offsets keep the real instruction sizes. - After the marker, the pair is opaque: any later line that names either word is refused, writes included. **Refused:** - a second call, and a backward or nested call; - a branch in the callee, a branch that crosses the call or jumps into the callee; - a callee without `s_setpc_b64`, or code after the callee; - reading or writing the pair in the callee or after the return; - `s_setpc_b64` of another pair, or without a call; - `s_swappc_b64`, `s_getpc_b64`, and a call in a masked region (the existing region gate). The only change to existing control flow is the refusal of branches across the call, and it applies only to programs that contain `s_call_b64`. **Not included:** `s_subvector_loop_begin`/`_end`. The ISA defines them (opcodes 27/28), but how they read `EXEC_HI` in the wave32 profile is not stated. The question is in #1786. ## Test New mode `draw-s-call`, registered as `pixel_aot_s_call_hardware` and `_warp` (60 s timeout, skip code 77, its own `FORM_COVERAGE_RECORD`). `form_coverage_check.py` counts `s_call_b64` and `s_setpc_b64` as covered and asserts that `s_swappc_b64`, `s_getpc_b64` and `s_subvector_loop_*` stay refused. - **Draw:** a program with a call whose callee does ALU work on values used before and after the call must export exactly the same words as the same body without the call. - **Wrong references:** the callee skipped or run twice. - **Controls:** about 45 refusals, each checked with its message. - **Encodings:** `check_scall_binary` pins `0xbb1e0000 | dwords` for the call and `be80201e` for `s_setpc_b64 s[30:31]`. The generic round-trip list expects a container that ends in `s_endpgm`, so this program is checked there instead of in that list. - **Mutations:** each makes the checks fail: callee not executed, return to the wrong place, and accepting a read of the pair. - **Against `main`:** with `main`'s `tools/pixel_aot.py` the program fails with `Unsupported instruction 22: s_call_b64 s[30:31], 4`. Run on `e779b736`, rebased on `65f8ef9d`, with an NVIDIA GeForce RTX 3080 (driver 32.0.16.2124), WARP 10.0.26100.9818 and Windows 11 build 26200: ```powershell ctest --preset dev --no-tests=error -R '^pixel_aot_(s_call|scc_skip|exec_regions|cmpx_regions)_' # 8/8 passed ctest --preset dev --no-tests=error # 1400/1400 passed; 25 capability skips, none from this change ``` The pure checks and the LLVM 15.0.7 binary round trip pass. `tools/scan_unsupported_shaders.py` is unchanged, because a static scan cannot see whether the narrow shape is met. AI-assisted.
upstream-sync closed this pull request 2026-11-25 04:04:13 +00:00
tedin7 commented 2026-11-25 04:04:13 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T03:34:53Z.

Review: COMMENTED


Review of head e779b7368425736ff4b426f04b551516a9ee9af2: 0 P1, 0 P2.

Logic (clean-room, vs RDNA2 SOPK s_call_b64: D = PC + 4; PC = PC + 4 + signext(simm16)*4):

  • Target math matches the ISA formula. Backward, recursive, out-of-range, non-boundary and not-after-s_endpgm targets are refused.
  • The callee must be straight-line and end the program with s_setpc_b64 of the same pair. Branches across the call or into the callee are refused. Offsets after the call move by the body size, so branch displacements stay valid.
  • The return-address pair is opaque: any later use of it raises. Masked regions refuse the call.
  • No other open or recently merged PR covers s_call_b64 / s_setpc_b64.

Linux (all executed locally):

  • python3 tests/pixel_aot_check.py -> Self-test passed
  • python3 tests/docs_links_check.py -> 402 links OK
  • python3 tests/bidi_controls_check.py -> OK
  • git diff --check origin/main...HEAD -> clean
  • Mutations that make check_scall_controls fail (each reverted afterwards):
    1. target = call_offset + 8 + 4*imm
    2. landing >= target changed to landing > target
    3. offsets after the call not shifted by the body size

Windows Server 2025 (WARP + hardware adapter), python3 x2w_pipe.py win2025 2189 --scope direct --targets offscreen_check --regex 'pixel_aot_s_call|form_coverage|pixel_aot_scc_skip' --wait 3600:

  • Debug dev preset: 5/5 passed (pixel_aot_s_call_warp, pixel_aot_s_call_hardware, scc_skip x2, form_coverage)
  • Release /O2: 5/5 passed
  • GitHub CI Build and test on Windows: pass

Note: tests/form_coverage_check.py could not run on Linux here (missing iced_x86); it passed on Win2025.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6051472829 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2189#pullrequestreview-6051472829). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T03:34:53Z. **Review:** COMMENTED --- Review of head `e779b7368425736ff4b426f04b551516a9ee9af2`: 0 P1, 0 P2. Logic (clean-room, vs RDNA2 SOPK s_call_b64: `D = PC + 4; PC = PC + 4 + signext(simm16)*4`): - Target math matches the ISA formula. Backward, recursive, out-of-range, non-boundary and not-after-s_endpgm targets are refused. - The callee must be straight-line and end the program with `s_setpc_b64` of the same pair. Branches across the call or into the callee are refused. Offsets after the call move by the body size, so branch displacements stay valid. - The return-address pair is opaque: any later use of it raises. Masked regions refuse the call. - No other open or recently merged PR covers `s_call_b64` / `s_setpc_b64`. Linux (all executed locally): - `python3 tests/pixel_aot_check.py` -> Self-test passed - `python3 tests/docs_links_check.py` -> 402 links OK - `python3 tests/bidi_controls_check.py` -> OK - `git diff --check origin/main...HEAD` -> clean - Mutations that make `check_scall_controls` fail (each reverted afterwards): 1. target = call_offset + 8 + 4*imm 2. `landing >= target` changed to `landing > target` 3. offsets after the call not shifted by the body size Windows Server 2025 (WARP + hardware adapter), `python3 x2w_pipe.py win2025 2189 --scope direct --targets offscreen_check --regex 'pixel_aot_s_call|form_coverage|pixel_aot_scc_skip' --wait 3600`: - Debug dev preset: 5/5 passed (pixel_aot_s_call_warp, pixel_aot_s_call_hardware, scc_skip x2, form_coverage) - Release /O2: 5/5 passed - GitHub CI `Build and test on Windows`: pass Note: `tests/form_coverage_check.py` could not run on Linux here (missing `iced_x86`); it passed on Win2025. AI-assisted; commands listed were executed locally.
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
R0Y00/Xbox2Windows!2181
No description provided.