shader: lower v_min3_f16, v_max3_f16, and v_med3_f16 in direct Compute and Pixel DXIL (#3266 merged with main) #3454

Manually merged
github merged 5 commits from github-bot/gh-3452 into main 2026-11-29 13:26:58 +00:00 AGit
Owner

@⁠Leyukaka on GitHub · 2026-11-29 12:13 UTC · original
Leyukaka:takeover-3266-minmax-med3-f16 → main · +457 −1 · 4 files · 5 commits · merged 2026-11-29 13:21 UTC

#3268 by @⁠legacy-code-archaeologist, merged with main so it can land. Supersedes #3268. Fixes #3266. Refs #2935.

What is here

  • The two commits of #3268, unchanged and with their original authorship: b82ba196 (lowering) and df6c0545 (five added test cases).
  • One merge commit of main (fe1c1d31, merge commit 5b06bab7). It is the only change of mine.

Conflict resolution

git merge-tree --write-tree fe1c1d31 df6c0545 exits 1 with one conflicted file and one region: the half_binary op list in DirectCompute::lower(), src/gfx1013_direct_compute.inl. main extended the list after v_fract_f16; #3268 added its three ops at the same place. The resolution keeps both sides, main's entries first:

            op.name == "v_fract_f16" ||
            op.name == "v_ldexp_f16" ||
            op.name == "v_cvt_norm_i16_f16" ||
            op.name == "v_cvt_norm_u16_f16" ||
            op.name == "v_cvt_pknorm_i16_f16" ||
            op.name == "v_cvt_pknorm_u16_f16" ||
            op.name == "v_min3_f16" ||
            op.name == "v_max3_f16" ||
            op.name == "v_med3_f16")

tests/native_minmax_med3_f16_check.py and tests/cmake/native_minmax_med3_f16.cmake are new files and merge without conflict.

Verified

  • The conflict is that single region; no other file conflicts.
  • Nothing was built or run locally on the merged head.

Not covered

  • The pull-request CI job runs ctest --preset pr. Its filter does not include native_minmax_med3_f16_*, so a green check here does not run the tests this PR adds. They need a run by a reviewer on this head (ctest --preset dev -R '^native_minmax_med3_f16_').
  • The measurements and mutant results posted on #3268 were taken on df6c0545 over older main commits, before v_ldexp_f16 and the v_cvt_pknorm_*_f16 entries joined the list. They are not repeated here.
  • No docs entry for the three ops, and the case counts in the #3268 description (24 cases, 12 draws) predate df6c0545 (29 cases, 14 draws).
**@⁠Leyukaka** on GitHub · 2026-11-29 12:13 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3452) `Leyukaka:takeover-3266-minmax-med3-f16` → `main` · +457 −1 · 4 files · 5 commits · merged 2026-11-29 13:21 UTC #3268 by @⁠legacy-code-archaeologist, merged with `main` so it can land. Supersedes #3268. Fixes #3266. Refs #2935. ### What is here - The two commits of #3268, unchanged and with their original authorship: `b82ba196` (lowering) and `df6c0545` (five added test cases). - One merge commit of `main` (`fe1c1d31`, merge commit `5b06bab7`). It is the only change of mine. ### Conflict resolution `git merge-tree --write-tree fe1c1d31 df6c0545` exits 1 with one conflicted file and one region: the `half_binary` op list in `DirectCompute::lower()`, `src/gfx1013_direct_compute.inl`. `main` extended the list after `v_fract_f16`; #3268 added its three ops at the same place. The resolution keeps both sides, `main`'s entries first: ```cpp op.name == "v_fract_f16" || op.name == "v_ldexp_f16" || op.name == "v_cvt_norm_i16_f16" || op.name == "v_cvt_norm_u16_f16" || op.name == "v_cvt_pknorm_i16_f16" || op.name == "v_cvt_pknorm_u16_f16" || op.name == "v_min3_f16" || op.name == "v_max3_f16" || op.name == "v_med3_f16") ``` `tests/native_minmax_med3_f16_check.py` and `tests/cmake/native_minmax_med3_f16.cmake` are new files and merge without conflict. ### Verified - The conflict is that single region; no other file conflicts. - Nothing was built or run locally on the merged head. ### Not covered - The pull-request CI job runs `ctest --preset pr`. Its filter does not include `native_minmax_med3_f16_*`, so a green check here does not run the tests this PR adds. They need a run by a reviewer on this head (`ctest --preset dev -R '^native_minmax_med3_f16_'`). - The measurements and mutant results posted on #3268 were taken on `df6c0545` over older `main` commits, before `v_ldexp_f16` and the `v_cvt_pknorm_*_f16` entries joined the list. They are not repeated here. - No docs entry for the three ops, and the case counts in the #3268 description (24 cases, 12 draws) predate `df6c0545` (29 cases, 14 draws).
Lower VOP3 v_min3_f16 (0x351), v_max3_f16 (0x354), and v_med3_f16 (0x357) in DirectCompute::float_alu() with abs/neg/clamp/op_sel[3:0], exact binary16 NaN and signed-zero ordering, other-half preservation, binary16 denormal mode tracking, and IR/DXIL/Pixel/Compute tests.

Fixes #3264, Refs #2935. AI-assisted.
Add med3_nan_src2, med3_two_nans, min3_clamp_negative, med3_three_nans_clamp, and min3_inline_neg_int (src0=193) to tests/native_minmax_med3_f16_check.py (29 cases total). Refs #3264, #2935. AI-assisted.
Resolves the half_binary list as the union of both sides.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-29 12:16:10 +00:00
Author
Owner

@⁠JohnConnorNPC on GitHub · 2026-11-29 12:25 UTC · original

Review of head 5b06bab7 (read-only, on Linux; no build or ctest run here). I found no MUST items, 1 SHOULD and 4 NITs.

The merge leaves the #3268 commits unchanged: git range-diff d649e470..df6c0545 fe1c1d31..5b06bab7 shows 1: b82ba196 = 1: b82ba196 and 2: df6c0545 = 2: df6c0545. The only thing the merge adds is the union of the half_binary list. git merge-tree --write-tree origin/main 5b06bab7 exits with rc 0 on current main.

SHOULD

  1. The new tests have not been run on this head. CI run 46261152654 at 5b06bab7 runs none of them, because the pr preset doesn't include them: gh run view 46261152654 --log | grep -c minmax_med3 prints 0. #3451 (1990fead, in this base) made the launchers default to native shaders. So these three ops are now lowered on the default launcher path with no flag, where before this PR they were refused. Before merge, please run this on this head, on WARP and on a GPU:
    ctest --preset dev --no-tests=error -R '^native_minmax_med3_f16_'
    (On the author's Intel adapter, _compute_hardware exited 77, a capability skip.) I expect a pass. The commits are identical, and the helper drift since d649e470 doesn't affect this check: native_f16_alu_check STRIDE went from 512 to 1024, but this check uses a fixed PROLOGUE literal and the hard-coded layout group * 1024 + lane * 32.

NIT

  1. The in-op mode gate only tests the denorm bits, (mode_bits & 0xc0u) != 0xc0u. That is correct, since min/max don't round. But its message says "rounding or denormal". The gate also can't be reached: consume_half_mode refuses first, so neither mode refusal control ever hits it.
  2. The expected values come from a Python model that mirrors the lowering. So the GPU runs show that the DXIL matches the model, not that it matches gfx1013. Three conventions are unmeasured on gfx1013: the two-NaN result 0x7e00, sNaN quieting in IEEE mode, and med3 signed-zero ties. For example, med3(-0, +0, -1) gives 0x8000 here, while the ISA pseudocode (max3 == S0 compared as floats, giving max(S1,S2)) gives 0x0000. This matches the existing v_med3_f32 and v_pk_min_f16, so it is not a regression.
  3. In _controls, the DXIL marker is weak: assert 'icmp ugt i32' in dump and 'icmp ult i32' in dump. The compile rc and the refusal cases carry the real weight.
  4. There is no docs entry for these ops. git grep -E 'v_(min3|max3|med3)_f16' -- '*.md' finds nothing, while the f32 forms are in docs/experiments.md. The case counts in the #3268 body are also stale. Both are already listed under "Not covered" in the body.

This comment was AI-assisted.

**@⁠JohnConnorNPC** on GitHub · 2026-11-29 12:25 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3452#issuecomment-7255800390) Review of head 5b06bab7 (read-only, on Linux; no build or ctest run here). I found no MUST items, 1 SHOULD and 4 NITs. The merge leaves the #3268 commits unchanged: `git range-diff d649e470..df6c0545 fe1c1d31..5b06bab7` shows `1: b82ba196 = 1: b82ba196` and `2: df6c0545 = 2: df6c0545`. The only thing the merge adds is the union of the `half_binary` list. `git merge-tree --write-tree origin/main 5b06bab7` exits with rc 0 on current main. **SHOULD** 1. The new tests have not been run on this head. CI run 46261152654 at 5b06bab7 runs none of them, because the pr preset doesn't include them: `gh run view 46261152654 --log | grep -c minmax_med3` prints `0`. #3451 (1990fead, in this base) made the launchers default to native shaders. So these three ops are now lowered on the default launcher path with no flag, where before this PR they were refused. Before merge, please run this on this head, on WARP and on a GPU: `ctest --preset dev --no-tests=error -R '^native_minmax_med3_f16_'` (On the author's Intel adapter, `_compute_hardware` exited 77, a capability skip.) I expect a pass. The commits are identical, and the helper drift since d649e470 doesn't affect this check: `native_f16_alu_check` STRIDE went from 512 to 1024, but this check uses a fixed PROLOGUE literal and the hard-coded layout `group * 1024 + lane * 32`. **NIT** 1. The in-op mode gate only tests the denorm bits, `(mode_bits & 0xc0u) != 0xc0u`. That is correct, since min/max don't round. But its message says "rounding or denormal". The gate also can't be reached: `consume_half_mode` refuses first, so neither mode refusal control ever hits it. 2. The expected values come from a Python model that mirrors the lowering. So the GPU runs show that the DXIL matches the model, not that it matches gfx1013. Three conventions are unmeasured on gfx1013: the two-NaN result `0x7e00`, sNaN quieting in IEEE mode, and med3 signed-zero ties. For example, med3(-0, +0, -1) gives `0x8000` here, while the ISA pseudocode (`max3 == S0` compared as floats, giving `max(S1,S2)`) gives `0x0000`. This matches the existing `v_med3_f32` and `v_pk_min_f16`, so it is not a regression. 3. In `_controls`, the DXIL marker is weak: `assert 'icmp ugt i32' in dump and 'icmp ult i32' in dump`. The compile rc and the refusal cases carry the real weight. 4. There is no docs entry for these ops. `git grep -E 'v_(min3|max3|med3)_f16' -- '*.md'` finds nothing, while the f32 forms are in `docs/experiments.md`. The case counts in the #3268 body are also stale. Both are already listed under "Not covered" in the body. This comment was AI-assisted.
Author
Owner

@⁠Leyukaka on GitHub · 2026-11-29 12:42 UTC · original

SHOULD 1, run on head 5b06bab7 in an isolated Windows Sandbox with no network: dev preset configured with -DX2W_WITH_OPUS=OFF, full build, then

ctest --preset dev --no-tests=error -R '^native_minmax_med3_f16_'

1/5 native_minmax_med3_f16_ir .................   Passed    1.22 sec
2/5 native_minmax_med3_f16_controls ...........   Passed    2.46 sec
3/5 native_minmax_med3_f16_compute_hardware ...   Passed    2.21 sec
4/5 native_minmax_med3_f16_pixel_warp .........   Passed    5.26 sec
5/5 native_minmax_med3_f16_pixel_hardware .....   Passed   10.00 sec
100% tests passed, 0 tests failed out of 5

Test output:

  • _ir: 29 cases matched exact model; 7 refusals matched.
  • _controls: compiled 29 cases to DXIL; verified 7 refusals.
  • _compute_hardware: 29 cases matched across 2x32 lanes and guards, on a hardware adapter. It passed, it did not exit 77.
  • _pixel_warp and _pixel_hardware: 14 pixel draws (28 cases) matched on each.

WARP is covered by the pixel test only: tests/cmake/native_minmax_med3_f16.cmake registers no WARP variant of the compute test.

NITs:

  1. Will fix in a follow-up commit: the gate at src/gfx1013_direct_compute.inl:2661 tests only (mode_bits & 0xc0u) != 0xc0u, so its message becomes a denormal-only one, as the packed min/max gate at line 3233 already has. The two mode controls get their string from consume_half_mode, so their expected text does not change.
  2. Left as the original author's design. Not measured on gfx1013 here either.
  3. Left as is.
  4. Will add a docs/experiments/ entry for the three ops in the same follow-up commit. The counts in this PR's body (29 cases, 14 draws) match the run above; the #3268 description is not ours to edit.

The follow-up commit changes the head, so the five tests will be rerun on it and the result posted here.

**@⁠Leyukaka** on GitHub · 2026-11-29 12:42 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3452#issuecomment-7256006354) SHOULD 1, run on head `5b06bab7` in an isolated Windows Sandbox with no network: dev preset configured with `-DX2W_WITH_OPUS=OFF`, full build, then `ctest --preset dev --no-tests=error -R '^native_minmax_med3_f16_'` ``` 1/5 native_minmax_med3_f16_ir ................. Passed 1.22 sec 2/5 native_minmax_med3_f16_controls ........... Passed 2.46 sec 3/5 native_minmax_med3_f16_compute_hardware ... Passed 2.21 sec 4/5 native_minmax_med3_f16_pixel_warp ......... Passed 5.26 sec 5/5 native_minmax_med3_f16_pixel_hardware ..... Passed 10.00 sec 100% tests passed, 0 tests failed out of 5 ``` Test output: - `_ir`: 29 cases matched exact model; 7 refusals matched. - `_controls`: compiled 29 cases to DXIL; verified 7 refusals. - `_compute_hardware`: 29 cases matched across 2x32 lanes and guards, on a hardware adapter. It passed, it did not exit 77. - `_pixel_warp` and `_pixel_hardware`: 14 pixel draws (28 cases) matched on each. WARP is covered by the pixel test only: `tests/cmake/native_minmax_med3_f16.cmake` registers no WARP variant of the compute test. NITs: 1. Will fix in a follow-up commit: the gate at `src/gfx1013_direct_compute.inl:2661` tests only `(mode_bits & 0xc0u) != 0xc0u`, so its message becomes a denormal-only one, as the packed min/max gate at line 3233 already has. The two mode controls get their string from `consume_half_mode`, so their expected text does not change. 2. Left as the original author's design. Not measured on gfx1013 here either. 3. Left as is. 4. Will add a `docs/experiments/` entry for the three ops in the same follow-up commit. The counts in this PR's body (29 cases, 14 draws) match the run above; the #3268 description is not ours to edit. The follow-up commit changes the head, so the five tests will be rerun on it and the result posted here.
Author
Owner

@⁠Leyukaka on GitHub · 2026-11-29 12:56 UTC · original

Follow-up commits 14aae9ba and 63416373 (NIT 1 and NIT 4), head is now 63416373. Three files:

  • src/gfx1013_direct_compute.inl:2662: the min3/max3/med3 gate message changes from unsupported binary16 rounding or denormal mode to unsupported binary16 min3/max3/med3 denormal mode. The condition is unchanged.
  • tests/native_minmax_med3_f16_check.py:188: the expected string of the conditional-branch MODE control follows the new message.
  • docs/experiments/native-minmax-med3-f16.md: new entry for the three ops (scope, refusals, test coverage, reproduction).

Correction to my previous comment: only the s_denorm_mode 3 control gets its message from consume_half_mode; the conditional-branch control writes denorm16 = 3, which consume_half_mode accepts, and the refusal comes from the gate itself, so its expected string did change.

Rerun on 14aae9ba (63416373 on top only rewords one sentence of docs/experiments/native-minmax-med3-f16.md, so it was not rerun), same procedure as before (isolated Windows Sandbox, no network, dev preset with -DX2W_WITH_OPUS=OFF, full build):

ctest --preset dev --no-tests=error -R '^native_minmax_med3_f16_'

native_minmax_med3_f16_ir                  Passed    1.32 sec
native_minmax_med3_f16_controls            Passed    2.84 sec
native_minmax_med3_f16_compute_hardware    Passed    2.09 sec
native_minmax_med3_f16_pixel_warp          Passed    4.95 sec
native_minmax_med3_f16_pixel_hardware      Passed   10.54 sec
100% tests passed, 0 tests failed out of 5
**@⁠Leyukaka** on GitHub · 2026-11-29 12:56 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3452#issuecomment-7256177695) Follow-up commits `14aae9ba` and `63416373` (NIT 1 and NIT 4), head is now `63416373`. Three files: - `src/gfx1013_direct_compute.inl:2662`: the min3/max3/med3 gate message changes from `unsupported binary16 rounding or denormal mode` to `unsupported binary16 min3/max3/med3 denormal mode`. The condition is unchanged. - `tests/native_minmax_med3_f16_check.py:188`: the expected string of the conditional-branch MODE control follows the new message. - `docs/experiments/native-minmax-med3-f16.md`: new entry for the three ops (scope, refusals, test coverage, reproduction). Correction to my previous comment: only the `s_denorm_mode 3` control gets its message from `consume_half_mode`; the conditional-branch control writes denorm16 = 3, which `consume_half_mode` accepts, and the refusal comes from the gate itself, so its expected string did change. Rerun on `14aae9ba` (`63416373` on top only rewords one sentence of `docs/experiments/native-minmax-med3-f16.md`, so it was not rerun), same procedure as before (isolated Windows Sandbox, no network, dev preset with `-DX2W_WITH_OPUS=OFF`, full build): `ctest --preset dev --no-tests=error -R '^native_minmax_med3_f16_'` ``` native_minmax_med3_f16_ir Passed 1.32 sec native_minmax_med3_f16_controls Passed 2.84 sec native_minmax_med3_f16_compute_hardware Passed 2.09 sec native_minmax_med3_f16_pixel_warp Passed 4.95 sec native_minmax_med3_f16_pixel_hardware Passed 10.54 sec 100% tests passed, 0 tests failed out of 5 ```
github manually merged commit 17b662a2bb into main 2026-11-29 13:26:58 +00:00
Author
Owner

@⁠JohnConnorNPC on GitHub · 2026-11-29 13:21 UTC · original

Re-review of the delta 5b06bab7 → 63416373 (read-only, on Linux; no build or ctest run here). No MUST, SHOULD or new NIT items. Merging.

  • SHOULD 1 is resolved by the Windows Sandbox run posted above: ctest --preset dev --no-tests=error -R '^native_minmax_med3_f16_' gave 5/5 passed on 14aae9ba, with _compute_hardware passing on a hardware adapter rather than exiting 77. git diff 14aae9ba 63416373 --stat touches only docs/experiments/native-minmax-med3-f16.md, so not rerunning on 63416373 is fine.
  • NIT 1 is fixed. The gate condition is unchanged ((mode_bits & 0xc0u) != 0xc0u), and the message now reads unsupported binary16 min3/max3/med3 denormal mode. Thanks for the correction: the conditional-branch MODE control does reach this gate. My earlier note that neither control could reach it was wrong. The test now pins the new string for that control and keeps consume_half_mode's string for s_denorm_mode 3.
  • NIT 4 is fixed by the new docs/experiments/native-minmax-med3-f16.md. It agrees with the code: opcodes 0x351/0x354/0x357, two NaNs give 0x7e00, med3 with a NaN gives min(min(a, b), c), and clamp sends NaN or a negative result to +0.0h and anything above 1.0h to 1.0h. It also states that WARP covers only the Pixel path.
  • NITs 2 and 3 are left as they were, as stated.
  • Checks: git merge-tree --write-tree origin/main 63416373 rc 0 on main c04e0dd6. CI at 63416373: Windows, Linux Python and gfx1013 fixtures pass. Delta hygiene: git diff --check rc 0, non-noreply emails 0, title-pattern hits 0, added @ lines 0.

This comment was AI-assisted.

**@⁠JohnConnorNPC** on GitHub · 2026-11-29 13:21 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3452#issuecomment-7256482444) Re-review of the delta 5b06bab7 → 63416373 (read-only, on Linux; no build or ctest run here). No MUST, SHOULD or new NIT items. Merging. - SHOULD 1 is resolved by the Windows Sandbox run posted above: `ctest --preset dev --no-tests=error -R '^native_minmax_med3_f16_'` gave 5/5 passed on 14aae9ba, with `_compute_hardware` passing on a hardware adapter rather than exiting 77. `git diff 14aae9ba 63416373 --stat` touches only `docs/experiments/native-minmax-med3-f16.md`, so not rerunning on 63416373 is fine. - NIT 1 is fixed. The gate condition is unchanged (`(mode_bits & 0xc0u) != 0xc0u`), and the message now reads `unsupported binary16 min3/max3/med3 denormal mode`. Thanks for the correction: the conditional-branch MODE control does reach this gate. My earlier note that neither control could reach it was wrong. The test now pins the new string for that control and keeps `consume_half_mode`'s string for `s_denorm_mode 3`. - NIT 4 is fixed by the new `docs/experiments/native-minmax-med3-f16.md`. It agrees with the code: opcodes 0x351/0x354/0x357, two NaNs give `0x7e00`, med3 with a NaN gives `min(min(a, b), c)`, and clamp sends NaN or a negative result to `+0.0h` and anything above `1.0h` to `1.0h`. It also states that WARP covers only the Pixel path. - NITs 2 and 3 are left as they were, as stated. - Checks: `git merge-tree --write-tree origin/main 63416373` rc 0 on main c04e0dd6. CI at 63416373: Windows, Linux Python and gfx1013 fixtures pass. Delta hygiene: `git diff --check` rc 0, non-noreply emails 0, title-pattern hits 0, added `@` lines 0. This comment was AI-assisted.
This discussion has been locked. Commenting is limited to contributors.
No description provided.