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

Manually merged
github merged 3 commits from gh-pr/2238/head into gh-pr/2238/base 2026-11-27 00:08:38 +00:00
Owner

@⁠chadhyatt on GitHub · 2026-11-25 07:03 UTC · original
chadhyatt:backport/proven-shader-pc-target → main · +507 −3 · 7 files · 3 commits · merged 2026-11-25 09:04 UTC

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.

**@⁠chadhyatt** on GitHub · 2026-11-25 07:03 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2238) `chadhyatt:backport/proven-shader-pc-target` → `main` · +507 −3 · 7 files · 3 commits · merged 2026-11-25 09:04 UTC 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.
- Intersect exact address facts across incoming paths and refuse unproven target or ordinary-definition escapes.
- Preserve existing interpolation branch boundaries and source-built direct controls.
- Register independently authored portable and LLVM-assembled fixtures.
- Keep normal translation strict and collect independent diagnostic refusals.
- Exercise mixed source-built refusal controls using LLVM21.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 00:08:36 +00:00
github manually merged commit 0784fda434 into gh-pr/2238/base 2026-11-27 00:08:38 +00:00
Author
Owner

@⁠tedin7 on GitHub · 2026-11-25 07:05 UTC · original · reviewed

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.

**@⁠tedin7** on GitHub · 2026-11-25 07:05 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2238#pullrequestreview-6053229313) · **reviewed** 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.
This discussion has been locked. Commenting is limited to contributors.
No description provided.