shader: lower s_not_b32, s_brev_b32 and s_bfe_i32 in the mesh frontend #3710

Manually merged
github merged 2 commits from github-bot/gh-3708 into main 2026-12-02 02:13:31 +00:00 AGit
Owner

@⁠mumba17 on GitHub · 2026-12-01 07:56 UTC · original
mumba17:shader/mesh-salu-not-bfe-brev → main · +41 −1 · 2 files · 2 commits · merged 2026-12-02 02:13 UTC

Refs #3643, #3705, #2413.

Problem

The C++ mesh frontend (lower_mesh, src/gfx1013_direct_mesh.inl) refuses s_not_b32, s_brev_b32 and s_bfe_i32 with unsupported mesh instruction or EXEC state. The shared scalar ALU (DirectCompute::arithmetic) already lowers all three. On a native Mesh86 capture they are among the most common first refusals.

Change

All three join s_bfe_u32 and s_min_u32 on the existing branch that hands scalar ops to the shared ALU. The EXEC and VCC destination refusals in that branch apply unchanged. SCC follows the shared lowering: s_not_b32 and s_bfe_i32 set it from the result, and s_brev_b32 leaves it alone.

Census

Capture. A native Mesh86 run on main 1c634037: run_preset.py --console x --gpu nvidia --set translate=false, with X2W_REFUSE_FIXED_MESH=1 and X2W_NATIVE_MESH86=1, 600 s from a saved profile. It recorded 2,873 .m86 requests, 1,569 of them distinct by content.

Translation. Each distinct request went through compile_dxil <dxc> <cache> gfx1013-container-ms-texture-heap req_<key>.m86 <out>.cso. These are counts only; request bytes stay local.

Translate fully Refused
main (built with #3708, which changes none of these counts) 267 1,302
this PR 389 1,180

First refusals that this PR changes:

First refusal before after
s_not_b32 286 0
s_bfe_i32 198 0
s_brev_b32 71 0
v_rcp_iflag_f32 85 371
v_cmpx_ne_u32 83 143
graphics register undefined on an incoming path 37 79
v_ashrrev_i32 16 50

Most of the 555 programs freed here now stop at v_rcp_iflag_f32. That is the next wall, and I'll take it as a separate PR.

Tests

tests/native_direct_mesh_check.py, on s20 = s_movk_i32 0xfffe (-2), with the result reaching the exported X position through v_and_b32:

  • Positives.
    • scalar-not: xor i32 -2, -1.
    • scalar-brev: dx.op.unary.i32(30, -2).
    • scalar-bfe-i32: an ashr of -2 followed by the shl/ashr sign extension, with no lshr of -2.
  • Refusals.
    • scalar-not-exec: s_not_b32 exec_lo.
    • scalar-brev-vcc: s_brev_b32 vcc_lo.
    • scalar-not-vcc-hi: s_not_b32 vcc_hi.
  • Mutation. With the source change reverted, native_direct_mesh fails at scalar-not with unsupported mesh instruction or EXEC state: s_not_b32.
  • Regression. ctest -R "native_|mesh|gfx1013" -E "hardware|_warp": 786/788 pass. The two failures, native_compute_implicit_lod_controls and native_wave_virtual_derivative_controls, are local only. The SDK 10.0.26100 validator here supports DXIL 1.7, and both tests emit 1.8 metadata. Neither touches the mesh frontend.

Environment: Windows 11 build 26300, RTX 3090, MSVC 14.44, DXC from SDK 10.0.26100.

AI-assisted.

🤖 Generated with Claude Code

**@⁠mumba17** on GitHub · 2026-12-01 07:56 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3708) `mumba17:shader/mesh-salu-not-bfe-brev` → `main` · +41 −1 · 2 files · 2 commits · merged 2026-12-02 02:13 UTC Refs #3643, #3705, #2413. ## Problem The C++ mesh frontend (`lower_mesh`, `src/gfx1013_direct_mesh.inl`) refuses `s_not_b32`, `s_brev_b32` and `s_bfe_i32` with `unsupported mesh instruction or EXEC state`. The shared scalar ALU (`DirectCompute::arithmetic`) already lowers all three. On a native Mesh86 capture they are among the most common first refusals. ## Change All three join `s_bfe_u32` and `s_min_u32` on the existing branch that hands scalar ops to the shared ALU. The EXEC and VCC destination refusals in that branch apply unchanged. SCC follows the shared lowering: `s_not_b32` and `s_bfe_i32` set it from the result, and `s_brev_b32` leaves it alone. ## Census **Capture.** A native Mesh86 run on `main` `1c634037`: `run_preset.py --console x --gpu nvidia --set translate=false`, with `X2W_REFUSE_FIXED_MESH=1` and `X2W_NATIVE_MESH86=1`, 600 s from a saved profile. It recorded 2,873 `.m86` requests, 1,569 of them distinct by content. **Translation.** Each distinct request went through `compile_dxil <dxc> <cache> gfx1013-container-ms-texture-heap req_<key>.m86 <out>.cso`. These are counts only; request bytes stay local. | | Translate fully | Refused | |---|---:|---:| | `main` (built with #3708, which changes none of these counts) | 267 | 1,302 | | this PR | **389** | 1,180 | First refusals that this PR changes: | First refusal | before | after | |---|---:|---:| | `s_not_b32` | 286 | 0 | | `s_bfe_i32` | 198 | 0 | | `s_brev_b32` | 71 | 0 | | `v_rcp_iflag_f32` | 85 | 371 | | `v_cmpx_ne_u32` | 83 | 143 | | `graphics register undefined on an incoming path` | 37 | 79 | | `v_ashrrev_i32` | 16 | 50 | Most of the 555 programs freed here now stop at `v_rcp_iflag_f32`. That is the next wall, and I'll take it as a separate PR. ## Tests `tests/native_direct_mesh_check.py`, on `s20 = s_movk_i32 0xfffe` (-2), with the result reaching the exported X position through `v_and_b32`: - **Positives.** - `scalar-not`: `xor i32 -2, -1`. - `scalar-brev`: `dx.op.unary.i32(30, -2)`. - `scalar-bfe-i32`: an `ashr` of -2 followed by the shl/ashr sign extension, with no `lshr` of -2. - **Refusals.** - `scalar-not-exec`: `s_not_b32 exec_lo`. - `scalar-brev-vcc`: `s_brev_b32 vcc_lo`. - `scalar-not-vcc-hi`: `s_not_b32 vcc_hi`. - **Mutation.** With the source change reverted, `native_direct_mesh` fails at `scalar-not` with `unsupported mesh instruction or EXEC state: s_not_b32`. - **Regression.** `ctest -R "native_|mesh|gfx1013" -E "hardware|_warp"`: 786/788 pass. The two failures, `native_compute_implicit_lod_controls` and `native_wave_virtual_derivative_controls`, are local only. The SDK 10.0.26100 validator here supports DXIL 1.7, and both tests emit 1.8 metadata. Neither touches the mesh frontend. Environment: Windows 11 build 26300, RTX 3090, MSVC 14.44, DXC from SDK 10.0.26100. AI-assisted. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The shared scalar ALU already lowers all three, SCC included. The mesh
frontend refused them with "unsupported mesh instruction or EXEC state".
They now join s_bfe_u32 and s_min_u32 on the shared path, with the same
EXEC and VCC destination refusals.

On a native Mesh86 capture (1,569 distinct slot 86 programs), these were
the first refusal for 555 of them, and 122 more now translate fully.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 07:59:57 +00:00
Author
Owner

@⁠lukaslw-lab on GitHub · 2026-12-01 08:07 UTC · original · approved these changes

Reviewed 9886eb8e by reading the diff; not built or run.

Verdict: approve. The three ops join the branch that already hands s_bfe_u32 and s_min_u32 to the shared scalar ALU, which lowers all three, and the EXEC and VCC destination refusals apply. No MUST.

  • SHOULD No case observes SCC, which is where the three ops differ. The shared ALU lists s_brev_b32 as SCC-preserving (gfx1013_direct_compute.inl:3808), and its lowering at :5425 does not write SCC. s_not_b32 and s_bfe_i32 are SCC writers (:3782, :3791, lowered at :5772 and :5697). Two cases would pin the behaviour the PR body states:
    • an s_cmp before s_brev_b32, then an s_cselect_b32 after it;
    • an s_cbranch_scc0 after s_not_b32.
  • Checked, no finding:
    • The test words decode as named: SOP1 op 7 / 11 into s21, and SOP2 op 40 with the literal 0x80004 (8 bits from bit 4).
    • The refusal cases target exec_lo, vcc_lo and vcc_hi as their names say.
    • The scalar-bfe-i32 pattern requires the ashr and the shl/ashr sign extension and rejects an lshr of -2, so it separates the signed form from s_bfe_u32.
    • No conflict with the open mesh-frontend PRs I could check (#3704, #3706, #3707, #3709): each merges cleanly with this head.

Tests: scalar-not, scalar-brev and scalar-bfe-i32 prove each op reaches the exported X through v_and_b32. The three refusals pin the destination checks. CI ran native_direct_mesh in the pr preset and passed at this head.

**@⁠lukaslw-lab** on GitHub · 2026-12-01 08:07 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3708#pullrequestreview-6127233913) · **approved these changes** Reviewed `9886eb8e` by reading the diff; not built or run. **Verdict: approve.** The three ops join the branch that already hands `s_bfe_u32` and `s_min_u32` to the shared scalar ALU, which lowers all three, and the EXEC and VCC destination refusals apply. No MUST. - **SHOULD** No case observes SCC, which is where the three ops differ. The shared ALU lists `s_brev_b32` as SCC-preserving (`gfx1013_direct_compute.inl:3808`), and its lowering at `:5425` does not write SCC. `s_not_b32` and `s_bfe_i32` are SCC writers (`:3782`, `:3791`, lowered at `:5772` and `:5697`). Two cases would pin the behaviour the PR body states: - an `s_cmp` before `s_brev_b32`, then an `s_cselect_b32` after it; - an `s_cbranch_scc0` after `s_not_b32`. - Checked, no finding: - The test words decode as named: SOP1 op 7 / 11 into s21, and SOP2 op 40 with the literal `0x80004` (8 bits from bit 4). - The refusal cases target `exec_lo`, `vcc_lo` and `vcc_hi` as their names say. - The `scalar-bfe-i32` pattern requires the `ashr` and the shl/ashr sign extension and rejects an `lshr` of -2, so it separates the signed form from `s_bfe_u32`. - No conflict with the open mesh-frontend PRs I could check (#3704, #3706, #3707, #3709): each merges cleanly with this head. Tests: `scalar-not`, `scalar-brev` and `scalar-bfe-i32` prove each op reaches the exported X through `v_and_b32`. The three refusals pin the destination checks. CI ran `native_direct_mesh` in the `pr` preset and passed at this head.
Review follow-up on #3708. After s_cmp_eq_u32 s20, 0, an s_cselect_b32
behind s_brev_b32 still selects on the compare's SCC, and behind s_not_b32
on (result != 0). Both selects reach the exported X.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Owner

@⁠mumba17 on GitHub · 2026-12-01 08:33 UTC · original

Thanks @⁠lukaslw-lab. SHOULD addressed in a6602c75, with the two cases you suggested. Both start from s_movk_i32 s20, 0xfffe and s_cmp_eq_u32 s20, 0, run the op, then s_cselect_b32 s21, 1, 0, and s21 reaches the exported X:

  • scalar-brev-keeps-scc (s_brev_b32 s22, s20): the select tests the compare's own icmp eq i32 -2, 0, so SCC passes through unchanged.
  • scalar-not-sets-scc (s_not_b32 s22, s20): the select tests icmp ne (xor -2, -1), 0, so SCC comes from the result.

AI-assisted.

**@⁠mumba17** on GitHub · 2026-12-01 08:33 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3708#issuecomment-7305472845) Thanks @⁠lukaslw-lab. SHOULD addressed in `a6602c75`, with the two cases you suggested. Both start from `s_movk_i32 s20, 0xfffe` and `s_cmp_eq_u32 s20, 0`, run the op, then `s_cselect_b32 s21, 1, 0`, and `s21` reaches the exported X: - **`scalar-brev-keeps-scc`** (`s_brev_b32 s22, s20`): the `select` tests the compare's own `icmp eq i32 -2, 0`, so SCC passes through unchanged. - **`scalar-not-sets-scc`** (`s_not_b32 s22, s20`): the `select` tests `icmp ne (xor -2, -1), 0`, so SCC comes from the result. AI-assisted.
Author
Owner

@⁠lukaslw-lab on GitHub · 2026-12-01 18:02 UTC · original · approved these changes

Reviewed a6602c75 by reading the diff; not built or run.

Verdict: approve. a6602c75 closes the SCC point from our earlier review. No MUST, no open points.

  • Encodings checked: 0xbf068014 = s_cmp_eq_u32 s20, 0 (SOPC op 6), 0x85158081 = s_cselect_b32 s21, 1, 0 (SOP2 op 10), 0xbe960b14 / 0xbe960714 = s_brev_b32 / s_not_b32 s22, s20 (SOP1 op 11 / 7).
  • scalar-brev-keeps-scc requires the select to test the zext of the compare's own icmp eq i32 -2, 0, so a brev that rewrote SCC would fail it. scalar-not-sets-scc requires the test to come from icmp ne (xor -2, -1), 0, so a not that kept the compare's SCC would fail it. Both tie the pick to the exported X through assert_position_x.

Tests: the two new cases reach the SCC handling of the shared scalar ALU through the gfx1013_direct_mesh.inl:1830 branch. native_direct_mesh is in the pr preset filter, and CI ran it green at this head.

**@⁠lukaslw-lab** on GitHub · 2026-12-01 18:02 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3708#pullrequestreview-6137042086) · **approved these changes** Reviewed `a6602c75` by reading the diff; not built or run. **Verdict: approve.** `a6602c75` closes the SCC point from our earlier review. No MUST, no open points. - Encodings checked: `0xbf068014` = `s_cmp_eq_u32 s20, 0` (SOPC op 6), `0x85158081` = `s_cselect_b32 s21, 1, 0` (SOP2 op 10), `0xbe960b14` / `0xbe960714` = `s_brev_b32` / `s_not_b32 s22, s20` (SOP1 op 11 / 7). - `scalar-brev-keeps-scc` requires the select to test the zext of the compare's own `icmp eq i32 -2, 0`, so a brev that rewrote SCC would fail it. `scalar-not-sets-scc` requires the test to come from `icmp ne (xor -2, -1), 0`, so a not that kept the compare's SCC would fail it. Both tie the pick to the exported X through `assert_position_x`. Tests: the two new cases reach the SCC handling of the shared scalar ALU through the `gfx1013_direct_mesh.inl:1830` branch. `native_direct_mesh` is in the `pr` preset filter, and CI ran it green at this head.
github manually merged commit 251fe2bd1f into main 2026-12-02 02:13:31 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.