shader: lower statically proven PC-relative branch targets #2230

Merged
chadhyatt merged 3 commits from upstream-pr/2238 into main 2026-11-25 09:04:52 +00:00
chadhyatt commented 2026-11-25 07:03:59 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chadhyatt on 2026-11-25T07:03:59Z.


AI-assisted backport patch from x2w-microlift. Independently authored static proof for ordinary gfx1013 getpc/add/addc/setpc branches. Emits only proven in-program instruction-boundary targets with consistent incoming definitions; refuses ambiguous/clobbered/unsupported cases and preserves stage-scoped refusal census. External project progress served as a research lead, no external implementation copied. Source-built LLVM21 fixtures: python3 -B tests/startup_gfx2hlsl_calculated_target_check.py binary /opt/homebrew/opt/llvm@21/bin/llvm-mc; python3 -B tests/startup_gfx2hlsl_interp_f16_check.py; python3 -B tests/startup_gfx2hlsl_refusals_check.py; python3 -B tests/docs_links_check.py: all passed on macOS ARM64, tested 0784fda4 on upstream 71c9c347. Contributor glass24 independently reported actual WARP and RTX 4070 Ti source-built draw evidence on the private adaptation (all channels 8, changed-displacement control 14); not rerun here. No retail or broad shader coverage claim.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6599138132 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2238). Originally posted by [chadhyatt](https://github.com/chadhyatt) on 2026-11-25T07:03:59Z. --- AI-assisted backport patch from x2w-microlift. Independently authored static proof for ordinary gfx1013 getpc/add/addc/setpc branches. Emits only proven in-program instruction-boundary targets with consistent incoming definitions; refuses ambiguous/clobbered/unsupported cases and preserves stage-scoped refusal census. External project progress served as a research lead, no external implementation copied. Source-built LLVM21 fixtures: `python3 -B tests/startup_gfx2hlsl_calculated_target_check.py binary /opt/homebrew/opt/llvm@21/bin/llvm-mc`; `python3 -B tests/startup_gfx2hlsl_interp_f16_check.py`; `python3 -B tests/startup_gfx2hlsl_refusals_check.py`; `python3 -B tests/docs_links_check.py`: all passed on macOS ARM64, tested 0784fda4 on upstream 71c9c347. Contributor glass24 independently reported actual WARP and RTX 4070 Ti source-built draw evidence on the private adaptation (all channels 8, changed-displacement control 14); not rerun here. No retail or broad shader coverage claim.
tedin7 commented 2026-11-25 08:04:55 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T07:05:23Z.

Review: COMMENTED


Review of head 0784fda434a2e0c0015c5db6971acd5760ae7362 (Linux only, no Windows run).

Commands executed locally

  • git diff --stat origin/main...HEAD: 7 files, +507/-3. Title neutral, MIT, no external code claimed.
  • python3 -B tests/startup_gfx2hlsl_calculated_target_check.py binary /usr/lib/llvm-19/bin/llvm-mc: pass (ambiguous, clobber, literal-target and outside-program cases all refuse).
  • python3 -B tests/startup_gfx2hlsl_interp_f16_check.py: pass
  • python3 -B tests/startup_gfx2hlsl_refusals_check.py: pass
  • python3 -B tests/docs_links_check.py: pass (419 links)
  • python3 -B tests/bidi_controls_check.py: pass
  • git diff --check origin/main...HEAD: clean
  • CI at review time: Linux Python checks pass; Windows and fixture jobs still pending.

Mutation testing

  1. In calculated_pc_proof, replaced if imm != fact[1]: (high-word must be the sign extension of the low-word displacement) with if False:. The calculated-target test still passed. SURVIVED.
  2. Replaced if not 0 <= target < end: with if False:. The test still passed, but the case is still refused by the next interior-of-instruction check, so only the message changes. Equivalent mutant, not a gap.

Findings

  • P2: tools/startup/gfx2hlsl.py (imm != fact[1] check in the s_addc_u32 branch of calculated_pc_proof) has no killing test. The only ADDC fixture is s_addc_u32 s21, s21, 0 (tests/startup_gfx2hlsl_calculated_target_check.py:33), which only covers a non-negative displacement. Please add a negative-displacement positive case (high word -1) and a mismatched-high-word refusal case (for example a negative low displacement with addc ..., 0, and a positive one with addc ..., -1). The check guards a wrong-address silent miscompile.
  • nit: check_encoding raises 's_setpc_b64: unsupported %s encoding' even when the name is s_getpc_b64. The message prefix is misleading.
  • nit: the PR body cites only macOS results and a private adaptation's GPU readback. The new lowering emits control flow in gfx2hlsl.py, so a Win2025 WARP readback vs CPU reference is still owed before merge. I did not run it.

No P1 found.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6053229313 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2238#pullrequestreview-6053229313). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T07:05:23Z. **Review:** COMMENTED --- Review of head `0784fda434a2e0c0015c5db6971acd5760ae7362` (Linux only, no Windows run). **Commands executed locally** - `git diff --stat origin/main...HEAD`: 7 files, +507/-3. Title neutral, MIT, no external code claimed. - `python3 -B tests/startup_gfx2hlsl_calculated_target_check.py binary /usr/lib/llvm-19/bin/llvm-mc`: pass (ambiguous, clobber, literal-target and outside-program cases all refuse). - `python3 -B tests/startup_gfx2hlsl_interp_f16_check.py`: pass - `python3 -B tests/startup_gfx2hlsl_refusals_check.py`: pass - `python3 -B tests/docs_links_check.py`: pass (419 links) - `python3 -B tests/bidi_controls_check.py`: pass - `git diff --check origin/main...HEAD`: clean - CI at review time: Linux Python checks pass; Windows and fixture jobs still pending. **Mutation testing** 1. In `calculated_pc_proof`, replaced `if imm != fact[1]:` (high-word must be the sign extension of the low-word displacement) with `if False:`. The calculated-target test still passed. SURVIVED. 2. Replaced `if not 0 <= target < end:` with `if False:`. The test still passed, but the case is still refused by the next interior-of-instruction check, so only the message changes. Equivalent mutant, not a gap. **Findings** - P2: `tools/startup/gfx2hlsl.py` (`imm != fact[1]` check in the `s_addc_u32` branch of `calculated_pc_proof`) has no killing test. The only ADDC fixture is `s_addc_u32 s21, s21, 0` (tests/startup_gfx2hlsl_calculated_target_check.py:33), which only covers a non-negative displacement. Please add a negative-displacement positive case (high word `-1`) and a mismatched-high-word refusal case (for example a negative low displacement with `addc ..., 0`, and a positive one with `addc ..., -1`). The check guards a wrong-address silent miscompile. - nit: `check_encoding` raises `'s_setpc_b64: unsupported %s encoding'` even when the name is `s_getpc_b64`. The message prefix is misleading. - nit: the PR body cites only macOS results and a private adaptation's GPU readback. The new lowering emits control flow in `gfx2hlsl.py`, so a Win2025 WARP readback vs CPU reference is still owed before merge. I did not run it. No P1 found. AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-25 10:05:18 +00:00
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!2230
No description provided.