shader: admit per-lane binary32 VALU forms in pixel_aot masked-region bodies #975

Closed
opened 2026-11-26 22:32:21 +00:00 by github-bot · 1 comment
Owner

@⁠MasterDomino on GitHub · 2026-11-23 19:24 UTC · original

Problem

After #957, the masked region in tools/pixel_aot.py opens with s_and_saveexec_b64 or with the s_mov_b64 exec save plus VOPC _e32 v_cmpx. Its body (REGION_ALU) still admits only v_mov_b32 and binary32 add/sub/subrev/mul/min/max, and that is what blocks almost every real region.

I proposed this as a next stage in #932 before that issue closed. This is the same proposal as its own task.

Measured on one local input (the 12,101 PS records from #932; aggregates only). It counts the regions #957 accepts structurally: save + f32/i32/u32 _e32 v_cmpx + restore of the same pair. That is 10,827 regions in 3,719 records. Regions that contain a further branch are left out, since nesting is a separate stage.

Body rule Regions accepted Records with ≥1
current REGION_ALU 152 112
+ the forms below 3,151 1,529 (12.6%)

A record also needs everything outside its regions to translate, so these count regions, not translatable shaders.

Proposal

Admit to the region body, under both openers, 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

That is 14 forms. Each lowers exactly as outside a region. The only translator change is the REGION_ALU pattern, so the existing per-instruction check still refuses any body instruction that changes more than VGPRs.

The restore-time select discards a false lane's speculated value, including an out-of-domain infinity or NaN from rcp/rsq/sqrt. The accumulator forms read their destination, so a destination still conditional from an earlier region rejects, as reads already do.

Other encodings, other operations and scalar instructions stay refused.

Alternatives

  • Admit scalar instructions (s_mov_b32, s_waitcnt, scalar loads), the next most common blockers. They run regardless of EXEC but are skipped with the region by s_cbranch_execz, so they need their own definition. That's a later stage.
  • Admit every VALU form lower() supports. That is broader than measured need, and each form would need its own speculation argument.

Verification

I have an implementation ready, and will link it here as a PR.

  • Translation controls. Every form under both openers, with exactly one merge of the rewritten register; twelve other forms and encodings refused; the conditional accumulator read refused; a chained region.

  • Binary. An LLVM 15 gfx1013 round trip of each program.

  • Draws (pixel_aot_region_body_warp/_hardware). One program per form rewrites a channel inside a v_cmpx region on mixed, full and empty masks, with exact inner values. rcp/rsqrt/sqrt results are rounded after the region with +0.5 and floor. A reference that applies the body to every lane must mismatch.

  • I checked for an existing issue or pull request for this change.

  • I did not include game files, dumps, distribution links or credentials.

AI-assisted.

**@⁠MasterDomino** on GitHub · 2026-11-23 19:24 UTC · [original](https://github.com/R0Y00/Xbox2Windows/issues/975) ### Problem After #957, the masked region in `tools/pixel_aot.py` opens with `s_and_saveexec_b64` or with the `s_mov_b64` exec save plus VOPC `_e32` `v_cmpx`. Its body (`REGION_ALU`) still admits only `v_mov_b32` and binary32 `add`/`sub`/`subrev`/`mul`/`min`/`max`, and that is what blocks almost every real region. I proposed this as a next stage in [#932](https://git.gtahub.st/github/R0Y00--Xbox2Windows/issues/932) before that issue closed. This is the same proposal as its own task. **Measured on one local input** (the 12,101 PS records from #932; aggregates only). It counts the regions #957 accepts structurally: save + f32/i32/u32 `_e32` `v_cmpx` + restore of the same pair. That is 10,827 regions in 3,719 records. Regions that contain a further branch are left out, since nesting is a separate stage. | Body rule | Regions accepted | Records with ≥1 | |---|---|---| | current `REGION_ALU` | 152 | 112 | | + the forms below | **3,151** | **1,529 (12.6%)** | A record also needs everything outside its regions to translate, so these count regions, not translatable shaders. ### Proposal Admit to the region body, under both openers, 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` That is 14 forms. Each lowers exactly as outside a region. The only translator change is the `REGION_ALU` pattern, so the existing per-instruction check still refuses any body instruction that changes more than VGPRs. The restore-time select discards a false lane's speculated value, including an out-of-domain infinity or NaN from `rcp`/`rsq`/`sqrt`. The accumulator forms read their destination, so a destination still conditional from an earlier region rejects, as reads already do. Other encodings, other operations and scalar instructions stay refused. ### Alternatives - **Admit scalar instructions** (`s_mov_b32`, `s_waitcnt`, scalar loads), the next most common blockers. They run regardless of EXEC but are skipped with the region by `s_cbranch_execz`, so they need their own definition. That's a later stage. - **Admit every VALU form `lower()` supports.** That is broader than measured need, and each form would need its own speculation argument. ### Verification I have an implementation ready, and will link it here as a PR. - **Translation controls.** Every form under both openers, with exactly one merge of the rewritten register; twelve other forms and encodings refused; the conditional accumulator read refused; a chained region. - **Binary.** An LLVM 15 gfx1013 round trip of each program. - **Draws** (`pixel_aot_region_body_warp`/`_hardware`). One program per form rewrites a channel inside a `v_cmpx` region on mixed, full and empty masks, with exact inner values. `rcp`/`rsqrt`/`sqrt` results are rounded after the region with +0.5 and floor. A reference that applies the body to every lane must mismatch. - [x] I checked for an existing issue or pull request for this change. - [x] I did not include game files, dumps, distribution links or credentials. AI-assisted.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 22:32:21 +00:00
Author
Owner

@⁠MasterDomino on GitHub · 2026-11-23 19:25 UTC · original

Implementation: #976. The translation controls and LLVM 15 round trip pass locally, and all 14 draw shaders compile with DXC; the WARP draws run first in the PR's CI.

AI-assisted.

**@⁠MasterDomino** on GitHub · 2026-11-23 19:25 UTC · [original](https://github.com/R0Y00/Xbox2Windows/issues/975#issuecomment-7111584885) Implementation: https://git.gtahub.st/github/R0Y00--Xbox2Windows/pulls/976. The translation controls and LLVM 15 round trip pass locally, and all 14 draw shaders compile with DXC; the WARP draws run first in the PR's CI. AI-assisted.
This discussion has been locked. Commenting is limited to contributors.
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.

Dependencies

No dependencies set

Reference
github/R0Y00--Xbox2Windows#975
No description provided.