shader: lower s_bcnt1_i32_b32 of a scalar word, v_mbcnt over exec_lo and wave32 vcc_hi in compute_store_aot #2158

Manually merged
github merged 4 commits from gh-pr/2158/head into gh-pr/2158/base 2026-11-27 00:01:24 +00:00
Owner

@⁠tedin7 on GitHub · 2026-11-25 01:50 UTC · original
tedin7:x2w-2022g-compute-alu-gaps → main · +317 −10 · 8 files · 4 commits · merged 2026-11-25 10:22 UTC

Part of #2022

What this unblocks: item G of #2022 in the compute store profile. s_bcnt1_i32_b32 of a general scalar word, v_mbcnt_lo/hi_u32_b32 with exec_lo as the mask, and wave32 vcc_hi as a known-word operand no longer stop a program at the instruction.

What changes (tools/compute_store_aot.py)

  • s_bcnt1_i32_b32 sD, S with a known scalar word S (loaded constant, move or ALU result, inline constant, literal, wave32 vcc_hi): D = CountOneBits(S) (RDNA2 ISA SOP1; LLVM S_BCNT1_I32_B32 = ctpop). Known words fold; run-time words emit countbits(...). exec_lo keeps its wave and group-size rules. exec, exec_hi, vcc_lo and unknown registers stay refused.
  • v_mbcnt_lo_u32_b32 vD, exec_lo, base outside a guarded region: every lane below the current one is active in a full wave, so the mask is all ones. Inside a guard the form is refused (Active lane mask inside guarded region).
  • vcc_hi (needs --wave-size 32): s_mov_b32 vcc_hi, K, then known-word reads. Every lowered VCC write touches vcc_lo only in wave32. Other writes and reads before the move stay refused; without the wave32 statement the name is unrecognised.
  • Not covered and still refused: v_cmp_ne_i32 operand forms beyond what #2110 already merged, and s_bcnt1_i32_b64 (merged in #2109).

Tests

  • New tests/compute_alu_lane_gaps_check.py: exact translations, refusal controls, and a real D3D12 compute readback against an independent CPU reference (two programs: a guarded read-compute one with a run-time word, a vcc_hi mask and v_mbcnt over scalar masks, and an unguarded 64-thread one with exec_lo). Wrong references (mask including the lane, mask ignoring the lane, dropped vcc_hi mask, zero-bit count, rank over 64 lanes, off-by-one count) and mutated HLSL must fail.
  • CTest: compute_alu_lane_gaps_controls, compute_store_aot_alu_lane_gaps_{warp,hardware}.
  • compute_alu_bcnt_check.py: the control that refused s_bcnt1_i32_b32 s9, s0 now refuses exec_hi, since a known scalar word is accepted.
  • Docs: docs/experiments.md, AGENTS.md list, workflow Python list.

Verification:

Linux (local):

  • python3 -B tests/compute_alu_lane_gaps_check.py controls PASS
  • python3 -B tests/compute_alu_bcnt_check.py controls PASS
  • python3 -B tests/compute_alu_bcnt64_check.py PASS
  • python3 -B tests/compute_alu_cmp_ne_check.py PASS
  • python3 -B tests/compute_lane_mask_check.py controls PASS; med3, xor3, cvt_pk_u8, mad_i24, minmax3, salu_absdiff controls PASS
  • compute_store_check.controls() PASS
  • python3 -B tests/docs_links_check.py PASS

Win2025 WARP (Windows Server 2025 build 26100, MSVC 14.44, D3D12 WARP) at 65765569, via the pipeline win2025 2158:

  • ctest --preset dev on the compute set, including compute_alu_lane_gaps_controls and compute_store_aot_alu_lane_gaps_warp: 63/63 passed, no skips.
  • ctest --preset release (/O2) on the same set: 63/63 passed, no skips.

Linux CI fix: the check list passed controls as a script name, so compute_alu_lane_gaps_check.py now defaults to controls and the workflow and AGENTS.md list it without the argument. GitHub Linux, fixtures and Windows checks pass on this head.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-25 01:50 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2158) `tedin7:x2w-2022g-compute-alu-gaps` → `main` · +317 −10 · 8 files · 4 commits · merged 2026-11-25 10:22 UTC Part of #2022 What this unblocks: item G of #2022 in the compute store profile. `s_bcnt1_i32_b32` of a general scalar word, `v_mbcnt_lo/hi_u32_b32` with `exec_lo` as the mask, and wave32 `vcc_hi` as a known-word operand no longer stop a program at the instruction. ## What changes (`tools/compute_store_aot.py`) - `s_bcnt1_i32_b32 sD, S` with a known scalar word `S` (loaded constant, move or ALU result, inline constant, literal, wave32 `vcc_hi`): `D = CountOneBits(S)` (RDNA2 ISA SOP1; LLVM `S_BCNT1_I32_B32` = `ctpop`). Known words fold; run-time words emit `countbits(...)`. `exec_lo` keeps its wave and group-size rules. `exec`, `exec_hi`, `vcc_lo` and unknown registers stay refused. - `v_mbcnt_lo_u32_b32 vD, exec_lo, base` outside a guarded region: every lane below the current one is active in a full wave, so the mask is all ones. Inside a guard the form is refused (`Active lane mask inside guarded region`). - `vcc_hi` (needs `--wave-size 32`): `s_mov_b32 vcc_hi, K`, then known-word reads. Every lowered VCC write touches `vcc_lo` only in wave32. Other writes and reads before the move stay refused; without the wave32 statement the name is unrecognised. - Not covered and still refused: `v_cmp_ne_i32` operand forms beyond what #2110 already merged, and `s_bcnt1_i32_b64` (merged in #2109). ## Tests - New `tests/compute_alu_lane_gaps_check.py`: exact translations, refusal controls, and a real D3D12 compute readback against an independent CPU reference (two programs: a guarded read-compute one with a run-time word, a `vcc_hi` mask and `v_mbcnt` over scalar masks, and an unguarded 64-thread one with `exec_lo`). Wrong references (mask including the lane, mask ignoring the lane, dropped `vcc_hi` mask, zero-bit count, rank over 64 lanes, off-by-one count) and mutated HLSL must fail. - CTest: `compute_alu_lane_gaps_controls`, `compute_store_aot_alu_lane_gaps_{warp,hardware}`. - `compute_alu_bcnt_check.py`: the control that refused `s_bcnt1_i32_b32 s9, s0` now refuses `exec_hi`, since a known scalar word is accepted. - Docs: `docs/experiments.md`, `AGENTS.md` list, workflow Python list. ## Verification: Linux (local): - `python3 -B tests/compute_alu_lane_gaps_check.py controls` PASS - `python3 -B tests/compute_alu_bcnt_check.py controls` PASS - `python3 -B tests/compute_alu_bcnt64_check.py` PASS - `python3 -B tests/compute_alu_cmp_ne_check.py` PASS - `python3 -B tests/compute_lane_mask_check.py controls` PASS; med3, xor3, cvt_pk_u8, mad_i24, minmax3, salu_absdiff controls PASS - `compute_store_check.controls()` PASS - `python3 -B tests/docs_links_check.py` PASS Win2025 WARP (Windows Server 2025 build 26100, MSVC 14.44, D3D12 WARP) at 65765569, via the pipeline `win2025 2158`: - `ctest --preset dev` on the compute set, including `compute_alu_lane_gaps_controls` and `compute_store_aot_alu_lane_gaps_warp`: 63/63 passed, no skips. - `ctest --preset release` (`/O2`) on the same set: 63/63 passed, no skips. Linux CI fix: the check list passed `controls` as a script name, so `compute_alu_lane_gaps_check.py` now defaults to `controls` and the workflow and AGENTS.md list it without the argument. GitHub Linux, fixtures and Windows checks pass on this head. AI-assisted; commands listed were executed locally.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 00:01:21 +00:00
github manually merged commit da43c9f4e4 into gh-pr/2158/base 2026-11-27 00:01:24 +00:00
Author
Owner

@⁠tedin7 on GitHub · 2026-11-25 02:03 UTC · original

[PASS] Win2025 WARP proof at bf5a5611

Command: x2w_pipe.py win2025 2158 --targets offscreen_check --regex '^(compute_alu_lane_gaps_controls|compute_store_aot_alu_lane_gaps_warp)$'

  • compute_alu_lane_gaps_controls Passed
  • compute_store_aot_alu_lane_gaps_warp Passed (D3D12 WARP readback vs CPU reference, wrong references and mutated HLSL rejected)

An earlier run at a00286fa failed on one mutation that changed nothing (a shift by 63 wraps to the same value). It now uses a mask of 15, which changes the result.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-25 02:03 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2158#issuecomment-7150258893) [PASS] Win2025 WARP proof at bf5a5611 Command: `x2w_pipe.py win2025 2158 --targets offscreen_check --regex '^(compute_alu_lane_gaps_controls|compute_store_aot_alu_lane_gaps_warp)$'` - `compute_alu_lane_gaps_controls` Passed - `compute_store_aot_alu_lane_gaps_warp` Passed (D3D12 WARP readback vs CPU reference, wrong references and mutated HLSL rejected) An earlier run at a00286fa failed on one mutation that changed nothing (a shift by 63 wraps to the same value). It now uses a mask of 15, which changes the result. AI-assisted; commands listed were executed locally.
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-25 02:48 UTC · original · edited 2026-11-25 02:54 UTC

Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-25T02:54:09.014208Z 6576556 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@⁠codex review" or "@⁠codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-25 02:48 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2158#issuecomment-7151215716) · edited 2026-11-25 02:54 UTC <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"65765569575161bb76e45383e2499822144be989","has_any_findings":true,"has_unresolved_findings":true,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-25T02:54:09.014208Z">2026-11-25T02:54:09.014208Z</relative-time> | `6576556` | Draft marked ready | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@⁠codex review" or "@⁠codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-25 02:54 UTC · original

P2 Badge Accept exec_lo after the lane guard has been restored

When v_mbcnt_* ..., exec_lo, ... occurs after a supported s_or_b32 exec_lo, exec_lo, sN restore, guard is cleared but guard_span remains to delimit the earlier guarded stores. This condition therefore rejects the instruction with Active lane mask inside guarded region even though EXEC is full again. This is reproducible by replacing the post-restore move in tests/compute_store_check.py's GUARD_JOIN fixture with v_mbcnt_lo_u32_b32 v1, exec_lo, 0; the equivalent -1 mask lowers successfully. Check whether the guard is currently active rather than whether any guard span exists.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-25 02:54 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2158#discussion_r4689781767) **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Accept exec_lo after the lane guard has been restored** When `v_mbcnt_* ..., exec_lo, ...` occurs after a supported `s_or_b32 exec_lo, exec_lo, sN` restore, `guard` is cleared but `guard_span` remains to delimit the earlier guarded stores. This condition therefore rejects the instruction with `Active lane mask inside guarded region` even though EXEC is full again. This is reproducible by replacing the post-restore move in `tests/compute_store_check.py`'s `GUARD_JOIN` fixture with `v_mbcnt_lo_u32_b32 v1, exec_lo, 0`; the equivalent `-1` mask lowers successfully. Check whether the guard is currently active rather than whether any guard span exists. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
Author
Owner

@⁠tedin7 on GitHub · 2026-11-25 03:41 UTC · original

Fixed in d375bf32.

Verified on Windows Server 2025 (D3D12 WARP) at d375bf3279632bdc23e49dd83a5bc52df80165f1:

  • dev: x2w_pipe.py win2025 2158 --force --targets offscreen_check --regex "^(compute_alu_lane_gaps_controls|compute_store_aot_alu_lane_gaps_warp)$" -> 2/2 passed, 0 skipped
  • release (/O2): same run -> 2/2 passed, 0 skipped

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-25 03:41 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2158#discussion_r4690105880) Fixed in d375bf32. Verified on Windows Server 2025 (D3D12 WARP) at d375bf3279632bdc23e49dd83a5bc52df80165f1: - dev: `x2w_pipe.py win2025 2158 --force --targets offscreen_check --regex "^(compute_alu_lane_gaps_controls|compute_store_aot_alu_lane_gaps_warp)$"` -> 2/2 passed, 0 skipped - release (/O2): same run -> 2/2 passed, 0 skipped AI-assisted; commands listed were executed locally.
Author
Owner

@⁠legacy-code-archaeologist on GitHub · 2026-11-25 05:50 UTC · original

Ran head dcec4727 on three adapters. All pass. Windows 11 build 26100, debug layer unavailable.

Test Adapter Driver Result
compute_alu_lane_gaps_controls n/a n/a pass
compute_store_aot_alu_lane_gaps_warp Microsoft Basic Render Driver 10.0.26100.8972 pass, 4/4 dispatches with mismatches=0
compute_store_aot_alu_lane_gaps_hardware (XBOX2WINDOWS_ADAPTER=Quadro) NVIDIA Quadro M1000M 32.0.15.7371 pass, same
compute_store_aot_alu_lane_gaps_hardware (XBOX2WINDOWS_ADAPTER=Intel) Intel HD Graphics 530 31.0.101.2111 pass, same

AI-assisted.

**@⁠legacy-code-archaeologist** on GitHub · 2026-11-25 05:50 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2158#issuecomment-7154194424) Ran head `dcec4727` on three adapters. All pass. Windows 11 build 26100, debug layer unavailable. | Test | Adapter | Driver | Result | |---|---|---|---| | `compute_alu_lane_gaps_controls` | n/a | n/a | pass | | `compute_store_aot_alu_lane_gaps_warp` | Microsoft Basic Render Driver | 10.0.26100.8972 | pass, 4/4 dispatches with `mismatches=0` | | `compute_store_aot_alu_lane_gaps_hardware` (`XBOX2WINDOWS_ADAPTER=Quadro`) | NVIDIA Quadro M1000M | 32.0.15.7371 | pass, same | | `compute_store_aot_alu_lane_gaps_hardware` (`XBOX2WINDOWS_ADAPTER=Intel`) | Intel HD Graphics 530 | 31.0.101.2111 | pass, same | _AI-assisted._
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-25 02:54 UTC · original · reviewed

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6576556957

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@⁠codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@⁠codex address that feedback".

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-25 02:54 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2158#pullrequestreview-6051151879) · **reviewed** <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `6576556957` <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@⁠codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@⁠codex address that feedback". </details>
This discussion has been locked. Commenting is limited to contributors.
No description provided.