startup: lower s_bitset0_b32 and s_bitset1_b32 in gfx2hlsl #2412

Closed
R0D4X wants to merge 1 commit from upstream-pr/2420 into main
R0D4X commented 2026-11-25 16:08:56 +00:00 (Migrated from github.com)

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


Summary

  • Lower the 32-bit SOP1 scalar bit clear/set instructions (s_bitset0_b32 and s_bitset1_b32) in tools/startup/gfx2hlsl.py (Stage.scalar_bitset()), addressing #2023 Item J (s_bitset1_b32) and its exact 32-bit counterpart without altering Pipeline.common().
  • Follow AMD RDNA 2 ISA §12.3 (SOP1 opcodes 0x1b / 0x1d) and LLVM 15 SOPInstructions.td: read D and S0 before updating D, mask bit index with S0 & 31u, fold constant D + constant S0 to ('const', value), and leave SCC unchanged (READ_MODIFY_WRITE already covers s_bitset).
  • Refuse lane masks (masks, execcopy, vcc*, exec*), non-numeric symbols (desc, descnum, ptr, ptrhi, smpheap, unassigned constants), m0 as destination, vector/pair/>105 registers, float literals, modifiers, wrong operand counts, and 64-bit forms (s_bitset0_b64 / s_bitset1_b64) before mutating scalar state.
  • Add tests/startup_gfx2hlsl_bitset_check.py covering CPU reference evaluation across SGPR/inline/literal/m0/D == S0 aliasing, SCC preservation (s_cmp_* -> s_bitset* -> s_cselect_b32), constant folding, uniformity, state-intact refusals, 8 mutation controls, binary <llvm-mc> assembly checks, and FXC ps_5_1 + DXC ps_6_0 offscreen draw readbacks (including GPU mutation controls).
  • Register startup_gfx2hlsl_bitset_{controls,warp,hardware} in CMakeLists.txt and wire tests/startup_gfx2hlsl_bitset_check.py into pixel-binary and python-linux in .github/workflows/windows.yml.

Refs #2023

Verification

  • Base commit: 7092683a (upstream/main)
  • Branch commit: 4fc70315 (feat/gfx2hlsl-bitset-b32)
  • Host environment: Windows 11 x64 (26300.9974), MSVC 19.44.35230, Windows SDK 10.0.26100.0, FXC + 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/startup_gfx2hlsl_bitset_check.py
.\out\pe-env\Scripts\python.exe -B tests/startup_gfx2hlsl_sopk_accum_check.py
.\out\pe-env\Scripts\python.exe -B tests/startup_gfx2hlsl_sop2_complement_check.py
.\out\pe-env\Scripts\python.exe -B tests/startup_gfx2hlsl_scalar_m0_check.py
.\out\pe-env\Scripts\python.exe -B tests/startup_gfx2hlsl_scalar_shift64_bfe_check.py
.\out\pe-env\Scripts\python.exe -B tests/startup_gfx2hlsl_scalar_brev_fold_check.py
.\out\pe-env\Scripts\python.exe -B tests/startup_gfx2hlsl_handler_arity_check.py
.\out\pe-env\Scripts\python.exe -B tests/startup_gfx2hlsl_operand_count_check.py
.\out\pe-env\Scripts\python.exe -B tests/startup_gfx2hlsl_bit_alu_check.py
.\out\pe-env\Scripts\python.exe -B tests/startup_translator_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 '^(startup_gfx2hlsl_bitset_|startup_tools_lint$)' -V
ctest --preset release --no-tests=error -j 1 -R '^startup_gfx2hlsl_bitset_' -V
  • Observed: all Python/neighbor/lint/docs/bidi checks passed (startup_gfx2hlsl_bitset_check.py: 13/13 checks ok, 8/8 in-process mutations caught; docs_links_check.py: 19 files / 464 links; bidi_controls_check.py: 1723 files; git diff --check: clean).
  • On-disk self-mutation test (dropping & 31u in tools/startup/gfx2hlsl.py): caught (rc=1) and reverted cleanly.
  • dev: 4 passed, 0 skipped, 0 failed (startup_tools_lint 0.15 s, controls 0.62 s, warp 1.05 s, hardware 2.26 s; debug_errors=0 debug_warnings=0 on WARP and RTX 5080 for both FXC ps_5_1 and DXC ps_6_0, including GPU mutation controls).
  • release: 3 passed, 0 skipped, 0 failed (controls 0.61 s, warp 0.99 s, hardware 2.13 s; debug_errors=0 debug_warnings=0).
  • Note: tests/startup_gfx2hlsl_bitset_check.py binary llvm-mc-15 was not run locally (llvm-mc is not installed on this Windows host) and is covered by the Ubuntu pixel-binary CI job.
  • Scope note: these passing fixtures verify s_bitset0_b32 / s_bitset1_b32 lowering and desktop GPU execution in isolation; they do not establish full-game startup.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6608590938 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2420). Originally posted by [R0D4X](https://github.com/R0D4X) on 2026-11-25T16:08:56Z. --- ## Summary - Lower the 32-bit SOP1 scalar bit clear/set instructions (`s_bitset0_b32` and `s_bitset1_b32`) in `tools/startup/gfx2hlsl.py` (`Stage.scalar_bitset()`), addressing #2023 Item J (`s_bitset1_b32`) and its exact 32-bit counterpart without altering `Pipeline.common()`. - Follow AMD RDNA 2 ISA §12.3 (SOP1 opcodes `0x1b` / `0x1d`) and LLVM 15 `SOPInstructions.td`: read `D` and `S0` before updating `D`, mask bit index with `S0 & 31u`, fold constant `D` + constant `S0` to `('const', value)`, and leave `SCC` unchanged (`READ_MODIFY_WRITE` already covers `s_bitset`). - Refuse lane masks (`masks`, `execcopy`, `vcc*`, `exec*`), non-numeric symbols (`desc`, `descnum`, `ptr`, `ptrhi`, `smpheap`, unassigned constants), `m0` as destination, vector/pair/`>105` registers, float literals, modifiers, wrong operand counts, and 64-bit forms (`s_bitset0_b64` / `s_bitset1_b64`) before mutating scalar state. - Add `tests/startup_gfx2hlsl_bitset_check.py` covering CPU reference evaluation across SGPR/inline/literal/`m0`/`D == S0` aliasing, `SCC` preservation (`s_cmp_*` -> `s_bitset*` -> `s_cselect_b32`), constant folding, uniformity, state-intact refusals, 8 mutation controls, `binary <llvm-mc>` assembly checks, and FXC `ps_5_1` + DXC `ps_6_0` offscreen draw readbacks (including GPU mutation controls). - Register `startup_gfx2hlsl_bitset_{controls,warp,hardware}` in `CMakeLists.txt` and wire `tests/startup_gfx2hlsl_bitset_check.py` into `pixel-binary` and `python-linux` in `.github/workflows/windows.yml`. Refs #2023 ## Verification - **Base commit:** `7092683a` (`upstream/main`) - **Branch commit:** `4fc70315` (`feat/gfx2hlsl-bitset-b32`) - **Host environment:** Windows 11 x64 (`26300.9974`), MSVC `19.44.35230`, Windows SDK `10.0.26100.0`, FXC + 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/startup_gfx2hlsl_bitset_check.py .\out\pe-env\Scripts\python.exe -B tests/startup_gfx2hlsl_sopk_accum_check.py .\out\pe-env\Scripts\python.exe -B tests/startup_gfx2hlsl_sop2_complement_check.py .\out\pe-env\Scripts\python.exe -B tests/startup_gfx2hlsl_scalar_m0_check.py .\out\pe-env\Scripts\python.exe -B tests/startup_gfx2hlsl_scalar_shift64_bfe_check.py .\out\pe-env\Scripts\python.exe -B tests/startup_gfx2hlsl_scalar_brev_fold_check.py .\out\pe-env\Scripts\python.exe -B tests/startup_gfx2hlsl_handler_arity_check.py .\out\pe-env\Scripts\python.exe -B tests/startup_gfx2hlsl_operand_count_check.py .\out\pe-env\Scripts\python.exe -B tests/startup_gfx2hlsl_bit_alu_check.py .\out\pe-env\Scripts\python.exe -B tests/startup_translator_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 '^(startup_gfx2hlsl_bitset_|startup_tools_lint$)' -V ctest --preset release --no-tests=error -j 1 -R '^startup_gfx2hlsl_bitset_' -V ``` - Observed: all Python/neighbor/lint/docs/bidi checks passed (`startup_gfx2hlsl_bitset_check.py`: 13/13 checks `ok`, 8/8 in-process mutations caught; `docs_links_check.py`: 19 files / 464 links; `bidi_controls_check.py`: 1723 files; `git diff --check`: clean). - On-disk self-mutation test (dropping `& 31u` in `tools/startup/gfx2hlsl.py`): caught (`rc=1`) and reverted cleanly. - `dev`: **4 passed, 0 skipped, 0 failed** (`startup_tools_lint` 0.15 s, `controls` 0.62 s, `warp` 1.05 s, `hardware` 2.26 s; `debug_errors=0 debug_warnings=0` on WARP and RTX 5080 for both FXC `ps_5_1` and DXC `ps_6_0`, including GPU mutation controls). - `release`: **3 passed, 0 skipped, 0 failed** (`controls` 0.61 s, `warp` 0.99 s, `hardware` 2.13 s; `debug_errors=0 debug_warnings=0`). - Note: `tests/startup_gfx2hlsl_bitset_check.py binary llvm-mc-15` was not run locally (`llvm-mc` is not installed on this Windows host) and is covered by the Ubuntu `pixel-binary` CI job. - Scope note: these passing fixtures verify `s_bitset0_b32` / `s_bitset1_b32` lowering and desktop GPU execution in isolation; they do not establish full-game startup.
KelboLive commented 2026-11-25 17:01:57 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-25T16:13:01Z.


APPROVED. Lowers s_bitset0_b32 and s_bitset1_b32 in gfx2hlsl.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7167694456 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2420#issuecomment-7167694456). Originally posted by [KelboLive](https://github.com/KelboLive) on 2026-11-25T16:13:01Z. --- APPROVED. Lowers s_bitset0_b32 and s_bitset1_b32 in gfx2hlsl.
tedin7 commented 2026-11-25 19:03:39 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T18:32:15Z.

Review: COMMENTED


Review of head 4fc70315 (comment only, no approval).

Code (tools/startup/gfx2hlsl.py): scalar_bitset lowers s_bitset0_b32 and s_bitset1_b32 as D = D & ~(1<<(S0&31)) and D = D | (1<<(S0&31)), with SCC unchanged. This matches the SOP1 definition. D is read before it is written, so the lane-mask, execcopy and descriptor/symbol refusals run before any state changes. Source forms (SGPR, m0, inline/literal constants) are range-checked. When both D and S0 are known constants the result is folded. Otherwise a runtime expression is emitted. self.masks and is_lane_mask are existing members.

Test: tests/startup_gfx2hlsl_bitset_check.py has an evaluator check, refusals, built-in mutation controls (drop S0 lane-mask refusal, drop D symbol refusal, remove the bitset1 lowering; each caught), and WARP/hardware draw readbacks. It is registered in CMakeLists.txt (controls, warp, hardware) and in both lists in windows.yml. The PR's own CI run exercised the changed workflow: pixel-binary, python-linux and the Windows build are green.

Siblings and duplicates: a search for s_bitset found #574 (merged, pixel_aot, a different file) and #2028 (closed, a different author, covered bitset1 plus ff1). No open PR covers the same slice. No "depends on" in the body.

Windows results: the body lists runs on branch commit 4fc70315, which is this exact head. I did not run Windows and did not re-check those results. The body notes the binary llvm-mc-15 mode was not run on the author's host. It is covered by the green pixel-binary CI job. No startup claim is made. The PR is 30 commits behind main and I did not update it, to keep the head SHA.

Commands run locally on this head:

  • python3 -B tests/startup_gfx2hlsl_bitset_check.py (ok, including its 3 built-in mutations)
  • git diff --check origin/main...HEAD (clean)
  • python3 tests/docs_links_check.py (19 files, 464 links ok)
  • python3 tests/bidi_controls_check.py (ok)

No blocking findings. Merge is left to @R0Y00 / MasterDomino.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6062935005 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2420#pullrequestreview-6062935005). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T18:32:15Z. **Review:** COMMENTED --- Review of head 4fc70315 (comment only, no approval). Code (tools/startup/gfx2hlsl.py): `scalar_bitset` lowers `s_bitset0_b32` and `s_bitset1_b32` as D = D & ~(1<<(S0&31)) and D = D | (1<<(S0&31)), with SCC unchanged. This matches the SOP1 definition. D is read before it is written, so the lane-mask, execcopy and descriptor/symbol refusals run before any state changes. Source forms (SGPR, m0, inline/literal constants) are range-checked. When both D and S0 are known constants the result is folded. Otherwise a runtime expression is emitted. `self.masks` and `is_lane_mask` are existing members. Test: tests/startup_gfx2hlsl_bitset_check.py has an evaluator check, refusals, built-in mutation controls (drop S0 lane-mask refusal, drop D symbol refusal, remove the bitset1 lowering; each caught), and WARP/hardware draw readbacks. It is registered in CMakeLists.txt (controls, warp, hardware) and in both lists in windows.yml. The PR's own CI run exercised the changed workflow: pixel-binary, python-linux and the Windows build are green. Siblings and duplicates: a search for s_bitset found #574 (merged, pixel_aot, a different file) and #2028 (closed, a different author, covered bitset1 plus ff1). No open PR covers the same slice. No "depends on" in the body. Windows results: the body lists runs on branch commit 4fc70315, which is this exact head. I did not run Windows and did not re-check those results. The body notes the `binary llvm-mc-15` mode was not run on the author's host. It is covered by the green pixel-binary CI job. No startup claim is made. The PR is 30 commits behind main and I did not update it, to keep the head SHA. Commands run locally on this head: - python3 -B tests/startup_gfx2hlsl_bitset_check.py (ok, including its 3 built-in mutations) - git diff --check origin/main...HEAD (clean) - python3 tests/docs_links_check.py (19 files, 464 links ok) - python3 tests/bidi_controls_check.py (ok) No blocking findings. Merge is left to @R0Y00 / MasterDomino. AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-26 03:02:53 +00:00
tedin7 commented 2026-11-26 03:03:22 +00:00 (Migrated from github.com)

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


Closing this as already covered: s_bitset0_b32 and s_bitset1_b32 are lowered in tools/startup/gfx2hlsl.py on main through #2638, which merged first. All six forms this PR adds are present on current main, so landing it now would only conflict.

Thank you for the work here. If this PR handles a case #2638 does not (an operand form or a stage it refuses), please reopen it or open a small follow-up on top of current main with just that case and its WARP readback, and we will review it right away.

Commands executed:

gh pr diff 2420 -R R0Y00/Xbox2Windows            # forms added by this PR
git grep -F <form> origin/main -- tools/startup/gfx2hlsl.py   # each one present on main

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7180785923 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2420#issuecomment-7180785923). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T02:25:07Z. --- Closing this as already covered: `s_bitset0_b32` and `s_bitset1_b32` are lowered in `tools/startup/gfx2hlsl.py` on `main` through #2638, which merged first. All six forms this PR adds are present on current `main`, so landing it now would only conflict. Thank you for the work here. If this PR handles a case #2638 does not (an operand form or a stage it refuses), please reopen it or open a small follow-up on top of current `main` with just that case and its WARP readback, and we will review it right away. Commands executed: ``` gh pr diff 2420 -R R0Y00/Xbox2Windows # forms added by this PR git grep -F <form> origin/main -- tools/startup/gfx2hlsl.py # each one present on main ``` AI-assisted; commands listed were executed locally.

Pull request closed

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!2412
No description provided.