shader: lower gfx1013 scalar halfword pack instructions in pixel_aot #544

Merged
descent81 merged 1 commit from upstream-pr/550 into main 2026-11-22 11:36:09 +00:00
descent81 commented 2026-11-22 10:51:10 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by descent81 on 2026-11-22T10:51:10Z.


Change

pixel_aot can now translate s_pack_ll_b32_b16, s_pack_lh_b32_b16, and s_pack_hh_b32_b16. Each instruction selects a halfword from each source and leaves SCC unchanged. The fixture writes the result back to the first source register, then reads SCC before comparing the packed word.

I chose two inputs whose four halfwords are all different. That makes a source-order or half-selection mistake visible in the result:

Sources: 0x1234ABCD, 0x5678EF90 Expected 32-bit word
LL 0xEF90ABCD
LH 0x5678ABCD
HH 0x56781234

Verification

Tested commit caa7fd8 against base e55c593. The CPU reference splits each input into two little-endian halfwords and writes the selected pair into the constant buffer. The shader compares all 32 result bits before exporting the equality result. A separate pixel channel reports the incoming SCC. A second input pair exercises zero and all-one halves with SCC set.

  • Binary fixtures. The full LLVM 15 pixel binary suite passed before and after the change. Comparing its accepted forms against the gfx1013 reference gave 327 → 330; against the gfx1030 reference, 325 → 328. Each difference contained exactly the three SOP2 instructions above.
  • GPU readback. I ran the new fixture directly on an RTX 4060 (driver 32.0.16.1088) and Microsoft WARP (10.0.26100.9818). All six positive draws per backend matched over 4,096 pixels each. Both backends reported pixel_mismatch when I compiled LL in place of LH and kept the original LH reference.

To reproduce the binary check with LLVM 15, then the registered Windows tests containing the draw:

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

Evidence and follow-up

The fixture uses source-written assembly and synthetic constants under the repository's MIT license. The counts above are local to the binary fixture suite; CI produces the aggregate dashboard separately. Instruction semantics follow the AMD RDNA 2 ISA reference.

AI-assisted with Codex for implementation, local verification, and this write-up.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6541502846 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/550). Originally posted by [descent81](https://github.com/descent81) on 2026-11-22T10:51:10Z. --- ## Change `pixel_aot` can now translate `s_pack_ll_b32_b16`, `s_pack_lh_b32_b16`, and `s_pack_hh_b32_b16`. Each instruction selects a halfword from each source and leaves SCC unchanged. The fixture writes the result back to the first source register, then reads SCC before comparing the packed word. I chose two inputs whose four halfwords are all different. That makes a source-order or half-selection mistake visible in the result: | Sources: `0x1234ABCD`, `0x5678EF90` | Expected 32-bit word | | --- | --- | | LL | `0xEF90ABCD` | | LH | `0x5678ABCD` | | HH | `0x56781234` | ## Verification Tested commit `caa7fd8` against base `e55c593`. The CPU reference splits each input into two little-endian halfwords and writes the selected pair into the constant buffer. The shader compares all 32 result bits before exporting the equality result. A separate pixel channel reports the incoming SCC. A second input pair exercises zero and all-one halves with SCC set. - **Binary fixtures.** The full LLVM 15 pixel binary suite passed before and after the change. Comparing its accepted forms against the gfx1013 reference gave **327 → 330**; against the gfx1030 reference, **325 → 328**. Each difference contained exactly the three SOP2 instructions above. - **GPU readback.** I ran the new fixture directly on an RTX 4060 (driver 32.0.16.1088) and Microsoft WARP (10.0.26100.9818). All six positive draws per backend matched over 4,096 pixels each. Both backends reported `pixel_mismatch` when I compiled LL in place of LH and kept the original LH reference. To reproduce the binary check with LLVM 15, then the registered Windows tests containing the draw: ```sh python -B tests/pixel_aot_check.py binary llvm-mc-15 llvm-objcopy-15 libLLVM-15.so.1 ``` ```powershell ctest --preset dev --no-tests=error -R '^pixel_aot_predicate_rounding_(hardware|warp)$' --output-on-failure ``` ## Evidence and follow-up The fixture uses source-written assembly and synthetic constants under the repository's MIT license. The counts above are local to the binary fixture suite; CI produces the aggregate dashboard separately. Instruction semantics follow the [AMD RDNA 2 ISA reference](https://docs.amd.com/v/u/en-US/rdna2-shader-instruction-set-architecture). AI-assisted with Codex for implementation, local verification, and this write-up.
upstream-sync closed this pull request 2026-11-24 06:43:38 +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!544
No description provided.