gfx2hlsl: lower v_pk_mul_f16, v_pk_add_f16 and v_pk_fma_f16 #2730

Merged
tedin7 merged 2 commits from upstream-pr/2738 into main 2026-11-26 05:47:58 +00:00
tedin7 commented 2026-11-26 04:42:52 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T04:42:52Z.


Part of #1723

What this unblocks: shaders that use packed half-precision math (v_pk_mul_f16, v_pk_add_f16, v_pk_fma_f16) no longer stop translation in gfx2hlsl.py.

What changed

  • Stage.packed_half lowers the three VOP3P ops. Result low half = op over source halves picked by op_sel; result high half = op over halves picked by op_sel_hi. With no modifier printed: op_sel all 0, op_sel_hi all 1 (LLVM VOP3P defaults). Both halves are written (no zeroing, unlike the scalar f16 ops).
  • Each half is f16rn(a*b), f16rn(a+b) or f16rn(fma16o(a,b,c)): the helpers v_mul_f16 / v_add_f16 / v_fmac_f16 already use, so one rounding per lane.
  • Still refused: neg_lo, neg_hi, clamp, any other modifier, a selector list of the wrong length, and any source that is not a plain VGPR (inline constant, literal, SGPR, -v, register pairs). An inline constant or literal in a packed op stays refused because its effect on the high lane is not proven.
  • Denormal mode is not assumed beyond what v_add_f16 already assumes (f16 denormals kept).

Tests (extended the existing sibling suites)

  • tests/f16_packed_model.py: independent CPU model (exact rationals for finite values, float64 for inf/NaN, IEEE signed-zero rules).
  • startup_gfx2hlsl_f16_alu_check.py: the lowered statement is evaluated over every selector pair (16 for mul/add, 64 for fma) x 150 value sets (0, -0, smallest/largest denormal, +-1, +-65504, +-inf, quiet/signalling/payload NaN, ties, random words) and compared with the model. Mutation controls: swapped lanes, zeroed high lane and wrong op_sel_hi default must be told apart by the value sets. Refusal controls for every refused form above. Also fixed the test-side fma16o model to give -0 only for (-0 product) + (-0).
  • startup_gfx2hlsl_f16_alu_draw_check.py: 24 new D3D12 draw keys (name:half:group): four selector pairs per key, the low or high half of the result isolated and read back, compared word for word with the model; one deliberately wrong expected word per run must be rejected. Fixture encodings recorded from llvm-mc (gfx1013) and re-checked by binary <llvm-mc>. Lanes whose result is a NaN made from inf*0 or inf-inf are left out of the draw (their sign differs between adapters); those are covered by the evaluator test above.

Verification

Linux only (Stage-1):

  • python3 -I -B tests/startup_gfx2hlsl_f16_alu_check.py -> f16 alu ok
  • python3 -I -B tests/startup_gfx2hlsl_f16_alu_draw_check.py (controls) -> all ok
  • python3 -I -B tests/startup_gfx2hlsl_f16_alu_draw_check.py binary <llvm-mc> -> fixture words match llvm-mc
  • remote_pycheck.sh <worktree> --compare origin/main -> 181 pass, 63 fail, 0 differ from main
  • Win2025 WARP dev+release: pending Stage-2 (draw keys startup_gfx2hlsl_f16_alu_draw_*).

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6619668274 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2738). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T04:42:52Z. --- Part of #1723 What this unblocks: shaders that use packed half-precision math (`v_pk_mul_f16`, `v_pk_add_f16`, `v_pk_fma_f16`) no longer stop translation in `gfx2hlsl.py`. ## What changed - `Stage.packed_half` lowers the three VOP3P ops. Result low half = op over source halves picked by `op_sel`; result high half = op over halves picked by `op_sel_hi`. With no modifier printed: `op_sel` all 0, `op_sel_hi` all 1 (LLVM VOP3P defaults). Both halves are written (no zeroing, unlike the scalar f16 ops). - Each half is `f16rn(a*b)`, `f16rn(a+b)` or `f16rn(fma16o(a,b,c))`: the helpers `v_mul_f16` / `v_add_f16` / `v_fmac_f16` already use, so one rounding per lane. - Still refused: `neg_lo`, `neg_hi`, `clamp`, any other modifier, a selector list of the wrong length, and any source that is not a plain VGPR (inline constant, literal, SGPR, `-v`, register pairs). An inline constant or literal in a packed op stays refused because its effect on the high lane is not proven. - Denormal mode is not assumed beyond what `v_add_f16` already assumes (f16 denormals kept). ## Tests (extended the existing sibling suites) - `tests/f16_packed_model.py`: independent CPU model (exact rationals for finite values, float64 for inf/NaN, IEEE signed-zero rules). - `startup_gfx2hlsl_f16_alu_check.py`: the lowered statement is evaluated over every selector pair (16 for mul/add, 64 for fma) x 150 value sets (0, -0, smallest/largest denormal, +-1, +-65504, +-inf, quiet/signalling/payload NaN, ties, random words) and compared with the model. Mutation controls: swapped lanes, zeroed high lane and wrong `op_sel_hi` default must be told apart by the value sets. Refusal controls for every refused form above. Also fixed the test-side `fma16o` model to give -0 only for (-0 product) + (-0). - `startup_gfx2hlsl_f16_alu_draw_check.py`: 24 new D3D12 draw keys (`name:half:group`): four selector pairs per key, the low or high half of the result isolated and read back, compared word for word with the model; one deliberately wrong expected word per run must be rejected. Fixture encodings recorded from llvm-mc (gfx1013) and re-checked by `binary <llvm-mc>`. Lanes whose result is a NaN made from inf*0 or inf-inf are left out of the draw (their sign differs between adapters); those are covered by the evaluator test above. ## Verification Linux only (Stage-1): - `python3 -I -B tests/startup_gfx2hlsl_f16_alu_check.py` -> `f16 alu ok` - `python3 -I -B tests/startup_gfx2hlsl_f16_alu_draw_check.py` (controls) -> all ok - `python3 -I -B tests/startup_gfx2hlsl_f16_alu_draw_check.py binary <llvm-mc>` -> `fixture words match llvm-mc` - `remote_pycheck.sh <worktree> --compare origin/main` -> 181 pass, 63 fail, 0 differ from main - Win2025 WARP dev+release: pending Stage-2 (draw keys `startup_gfx2hlsl_f16_alu_draw_*`). AI-assisted; commands listed were executed locally.
RonLogic commented 2026-11-26 05:02:29 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by RonLogic on 2026-11-26T04:46:06Z.


Windows fixture blocker on 911ccf24: both adapter runs stop before the first packed-half draw with OSError: [Errno 22] Invalid argument while writing ps_v_pk_mul_f16:lo:0_fxc.hlsl. check_draw() uses the colon-delimited key as the filename for both pixel and vertex shader outputs. A local file_key = op.replace(':', '_') for the two filename formats preserves the test ID and avoids the Windows path error. The pure-Python f16 check passes. I am using that filename-only substitution to check the GPU cases separately.

Filename-only retest on the same head: the complete draw scripts passed on in-box WARP 10.0.26100.10068 and RTX 4070 32.0.16.2124, with both FXC ps_5_1 and DXC ps_6_0, including every new packed-half key and the wrong-value controls. No skips or debug-layer errors/warnings. Only the names passed to compile_hlsl were changed in memory.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7182885228 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2738#issuecomment-7182885228). Originally posted by [RonLogic](https://github.com/RonLogic) on 2026-11-26T04:46:06Z. --- Windows fixture blocker on `911ccf24`: both adapter runs stop before the first packed-half draw with `OSError: [Errno 22] Invalid argument` while writing `ps_v_pk_mul_f16:lo:0_fxc.hlsl`. `check_draw()` uses the colon-delimited key as the filename for both pixel and vertex shader outputs. A local `file_key = op.replace(':', '_')` for the two filename formats preserves the test ID and avoids the Windows path error. The pure-Python f16 check passes. I am using that filename-only substitution to check the GPU cases separately. Filename-only retest on the same head: the complete draw scripts passed on in-box WARP `10.0.26100.10068` and RTX 4070 `32.0.16.2124`, with both FXC `ps_5_1` and DXC `ps_6_0`, including every new packed-half key and the wrong-value controls. No skips or debug-layer errors/warnings. Only the names passed to `compile_hlsl` were changed in memory.
upstream-sync closed this pull request 2026-11-26 06:01:58 +00:00
R0Y00 commented 2026-11-26 06:01:59 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-26T05:47:45Z.

Review: APPROVED


Reviewed the packed half selections, result packing and Windows-safe fixture filenames. With main 1ec01d70 combined, the host controls and FXC/DXC readback suite passed on Windows 11 build 26200 with WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656. The independent rational model covers asymmetric halves and the fused rounding discriminator. The wrong-value controls were rejected on each adapter.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6069139633 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2738#pullrequestreview-6069139633). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-26T05:47:45Z. **Review:** APPROVED --- Reviewed the packed half selections, result packing and Windows-safe fixture filenames. With main 1ec01d70 combined, the host controls and FXC/DXC readback suite passed on Windows 11 build 26200 with WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656. The independent rational model covers asymmetric halves and the fused rounding discriminator. The wrong-value controls were rejected on each adapter.
tedin7 commented 2026-11-26 06:02:06 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T05:11:35Z.


Thank you @RonLogic: your filename-only retest on this PR (in-box WARP 10.0.26100.10068 and RTX 4070 32.0.16.2124, FXC ps_5_1 and DXC ps_6_0, every new packed-half key and the wrong-value controls, no skips) found the ':' problem and the fix. Applied as you described in a214ef3b: op.replace(':', '_') only in the two temp file name formats; the test IDs and draw keys are unchanged. Linux: startup_gfx2hlsl_f16_alu_check.py and the draw controls pass.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7183263246 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2738#issuecomment-7183263246). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T05:11:35Z. --- Thank you @RonLogic: your filename-only retest on this PR (in-box WARP 10.0.26100.10068 and RTX 4070 32.0.16.2124, FXC ps_5_1 and DXC ps_6_0, every new packed-half key and the wrong-value controls, no skips) found the ':' problem and the fix. Applied as you described in a214ef3b: `op.replace(':', '_')` only in the two temp file name formats; the test IDs and draw keys are unchanged. Linux: `startup_gfx2hlsl_f16_alu_check.py` and the draw controls pass. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-26 06:02:07 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T05:23:20Z.


Independent gate on head a214ef3b2a: PASS. Marking Ready for review. @MasterDomino @R0Y00

Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit a214ef3b2a28e628fe08ab2887e2002095f9a162:

  • Debug (--preset dev): cmake --build --preset dev --target d3d12_xs_device_obj d3d12_xs_shim startup_buffer_format_word3_check, then ctest --preset dev -R '^startup_gfx2hlsl_f16_alu' --no-tests=error --output-on-failure -> 4/4 passed (startup_gfx2hlsl_f16_alu, _draw_controls, _draw_warp, _draw_hardware).
  • Release (--preset release): same build and ctest commands -> 4/4 passed.
  • Python checks tests/startup_gfx2hlsl_f16_alu_check.py and tests/startup_gfx2hlsl_f16_alu_draw_check.py ok.
  • Linux: shape sweep identical to main (171/171); mask-family findings identical to main; two one-line mutations (op_sel_hi default, add -> sub) are rejected by the evaluator test.
  • The earlier ':' in draw temp file names (invalid on Windows) is fixed in this head.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7183440890 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2738#issuecomment-7183440890). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T05:23:20Z. --- Independent gate on head a214ef3b2a28e628fe08ab2887e2002095f9a162: PASS. Marking Ready for review. @MasterDomino @R0Y00 Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit `a214ef3b2a28e628fe08ab2887e2002095f9a162`: - Debug (`--preset dev`): `cmake --build --preset dev --target d3d12_xs_device_obj d3d12_xs_shim startup_buffer_format_word3_check`, then `ctest --preset dev -R '^startup_gfx2hlsl_f16_alu' --no-tests=error --output-on-failure` -> 4/4 passed (`startup_gfx2hlsl_f16_alu`, `_draw_controls`, `_draw_warp`, `_draw_hardware`). - Release (`--preset release`): same build and ctest commands -> 4/4 passed. - Python checks `tests/startup_gfx2hlsl_f16_alu_check.py` and `tests/startup_gfx2hlsl_f16_alu_draw_check.py` ok. - Linux: shape sweep identical to main (171/171); mask-family findings identical to main; two one-line mutations (op_sel_hi default, add -> sub) are rejected by the evaluator test. - The earlier ':' in draw temp file names (invalid on Windows) is fixed in this head. AI-assisted; commands listed were executed locally.
chatgpt-codex-connector[bot commented 2026-11-26 06:02:07 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-26T05:23:32Z.


Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T05:28:34.766878Z a214ef3 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7183443817 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2738#issuecomment-7183443817). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-26T05:23:32Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"a214ef3b2a28e628fe08ab2887e2002095f9a162","has_any_findings":false,"has_unresolved_findings":false,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-26T05:28:34.766878Z">2026-11-26T05:28:34.766878Z</relative-time> | `a214ef3` | Draft marked ready | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review" or "@codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
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!2730
No description provided.