startup: lower v_pk_max_f16 and v_pk_min_f16 in gfx2hlsl (Part of #2022) #2927

Merged
Leyukaka merged 1 commit from upstream-pr/2927 into main 2026-11-27 05:02:32 +00:00
Leyukaka commented 2026-11-26 21:31:40 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-26T21:31:40Z.


Part of #2022 (claim).

Change (tools/startup/gfx2hlsl.py): v_pk_max_f16 and v_pk_min_f16 lower per lane through packed_half.

  • Sources. Each source may be a single VGPR, a numeric SGPR (S(), after reject_lane_mask_data), a 32-bit hex literal or the inline 0. It is read as a full word. op_sel[i] picks its low or high half for the low result, and op_sel_hi[i] for the high result, with defaults 0 and 1. This is the packed-source rule that tools/pixel_aot.py implements in vop3p_f16_word.

  • Result. It is the selected binary16 encoding of one input, so nothing goes through a float conversion. minmax16_bits in the preamble:

    • detects NaN on the encoding ((x & 0x7fff) > 0x7c00), not with a float isnan();
    • returns the other operand when one input is NaN, and 0x7e00 when both are (that payload is not hardware-proven);
    • otherwise compares an order key that puts negatives below positives and -0 below +0, so mixed zeros give -0 for min and +0 for max in either order.

    The one-NaN and signed-zero rules are those of pixel_aot.py's minmax16_num. Unlike it, minmax16_bits works on the encodings and returns 0x7e00 for two NaNs, where minmax16_num returns its second operand.

  • Still refused:

    • nonzero inline integers, inline floats and other operands (vcc, exec, ranges, symbolic SGPRs);
    • neg_lo, neg_hi, clamp and other modifiers.

    v_pk_add/mul/fma_f16 still take VGPRs only, and the packed_half docstring now says which forms accept what.

Tests (Windows 11, Python 3.14, DXC from the Windows SDK 10.0.26100, on main 6ee878d8 plus this commit):

  • New tests/startup_gfx2hlsl_pk_minmax_check.py: ok. It checks:
    • the emitted HLSL for a VGPR, an SGPR, a hex word and the inline 0, each with default, reversed and mixed selectors;
    • refusal controls for the kept refusals;
    • that packed add, mul and fma still refuse a hex literal.
  • ... draw <dxc> <offscreen_check> warp and hardware: ok on WARP (Microsoft Basic Render Driver) and an NVIDIA GeForce RTX 5080. A source-built program is read back against a CPU reference, both halves separately, for:
    • mixed and equal signed zeros in either order;
    • one NaN in either position, and two NaNs;
    • opposite infinities and subnormals;
    • a selector flip on a literal and on an SGPR;
    • the inline 0 with an explicit high selector;
    • two VGPRs.
  • Also ok: startup_gfx2hlsl_f16_alu_check, startup_translator_check, startup_gfx2hlsl_refusals_check, shader_signed_zero_minmax_check, docs_links_check, bidi_controls_check.

Mutation checks, run by hand:

  • Swapping the op_sel/op_sel_hi roles fails the controls and the WARP draw.
  • Using max for min fails the controls and the WARP draw.
  • Folding the NaN test to false fails the WARP draw.

Measured on a local capture (counts and instruction shape only):

  • Census: 4 of the 6 census requests that stopped at these instructions now translate. The other 2 stop next at v_pk_mul_f16 with a literal source, which this PR keeps refused.
  • Start-up run: of the two compute pipelines that stopped at v_pk_max_f16:
    • the one dispatched 211 times now translates;
    • the one dispatched 5,152 times stops next at the same v_pk_mul_f16 literal.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5517410465 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2927). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-26T21:31:40Z. --- Part of #2022 ([claim](https://github.com/R0Y00/Xbox2Windows/issues/2022#issuecomment-7203654842)). **Change** (`tools/startup/gfx2hlsl.py`): `v_pk_max_f16` and `v_pk_min_f16` lower per lane through `packed_half`. - **Sources.** Each source may be a single VGPR, a numeric SGPR (`S()`, after `reject_lane_mask_data`), a 32-bit hex literal or the inline `0`. It is read as a full word. `op_sel[i]` picks its low or high half for the low result, and `op_sel_hi[i]` for the high result, with defaults 0 and 1. This is the packed-source rule that `tools/pixel_aot.py` implements in `vop3p_f16_word`. - **Result.** It is the selected binary16 encoding of one input, so nothing goes through a float conversion. `minmax16_bits` in the preamble: - detects NaN on the encoding (`(x & 0x7fff) > 0x7c00`), not with a float `isnan()`; - returns the other operand when one input is NaN, and `0x7e00` when both are (that payload is not hardware-proven); - otherwise compares an order key that puts negatives below positives and `-0` below `+0`, so mixed zeros give `-0` for min and `+0` for max in either order. The one-NaN and signed-zero rules are those of `pixel_aot.py`'s `minmax16_num`. Unlike it, `minmax16_bits` works on the encodings and returns `0x7e00` for two NaNs, where `minmax16_num` returns its second operand. - **Still refused:** - nonzero inline integers, inline floats and other operands (`vcc`, `exec`, ranges, symbolic SGPRs); - `neg_lo`, `neg_hi`, `clamp` and other modifiers. `v_pk_add/mul/fma_f16` still take VGPRs only, and the `packed_half` docstring now says which forms accept what. **Tests** (Windows 11, Python 3.14, DXC from the Windows SDK 10.0.26100, on main `6ee878d8` plus this commit): - New `tests/startup_gfx2hlsl_pk_minmax_check.py`: ok. It checks: - the emitted HLSL for a VGPR, an SGPR, a hex word and the inline `0`, each with default, reversed and mixed selectors; - refusal controls for the kept refusals; - that packed add, mul and fma still refuse a hex literal. - `... draw <dxc> <offscreen_check> warp` and `hardware`: ok on WARP (Microsoft Basic Render Driver) and an NVIDIA GeForce RTX 5080. A source-built program is read back against a CPU reference, both halves separately, for: - mixed and equal signed zeros in either order; - one NaN in either position, and two NaNs; - opposite infinities and subnormals; - a selector flip on a literal and on an SGPR; - the inline `0` with an explicit high selector; - two VGPRs. - Also ok: `startup_gfx2hlsl_f16_alu_check`, `startup_translator_check`, `startup_gfx2hlsl_refusals_check`, `shader_signed_zero_minmax_check`, `docs_links_check`, `bidi_controls_check`. **Mutation checks**, run by hand: - Swapping the `op_sel`/`op_sel_hi` roles fails the controls and the WARP draw. - Using max for min fails the controls and the WARP draw. - Folding the NaN test to false fails the WARP draw. **Measured on a local capture** (counts and instruction shape only): - **Census:** 4 of the 6 census requests that stopped at these instructions now translate. The other 2 stop next at `v_pk_mul_f16` with a literal source, which this PR keeps refused. - **Start-up run:** of the two compute pipelines that stopped at `v_pk_max_f16`: - the one dispatched 211 times now translates; - the one dispatched 5,152 times stops next at the same `v_pk_mul_f16` literal. AI-assisted.
thepatrickworld commented 2026-11-26 21:54:54 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-26T21:54:54Z.


Independent AMD RDNA 4 result on 3d848649: the emitted formula matches the reference on the card, and only a draw pins the helper body. Measurements only.

The open point in tools/startup/gfx2hlsl.py stays open: the two-NaN payload (0x7e00) has no hardware confirmation, and an AMD run cannot close it (see Limits). What the card adds is a second vendor for the draw, plus the three mutants below.

Environment

  • Windows 11 10.0.26200.9974 (build and UBR from ver).
  • AMD Radeon RX 9070 XT 1002:7550, driver 32.0.32029.2010; in-box WARP 1414:008c, driver 10.0.26100.9818.
  • MSVC 19.44.35230 x64 (toolset 14.44.35207), DXC 1.9.2602.17, FXC 10.0.26100.9457.
  • debug_layer=unavailable on both adapters: no API validation in any run below.
  • Worktree at 3d848649 (base 6ee878d8), git status --porcelain --untracked-files=no empty before the matrix and after every restore.

Commands

cmake --preset dev "-DINTAKE_PYTHON=C:/.../x2w-pr641/out/pe-env/Scripts/python.exe"
cmake --build --preset dev --target offscreen_check
ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_pk_minmax' -V
python -B tests/startup_gfx2hlsl_pk_minmax_check.py draw <dxc.exe> <offscreen_check.exe> warp
python -B tests/startup_gfx2hlsl_pk_minmax_check.py draw <dxc.exe> <offscreen_check.exe> hardware

XBOX2WINDOWS_ADAPTER is set with the quoted form, so the name carries no trailing space.

Observed

  • Registered names: startup_gfx2hlsl_pk_minmax_controls, _warp, _hardware (ctest -N, 3 entries); ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_pk_minmax' -V → 100% tests passed out of 3. The hardware entry returned 0, not a 77 skip, and the renderer printed its adapter inside the draw log:
backend=hardware debug_layer=unavailable
adapter=AMD Radeon RX 9070 XT vendor=1002 device=7550
driver=32.0.32029.2010
startup_flat_param words=40004000,40004000,40007e00,40007c00
nan_and_range_max, shift 16: 40004000,40004000,40007e00,40007c00
  • 12 launches per backend (3 groups × 2 ops × 2 shifts), 48 readback words each, all equal to the fixture's CPU reference. Four of those 48 words are the two-NaN channels, i.e. the fixture's own payload.
  • The helper is not folded away by DXC: in the DXIL of the selectors group's max program at shift 0 (sources: a literal, an SGPR-held constant and an inline zero), all four storeOutput values are computed SSA values, none is an immediate. The readback therefore comes from the integer formula, not from a compile-time constant.
  • Neighbours on the same tree: ctest -R '^startup_gfx2hlsl_f16_alu' → 4 entries, 100% tests passed out of 4; tests/shader_signed_zero_minmax_check.py draw <dxc> <offscreen_check> hardware exit 0. The WARP draw also returns 0 here, which reproduces your WARP result on a second machine.

Three helper-body mutants (mine; the fixture documents a different set)

Each one edits minmax16_bits in tools/startup/gfx2hlsl.py (Python, so no rebuild). For each: the applied hunk and the mutated sha256 are in the log, and after git checkout -- the file's sha256 is back to 1c1cec187e8401ec07291e13b1d224a9238cd11c2f124f780ff9d79b155aca38, git status --porcelain --untracked-files=no is empty, and the same draw returns 0 again.

  1. (a & 0x7fffu) > 0x7c00u → >= 0x7c00u on both operands (infinity read as NaN): controls exit 0, card draw exit 1 — nan_and_range_min shift 16, expected …4000fc00 actual …40007e00.
  2. two-NaN payload 0x7e00u → 0x7c01u: controls exit 0, card draw exit 1 — nan_and_range_min shift 0, expected …40007e00,…40008001 actual …40007c01,…40008001 (the third word, as a payload change should).
  3. if (b_nan) return a; → return 0x7dffu;: controls exit 0, card draw exit 1 — nan_and_range_min shift 0, second word 40003c00 → 40007dff.

The controls exit 0 on all three by construction: controls() compares the emitted call sites (minmax16_bits(<args>, <flag>)) and the body comes from the shared preamble, which it never inspects. With mutant 2 applied, five Python control fixtures still exit 0 — startup_gfx2hlsl_pk_minmax_check.py, startup_gfx2hlsl_f16_alu_check.py, startup_translator_check.py, startup_gfx2hlsl_refusals_check.py, startup_gfx2hlsl_bit_alu_check.py.

No test under tests/*.py names minmax16_bits (findstr /s /c:"minmax16_bits" tests\*.py returns only the new fixture), and only a draw that calls it executes it.

CI, precisely

  • pull_request: the Windows step runs ctest --preset pr (.github/workflows/windows.yml:489), and that preset is an explicit include list in CMakePresets.json with no pk_minmax entry — so none of the three entries runs before merge.
  • push to main: ctest --preset dev --no-tests=error --parallel 4 -E '_hardware$' (:494) runs _controls and _warp; _hardware stays excluded.
  • the Linux job runs the fixture through tests/checks/python-linux/startup_gfx2hlsl_pk_minmax.txt and run_checks_parallel.py --from-dir, with the bare path, and the fixture's no-argument mode is controls().

So the helper body is pinned by nothing before merge, and by the WARP draw after merge. Adding startup_gfx2hlsl_pk_minmax_(controls|warp) to the pr include regex would move that to the PR, one line.

Limits

  • What is measured is the emitted integer helper through the AMD compiler, not v_pk_min_f16; nothing here says the console instruction behaves like the helper.
  • The two-NaN payload remains a choice: the fixture's reference returns 0x7e00 and mutant 2 shows the draw enforces that constant instead of testing it against hardware. This run cannot settle it.
  • Whether the driver folds the constant-source channels between DXIL and ISA is not measured.
  • One adapter, one driver, no debug layer; the WARP numbers above are this machine's in-box WARP.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7204182980 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2927#issuecomment-7204182980). Originally posted by [thepatrickworld](https://github.com/thepatrickworld) on 2026-11-26T21:54:54Z. --- **Independent AMD RDNA 4 result on `3d848649`: the emitted formula matches the reference on the card, and only a draw pins the helper body. Measurements only.** The open point in `tools/startup/gfx2hlsl.py` stays open: the two-NaN payload (`0x7e00`) has no hardware confirmation, and an AMD run cannot close it (see Limits). What the card adds is a second vendor for the draw, plus the three mutants below. ### Environment - Windows 11 `10.0.26200.9974` (build and UBR from `ver`). - AMD Radeon RX 9070 XT `1002:7550`, driver `32.0.32029.2010`; in-box WARP `1414:008c`, driver `10.0.26100.9818`. - MSVC `19.44.35230` x64 (toolset `14.44.35207`), DXC `1.9.2602.17`, FXC `10.0.26100.9457`. - `debug_layer=unavailable` on both adapters: no API validation in any run below. - Worktree at `3d848649` (base `6ee878d8`), `git status --porcelain --untracked-files=no` empty before the matrix and after every restore. ### Commands ```sh cmake --preset dev "-DINTAKE_PYTHON=C:/.../x2w-pr641/out/pe-env/Scripts/python.exe" cmake --build --preset dev --target offscreen_check ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_pk_minmax' -V python -B tests/startup_gfx2hlsl_pk_minmax_check.py draw <dxc.exe> <offscreen_check.exe> warp python -B tests/startup_gfx2hlsl_pk_minmax_check.py draw <dxc.exe> <offscreen_check.exe> hardware ``` `XBOX2WINDOWS_ADAPTER` is set with the quoted form, so the name carries no trailing space. ### Observed - Registered names: `startup_gfx2hlsl_pk_minmax_controls`, `_warp`, `_hardware` (`ctest -N`, 3 entries); `ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_pk_minmax' -V` → `100% tests passed out of 3`. The hardware entry returned 0, not a 77 skip, and the renderer printed its adapter inside the draw log: ``` backend=hardware debug_layer=unavailable adapter=AMD Radeon RX 9070 XT vendor=1002 device=7550 driver=32.0.32029.2010 startup_flat_param words=40004000,40004000,40007e00,40007c00 nan_and_range_max, shift 16: 40004000,40004000,40007e00,40007c00 ``` - 12 launches per backend (3 groups × 2 ops × 2 shifts), 48 readback words each, all equal to the fixture's CPU reference. Four of those 48 words are the two-NaN channels, i.e. the fixture's own payload. - The helper is not folded away by DXC: in the DXIL of the `selectors` group's max program at shift 0 (sources: a literal, an SGPR-held constant and an inline zero), all four `storeOutput` values are computed SSA values, none is an immediate. The readback therefore comes from the integer formula, not from a compile-time constant. - Neighbours on the same tree: `ctest -R '^startup_gfx2hlsl_f16_alu'` → 4 entries, `100% tests passed out of 4`; `tests/shader_signed_zero_minmax_check.py draw <dxc> <offscreen_check> hardware` exit 0. The WARP draw also returns 0 here, which reproduces your WARP result on a second machine. ### Three helper-body mutants (mine; the fixture documents a different set) Each one edits `minmax16_bits` in `tools/startup/gfx2hlsl.py` (Python, so no rebuild). For each: the applied hunk and the mutated sha256 are in the log, and after `git checkout --` the file's sha256 is back to `1c1cec187e8401ec07291e13b1d224a9238cd11c2f124f780ff9d79b155aca38`, `git status --porcelain --untracked-files=no` is empty, and the same draw returns 0 again. 1. `(a & 0x7fffu) > 0x7c00u` → `>= 0x7c00u` on both operands (infinity read as NaN): controls exit 0, card draw exit 1 — `nan_and_range_min` shift 16, `expected …4000fc00 actual …40007e00`. 2. two-NaN payload `0x7e00u` → `0x7c01u`: controls exit 0, card draw exit 1 — `nan_and_range_min` shift 0, `expected …40007e00,…40008001 actual …40007c01,…40008001` (the third word, as a payload change should). 3. `if (b_nan) return a;` → `return 0x7dffu;`: controls exit 0, card draw exit 1 — `nan_and_range_min` shift 0, second word `40003c00` → `40007dff`. The controls exit 0 on all three by construction: `controls()` compares the emitted call sites (`minmax16_bits(<args>, <flag>)`) and the body comes from the shared preamble, which it never inspects. With mutant 2 applied, five Python control fixtures still exit 0 — `startup_gfx2hlsl_pk_minmax_check.py`, `startup_gfx2hlsl_f16_alu_check.py`, `startup_translator_check.py`, `startup_gfx2hlsl_refusals_check.py`, `startup_gfx2hlsl_bit_alu_check.py`. No test under `tests/*.py` names `minmax16_bits` (`findstr /s /c:"minmax16_bits" tests\*.py` returns only the new fixture), and only a draw that calls it executes it. ### CI, precisely - `pull_request`: the Windows step runs `ctest --preset pr` (`.github/workflows/windows.yml:489`), and that preset is an explicit include list in `CMakePresets.json` with no `pk_minmax` entry — so **none of the three entries runs before merge**. - push to `main`: `ctest --preset dev --no-tests=error --parallel 4 -E '_hardware$'` (`:494`) runs `_controls` and `_warp`; `_hardware` stays excluded. - the Linux job runs the fixture through `tests/checks/python-linux/startup_gfx2hlsl_pk_minmax.txt` and `run_checks_parallel.py --from-dir`, with the bare path, and the fixture's no-argument mode is `controls()`. So the helper body is pinned by nothing before merge, and by the WARP draw after merge. Adding `startup_gfx2hlsl_pk_minmax_(controls|warp)` to the `pr` include regex would move that to the PR, one line. ### Limits - What is measured is the emitted integer helper through the AMD compiler, not `v_pk_min_f16`; nothing here says the console instruction behaves like the helper. - The two-NaN payload remains a choice: the fixture's reference returns `0x7e00` and mutant 2 shows the draw enforces that constant instead of testing it against hardware. This run cannot settle it. - Whether the driver folds the constant-source channels between DXIL and ISA is not measured. - One adapter, one driver, no debug layer; the WARP numbers above are this machine's in-box WARP. _AI-assisted._
R0Y00 commented 2026-11-27 05:00:42 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-27T05:00:42Z.

Review: APPROVED


Reviewed 3d84864956c7f9edec94545d8de1c2268371b37d. The Release main integration build passed startup_gfx2hlsl_pk_minmax_(controls|warp|hardware). Checked half-selection validation, ordering of signed zero, and the one-NaN case. The canonical payload for two NaNs remains documented as unverified against the guest hardware. Independent Windows 11 26200.9974 testing used WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656 where applicable. Required Windows CI passed.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6083687473 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2927#pullrequestreview-6083687473). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-27T05:00:42Z. **Review:** APPROVED --- Reviewed `3d84864956c7f9edec94545d8de1c2268371b37d`. The Release main integration build passed `startup_gfx2hlsl_pk_minmax_(controls|warp|hardware)`. Checked half-selection validation, ordering of signed zero, and the one-NaN case. The canonical payload for two NaNs remains documented as unverified against the guest hardware. Independent Windows 11 26200.9974 testing used WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656 where applicable. Required Windows CI passed.
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!2927
No description provided.