shader: lower compute v_max3_u32 and v_min3_u32 #1567

Merged
Asimmimx merged 2 commits from upstream-pr/1574 into main 2026-11-24 15:47:36 +00:00
Asimmimx commented 2026-11-24 14:31:34 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Asimmimx on 2026-11-24T14:31:34Z.


Change

Refs #1546. This adds v_max3_u32 and v_min3_u32 to the compute translator (tools/compute_store_aot.py):

  • v_max3_u32 vD, a, b, c → max(max(a, b), c)
  • v_min3_u32 vD, a, b, c → min(min(a, b), c)

These are the unsigned maximum and minimum of three sources, as V_MAX3_U32 / V_MIN3_U32 (VOP3A) define them in the RDNA2 ISA. Every operand in the generated HLSL is uint-typed (literals with a u suffix, inputData.Load, tid.x, params[]), so max and min compare unsigned.

The translator change is two ALU entries plus the two opcodes appended to the three-source matcher group (v_mad_u32_u24|v_max3_u32|v_min3_u32). The fixture and controls live in a new tests/compute_alu_minmax3_check.py, which imports the helpers of tests/compute_store_check.py and leaves that file unchanged.

Fixture. It is a variant of READ_COMPUTE:

d   = v * 0x9e3779b9                                  (v_mul_lo_u32)
out = umax3(v, cap, d) ^ umin3(d, 0x8c800000, v)       cap = params[0].y = 0x8c000000
  • The source words run from 0x8b02a7f1 to 0x8d621df6, and d falls on both sides of 0x80000000. A signed comparison would change 73 of the 150 lanes for each operation.
  • In the largest dispatch, each operation selects each of its three sources for some lanes; the test asserts this.
  • The expected words come from a Python model that sorts the three words. Lane 0 was checked by hand: max3 = 0x8c000000, min3 = 0x89134629, XOR = 0x05134629.

Controls.

  • Seven wrong references must fail at their first differing word: signed max3 or min3, the two operations swapped, either one without its third source, and a lane past the bound.
  • Seven recompiled HLSL mutations must fail with "Compute readback differs".
  • The controls mode pins the exact HLSL and refuses 18 forms with the existing messages:
    • v_max3_i32, v_min3_i32, v_max3_u16, v_min3_u16;
    • clamp, an |v1| source, a v[1:2] range or a missing third source;
    • unknown, descriptor or byte-offset sources, or a literal wider than 32 bits;
    • a v256 destination;
    • the result used as an address or as a guard operand;
    • a chain that is too long.

The new CTest is compute_store_aot_alu_minmax3_${adapter}, after compute_store_aot_mubuf_reduction. A new "Unsigned three-source maximum and minimum" subsection goes in docs/experiments.md.

Verification

Commit 6c0e5380 (main) plus this change, dev preset, Windows 11 Pro build 26300.9974, DXC 1.8.2502.11.

python -B tests/compute_alu_minmax3_check.py controls                                  # pass
python -B tests/compute_alu_minmax3_check.py draw <dxc> <offscreen_check.exe> warp     # pass
python -B tests/compute_alu_minmax3_check.py draw <dxc> <offscreen_check.exe> hardware # pass
ctest --preset dev --no-tests=error -R '^compute_store_aot_alu_minmax3_(warp|hardware)$' -V
Backend Result
WARP 10.0.26100.9818, debug layer enabled 3 dispatches (0, 17, 150 lanes), 320 words each, mismatches 0
AMD Radeon RX 6600 (RDNA 2, 1002:73ff), driver 32.0.21045.29003, debug layer enabled 3 dispatches, 320 words each, mismatches 0, debug errors 0

Regression with the change: compute_store_check controls, draw-guard-read on WARP and the compile-mimg-atomic-* modes pass. tests/docs_links_check.py, tests/bidi_controls_check.py and git diff --check pass.

Notes

  • Error message for unknown operands. The shared three-source matcher keeps its existing operand guard. That guard is what lets v_mad_u32_u24 fall through to its row-pitch case. As a result, an unknown source here stops with Unsupported compute instruction: …, not Unverified ALU operand.
  • Fixture provenance. The fixture is hand-written assembly in the READ_VOP2 style. Its encodings were checked with llvm-mc 19 only.
  • Rebase. #1573 (v_xor3_b32) appends to the same matcher group. Whichever of the two lands second needs a trivial rebase, which I will do.

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 (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6584126975 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1574). Originally posted by [Asimmimx](https://github.com/Asimmimx) on 2026-11-24T14:31:34Z. --- ## Change Refs #1546. This adds `v_max3_u32` and `v_min3_u32` to the compute translator (`tools/compute_store_aot.py`): - `v_max3_u32 vD, a, b, c` → `max(max(a, b), c)` - `v_min3_u32 vD, a, b, c` → `min(min(a, b), c)` These are the unsigned maximum and minimum of three sources, as `V_MAX3_U32` / `V_MIN3_U32` (VOP3A) define them in the RDNA2 ISA. Every operand in the generated HLSL is `uint`-typed (literals with a `u` suffix, `inputData.Load`, `tid.x`, `params[]`), so `max` and `min` compare unsigned. The translator change is two `ALU` entries plus the two opcodes appended to the three-source matcher group `(v_mad_u32_u24|v_max3_u32|v_min3_u32)`. The fixture and controls live in a new `tests/compute_alu_minmax3_check.py`, which imports the helpers of `tests/compute_store_check.py` and leaves that file unchanged. **Fixture.** It is a variant of `READ_COMPUTE`: ``` d = v * 0x9e3779b9 (v_mul_lo_u32) out = umax3(v, cap, d) ^ umin3(d, 0x8c800000, v) cap = params[0].y = 0x8c000000 ``` - The source words run from `0x8b02a7f1` to `0x8d621df6`, and `d` falls on both sides of `0x80000000`. A signed comparison would change 73 of the 150 lanes for each operation. - In the largest dispatch, each operation selects each of its three sources for some lanes; the test asserts this. - The expected words come from a Python model that sorts the three words. Lane 0 was checked by hand: max3 = `0x8c000000`, min3 = `0x89134629`, XOR = `0x05134629`. **Controls.** - Seven wrong references must fail at their first differing word: signed max3 or min3, the two operations swapped, either one without its third source, and a lane past the bound. - Seven recompiled HLSL mutations must fail with "Compute readback differs". - The `controls` mode pins the exact HLSL and refuses 18 forms with the existing messages: - `v_max3_i32`, `v_min3_i32`, `v_max3_u16`, `v_min3_u16`; - `clamp`, an `|v1|` source, a `v[1:2]` range or a missing third source; - unknown, descriptor or byte-offset sources, or a literal wider than 32 bits; - a `v256` destination; - the result used as an address or as a guard operand; - a chain that is too long. The new CTest is `compute_store_aot_alu_minmax3_${adapter}`, after `compute_store_aot_mubuf_reduction`. A new "Unsigned three-source maximum and minimum" subsection goes in `docs/experiments.md`. ## Verification Commit `6c0e5380` (`main`) plus this change, `dev` preset, Windows 11 Pro build 26300.9974, DXC 1.8.2502.11. ```powershell python -B tests/compute_alu_minmax3_check.py controls # pass python -B tests/compute_alu_minmax3_check.py draw <dxc> <offscreen_check.exe> warp # pass python -B tests/compute_alu_minmax3_check.py draw <dxc> <offscreen_check.exe> hardware # pass ctest --preset dev --no-tests=error -R '^compute_store_aot_alu_minmax3_(warp|hardware)$' -V ``` | Backend | Result | |---|---| | WARP 10.0.26100.9818, debug layer enabled | 3 dispatches (0, 17, 150 lanes), 320 words each, mismatches 0 | | AMD Radeon RX 6600 (RDNA 2, `1002:73ff`), driver 32.0.21045.29003, debug layer enabled | 3 dispatches, 320 words each, mismatches 0, debug errors 0 | Regression with the change: `compute_store_check` controls, `draw-guard-read` on WARP and the `compile-mimg-atomic-*` modes pass. `tests/docs_links_check.py`, `tests/bidi_controls_check.py` and `git diff --check` pass. ## Notes - **Error message for unknown operands.** The shared three-source matcher keeps its existing operand guard. That guard is what lets `v_mad_u32_u24` fall through to its row-pitch case. As a result, an unknown source here stops with `Unsupported compute instruction: …`, not `Unverified ALU operand`. - **Fixture provenance.** The fixture is hand-written assembly in the `READ_VOP2` style. Its encodings were checked with `llvm-mc` 19 only. - **Rebase.** #1573 (`v_xor3_b32`) appends to the same matcher group. Whichever of the two lands second needs a trivial rebase, which I will do. ## 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 (Claude Code).
upstream-sync closed this pull request 2026-11-24 16:03:06 +00:00
R0Y00 commented 2026-11-24 16:03:34 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T15:27:13Z.


Resolved the shared compute matcher conflict in 158626c9. The combined Windows Release build passed both min/max3 and XOR3 on RTX and WARP (4/4, zero skips).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7136051322 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1574#issuecomment-7136051322). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T15:27:13Z. --- Resolved the shared compute matcher conflict in 158626c9. The combined Windows Release build passed both min/max3 and XOR3 on RTX and WARP (4/4, zero skips).
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!1567
No description provided.