fix(shader): honor directed f16 rounding in f16 conversions and ldexp #3012
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3012"
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 CouchRiv on 2026-10-10T20:28:59Z.
What
v_cvt_f16_f32,v_cvt_f16_i16,v_cvt_f16_u16andv_ldexp_f16ignored directedFLOAT_MODErounding and always rounded to nearest even. On RDNA2 (gfx1036), 0 of 7,120 outputs depend on round32 (bits 1:0); the f16 result follows round16 (bits 3:2). LLVM AMDGPUSIModeRegister.cpp:247-251andSIDefines.h:1502putfptrunc.roundf32→f16 inFP_ROUND_MODE_DP(bits 3:2).The directed path now reads bits 3:2 and runs only when f16 denormals are preserved (bits 7:6 = 3). With f16 denormals flushed, behaviour stays as on
main(nearest even); that combination is recorded in TechnicalDebt.Shares the test file
Float16Rounding.cppwith #2987; I rebase whichever lands second.Tested
CachyOS Linux, RTX 4070 Ti (NVIDIA) and Radeon 610M (RADV gfx1036), lavapipe (Mesa llvmpipe).
agc_driver_float16_roundingpasses on NVIDIA, RADV and lavapipe (each under 1 s).v_cvt_f16_f3249,v_cvt_f16_i166,v_cvt_f16_u1619,v_ldexp_f16207), 0 regressions; round32-only followups unchanged (0 wrong on main and on this change).python3 tools/check_conventions.py --base origin/main,git diff --check.Not tested: denorm16 modes 1 and 2,
clamp/omod/SDWA with directed rounding, gfx1013.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by ArjenS-LA on 2026-10-10T21:37:33Z.
Checked
95152666against #3040 atd9b22a93usinggit merge-tree. The overlap includes a content conflict inFloatInstructions.cpp’svLdexpF16, alongsideFloat16Rounding.cpp.When rebasing whichever lands second, the resolution needs to retain this PR’s
convertF32ToF16Bitscall together with #3040’s signed-zero input/output denormal flushing. Taking either side of the conflicting result-conversion block wholesale would lose part of the other fix.Could the rebased version rerun both the directed-rounding and ldexp-denormal cases? This is an integration check; I haven’t independently reproduced the GPU results.
Review performed with Codex assistance.
Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-10T23:53:33Z.
Review: COMMENTED
The citation is what makes this land: LLVM's
SIModeRegister.cppandSIDefines.hputfptrunc.roundfor f32→f16 inFP_ROUND_MODE_DP, bits 3:2 — so the directed path belongs there rather than onround32, and saying so turns the finding from a guess into a reference. Going the extra step and disproving the alternative — 0 of 7,120 outputs depending on bits 1:0 on gfx1036 — is what closes it.The scoping is honest and worth keeping. Running the directed path only when f16 denormals are preserved, and leaving the flushed combination as it is on
main, is a declared boundary rather than a silent one, and the entry carries it. It also connects to its siblings the way these should:Float16Rounding.cppis shared with #2987 and #3040 — three open PRs on one test file — and the intent to rebase whichever lands second is exactly the discipline this series needed. With three parties rather than two, the order is worth naming explicitly once the first of them merges.The verification is the strongest part. Three stacks — NVIDIA, RADV on gfx1036, and lavapipe — with the same test failing when the Translation change is reverted, plus a sweep replay fixing 281 rows per driver with a per-function breakdown. The negative control is what makes the other numbers mean something.
One question about the boundary. The directed path is gated on bits 7:6 being 3. If that is because the hardware needs denormals preserved for directed rounding to be observable at all, this is complete; if it is because the sweep happened to run in that mode, a single flushed-mode row would settle it the way the 7,120-row sweep settled bits 1:0.
Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-11T01:08:31Z.
#2987 is in, so this conflicts in
Float16Rounding.cpp; please rebase. Whichever of this and #3040 goes second also needs to keep bothvLdexpF16changes.Imported from boykopovar/AnyPS5. Originally posted by Silverash-i8 on 2026-10-11T02:16:25Z.
Windows run of the rebased head
7c4f9381, since the PR has no Windows results: Windows 11, WinLibs GCC 15.2.0 r7, Release, merged ontomain84cc975e, RTX 5060 Laptop and the Arrow Lake iGPU (ANYPS5_GPU=Intel).agc_driver_float16_roundingpasses on both GPUs, and so do the 6 other f16 and half tests I ran with it.AI-assisted (Claude Code); I ran this on my machine.