shader: lower vector bitfield, population count and bit scans #430

Merged
Joacoorandom merged 6 commits from upstream-pr/436 into main 2026-11-23 09:41:58 +00:00
Joacoorandom commented 2026-11-22 02:51:20 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Joacoorandom on 2026-11-22T02:51:20Z.


Change

The pixel translator currently rejects vector bitfield extraction/masks, population counts, bit reversal and bit scans. Add twelve instruction forms covering v_bfe_u32, v_bfe_i32, v_bfm_b32, v_bcnt_u32_b32, and e32/e64 v_bfrev_b32, v_ffbh_u32, v_ffbh_i32, v_ffbl_b32.

Preserve raw VGPR bits through HLSL, mask offsets and widths to five bits, handle signed extracts crossing bit 31, wrapping population-count addition and the all-zero/all-sign-bit scan sentinel. Pending loads/samples, entry execution-mask restrictions and unsupported modifiers remain guarded.

This touches tools/pixel_aot.py:lower and its helper selection. No prerequisite PR. #329's SDWA work also touches the pixel translator, but SDWA/DPP variants are outside this change.

Verification

Latest integration: f3aeede, merging upstream f8d11ad while retaining the existing PR head f85b327. Resolved README, experiment notes, coverage checks, binary-fixture registration, draw dispatch and HLSL helper selection. The current main draw-core/other draw modes, DPP fixtures and float-to-int helpers are retained.

On this integration, the LLVM 18 binary round trip, tests/form_coverage_check.py, tests/docs_links_check.py, tests/bidi_controls_check.py and git diff --check passed. The focused vector-bit matrix also passed on native Windows WARP 10.0.26100.9818: 192 positive draws, twelve wrong-reference controls, zero pixel error and no skips (debug layer unavailable). This check used the merged Python translator/test and helper include with the previously built renderer; it was not a full rebuild of current main.

Exact focused native command:

out/python/python.exe -B tests/pixel_aot_check.py bits "C:/Program Files (x86)/Windows Kits/10/bin/10.0.26100.0/x64/dxc.exe" out/native/offscreen_check.exe warp

The results below are historical measurements of the indicated earlier commits; the new integration starts fresh CI.

Commit 8e3158c, based on upstream 73ed4b7. Includes the newly merged #322 capability-skip fix. Windows 11 build 26300.9974, MSVC/ML64 19.44.35230, Windows SDK 10.0.26100 DXC, Python 3.12.8.

After rebasing, rebuilt the renderer and passed both selected WARP tests:

cmake --build out/native --target offscreen_check --parallel 4
ctest --test-dir out/native --no-tests=error -R "^pixel_aot_(bits_warp|warp)$" --output-on-failure

On the pre-rebase implementation 9373f17 (base 6ee2406), ran:

ctest --test-dir out/native --no-tests=error -R "^pixel_aot_bits_(hardware|warp)$" -V

Both new tests passed: NVIDIA GeForce RTX 3060 (10de:2503), driver 32.0.16.2101, in 113.72 seconds; WARP 10.0.26100.9818 in 8.46 seconds. Each backend checked 192 positive draws and twelve deliberately wrong references. Zero pixel error; no capability skips. The debug layer was unavailable. Hardware has not been rerun after rebasing.

Linux checks passed on the rebased commit:

python -B tests/pixel_aot_check.py binary /usr/lib/llvm-18/bin/llvm-mc /usr/lib/llvm-18/bin/llvm-objcopy /usr/lib/x86_64-linux-gnu/libLLVM-18.so
python -B tests/form_coverage_check.py
python -B tests/docs_links_check.py
git diff --check

LLVM 18 assembled/disassembled all twelve gfx1013 forms and binary-derived HLSL matched source lowering. Coverage checks require exactly twelve added forms in each GPU reference list and refuse coverage from failed or skipped tests.

The legacy pixel_aot_hardware reached its separate 60-second timeout during earlier validation. It is not counted as a pass or capability skip. The original serial new-test matrix exceeded 180 seconds; four independent renderer workers, separate case files and per-process deadlines completed the same matrix within the budget. Full-suite success is not claimed.

Evidence and follow-up

The source-built assembly fixtures, translator changes and independent Python bit-loop reference are original MIT code. Sixteen input sets cover offset/width masking, signed boundaries, zero/all-one values, scan sentinels and population-count wraparound. Every 32-bit result is exported as four exact byte-valued channels; all twelve wrong references must report a pixel mismatch. Acceptance-only checks do not add forms to unrelated draw records.

README and docs/experiments.md document the supported forms, limits and reproduction commands. No proprietary binaries or prototype apps are included.

AI-assisted implementation and tests.

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:6537579351 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/436). Originally posted by [Joacoorandom](https://github.com/Joacoorandom) on 2026-11-22T02:51:20Z. --- ## Change The pixel translator currently rejects vector bitfield extraction/masks, population counts, bit reversal and bit scans. Add twelve instruction forms covering `v_bfe_u32`, `v_bfe_i32`, `v_bfm_b32`, `v_bcnt_u32_b32`, and e32/e64 `v_bfrev_b32`, `v_ffbh_u32`, `v_ffbh_i32`, `v_ffbl_b32`. Preserve raw VGPR bits through HLSL, mask offsets and widths to five bits, handle signed extracts crossing bit 31, wrapping population-count addition and the all-zero/all-sign-bit scan sentinel. Pending loads/samples, entry execution-mask restrictions and unsupported modifiers remain guarded. This touches `tools/pixel_aot.py:lower` and its helper selection. No prerequisite PR. #329's SDWA work also touches the pixel translator, but SDWA/DPP variants are outside this change. ## Verification Latest integration: `f3aeede`, merging upstream `f8d11ad` while retaining the existing PR head `f85b327`. Resolved README, experiment notes, coverage checks, binary-fixture registration, draw dispatch and HLSL helper selection. The current main draw-core/other draw modes, DPP fixtures and float-to-int helpers are retained. On this integration, the LLVM 18 binary round trip, `tests/form_coverage_check.py`, `tests/docs_links_check.py`, `tests/bidi_controls_check.py` and `git diff --check` passed. The focused vector-bit matrix also passed on native Windows WARP 10.0.26100.9818: 192 positive draws, twelve wrong-reference controls, zero pixel error and no skips (debug layer unavailable). This check used the merged Python translator/test and helper include with the previously built renderer; it was not a full rebuild of current main. Exact focused native command: ```powershell out/python/python.exe -B tests/pixel_aot_check.py bits "C:/Program Files (x86)/Windows Kits/10/bin/10.0.26100.0/x64/dxc.exe" out/native/offscreen_check.exe warp ``` The results below are historical measurements of the indicated earlier commits; the new integration starts fresh CI. Commit `8e3158c`, based on upstream `73ed4b7`. Includes the newly merged #322 capability-skip fix. Windows 11 build 26300.9974, MSVC/ML64 19.44.35230, Windows SDK 10.0.26100 DXC, Python 3.12.8. After rebasing, rebuilt the renderer and passed both selected WARP tests: ```powershell cmake --build out/native --target offscreen_check --parallel 4 ctest --test-dir out/native --no-tests=error -R "^pixel_aot_(bits_warp|warp)$" --output-on-failure ``` On the pre-rebase implementation `9373f17` (base `6ee2406`), ran: ```powershell ctest --test-dir out/native --no-tests=error -R "^pixel_aot_bits_(hardware|warp)$" -V ``` Both new tests passed: NVIDIA GeForce RTX 3060 (10de:2503), driver 32.0.16.2101, in 113.72 seconds; WARP 10.0.26100.9818 in 8.46 seconds. Each backend checked 192 positive draws and twelve deliberately wrong references. Zero pixel error; no capability skips. The debug layer was unavailable. Hardware has not been rerun after rebasing. Linux checks passed on the rebased commit: ```bash python -B tests/pixel_aot_check.py binary /usr/lib/llvm-18/bin/llvm-mc /usr/lib/llvm-18/bin/llvm-objcopy /usr/lib/x86_64-linux-gnu/libLLVM-18.so python -B tests/form_coverage_check.py python -B tests/docs_links_check.py git diff --check ``` LLVM 18 assembled/disassembled all twelve gfx1013 forms and binary-derived HLSL matched source lowering. Coverage checks require exactly twelve added forms in each GPU reference list and refuse coverage from failed or skipped tests. The legacy `pixel_aot_hardware` reached its separate 60-second timeout during earlier validation. It is not counted as a pass or capability skip. The original serial new-test matrix exceeded 180 seconds; four independent renderer workers, separate case files and per-process deadlines completed the same matrix within the budget. Full-suite success is not claimed. ## Evidence and follow-up The source-built assembly fixtures, translator changes and independent Python bit-loop reference are original MIT code. Sixteen input sets cover offset/width masking, signed boundaries, zero/all-one values, scan sentinels and population-count wraparound. Every 32-bit result is exported as four exact byte-valued channels; all twelve wrong references must report a pixel mismatch. Acceptance-only checks do not add forms to unrelated draw records. README and `docs/experiments.md` document the supported forms, limits and reproduction commands. No proprietary binaries or prototype apps are included. AI-assisted implementation and tests. ## 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.
upstream-sync closed this pull request 2026-11-24 06:43:02 +00:00
roansystemlabs commented 2026-11-24 06:48:43 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by roansystemlabs on 2026-11-22T19:48:24Z.


Hardware run of the current head, since the description notes hardware was not rerun after the rebase and the integration was not a full rebuild.

Commit: f3aeede (PR head), fresh configure and full build with the dev preset (MSVC 19.44, DXC 1.9.2602.17 from Windows SDK 10.0.26100).

ctest --preset dev --no-tests=error -R '^pixel_aot_bits_(hardware|warp)$' -V
Test RTX 3070 WARP
pixel_aot_bits_hardware / _warp Pass (24.9–26.0 s, 4 runs) Pass (4.0–4.5 s, 4 runs)

Each adapter reports 12 × cases=16 matched, with debug_layer=enabled debug_errors=0 debug_warnings=0 and max_absolute_error=0 on every printed draw, and the wrong-byte control is caught for every form. pixel_aot_hardware (41.3 s) and pixel_aot_warp (8.1 s) also pass. tests/form_coverage_check.py passes.

Full suite: ctest --preset dev --no-tests=error gives 278/278, with the usual four capability skips (bvh_wave64_hardware, bvh_wave64_warp, wave_shuffle_warp, cpu_aot_crypto_sha).

Timing note: the GPU was not fully idle. Other processes used 0–6 % of the GPU and about 5.5 GB of 8 GB VRAM, and another D3D12 test process ran at the same time for part of the session. The pass/fail results do not depend on this. Treat the times as approximate.

Negative controls (local edits to tools/pixel_aot.py, one at a time, reverted afterwards; both tests fail each time):

Mutation First failing case (RTX 3070 and WARP)
v_bfe_i32 helper uses a logical shift (drops asint) v_bfe_i32(0xdeadbeef, 0x4, 0x8)
v_ffbh_i32 drops the sign inversion v_ffbh_i32_e32(0xffffffff, 0x0, 0x0)
v_bcnt_u32_b32 drops + {1} v_bcnt_u32_b32(0x80000000, 0x1f, 0x1)
v_ffbh_u32 helper drops 31u - v_ffbh_u32_e32(0xffffffff, 0x0, 0x0)

Overlap with #541. #541 (head 45185c0) also lowers v_bfrev_b32, v_ffbh_u32 and v_ffbh_i32 (e32/e64), with its own ffbh_u32/ffbh_i32 helpers. The two branches merge without textual conflicts. I merged #541 into f3aeede locally and rebuilt:

  • pixel_aot_bits_*, pixel_aot_blend_scalar_*, pixel_aot_hardware/_warp, rdna2_tools_check, docs_links and form_coverage_check.py all pass on RTX 3070 and WARP.
  • In the merged tree, #541's lowering handles the v_ffbh_* forms. The generated HLSL calls ffbh_u32/ffbh_i32, not this PR's v_ffbh_u32 helper. With the 31u - mutation applied to this PR's helper, pixel_aot_bits_hardware and _warp still pass in the merged tree, while the same mutation fails on this PR alone (last row above).

The reason is ordering: #541's integer-op branch in lower() matches v_bfrev_b32/v_ffbh_* before this PR's branch is reached. So if both PRs land as they are, this PR's v_bfrev_b32/v_ffbh_* entries and its v_ffbh_u32 helper become unreachable, and its bits cases exercise #541's helpers instead. Results are identical today, but there would be two copies of the same rule, and a later fix to one copy would not reach the generated code if it was the dead one.

Suggestion: whichever of the two PRs lands second drops its duplicate v_bfrev_b32/v_ffbh_* lowering and helpers and keeps its test cases, so both suites cover the single remaining implementation.

Environment: Windows 11 build 26200.9974, NVIDIA GeForce RTX 3070 (10de:2484), driver 32.0.16.2101, D3D12 debug layer on (Graphics Tools installed); WARP 10.0.26100.9818.

Not tested: AMD or Intel hardware, the LLVM binary round-trip (pixel_aot_check.py binary; no LLVM on this machine), and the /O2 release preset.

AI-assisted: yes. All reported checks ran locally on the adapter and driver listed.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7084690561 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/436#issuecomment-7084690561). Originally posted by [roansystemlabs](https://github.com/roansystemlabs) on 2026-11-22T19:48:24Z. --- Hardware run of the current head, since the description notes hardware was not rerun after the rebase and the integration was not a full rebuild. **Commit:** `f3aeede` (PR head), fresh configure and full build with the `dev` preset (MSVC 19.44, DXC 1.9.2602.17 from Windows SDK 10.0.26100). ```powershell ctest --preset dev --no-tests=error -R '^pixel_aot_bits_(hardware|warp)$' -V ``` | Test | RTX 3070 | WARP | |---|---|---| | `pixel_aot_bits_hardware` / `_warp` | Pass (24.9–26.0 s, 4 runs) | Pass (4.0–4.5 s, 4 runs) | Each adapter reports 12 × `cases=16 matched`, with `debug_layer=enabled debug_errors=0 debug_warnings=0` and `max_absolute_error=0` on every printed draw, and the wrong-byte control is caught for every form. `pixel_aot_hardware` (41.3 s) and `pixel_aot_warp` (8.1 s) also pass. `tests/form_coverage_check.py` passes. **Full suite:** `ctest --preset dev --no-tests=error` gives 278/278, with the usual four capability skips (`bvh_wave64_hardware`, `bvh_wave64_warp`, `wave_shuffle_warp`, `cpu_aot_crypto_sha`). Timing note: the GPU was not fully idle. Other processes used 0–6 % of the GPU and about 5.5 GB of 8 GB VRAM, and another D3D12 test process ran at the same time for part of the session. The pass/fail results do not depend on this. Treat the times as approximate. **Negative controls** (local edits to `tools/pixel_aot.py`, one at a time, reverted afterwards; both tests fail each time): | Mutation | First failing case (RTX 3070 and WARP) | |---|---| | `v_bfe_i32` helper uses a logical shift (drops `asint`) | `v_bfe_i32(0xdeadbeef, 0x4, 0x8)` | | `v_ffbh_i32` drops the sign inversion | `v_ffbh_i32_e32(0xffffffff, 0x0, 0x0)` | | `v_bcnt_u32_b32` drops `+ {1}` | `v_bcnt_u32_b32(0x80000000, 0x1f, 0x1)` | | `v_ffbh_u32` helper drops `31u -` | `v_ffbh_u32_e32(0xffffffff, 0x0, 0x0)` | **Overlap with #541.** #541 (head `45185c0`) also lowers `v_bfrev_b32`, `v_ffbh_u32` and `v_ffbh_i32` (e32/e64), with its own `ffbh_u32`/`ffbh_i32` helpers. The two branches merge without textual conflicts. I merged #541 into `f3aeede` locally and rebuilt: - `pixel_aot_bits_*`, `pixel_aot_blend_scalar_*`, `pixel_aot_hardware`/`_warp`, `rdna2_tools_check`, `docs_links` and `form_coverage_check.py` all pass on RTX 3070 and WARP. - In the merged tree, #541's lowering handles the `v_ffbh_*` forms. The generated HLSL calls `ffbh_u32`/`ffbh_i32`, not this PR's `v_ffbh_u32` helper. With the `31u -` mutation applied to this PR's helper, `pixel_aot_bits_hardware` and `_warp` still pass in the merged tree, while the same mutation fails on this PR alone (last row above). The reason is ordering: #541's integer-op branch in `lower()` matches `v_bfrev_b32`/`v_ffbh_*` before this PR's branch is reached. So if both PRs land as they are, this PR's `v_bfrev_b32`/`v_ffbh_*` entries and its `v_ffbh_u32` helper become unreachable, and its bits cases exercise #541's helpers instead. Results are identical today, but there would be two copies of the same rule, and a later fix to one copy would not reach the generated code if it was the dead one. Suggestion: whichever of the two PRs lands second drops its duplicate `v_bfrev_b32`/`v_ffbh_*` lowering and helpers and keeps its test cases, so both suites cover the single remaining implementation. **Environment:** Windows 11 build 26200.9974, NVIDIA GeForce RTX 3070 (10de:2484), driver 32.0.16.2101, D3D12 debug layer on (Graphics Tools installed); WARP 10.0.26100.9818. **Not tested:** AMD or Intel hardware, the LLVM binary round-trip (`pixel_aot_check.py binary`; no LLVM on this machine), and the `/O2` release preset. AI-assisted: yes. All reported checks ran locally on the adapter and driver listed.
R0Y00 commented 2026-11-24 06:49:05 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T08:56:45Z.


Current main already lowers the four plain unary families in both spellings (v_bfrev_b32, v_ffbl_b32, v_ffbh_u32, v_ffbh_i32) using its shared integer templates. The remaining implementation here is v_bfe_{u32,i32}, v_bfm_b32 and v_bcnt_u32_b32. Let’s retain your independent edge references, especially the signed extract crossing bit 31 and the population-count addition wrapping at 2^32, while using the current unary helpers. That keeps the previous hardware evidence and avoids replacing shared code already in use.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7096029688 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/436#issuecomment-7096029688). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T08:56:45Z. --- Current `main` already lowers the four plain unary families in both spellings (`v_bfrev_b32`, `v_ffbl_b32`, `v_ffbh_u32`, `v_ffbh_i32`) using its shared integer templates. The remaining implementation here is `v_bfe_{u32,i32}`, `v_bfm_b32` and `v_bcnt_u32_b32`. Let’s retain your independent edge references, especially the signed extract crossing bit 31 and the population-count addition wrapping at 2^32, while using the current unary helpers. That keeps the previous hardware evidence and avoids replacing shared code already in use.
R0Y00 commented 2026-11-24 06:49:06 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T09:25:25Z.


I fast-forwarded the branch to f80b24b and resolved the shared lowering and coverage conflicts. The four new bitfield and population-count operations use the existing integer lowering, and all twelve of your independent reference cases still run. Each form now batches its 16 inputs and one wrong reference on a single renderer device. LLVM 15 round-trip and Python controls passed. Windows 11 build 26200.9974: WARP 10.0.26100.9818 passed in 5.7 s and RTX 4060 Laptop 32.0.16.1656 in 19.3 s, both with the debug layer enabled. Waiting for GitHub CI on this head.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7096629089 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/436#issuecomment-7096629089). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T09:25:25Z. --- I fast-forwarded the branch to `f80b24b` and resolved the shared lowering and coverage conflicts. The four new bitfield and population-count operations use the existing integer lowering, and all twelve of your independent reference cases still run. Each form now batches its 16 inputs and one wrong reference on a single renderer device. LLVM 15 round-trip and Python controls passed. Windows 11 build 26200.9974: WARP 10.0.26100.9818 passed in 5.7 s and RTX 4060 Laptop 32.0.16.1656 in 19.3 s, both with the debug layer enabled. Waiting for GitHub CI on this head.
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!430
No description provided.