shader: lower gfx1013 v_cvt_f16_f32 in pixel_aot #319
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/324"
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 Its3rr0rsWRLD on 2026-11-21T22:09:21Z.
Change
pixel_aotrejectedv_cvt_f16_f32, the binary32-to-binary16 conversion that is the reverse of thev_cvt_f32_f16lowering from #297. This adds both encodings, e32 and e64 withabsandneg.A new
narrow16helper builds the binary16 encoding in integer arithmetic, rounding to nearest even. Desktopf32tof16and denormal handling therefore cannot change the result:On GFX10 the result replaces only the low 16 bits of the destination. The LLVM 15 list
GCNSubtarget::zeroesHigh16BitsOfDest(AMDGPUSubtarget.cpp) says "On gfx10, all 16-bit instructions preserve the high bits" and includesV_CVT_F16_F32_e32/_e64. The lowering therefore merges into the destination's tracked value. A destination with no tracked value contributes zero.clampand SDWA forms are refused.Verification
Commit
6ee2406plus this change, Windows 10 Enterprise 26H2 build 26300.9974, MSVC 14.51.36231, Windows SDK 10.0.26100.0 DXC.pixel_aot_hardware: Passed on NVIDIA GeForce RTX 4070 Ti (10de:2782), driver 32.0.16.1088.pixel_aot_warp: Passed on WARP 10.0.26100.9818.6ee2406; the four extra draws are the four constant sets. Every draw reportsdebug_errors=0andmax_absolute_error=0.tests/pixel_aot_check.py binarypasses with the program added to the binary fixtures: LLVM 15.0.6llvm-mcandllvm-objcopy, disassembled throughlibLLVM-17.soandlibLLVM-18.soon Linux. The controls,tests/docs_links_check.pyandtests/bidi_controls_check.pyalso pass.narrow16, transcribed to Python, matches NumPy's float16 conversion on 412,799 binary32 inputs: 400,000 random bit patterns, the rounding points of every exponent, and both neighbours of every binary16 subnormal boundary. NaN inputs were excluded, because NumPy's payload handling differs.Evidence and follow-up
The fixture is synthetic. One shader reads the whole destination word. It narrows into a register holding 1.0, so a kept high half makes the word 1 + h × 2^-23, and
(v - 1) × 2^23is split into the two bytes of the encoding withv_floor_f32andv_fmac_f32. A zeroed high half would turn the word into a subnormal. The same shader also widens-|S0|and a subnormal result (scaled by 2^24) back to binary32. The four constant sets cover:Eleven wrong references each report
pixel_mismatch: round-half-up, truncation, early and saturating overflow, a missing carry, and a lost sign or negation. The reference uses Python's own binary16 packing, not the lowering's algorithm. The translator on6ee2406rejects the program at its firstv_cvt_f16_f32.Not measured: NaN inputs, which are not drawn, and whether Scarlett titles run with binary16 denormals enabled, as the lowering assumes. That is LLVM's default for shaders.
This branch merges cleanly with #288 and #293.
Checklist
AI-assisted: yes. Written with Claude Opus 5.5; verified on the hardware listed above.
🤖 Generated with Claude Code
https://claude.ai/code/session_01X1EBSe6YfE2ivQChRsx1hc
Imported from R0Y00/Xbox2Windows. Originally posted by alexander-src on 2026-11-21T22:27:18Z.
Checked
042b1f1on Linux (python3 -B tests/pixel_aot_check.py binary llvm-mc llvm-objcopy libLLVM.sopassed with LLVM 23.1, andnarrow16compiled in C++ matched Python's IEEE-754 half packing across all 25 boundary/rounding/overflow/subnormal cases).Two bugs caught in the
v_cvt_f16_f32lowering intools/pixel_aot.py:(-?)out before callingfp_operand()miscompiles negative inline integer constants.llvm-mc -mcpu=gfx1013assembles and disassemblesv_cvt_f16_f32_e32 v12, -1verbatim, where-1is the 32-bit pattern0xffffffff(quiet NaN ->0xfe00), but the current regex hands"1"tofp_operand()and emitsnarrow16((-asfloat(1u)))(-0.0->0x8000). Passing the full operand directly tofp_operand()fixes-1and also handles|0.5|/-|0.5|.old = vector.get(dst)only checksisinstance(old, str), so writing intov0("bary_i") orv1("bary_j") emitsasuint(bary_i) & 0xffff0000u(undeclared identifier in HLSL), andv8/v9("uv.x"/"uv.y") also bypass the numeric-register check. Requiringold.startswith(("sample", "alu", "params["))(matchingfp_operand) rejects non-numeric provenance strings cleanly.AI-assisted: yes.
Imported from R0Y00/Xbox2Windows. Originally posted by Its3rr0rsWRLD on 2026-11-21T23:11:37Z.
Thanks, @alexander-src, both confirmed and fixed in
3007879:fp_operand, sov_cvt_f16_f32_e32 v12, -1lowers tonarrow16(asfloat(4294967295u)). Before, the old regex emittednarrow16((-asfloat(1u))).-|0.5|lowers tonarrow16((-abs(0.5f))).sample/alu/params[value, as infp_operand, so writes intov0,v1,v8andv9are refused.Both cases are new controls. Before the fix, the old code accepted
v0and produced the-asfloat(1u)form.Rerun on Windows 10 Enterprise 26H2 build 26300.9974 with
ctest --preset dev --no-tests=error -R '^pixel_aot_' -V, merged with current main (bc24dfd):pixel_aot_hardware(RTX 4070 Ti, driver 32.0.16.1088) andpixel_aot_warp(WARP 10.0.26100.9818) pass with 59 draws each against 55 on main. Every draw reportsdebug_errors=0andmax_absolute_error=0.tests/pixel_aot_check.py binaryand the controls pass on Linux with LLVM 15.0.6 tools and libLLVM 18.AI-assisted: yes. Claude Opus 5.5 replying from this account.