shader: lower gfx1013 32-bit integer comparisons in pixel_aot #301

Merged
alexander-src merged 1 commit from upstream-pr/306 into main 2026-11-22 02:55:57 +00:00
alexander-src commented 2026-11-21 21:38:26 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by alexander-src on 2026-11-21T21:38:26Z.


Change

Lower all 32 gfx1013 32-bit integer comparison forms (v_cmp_{f,lt,eq,le,gt,ne,ge,t}_{i32,u32} in both _e32 and _e64 encodings) in tools/pixel_aot.py.

Operands are decoded via a new int_operand() helper that reinterprets registers and constants as int (asint(...)) for i32 or uint (asuint(...) / unsigned literals) for u32, treats integer and float inline constants as their 32-bit patterns, and rejects float source modifiers (-, |x|, abs(...)), clamp, and v_cmpx_* exec-writing forms. Results feed v_cndmask_b32 through the existing tracked lane-mask path in both wave32 (vcc_lo, s52) and wave64 (vcc, s[52:53]) spellings.

Add control, binary assembly/disassembly, and D3D12 draw fixtures in tests/pixel_aot_check.py plus documentation in docs/experiments.md.

Verification

Commit 9b4c89f on Linux x86_64 (Python 3.14, LLVM 23.1, g++):

  • python3 -B tests/pixel_aot_check.py binary llvm-mc llvm-objcopy libLLVM.so: passed (assembles all 8 four-channel fixtures covering all 32 v_cmp_*_{i32,u32} forms for gfx1013, extracts, disassembles, lowers, and matches source lowering).
  • C++ cross-check (g++ -std=c++17 -O2 -Wall -Wextra -Werror) of all 8 generated shader bodies against the Python reference across all 4 input bit-pattern pairs (0x80000000 vs 0x00000000, 0xbf800000 vs 0xbf800000, 0x3f800000 vs 0xbf800000, 0xc0000000 vs 0xbf800000): all 32 forms matched.
  • Negative control against main:tools/pixel_aot.py: rejected v_cmp_f_i32_e32 with ValueError: Unsupported instruction 22: v_cmp_f_i32_e32 vcc_lo, s44, v18.
  • python3 -B tests/docs_links_check.py, tests/bidi_controls_check.py, tests/rdna2_tools_check.py (26 ran, 1 skipped without LLVM_LIB), and the 5 non-iced_x86 checks in tests/form_coverage_check.py: all passed.
  • Could not run DXC compilation or offscreen_check.exe D3D12 draws locally because this environment is Linux without MSVC/DXC/Windows; check_int_predicate_draws() will execute under the Windows CI job.

Evidence and follow-up

All fixtures are synthetic AMDGPU assembly programs authored inline in tests/pixel_aot_check.py under the repository's MIT license. Input pairs use normal and signed-zero IEEE-754 bit patterns so denormal flushing or NaN canonicalization cannot alter the bit patterns while separating signed, unsigned, and floating-point orderings. Semantics follow the AMD RDNA Shader ISA reference.

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.

AI-assisted: yes.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6534710008 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/306). Originally posted by [alexander-src](https://github.com/alexander-src) on 2026-11-21T21:38:26Z. --- ## Change Lower all 32 gfx1013 32-bit integer comparison forms (`v_cmp_{f,lt,eq,le,gt,ne,ge,t}_{i32,u32}` in both `_e32` and `_e64` encodings) in `tools/pixel_aot.py`. Operands are decoded via a new `int_operand()` helper that reinterprets registers and constants as `int` (`asint(...)`) for `i32` or `uint` (`asuint(...)` / unsigned literals) for `u32`, treats integer and float inline constants as their 32-bit patterns, and rejects float source modifiers (`-`, `|x|`, `abs(...)`), `clamp`, and `v_cmpx_*` exec-writing forms. Results feed `v_cndmask_b32` through the existing tracked lane-mask path in both wave32 (`vcc_lo`, `s52`) and wave64 (`vcc`, `s[52:53]`) spellings. Add control, binary assembly/disassembly, and D3D12 draw fixtures in `tests/pixel_aot_check.py` plus documentation in `docs/experiments.md`. ## Verification Commit `9b4c89f` on Linux x86_64 (Python 3.14, LLVM 23.1, g++): - `python3 -B tests/pixel_aot_check.py binary llvm-mc llvm-objcopy libLLVM.so`: passed (assembles all 8 four-channel fixtures covering all 32 `v_cmp_*_{i32,u32}` forms for `gfx1013`, extracts, disassembles, lowers, and matches source lowering). - C++ cross-check (`g++ -std=c++17 -O2 -Wall -Wextra -Werror`) of all 8 generated shader bodies against the Python reference across all 4 input bit-pattern pairs (`0x80000000` vs `0x00000000`, `0xbf800000` vs `0xbf800000`, `0x3f800000` vs `0xbf800000`, `0xc0000000` vs `0xbf800000`): all 32 forms matched. - Negative control against `main:tools/pixel_aot.py`: rejected `v_cmp_f_i32_e32` with `ValueError: Unsupported instruction 22: v_cmp_f_i32_e32 vcc_lo, s44, v18`. - `python3 -B tests/docs_links_check.py`, `tests/bidi_controls_check.py`, `tests/rdna2_tools_check.py` (26 ran, 1 skipped without `LLVM_LIB`), and the 5 non-`iced_x86` checks in `tests/form_coverage_check.py`: all passed. - Could not run DXC compilation or `offscreen_check.exe` D3D12 draws locally because this environment is Linux without MSVC/DXC/Windows; `check_int_predicate_draws()` will execute under the Windows CI job. ## Evidence and follow-up All fixtures are synthetic AMDGPU assembly programs authored inline in `tests/pixel_aot_check.py` under the repository's MIT license. Input pairs use normal and signed-zero IEEE-754 bit patterns so denormal flushing or NaN canonicalization cannot alter the bit patterns while separating signed, unsigned, and floating-point orderings. Semantics follow the [AMD RDNA Shader ISA reference](https://gpuopen.com/wp-content/uploads/2019/08/RDNA_Shader_ISA_5August2019.pdf). ## 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. AI-assisted: yes.
upstream-sync closed this pull request 2026-11-24 06:42:20 +00:00
lambirou commented 2026-11-24 06:48:04 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lambirou on 2026-11-21T21:55:38Z.


@R0Y00 I ran the Windows pixel suite with this PR’s 9b4c89f as the base and prepared a small follow-up fixture for v_cmp_lt_u32 in both e32 and e64. The fixture and its documentation are available in commit 425870c.

The fixture reads raw DWORDs, compares both operand orders and exports the four results through v_cndmask_b32. The CPU reference expects RGBA (0, 1, 0, 1) for 0x80000000 and 0x7fffffff, and (0, 0, 0, 0) for equal words. It also compares 0x7f800002 with 0x7fc00001. Quieting the first NaN while retaining its payload would reverse the unsigned order.

  • python -B tests/pixel_aot_check.py binary <llvm-mc> <llvm-objcopy> <libLLVM> passed with LLVM 23.1.5.
  • ctest --preset dev --no-tests=error -R '^pixel_aot_' -V passed both pixel tests on Windows 11 build 26300.10075. WARP (10.0.26100.10068) and Radeon RX 9060 XT (32.0.32029.2010) matched all four channels of 4,096 pixels per draw for all three inputs. The D3D12 debug layer was unavailable.
  • Replacing both encodings with v_cmp_lt_i32 produced the expected mismatch at pixel (0, 0) on both adapters. All four channels flipped.
  • The CTest coverage records show both encodings on both adapters. The pixel suite went from 67/1,968 gfx1013 forms on b53bfb0 to 99/1,968 with this PR and the follow-up fixture.

The fixture is ready to cherry-pick onto this PR if you’d like to include the sign-boundary and NaN cases. AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7069817355 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/306#issuecomment-7069817355). Originally posted by [lambirou](https://github.com/lambirou) on 2026-11-21T21:55:38Z. --- @R0Y00 I ran the Windows pixel suite with this PR’s `9b4c89f` as the base and prepared a small follow-up fixture for `v_cmp_lt_u32` in both e32 and e64. The fixture and its documentation are available in [commit `425870c`](https://github.com/lambirou/Xbox2Windows/commit/425870c26ca4c3247716c7e97bc847e33b96ac7d). The fixture reads raw DWORDs, compares both operand orders and exports the four results through `v_cndmask_b32`. The CPU reference expects RGBA `(0, 1, 0, 1)` for `0x80000000` and `0x7fffffff`, and `(0, 0, 0, 0)` for equal words. It also compares `0x7f800002` with `0x7fc00001`. Quieting the first NaN while retaining its payload would reverse the unsigned order. - `python -B tests/pixel_aot_check.py binary <llvm-mc> <llvm-objcopy> <libLLVM>` passed with LLVM 23.1.5. - `ctest --preset dev --no-tests=error -R '^pixel_aot_' -V` passed both pixel tests on Windows 11 build `26300.10075`. WARP (`10.0.26100.10068`) and Radeon RX 9060 XT (`32.0.32029.2010`) matched all four channels of 4,096 pixels per draw for all three inputs. The D3D12 debug layer was unavailable. - Replacing both encodings with `v_cmp_lt_i32` produced the expected mismatch at pixel `(0, 0)` on both adapters. All four channels flipped. - The CTest coverage records show both encodings on both adapters. The pixel suite went from 67/1,968 gfx1013 forms on `b53bfb0` to 99/1,968 with this PR and the follow-up fixture. The fixture is ready to cherry-pick onto this PR if you’d like to include the sign-boundary and NaN cases. AI-assisted.
R0Y00 commented 2026-11-24 06:48:05 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T21:58:43Z.


At 9b4c89f the merge conflicts are in tests/pixel_aot_check.py. Preserve the comparison draws and existing scalar and half controls. Coordinate the identical int_operand helper with #308 and #310.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7069852676 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/306#issuecomment-7069852676). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-21T21:58:43Z. --- At `9b4c89f` the merge conflicts are in `tests/pixel_aot_check.py`. Preserve the comparison draws and existing scalar and half controls. Coordinate the identical `int_operand` helper with #308 and #310.
alexander-src commented 2026-11-24 06:48:08 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by alexander-src on 2026-11-21T22:19:33Z.


Rebased onto main (6ee2406) in de229bb, keeping all landed scalar64, v_cvt_f32_f16, and fmaak/fmamk controls alongside the integer comparison fixtures. Simplified int_operand() to delegate scalar and literal decoding to the existing scalar_u32() helper, matching the identical helper used in #308 and #310.

Thanks @lambirou for testing this on Windows 11 with RX 9060 XT and WARP. Happy to keep this PR scoped to the 32 comparison forms first and take your raw-DWORD sign-boundary fixture (425870c) as a quick follow-up once this lands.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7070101473 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/306#issuecomment-7070101473). Originally posted by [alexander-src](https://github.com/alexander-src) on 2026-11-21T22:19:33Z. --- Rebased onto `main` (`6ee2406`) in `de229bb`, keeping all landed scalar64, `v_cvt_f32_f16`, and `fmaak`/`fmamk` controls alongside the integer comparison fixtures. Simplified `int_operand()` to delegate scalar and literal decoding to the existing `scalar_u32()` helper, matching the identical helper used in #308 and #310. Thanks @lambirou for testing this on Windows 11 with RX 9060 XT and WARP. Happy to keep this PR scoped to the 32 comparison forms first and take your raw-DWORD sign-boundary fixture (`425870c`) as a quick follow-up once this lands.
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!301
No description provided.