shader: lower remaining SOP1 *_saveexec_* and *_wrexec_* ops in direct Compute DXIL #3297

Merged
legacy-code-archaeologist merged 1 commit from upstream-pr/3297 into main 2026-11-28 08:27:43 +00:00
legacy-code-archaeologist commented 2026-11-28 06:05:37 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-28T06:05:37Z.


Lowers the remaining 12 SOP1 EXEC-mask instructions (*_saveexec_* and *_wrexec_*) in the direct Compute DXIL translator, alongside consistent uses_scc_after() and transfer() tracking.

Fixes #3296. Refs #2935.

Changes

  • src/gfx1013_compute_native.cpp (transfer()): Generalize the wave32 compute !graphics && !wave64 EXEC-mask transfer rule to cover all *_saveexec_b32 and s_andn1_wrexec_b32 / s_andn2_wrexec_b32 instructions, clearing symbolic provenance on both i.dst and 126 (EXEC_LO).
  • src/gfx1013_direct_compute.inl (uses_scc_after()): Add s_orn2_b64, s_nand_b64, s_nor_b64, s_xnor_b64, s_andn1_saveexec_b64, s_orn1_saveexec_b64, and s_andn1_wrexec_b64 to mask_scc, and add all 9 newly lowered wave32 ops (s_xor_saveexec_b32, s_andn2_saveexec_b32, s_orn2_saveexec_b32, s_nand_saveexec_b32, s_nor_saveexec_b32, s_xnor_saveexec_b32, s_andn1_saveexec_b32, s_orn1_saveexec_b32, s_andn1_wrexec_b32) to overwrites.
  • src/gfx1013_direct_compute.inl (emit()):
    • Extract a shared combine_scalar_mask helper covering and/or/xor, andn2/orn2 (a op ~b), andn1/orn1 (~a op b), and nand/nor/xnor (~(a op b)).
    • Lower s_andn1_saveexec_b64 (0x37), s_orn1_saveexec_b64 (0x38), and s_andn1_wrexec_b64 (0x39) in the 64-bit mask path (s_andn1_wrexec_b64 gated to compute && wave64 with even SGPR pair operands <= 104, matching s_andn2_wrexec_b64).
    • Generalize the wave32 EXEC-mask handler for all *_saveexec_b32 (0x3e..0x45) and s_andn1_wrexec_b32 (0x46) under compute && !wave64 (dst <= 107, refusing dst > 107 with unsupported wave32 SAVEEXEC destination), updating dst (old for saveexec, mask for wrexec), EXEC_LO, and SCC = (mask != 0).
  • tests/native_saveexec_wrexec_check.py, tests/cmake/native_saveexec_wrexec.cmake, docs/experiments/native-saveexec-wrexec.md: Add ir, controls, and hardware checks covering 19 wave32 cases, 9 wave64 cases (including SCC=0, SCC=1, high-word-only non-zero EXEC_HI, dst == src aliasing, vcc_lo/exec_lo/inline/literal sources, partial waves), and 8 negative operand/mode refusals.

Verification

All tests ran after the final edit on both dev and release presets:

  • ctest --preset dev --no-tests=error --output-on-failure -j 1 -V -R '^native_saveexec_wrexec_':
    • native_saveexec_wrexec_ir: Passed (0.84s, evaluated IR for 19 wave32 + 9 wave64 cases + 8 refusals)
    • native_saveexec_wrexec_controls: Passed (3.62s, compiled 28 wave32/wave64 cases + 8 refusals)
    • native_saveexec_wrexec_hardware: Skipped (77) on local Intel(R) HD Graphics 530 (driver=31.0.101.2111, requires shader model 6.6 with wave32; hardware execution unmeasured locally)
  • ctest --preset dev --no-tests=error --output-on-failure -j 1 -R '^native_direct_container$' & -R '^(native_or_saveexec|native_wrexec64|native_salu_cmp64|native_s_not_b64_exec)_': native_direct_container (24.99s), native_s_not_b64_exec_controls, native_salu_cmp64_ir, and native_salu_cmp64_controls Passed; 4 hardware tests Skipped (77).
  • ctest --preset release --no-tests=error --output-on-failure -j 1 -R '^(native_saveexec_wrexec_|native_or_saveexec_|native_wrexec64_|native_salu_cmp64_|native_s_not_b64_exec_|native_direct_container$)': 6 non-hardware tests Passed (31.88s), 5 hardware tests Skipped (77).
  • python -B tests/docs_links_check.py: Passed (145 Markdown files, 663 links).
  • Sensitivity mutants on dev (native_saveexec_wrexec_ir):
    1. andn1/orn1 operand swap (~right instead of ~left): killed at w32_andn1_nz
    2. Drop outer inversion on nand/nor/xnor: killed at w32_nand_nz
    3. Write old instead of mask for wrexec: killed at w32_wr1_nz
      (src/gfx1013_direct_compute.inl restored cleanly and native_saveexec_wrexec_ir re-passed.)

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5537313677 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3297). Originally posted by [legacy-code-archaeologist](https://github.com/legacy-code-archaeologist) on 2026-11-28T06:05:37Z. --- Lowers the remaining 12 SOP1 EXEC-mask instructions (`*_saveexec_*` and `*_wrexec_*`) in the direct Compute DXIL translator, alongside consistent `uses_scc_after()` and `transfer()` tracking. Fixes #3296. Refs #2935. ## Changes - **`src/gfx1013_compute_native.cpp` (`transfer()`):** Generalize the wave32 compute `!graphics && !wave64` EXEC-mask transfer rule to cover all `*_saveexec_b32` and `s_andn1_wrexec_b32` / `s_andn2_wrexec_b32` instructions, clearing symbolic provenance on both `i.dst` and `126` (`EXEC_LO`). - **`src/gfx1013_direct_compute.inl` (`uses_scc_after()`):** Add `s_orn2_b64`, `s_nand_b64`, `s_nor_b64`, `s_xnor_b64`, `s_andn1_saveexec_b64`, `s_orn1_saveexec_b64`, and `s_andn1_wrexec_b64` to `mask_scc`, and add all 9 newly lowered wave32 ops (`s_xor_saveexec_b32`, `s_andn2_saveexec_b32`, `s_orn2_saveexec_b32`, `s_nand_saveexec_b32`, `s_nor_saveexec_b32`, `s_xnor_saveexec_b32`, `s_andn1_saveexec_b32`, `s_orn1_saveexec_b32`, `s_andn1_wrexec_b32`) to `overwrites`. - **`src/gfx1013_direct_compute.inl` (`emit()`):** - Extract a shared `combine_scalar_mask` helper covering `and`/`or`/`xor`, `andn2`/`orn2` (`a op ~b`), `andn1`/`orn1` (`~a op b`), and `nand`/`nor`/`xnor` (`~(a op b)`). - Lower `s_andn1_saveexec_b64` (`0x37`), `s_orn1_saveexec_b64` (`0x38`), and `s_andn1_wrexec_b64` (`0x39`) in the 64-bit mask path (`s_andn1_wrexec_b64` gated to `compute && wave64` with even SGPR pair operands `<= 104`, matching `s_andn2_wrexec_b64`). - Generalize the wave32 EXEC-mask handler for all `*_saveexec_b32` (`0x3e..0x45`) and `s_andn1_wrexec_b32` (`0x46`) under `compute && !wave64` (`dst <= 107`, refusing `dst > 107` with `unsupported wave32 SAVEEXEC destination`), updating `dst` (`old` for saveexec, `mask` for wrexec), `EXEC_LO`, and `SCC = (mask != 0)`. - **`tests/native_saveexec_wrexec_check.py`, `tests/cmake/native_saveexec_wrexec.cmake`, `docs/experiments/native-saveexec-wrexec.md`:** Add `ir`, `controls`, and `hardware` checks covering 19 wave32 cases, 9 wave64 cases (including `SCC=0`, `SCC=1`, high-word-only non-zero `EXEC_HI`, `dst == src` aliasing, `vcc_lo`/`exec_lo`/inline/literal sources, partial waves), and 8 negative operand/mode refusals. ## Verification All tests ran after the final edit on both `dev` and `release` presets: - `ctest --preset dev --no-tests=error --output-on-failure -j 1 -V -R '^native_saveexec_wrexec_'`: - `native_saveexec_wrexec_ir`: **Passed** (`0.84s`, evaluated IR for `19` wave32 + `9` wave64 cases + `8` refusals) - `native_saveexec_wrexec_controls`: **Passed** (`3.62s`, compiled `28` wave32/wave64 cases + `8` refusals) - `native_saveexec_wrexec_hardware`: **Skipped (`77`)** on local `Intel(R) HD Graphics 530` (`driver=31.0.101.2111`, `requires shader model 6.6 with wave32`; hardware execution unmeasured locally) - `ctest --preset dev --no-tests=error --output-on-failure -j 1 -R '^native_direct_container$'` & `-R '^(native_or_saveexec|native_wrexec64|native_salu_cmp64|native_s_not_b64_exec)_'`: `native_direct_container` (`24.99s`), `native_s_not_b64_exec_controls`, `native_salu_cmp64_ir`, and `native_salu_cmp64_controls` **Passed**; `4` hardware tests **Skipped (`77`)**. - `ctest --preset release --no-tests=error --output-on-failure -j 1 -R '^(native_saveexec_wrexec_|native_or_saveexec_|native_wrexec64_|native_salu_cmp64_|native_s_not_b64_exec_|native_direct_container$)'`: `6` non-hardware tests **Passed** (`31.88s`), `5` hardware tests **Skipped (`77`)**. - `python -B tests/docs_links_check.py`: **Passed** (`145` Markdown files, `663` links). - Sensitivity mutants on `dev` (`native_saveexec_wrexec_ir`): 1. `andn1`/`orn1` operand swap (`~right` instead of `~left`): **killed** at `w32_andn1_nz` 2. Drop outer inversion on `nand`/`nor`/`xnor`: **killed** at `w32_nand_nz` 3. Write `old` instead of `mask` for `wrexec`: **killed** at `w32_wr1_nz` (`src/gfx1013_direct_compute.inl` restored cleanly and `native_saveexec_wrexec_ir` re-passed.) AI-assisted.
RonLogic commented 2026-11-28 06:27:56 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by RonLogic on 2026-11-28T06:27:56Z.


Independent Windows verification at 80c13cf5, parent 17f112b2. Windows 11 26300.10075, MSVC 19.52.37029, Windows SDK 10.0.26100 DXC, RTX 4070 driver 32.0.16.2124, and app-local WARP 1.0.22.

cmake --build <configured-directory> --target native_compute_ir_dump compile_dxil native_store_replay
ctest --test-dir <configured-directory> --no-tests=error -j 1 -V -R "^(native_saveexec_wrexec_|native_or_saveexec_|native_wrexec64_|native_salu_cmp64_|native_s_not_b64_exec_|native_direct_container$)"

Debug and Release each passed 11/11. The RTX 4070 matched all 2,064 words per case across 19 wave32 and 9 wave64 replays, including aliasing, the high-word SCC cases, and the 128-thread dispatch. Both configurations passed the eight compiler refusals.

I also ran the 28 cases via native_store_replay --direct-warp. Both configurations matched 27 cases. The 8-thread w32_andn1_z had the same 45 wrong words in each, first at word 265 (69696969 instead of 000000a5). The fixture calculates its vector addresses before setting guest EXEC, so this case relies on the partial-wave entry ballot from #3160. Prepending s_mov_b32 exec_lo, -1 to that fixture before its first vector instruction restored all 2,064 words on WARP and preserved the RTX result. The explicit old EXEC used by the tested opcode remains 0xa5.

I separately checked the SCC liveness change in Release. A symbolic stride extraction from a UAV slot precedes each of the nine new wave32 forms, whose result is immediately observed by s_cselect_b32. All 18 combinations compiled and matched both result words and every guard on both adapters without stride metadata. Omitting the EXEC instruction or making it read SRC_SCC correctly refused the live symbolic SCC.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7235311084 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3297#issuecomment-7235311084). Originally posted by [RonLogic](https://github.com/RonLogic) on 2026-11-28T06:27:56Z. --- Independent Windows verification at `80c13cf5`, parent `17f112b2`. Windows 11 26300.10075, MSVC 19.52.37029, Windows SDK 10.0.26100 DXC, RTX 4070 driver 32.0.16.2124, and app-local WARP 1.0.22. ``` cmake --build <configured-directory> --target native_compute_ir_dump compile_dxil native_store_replay ctest --test-dir <configured-directory> --no-tests=error -j 1 -V -R "^(native_saveexec_wrexec_|native_or_saveexec_|native_wrexec64_|native_salu_cmp64_|native_s_not_b64_exec_|native_direct_container$)" ``` Debug and Release each passed **11/11**. The RTX 4070 matched all 2,064 words per case across 19 wave32 and 9 wave64 replays, including aliasing, the high-word SCC cases, and the 128-thread dispatch. Both configurations passed the eight compiler refusals. I also ran the 28 cases via `native_store_replay --direct-warp`. Both configurations matched 27 cases. The 8-thread `w32_andn1_z` had the same 45 wrong words in each, first at word 265 (`69696969` instead of `000000a5`). The fixture calculates its vector addresses before setting guest EXEC, so this case relies on the partial-wave entry ballot from #3160. Prepending `s_mov_b32 exec_lo, -1` to that fixture before its first vector instruction restored all 2,064 words on WARP and preserved the RTX result. The explicit old EXEC used by the tested opcode remains `0xa5`. I separately checked the SCC liveness change in Release. A symbolic stride extraction from a UAV slot precedes each of the nine new wave32 forms, whose result is immediately observed by `s_cselect_b32`. All 18 combinations compiled and matched both result words and every guard on both adapters without stride metadata. Omitting the EXEC instruction or making it read `SRC_SCC` correctly refused the live symbolic SCC.
Leyukaka commented 2026-11-28 06:31:38 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-28T06:31:38Z.


I reviewed the diff (not run). The new lowerings look right: operand order for the n1/n2 forms, saveexec versus wrexec, SCC from the new mask, and both EXEC words in wave64. The widened wave32 branch in transfer() now also clears s[126] after s_andn2_wrexec_b32, which main did not do.

One soundness gap in the static analysis, which this PR inherits rather than introduces:

  • Stale EXEC symbols after the 64-bit forms. In transfer() (src/gfx1013_compute_native.cpp), only the wave32 *_saveexec_b32 / *_wrexec_b32 branch clears s[126]. The 64-bit *_saveexec_b64 and *_wrexec_b64 fall into the generic SOP1 branch, which clears dst and dst + 1 but leaves s[126] and s[127] as they were.
    • After s_mov_b64 exec, <constant> and then a 64-bit saveexec or wrexec, the analysis still sees EXEC as that constant.
    • A later s_mov_b32 sN, exec_lo copies the stale constant into sN, and the constant-sampler path (sampler_index) would then fold it. I do not expect real shaders to do this, so it is a soundness gap rather than an observed miscompile.
    • It already applies on main to the eight *_saveexec_b64 forms main lowers and to s_andn2_wrexec_b64 (that one is mine, from #3247). This PR adds s_andn1_saveexec_b64, s_orn1_saveexec_b64 and s_andn1_wrexec_b64.
    • Clearing s[126] and s[127] for every compute SOP1 *_saveexec_b64 / *_wrexec_b64 in transfer() would close it. I'm happy to do that separately after this PR, since it also touches #3247's op.
  • A smaller inherited one: the 64-bit destination check accepts dst == exec for the saveexec forms. s_andn1_saveexec_b64 exec, s[22:23] then writes the saved EXEC and immediately overwrites it with the new mask. The wave32 forms added in this PR refuse exec_lo as the destination. I have not checked what RDNA2 does with that encoding.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7235350939 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3297#issuecomment-7235350939). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-28T06:31:38Z. --- I reviewed the diff (not run). The new lowerings look right: operand order for the n1/n2 forms, saveexec versus wrexec, SCC from the new mask, and both EXEC words in wave64. The widened wave32 branch in `transfer()` now also clears `s[126]` after `s_andn2_wrexec_b32`, which `main` did not do. One soundness gap in the static analysis, which this PR inherits rather than introduces: - **Stale EXEC symbols after the 64-bit forms.** In `transfer()` (`src/gfx1013_compute_native.cpp`), only the wave32 `*_saveexec_b32` / `*_wrexec_b32` branch clears `s[126]`. The 64-bit `*_saveexec_b64` and `*_wrexec_b64` fall into the generic SOP1 branch, which clears `dst` and `dst + 1` but leaves `s[126]` and `s[127]` as they were. - After `s_mov_b64 exec, <constant>` and then a 64-bit saveexec or wrexec, the analysis still sees EXEC as that constant. - A later `s_mov_b32 sN, exec_lo` copies the stale constant into sN, and the constant-sampler path (`sampler_index`) would then fold it. I do not expect real shaders to do this, so it is a soundness gap rather than an observed miscompile. - It already applies on `main` to the eight `*_saveexec_b64` forms `main` lowers and to `s_andn2_wrexec_b64` (that one is mine, from #3247). This PR adds `s_andn1_saveexec_b64`, `s_orn1_saveexec_b64` and `s_andn1_wrexec_b64`. - Clearing `s[126]` and `s[127]` for every compute SOP1 `*_saveexec_b64` / `*_wrexec_b64` in `transfer()` would close it. I'm happy to do that separately after this PR, since it also touches #3247's op. - **A smaller inherited one:** the 64-bit destination check accepts `dst == exec` for the saveexec forms. `s_andn1_saveexec_b64 exec, s[22:23]` then writes the saved EXEC and immediately overwrites it with the new mask. The wave32 forms added in this PR refuse `exec_lo` as the destination. I have not checked what RDNA2 does with that encoding. AI-assisted.
legacy-code-archaeologist commented 2026-11-28 06:44:44 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-28T06:44:44Z.


Thanks @RonLogic for running the independent Debug/Release verification on RTX 4070 + WARP (and confirming the symbolic SCC liveness test!), and @Leyukaka for the thorough diff review and noting the inherited 64-bit transfer() EXEC symbol / dst == exec items (and #3247's wave64 wrexec). Happy to leave #3297 clean on 80c13cf5 since both points are pre-existing across the *_saveexec_b64 / *_wrexec_b64 family and #3297's wave32 s_mov_b32 exec_lo, -1 question on WARP isn't blocking, or let me know if a follow-up fixture/patch on this PR is preferred.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7235491288 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3297#issuecomment-7235491288). Originally posted by [legacy-code-archaeologist](https://github.com/legacy-code-archaeologist) on 2026-11-28T06:44:44Z. --- Thanks @RonLogic for running the independent Debug/Release verification on RTX 4070 + WARP (and confirming the symbolic SCC liveness test!), and @Leyukaka for the thorough diff review and noting the inherited 64-bit `transfer()` EXEC symbol / `dst == exec` items (and #3247's wave64 wrexec). Happy to leave #3297 clean on `80c13cf5` since both points are pre-existing across the `*_saveexec_b64` / `*_wrexec_b64` family and #3297's wave32 `s_mov_b32 exec_lo, -1` question on WARP isn't blocking, or let me know if a follow-up fixture/patch on this PR is preferred. AI-assisted.
JohnConnorNPC commented 2026-11-28 06:45:21 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by JohnConnorNPC on 2026-11-28T06:45:21Z.


Thank you for this PR. I reviewed 80c13cf5 merged locally into current main (cross build under Wine, not Windows). native_saveexec_wrexec_ir ("19 wave32 and 9 wave64 cases, plus 8 refusals") and native_saveexec_wrexec_controls ("compiled 28 wave32/wave64 cases cleanly and verified 8 refusals") both pass there. Your operand-swap mutant turns the test red, and so does dropping the wave32 destination refusal.

Could you remove one fixture dependency before merge? The 8-thread w32_andn1_z case relies on #3160's partial-wave entry ballot:

  • build_wave32_program computes the vector addresses (v_lshlrev_b32 v8, v_add_nc_u32 v8, v_add_nc_u32 v1) before it sets guest EXEC with s_mov_b32 exec_lo, <old_exec>. So in a partial wave the store addresses depend on the EXEC the wave starts with.
  • The --direct-warp run in the earlier comment shows the effect: w32_andn1_z had 45 wrong words, first at word 265 (69696969 instead of 000000a5). Prepending s_mov_b32 exec_lo, -1 before the first vector instruction restored all 2,064 words on WARP and kept the RTX result.
  • That change leaves the opcode's tested old EXEC (0xa5) as it is, so the case still checks the same thing without relying on #3160.

Could you add that line at the start of build_wave32_program (build_wave64_program already starts with s_mov_b64 exec, -1) and rerun native_saveexec_wrexec_hardware, on WARP if you can?

This comment was AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7235497418 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3297#issuecomment-7235497418). Originally posted by [JohnConnorNPC](https://github.com/JohnConnorNPC) on 2026-11-28T06:45:21Z. --- Thank you for this PR. I reviewed `80c13cf5` merged locally into current `main` (cross build under Wine, not Windows). `native_saveexec_wrexec_ir` ("19 wave32 and 9 wave64 cases, plus 8 refusals") and `native_saveexec_wrexec_controls` ("compiled 28 wave32/wave64 cases cleanly and verified 8 refusals") both pass there. Your operand-swap mutant turns the test red, and so does dropping the wave32 destination refusal. Could you remove one fixture dependency before merge? The 8-thread `w32_andn1_z` case relies on #3160's partial-wave entry ballot: - `build_wave32_program` computes the vector addresses (`v_lshlrev_b32 v8`, `v_add_nc_u32 v8`, `v_add_nc_u32 v1`) before it sets guest EXEC with `s_mov_b32 exec_lo, <old_exec>`. So in a partial wave the store addresses depend on the EXEC the wave starts with. - The `--direct-warp` run in the earlier comment shows the effect: `w32_andn1_z` had 45 wrong words, first at word 265 (`69696969` instead of `000000a5`). Prepending `s_mov_b32 exec_lo, -1` before the first vector instruction restored all 2,064 words on WARP and kept the RTX result. - That change leaves the opcode's tested old EXEC (`0xa5`) as it is, so the case still checks the same thing without relying on #3160. Could you add that line at the start of `build_wave32_program` (`build_wave64_program` already starts with `s_mov_b64 exec, -1`) and rerun `native_saveexec_wrexec_hardware`, on WARP if you can? This comment was AI-assisted.
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!3297
No description provided.