Repository navigation
shader: lower gfx1013 v_cvt_pkrtz_f16_f32 as an ALU result in pixel_aot - #528
Draft
evilclanker9000 wants to merge 2 commits into
Draft
evilclanker9000 wants to merge 2 commits into
evilclanker9000 wants to merge 2 commits into
Conversation
v_cvt_pkrtz_f16_f32 was accepted only as the input of a compressed MRT0 export. Lower the VOP2 and VOP3 forms as an ordinary 32-bit result through an integer round-toward-zero helper, so later instructions can read the packed word. A finite value past the binary16 range gives the largest finite half, as LLVM folds llvm.amdgcn.cvt.pkrtz with rmTowardZero. The e64 form takes neg and abs; clamp, output modifiers, op_sel and SDWA are refused. The compressed export keeps its existing path. A draw reads the packed word byte by byte for both encodings and five constant sets, with round-to-nearest-even, swapped-half, helper-swap, dropped-modifier and exchanged-operand controls.
The negative control renamed every 'pack16_rtz(' to 'pack16_rne(', including the helper's own definition, and then prepended the real pack16_rne helper. The shader defined pack16_rne twice and DXC rejected it (redefinition of 'pack16_rne'), so pixel_aot_predicate_rounding_* failed before any draw. Only the call sites are renamed now, and the real helper is added unless the program already defines it.
5 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Change
v_cvt_pkrtz_f16_f32was only accepted as the direct input of a compressed MRT0 export: the translator kept the two source registers and rounded them inexport16. Any other read of the packed word was refused. This PR lowers the VOP2 (_e32) and VOP3 (_e64) forms as an ordinary 32-bit ALU result:pack16_rtzconverts each half in integer arithmetic, rounding toward zero whatever the MODE rounding field says. DXCf32tof16rounds to nearest even, so it is not used here, and desktop denormal handling cannot change the result.llvm.amdgcn.cvt.pkrtzwithrmTowardZero. Infinity stays infinity, a binary16 subnormal result is kept, and a binary32 subnormal input gives a signed zero. A NaN keeps its sign and top payload bits and gets the quiet bit. NaN is not drawn.negandabs.clamp, output modifiers (mul:2),op_seland the SDWA form are refused. DPP forms are left to shader: lower quad-local DPP16 and DPP8 conversion ops in pixel_aot #421.export16, so existing fixtures produce the same export. Any other word, including a moved copy of a pack, is refused by the export as before.tools/scan_unsupported_shaders.pylists the widened e32 operands and the e64 form as supported.v_cvt_f32_f16is already on main andv_cvt_f16_f32is in open #324, so this PR leaves them alone. #421 adds a DPP-onlypack16_rtzhelper that returns infinity for finite overflow; if both land, keep one helper. This PR's overflow behavior follows LLVM's constant folding.A second commit fixes the round-to-nearest-even negative control: it renamed the
pack16_rtzdefinition along with its call sites and then prepended the realpack16_rne, so DXC rejected the shader withredefinition of 'pack16_rne'and bothpixel_aot_predicate_rounding_*tests failed on Windows before any draw. Only the call sites are renamed now.Verification
pkrtz_body("e32")andpkrtz_body("e64")are assembled with llvm-mc for gfx1013, round-trip through the binary check and translate to the same HLSL as the source text.check_pkrtz_controlschecks the emitted operands (including(-params[0].w)andabs(params[1].x)for e64) and rejectsclamp,mul:2,op_sel, SDWA,v_cvt_f16_u16_e32, a missing operand, an e32 SGPR in S1, pending-sample reads/writes, and compressed exports of an SGPR-sourced or e64 pack. It asserts the CPU reference separates RTZ from RNE and from the swapped-half word in every set.v_mov_b32 v20, v16after a pack now checks that the move is a bit copy and that exporting the copy is still refused.check_pkrtz_draws(inpixel_aot_predicate_rounding_*) reads the packed word as four bytes throughv_cvt_f32_ubyte0..3. It draws e32 (S0, S1) and e64 (-S0, |S1|) with five constant sets covering ties and near-ties, 2^100 and -65520 past the range, subnormal halves, -1.5·2^-25 → -0, and -infinity. Negative controls must reportpixel_mismatch: an RNE or swapped-half reference, the shader withpack16_rtzreplaced bypack16_rne, and e64 programs that dropneg, dropabsor exchange operands.tests/form_coverage_check.pyassertsVOP2 v_cvt_pkrtz_f16_f32andVOP3 v_cvt_pkrtz_f16_f32_e64are covered in both gfx1013 and rdna2, and the rejected SDWA form andv_cvt_f16_u16are not.tools/pixel_aot.pyreverted to main, pixel_aot_check and form_coverage_check fail onUnsupported instruction 21: v_cvt_pkrtz_f16_f32_e32 v20, s44, v19.pack16_rneshader, and the e64 programs withnegorabsdropped or operands exchanged) reportspixel_mismatch, on the RTX 5080 and on WARP.ctest --preset dev --no-tests=error -R '^pixel_aot_(predicate_rounding_)?(hardware|warp)$' -Vat 2e286dd on Windows 11 build 26200.9974, VS Build Tools 2022 17.14 (MSVC 14.44.35207), Windows SDK 10.0.26100, DXC 1.9.2602.17: 4/4 passed. On an NVIDIA GeForce RTX 5080 (driver 32.0.16.1692)pixel_aot_predicate_rounding_hardwaretook 36.6 s; on WARPpixel_aot_predicate_rounding_warptook 8.4 s, both under the 60 s timeout. At 775eed8 (before the control fix) bothpixel_aot_predicate_rounding_*tests failed withredefinition of 'pack16_rne'. The D3D12 debug layer was not available. The fullctest --preset dev --no-tests=errorpassed 236/236, withbvh_wave64_hardware,bvh_wave64_warpandwave_shuffle_warpskipped.Evidence and follow-up
v_cvt_pkrtz_f16_f32has not been measured; overflow follows LLVM's constant folding.v_pk_*_f16result) is still refused.