shader: lower s_bitcmp0/1_b32 and b64 in bounded mesh lowerers #2436

Merged
R0D4X merged 2 commits from upstream-pr/2444 into main 2026-11-26 07:33:14 +00:00
R0D4X commented 2026-11-25 16:59:36 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0D4X on 2026-11-25T16:59:36Z.


Summary

  • Implement s_bitcmp0_b32, s_bitcmp1_b32, s_bitcmp0_b64, and s_bitcmp1_b64 in the bounded mesh lowerers (tools/mesh_entry_aot.py and tools/mesh_dynamic_aot.py), addressing the s_bitcmp0_b32 refusal (129 of 298 slot-57 programs) reported in the #2413 T2 census.
  • Lower concrete 32-bit (S1[4:0]) and 64-bit (S1[5:0], including s[M:N], exec, vcc, and sign-extended -1) forms per AMD RDNA 2 ISA §9.3 (SOPC), as well as 32-bit constant-buffer Dyn bit tests feeding s_cbranch_scc0 / s_cbranch_scc1 descriptor joins.
  • Update Wave.steps() to skip no-destination s_cmp_* and s_bitcmp* ops in the self.written pre-scan so comparing a never-written SGPR fails with Scalar register sN used before it is written, extend Wave.exec_range() dynamic joins to handle s_cbranch_scc1, and check all compare operands in RuntimeWave.descriptor_scalar_op() so sampler/texture descriptor words are refused cleanly.
  • Add tests/mesh_bitcmp_check.py, register mesh_bitcmp_cpu and mesh_bitcmp_draw_{warp,hardware} in CMakeLists.txt, wire tests/mesh_bitcmp_check.py into pixel-binary (llvm-mc-15) and python-linux in .github/workflows/windows.yml, and document the behavior and checks in AGENTS.md and docs/experiments.md.

Refs #2413, #1998

Verification

  • Base commit: b442b57f (upstream/main)
  • Branch commit: a60be126 (shader/mesh-bitcmp)
  • Host environment: Windows 11 x64 (10.0.26300.0), DXC 1.9.2602.17
  • WARP: Microsoft Basic Render Driver (1414:008c), driver 10.0.26100.9818, D3D12 debug layer enabled
  • Hardware GPU: NVIDIA GeForce RTX 5080 (10de:2c02), driver 32.0.16.2124, D3D12 debug layer enabled

Commands and Observed Results

.\out\pe-env\Scripts\python.exe -B tests/mesh_bitcmp_check.py
.\out\pe-env\Scripts\python.exe -B tests/mesh_entry_check.py skipped
.\out\pe-env\Scripts\python.exe -B tests/mesh_entry_check.py exec-restore
.\out\pe-env\Scripts\python.exe -B tests/mesh_dynamic_geometry_check.py
.\out\pe-env\Scripts\python.exe -B tests/mesh_dynamic_aot_check.py
.\out\pe-env\Scripts\python.exe -B tests/mesh_join_descriptor_check.py
.\out\pe-env\Scripts\python.exe -B tests/mesh_lane_spill_check.py
.\out\pe-env\Scripts\python.exe -B tests/mesh_heap_sampler_check.py
.\out\pe-env\Scripts\python.exe -B tests/mesh_clip_cull_check.py
.\out\pe-env\Scripts\python.exe -B tests/mesh_loop_census_check.py
.\out\pe-env\Scripts\python.exe -B tests/startup_gfx2hlsl_s_bitcmp_check.py
.\out\pe-env\Scripts\python.exe -B tests/startup_tools_lint_check.py
.\out\pe-env\Scripts\python.exe -B tests/docs_links_check.py
.\out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.py
git diff --check upstream/main...HEAD
ctest --preset dev --no-tests=error -j 1 -R '^(mesh_bitcmp_|mesh_join_descriptor_|mesh_dynamic_aot_cpu|mesh_lane_spill_cpu|mesh_entry_skipped_scalar_cpu)' -V
ctest --preset release --no-tests=error -j 1 -R '^mesh_bitcmp_' -V
  • Pure-Python & hygiene checks: all passed (docs_links_check.py: 19 files / 465 links; bidi_controls_check.py: 1725 files; git diff --check: clean).
  • On-disk self-mutation tests (tools/mesh_entry_aot.py): both masking _b64 shift by 31 instead of 63 (rc=1) and disabling the Wave.steps() compare skip (rc=1) failed tests/mesh_bitcmp_check.py as expected and were reverted cleanly.
  • dev CTest: 8 passed, 0 skipped, 0 failed (mesh_dynamic_aot_cpu 0.53 s, mesh_lane_spill_cpu 0.18 s, mesh_bitcmp_cpu 0.41 s, mesh_entry_skipped_scalar_cpu 0.19 s, mesh_join_descriptor_hardware 3.15 s, mesh_bitcmp_draw_hardware 5.80 s, mesh_join_descriptor_warp 0.74 s, mesh_bitcmp_draw_warp 1.40 s; debug_errors=0 debug_warnings=0).
  • release CTest: 3 passed, 0 skipped, 0 failed (mesh_bitcmp_cpu 0.41 s, mesh_bitcmp_draw_hardware 5.43 s, mesh_bitcmp_draw_warp 1.36 s; all draws pixels=1024 mismatches=0, debug_errors=0 debug_warnings=0, inverted s_bitcmp0_b32 -> s_bitcmp1_b32 GPU negative control failed with pixels=1024 mismatches=1024).
  • Not run locally: tests/mesh_bitcmp_check.py binary llvm-mc-15 (llvm-mc is not installed on this Windows host); wired into the Ubuntu pixel-binary CI job.
  • Scope note: passing source-built fixtures verify bounded s_bitcmp* evaluation and descriptor-join branching in mesh_entry_aot / mesh_dynamic_aot; they do not establish full-game startup or direct slot-57 mesh emission.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6609495691 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2444). Originally posted by [R0D4X](https://github.com/R0D4X) on 2026-11-25T16:59:36Z. --- ## Summary - Implement `s_bitcmp0_b32`, `s_bitcmp1_b32`, `s_bitcmp0_b64`, and `s_bitcmp1_b64` in the bounded mesh lowerers (`tools/mesh_entry_aot.py` and `tools/mesh_dynamic_aot.py`), addressing the `s_bitcmp0_b32` refusal (129 of 298 slot-57 programs) reported in the #2413 T2 census. - Lower concrete 32-bit (`S1[4:0]`) and 64-bit (`S1[5:0]`, including `s[M:N]`, `exec`, `vcc`, and sign-extended `-1`) forms per AMD RDNA 2 ISA §9.3 (SOPC), as well as 32-bit constant-buffer `Dyn` bit tests feeding `s_cbranch_scc0` / `s_cbranch_scc1` descriptor joins. - Update `Wave.steps()` to skip no-destination `s_cmp_*` and `s_bitcmp*` ops in the `self.written` pre-scan so comparing a never-written SGPR fails with `Scalar register sN used before it is written`, extend `Wave.exec_range()` dynamic joins to handle `s_cbranch_scc1`, and check all compare operands in `RuntimeWave.descriptor_scalar_op()` so sampler/texture descriptor words are refused cleanly. - Add `tests/mesh_bitcmp_check.py`, register `mesh_bitcmp_cpu` and `mesh_bitcmp_draw_{warp,hardware}` in `CMakeLists.txt`, wire `tests/mesh_bitcmp_check.py` into `pixel-binary` (`llvm-mc-15`) and `python-linux` in `.github/workflows/windows.yml`, and document the behavior and checks in `AGENTS.md` and `docs/experiments.md`. Refs #2413, #1998 ## Verification - **Base commit:** `b442b57f` (`upstream/main`) - **Branch commit:** `a60be126` (`shader/mesh-bitcmp`) - **Host environment:** Windows 11 x64 (`10.0.26300.0`), DXC `1.9.2602.17` - **WARP:** `Microsoft Basic Render Driver` (`1414:008c`), driver `10.0.26100.9818`, D3D12 debug layer enabled - **Hardware GPU:** `NVIDIA GeForce RTX 5080` (`10de:2c02`), driver `32.0.16.2124`, D3D12 debug layer enabled ### Commands and Observed Results ```powershell .\out\pe-env\Scripts\python.exe -B tests/mesh_bitcmp_check.py .\out\pe-env\Scripts\python.exe -B tests/mesh_entry_check.py skipped .\out\pe-env\Scripts\python.exe -B tests/mesh_entry_check.py exec-restore .\out\pe-env\Scripts\python.exe -B tests/mesh_dynamic_geometry_check.py .\out\pe-env\Scripts\python.exe -B tests/mesh_dynamic_aot_check.py .\out\pe-env\Scripts\python.exe -B tests/mesh_join_descriptor_check.py .\out\pe-env\Scripts\python.exe -B tests/mesh_lane_spill_check.py .\out\pe-env\Scripts\python.exe -B tests/mesh_heap_sampler_check.py .\out\pe-env\Scripts\python.exe -B tests/mesh_clip_cull_check.py .\out\pe-env\Scripts\python.exe -B tests/mesh_loop_census_check.py .\out\pe-env\Scripts\python.exe -B tests/startup_gfx2hlsl_s_bitcmp_check.py .\out\pe-env\Scripts\python.exe -B tests/startup_tools_lint_check.py .\out\pe-env\Scripts\python.exe -B tests/docs_links_check.py .\out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.py git diff --check upstream/main...HEAD ctest --preset dev --no-tests=error -j 1 -R '^(mesh_bitcmp_|mesh_join_descriptor_|mesh_dynamic_aot_cpu|mesh_lane_spill_cpu|mesh_entry_skipped_scalar_cpu)' -V ctest --preset release --no-tests=error -j 1 -R '^mesh_bitcmp_' -V ``` - **Pure-Python & hygiene checks:** all passed (`docs_links_check.py`: 19 files / 465 links; `bidi_controls_check.py`: 1725 files; `git diff --check`: clean). - **On-disk self-mutation tests (`tools/mesh_entry_aot.py`):** both masking `_b64` shift by `31` instead of `63` (`rc=1`) and disabling the `Wave.steps()` compare skip (`rc=1`) failed `tests/mesh_bitcmp_check.py` as expected and were reverted cleanly. - **`dev` CTest:** **8 passed, 0 skipped, 0 failed** (`mesh_dynamic_aot_cpu` 0.53 s, `mesh_lane_spill_cpu` 0.18 s, `mesh_bitcmp_cpu` 0.41 s, `mesh_entry_skipped_scalar_cpu` 0.19 s, `mesh_join_descriptor_hardware` 3.15 s, `mesh_bitcmp_draw_hardware` 5.80 s, `mesh_join_descriptor_warp` 0.74 s, `mesh_bitcmp_draw_warp` 1.40 s; `debug_errors=0 debug_warnings=0`). - **`release` CTest:** **3 passed, 0 skipped, 0 failed** (`mesh_bitcmp_cpu` 0.41 s, `mesh_bitcmp_draw_hardware` 5.43 s, `mesh_bitcmp_draw_warp` 1.36 s; all draws `pixels=1024 mismatches=0`, `debug_errors=0 debug_warnings=0`, inverted `s_bitcmp0_b32` -> `s_bitcmp1_b32` GPU negative control failed with `pixels=1024 mismatches=1024`). - **Not run locally:** `tests/mesh_bitcmp_check.py binary llvm-mc-15` (`llvm-mc` is not installed on this Windows host); wired into the Ubuntu `pixel-binary` CI job. - **Scope note:** passing source-built fixtures verify bounded `s_bitcmp*` evaluation and descriptor-join branching in `mesh_entry_aot` / `mesh_dynamic_aot`; they do not establish full-game startup or direct slot-57 mesh emission.
ChazY11 commented 2026-11-25 19:04:13 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-25T18:28:53Z.


Five mutations, all caught — including the two that decide the predicate

Baseline: mesh s_bitcmp controls passed, exit 0.

mutation of the s_bitcmp{0,1}_b{32,64} lowering in mesh_entry_aot.py result
s_bitcmp0 predicate inverted (== ↔ !=) caught
the one-bit mask replaced with all-ones (1u << bit → ~0u) caught
the bit index shifted by one (1u << (bit + 1)) caught
the 64-bit operand check removed caught
the two-operand check removed caught

The first two are the whole instruction: SCC = (S0[S1] == 0) for bitcmp0 and != 0 for bitcmp1, so an inverted comparison and a mask that stops isolating one bit are the two ways to get a silently wrong predicate. Both are pinned, and so is the off-by-one in the index, which is the third.

The refusal rows matter for a different reason: this is the same translator-crash class the gfx2hlsl side has been closing — a short or wrong-width operand list must be a ValueError naming the requirement rather than an index error. Both surface here, so removing either is visible.

What I checked beyond the diff

  • docs/experiments.md gains the ISA citation (RDNA 2 ISA s9.3 (SOPC)) next to the lowering, which is the right place for it: the bit index width (5 bits for b32, 6 for b64) is the only non-obvious part, and it is exactly what a reader would get wrong.
  • The three-way registration (CMakeLists.txt, the Linux Run Python checks list, AGENTS.md) is present for mesh_bitcmp_check.py, so the new fixture actually runs in CI rather than only locally.

One suggestion

The b64 case is the one where the bit index can legitimately exceed 31, and the fixture's controls pass — but I could not find an assertion that pairs a 64-bit source with an index above 31 specifically. If that case is absent, it is the one I would add: it is the only input that distinguishes "index taken modulo 32" from "index used as-is", and the mutation above (bit + 1) was caught by some other case, not necessarily that one.

AI-assisted; the five mutations were run locally on Windows 11 build 26300.9974.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7170965733 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2444#issuecomment-7170965733). Originally posted by [ChazY11](https://github.com/ChazY11) on 2026-11-25T18:28:53Z. --- ## Five mutations, all caught — including the two that decide the predicate Baseline: `mesh s_bitcmp controls passed`, exit 0. | mutation of the `s_bitcmp{0,1}_b{32,64}` lowering in `mesh_entry_aot.py` | result | |---|---| | `s_bitcmp0` predicate inverted (`==` ↔ `!=`) | **caught** | | the one-bit mask replaced with all-ones (`1u << bit` → `~0u`) | **caught** | | the bit index shifted by one (`1u << (bit + 1)`) | **caught** | | the 64-bit operand check removed | **caught** | | the two-operand check removed | **caught** | The first two are the whole instruction: `SCC = (S0[S1] == 0)` for `bitcmp0` and `!= 0` for `bitcmp1`, so an inverted comparison and a mask that stops isolating one bit are the two ways to get a silently wrong predicate. Both are pinned, and so is the off-by-one in the index, which is the third. The refusal rows matter for a different reason: this is the same translator-crash class the `gfx2hlsl` side has been closing — a short or wrong-width operand list must be a `ValueError` naming the requirement rather than an index error. Both surface here, so removing either is visible. ## What I checked beyond the diff - `docs/experiments.md` gains the ISA citation (`RDNA 2 ISA s9.3 (SOPC)`) next to the lowering, which is the right place for it: the bit index width (5 bits for `b32`, 6 for `b64`) is the only non-obvious part, and it is exactly what a reader would get wrong. - The three-way registration (`CMakeLists.txt`, the Linux `Run Python checks` list, `AGENTS.md`) is present for `mesh_bitcmp_check.py`, so the new fixture actually runs in CI rather than only locally. ## One suggestion The `b64` case is the one where the bit index can legitimately exceed 31, and the fixture's controls pass — but I could not find an assertion that pairs a **64-bit** source with an index **above 31** specifically. If that case is absent, it is the one I would add: it is the only input that distinguishes "index taken modulo 32" from "index used as-is", and the mutation above (`bit + 1`) was caught by some other case, not necessarily that one. AI-assisted; the five mutations were run locally on Windows 11 build 26300.9974.
tedin7 commented 2026-11-25 20:04:14 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T19:24:00Z.

Review: COMMENTED


Review of head a60be126 (comment only, no merge from me).

Findings:

  • Overlap: #2438 (opened 11 minutes earlier, still open) lowers the same four ops (s_bitcmp0/1_b32, s_bitcmp0/1_b64) in tools/mesh_entry_aot.py with different code. This PR also covers tools/mesh_dynamic_aot.py and the Wave.steps() / exec_range() / descriptor_scalar_op() changes, so it is the wider slice. Two PRs for one slice is a design choice, so I leave it to @R0Y00 which one lands (the other then needs a rebase or a close).
  • Branch is 56 commits behind main and touches .github/workflows/windows.yml, so it needs an update with main and a fresh CI run before any merge. The new tests/mesh_bitcmp_check.py lines in pixel-binary and python-linux must run in that CI run.
  • Win2025 evidence is the author's own Windows run (contributor receipt). No receipt from our pool on the updated head.

Not done: no Win2025 run and no mutation run, because the choice between the two PRs comes first.

Commands run: gh pr view, gh pr list --search s_bitcmp, python3 merge_check.py 2444.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6063654880 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2444#pullrequestreview-6063654880). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T19:24:00Z. **Review:** COMMENTED --- Review of head a60be126 (comment only, no merge from me). Findings: - Overlap: #2438 (opened 11 minutes earlier, still open) lowers the same four ops (`s_bitcmp0/1_b32`, `s_bitcmp0/1_b64`) in `tools/mesh_entry_aot.py` with different code. This PR also covers `tools/mesh_dynamic_aot.py` and the `Wave.steps()` / `exec_range()` / `descriptor_scalar_op()` changes, so it is the wider slice. Two PRs for one slice is a design choice, so I leave it to @R0Y00 which one lands (the other then needs a rebase or a close). - Branch is 56 commits behind main and touches `.github/workflows/windows.yml`, so it needs an update with main and a fresh CI run before any merge. The new `tests/mesh_bitcmp_check.py` lines in `pixel-binary` and `python-linux` must run in that CI run. - Win2025 evidence is the author's own Windows run (contributor receipt). No receipt from our pool on the updated head. Not done: no Win2025 run and no mutation run, because the choice between the two PRs comes first. Commands run: `gh pr view`, `gh pr list --search s_bitcmp`, `python3 merge_check.py 2444`. AI-assisted; commands listed were executed locally.
MasterDomino commented 2026-11-25 20:04:42 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-25T19:20:54Z.


Routing note: this PR and #2438 (by @triggered02, opened 11 minutes earlier) both add s_bitcmp0_b32, s_bitcmp1_b32, s_bitcmp0_b64 and s_bitcmp1_b64 to tools/mesh_entry_aot.py, with different code. This PR also covers tools/mesh_dynamic_aot.py.

  • @tedin7 raised the overlap as a P2 in their review of #2438.
  • git merge-tree shows the two branches merge without a textual conflict, so both could land and leave two implementations of the same ops.

Competing implementations go to the maintainer. @R0Y00, could you pick one, or ask the authors to consolidate (for example, one PR takes mesh_entry_aot.py, the other only adds mesh_dynamic_aot.py)? I'm not reviewing either for merge until that's decided.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7172170057 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2444#issuecomment-7172170057). Originally posted by [MasterDomino](https://github.com/MasterDomino) on 2026-11-25T19:20:54Z. --- Routing note: this PR and #2438 (by @triggered02, opened 11 minutes earlier) both add `s_bitcmp0_b32`, `s_bitcmp1_b32`, `s_bitcmp0_b64` and `s_bitcmp1_b64` to `tools/mesh_entry_aot.py`, with different code. This PR also covers `tools/mesh_dynamic_aot.py`. - @tedin7 raised the overlap as a P2 in their review of #2438. - `git merge-tree` shows the two branches merge without a textual conflict, so both could land and leave two implementations of the same ops. Competing implementations go to the maintainer. @R0Y00, could you pick one, or ask the authors to consolidate (for example, one PR takes `mesh_entry_aot.py`, the other only adds `mesh_dynamic_aot.py`)? I'm not reviewing either for merge until that's decided. AI-assisted.
upstream-sync closed this pull request 2026-11-26 08:01:41 +00:00
R0Y00 commented 2026-11-26 08:01:41 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-26T07:30:20Z.

Review: APPROVED


The merged tree retains the #2438 concrete bitcmp model and its verified branch ordering. The new constant-buffer predicate is allowed only immediately before a supported descriptor join. Unsupported dynamic consumers keep their existing refusal. Windows Release passed all 9 CTests, zero skips, with both WARP and RTX 4060 Laptop draw readback and an inverted-predicate control. The original #2438 checks still pass.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6070060011 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2444#pullrequestreview-6070060011). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-26T07:30:20Z. **Review:** APPROVED --- The merged tree retains the #2438 concrete bitcmp model and its verified branch ordering. The new constant-buffer predicate is allowed only immediately before a supported descriptor join. Unsupported dynamic consumers keep their existing refusal. Windows Release passed all 9 CTests, zero skips, with both WARP and RTX 4060 Laptop draw readback and an inverted-predicate control. The original #2438 checks still pass.
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!2436
No description provided.