feat(shader): allow directed rounding modes for packed f16 multiply #16889
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/16889"
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 boykopovar/AnyPS5. Originally posted by AlexWhitehouse on 2026-11-07T20:36:59Z.
What
v_pk_mul_f16threwpacked f16 at pc … in FLOAT_MODE … (f16 rounding not to nearest even) is not implementedwhenever the shader'sFLOAT_MODEselected a directed f16 rounding (toward +∞, −∞ or zero). My #16739 lifted that guard forv_pk_add_f16; this PR does the same for packed multiply, with the same design, and builds on #16739.Sources:
V_PK_MUL_F16);VOP3PInstructions.tdlines 95–99, whereFPDPRounding = 1, so the instruction uses the mode's rounding;How it works:
v_interp_p2_f16interpolation arithmetic #16739 uses (FPInterpolateF16with a factor of 1 and a zero addend of the product's sign).neg_lo/neg_hi, clamp,FP16_OVFLand the NaN rules are unchanged.Debt:
shader.mdnow listsv_pk_mul_f16withv_pk_add_f16andv_pk_min/max_f16as the packed ops that accept directed rounding. It records that its four encodings match RDNA2 (gfx1036) in every mode on the test's rows, and that gfx1013 is not measured, the same way #16739 records packed add. Only those two entries changed.Tested
New test:
agc_driver_packed_mul_f16_rounding_*, 16 variants: wave32 and wave64 × rounding 0–3 × native and forced integer paths. Each variant compares 4,096 words against an independent integer significand-and-exponent reference. They cover:op_sel/op_sel_hilane selections, negation and clamp;The key case:
0x3c01 × 0x3c01gives0x3c02to nearest even and0x3c03toward +∞.Linux x86-64 (Ubuntu 26.04, GCC 15, Release, lavapipe / Mesa 26.0.8, with
ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation):VUID-lines and no missing-layer warning in either run.Windows 11, RTX 3060: (build 26300, WinLibs MinGW-w64 GCC 15.2.0 UCRT, Release, NVIDIA driver 610.88, Vulkan SDK 1.4.363, same validation environment, with the Khronos validation layer confirmed loaded):
VUID-lines and no missing-layer warning in either run;After rebasing onto
main527b309dd9(#16739 merged): on lavapipe (llvmpipe, LLVM 21.1.8) with the same validation environment, all 34 packed add and multiply tests pass with noVUID-lines and no missing-layer warning; withmain'sFloatInstructions.cppthe 12 directed multiply variants fail with the throw again.RDNA2 hardware reference (run by Nawid3333 on this PR with
tools/hw-oracle, gfx1036, AMD Windows driver 32.0.21045.16010, HIP, wave32): the test's fourv_pk_mul_f16encodings in all 128 combinations of f16 round, f16 denormal, IEEE, DX10_CLAMP and FP16_OVFL give 8,192 of 8,192 results equal to the test's expected values.Other results posted on this PR: the 34 tests pass on an NVIDIA Turing laptop GPU and an Intel iGPU (gabichuuuuu) and on an AMD RX 7800 XT (DonRyuzaki). An RDNA 3.5 measurement on gfx1151 with
tools/hw-oracleand an independent exact-fraction reference matches in all 73,728 lane results of each of the four forms, in every f16 round, f16 denormal, IEEE and FP16_OVFL mode (Jirka135).Mutation check: forcing nearest-even in the directed multiply fails with
actual=bc023c02 expected=bc023c03.python3 tools/check_conventions.py --base origin/main: no errors. The two warnings are about thev_fma_mixlo_f16and packed-NaN entries, which were already over 1,000 characters onmain; this PR only addsv_pk_mul_f16to one clause in each.python3 tools/pr_overlap.py: no other PR implements directed packed multiply.mainafter it.FloatInstructions.cpp, as it already does with #16739. Whoever merges second keeps both conditions in the native-path test (!directedAdd && !directedMul).shader.mdclauses or distant code. #14212 only reformats debt entries.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)main)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by gabichuuuuu on 2026-11-07T22:13:02Z.
Review: COMMENTED
The Intel and Turing cells. Head
06c15ccb9e(stacked on #16739's two commits) merged ontomain302864d48c(clean). Windows 11 x64, WinLibs GCC 15.2.0 r7, Release,ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 ctest -R '^agc_driver_packed_(add|mul)_f16_rounding', 3 runs per GPU.mul, 17add), 3 of 3 runsSo the new multiply rows, every rounding mode in wave32 and wave64, integer and float, give the expected bits on both drivers, and #16739's add rows still pass with this on top. Not run with
VK_LAYER_KHRONOS_validation.AI-assisted: yes.