shader: lower compute s_bcnt1_i32_b32 of exec_lo as a known word #1865

Merged
henriazz10 merged 1 commit from upstream-pr/1872 into main 2026-11-24 20:09:08 +00:00
henriazz10 commented 2026-11-24 19:54:26 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by henriazz10 on 2026-11-24T19:54:26Z.


Change

Refs #1543. This is the s_bcnt1_i32_b32 sN, exec_lo slice claimed in https://github.com/R0Y00/Xbox2Windows/issues/1543#issuecomment-7141801643. It is separate from the quad_perm and row_shr DPP slices, and it builds on the v_mbcnt slice (#1782). It touches only tools/compute_store_aot.py, its test, CMakeLists.txt and the docs.

  • Outside a guarded region, exec is the whole wave, so s_bcnt1_i32_b32 sD, exec_lo is folded to a known scalar word:
    • For a group of at most 32 threads, the word is the group's thread count. Such a group is one wave of either size.
    • For a larger group, the word is 32. This needs the existing wave_size=32 statement (--wave-size 32) and a thread count that is a multiple of 32.
  • Refused, each with its own control:
    • the instruction inside a guarded region (s_and_saveexec_b32 up to the exec restore);
    • exec_hi, exec and vcc_lo as the source;
    • a group larger than 32 without the statement;
    • a size above 32 that is not a multiple of 32;
    • a destination above s105 or one still loading.
  • SCC (sD != 0) is not modelled, as for the other scalar ALU forms in this subset. A later s_cbranch_scc0 stays refused, and a control checks this.

v_readlane, v_writelane, ds_bpermute and s_ff1_i32_b64 are not part of this PR.

Verification

Commit b7854f13, rebased onto dd753176. Windows 11 build 26300, VS 2019 Build Tools 16.11 (MSVC 14.29), DXC 1.8.2502.11, Python 3.12, debug layer enabled. offscreen_check was built from an earlier main (0aa6522c); this PR does not change it.

python -B tests/compute_store_check.py draw-bcnt-exec <dxc> <offscreen_check> warp
python -B tests/compute_store_check.py draw-bcnt-exec <dxc> <offscreen_check> hardware
Backend Adapter / driver Result
WARP Microsoft Basic Render Driver 10.0.26100.9818 exit 0, compared_words=320 mismatches=0, debug_errors=0
hardware NVIDIA GeForce RTX 5080, 32.0.16.1692 exit 0, compared_words=320 mismatches=0, debug_errors=0

No capability skips. The draws ran before the rebase onto the base above, which changed none of the four files. controls() was re-run on the final commit.

The LLVM 15 round trip ran in Ubuntu 22.04 (llvm-15 15.0.7 from apt, as in the Linux CI job):

python3 -B tests/compute_store_check.py binary llvm-mc-15 llvm-objcopy-15 libLLVM-15.so.1   # exit 0

bcnt_exec_binary() decodes the assembled fixture back to the same s_bcnt1_i32_b32 line and requires the same translation.

Negative control. With tools/compute_store_aot.py reverted to main, controls() fails with Unsupported compute instruction: s_bcnt1_i32_b32 s4, exec_lo.

Evidence

The fixture is source-built in LLVM 15 spelling. It runs one group of 64 threads (two wave32 waves) with wave_size=32. Each thread stores flat * 64 + count, so all 64 words are distinct, and a Python reference gives the expected words. All 320 words are compared.

  • Translation controls. They check the exact HLSL line for three groups:
    • 64 threads with the statement: 32;
    • 32 threads without it: 32;
    • 16 threads without it: 16. This separates the group-size rule from the wave size.
  • Reference controls. Each must fail at its first differing word:
    • a count of 33: word 0;
    • the group size (64) in place of 32: word 0;
    • a changed sentinel past the group: word 64.
  • Recompiled-HLSL controls. Each must fail on the device:
    • the count off by one;
    • the group size in place of 32.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed (docs/experiments.md).
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted. Gemini 4 Hydrogen (Antigravity CLI) wrote the translator change, the fixture and the docs. Claude Code (Claude Opus 5.5) reviewed them, added the 16-thread control, re-ran the GPU draws and the negative control, and ran the LLVM 15 round trip. The measurements come from the machine described in Verification.

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6590173672 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1872). Originally posted by [henriazz10](https://github.com/henriazz10) on 2026-11-24T19:54:26Z. --- ## Change Refs #1543. This is the `s_bcnt1_i32_b32 sN, exec_lo` slice claimed in https://github.com/R0Y00/Xbox2Windows/issues/1543#issuecomment-7141801643. It is separate from the `quad_perm` and `row_shr` DPP slices, and it builds on the `v_mbcnt` slice (#1782). It touches only `tools/compute_store_aot.py`, its test, `CMakeLists.txt` and the docs. - Outside a guarded region, `exec` is the whole wave, so `s_bcnt1_i32_b32 sD, exec_lo` is folded to a known scalar word: - For a group of at most 32 threads, the word is the group's thread count. Such a group is one wave of either size. - For a larger group, the word is 32. This needs the existing `wave_size=32` statement (`--wave-size 32`) and a thread count that is a multiple of 32. - Refused, each with its own control: - the instruction inside a guarded region (`s_and_saveexec_b32` up to the `exec` restore); - `exec_hi`, `exec` and `vcc_lo` as the source; - a group larger than 32 without the statement; - a size above 32 that is not a multiple of 32; - a destination above `s105` or one still loading. - SCC (`sD != 0`) is not modelled, as for the other scalar ALU forms in this subset. A later `s_cbranch_scc0` stays refused, and a control checks this. `v_readlane`, `v_writelane`, `ds_bpermute` and `s_ff1_i32_b64` are not part of this PR. ## Verification Commit `b7854f13`, rebased onto `dd753176`. Windows 11 build 26300, VS 2019 Build Tools 16.11 (MSVC 14.29), DXC 1.8.2502.11, Python 3.12, debug layer enabled. `offscreen_check` was built from an earlier `main` (`0aa6522c`); this PR does not change it. ```powershell python -B tests/compute_store_check.py draw-bcnt-exec <dxc> <offscreen_check> warp python -B tests/compute_store_check.py draw-bcnt-exec <dxc> <offscreen_check> hardware ``` | Backend | Adapter / driver | Result | |---|---|---| | WARP | Microsoft Basic Render Driver 10.0.26100.9818 | exit 0, `compared_words=320 mismatches=0`, `debug_errors=0` | | hardware | NVIDIA GeForce RTX 5080, 32.0.16.1692 | exit 0, `compared_words=320 mismatches=0`, `debug_errors=0` | No capability skips. The draws ran before the rebase onto the base above, which changed none of the four files. `controls()` was re-run on the final commit. The LLVM 15 round trip ran in Ubuntu 22.04 (`llvm-15` 15.0.7 from apt, as in the Linux CI job): ```sh python3 -B tests/compute_store_check.py binary llvm-mc-15 llvm-objcopy-15 libLLVM-15.so.1 # exit 0 ``` `bcnt_exec_binary()` decodes the assembled fixture back to the same `s_bcnt1_i32_b32` line and requires the same translation. **Negative control.** With `tools/compute_store_aot.py` reverted to `main`, `controls()` fails with `Unsupported compute instruction: s_bcnt1_i32_b32 s4, exec_lo`. ## Evidence The fixture is source-built in LLVM 15 spelling. It runs one group of 64 threads (two wave32 waves) with `wave_size=32`. Each thread stores `flat * 64 + count`, so all 64 words are distinct, and a Python reference gives the expected words. All 320 words are compared. - **Translation controls.** They check the exact HLSL line for three groups: - 64 threads with the statement: 32; - 32 threads without it: 32; - 16 threads without it: 16. This separates the group-size rule from the wave size. - **Reference controls.** Each must fail at its first differing word: - a count of 33: word 0; - the group size (64) in place of 32: word 0; - a changed sentinel past the group: word 64. - **Recompiled-HLSL controls.** Each must fail on the device: - the count off by one; - the group size in place of 32. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed (`docs/experiments.md`). - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted. Gemini 4 Hydrogen (Antigravity CLI) wrote the translator change, the fixture and the docs. Claude Code (Claude Opus 5.5) reviewed them, added the 16-thread control, re-ran the GPU draws and the negative control, and ran the LLVM 15 round trip. The measurements come from the machine described in Verification. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
upstream-sync closed this pull request 2026-11-24 21:01:01 +00:00
tedin7 commented 2026-11-24 21:01:01 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T20:03:16Z.

Review: COMMENTED


Review of head b7854f1344e91f5e50db0554da2e49e7c5f592be (PR #1872).

Findings: 0 defects.

Semantics checked against the RDNA2 definition of s_bcnt1_i32_b32 sD, exec_lo (sD = popcount of exec_lo, SCC = sD != 0):

  • Outside a guarded region exec covers the whole wave. At most 32 threads gives the thread count in both wave sizes. Above 32 the fold to 32 needs wave_size=32 and a multiple of 32 threads. Everything else is refused (wave64 with a large group, 48 threads).
  • SCC is unread in this subset and s_cbranch_scc0 is refused, so skipping the SCC write is safe.
  • Refused: guarded region, sources other than exec_lo (exec_hi, exec, vcc_lo), destination above s105 or with a pending load.
  • The HLSL stays a plain constant (no wave intrinsic), the CMake change only adds a test per adapter, and the docs describe the same rules as the code. No copied or vendor material seen.

Commands executed locally (Linux, LLVM-19):

  • git diff --check origin/main...HEAD: rc 0
  • tests/docs_links_check.py: passed (18 files, 370 links)
  • tests/bidi_controls_check.py: passed
  • tests/compute_store_check.py binary llvm-mc-19 llvm-objcopy-19 /usr/lib/llvm-19/lib/libLLVM-19.so: rc 0
  • tests/rdna2_tools_check.py: OK (148 tests, 18 skipped)
  • tests/form_coverage_check.py: passed

Local mutations on tools/compute_store_aot.py, each made compute_store_check.py binary fail (rc 1), then the tree was restored:

  1. Folded count 32 changed to 31.
  2. Guarded-region rejection removed.
  3. Source check for exec_lo disabled.
  4. Threshold threads <= 32 changed to threads < 32.

Not run here: the Windows draw tests (compute_store_aot_bcnt_exec_*).

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6046465440 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1872#pullrequestreview-6046465440). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T20:03:16Z. **Review:** COMMENTED --- Review of head `b7854f1344e91f5e50db0554da2e49e7c5f592be` (PR #1872). Findings: 0 defects. Semantics checked against the RDNA2 definition of `s_bcnt1_i32_b32 sD, exec_lo` (sD = popcount of exec_lo, SCC = sD != 0): - Outside a guarded region exec covers the whole wave. At most 32 threads gives the thread count in both wave sizes. Above 32 the fold to 32 needs `wave_size=32` and a multiple of 32 threads. Everything else is refused (wave64 with a large group, 48 threads). - SCC is unread in this subset and `s_cbranch_scc0` is refused, so skipping the SCC write is safe. - Refused: guarded region, sources other than `exec_lo` (`exec_hi`, `exec`, `vcc_lo`), destination above s105 or with a pending load. - The HLSL stays a plain constant (no wave intrinsic), the CMake change only adds a test per adapter, and the docs describe the same rules as the code. No copied or vendor material seen. Commands executed locally (Linux, LLVM-19): - `git diff --check origin/main...HEAD`: rc 0 - `tests/docs_links_check.py`: passed (18 files, 370 links) - `tests/bidi_controls_check.py`: passed - `tests/compute_store_check.py binary llvm-mc-19 llvm-objcopy-19 /usr/lib/llvm-19/lib/libLLVM-19.so`: rc 0 - `tests/rdna2_tools_check.py`: OK (148 tests, 18 skipped) - `tests/form_coverage_check.py`: passed Local mutations on `tools/compute_store_aot.py`, each made `compute_store_check.py binary` fail (rc 1), then the tree was restored: 1. Folded count 32 changed to 31. 2. Guarded-region rejection removed. 3. Source check for `exec_lo` disabled. 4. Threshold `threads <= 32` changed to `threads < 32`. Not run here: the Windows draw tests (`compute_store_aot_bcnt_exec_*`). AI-assisted; commands listed were executed locally.
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!1865
No description provided.