shader: admit per-lane binary32 VALU forms in pixel_aot masked regions #969

Merged
MasterDomino merged 2 commits from upstream-pr/976 into main 2026-11-23 20:12:48 +00:00
MasterDomino commented 2026-11-23 19:25:28 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-23T19:25:28Z.


Change

Implements #975, the region-body stage first proposed on #932 (stage one closed with #957). The masked-region body (REGION_ALU) admitted only v_mov_b32 and binary32 add/sub/subrev/mul/min/max. That blocked almost every region the console compiler emits, even with #957's v_cmpx opener.

This PR admits the per-lane binary32 forms lower() already handles outside regions, in the encodings measured in real regions:

  • v_fmac_f32_e32, v_mac_f32_e32
  • v_mul_legacy_f32_e32 and _e64
  • v_cvt_f32_ubyte0..3 _e32
  • v_rcp_f32_e32, v_rsq_f32_e32, v_sqrt_f32_e32
  • v_fma_f32, v_mad_f32, v_med3_f32

These are 14 forms, admitted under both openers (s_and_saveexec_b64 and v_cmpx).

  • Lowering is unchanged. Each form lowers exactly as outside a region. The only translator change is the REGION_ALU pattern.
  • The existing safety net still applies. The per-instruction check in lower() refuses a body instruction that changes anything but VGPRs (scalar state, SCC, pending loads, export state).
  • Speculation is safe. The restore-time select discards a false lane's speculated value, including an out-of-domain infinity or NaN from rcp/rsq/sqrt.
  • Accumulator forms. fmac/mac read their destination, so a destination still conditional from an earlier region rejects, as reads already do.
  • Still refused: other encodings (_e64 of the VOP1/VOP2 forms), other operations (e.g. v_exp, v_log, v_cvt_f32_f16, v_fma_mix, v_max3), and scalar instructions (s_nop, s_mov_b32, s_waitcnt, loads).

Fixes #975
Refs #932

Verification

Upstream main at b3af628 (with #957), Fedora 45 x86_64, Python 3.15.2, LLVM 15.0.7.

python -B tests/pixel_aot_check.py                       # controls, including check_region_body_controls
python -B tests/pixel_aot_check.py binary <llvm-mc> <llvm-objcopy> <libLLVM-15.so>

Both exit 0, and so do the 26 platform-independent checks, tests/form_coverage_check.py, tests/rdna2_tools_check.py with LLVM, tests/compute_store_check.py binary and tests/ffx_dispatch_aot_check.py.

  • Translation controls (check_region_body_controls):
    • Every form lowers under both openers with exactly one merge of the rewritten register.
    • Twelve other forms or encodings are refused under both openers with Instruction cannot run in a masked region.
    • v_fmac on a destination left conditional by an earlier region rejects with Read of a register defined only on the masked path.
    • A region chaining rcp, fmac and med3 across two registers merges each register once.
  • Binary. The 14 programs are assembled and disassembled with LLVM 15 for gfx1013, and each must lower identically.
  • Draw dry run. Not a substitute for WARP. check_region_body_draw ran with the Linux DXC 1.9.2609 release and only the D3D12 batch call replaced by a recorder: all 14 shaders compile, and 56 well-formed cases are written (42 pass, 14 mismatch).

Not run here: pixel_aot_region_body_warp. It needs Windows; this PR's CI run is the first WARP result.

  • Programs. One per form. Each rewrites the green channel inside a v_cmpx region on mixed (0.5), full (10) and empty (-1) masks.
  • Inputs. Chosen so every inner value is exact: 1.0, -1.0, 1.0-4.0 from the bytes of 0x04030201, 2.0, g + 1.0.
  • The approximate operations. D3D allows rcp, rsqrt and sqrt an error, so their integer results (8, 4 and 4) and the outer value are rounded after the region with +0.5 and floor, as in the existing SDWA unary draws.
  • Mismatch control. A reference applying the body to every lane must mismatch. The inner value differs from every outer value on every lane, so this control always fires.

No _hardware run is reported.

Evidence and follow-up

Impact on one local input (the 12,101 PS records from #932; aggregates only), on the regions #957 accepts structurally (save + f32/i32/u32 _e32 v_cmpx + restore of the same pair):

Body rule Regions accepted Records with ≥1
before (main) 152 112
this PR 3,151 1,529 (12.6%)

That matches #975, now measured with the branch's own REGION_ALU. A record also needs everything outside its regions to translate, so these count regions, not translatable shaders.

Next blockers after this stage: scalar instructions in the body (s_mov_b32, s_waitcnt, scalar loads), nesting, and else (s_andn2_b64 exec, saved, exec).

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed. (docs/experiments.md, "Exec-masked pixel regions".)
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted.

🤖 Generated with Claude Code

https://claude.ai/code/session_01B48PpcRN2Er51keRf2DsS5

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6567091476 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/976). Originally posted by [MasterDomino](https://github.com/MasterDomino) on 2026-11-23T19:25:28Z. --- ## Change Implements #975, the region-body stage first proposed on #932 (stage one closed with #957). The masked-region body (`REGION_ALU`) admitted only `v_mov_b32` and binary32 `add`/`sub`/`subrev`/`mul`/`min`/`max`. That blocked almost every region the console compiler emits, even with #957's `v_cmpx` opener. This PR admits the per-lane binary32 forms `lower()` already handles outside regions, in the encodings measured in real regions: - `v_fmac_f32_e32`, `v_mac_f32_e32` - `v_mul_legacy_f32_e32` and `_e64` - `v_cvt_f32_ubyte0`..`3` `_e32` - `v_rcp_f32_e32`, `v_rsq_f32_e32`, `v_sqrt_f32_e32` - `v_fma_f32`, `v_mad_f32`, `v_med3_f32` These are 14 forms, admitted under both openers (`s_and_saveexec_b64` and `v_cmpx`). - **Lowering is unchanged.** Each form lowers exactly as outside a region. The only translator change is the `REGION_ALU` pattern. - **The existing safety net still applies.** The per-instruction check in `lower()` refuses a body instruction that changes anything but VGPRs (scalar state, SCC, pending loads, export state). - **Speculation is safe.** The restore-time select discards a false lane's speculated value, including an out-of-domain infinity or NaN from `rcp`/`rsq`/`sqrt`. - **Accumulator forms.** `fmac`/`mac` read their destination, so a destination still conditional from an earlier region rejects, as reads already do. - **Still refused:** other encodings (`_e64` of the VOP1/VOP2 forms), other operations (e.g. `v_exp`, `v_log`, `v_cvt_f32_f16`, `v_fma_mix`, `v_max3`), and scalar instructions (`s_nop`, `s_mov_b32`, `s_waitcnt`, loads). Fixes #975 Refs #932 ## Verification Upstream `main` at `b3af628` (with #957), Fedora 45 x86_64, Python 3.15.2, LLVM 15.0.7. ```sh python -B tests/pixel_aot_check.py # controls, including check_region_body_controls python -B tests/pixel_aot_check.py binary <llvm-mc> <llvm-objcopy> <libLLVM-15.so> ``` Both exit 0, and so do the 26 platform-independent checks, `tests/form_coverage_check.py`, `tests/rdna2_tools_check.py` with LLVM, `tests/compute_store_check.py binary` and `tests/ffx_dispatch_aot_check.py`. - **Translation controls** (`check_region_body_controls`): - Every form lowers under both openers with exactly one merge of the rewritten register. - Twelve other forms or encodings are refused under both openers with `Instruction cannot run in a masked region`. - `v_fmac` on a destination left conditional by an earlier region rejects with `Read of a register defined only on the masked path`. - A region chaining `rcp`, `fmac` and `med3` across two registers merges each register once. - **Binary.** The 14 programs are assembled and disassembled with LLVM 15 for gfx1013, and each must lower identically. - **Draw dry run.** Not a substitute for WARP. `check_region_body_draw` ran with the Linux DXC 1.9.2609 release and only the D3D12 batch call replaced by a recorder: all 14 shaders compile, and 56 well-formed cases are written (42 `pass`, 14 `mismatch`). **Not run here: `pixel_aot_region_body_warp`.** It needs Windows; this PR's CI run is the first WARP result. - **Programs.** One per form. Each rewrites the green channel inside a `v_cmpx` region on mixed (0.5), full (10) and empty (-1) masks. - **Inputs.** Chosen so every inner value is exact: 1.0, -1.0, 1.0-4.0 from the bytes of `0x04030201`, 2.0, `g + 1.0`. - **The approximate operations.** D3D allows `rcp`, `rsqrt` and `sqrt` an error, so their integer results (8, 4 and 4) and the outer value are rounded after the region with +0.5 and floor, as in the existing SDWA unary draws. - **Mismatch control.** A reference applying the body to every lane must mismatch. The inner value differs from every outer value on every lane, so this control always fires. No `_hardware` run is reported. ## Evidence and follow-up **Impact on one local input** (the 12,101 PS records from #932; aggregates only), on the regions #957 accepts structurally (save + f32/i32/u32 `_e32` `v_cmpx` + restore of the same pair): | Body rule | Regions accepted | Records with ≥1 | |---|---|---| | before (`main`) | 152 | 112 | | this PR | **3,151** | **1,529 (12.6%)** | That matches #975, now measured with the branch's own `REGION_ALU`. A record also needs everything outside its regions to translate, so these count regions, not translatable shaders. Next blockers after this stage: scalar instructions in the body (`s_mov_b32`, `s_waitcnt`, scalar loads), nesting, and else (`s_andn2_b64 exec, saved, exec`). ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. (`docs/experiments.md`, "Exec-masked pixel regions".) - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01B48PpcRN2Er51keRf2DsS5
upstream-sync closed this pull request 2026-11-24 06:45:40 +00:00
R0Y00 commented 2026-11-24 06:49:35 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T19:55:16Z.


6d5072a resolves the test registration conflict after #964. Static checks and the complete LLVM 15 binary run passed. The masked-region body and 64-bit shifts each passed on both WARP and RTX 4060 Laptop, keeping the no-mask reference mutation and old shift controls. The updated head is waiting for Windows CI.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7112299664 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/976#issuecomment-7112299664). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T19:55:16Z. --- 6d5072a resolves the test registration conflict after #964. Static checks and the complete LLVM 15 binary run passed. The masked-region body and 64-bit shifts each passed on both WARP and RTX 4060 Laptop, keeping the no-mask reference mutation and old shift controls. The updated head is waiting for Windows CI.
lantiumBot commented 2026-11-24 06:49:45 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lantiumBot on 2026-11-23T21:56:59Z.


First _hardware result for this draw on RDNA 4. Data only.

pixel_aot_region_body_hardware passed on an AMD Radeon RX 9060 XT, and pixel_aot_region_body_warp passed on in-box WARP, at merged main.

ctest --preset dev --no-tests=error -R '^pixel_aot_region_body_(hardware|warp)$'
  • Commit: 44c7a7b, clean tree, dev preset (Debug)
  • Adapter: AMD Radeon RX 9060 XT (vendor=1002 device=7590), driver 32.0.32029.2010
  • WARP: Microsoft Basic Render Driver (1414:008c), in-box, driver 10.0.26100.10068
  • Windows build: 26300.10075, D3D12 debug layer unavailable
  • DXC 1.9.2602.17 (21d28f727) from Windows SDK 10.0.26100.0

Two runs on hardware (one alone, one in the full _hardware set), one on WARP, 0 capability skips. CTest verdict only; the test prints no per-case lines on success.

AI-assisted (Claude Code - Fable 5.2); runs executed locally on the adapter above.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7115130491 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/976#issuecomment-7115130491). Originally posted by [lantiumBot](https://github.com/lantiumBot) on 2026-11-23T21:56:59Z. --- First `_hardware` result for this draw on RDNA 4. Data only. `pixel_aot_region_body_hardware` passed on an AMD Radeon RX 9060 XT, and `pixel_aot_region_body_warp` passed on in-box WARP, at merged `main`. ```powershell ctest --preset dev --no-tests=error -R '^pixel_aot_region_body_(hardware|warp)$' ``` - Commit: `44c7a7b`, clean tree, `dev` preset (Debug) - Adapter: AMD Radeon RX 9060 XT (vendor=1002 device=7590), driver 32.0.32029.2010 - WARP: Microsoft Basic Render Driver (1414:008c), in-box, driver 10.0.26100.10068 - Windows build: 26300.10075, D3D12 debug layer unavailable - DXC 1.9.2602.17 (21d28f727) from Windows SDK 10.0.26100.0 Two runs on hardware (one alone, one in the full `_hardware` set), one on WARP, 0 capability skips. CTest verdict only; the test prints no per-case lines on success. AI-assisted (Claude Code - Fable 5.2); runs executed locally on the adapter above.
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!969
No description provided.