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

Merged
mumba17 merged 2 commits from upstream-pr/3708 into main 2026-12-02 02:13:10 +00:00
mumba17 commented 2026-12-01 07:56:02 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by mumba17 on 2026-12-01T07:56:02Z.


Refs #3641, #3703, #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 #3706, 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

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5581466038 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3708). Originally posted by [mumba17](https://github.com/mumba17) on 2026-12-01T07:56:02Z. --- Refs #3641, #3703, #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 #3706, 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)
lukaslw-lab commented 2026-12-01 08:07:19 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-12-01T08:07:19Z.

Review: APPROVED


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 (#3702, #3704, #3705, #3707): 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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6127233913 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3708#pullrequestreview-6127233913). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-12-01T08:07:19Z. **Review:** APPROVED --- 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 (#3702, #3704, #3705, #3707): 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.
mumba17 commented 2026-12-01 08:33:21 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by mumba17 on 2026-12-01T08:33:21Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7305472845 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3708#issuecomment-7305472845). Originally posted by [mumba17](https://github.com/mumba17) on 2026-12-01T08:33:21Z. --- 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.
lukaslw-lab commented 2026-12-01 18:02:31 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-12-01T18:02:31Z.

Review: APPROVED


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6137042086 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3708#pullrequestreview-6137042086). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-12-01T18:02:31Z. **Review:** APPROVED --- 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.
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!3708
No description provided.