shader: accept SGPR, hex literal and zero sources in gfx2hlsl packed f16 ops #3615

Manually merged
github merged 3 commits from github-bot/gh-3613 into gh-pr/3613/base 2026-11-30 15:49:42 +00:00 AGit
Owner

@⁠Ammmae0x on GitHub · 2026-11-30 14:22 UTC · original
Ammmae0x:shader/pk-f16-sources → main · +343 −38 · 6 files · 3 commits · merged 2026-11-30 15:48 UTC

Refs #2022, #1723

@Leyukaka released this claim on #2022 on 2026-11-29 (keeping only the v_pk_mul_f16 32-bit literal in merged PR #3490). This change lets v_pk_add_f16, v_pk_mul_f16 and v_pk_fma_f16 accept the same non-VGPR sources that v_pk_min_f16 and v_pk_max_f16 already accept: numeric SGPRs s0..s105, 32-bit hex literals 0x..., and inline 0.

What changed

Stage.packed_half() (tools/startup/gfx2hlsl.py) now applies one source-validation and word-lowering path to all five packed f16 ops, and the v_pk_mul_f16-only literal special case from #3490 is removed:

  • Sources (i >= 1): single VGPR (v0..v255), single numeric SGPR (s0..s105, with reject_lane_mask_data running before S() so lane-mask SGPRs in self.masks are always refused), 32-bit hex literal (0x[0-9a-f]{1,8}), inline 0 (0x00000000u, +0.0 in both halves).
  • Destination (i == 0): still a single VGPR (v0..v255). This also closes a gap the f16 forms had: v_pk_add_f16 v256, v0, v1 used to be accepted and now refuses with destination v256 is out of range.
  • Lowering: SGPR sources go through reject_lane_mask_data + S() on every form (previously only when select_bits=True); VGPRs keep the same u(tok, low16_only=not any(both)) call, so note_whole_read behaviour is unchanged. Modifier checks (clamp, neg_lo, neg_hi, arity, op_sel/op_sel_hi) are unchanged and strict. The _i16/_u16 forms are untouched (they already pass select_bits=True).

Tests

tests/startup_gfx2hlsl_f16_alu_check.py:

  • The three obsolete refusals (v_pk_add_f16 v3, s0, v1, v_pk_mul_f16 v3, s20, v0, v_pk_mul_f16 v3, v0, 0) are positive tests, plus -0.0 + +0.0 == +0.0, Inf * 0 == NaN (inline zero) and fma(-0.0, x, 0) == +0.0.
  • Every source form (SGPR s0/s105, literals 0x80003c00/0x7bff0400/0x7c00fc00, inline 0) in every source position of all three ops, over every selector pair, plus mixed combinations, checked against f16_packed_model.
  • Synthetic gfx1013 VOP3P decodes through Stage.one() for literals in every position (add src0/src1, fma src0/src1/src2), plus an SGPR decode and an inline-zero decode.
  • Every refusal is pinned by its exact error substring (lane-mask SGPR, s106, s[0:1], vcc_lo, exec_lo, m0, src_scc, float literal 2.0, -1, 0x100000000, v256 source/destination, v[3:4], scalar/literal destinations, clamp, neg_lo, neg_hi, mul:2, malformed op_sel, arity), including a d16 low-half pin (a high-half pick of a d16-loaded VGPR refuses; a low-only pick is accepted).

tests/startup_gfx2hlsl_f16_alu_draw_check.py: six new :src: draw keys (SGPR, 32-bit literal, inline 0 and mixed lanes per op, both halves) with recorded words, a decode round-trip in the controls, and a Linux evaluation of the translated pixel program against the model reference. The check is wired into tests/checks/python-linux/startup-gfx2hlsl-f16-alu.txt, so Linux CI runs it.

tests/startup_gfx2hlsl_pk_minmax_check.py: the add/fma hex-literal refusal is gone (now accepted).

docs/experiments/startup-gfx2hlsl-pk-minmax.md: the stale sentence Packed add, mul and fma still require VGPRs. now states that add, mul and fma accept the same source forms, covered in tests/startup_gfx2hlsl_f16_alu_check.py and tests/startup_gfx2hlsl_f16_alu_draw_check.py. The docs/experiments/native-packed-f16-inline.md note covers the direct-compute C++ path, not this translator, so it is untouched.

Linux verification (/tmp/pe-env, branch shader/pk-f16-sources from origin/main 077bff3a)

  • tests/startup_gfx2hlsl_f16_alu_check.py — ok (~6s)
  • tests/startup_gfx2hlsl_f16_alu_draw_check.py (controls) — ok, 346 checks
  • tests/startup_gfx2hlsl_pk_minmax_check.py (controls) — ok
  • tools/run_checks_parallel.py --from-dir tests/checks/python-linux — 68/68 passed (includes the newly wired startup_gfx2hlsl_f16_alu_check.py, 18.2s)
  • tests/form_coverage_check.py, tests/docs_links_check.py (186 files / 736 links), tests/bidi_controls_check.py (2726 files) — pass
  • py_compile, git diff --check clean, git merge-tree --write-tree origin/main HEAD exits 0
  • Mutation audit: 21/21 branch-by-branch mutants of packed_half() (destination bounds, select_bits, s0..s105, reject_lane_mask_data, 0x[0-9a-f]{1,8}, 0, arity/mods, low16_only) are killed by the three packed-f16 suites.

Not verified on this host: the draw check's binary (llvm-mc) comparison — no llvm-mc here. The recorded words are instead pinned by the decode round-trip in the controls, which runs on Linux and Windows CI.

Follow-up (2be4157b, merged origin/main 35a3f6d6)

Windows verification of 240bf98f passed dev + release (7/7) and CI is green. The audit's remaining pins are closed here:

  • docs/experiments/startup-gfx2hlsl-pk-minmax.md: the stale sentence Packed add, mul and fma still require VGPRs. now reads that add, mul and fma accept the same source forms, covered in tests/startup_gfx2hlsl_f16_alu_check.py and tests/startup_gfx2hlsl_f16_alu_draw_check.py.
  • tests/startup_gfx2hlsl_f16_alu_check.py: symbolic SGPRs through S() (a const word inlines as its literal with used_s empty, a user-data word lowers to udN, a TG_SIZE register still refuses outside s_and_b32), a repeated numeric SGPR source (s20, s20), short hex literals (0x0, 0x3c00, zero-extended) and the uppercase-hex refusal (0x80003C00).

Linux re-verification on 2be4157b (/tmp/pe-env): f16 alu check ok, draw controls ok (346 checks), pk_minmax controls ok, run_checks_parallel.py --from-dir tests/checks/python-linux 68/68 passed, form/docs/bidi pass (186 files / 736 links, 2729 files), diff --check clean, merge-tree exits 0.

Windows Verification (2be4157b)

ext Commit: 2be4157bf4d90718d505afde4f73c54426e92d7f (merge-tree upstream/main -> clean, exit 0) Host: Windows 11 build 26100.7623, NVIDIA GeForce RTX 4050 Laptop GPU (driver 32.0.15.9186, XBOX2WINDOWS_ADAPTER=NVIDIA, debug_layer=unavailable) dev: cmake --build --preset dev --target offscreen_check dev: ctest --preset dev --no-tests=error -R '^(startup_gfx2hlsl_f16_alu|startup_gfx2hlsl_f16_alu_draw_.*|startup_gfx2hlsl_pk_minmax.*)$' --output-on-failure -> 7 passed, 0 failed (47.19s; f16_alu 4.21s, draw controls/warp/hw 0.47s/19.73s/19.05s, pk_minmax 0.14s/1.25s/2.19s) release: cmake --build --preset release --target offscreen_check release: ctest --preset release --no-tests=error -R '^(startup_gfx2hlsl_f16_alu|startup_gfx2hlsl_f16_alu_draw_.*|startup_gfx2hlsl_pk_minmax.*)$' -E 'cpu_native_archive_' --output-on-failure -> 7 passed, 0 failed (46.12s; f16_alu 4.13s, draw controls/warp/hw 0.50s/19.01s/18.80s, pk_minmax 0.16s/1.22s/2.13s) Checks: startup_gfx2hlsl_f16_alu_check.py, startup_gfx2hlsl_pk_minmax_check.py, form_coverage_check.py, docs_links_check.py (186 files, 736 links), bidi_controls_check.py (2729 files) -> all passed CI: Assemble & translate gfx1013 (3m20s), Windows (3m22s), Python checks on Linux (3m39s) -> all passed

AI-assisted.

**@⁠Ammmae0x** on GitHub · 2026-11-30 14:22 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3613) `Ammmae0x:shader/pk-f16-sources` → `main` · +343 −38 · 6 files · 3 commits · merged 2026-11-30 15:48 UTC Refs #2022, #1723 `@Leyukaka` released this claim on #2022 on 2026-11-29 (keeping only the `v_pk_mul_f16` 32-bit literal in merged PR #3490). This change lets `v_pk_add_f16`, `v_pk_mul_f16` and `v_pk_fma_f16` accept the same non-VGPR sources that `v_pk_min_f16` and `v_pk_max_f16` already accept: numeric SGPRs `s0..s105`, 32-bit hex literals `0x...`, and inline `0`. ## What changed `Stage.packed_half()` (`tools/startup/gfx2hlsl.py`) now applies one source-validation and word-lowering path to all five packed f16 ops, and the `v_pk_mul_f16`-only literal special case from #3490 is removed: - Sources (`i >= 1`): single VGPR (`v0..v255`), single numeric SGPR (`s0..s105`, with `reject_lane_mask_data` running before `S()` so lane-mask SGPRs in `self.masks` are always refused), 32-bit hex literal (`0x[0-9a-f]{1,8}`), inline `0` (`0x00000000u`, `+0.0` in both halves). - Destination (`i == 0`): still a single VGPR (`v0..v255`). This also closes a gap the f16 forms had: `v_pk_add_f16 v256, v0, v1` used to be accepted and now refuses with `destination v256 is out of range`. - Lowering: SGPR sources go through `reject_lane_mask_data` + `S()` on every form (previously only when `select_bits=True`); VGPRs keep the same `u(tok, low16_only=not any(both))` call, so `note_whole_read` behaviour is unchanged. Modifier checks (`clamp`, `neg_lo`, `neg_hi`, arity, `op_sel`/`op_sel_hi`) are unchanged and strict. The `_i16`/`_u16` forms are untouched (they already pass `select_bits=True`). ## Tests `tests/startup_gfx2hlsl_f16_alu_check.py`: - The three obsolete refusals (`v_pk_add_f16 v3, s0, v1`, `v_pk_mul_f16 v3, s20, v0`, `v_pk_mul_f16 v3, v0, 0`) are positive tests, plus `-0.0 + +0.0 == +0.0`, `Inf * 0 == NaN` (inline zero) and `fma(-0.0, x, 0) == +0.0`. - Every source form (SGPR `s0`/`s105`, literals `0x80003c00`/`0x7bff0400`/`0x7c00fc00`, inline `0`) in every source position of all three ops, over every selector pair, plus mixed combinations, checked against `f16_packed_model`. - Synthetic gfx1013 VOP3P decodes through `Stage.one()` for literals in every position (add src0/src1, fma src0/src1/src2), plus an SGPR decode and an inline-zero decode. - Every refusal is pinned by its exact error substring (lane-mask SGPR, `s106`, `s[0:1]`, `vcc_lo`, `exec_lo`, `m0`, `src_scc`, float literal `2.0`, `-1`, `0x100000000`, `v256` source/destination, `v[3:4]`, scalar/literal destinations, `clamp`, `neg_lo`, `neg_hi`, `mul:2`, malformed `op_sel`, arity), including a d16 low-half pin (a high-half pick of a d16-loaded VGPR refuses; a low-only pick is accepted). `tests/startup_gfx2hlsl_f16_alu_draw_check.py`: six new `:src:` draw keys (SGPR, 32-bit literal, inline 0 and mixed lanes per op, both halves) with recorded words, a decode round-trip in the controls, and a Linux evaluation of the translated pixel program against the model reference. The check is wired into `tests/checks/python-linux/startup-gfx2hlsl-f16-alu.txt`, so Linux CI runs it. `tests/startup_gfx2hlsl_pk_minmax_check.py`: the add/fma hex-literal refusal is gone (now accepted). `docs/experiments/startup-gfx2hlsl-pk-minmax.md`: the stale sentence `Packed add, mul and fma still require VGPRs.` now states that add, mul and fma accept the same source forms, covered in `tests/startup_gfx2hlsl_f16_alu_check.py` and `tests/startup_gfx2hlsl_f16_alu_draw_check.py`. The `docs/experiments/native-packed-f16-inline.md` note covers the direct-compute C++ path, not this translator, so it is untouched. ## Linux verification (`/tmp/pe-env`, branch `shader/pk-f16-sources` from `origin/main` `077bff3a`) - `tests/startup_gfx2hlsl_f16_alu_check.py` — ok (~6s) - `tests/startup_gfx2hlsl_f16_alu_draw_check.py` (controls) — ok, 346 checks - `tests/startup_gfx2hlsl_pk_minmax_check.py` (controls) — ok - `tools/run_checks_parallel.py --from-dir tests/checks/python-linux` — 68/68 passed (includes the newly wired `startup_gfx2hlsl_f16_alu_check.py`, 18.2s) - `tests/form_coverage_check.py`, `tests/docs_links_check.py` (186 files / 736 links), `tests/bidi_controls_check.py` (2726 files) — pass - `py_compile`, `git diff --check` clean, `git merge-tree --write-tree origin/main HEAD` exits 0 - Mutation audit: 21/21 branch-by-branch mutants of `packed_half()` (destination bounds, `select_bits`, `s0..s105`, `reject_lane_mask_data`, `0x[0-9a-f]{1,8}`, `0`, arity/mods, `low16_only`) are killed by the three packed-f16 suites. Not verified on this host: the draw check's `binary` (llvm-mc) comparison — no llvm-mc here. The recorded words are instead pinned by the decode round-trip in the controls, which runs on Linux and Windows CI. ## Follow-up (`2be4157b`, merged `origin/main` `35a3f6d6`) Windows verification of `240bf98f` passed `dev` + `release` (7/7) and CI is green. The audit's remaining pins are closed here: - `docs/experiments/startup-gfx2hlsl-pk-minmax.md`: the stale sentence `Packed add, mul and fma still require VGPRs.` now reads that add, mul and fma accept the same source forms, covered in `tests/startup_gfx2hlsl_f16_alu_check.py` and `tests/startup_gfx2hlsl_f16_alu_draw_check.py`. - `tests/startup_gfx2hlsl_f16_alu_check.py`: symbolic SGPRs through `S()` (a const word inlines as its literal with `used_s` empty, a user-data word lowers to `udN`, a `TG_SIZE` register still refuses outside `s_and_b32`), a repeated numeric SGPR source (`s20, s20`), short hex literals (`0x0`, `0x3c00`, zero-extended) and the uppercase-hex refusal (`0x80003C00`). Linux re-verification on `2be4157b` (`/tmp/pe-env`): f16 alu check ok, draw controls ok (346 checks), pk_minmax controls ok, `run_checks_parallel.py --from-dir tests/checks/python-linux` 68/68 passed, form/docs/bidi pass (186 files / 736 links, 2729 files), `diff --check` clean, `merge-tree` exits 0. ### Windows Verification (2be4157b) ` ext Commit: 2be4157bf4d90718d505afde4f73c54426e92d7f (merge-tree upstream/main -> clean, exit 0) Host: Windows 11 build 26100.7623, NVIDIA GeForce RTX 4050 Laptop GPU (driver 32.0.15.9186, XBOX2WINDOWS_ADAPTER=NVIDIA, debug_layer=unavailable) dev: cmake --build --preset dev --target offscreen_check dev: ctest --preset dev --no-tests=error -R '^(startup_gfx2hlsl_f16_alu|startup_gfx2hlsl_f16_alu_draw_.*|startup_gfx2hlsl_pk_minmax.*)$' --output-on-failure -> 7 passed, 0 failed (47.19s; f16_alu 4.21s, draw controls/warp/hw 0.47s/19.73s/19.05s, pk_minmax 0.14s/1.25s/2.19s) release: cmake --build --preset release --target offscreen_check release: ctest --preset release --no-tests=error -R '^(startup_gfx2hlsl_f16_alu|startup_gfx2hlsl_f16_alu_draw_.*|startup_gfx2hlsl_pk_minmax.*)$' -E 'cpu_native_archive_' --output-on-failure -> 7 passed, 0 failed (46.12s; f16_alu 4.13s, draw controls/warp/hw 0.50s/19.01s/18.80s, pk_minmax 0.16s/1.22s/2.13s) Checks: startup_gfx2hlsl_f16_alu_check.py, startup_gfx2hlsl_pk_minmax_check.py, form_coverage_check.py, docs_links_check.py (186 files, 736 links), bidi_controls_check.py (2729 files) -> all passed CI: Assemble & translate gfx1013 (3m20s), Windows (3m22s), Python checks on Linux (3m39s) -> all passed ` AI-assisted. <!-- WIN-VERIFY: passed | sha=2be4157bf4d90718d505afde4f73c54426e92d7f -->
Refs #2022, #1723

Stage.packed_half() now applies one source-validation and word-lowering
path to v_pk_add/mul/fma_f16 and v_pk_min/max_f16: a single VGPR
(v0..v255), a numeric SGPR (s0..s105, lane-mask SGPRs refused via
reject_lane_mask_data before S()), a 32-bit hex literal or inline 0
(0x00000000u, +0.0 in both halves). The destination stays a single VGPR
(v0..v255); this also closes the v256 destination the f16 forms used to
accept. The v_pk_mul_f16-only literal special case from #3488 is removed,
and the _i16/_u16 forms are unchanged (they already pass select_bits=True).

tests/startup_gfx2hlsl_f16_alu_check.py: the three obsolete refusals
(v_pk_add_f16 v3, s0, v1; v_pk_mul_f16 v3, s20, v0; v_pk_mul_f16 v3,
v0, 0) are positive tests; every source form is checked against
f16_packed_model in every source position over every selector pair, plus
mixed combinations and synthetic VOP3P decodes for add/fma literals in
every position; every refusal is pinned by its exact error substring.
tests/startup_gfx2hlsl_f16_alu_draw_check.py: six new :src: draw keys
(SGPR, 32-bit literal, inline 0 and mixed lanes per op, both halves)
with recorded words, a decode round-trip and a Linux evaluation of the
translated pixel program against the model. The check is wired into
tests/checks/python-linux/startup-gfx2hlsl-f16-alu.txt.
tests/startup_gfx2hlsl_pk_minmax_check.py: the add/fma hex-literal
refusal is gone (now accepted).

Linux verification (/tmp/pe-env): startup_gfx2hlsl_f16_alu_check.py ok,
startup_gfx2hlsl_f16_alu_draw_check.py controls ok (346 checks),
startup_gfx2hlsl_pk_minmax_check.py controls ok, run_checks_parallel.py
--from-dir tests/checks/python-linux 68/68 passed, form/docs/bidi pass,
py_compile pass, diff --check clean, merge-tree exits 0. Mutation audit:
21/21 branch mutants of packed_half() killed by the suites. The draw
check binary (llvm-mc) comparison could not run on this host (no
llvm-mc); the recorded words are instead pinned by the decode round-trip
in the controls.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 14:26:19 +00:00
Windows verification of 240bf98f passed dev + release (7/7) and CI is
green; this closes the audit's remaining pins before the PR leaves Draft.

docs/experiments/startup-gfx2hlsl-pk-minmax.md: the sentence 'Packed add,
mul and fma still require VGPRs.' is stale since 240bf98f unified the
source forms; it now states that add, mul and fma accept the same source
forms, covered in tests/startup_gfx2hlsl_f16_alu_check.py and
tests/startup_gfx2hlsl_f16_alu_draw_check.py.

tests/startup_gfx2hlsl_f16_alu_check.py: symbolic SGPRs through S() (a
const word inlines as its literal with used_s empty, a user-data word
lowers to udN, a TG_SIZE register still refuses outside s_and_b32), a
repeated numeric SGPR source (s20, s20), short hex literals (0x0, 0x3c00
zero-extended) and the uppercase-hex refusal (0x80003C00). A lowered()
helper exposes the stage for text and used-register pins, and run() takes
sym/extra for symbolic evaluation.

Linux verification (/tmp/pe-env): startup_gfx2hlsl_f16_alu_check.py ok,
startup_gfx2hlsl_f16_alu_draw_check.py controls ok (346 checks),
startup_gfx2hlsl_pk_minmax_check.py controls ok, run_checks_parallel.py
--from-dir tests/checks/python-linux 68/68 passed, form/docs/bidi pass,
py_compile pass, diff --check clean, merge-tree exits 0.
github-bot changed target branch from main to gh-pr/3613/base 2026-11-30 15:49:41 +00:00
github manually merged commit 2be4157bf4 into gh-pr/3613/base 2026-11-30 15:49:42 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-30 15:48 UTC · original · approved these changes

Independent Debug check on 2be4157b with ctest --preset dev --no-tests=error --output-on-failure -j 1 -R '^startup_gfx2hlsl_(f16_alu|pk_minmax)': seven passed, zero skips, including WARP and physical RTX draws. The shared source validation admits numeric SGPRs, literal words and inline zero while keeping lane-mask and undefined-half refusals. The min/max regressions passed as well.

**@⁠R0Y00** on GitHub · 2026-11-30 15:48 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3613#pullrequestreview-6115409298) · **approved these changes** Independent Debug check on `2be4157b` with `ctest --preset dev --no-tests=error --output-on-failure -j 1 -R '^startup_gfx2hlsl_(f16_alu|pk_minmax)'`: seven passed, zero skips, including WARP and physical RTX draws. The shared source validation admits numeric SGPRs, literal words and inline zero while keeping lane-mask and undefined-half refusals. The min/max regressions passed as well.
This discussion has been locked. Commenting is limited to contributors.
No description provided.