shader: lower gfx1013 s_bfm_b32 in pixel_aot #601

Manually merged
github merged 3 commits from gh-pr/601/head into gh-pr/601/base 2026-11-26 22:04:53 +00:00
Owner

@⁠JB2WIN on GitHub · 2026-11-22 15:08 UTC · original
JB2WIN:shader/s-bfm → main · +132 −6 · 6 files · 3 commits · merged 2026-11-22 15:48 UTC

Change

tools/pixel_aot.py now lowers s_bfm_b32 through the SCALAR table: ((1u << (S0 & 31u)) - 1u) << (S1 & 31u), with no SCC write. s_bfm_b64 was already lowered (SALU_HELPERS["s_bfm_b64"]); this follows its count-mask convention (& 63u there). The scanner picks the form up from the table.

  • Semantics source: LLVM 15 selects S_BFM_B32 for (shl (add (shl 1, a), -1), b) (SIInstructions.td, BFMPatterns). The 5-/6-bit count masking is the usual SOP2 convention and an assumption. I could not check it against the RDNA 2 ISA PDF, and docs/experiments.md says so.
  • Changed expectations: s_bfm_b32 s70, 4, 8 moves from the rejected to the supported list, and s_bfm_b32 leaves rejected_forms in tests/form_coverage_check.py. Five new rejections are added: VGPR source or destination, pair destination, s106, wrong operand count, and reads of pending scalar loads.

Fixes #596. AI-assisted (Claude Code).

Verification

Windows 11 (10.0.26200.9974), NVIDIA GeForce RTX 3080 (driver 32.0.16.2124) and WARP 10.0.26100.9818, head on c8a3fd9.

  • Static checks: the formula is emitted as shown. A following s_cselect_b32 keeps selecting on the earlier compare, which shows SCC is unchanged. This is checked statically only, and the docs say so.
  • New integer-export draw check_bfm_draw in the blend-scalar mode. Channels: two s_bfm_b32 results, plus s_bfm_b64 lo/hi. Five word sets cover counts 0, 1, 31, 32, 33, 63 and 64, plus wrapping offsets. Generated-HLSL controls narrow the count mask to 4 bits, or swap count and offset; each gives pixel_mismatch. Removing the mask entirely is not observable on the GPU, because DXIL masks shift amounts itself; the static check catches that case.
  • Targeted ctest: ctest --preset dev --no-tests=error -R "^(pixel_aot_|rdna2_tools_check$|pso_readiness)" passed 22/22. pixel_aot_blend_scalar_hardware took 36.7 s (timeout 60 s).
  • Full ctest: ctest --preset dev --no-tests=error passed 278/278, with skips bvh_wave64_hardware, bvh_wave64_warp and wave_shuffle_warp.
  • LLVM 15 round trip: tests/pixel_aot_check.py binary with LLVM 15.0.7 exited 0, run locally (fixture bfm_scalar_ops). The controls, form_coverage_check.py, docs_links_check.py and rdna2_tools_check.py pass.

Evidence and follow-up

  • Synthetic inputs only.
  • Timing note: #595 also adds a draw to the blend-scalar mode (34.7 s on its own branch). If both land, pixel_aot_blend_scalar_hardware on this RTX 3080 may get close to the 45 s budget the suite keeps under its 60 s timeout. Splitting one of them into its own mode would be the fix. I can do that in whichever PR lands second.

🤖 Generated with Claude Code

**@⁠JB2WIN** on GitHub · 2026-11-22 15:08 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/601) `JB2WIN:shader/s-bfm` → `main` · +132 −6 · 6 files · 3 commits · merged 2026-11-22 15:48 UTC ## Change `tools/pixel_aot.py` now lowers `s_bfm_b32` through the `SCALAR` table: `((1u << (S0 & 31u)) - 1u) << (S1 & 31u)`, with no SCC write. `s_bfm_b64` was already lowered (`SALU_HELPERS["s_bfm_b64"]`); this follows its count-mask convention (`& 63u` there). The scanner picks the form up from the table. - Semantics source: LLVM 15 selects `S_BFM_B32` for `(shl (add (shl 1, a), -1), b)` (`SIInstructions.td`, `BFMPatterns`). The 5-/6-bit count masking is the usual SOP2 convention and an **assumption**. I could not check it against the RDNA 2 ISA PDF, and `docs/experiments.md` says so. - **Changed expectations:** `s_bfm_b32 s70, 4, 8` moves from the rejected to the supported list, and `s_bfm_b32` leaves `rejected_forms` in `tests/form_coverage_check.py`. Five new rejections are added: VGPR source or destination, pair destination, `s106`, wrong operand count, and reads of pending scalar loads. Fixes #596. AI-assisted (Claude Code). ## Verification Windows 11 (10.0.26200.9974), NVIDIA GeForce RTX 3080 (driver 32.0.16.2124) and WARP 10.0.26100.9818, head on `c8a3fd9`. - **Static checks:** the formula is emitted as shown. A following `s_cselect_b32` keeps selecting on the earlier compare, which shows SCC is unchanged. This is checked statically only, and the docs say so. - **New integer-export draw `check_bfm_draw`** in the `blend-scalar` mode. Channels: two `s_bfm_b32` results, plus `s_bfm_b64` lo/hi. Five word sets cover counts 0, 1, 31, 32, 33, 63 and 64, plus wrapping offsets. Generated-HLSL controls narrow the count mask to 4 bits, or swap count and offset; each gives `pixel_mismatch`. Removing the mask entirely is not observable on the GPU, because DXIL masks shift amounts itself; the static check catches that case. - **Targeted ctest:** `ctest --preset dev --no-tests=error -R "^(pixel_aot_|rdna2_tools_check$|pso_readiness)"` passed 22/22. `pixel_aot_blend_scalar_hardware` took 36.7 s (timeout 60 s). - **Full ctest:** `ctest --preset dev --no-tests=error` passed 278/278, with skips `bvh_wave64_hardware`, `bvh_wave64_warp` and `wave_shuffle_warp`. - **LLVM 15 round trip:** `tests/pixel_aot_check.py binary` with LLVM 15.0.7 exited 0, run locally (fixture `bfm_scalar_ops`). The controls, `form_coverage_check.py`, `docs_links_check.py` and `rdna2_tools_check.py` pass. ## Evidence and follow-up - Synthetic inputs only. - **Timing note:** #595 also adds a draw to the `blend-scalar` mode (34.7 s on its own branch). If both land, `pixel_aot_blend_scalar_hardware` on this RTX 3080 may get close to the 45 s budget the suite keeps under its 60 s timeout. Splitting one of them into its own mode would be the fix. I can do that in whichever PR lands second. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Fixes #596

Add s_bfm_b32 to the scalar ALU table as
((1u << (S0 & 31u)) - 1u) << (S1 & 31u); SCC is not written.
s_bfm_b64 was already lowered on main (d8bf0c0); the new integer-export
draw now also covers it at counts 32, 63 and 64. Adds static lowering and
rejection checks, an LLVM 15 fixture, a draw with mutation controls,
scanner and form-coverage updates, and the docs paragraph.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 22:04:52 +00:00
github manually merged commit 2c39b5fb2f into gh-pr/601/base 2026-11-26 22:04:53 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.