gfx2hlsl: lower v_pk_mul_f16, v_pk_add_f16 and v_pk_fma_f16 #2730
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2738"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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 ingfx2hlsl.py.What changed
Stage.packed_halflowers the three VOP3P ops. Result low half = op over source halves picked byop_sel; result high half = op over halves picked byop_sel_hi. With no modifier printed:op_selall 0,op_sel_hiall 1 (LLVM VOP3P defaults). Both halves are written (no zeroing, unlike the scalar f16 ops).f16rn(a*b),f16rn(a+b)orf16rn(fma16o(a,b,c)): the helpersv_mul_f16/v_add_f16/v_fmac_f16already use, so one rounding per lane.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.v_add_f16already 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 wrongop_sel_hidefault must be told apart by the value sets. Refusal controls for every refused form above. Also fixed the test-sidefma16omodel 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 bybinary <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 okpython3 -I -B tests/startup_gfx2hlsl_f16_alu_draw_check.py(controls) -> all okpython3 -I -B tests/startup_gfx2hlsl_f16_alu_draw_check.py binary <llvm-mc>->fixture words match llvm-mcremote_pycheck.sh <worktree> --compare origin/main-> 181 pass, 63 fail, 0 differ from mainstartup_gfx2hlsl_f16_alu_draw_*).AI-assisted; commands listed were executed locally.
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 withOSError: [Errno 22] Invalid argumentwhile writingps_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 localfile_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.10068and RTX 407032.0.16.2124, with both FXCps_5_1and DXCps_6_0, including every new packed-half key and the wrong-value controls. No skips or debug-layer errors/warnings. Only the names passed tocompile_hlslwere changed in memory.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
1ec01d70combined, 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.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.pyand the draw controls pass.AI-assisted; commands listed were executed locally.
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 @R0Y00Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit
a214ef3b2a28e628fe08ab2887e2002095f9a162:--preset dev):cmake --build --preset dev --target d3d12_xs_device_obj d3d12_xs_shim startup_buffer_format_word3_check, thenctest --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).--preset release): same build and ctest commands -> 4/4 passed.tests/startup_gfx2hlsl_f16_alu_check.pyandtests/startup_gfx2hlsl_f16_alu_draw_check.pyok.AI-assisted; commands listed were executed locally.
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.
a214ef3ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.