shader: support neg_lo, neg_hi, and clamp on v_pk_min/max_f16 #3265

Manually merged
github merged 2 commits from github-bot/gh-3263 into gh-pr/3263/base 2026-11-28 05:28:05 +00:00 AGit
Owner

@⁠legacy-code-archaeologist on GitHub · 2026-11-28 02:37 UTC · original
legacy-code-archaeologist:shader/direct-packed-minmax-f16-mods → main · +123 −44 · 3 files · 2 commits · merged 2026-11-28 05:24 UTC

Supports VOP3P neg_lo, neg_hi, and clamp modifiers on v_pk_min_f16 and v_pk_max_f16 in DirectCompute::packed_minmax(), addressing unsupported packed 16-bit min/max encoding in #3226's refreshed census.

Fixes #3263. Refs #2935, #3226.

Summary

  • src/gfx1013_direct_compute.inl (DirectCompute::packed_minmax()):
    • Admits NEG_LO[1:0], NEG_HI[1:0], and CLAMP when floating (v_pk_min_f16 / v_pk_max_f16), while continuing to refuse NEG_LO[2], NEG_HI[2], OP_SEL[2], nonzero src2, and all clamp/negation bits on v_pk_min/max_{i16,u16} with unsupported packed 16-bit min/max encoding.
    • Applies input sign-bit inversion (xor 32768) before NaN/zero/min/max comparison and applies binary16 output clamp (NaN / negative -> +0.0, > 0x3bff -> 1.0, positive subnormals preserved) after NaN selection.
  • tests/native_packed_minmax_check.py:
    • Extended packed(), half_result(), and expected() with neg_lo, neg_hi, and clamp.
    • Added MOD_CASES (9 asymmetric neg_lo / neg_hi, -0.0 / -Inf / +Inf / NaN clamp, positive subnormal clamp, and combined negation+clamp cases, across VGPR, SGPR, and literal src0) verified in controls, compute, and lossless pixel (warp and hardware: i16 4 + u16 4 + f16 13 cases).
    • Updated controls() to keep testing reserved modifier bits on f16 (NEG_HI[2], OP_SEL[2], NEG_LO[2]) and existing refusals on i16/u16.

Verification (dev and release /O2, Windows 10.0.26100)

  • ctest --preset dev --no-tests=error -V -R '^native_packed_minmax_' & ctest --preset release --no-tests=error -V -R '^native_packed_minmax_':
    • native_packed_minmax_controls: Passed (6 opcodes compiled including f16 with neg_lo/neg_hi/clamp; reserved/integer mods and f16 flush mode refused).
    • native_packed_minmax_pixel_warp: Passed (Microsoft Basic Render Driver 10.0.26100.9711, 4+4+13 Pixel cases matched; debug_layer=unavailable).
    • native_packed_minmax_pixel_hardware: Passed (4+4+13 Pixel cases matched; NVIDIA Quadro M1000M, 32.0.15.7371, debug_layer=unavailable).
    • native_packed_minmax_compute_hardware: Skipped (77) (Intel(R) HD Graphics 530, vendor 8086, device 191b, driver 31.0.101.2111 lacks SM 6.6 wave32 — needs testing on a wave32-capable GPU).
  • ctest --preset dev --no-tests=error -V -R '^native_f16_alu_ir$': Passed (82 results, 14 refusals); the remaining 68 native_.*_(controls|ir) tests in dev also passed.
  • Sensitivity mutants caught (rc=8): swapping i.neg/i.abs between low and high lanes (f16-mod-0), disabling if (i.clamp) (f16-mod-4), and dropping the NaN check in clamp (f16-mod-7) all failed native_packed_minmax_pixel_warp.

AI-assisted.

**@⁠legacy-code-archaeologist** on GitHub · 2026-11-28 02:37 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3263) `legacy-code-archaeologist:shader/direct-packed-minmax-f16-mods` → `main` · +123 −44 · 3 files · 2 commits · merged 2026-11-28 05:24 UTC Supports VOP3P `neg_lo`, `neg_hi`, and `clamp` modifiers on `v_pk_min_f16` and `v_pk_max_f16` in `DirectCompute::packed_minmax()`, addressing `unsupported packed 16-bit min/max encoding` in #3226's refreshed census. Fixes #3263. Refs #2935, #3226. ### Summary - **`src/gfx1013_direct_compute.inl` (`DirectCompute::packed_minmax()`):** - Admits `NEG_LO[1:0]`, `NEG_HI[1:0]`, and `CLAMP` when `floating` (`v_pk_min_f16` / `v_pk_max_f16`), while continuing to refuse `NEG_LO[2]`, `NEG_HI[2]`, `OP_SEL[2]`, nonzero `src2`, and all clamp/negation bits on `v_pk_min/max_{i16,u16}` with `unsupported packed 16-bit min/max encoding`. - Applies input sign-bit inversion (`xor 32768`) before NaN/zero/min/max comparison and applies binary16 output clamp (`NaN` / negative -> `+0.0`, `> 0x3bff` -> `1.0`, positive subnormals preserved) after NaN selection. - **`tests/native_packed_minmax_check.py`:** - Extended `packed()`, `half_result()`, and `expected()` with `neg_lo`, `neg_hi`, and `clamp`. - Added `MOD_CASES` (`9` asymmetric `neg_lo` / `neg_hi`, `-0.0` / `-Inf` / `+Inf` / NaN clamp, positive subnormal clamp, and combined negation+clamp cases, across VGPR, SGPR, and literal `src0`) verified in `controls`, `compute`, and lossless `pixel` (`warp` and `hardware`: `i16` 4 + `u16` 4 + `f16` 13 cases). - Updated `controls()` to keep testing reserved modifier bits on `f16` (`NEG_HI[2]`, `OP_SEL[2]`, `NEG_LO[2]`) and existing refusals on `i16`/`u16`. ### Verification (`dev` and `release` `/O2`, Windows `10.0.26100`) - `ctest --preset dev --no-tests=error -V -R '^native_packed_minmax_'` & `ctest --preset release --no-tests=error -V -R '^native_packed_minmax_'`: - `native_packed_minmax_controls`: **Passed** (6 opcodes compiled including `f16` with `neg_lo`/`neg_hi`/`clamp`; reserved/integer mods and `f16` flush mode refused). - `native_packed_minmax_pixel_warp`: **Passed** (`Microsoft Basic Render Driver` `10.0.26100.9711`, `4+4+13` Pixel cases matched; `debug_layer=unavailable`). - `native_packed_minmax_pixel_hardware`: **Passed** (`4+4+13` Pixel cases matched; `NVIDIA Quadro M1000M`, `32.0.15.7371`, `debug_layer=unavailable`). - `native_packed_minmax_compute_hardware`: **Skipped (`77`)** (`Intel(R) HD Graphics 530`, vendor `8086`, device `191b`, driver `31.0.101.2111` lacks SM 6.6 wave32 — needs testing on a wave32-capable GPU). - `ctest --preset dev --no-tests=error -V -R '^native_f16_alu_ir$'`: **Passed** (`82` results, `14` refusals); the remaining `68` `native_.*_(controls|ir)` tests in `dev` also passed. - Sensitivity mutants caught (`rc=8`): swapping `i.neg`/`i.abs` between `low` and `high` lanes (`f16-mod-0`), disabling `if (i.clamp)` (`f16-mod-4`), and dropping the NaN check in `clamp` (`f16-mod-7`) all failed `native_packed_minmax_pixel_warp`. AI-assisted.
Admit VOP3P NEG_LO[1:0], NEG_HI[1:0], and CLAMP on v_pk_min_f16 and v_pk_max_f16 in DirectCompute::packed_minmax() while keeping third-operand/reserved modifier bits and integer packed min/max clamp/negation refused, and extend native_packed_minmax_check.py with modifier compute/pixel/control tests.

Fixes #3261, Refs #2935, #3224. AI-assisted.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 02:40:28 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-28 02:49 UTC · original · requested changes

I reviewed 8d5bd5d145 on main 4d7265c0 (trial b9b6c8a6eb). The modifier bits are applied per half before comparison, clamp is applied after selection, and integer/reserved encodings retain their refusal controls. The Compute adapter that was skipped in the author run is now covered: exact 2,064-word readbacks include both negate groups, subnormal and NaN clamp cases, and the buffer guards.

ctest --test-dir <build> --no-tests=error --output-on-failure -j 1 -R "^native_(packed_minmax_.*|f16_alu_ir)$"

Debug and Release /O2 each passed 5/5, zero skips, including physical Compute and both Pixel adapters. Windows 11 26200.9974, RTX 4060 Laptop 32.0.16.1656, and inbox WARP 10.0.26100.9818. Pixel used the debug layer. The standalone Compute replay did not.

Please update docs/experiments/native-packed-minmax.md. It still says that negation and clamp are refused for the whole family. The new scope is floating-point only, with the integer and reserved-encoding refusals preserved. Include the extended fixture coverage.

**@⁠R0Y00** on GitHub · 2026-11-28 02:49 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3263#pullrequestreview-6095264641) · **requested changes** I reviewed 8d5bd5d14546 on main 4d7265c0 (trial b9b6c8a6eb9f7e2a6e3a4df289dd394217da1468). The modifier bits are applied per half before comparison, clamp is applied after selection, and integer/reserved encodings retain their refusal controls. The Compute adapter that was skipped in the author run is now covered: exact 2,064-word readbacks include both negate groups, subnormal and NaN clamp cases, and the buffer guards. ``` ctest --test-dir <build> --no-tests=error --output-on-failure -j 1 -R "^native_(packed_minmax_.*|f16_alu_ir)$" ``` Debug and Release /O2 each passed 5/5, zero skips, including physical Compute and both Pixel adapters. Windows 11 26200.9974, RTX 4060 Laptop 32.0.16.1656, and inbox WARP 10.0.26100.9818. Pixel used the debug layer. The standalone Compute replay did not. Please update docs/experiments/native-packed-minmax.md. It still says that negation and clamp are refused for the whole family. The new scope is floating-point only, with the integer and reserved-encoding refusals preserved. Include the extended fixture coverage.
Clarify FP16-only neg_lo[1:0], neg_hi[1:0], and clamp semantics, preserved integer/reserved-bit refusals, and extended MOD_CASES/Pixel coverage in native-packed-minmax.md. Refs #3261, #2935, #3224. AI-assisted.
Author
Owner

@⁠legacy-code-archaeologist on GitHub · 2026-11-28 05:10 UTC · original

Thanks @⁠R0Y00 — updated docs/experiments/native-packed-minmax.md to match the v_pk_min_f16 / v_pk_max_f16 modifier support:

  • documented FP16 neg_lo[1:0], neg_hi[1:0] (sign-bit flip per selected operand half prior to comparison) and clamp ([+0.0, 1.0] saturation with NaN -> +0.0 after min/max selection)
  • documented preserved refusals on integer v_pk_min/max_{i16,u16} modifiers and unused third-operand fields (src2, op_sel[2], neg_lo[2], neg_hi[2])
  • documented the extended compute MOD_CASES and 13 f16 Pixel fixture cases

Re-verified on the updated commit (dev and release presets):

  • python -B tests/docs_links_check.py: passed (132 Markdown files, 635 links)
  • ctest --preset dev --no-tests=error --output-on-failure -j 1 -V -R '^native_packed_minmax_': native_packed_minmax_controls, native_packed_minmax_pixel_warp (Microsoft Basic Render Driver), and native_packed_minmax_pixel_hardware passed; native_packed_minmax_compute_hardware skipped (77 on local Intel HD Graphics 530 31.0.101.2111 lacking SM 6.6 wave32)
  • ctest --preset release --no-tests=error --output-on-failure -j 1 -V -R '^native_packed_minmax_': 3 passed, 1 skipped (77 on Intel HD Graphics 530)

AI-assisted.

**@⁠legacy-code-archaeologist** on GitHub · 2026-11-28 05:10 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3263#issuecomment-7234506732) Thanks @⁠R0Y00 — updated `docs/experiments/native-packed-minmax.md` to match the `v_pk_min_f16` / `v_pk_max_f16` modifier support: - documented FP16 `neg_lo[1:0]`, `neg_hi[1:0]` (sign-bit flip per selected operand half prior to comparison) and `clamp` (`[+0.0, 1.0]` saturation with `NaN -> +0.0` after min/max selection) - documented preserved refusals on integer `v_pk_min/max_{i16,u16}` modifiers and unused third-operand fields (`src2`, `op_sel[2]`, `neg_lo[2]`, `neg_hi[2]`) - documented the extended compute `MOD_CASES` and 13 `f16` Pixel fixture cases Re-verified on the updated commit (`dev` and `release` presets): - `python -B tests/docs_links_check.py`: passed (`132` Markdown files, `635` links) - `ctest --preset dev --no-tests=error --output-on-failure -j 1 -V -R '^native_packed_minmax_'`: `native_packed_minmax_controls`, `native_packed_minmax_pixel_warp` (Microsoft Basic Render Driver), and `native_packed_minmax_pixel_hardware` passed; `native_packed_minmax_compute_hardware` skipped (`77` on local Intel HD Graphics 530 `31.0.101.2111` lacking SM 6.6 wave32) - `ctest --preset release --no-tests=error --output-on-failure -j 1 -V -R '^native_packed_minmax_'`: `3` passed, `1` skipped (`77` on Intel HD Graphics 530) AI-assisted.
github-bot changed target branch from main to gh-pr/3263/base 2026-11-28 05:28:02 +00:00
github manually merged commit 9388799c8c into gh-pr/3263/base 2026-11-28 05:28:05 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-28 05:24 UTC · original · approved these changes

Re-reviewed 9388799c. The only revision since 8d5bd5d1 is the experiment note. It now covers FP16-only negate/clamp, the integer and reserved-encoding refusals, and the new fixture cases. The implementation and fixtures are byte-identical to those independently tested in Debug and Release /O2 (5/5 each, zero skips, including RTX Compute and RTX/WARP Pixel). The requested documentation change is resolved.

**@⁠R0Y00** on GitHub · 2026-11-28 05:24 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3263#pullrequestreview-6096001626) · **approved these changes** Re-reviewed `9388799c`. The only revision since `8d5bd5d1` is the experiment note. It now covers FP16-only negate/clamp, the integer and reserved-encoding refusals, and the new fixture cases. The implementation and fixtures are byte-identical to those independently tested in Debug and Release /O2 (5/5 each, zero skips, including RTX Compute and RTX/WARP Pixel). The requested documentation change is resolved.
Author
Owner

@⁠pigalot on GitHub · 2026-11-28 06:18 UTC · original · approved these changes

Reviewed 9388799c integrated over current main aeef65b2. The merge is clean (tree 9d345bc7) and git diff --cached --check is clean.

R0Y00's changes request on 8d5bd5d1 (docs): addressed. 9388799c changes only docs/experiments/native-packed-minmax.md. It now limits negation and clamp to v_pk_min_f16/v_pk_max_f16, keeps the integer-form and unused third-operand refusals (src2, op_sel[2], neg_lo[2], neg_hi[2]), and describes the 9 MOD_CASES and the 13 f16 Pixel cases. Each statement matches the code and the check.

What I traced in packed_minmax().

  • Negation: NEG_LO is the VOP3P neg field and NEG_HI the abs field. The low lane takes i.neg and the high lane i.abs, and bit j flips the sign of source j's selected half before the NaN test and the compare. That is the per-lane meaning of the VOP3P negate bits.
  • Clamp: it applies after NaN selection. NaN and any value with the sign bit set (so -0.0 too) become +0.0, anything above 0x3bff becomes 1.0, and positive subnormals pass through.
  • Refusals: the integer forms still refuse clamp, neg_lo and neg_hi.
  • The reference: half_result() in the check follows the same order: negate, select, clamp.

What I ran.

  • Builds: full dev and release /O2.
  • CPU: ctest --test-dir out/build/<preset> --no-tests=error -j 4 -R '^native_(packed_minmax_.*|f16_alu_ir)$' -E '_hardware$': native_packed_minmax_controls, native_packed_minmax_pixel_warp and native_f16_alu_ir pass in each preset.
  • Hardware: ctest --test-dir out/build/<preset> --no-tests=error -j 1 -V -R '^native_packed_minmax_.*_hardware$' passes 2/2 in each preset, with no skips.
    • native_packed_minmax_compute_hardware matches 2064 words for each of i16, u16 and f16, plus the 9×2 modifier cases. This is the wave32 Compute run the description lists as skipped.
    • native_packed_minmax_pixel_hardware matches 4+4+13 cases.
  • Full suite: ctest --test-dir out/build/dev --no-tests=error -j 8 -E '(startup_audio|_hardware$)' gives 2033 tests: 1973 pass, 0 fail and 60 are capability skips.

Mutants of src/gfx1013_direct_compute.inl, each rebuilt in dev and run against native_packed_minmax_controls, native_packed_minmax_pixel_warp and native_packed_minmax_compute_hardware, after an unmutated baseline that passes:

Mutant Result
NEG_LO and NEG_HI lanes swapped killed (Pixel WARP, Compute hardware)
src1 negation dropped killed (Pixel WARP, Compute hardware)
clamp ignored killed (Pixel WARP, Compute hardware)
clamp keeps NaN instead of +0.0 killed (Pixel WARP, Compute hardware)
clamp keeps negative results killed (Pixel WARP, Compute hardware)
f16 accepts NEG_LO[2] killed (controls)
integer forms accept clamp killed (controls)
clamp's upper threshold 0x3bff → 0x3fff (only values above 2.0 saturate) survives

Restored afterwards; git diff --quiet is clean.

Non-blocking. No clamped lane has a result strictly between 1.0 and 2.0. Every clamped value above 1.0 in MOD_CASES is 2.0 (0x4000), +Inf or 65504 (0x7bff), and each of those is also above 0x3fff. So the threshold could sit anywhere in 0x3bff..0x3fff without a failure. A clamped max whose result is 0x3c01 (the next value above 1.0), or 1.5 (0x3e00), would pin it.

Verdict: approve on 9388799c.

Environment: NVIDIA GeForce RTX 5090 driver 32.0.16.1088; Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; DXC 1.9.2602.17; Python 3.12.10; wave32; debug layer off.
CI: Build and test on Windows, Assemble and translate gfx1013 fixtures and Run platform-independent Python checks on Linux pass on 9388799c.

This reply was AI-assisted.

**@⁠pigalot** on GitHub · 2026-11-28 06:18 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3263#pullrequestreview-6096244017) · **approved these changes** Reviewed `9388799c` integrated over current `main` `aeef65b2`. The merge is clean (tree `9d345bc7`) and `git diff --cached --check` is clean. **R0Y00's changes request on `8d5bd5d1` (docs): addressed.** `9388799c` changes only `docs/experiments/native-packed-minmax.md`. It now limits negation and clamp to `v_pk_min_f16`/`v_pk_max_f16`, keeps the integer-form and unused third-operand refusals (`src2`, `op_sel[2]`, `neg_lo[2]`, `neg_hi[2]`), and describes the 9 `MOD_CASES` and the 13 `f16` Pixel cases. Each statement matches the code and the check. **What I traced in `packed_minmax()`.** - **Negation:** NEG_LO is the VOP3P `neg` field and NEG_HI the `abs` field. The low lane takes `i.neg` and the high lane `i.abs`, and bit j flips the sign of source j's selected half before the NaN test and the compare. That is the per-lane meaning of the VOP3P negate bits. - **Clamp:** it applies after NaN selection. NaN and any value with the sign bit set (so `-0.0` too) become `+0.0`, anything above `0x3bff` becomes `1.0`, and positive subnormals pass through. - **Refusals:** the integer forms still refuse `clamp`, `neg_lo` and `neg_hi`. - **The reference:** `half_result()` in the check follows the same order: negate, select, clamp. **What I ran.** - **Builds:** full `dev` and `release` `/O2`. - **CPU:** `ctest --test-dir out/build/<preset> --no-tests=error -j 4 -R '^native_(packed_minmax_.*|f16_alu_ir)$' -E '_hardware$'`: `native_packed_minmax_controls`, `native_packed_minmax_pixel_warp` and `native_f16_alu_ir` pass in each preset. - **Hardware:** `ctest --test-dir out/build/<preset> --no-tests=error -j 1 -V -R '^native_packed_minmax_.*_hardware$'` passes 2/2 in each preset, with no skips. - `native_packed_minmax_compute_hardware` matches 2064 words for each of `i16`, `u16` and `f16`, plus the 9×2 modifier cases. This is the wave32 Compute run the description lists as skipped. - `native_packed_minmax_pixel_hardware` matches 4+4+13 cases. - **Full suite:** `ctest --test-dir out/build/dev --no-tests=error -j 8 -E '(startup_audio|_hardware$)'` gives 2033 tests: 1973 pass, 0 fail and 60 are capability skips. **Mutants** of `src/gfx1013_direct_compute.inl`, each rebuilt in `dev` and run against `native_packed_minmax_controls`, `native_packed_minmax_pixel_warp` and `native_packed_minmax_compute_hardware`, after an unmutated baseline that passes: | Mutant | Result | |---|---| | NEG_LO and NEG_HI lanes swapped | killed (Pixel WARP, Compute hardware) | | `src1` negation dropped | killed (Pixel WARP, Compute hardware) | | clamp ignored | killed (Pixel WARP, Compute hardware) | | clamp keeps NaN instead of `+0.0` | killed (Pixel WARP, Compute hardware) | | clamp keeps negative results | killed (Pixel WARP, Compute hardware) | | `f16` accepts `NEG_LO[2]` | killed (controls) | | integer forms accept `clamp` | killed (controls) | | clamp's upper threshold `0x3bff` → `0x3fff` (only values above 2.0 saturate) | **survives** | Restored afterwards; `git diff --quiet` is clean. **Non-blocking.** No clamped lane has a result strictly between 1.0 and 2.0. Every clamped value above 1.0 in `MOD_CASES` is 2.0 (`0x4000`), `+Inf` or 65504 (`0x7bff`), and each of those is also above `0x3fff`. So the threshold could sit anywhere in `0x3bff`..`0x3fff` without a failure. A clamped `max` whose result is `0x3c01` (the next value above 1.0), or 1.5 (`0x3e00`), would pin it. **Verdict:** approve on `9388799c`. Environment: NVIDIA GeForce RTX 5090 driver 32.0.16.1088; Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; DXC 1.9.2602.17; Python 3.12.10; wave32; debug layer off. CI: `Build and test on Windows`, `Assemble and translate gfx1013 fixtures` and `Run platform-independent Python checks on Linux` pass on `9388799c`. This reply was AI-assisted.
This discussion has been locked. Commenting is limited to contributors.
No description provided.