shader: lower compute v_bfm_b32 #1573

Merged
Asimmimx merged 3 commits from upstream-pr/1580 into main 2026-11-26 03:08:34 +00:00
Asimmimx commented 2026-11-24 14:34:44 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Asimmimx on 2026-11-24T14:34:44Z.


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).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6584193341 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1580). Originally posted by [Asimmimx](https://github.com/Asimmimx) on 2026-11-24T14:34:44Z. --- ## 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).
tedin7 commented 2026-11-24 16:03:08 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T15:39:32Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6042421481 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1580#pullrequestreview-6042421481). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T15:39:32Z. **Review:** COMMENTED --- 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 commented 2026-11-24 18:02:14 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T17:08:23Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6043876579 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1580#pullrequestreview-6043876579). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T17:08:23Z. **Review:** COMMENTED --- 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 commented 2026-11-24 18:02:14 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T17:39:54Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6044350093 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1580#pullrequestreview-6044350093). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T17:39:54Z. **Review:** COMMENTED --- 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 commented 2026-11-25 13:00:59 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T12:44:19Z.


@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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7162786444 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1580#issuecomment-7162786444). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T12:44:19Z. --- @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 commented 2026-11-26 03:03:25 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T02:53:21Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7181207737 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1580#issuecomment-7181207737). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T02:53:21Z. --- 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.
upstream-sync closed this pull request 2026-11-26 04:04:01 +00:00
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!1573
No description provided.