shader: lower gfx1013 32-bit integer min, max and med3 in pixel_aot #303

Merged
alexander-src merged 2 commits from upstream-pr/308 into main 2026-11-22 04:08:29 +00:00
alexander-src commented 2026-11-21 21:41:23 +00:00 (Migrated from github.com)

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


Change

Lower all 14 gfx1013 32-bit integer minimum, maximum, and median instruction forms in tools/pixel_aot.py:

  • Two-operand v_min_i32, v_max_i32, v_min_u32, and v_max_u32 in both _e32 and _e64 encodings (8 forms).
  • Three-operand v_min3_i32, v_max3_i32, v_med3_i32, v_min3_u32, v_max3_u32, and v_med3_u32 (6 forms).

Operands are reinterpreted via asint (i32) or asuint (u32), evaluated with HLSL min/max (storing the three med3 operands once into an int3/uint3 local before taking max(min(x, y), min(max(x, y), z))), and written back to vector registers with asfloat. Float source modifiers (-, |x|, abs(...)), clamp, pending sample overwrites, unresolved loads, and whole-quad mode are rejected.

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

Verification

Commit 4f0811c 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 4 new fixtures covering all 14 forms for gfx1013, extracts, disassembles, lowers, and matches source lowering).
  • C++ cross-check (g++ -std=c++17 -O2 -Wall -Wextra -Werror) of all 4 generated shader bodies against the Python reference across exact binary16 inputs ((-2.0, 1.0), (-2.0, -1.0), (-2.0, -1.0, 1.0), (0.5, -0.5, 4.0) plus med3 ties): all 14 forms matched.
  • Negative controls against main:tools/pixel_aot.py: rejected v_min_i32_e32 (Unsupported instruction 21) and v_min3_i32 (Unsupported instruction 22).
  • 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_minmax_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. Test inputs are exact normal binary16 floats whose 32-bit patterns reverse order across signed, unsigned, and floating-point comparisons, so every winning bit pattern survives export16 without precision loss. Semantics follow the AMD RDNA Shader ISA reference.

This shares the int_operand() helper with #306; whichever merges second will need a small rebase. It does not overlap with #169 (f32 min3/max3/med3) or #232 (bitwise/shift/conversion).

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:6534741795 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/308). Originally posted by [alexander-src](https://github.com/alexander-src) on 2026-11-21T21:41:23Z. --- ## Change Lower all 14 gfx1013 32-bit integer minimum, maximum, and median instruction forms in `tools/pixel_aot.py`: - Two-operand `v_min_i32`, `v_max_i32`, `v_min_u32`, and `v_max_u32` in both `_e32` and `_e64` encodings (8 forms). - Three-operand `v_min3_i32`, `v_max3_i32`, `v_med3_i32`, `v_min3_u32`, `v_max3_u32`, and `v_med3_u32` (6 forms). Operands are reinterpreted via `asint` (`i32`) or `asuint` (`u32`), evaluated with HLSL `min`/`max` (storing the three `med3` operands once into an `int3`/`uint3` local before taking `max(min(x, y), min(max(x, y), z))`), and written back to vector registers with `asfloat`. Float source modifiers (`-`, `|x|`, `abs(...)`), `clamp`, pending sample overwrites, unresolved loads, and whole-quad mode are rejected. Add control, binary assembly/disassembly, and D3D12 draw fixtures in `tests/pixel_aot_check.py`, plus documentation in `docs/experiments.md`. ## Verification Commit `4f0811c` 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 4 new fixtures covering all 14 forms for `gfx1013`, extracts, disassembles, lowers, and matches source lowering). - C++ cross-check (`g++ -std=c++17 -O2 -Wall -Wextra -Werror`) of all 4 generated shader bodies against the Python reference across exact binary16 inputs (`(-2.0, 1.0)`, `(-2.0, -1.0)`, `(-2.0, -1.0, 1.0)`, `(0.5, -0.5, 4.0)` plus `med3` ties): all 14 forms matched. - Negative controls against `main:tools/pixel_aot.py`: rejected `v_min_i32_e32` (`Unsupported instruction 21`) and `v_min3_i32` (`Unsupported instruction 22`). - `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_minmax_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. Test inputs are exact normal binary16 floats whose 32-bit patterns reverse order across signed, unsigned, and floating-point comparisons, so every winning bit pattern survives `export16` without precision loss. Semantics follow the [AMD RDNA Shader ISA reference](https://gpuopen.com/wp-content/uploads/2019/08/RDNA_Shader_ISA_5August2019.pdf). This shares the `int_operand()` helper with #306; whichever merges second will need a small rebase. It does not overlap with #169 (`f32` `min3`/`max3`/`med3`) or #232 (bitwise/shift/conversion). ## 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:21 +00:00
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:50Z.


At 4f0811c the merge conflicts are in docs/experiments.md, tests/pixel_aot_check.py. Keep the integer extrema cases alongside existing pixel coverage and share int_operand with the adjacent comparison work.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7069854128 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/308#issuecomment-7069854128). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-21T21:58:50Z. --- At `4f0811c` the merge conflicts are in `docs/experiments.md`, `tests/pixel_aot_check.py`. Keep the integer extrema cases alongside existing pixel coverage and share `int_operand` with the adjacent comparison work.
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:49Z.


Rebased onto main (6ee2406) in 8f24058, preserving all landed scalar64, v_cvt_f32_f16, and fmaak/fmamk tests and docs alongside the integer min/max/med3 cases. Updated int_operand() to delegate to scalar_u32() identically to #306 and #310 so whichever lands second stays an easy rebase.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7070104629 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/308#issuecomment-7070104629). Originally posted by [alexander-src](https://github.com/alexander-src) on 2026-11-21T22:19:49Z. --- Rebased onto `main` (`6ee2406`) in `8f24058`, preserving all landed scalar64, `v_cvt_f32_f16`, and `fmaak`/`fmamk` tests and docs alongside the integer min/max/med3 cases. Updated `int_operand()` to delegate to `scalar_u32()` identically to #306 and #310 so whichever lands second stays an easy rebase.
R0Y00 commented 2026-11-24 06:48:20 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-22T02:56:26Z.


A test merge of 8f24058 against main conflicts in tests/pixel_aot_check.py. The integer comparisons in #306 have now landed. Reuse their int_operand and retain both the comparison and extrema fixtures. Please refresh the branch and rerun the relevant fixture and Windows CI.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7073227061 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/308#issuecomment-7073227061). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-22T02:56:26Z. --- A test merge of `8f24058` against main conflicts in `tests/pixel_aot_check.py`. The integer comparisons in #306 have now landed. Reuse their `int_operand` and retain both the comparison and extrema fixtures. Please refresh the branch and rerun the relevant fixture and Windows CI.
R0Y00 commented 2026-11-24 06:48:21 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-22T03:08:19Z.


Please update only #308 first, using the integer operand handling that landed in #306. The earlier request to refresh #310 can wait until #308 lands; that way the shared helper and draw list only need reconciling once per branch.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7073349773 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/308#issuecomment-7073349773). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-22T03:08:19Z. --- Please update only #308 first, using the integer operand handling that landed in #306. The earlier request to refresh #310 can wait until #308 lands; that way the shared helper and draw list only need reconciling once per branch.
R0Y00 commented 2026-11-24 06:48:24 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-22T04:04:05Z.


I merged main into this branch and resolved the conflicts in the pixel lowerer and its test driver. On 9105a0d, ctest --preset dev --no-tests=error -R ^pixel_aot_ passed on hardware (53.40 s) and WARP (11.10 s). Auto-merge is enabled while CI runs. No rebase is needed from you.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7073956981 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/308#issuecomment-7073956981). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-22T04:04:05Z. --- I merged main into this branch and resolved the conflicts in the pixel lowerer and its test driver. On 9105a0d, ctest --preset dev --no-tests=error -R ^pixel_aot_ passed on hardware (53.40 s) and WARP (11.10 s). Auto-merge is enabled while CI runs. No rebase is needed from you.
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!303
No description provided.