startup: accept SGPR, hex and inline 0 sources in packed f16 add, mul and fma #2930

Closed
Leyukaka wants to merge 1 commit from upstream-pr/2930 into main
Leyukaka commented 2026-11-26 21:44:37 +00:00 (Migrated from github.com)

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


Part of #2022 (claim). Stacked on #2927: the first commit is #2927, and this PR adds the second one (071de02e).

Change (tools/startup/gfx2hlsl.py): v_pk_add_f16, v_pk_mul_f16 and v_pk_fma_f16 now take the sources that #2927 accepts for min and max:

  • a single VGPR;
  • a numeric SGPR, read with S() after reject_lane_mask_data;
  • a hex word of up to 8 digits, read as a full 32-bit word, so a short literal has a zero high half;
  • the inline 0.

packed_half now validates the sources once for all five instructions. op_sel and op_sel_hi select the half of each source as before (the vop3p_f16_word rule in tools/pixel_aot.py). The arithmetic is unchanged: f16tof32 of the selected halves, then f16rn of the result. Min and max still select an encoding.

Still refused, with the existing messages:

  • inline floats and nonzero inline integers;
  • oversized hex words and other operands;
  • VGPR sources and destinations above v255, now checked for add, mul and fma as well;
  • neg_lo, neg_hi, clamp and other modifiers.

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

  • tests/startup_gfx2hlsl_pk_minmax_check.py, extended: ok.
    • Add, mul and fma each take an SGPR, a short hex literal, a full-word hex literal and the inline 0 under default and flipped selectors.
    • It keeps refusal controls for the kept refusals.
  • ... draw <dxc> <offscreen_check> warp and hardware: ok on WARP (Microsoft Basic Render Driver) and an NVIDIA GeForce RTX 5080. For each of add, mul and fma, a literal source and an SGPR source under default and flipped selectors are read back against an independent CPU reference (struct binary16, round to nearest even). One case selects a literal's zero high half.
  • tests/startup_gfx2hlsl_f16_alu_check.py: its controls that packed mul and add refuse a hex literal and an SGPR are removed, since this PR accepts them. Its inline-float refusal stays, and the check is ok.
  • Also ok: startup_translator_check, startup_gfx2hlsl_refusals_check, docs_links_check, bidi_controls_check.

Mutation checks, run by hand; each fails the controls and the WARP draw:

  • swapping the op_sel/op_sel_hi roles;
  • reading a literal's high half as a copy of its low half;
  • (from #2927) using max for min.

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

  • Start-up run: a compute pipeline that the title dispatched 5,152 times in a 600 s start-up run gets past v_pk_max_f16 and v_pk_mul_f16 with both commits. It now stops at the SDWA form of v_exp_f16.
  • Census:
    • the request that stopped at v_pk_mul_f16 with an SGPR source now translates;
    • the two requests that #2927 moved to the v_pk_mul_f16 literal now also stop at the SDWA v_exp_f16.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5517556263 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2930). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-26T21:44:37Z. --- Part of #2022 ([claim](https://github.com/R0Y00/Xbox2Windows/issues/2022#issuecomment-7203896230)). **Stacked on #2927**: the first commit is #2927, and this PR adds the second one (`071de02e`). **Change** (`tools/startup/gfx2hlsl.py`): `v_pk_add_f16`, `v_pk_mul_f16` and `v_pk_fma_f16` now take the sources that #2927 accepts for min and max: - a single VGPR; - a numeric SGPR, read with `S()` after `reject_lane_mask_data`; - a hex word of up to 8 digits, read as a full 32-bit word, so a short literal has a zero high half; - the inline `0`. `packed_half` now validates the sources once for all five instructions. `op_sel` and `op_sel_hi` select the half of each source as before (the `vop3p_f16_word` rule in `tools/pixel_aot.py`). The arithmetic is unchanged: `f16tof32` of the selected halves, then `f16rn` of the result. Min and max still select an encoding. Still refused, with the existing messages: - inline floats and nonzero inline integers; - oversized hex words and other operands; - VGPR sources and destinations above `v255`, now checked for add, mul and fma as well; - `neg_lo`, `neg_hi`, `clamp` and other modifiers. **Tests** (Windows 11, Python 3.14, DXC from the Windows SDK 10.0.26100, on main `6ee878d8` plus both commits): - `tests/startup_gfx2hlsl_pk_minmax_check.py`, extended: ok. - Add, mul and fma each take an SGPR, a short hex literal, a full-word hex literal and the inline `0` under default and flipped selectors. - It keeps refusal controls for the kept refusals. - `... draw <dxc> <offscreen_check> warp` and `hardware`: ok on WARP (Microsoft Basic Render Driver) and an NVIDIA GeForce RTX 5080. For each of add, mul and fma, a literal source and an SGPR source under default and flipped selectors are read back against an independent CPU reference (`struct` binary16, round to nearest even). One case selects a literal's zero high half. - `tests/startup_gfx2hlsl_f16_alu_check.py`: its controls that packed mul and add refuse a hex literal and an SGPR are removed, since this PR accepts them. Its inline-float refusal stays, and the check is ok. - Also ok: `startup_translator_check`, `startup_gfx2hlsl_refusals_check`, `docs_links_check`, `bidi_controls_check`. **Mutation checks**, run by hand; each fails the controls and the WARP draw: - swapping the `op_sel`/`op_sel_hi` roles; - reading a literal's high half as a copy of its low half; - (from #2927) using max for min. **Measured on a local capture** (counts and instruction shape only): - **Start-up run:** a compute pipeline that the title dispatched 5,152 times in a 600 s start-up run gets past `v_pk_max_f16` and `v_pk_mul_f16` with both commits. It now stops at the SDWA form of `v_exp_f16`. - **Census:** - the request that stopped at `v_pk_mul_f16` with an SGPR source now translates; - the two requests that #2927 moved to the `v_pk_mul_f16` literal now also stop at the SDWA `v_exp_f16`. AI-assisted.
KelboLive commented 2026-11-27 05:23:04 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-27T05:23:04Z.

Review: COMMENTED


PR #2930 by @Leyukaka — startup: accept SGPR, hex and inline 0 sources in packed f16 add, mul, and fma

What works

  • Clean centralization: packed_half validates sources once for all five instructions (min, max, add, mul, fma)
  • op_sel/op_sel_hi half-select correctly applied to VGPR, SGPR, and hex sources
  • Arithmetic semantics correct: f16tof32 select → arithmetic → f16rn (matches console behavior)
  • Hex word reads as full 32-bit value; short hex has zero high half — matches gfx1013 encoding
  • Inline 0 handling is consistent with other packed operations in gfx2hlsl.py
  • Refusal rules maintained: inline floats, nonzero inline ints, VGPR > v255, neg_lo, neg_hi, clamp
  • Mutation checks thorough: swapping op_sel/op_sel_hi, reading literal high half as copy, max-for-min
  • Measured data shows 5,152 compute pipeline dispatches with the title get past these instructions
  • Controls test both halves, signed zeros, NaNs, infinity, subnormals, literal/SGPR selector flips
  • Test extension reuses the existing pk_minmax check framework — no new test files needed
  • AGENTS.md and python-linux checks updated with new test entry

Issues

  • Stacked on #2927: needs review as a two-commit stack, which means reviewers must verify both commits together for source handling consistency.
  • The "hex word of up to 8 digits" description means the hex literal fits in a 32-bit unsigned integer, but packed f16 encodings use the full 32-bit bit pattern including the sign bit and exponent range. A hex value like 0x7C00 (positive zero) and 0xFC00 (negative zero) are both valid 32-bit values. The validation should ensure the hex is treated as unsigned when parsed but kept as raw bits in the f16tof32 conversion.
  • No explicit guard against SGPR sources that are actually descriptor/constant-buffer registers (not numeric). The PR says "SGPR sources must hold numeric data" but there is no runtime check to ensure the SGPR actually contains the expected format.
  • The v_pk_fma_f16 FMA semantics need verification: the result is (S0 * S1) + S2 with f16tof32 conversions and f16rn rounding. Is the rounding of the product before the add correct for f16 FMA on gfx1013? Some implementations use single-precision internally for FMA and then round once.

Recommendations

  • Document in gfx2hlsl.py the source-handling decision for packed_f16: VGPR, SGPR, hex literal, inline 0 are all accepted, and list the specific refusal conditions.
  • For the SGPR source, consider adding a debug assertion or check that the SGPR index is within the expected range for numeric registers (not descriptor/constant tables).
  • Consider adding a test case with a hex literal whose high half is non-zero to verify the full 32-bit word handling.

Overall

Natural extension of #2927 and the min/max support. The source centralization into packed_half is clean, and the test coverage is solid. With the source-handling docs update, this would be merge-ready once #2927 lands.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6083830184 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2930#pullrequestreview-6083830184). Originally posted by [KelboLive](https://github.com/KelboLive) on 2026-11-27T05:23:04Z. **Review:** COMMENTED --- PR #2930 by @Leyukaka — startup: accept SGPR, hex and inline 0 sources in packed f16 add, mul, and fma ## What works - Clean centralization: packed_half validates sources once for all five instructions (min, max, add, mul, fma) - op_sel/op_sel_hi half-select correctly applied to VGPR, SGPR, and hex sources - Arithmetic semantics correct: f16tof32 select → arithmetic → f16rn (matches console behavior) - Hex word reads as full 32-bit value; short hex has zero high half — matches gfx1013 encoding - Inline 0 handling is consistent with other packed operations in gfx2hlsl.py - Refusal rules maintained: inline floats, nonzero inline ints, VGPR > v255, neg_lo, neg_hi, clamp - Mutation checks thorough: swapping op_sel/op_sel_hi, reading literal high half as copy, max-for-min - Measured data shows 5,152 compute pipeline dispatches with the title get past these instructions - Controls test both halves, signed zeros, NaNs, infinity, subnormals, literal/SGPR selector flips - Test extension reuses the existing pk_minmax check framework — no new test files needed - AGENTS.md and python-linux checks updated with new test entry ## Issues - Stacked on #2927: needs review as a two-commit stack, which means reviewers must verify both commits together for source handling consistency. - The "hex word of up to 8 digits" description means the hex literal fits in a 32-bit unsigned integer, but packed f16 encodings use the full 32-bit bit pattern including the sign bit and exponent range. A hex value like 0x7C00 (positive zero) and 0xFC00 (negative zero) are both valid 32-bit values. The validation should ensure the hex is treated as unsigned when parsed but kept as raw bits in the f16tof32 conversion. - No explicit guard against SGPR sources that are actually descriptor/constant-buffer registers (not numeric). The PR says "SGPR sources must hold numeric data" but there is no runtime check to ensure the SGPR actually contains the expected format. - The v_pk_fma_f16 FMA semantics need verification: the result is (S0 * S1) + S2 with f16tof32 conversions and f16rn rounding. Is the rounding of the product before the add correct for f16 FMA on gfx1013? Some implementations use single-precision internally for FMA and then round once. ## Recommendations - Document in gfx2hlsl.py the source-handling decision for packed_f16: VGPR, SGPR, hex literal, inline 0 are all accepted, and list the specific refusal conditions. - For the SGPR source, consider adding a debug assertion or check that the SGPR index is within the expected range for numeric registers (not descriptor/constant tables). - Consider adding a test case with a hex literal whose high half is non-zero to verify the full 32-bit word handling. ## Overall Natural extension of #2927 and the min/max support. The source centralization into packed_half is clean, and the test coverage is solid. With the source-handling docs update, this would be merge-ready once #2927 lands.
Leyukaka commented 2026-11-27 05:42:53 +00:00 (Migrated from github.com)

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


Rebased on main now that #2927 is merged: this PR is down to its own commit (9eac81b1) and no longer conflicts. After the rebase, startup_gfx2hlsl_pk_minmax_check, startup_gfx2hlsl_f16_alu_check, startup_gfx2hlsl_compute_check and startup_gfx2hlsl_refusals_check pass.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7210879096 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2930#issuecomment-7210879096). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-27T05:42:53Z. --- Rebased on `main` now that #2927 is merged: this PR is down to its own commit (`9eac81b1`) and no longer conflicts. After the rebase, `startup_gfx2hlsl_pk_minmax_check`, `startup_gfx2hlsl_f16_alu_check`, `startup_gfx2hlsl_compute_check` and `startup_gfx2hlsl_refusals_check` pass. AI-assisted.
Leyukaka commented 2026-11-29 12:24:12 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-29T12:24:12Z.


Closing this draft: no update since 2026-11-27 and I am not continuing it. My claim on #2022 for this item is released.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7255786569 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2930#issuecomment-7255786569). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-29T12:24:12Z. --- Closing this draft: no update since 2026-11-27 and I am not continuing it. My claim on #2022 for this item is released.

Pull request closed

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!2930
No description provided.