shader: lower compute v_max3_u32 and v_min3_u32 #1574

Manually merged
github merged 2 commits from gh-pr/1574/head into gh-pr/1574/base 2026-11-26 23:17:52 +00:00
Owner

@⁠Asimmimx on GitHub · 2026-11-24 14:31 UTC · original
Asimmimx:shader/compute-max3-min3 → main · +224 −1 · 4 files · 2 commits · merged 2026-11-24 15:47 UTC

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).

**@⁠Asimmimx** on GitHub · 2026-11-24 14:31 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1574) `Asimmimx:shader/compute-max3-min3` → `main` · +224 −1 · 4 files · 2 commits · merged 2026-11-24 15:47 UTC ## 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).
Refs #1546. The compute store profile now lowers the VOP3 forms
v_max3_u32 vD, a, b, c and v_min3_u32 vD, a, b, c on known words to
max(max(a, b), c) and min(min(a, b), c): the unsigned maximum and minimum
of the three sources (RDNA2 ISA V_MAX3_U32 and V_MIN3_U32). They join the
three-source matcher of v_mad_u32_u24, so a source that is not a known word,
signed and 16-bit forms, modifiers, register ranges and missing sources still
stop the lowering at the instruction.

tests/compute_alu_minmax3_check.py changes the read-compute-write fixture by
hand: out[gid] = umax3(v, cap, d) ^ umin3(d, 0x8c800000, v), with
d = v * 0x9e3779b9 and cap = 0x8c000000. The source words and constants
are above 0x80000000 and d falls on both sides, so a signed comparison
differs on 73 of 150 lanes. Each operation picks each source for some lanes.
The expected words come from a CPU model that sorts the three words.

Verified on WARP (draw mode): all three read-harness dispatches match. Six
wrong references (signed, swapped, third source dropped) and a lane past
the bound fail at their first differing word. Seven recompiled HLSL
mutations fail the readback. The controls mode checks exact output, operand
forms and 18 rejections. compute_store_check.py controls and
draw-guard-read on WARP still pass.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 23:17:50 +00:00
github manually merged commit 158626c998 into gh-pr/1574/base 2026-11-26 23:17:52 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-24 15:27 UTC · original

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).

**@⁠R0Y00** on GitHub · 2026-11-24 15:27 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1574#issuecomment-7136051322) 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).
This discussion has been locked. Commenting is limited to contributors.
No description provided.