shader: lower scalar bit-count instructions in pixel_aot #599

Merged
descent81 merged 3 commits from upstream-pr/605 into main 2026-11-22 15:59:44 +00:00
descent81 commented 2026-11-22 15:24:47 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by descent81 on 2026-11-22T15:24:47Z.


Change

pixel_aot now translates four SOP1 instructions: s_bcnt0_i32_b32, s_bcnt1_i32_b32, s_bcnt0_i32_b64, and s_bcnt1_i32_b64. They count zeros or ones over the source width and set SCC when the count is nonzero. The 64-bit path reads the existing SGPR pair representation and counts both 32-bit words. It uses 32-bit HLSL operations.

Verification

Tested commit 3139ef3 on base 3ffc193. The fixture exports both counts and both SCC values. Python computes the reference with integer bit_count(). Counts are encoded as 1 + count/1024, which is exact through the binary16 pixel export for every possible count. Before each count, the fixture seeds SCC to the opposite of the expected result so a lowering that leaves SCC unchanged fails.

For the 64-bit input 0x80000000_00000000, the expected counts are 63 zeros and one one. A second shader replaces the 64-bit ones count with a low-word-only count and uses the unchanged reference. Both backends reported pixel_mismatch. The all-zero and all-one inputs exercise the zero count and cleared SCC for each operation.

  • D3D12: RTX 4060 (32.0.16.1088) and WARP (10.0.26100.9818) matched all 4,096 pixels in each of eight positive draws per backend, with the debug layer enabled. The complete predicate/rounding CTest passed on both backends locally (29.57 s hardware, 5.74 s WARP). Neither was skipped.
  • LLVM: The full LLVM 15 assemble/disassemble and pixel controls passed on the base and head. Applying the two coverage references to the accepted binary fixture forms gives gfx1013 452 → 456 and gfx1030 450 → 454, with exactly the four SOP1 forms added and no removals. These counts are scoped to the local binary suite.

From the repository root, with the documented Windows dev build or LLVM 15 installed:

ctest --preset dev --no-tests=error -R '^pixel_aot_predicate_rounding_(hardware|warp)$' --output-on-failure
python -B tests/pixel_aot_check.py binary llvm-mc-15 llvm-objcopy-15 libLLVM-15.so.1

Evidence and follow-up

The fixture uses source-written assembly and synthetic inputs under the repository's MIT license. This change is scoped to scalar counts; the coverage comparison above uses the existing dashboard references. AMD RDNA 2 ISA reference

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6544143443 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/605). Originally posted by [descent81](https://github.com/descent81) on 2026-11-22T15:24:47Z. --- ## Change `pixel_aot` now translates four SOP1 instructions: `s_bcnt0_i32_b32`, `s_bcnt1_i32_b32`, `s_bcnt0_i32_b64`, and `s_bcnt1_i32_b64`. They count zeros or ones over the source width and set SCC when the count is nonzero. The 64-bit path reads the existing SGPR pair representation and counts both 32-bit words. It uses 32-bit HLSL operations. ## Verification Tested commit `3139ef3` on base `3ffc193`. The fixture exports both counts and both SCC values. Python computes the reference with integer `bit_count()`. Counts are encoded as `1 + count/1024`, which is exact through the binary16 pixel export for every possible count. Before each count, the fixture seeds SCC to the opposite of the expected result so a lowering that leaves SCC unchanged fails. For the 64-bit input `0x80000000_00000000`, the expected counts are 63 zeros and one one. A second shader replaces the 64-bit ones count with a low-word-only count and uses the unchanged reference. Both backends reported `pixel_mismatch`. The all-zero and all-one inputs exercise the zero count and cleared SCC for each operation. - **D3D12:** RTX 4060 (32.0.16.1088) and WARP (10.0.26100.9818) matched all 4,096 pixels in each of eight positive draws per backend, with the debug layer enabled. The complete predicate/rounding CTest passed on both backends locally (29.57 s hardware, 5.74 s WARP). Neither was skipped. - **LLVM:** The full LLVM 15 assemble/disassemble and pixel controls passed on the base and head. Applying the two coverage references to the accepted binary fixture forms gives gfx1013 **452 → 456** and gfx1030 **450 → 454**, with exactly the four SOP1 forms added and no removals. These counts are scoped to the local binary suite. From the repository root, with the documented Windows dev build or LLVM 15 installed: ```powershell ctest --preset dev --no-tests=error -R '^pixel_aot_predicate_rounding_(hardware|warp)$' --output-on-failure ``` ```sh python -B tests/pixel_aot_check.py binary llvm-mc-15 llvm-objcopy-15 libLLVM-15.so.1 ``` ## Evidence and follow-up The fixture uses source-written assembly and synthetic inputs under the repository's MIT license. This change is scoped to scalar counts; the coverage comparison above uses the existing dashboard references. [AMD RDNA 2 ISA reference](https://docs.amd.com/v/u/en-US/rdna2-shader-instruction-set-architecture) AI-assisted.
upstream-sync closed this pull request 2026-11-24 06:43:54 +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!599
No description provided.