shader: lower compute v_bfm_b32 #1580

Manually merged
github merged 3 commits from gh-pr/1580/head into gh-pr/1580/base 2026-11-26 23:18:25 +00:00
Owner

@⁠Asimmimx on GitHub · 2026-11-24 14:34 UTC · original
Asimmimx:shader/compute-bfm → main · +221 −1 · 4 files · 3 commits · merged 2026-11-26 03:08 UTC

Change

Refs #1546. This lowers v_bfm_b32 in the compute translator (tools/compute_store_aot.py). v_bfm_b32 vD, src0, src1 becomes (((1u << (src0 & 31u)) - 1u) << (src1 & 31u)):

  • src0 is the mask width and src1 its offset, both taken from bits [4:0].
  • A width of 0 gives 0. A width of 32 cannot be encoded, so the widest mask is 0x7fffffff.
  • Bits shifted past bit 31 are dropped.

Sources for these semantics:

  • LLVM 15 SIInstructions.td, BFMPatterns: (shl (add (shl 1, a), -1), b) is selected to V_BFM_B32_e64 a, b.
  • Mesa nir_opcodes.py bfm: ((1u << (src0 & 0x1F)) - 1) << (src1 & 0x1F).

The code change is one ALU entry, plus the opcode appended to the two-source VOP3 matcher: (v_mul_lo_u32|v_bfm_b32). The fixture and controls are in a new tests/compute_alu_bfm_check.py, which imports the helpers of tests/compute_store_check.py. That file itself is unchanged.

Fixture. It is a variant of READ_COMPUTE:

v2 = w >> 5
a  = bfm(v1, v2)
b  = bfm(s0, 0x7b)      s0 = params[0].y = 0xc0de0029, so b = 0xf8000000 (cut at bit 31)
c  = bfm(44, v0)
store a ^ b ^ c
  • The sources are VGPRs, an SGPR, a literal, an inline constant and the dispatch index. Every width and offset word has bits set above bit 4.
  • Across lanes 0..31 the widths take all 32 values: width 0 at lane 31, width 31 at lane 14.
  • The expected words come from a Python model that builds each mask bit by bit.
  • Five lanes are also worked by hand: 0 → 0x78000fff, 14 → 0x0bffc000, 31 → 0x78000000, 32 → 0x07ff0fff, 149 → 0xf81f8000.

Checks that must fail:

  • Seven wrong references, each at its first differing word:
    • one word off;
    • lane 150 writing;
    • operands swapped;
    • a 6-bit width field;
    • a 6-bit offset field;
    • width 0 read as 32;
    • cut bits rotated into the low bits.
  • Four HLSL mutants: - 1u dropped, an inline width of 43, the cap operands swapped, and the cap read from params[0].z.

Translator controls (refused with the existing messages):

  • the |v1|, -v1, clamp, v[1:2], vcc_lo, exec_lo and 0.5 forms;
  • v_bfm_b32_e64, s_bfm_b32, s_bfm_b64, v_bfe_u32 and v_bfi_b32;
  • unknown, descriptor, saved-exec and pending sources, a 33-bit literal and v256;
  • a read before s_waitcnt, the result used as an address or as a guard operand, and a chain that is too long.

The new CTest is compute_store_aot_alu_bfm_${adapter}, registered after compute_store_aot_f32. A "Bitfield mask (v_bfm_b32)" subsection is added to docs/experiments.md.

Verification

Commit 6c0e5380 (main) plus this change, dev preset, Windows 11 Pro build 26300.9974, DXC 1.8.2502.11.

python -B tests/compute_alu_bfm_check.py controls                                  # pass
python -B tests/compute_alu_bfm_check.py draw <dxc> <offscreen_check.exe> warp     # pass
python -B tests/compute_alu_bfm_check.py draw <dxc> <offscreen_check.exe> hardware # pass
ctest --preset dev --no-tests=error -R '^compute_store_aot_alu_bfm_(warp|hardware)$' -V
Backend Result
WARP 10.0.26100.9818, debug layer enabled 3 dispatches (0, 17, 150 lanes), 320 words each, mismatches 0, debug errors 0
AMD Radeon RX 6600 (RDNA 2, 1002:73ff), driver 32.0.21045.29003, debug layer enabled 3 dispatches, 320 words each, mismatches 0, debug errors 0

These also pass with the change:

  • the compute_store_check control functions (alu, f32, scalar_alu, read, guard);
  • draw-guard-read and draw-f32 on WARP;
  • tests/docs_links_check.py, tests/bidi_controls_check.py and git diff --check.

Notes

  • The fixture is a hand variant, not unchanged LLVM 15 output. It assembles and prints back identically with llvm-mc 19 for gfx1013.
  • The _e64 spelling is refused, on the assumption that LLVM 15 prints v_bfm_b32 without it, as it does for v_mul_lo_u32.
  • The explicit & 31u cannot be distinguished on the GPU, because DXIL masks shift amounts anyway. It is pinned by the translator text check.

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.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted (Claude Code).

**@⁠Asimmimx** on GitHub · 2026-11-24 14:34 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1580) `Asimmimx:shader/compute-bfm` → `main` · +221 −1 · 4 files · 3 commits · merged 2026-11-26 03:08 UTC ## Change Refs #1546. This lowers `v_bfm_b32` in the compute translator (`tools/compute_store_aot.py`). `v_bfm_b32 vD, src0, src1` becomes `(((1u << (src0 & 31u)) - 1u) << (src1 & 31u))`: - src0 is the mask width and src1 its offset, both taken from bits [4:0]. - A width of 0 gives 0. A width of 32 cannot be encoded, so the widest mask is `0x7fffffff`. - Bits shifted past bit 31 are dropped. Sources for these semantics: - LLVM 15 `SIInstructions.td`, `BFMPatterns`: `(shl (add (shl 1, a), -1), b)` is selected to `V_BFM_B32_e64 a, b`. - Mesa `nir_opcodes.py` `bfm`: `((1u << (src0 & 0x1F)) - 1) << (src1 & 0x1F)`. The code change is one `ALU` entry, plus the opcode appended to the two-source VOP3 matcher: `(v_mul_lo_u32|v_bfm_b32)`. The fixture and controls are in a new `tests/compute_alu_bfm_check.py`, which imports the helpers of `tests/compute_store_check.py`. That file itself is unchanged. **Fixture.** It is a variant of `READ_COMPUTE`: ``` v2 = w >> 5 a = bfm(v1, v2) b = bfm(s0, 0x7b) s0 = params[0].y = 0xc0de0029, so b = 0xf8000000 (cut at bit 31) c = bfm(44, v0) store a ^ b ^ c ``` - The sources are VGPRs, an SGPR, a literal, an inline constant and the dispatch index. Every width and offset word has bits set above bit 4. - Across lanes 0..31 the widths take all 32 values: width 0 at lane 31, width 31 at lane 14. - The expected words come from a Python model that builds each mask bit by bit. - Five lanes are also worked by hand: 0 → `0x78000fff`, 14 → `0x0bffc000`, 31 → `0x78000000`, 32 → `0x07ff0fff`, 149 → `0xf81f8000`. **Checks that must fail:** - Seven wrong references, each at its first differing word: - one word off; - lane 150 writing; - operands swapped; - a 6-bit width field; - a 6-bit offset field; - width 0 read as 32; - cut bits rotated into the low bits. - Four HLSL mutants: `- 1u` dropped, an inline width of 43, the cap operands swapped, and the cap read from `params[0].z`. **Translator controls** (refused with the existing messages): - the `|v1|`, `-v1`, `clamp`, `v[1:2]`, `vcc_lo`, `exec_lo` and `0.5` forms; - `v_bfm_b32_e64`, `s_bfm_b32`, `s_bfm_b64`, `v_bfe_u32` and `v_bfi_b32`; - unknown, descriptor, saved-exec and pending sources, a 33-bit literal and `v256`; - a read before `s_waitcnt`, the result used as an address or as a guard operand, and a chain that is too long. The new CTest is `compute_store_aot_alu_bfm_${adapter}`, registered after `compute_store_aot_f32`. A "Bitfield mask (`v_bfm_b32`)" subsection is added to `docs/experiments.md`. ## Verification Commit `6c0e5380` (`main`) plus this change, `dev` preset, Windows 11 Pro build 26300.9974, DXC 1.8.2502.11. ```powershell python -B tests/compute_alu_bfm_check.py controls # pass python -B tests/compute_alu_bfm_check.py draw <dxc> <offscreen_check.exe> warp # pass python -B tests/compute_alu_bfm_check.py draw <dxc> <offscreen_check.exe> hardware # pass ctest --preset dev --no-tests=error -R '^compute_store_aot_alu_bfm_(warp|hardware)$' -V ``` | Backend | Result | |---|---| | WARP 10.0.26100.9818, debug layer enabled | 3 dispatches (0, 17, 150 lanes), 320 words each, mismatches 0, debug errors 0 | | AMD Radeon RX 6600 (RDNA 2, `1002:73ff`), driver 32.0.21045.29003, debug layer enabled | 3 dispatches, 320 words each, mismatches 0, debug errors 0 | These also pass with the change: - the `compute_store_check` control functions (`alu`, `f32`, `scalar_alu`, `read`, `guard`); - `draw-guard-read` and `draw-f32` on WARP; - `tests/docs_links_check.py`, `tests/bidi_controls_check.py` and `git diff --check`. ## Notes - The fixture is a hand variant, not unchanged LLVM 15 output. It assembles and prints back identically with `llvm-mc` 19 for gfx1013. - The `_e64` spelling is refused, on the assumption that LLVM 15 prints `v_bfm_b32` without it, as it does for `v_mul_lo_u32`. - The explicit `& 31u` cannot be distinguished on the GPU, because DXIL masks shift amounts anyway. It is pinned by the translator text check. ## 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. - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted (Claude Code).
Refs #1546. v_bfm_b32 vD, a, b (VOP3 only on gfx10) becomes the inline
HLSL expression ((1u << (a & 31u)) - 1u) << (b & 31u): a width taken
from src0[4:0] and an offset from src1[4:0], modulo 2^32. A width field
of 0 gives an empty mask, a width of 32 cannot be encoded, and mask bits
shifted past bit 31 are dropped. This matches LLVM's BFM selection
pattern (shl (add (shl 1, a), -1), b) -> V_BFM_B32_e64 and Mesa's nir
bfm definition. Both sources must be known words, as for v_mul_lo_u32,
and the result is data only.

tests/compute_alu_bfm_check.py varies the read-compute-write fixture
by hand to store bfm(w, w >> 5) ^ bfm(cap, 0x7b) ^ bfm(44, gid). It
covers VGPR, SGPR, literal, inline and dispatch-index sources, every
width from 0 to 31 and masks cut at bit 31. Expected words come from a
bit-by-bit Python model, checked against five hand-worked lanes. On WARP
the full 320-word readback must match. Wrong references (operands
swapped, 6-bit fields, width 0 as 32, rotated bits, one word off, lane
150 writing) and four HLSL mutants must each fail. The translator
controls refuse modifiers, clamp, ranges, vcc_lo/exec_lo, a float
inline constant, the _e64 spelling, s_bfm and v_bfe/v_bfi, and unknown
sources.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 23:18:24 +00:00
github manually merged commit 72ebd5fc3c into gh-pr/1580/base 2026-11-26 23:18:25 +00:00
Author
Owner

@⁠tedin7 on GitHub · 2026-11-25 12:44 UTC · original

@⁠Asimmimx could you rebase this branch onto current main and force-push?

GitHub reports head fb05645f as conflicting with main, so it cannot be merged as is.

Files that conflict with current main (b1a644ae):

  • CMakeLists.txt
  • docs/experiments.md
  • tools/compute_store_aot.py

Commands run locally:

git fetch origin main pull/1580/head
git merge-tree --write-tree --name-only origin/main FETCH_HEAD
gh pr view 1580 --json mergeable   # CONFLICTING

Once it is rebased and CI is green it will be re-checked right away.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-25 12:44 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1580#issuecomment-7162786444) @⁠Asimmimx could you rebase this branch onto current `main` and force-push? GitHub reports head `fb05645f` as conflicting with `main`, so it cannot be merged as is. Files that conflict with current `main` (`b1a644ae`): - `CMakeLists.txt` - `docs/experiments.md` - `tools/compute_store_aot.py` Commands run locally: ``` git fetch origin main pull/1580/head git merge-tree --write-tree --name-only origin/main FETCH_HEAD gh pr view 1580 --json mergeable # CONFLICTING ``` Once it is rebased and CI is green it will be re-checked right away. AI-assisted; commands listed were executed locally.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-26 02:53 UTC · original

Merged origin/main into this branch (plain merge, no rebase) to clear the conflicts, and pushed f32d6d1a.

What I resolved (keep both sides):

  • CMakeLists.txt: kept main's FORM_COVERAGE_RECORD environment on the neighbouring tests and added the same environment to compute_store_aot_alu_bfm_*.
  • tools/compute_store_aot.py: added v_bfm_b32 to main's current VOP3 binary regex (main had added v_add_nc_i32, v_sub_nc_i32, v_bcnt_u32_b32 there).
  • docs/experiments.md: kept both sections.

Commands executed locally:

  • python3 tests/docs_links_check.py, python3 tests/bidi_controls_check.py, git diff --check: ok
  • python3 tests/compute_alu_bfm_check.py controls: ok
  • Win2025 WARP x2w_pipe.py win2025 1580 --patch <merge diff> --regex 'compute_store_aot_alu_bfm|compute_store_aot_.*_warp': dev 85/85, release 85/85 (includes compute_store_aot_alu_bfm_warp and _hardware on WARP)
  • Wider run (compute_store_aot|compute_alu|startup_compute) had 3 failures outside this change: startup_compute_dispatch_texture_warp/_hardware (already failing on main) and compute_store_aot_mac_f32_hardware (a mutation check of an existing test on the WARP adapter; its _warp twin passes).

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-26 02:53 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1580#issuecomment-7181207737) Merged `origin/main` into this branch (plain merge, no rebase) to clear the conflicts, and pushed f32d6d1a. What I resolved (keep both sides): - `CMakeLists.txt`: kept main's `FORM_COVERAGE_RECORD` environment on the neighbouring tests and added the same environment to `compute_store_aot_alu_bfm_*`. - `tools/compute_store_aot.py`: added `v_bfm_b32` to main's current VOP3 binary regex (main had added `v_add_nc_i32`, `v_sub_nc_i32`, `v_bcnt_u32_b32` there). - `docs/experiments.md`: kept both sections. Commands executed locally: - `python3 tests/docs_links_check.py`, `python3 tests/bidi_controls_check.py`, `git diff --check`: ok - `python3 tests/compute_alu_bfm_check.py controls`: ok - Win2025 WARP `x2w_pipe.py win2025 1580 --patch <merge diff> --regex 'compute_store_aot_alu_bfm|compute_store_aot_.*_warp'`: dev 85/85, release 85/85 (includes `compute_store_aot_alu_bfm_warp` and `_hardware` on WARP) - Wider run (`compute_store_aot|compute_alu|startup_compute`) had 3 failures outside this change: `startup_compute_dispatch_texture_warp`/`_hardware` (already failing on main) and `compute_store_aot_mac_f32_hardware` (a mutation check of an existing test on the WARP adapter; its `_warp` twin passes). AI-assisted; commands listed were executed locally.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 15:39 UTC · original · reviewed

Peer review at 993f4351 (shader: lower compute v_bfm_b32): looks good, no blocking issues found.

Code & Semantics Review

  • tools/compute_store_aot.py: v_bfm_b32 lowers to (((1u << ({0} & 31u)) - 1u) << ({1} & 31u)) and reuses the 2-source ALU_SOURCE, ALU_SOURCE matcher alongside v_mul_lo_u32, enforcing known-word sources, v0–v255 destination bounds, data-only usage, and ALU_EXPRESSION_LIMIT.
  • tests/compute_alu_bfm_check.py: covers VGPR, SGPR, literal, and inline-constant operands (including negative inline constants and widths 0–31), verifies hand-worked lanes and bit-by-bit CPU reference, rejects modifiers/other opcodes/unverified operands, and tests 7 wrong references + 4 DXC-compiled HLSL mutations in draw.
  • CMakeLists.txt & docs/experiments.md: registers compute_store_aot_alu_bfm_${adapter} and documents the lowering and controls.

Local Verification

  • Linux / LLVM-19:
    • python3 tests/compute_alu_bfm_check.py controls — passed
    • llvm-mc-19 -arch=amdgcn -mcpu=gfx1013 -show-encoding & -mcpu=gfx1030 on fixture v_bfm_b32 forms — passed
    • python3 tests/docs_links_check.py (16 Markdown files, 344 links) — passed
    • python3 tests/bidi_controls_check.py (1253 tracked files) — passed
  • Win2025 WARP (--preset dev Debug & --preset release /O2):
    • ctest --preset dev -R '^compute_store_aot_alu_bfm_warp$' (within 41/41 compute-store suite) — 41/41 passed (compute_store_aot_alu_bfm_warp 3.81s)
    • ctest --preset release -R '^compute_store_aot_alu_bfm_warp$' (within 41/41 compute-store suite) — 41/41 passed (compute_store_aot_alu_bfm_warp 3.74s)

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-24 15:39 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1580#pullrequestreview-6042421481) · **reviewed** Peer review at `993f4351` (`shader: lower compute v_bfm_b32`): looks good, no blocking issues found. ### Code & Semantics Review - `tools/compute_store_aot.py`: `v_bfm_b32` lowers to `(((1u << ({0} & 31u)) - 1u) << ({1} & 31u))` and reuses the 2-source `ALU_SOURCE, ALU_SOURCE` matcher alongside `v_mul_lo_u32`, enforcing known-word sources, `v0`–`v255` destination bounds, data-only usage, and `ALU_EXPRESSION_LIMIT`. - `tests/compute_alu_bfm_check.py`: covers VGPR, SGPR, literal, and inline-constant operands (including negative inline constants and widths 0–31), verifies hand-worked lanes and bit-by-bit CPU reference, rejects modifiers/other opcodes/unverified operands, and tests 7 wrong references + 4 DXC-compiled HLSL mutations in `draw`. - `CMakeLists.txt` & `docs/experiments.md`: registers `compute_store_aot_alu_bfm_${adapter}` and documents the lowering and controls. ### Local Verification - **Linux / LLVM-19**: - `python3 tests/compute_alu_bfm_check.py controls` — passed - `llvm-mc-19 -arch=amdgcn -mcpu=gfx1013 -show-encoding` & `-mcpu=gfx1030` on fixture `v_bfm_b32` forms — passed - `python3 tests/docs_links_check.py` (16 Markdown files, 344 links) — passed - `python3 tests/bidi_controls_check.py` (1253 tracked files) — passed - **Win2025 WARP (`--preset dev` Debug & `--preset release` `/O2`)**: - `ctest --preset dev -R '^compute_store_aot_alu_bfm_warp$'` (within 41/41 compute-store suite) — 41/41 passed (`compute_store_aot_alu_bfm_warp` `3.81s`) - `ctest --preset release -R '^compute_store_aot_alu_bfm_warp$'` (within 41/41 compute-store suite) — 41/41 passed (`compute_store_aot_alu_bfm_warp` `3.74s`) AI-assisted; commands listed were executed locally.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 17:08 UTC · original · reviewed

Re-review at head_sha: fb05645f624a10e4ba4bd27799145db09ec7a34a (previously reviewed at 993f4351).

Findings

No P1/P2. No defect found.

  • The new head is a rebase onto a newer main. I compared the patch of the old commit with the patch of this one (git range-diff, and a diff of the added and removed lines): the PR's own content is unchanged. Even the changed lines are the same; only the surrounding context differs.
  • git merge-tree of the head against current main (80f413a7 at the time) reports no conflicts (tree 17774c0c).

Verified

Limits: Linux x86-64 only. I did not rerun the Windows WARP/hardware ctest for this head (no Windows runner in this pass), so the draw mode is covered only by the unchanged patch content and the earlier Windows results on the previous head.

  • python3 -B tests/compute_alu_bfm_check.py controls -> exit 0.
  • llvm-mc-19 -triple=amdgcn-amd-amdhsa -mcpu=gfx1013 -show-encoding assembles v_bfm_b32 v1, v2, v3 and v_bfm_b32 v1, 5, s3.
  • python3 -B tests/docs_links_check.py -> 16 files, 351 links OK. git diff --check HEAD^ HEAD clean.
  • Mutation: changed the v_bfm_b32 template - 1u to - 2u; controls fails with an AssertionError (exit 1). Restored with git checkout -- .; git status --short clean.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-24 17:08 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1580#pullrequestreview-6043876579) · **reviewed** Re-review at `head_sha`: `fb05645f624a10e4ba4bd27799145db09ec7a34a` (previously reviewed at `993f4351`). ### Findings No P1/P2. No defect found. - The new head is a rebase onto a newer `main`. I compared the patch of the old commit with the patch of this one (`git range-diff`, and a diff of the added and removed lines): the PR's own content is unchanged. Even the changed lines are the same; only the surrounding context differs. - `git merge-tree` of the head against current `main` (`80f413a7` at the time) reports no conflicts (tree `17774c0c`). ### Verified Limits: Linux x86-64 only. I did not rerun the Windows WARP/hardware `ctest` for this head (no Windows runner in this pass), so the `draw` mode is covered only by the unchanged patch content and the earlier Windows results on the previous head. - `python3 -B tests/compute_alu_bfm_check.py controls` -> exit 0. - `llvm-mc-19 -triple=amdgcn-amd-amdhsa -mcpu=gfx1013 -show-encoding` assembles `v_bfm_b32 v1, v2, v3` and `v_bfm_b32 v1, 5, s3`. - `python3 -B tests/docs_links_check.py` -> 16 files, 351 links OK. `git diff --check HEAD^ HEAD` clean. - **Mutation:** changed the `v_bfm_b32` template `- 1u` to `- 2u`; `controls` fails with an `AssertionError` (exit 1). Restored with `git checkout -- .`; `git status --short` clean. AI-assisted; commands listed were executed locally.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 17:39 UTC · original · reviewed

Thanks for this PR. The earlier review at fb05645f found no blocking issues, but #1596 has since been merged and this branch now conflicts with main. Could you rebase onto the current main and push? After that I am happy to re-check the new head.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-24 17:39 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1580#pullrequestreview-6044350093) · **reviewed** Thanks for this PR. The earlier review at `fb05645f` found no blocking issues, but #1596 has since been merged and this branch now conflicts with `main`. Could you rebase onto the current `main` and push? After that I am happy to re-check the new head. AI-assisted; commands listed were executed locally.
This discussion has been locked. Commenting is limited to contributors.
No description provided.