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

Merged
mumba17 merged 3 commits from upstream-pr/3635 into main 2026-12-01 00:12:06 +00:00
mumba17 commented 2026-11-30 18:53:21 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by mumba17 on 2026-11-30T18:53:21Z.


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.

#3638 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 #3416): no s_xor_b32 or s_movk_i32 refusal is left.

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5571679147 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3635). Originally posted by [mumba17](https://github.com/mumba17) on 2026-11-30T18:53:21Z. --- 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. #3638 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 #3416): no `s_xor_b32` or `s_movk_i32` refusal is left. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
lukaslw-lab commented 2026-11-30 19:09:48 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-11-30T19:09:48Z.

Review: APPROVED


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).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6118730307 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3635#pullrequestreview-6118730307). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-11-30T19:09:48Z. **Review:** APPROVED --- 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).
R0Y00 commented 2026-11-30 19:40:04 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-30T19:40:04Z.

Review: COMMENTED


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

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6119248144 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3635#pullrequestreview-6119248144). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-30T19:40:04Z. **Review:** COMMENTED --- Windows passed on this head. The failing Linux job is `tests/startup_close_guard_check.py`: the Close fixture extracts the trace added by #3638 and its fake state has no trace recording field. I reproduced the failure separately from the mesh lowering and opened #3642 with the narrow fix. Please rerun the Linux check against a base containing that fix before merging this PR.
mumba17 commented 2026-11-30 19:59:09 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by mumba17 on 2026-11-30T19:59:09Z.


Thanks for the review and the real-program table. While this was open, #3638 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 #3638'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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7290233384 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3635#issuecomment-7290233384). Originally posted by [mumba17](https://github.com/mumba17) on 2026-11-30T19:59:09Z. --- Thanks for the review and the real-program table. While this was open, #3638 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 #3638'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.
lukaslw-lab commented 2026-11-30 20:05:02 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-11-30T20:05:02Z.

Review: APPROVED


Re-reviewed a671a700 by reading the diff; not built or run. Main has been merged twice since my last review. The PR now keeps #3638'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.
    • #3638'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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6119632793 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3635#pullrequestreview-6119632793). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-11-30T20:05:02Z. **Review:** APPROVED --- Re-reviewed `a671a700` by reading the diff; not built or run. Main has been merged twice since my last review. The PR now keeps #3638'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`. - #3638'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`.
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!3635
No description provided.