gfx2hlsl: lower per-lane bit operations (bfe_i32, bcnt, ffbl, ffbh, bfrev) #1436

Merged
tedin7 merged 2 commits from upstream-pr/1443 into main 2026-11-24 12:02:57 +00:00
tedin7 commented 2026-11-24 11:34:10 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T11:34:10Z.


Change

tools/startup/gfx2hlsl.py refused six per-lane bit operations (Unsupported: v_bfe_i32 and the others). This lowers v_bfe_i32, v_bcnt_u32_b32, v_ffbl_b32, v_ffbh_u32, v_ffbh_i32 and v_bfrev_b32 to single HLSL expressions with the semantics tools/pixel_aot.py already uses. Source modifiers, clamp, op_sel and a wrong operand count are refused; the operand count is now checked for the whole integer table (a missing operand raised IndexError). The 64-bit carry forms, v_bfm_b32, 24-bit multiplies and v_alignbit_b32 stay out of scope for separate changes.

Outside --preset pr: startup_gfx2hlsl_bit_alu_controls, startup_gfx2hlsl_bit_alu_warp, startup_gfx2hlsl_bit_alu_hardware.

Verification

Linux, local (llvm-mc 19; llvm-mc 15 is not installed here, the CI job runs the binary mode with it):

  • python3 -B tests/startup_gfx2hlsl_bit_alu_check.py: all checks ok (17,459 bfe inputs, 324 bcnt, 81 per scan against an independent reference; six mutations each read a wrong word).
  • Same test on origin/main: fails with Unsupported: v_bfe_i32.
  • python3 -B tests/startup_gfx2hlsl_bit_alu_check.py binary llvm-mc-19: fixture words match, including the generated vertex stage for every draw set.
  • startup_gfx2hlsl_sdwa_check.py, startup_translator_check.py, startup_flat_param_check.py, startup_image_*_check.py, rdna2_tools_check.py, docs_links_check.py, bidi_controls_check.py: unchanged and passing.

Not run here: the draw mode (FXC ps_5_1, DXC ps_6_0, WARP and hardware readback through offscreen_check --startup-flat-param) needs the Windows toolchain.

Evidence and follow-up

Fixtures are assembled from original sources in the test file; the words are checked against llvm-mc. The reference uses bit loops, string reversal and integer arithmetic written from the ISA description, not the lowering's expressions. The draw mode also draws the mutated lowering and requires the mutated words. One assumption: results of 0xffffffff travel through a float render target unchanged, as the existing flat-parameter draw already relies on for NaN payloads.

AI-assisted; commands listed were executed locally.

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.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6580839731 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1443). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T11:34:10Z. --- ## Change `tools/startup/gfx2hlsl.py` refused six per-lane bit operations (`Unsupported: v_bfe_i32` and the others). This lowers `v_bfe_i32`, `v_bcnt_u32_b32`, `v_ffbl_b32`, `v_ffbh_u32`, `v_ffbh_i32` and `v_bfrev_b32` to single HLSL expressions with the semantics `tools/pixel_aot.py` already uses. Source modifiers, `clamp`, `op_sel` and a wrong operand count are refused; the operand count is now checked for the whole integer table (a missing operand raised `IndexError`). The 64-bit carry forms, `v_bfm_b32`, 24-bit multiplies and `v_alignbit_b32` stay out of scope for separate changes. Outside `--preset pr`: `startup_gfx2hlsl_bit_alu_controls`, `startup_gfx2hlsl_bit_alu_warp`, `startup_gfx2hlsl_bit_alu_hardware`. ## Verification Linux, local (llvm-mc 19; llvm-mc 15 is not installed here, the CI job runs the `binary` mode with it): - `python3 -B tests/startup_gfx2hlsl_bit_alu_check.py`: all checks ok (17,459 bfe inputs, 324 bcnt, 81 per scan against an independent reference; six mutations each read a wrong word). - Same test on `origin/main`: fails with `Unsupported: v_bfe_i32`. - `python3 -B tests/startup_gfx2hlsl_bit_alu_check.py binary llvm-mc-19`: fixture words match, including the generated vertex stage for every draw set. - `startup_gfx2hlsl_sdwa_check.py`, `startup_translator_check.py`, `startup_flat_param_check.py`, `startup_image_*_check.py`, `rdna2_tools_check.py`, `docs_links_check.py`, `bidi_controls_check.py`: unchanged and passing. Not run here: the `draw` mode (FXC ps_5_1, DXC ps_6_0, WARP and hardware readback through `offscreen_check --startup-flat-param`) needs the Windows toolchain. ## Evidence and follow-up Fixtures are assembled from original sources in the test file; the words are checked against llvm-mc. The reference uses bit loops, string reversal and integer arithmetic written from the ISA description, not the lowering's expressions. The draw mode also draws the mutated lowering and requires the mutated words. One assumption: results of 0xffffffff travel through a float render target unchanged, as the existing flat-parameter draw already relies on for NaN payloads. AI-assisted; commands listed were executed locally. ## 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.
tedin7 commented 2026-11-24 12:03:17 +00:00 (Migrated from github.com)

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


AI-assisted. Fixed in 75908557 (test only, lowering unchanged). The v_bcnt_u32_b32 mutation dropped the addend, so the mutated pixel stage no longer read the second flat parameter set and the WARP readback was all zero. It now subtracts the addend (same inputs read as the correct lowering). Expected mutated words now come from a plain integer definition per mutation (MUTATION_REF), cross-checked against the CPU evaluator over the whole grid. Draw mode for the new mutated words is not yet run on WARP: ctest --preset dev -R startup_gfx2hlsl_bit_alu (Debug and /O2).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7130376473 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1443#issuecomment-7130376473). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T11:39:20Z. --- AI-assisted. Fixed in 75908557 (test only, lowering unchanged). The v_bcnt_u32_b32 mutation dropped the addend, so the mutated pixel stage no longer read the second flat parameter set and the WARP readback was all zero. It now subtracts the addend (same inputs read as the correct lowering). Expected mutated words now come from a plain integer definition per mutation (MUTATION_REF), cross-checked against the CPU evaluator over the whole grid. Draw mode for the new mutated words is not yet run on WARP: ctest --preset dev -R startup_gfx2hlsl_bit_alu (Debug and /O2).
tedin7 commented 2026-11-24 12:03:17 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T11:42:21Z.


@codex review

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7130440328 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1443#issuecomment-7130440328). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T11:42:21Z. --- @codex review
tedin7 commented 2026-11-24 12:03:18 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T11:42:45Z.


Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit 75908557:

  • Debug (--preset dev): ctest --preset dev -R '^(startup_gfx2hlsl_bit_alu_controls|startup_gfx2hlsl_bit_alu_warp)$' --no-tests=error --output-on-failure — 2/2 passed (startup_gfx2hlsl_bit_alu_controls 0.65s, startup_gfx2hlsl_bit_alu_warp 4.63s)
  • Release /O2 (--preset release): ctest --preset release -R '^(startup_gfx2hlsl_bit_alu_controls|startup_gfx2hlsl_bit_alu_warp)$' --no-tests=error --output-on-failure — 2/2 passed (startup_gfx2hlsl_bit_alu_controls 0.69s, startup_gfx2hlsl_bit_alu_warp 4.79s)
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7130449013 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1443#issuecomment-7130449013). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T11:42:45Z. --- Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit `75908557`: - **Debug (`--preset dev`)**: `ctest --preset dev -R '^(startup_gfx2hlsl_bit_alu_controls|startup_gfx2hlsl_bit_alu_warp)$' --no-tests=error --output-on-failure` — **2/2 passed** (`startup_gfx2hlsl_bit_alu_controls` 0.65s, `startup_gfx2hlsl_bit_alu_warp` 4.63s) - **Release `/O2` (`--preset release`)**: `ctest --preset release -R '^(startup_gfx2hlsl_bit_alu_controls|startup_gfx2hlsl_bit_alu_warp)$' --no-tests=error --output-on-failure` — **2/2 passed** (`startup_gfx2hlsl_bit_alu_controls` 0.69s, `startup_gfx2hlsl_bit_alu_warp` 4.79s)
chatgpt-codex-connector[bot commented 2026-11-24 12:03:18 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T11:46:41Z.


Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: 75908557c8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7130535111 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1443#issuecomment-7130535111). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T11:46:41Z. --- <!-- codex-review-receipt:v1 --> Codex Review: Didn't find any major issues. Bravo. **Reviewed commit:** `75908557c8` <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". </details>
chatgpt-codex-connector[bot commented 2026-11-24 12:03:19 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T11:38:11Z.


Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T11:46:42.505744Z 7590855 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7130352247 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1443#issuecomment-7130352247). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T11:38:11Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"75908557c812132990b292fe9734fbf0ddfff713","has_any_findings":false,"has_unresolved_findings":false,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-24T11:46:42.505744Z">2026-11-24T11:46:42.505744Z</relative-time> | `7590855` | Manual request | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review" or "@codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
upstream-sync closed this pull request 2026-11-24 13:00:28 +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!1436
No description provided.