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

Closed
opened 2026-11-23 19:24:15 +00:00 by MasterDomino · 1 comment
MasterDomino commented 2026-11-23 19:24:15 +00:00 (Migrated from github.com)
Contributor

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


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6567070530 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/975). Originally posted by [MasterDomino](https://github.com/MasterDomino) on 2026-11-23T19:24:15Z. --- ### 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://github.com/R0Y00/Xbox2Windows/issues/932#issuecomment-7110745431) 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.
MasterDomino commented 2026-11-24 06:49:32 +00:00 (Migrated from github.com)
Author
Contributor

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


Implementation: https://github.com/R0Y00/Xbox2Windows/pull/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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7111584885 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/975#issuecomment-7111584885). Originally posted by [MasterDomino](https://github.com/MasterDomino) on 2026-11-23T19:25:30Z. --- Implementation: https://github.com/R0Y00/Xbox2Windows/pull/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.
Sign in to join this conversation.
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#968
No description provided.