shader: lower s_xor_b32 in the mesh frontend, with s_movk_i32/s_xor_b32 tests (Part of #2413) #3637

Manually merged
github merged 3 commits from github-bot/gh-3635 into main 2026-12-01 00:12:37 +00:00 AGit
Owner

@⁠mumba17 on GitHub · 2026-11-30 18:53 UTC · original
mumba17:shader/mesh-movk-xor → main · +17 −2 · 2 files · 3 commits · merged 2026-12-01 00:12 UTC

Part of #2413.

The C++ mesh frontend (src/gfx1013_direct_mesh.inl) refused s_xor_b32 as unsupported mesh instruction or EXEC state. It was the first refusal for 41 of the 454 cached slot 57 requests in my local census.

#3640 landed s_movk_i32 for SGPR destinations while this PR was open. I merged main and kept that implementation. This PR now adds s_xor_b32 and tests for both instructions.

Change

  • s_xor_b32 joins the existing SOP2 bitwise branch next to s_or_b32 and s_and_b32. It lowers to xor i32, with SCC = (result != 0). A destination of 106 or above is still refused, because that branch only takes SGPR destinations.

Tests

In tests/native_direct_mesh_check.py, next to the scalar EXEC/VCC write checks:

  • scalar-movk-xor: s_movk_i32 s20, 0xfffe, then s_xor_b32 s21, s20, -1, feeds v_and_b32 v1, s21, v0 and the exported X position. The test asserts xor i32 -2, -1 (so the s_movk_i32 immediate is sign-extended) and that the and reaching the position export uses that result.
  • Negative controls: s_movk_i32 to VCC, EXEC and M0, and s_xor_b32 to EXEC and VCC. Each one must be refused at +0x14 with its exact reason.

Mutation checks on the merged branch, each caught by native_direct_mesh:

  • lowering s_xor_b32 as or;
  • dropping s_xor_b32 from the SOP2 branch;
  • zero-extending the s_movk_i32 immediate in the shared scalar ALU (gfx1013_direct_compute.inl).

Verification

  • On the merge with main a0e126c2, ctest --preset release -R "mesh|compile_dxil" -j 4: 202 passed (the two mesh_two_exits cases skip, as on main).
  • compile_dxil --refusals over the 454 cached slot 57 requests (layout from #3418): no s_xor_b32 or s_movk_i32 refusal is left.

🤖 Generated with Claude Code

**@⁠mumba17** on GitHub · 2026-11-30 18:53 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3635) `mumba17:shader/mesh-movk-xor` → `main` · +17 −2 · 2 files · 3 commits · merged 2026-12-01 00:12 UTC Part of #2413. The C++ mesh frontend (`src/gfx1013_direct_mesh.inl`) refused `s_xor_b32` as `unsupported mesh instruction or EXEC state`. It was the first refusal for 41 of the 454 cached slot 57 requests in my local census. #3640 landed `s_movk_i32` for SGPR destinations while this PR was open. I merged main and kept that implementation. This PR now adds `s_xor_b32` and tests for both instructions. ## Change - `s_xor_b32` joins the existing SOP2 bitwise branch next to `s_or_b32` and `s_and_b32`. It lowers to `xor i32`, with SCC = (result != 0). A destination of 106 or above is still refused, because that branch only takes SGPR destinations. ## Tests In `tests/native_direct_mesh_check.py`, next to the scalar EXEC/VCC write checks: - `scalar-movk-xor`: `s_movk_i32 s20, 0xfffe`, then `s_xor_b32 s21, s20, -1`, feeds `v_and_b32 v1, s21, v0` and the exported X position. The test asserts `xor i32 -2, -1` (so the `s_movk_i32` immediate is sign-extended) and that the `and` reaching the position export uses that result. - Negative controls: `s_movk_i32` to VCC, EXEC and M0, and `s_xor_b32` to EXEC and VCC. Each one must be refused at `+0x14` with its exact reason. Mutation checks on the merged branch, each caught by `native_direct_mesh`: - lowering `s_xor_b32` as `or`; - dropping `s_xor_b32` from the SOP2 branch; - zero-extending the `s_movk_i32` immediate in the shared scalar ALU (`gfx1013_direct_compute.inl`). ## Verification - On the merge with main `a0e126c2`, `ctest --preset release -R "mesh|compile_dxil" -j 4`: 202 passed (the two `mesh_two_exits` cases skip, as on main). - `compile_dxil --refusals` over the 454 cached slot 57 requests (layout from #3418): no `s_xor_b32` or `s_movk_i32` refusal is left. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
s_movk_i32 writes the sign-extended 16-bit immediate as a known constant;
VCC, EXEC and other special destinations stay refused. s_xor_b32 joins the
SGPR-destination SOP2 bitwise branch. Source-built tests cover both, plus
VCC/EXEC/M0 destination controls.

Part of #2413.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 18:58:49 +00:00
Author
Owner

@⁠lukaslw-lab on GitHub · 2026-11-30 19:09 UTC · original · approved these changes

Reviewed 9d21285b by reading the diff; not built or run. I also disassembled our own cache of slot 57 programs to see which forms of these two instructions real code uses.

Verdict: approve. Both lowerings match the scalar analysis they sit next to, and neither can create heap or mask provenance. No MUST, no SHOULD.

  • s_movk_i32 writes the same sign-extended i.a constant as transfer() (gfx1013_compute_native.cpp:891-892) and leaves the mesh SCC alone, as the ISA does. Overwriting an SGPR that held a saved EXEC mask turns it into a constant, so a later restore from it stays refused. Inside a per-lane skip, the write goes through alu.write, so the skip-end invalidation covers it.

  • s_xor_b32: transfer() has no case for it, so the destination symbol becomes unknown (:908-910). root_values only extends on s_and_b32 and s_lshl_b32, so an xor result can never pass as a masked root-constant heap slot. The value and SCC use the existing or/and code.

  • Checked against real programs: 310 cached slot 57 programs from our runs, disassembled:

    Instruction Programs Destinations
    s_movk_i32 61 213 SGPR, 1 vcc_lo, none M0
    s_xor_b32 46 SGPR only

    The one vcc_lo write (a34e610e +0x2ef0) comes after v_writelane_b32 spills VCC to v127. The compiler then uses vcc_lo/vcc_hi as words 2–3 of a buffer descriptor. Keeping that refused, as this PR does, matches the frontend's other VCC writes. It needs VCC-as-SGPR support, which is separate work.

Tests: scalar-movk-xor proves the sign extension (xor i32 -2, -1) and that the result reaches the position export. The five negative controls pin each destination refusal. CI did not run native_direct_mesh (not in the pr filter); the author ran it locally (192 passed).

**@⁠lukaslw-lab** on GitHub · 2026-11-30 19:09 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3635#pullrequestreview-6118730307) · **approved these changes** Reviewed `9d21285b` by reading the diff; not built or run. I also disassembled our own cache of slot 57 programs to see which forms of these two instructions real code uses. **Verdict: approve.** Both lowerings match the scalar analysis they sit next to, and neither can create heap or mask provenance. No MUST, no SHOULD. - **`s_movk_i32`** writes the same sign-extended `i.a` constant as `transfer()` (`gfx1013_compute_native.cpp:891-892`) and leaves the mesh SCC alone, as the ISA does. Overwriting an SGPR that held a saved EXEC mask turns it into a constant, so a later restore from it stays refused. Inside a per-lane skip, the write goes through `alu.write`, so the skip-end invalidation covers it. - **`s_xor_b32`**: `transfer()` has no case for it, so the destination symbol becomes unknown (`:908-910`). `root_values` only extends on `s_and_b32` and `s_lshl_b32`, so an xor result can never pass as a masked root-constant heap slot. The value and SCC use the existing `or`/`and` code. - **Checked against real programs**: 310 cached slot 57 programs from our runs, disassembled: | Instruction | Programs | Destinations | |---|---|---| | `s_movk_i32` | 61 | 213 SGPR, 1 `vcc_lo`, none M0 | | `s_xor_b32` | 46 | SGPR only | The one `vcc_lo` write (a34e610e +0x2ef0) comes after `v_writelane_b32` spills VCC to `v127`. The compiler then uses `vcc_lo`/`vcc_hi` as words 2–3 of a buffer descriptor. Keeping that refused, as this PR does, matches the frontend's other VCC writes. It needs VCC-as-SGPR support, which is separate work. Tests: `scalar-movk-xor` proves the sign extension (`xor i32 -2, -1`) and that the result reaches the position export. The five negative controls pin each destination refusal. CI did not run `native_direct_mesh` (not in the `pr` filter); the author ran it locally (192 passed).
github-bot changed title from shader: lower s_movk_i32 and s_xor_b32 in the mesh frontend (Part of #2413) to shader: lower s_xor_b32 in the mesh frontend, with s_movk_i32/s_xor_b32 tests (Part of #2413) 2026-11-30 19:29:22 +00:00
#3638 added s_movk_i32 for SGPR destinations. Keep that implementation
and drop this branch's copy. The tests now expect the generic refusal
for VCC, EXEC and M0 destinations.

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

@⁠R0Y00 on GitHub · 2026-11-30 19:40 UTC · original · reviewed

Windows passed on this head. The failing Linux job is tests/startup_close_guard_check.py: the Close fixture extracts the trace added by #3640 and its fake state has no trace recording field. I reproduced the failure separately from the mesh lowering and opened #3644 with the narrow fix. Please rerun the Linux check against a base containing that fix before merging this PR.

**@⁠R0Y00** on GitHub · 2026-11-30 19:40 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3635#pullrequestreview-6119248144) · **reviewed** Windows passed on this head. The failing Linux job is `tests/startup_close_guard_check.py`: the Close fixture extracts the trace added by #3640 and its fake state has no trace recording field. I reproduced the failure separately from the mesh lowering and opened #3644 with the narrow fix. Please rerun the Linux check against a base containing that fix before merging this PR.
Author
Owner

@⁠mumba17 on GitHub · 2026-11-30 19:59 UTC · original

Thanks for the review and the real-program table. While this was open, #3640 landed its own s_movk_i32 handler (SGPR destinations, through the shared scalar ALU). I merged main and kept that one, so the s_movk_i32 code you reviewed is gone. This PR is now s_xor_b32 plus tests for both.

Two test changes came with it:

  • The VCC, EXEC and M0 controls for s_movk_i32 now expect the generic unsupported mesh instruction or EXEC state: s_movk_i32.
  • scalar-movk-xor still checks the sign extension, now against #3640's lowering.

I re-ran the mutation checks on the merged head e5c65430. Each one fails native_direct_mesh:

  • xor lowered as or;
  • s_xor_b32 dropped;
  • zero-extending the s_movk_i32 immediate.

The mesh suite passes, 202/202. The vcc_lo case stays refused, as you said.

**@⁠mumba17** on GitHub · 2026-11-30 19:59 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3635#issuecomment-7290233384) Thanks for the review and the real-program table. While this was open, #3640 landed its own `s_movk_i32` handler (SGPR destinations, through the shared scalar ALU). I merged main and kept that one, so the `s_movk_i32` code you reviewed is gone. This PR is now `s_xor_b32` plus tests for both. Two test changes came with it: - The VCC, EXEC and M0 controls for `s_movk_i32` now expect the generic `unsupported mesh instruction or EXEC state: s_movk_i32`. - `scalar-movk-xor` still checks the sign extension, now against #3640's lowering. I re-ran the mutation checks on the merged head `e5c65430`. Each one fails `native_direct_mesh`: - `xor` lowered as `or`; - `s_xor_b32` dropped; - zero-extending the `s_movk_i32` immediate. The mesh suite passes, 202/202. The `vcc_lo` case stays refused, as you said.
Author
Owner

@⁠lukaslw-lab on GitHub · 2026-11-30 20:05 UTC · original · approved these changes

Re-reviewed a671a700 by reading the diff; not built or run. Main has been merged twice since my last review. The PR now keeps #3640's s_movk_i32 and adds s_xor_b32 plus tests. Its own lines are the same as at e5c65430.

Verdict: approve. No MUST, no SHOULD.

  • Checked, no finding:
    • s_xor_b32 joins the SOP2 bitwise branch (src/gfx1013_direct_mesh.inl:1517-1528). It uses the same known() guard, the same unknown-destination fallback and SCC = result ≠ 0 as s_or_b32/s_and_b32.
    • root_values is not propagated through xor, so a masked root constant loses its provenance there. That is the conservative choice, and an xor'd heap slot stays refused.
    • transfer() has no s_xor_b32 case, so the symbolic state is the same as for s_or_b32.
    • #3640's s_movk_i32 handler (:1504) takes only dst < 106. VCC/EXEC/M0 destinations fall through to the generic refusal, which matches the updated test reasons. A VCC destination, as at a34e610e +0x2ef0 in my earlier census, stays refused.
    • Test encodings: SOPK 0xb014fffe = s_movk_i32 s20, 0xfffe; SOP2 op 18 0x8915c114 = s_xor_b32 s21, s20, -1; VOP2 0x36020015 = v_and_b32 v1, s21, v0. The negative words differ only in sdst (0x6a/0x7e/0x7c), inserted at +0x14.

Tests: scalar-movk-xor proves sign extension (xor i32 -2, -1) and that the xor result reaches the position export. The five refusals pin both opcodes' non-SGPR destinations. native_direct_mesh is not in the Windows pr preset filter, so CI does not run it. The author ran it locally on the merge with a0e126c2.

**@⁠lukaslw-lab** on GitHub · 2026-11-30 20:05 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3635#pullrequestreview-6119632793) · **approved these changes** Re-reviewed `a671a700` by reading the diff; not built or run. Main has been merged twice since my last review. The PR now keeps #3640's `s_movk_i32` and adds `s_xor_b32` plus tests. Its own lines are the same as at `e5c65430`. **Verdict: approve.** No MUST, no SHOULD. - Checked, no finding: - `s_xor_b32` joins the SOP2 bitwise branch (`src/gfx1013_direct_mesh.inl:1517-1528`). It uses the same `known()` guard, the same unknown-destination fallback and SCC = result ≠ 0 as `s_or_b32`/`s_and_b32`. - `root_values` is not propagated through xor, so a masked root constant loses its provenance there. That is the conservative choice, and an xor'd heap slot stays refused. - `transfer()` has no `s_xor_b32` case, so the symbolic state is the same as for `s_or_b32`. - #3640's `s_movk_i32` handler (`:1504`) takes only `dst < 106`. VCC/EXEC/M0 destinations fall through to the generic refusal, which matches the updated test reasons. A VCC destination, as at `a34e610e` +0x2ef0 in my earlier census, stays refused. - Test encodings: SOPK `0xb014fffe` = `s_movk_i32 s20, 0xfffe`; SOP2 op 18 `0x8915c114` = `s_xor_b32 s21, s20, -1`; VOP2 `0x36020015` = `v_and_b32 v1, s21, v0`. The negative words differ only in `sdst` (0x6a/0x7e/0x7c), inserted at `+0x14`. Tests: `scalar-movk-xor` proves sign extension (`xor i32 -2, -1`) and that the xor result reaches the position export. The five refusals pin both opcodes' non-SGPR destinations. `native_direct_mesh` is not in the Windows `pr` preset filter, so CI does not run it. The author ran it locally on the merge with `a0e126c2`.
github manually merged commit 0d90e253bf into main 2026-12-01 00:12:37 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.