fix(shader): flush v_ldexp_f16 denormals per the f16 denormal mode #3040
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3040"
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:55:31Z.
What
On
main,v_ldexp_f16ignoresFLOAT_MODEf16 denormal bits and keeps denormals the hardware flushes. It now flushes a denormal half input to its signed zero when denorm16 bit 0 is clear, and a denormal half result when bit 1 is clear. NaN and infinity handling and destination high-half preservation are unchanged.denorm16 = 3and shaders without a known float mode stay as onmain. Directedround16is not changed here.Shares the test file
Float16Rounding.cppwith #2987 and #3012; I rebase whichever lands later.Tested
CachyOS Linux; RTX 4070 Ti (NVIDIA), Radeon 610M (RADV / gfx1036 hw-oracle), lavapipe (CI ICD).
agc_driver_float16_roundingfails on main with the line above and passes on the branch on NVIDIA (0.23 s), RADV (0.09 s) and lavapipe (0.15 s).v_ldexp_f16_controlsrows (denorm16 = 0/1/2 × 328) against gfx1036: 82 mismatches on main → 0 on the branch on each of NVIDIA, RADV and lavapipe; 0 regressions.check_conventions.py --base origin/main;git diff --check.Not tested here: Windows, directed
round16≠ 0, packed or ternary f16.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 Dextroid17 on 2026-10-10T22:23:05Z.
Review: COMMENTED
Six PRs landed as one series in a few hours, so I read them as one series rather than six times — and the part worth saying is that the shared premise holds up.
The premise, checked in the tree. Every change in the series reads the shader's
FLOAT_MODEthrough the model that is already here: the f32 denormal field in bits 5:4, the f16 field in bits 7:6,IEEE_MODE, and the rounding field in bits 1:0. That model is load-bearing already —AttributeInstructions.cppderives the interpolation flush flags from the same two fields (and refuses the combination it has not measured),OperandAccess.cppgates the output modifier on the field's high bit, and the quieting the NaN vectors expect (0x00400000for f32,0x0200for f16) is exactly the constantsOperandAccess.cppalready uses. Nothing in the series invents a second encoding, and every PR carries its own test undertests/execution/— collected automatically, so there is no build-list churn — with debt entries on most of them.One thing I would write down, because your own measurement implies it. This PR's debt entry reads the f16 field per bit — bit 0 preserves the half input, bit 1 the half result. The f32 field is treated differently:
VectorInstructions.cpprefuses f32 denormal fields 1 and 2 as not implemented. That is two shapes for the same register, and this series is the first place both are visible at once. If the f32 field has the same per-bit structure, then that existing refusal is refusing states that are legal, and the same gfx1036 oracle that settled f16 could settle it the same way. Worth a line in the entry whichever way it falls.One triage note for whoever merges these, since they are a series and not a cluster. The overlap is wider than any single diff suggests:
FloatInstructions.cppis touched by four of the six,docs/dev/TechnicalDebt.mdby four,Division.cppby two, andFloat16Rounding.cppby two. Merged in order, each stays the small diff it appears to be; out of order, expect conflicts in exactly those files — and expect the debt file to conflict on nearly every rebase. Thev_log_f32change is not part of the series at all — a different author, a different mechanism, a numerics correction against the driver'slog2near 1.0. Reading it as one of these would misjudge it.Measured on silicon is the bar this tree sets for instruction semantics, and the series clears it. Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-11T01:08:33Z.
Same as #3012: #2987 is in, please rebase (
Float16Rounding.cpp, TechnicalDebt).Imported from boykopovar/AnyPS5. Originally posted by Silverash-i8 on 2026-10-11T02:16:26Z.
Windows run of the rebased head
3de384f2(the PR lists Windows as not tested): Windows 11, WinLibs GCC 15.2.0 r7, Release, merged ontomain84cc975ealone (it still conflicts with #3012 invLdexpF16), RTX 5060 Laptop and the Arrow Lake iGPU (ANYPS5_GPU=Intel).agc_driver_float16_roundingpasses on both GPUs, as do the other 13 f16 and half tests. The Intel iGPU is worth having here since its f16 denormal handling differs (#2822), and the new flush cases pass on it.AI-assisted (Claude Code); I ran this on my machine.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T07:06:08Z.
Review: CHANGES_REQUESTED
Rebase looks fine and the test fails without the change, but I measured
v_ldexp_f16on RDNA2 (gfx1035) over 544 operand rows × denorm16 0..3 × IEEE 0/1 and found one mismatch class:FloatInstructions.cpp:342-345: with denorm16 bit 1 clear (modes 0 and 1), the result is flushed afterConvertF16F32rounds it. The hardware flushes when the exact result is below the minimum normal, before rounding:v_ldexp_f16 0x07ff, -1(and0x87ff) returns±0on HW, the PR returns0x0400/0x8400(0x03ff.8 rounds up to the minimum normal). Modes 2 and 3 match.0x38800000, as the multiply path in #2987 does for its tininess check) instead of the rounded half, and add{0x000007ff, 0xffffffff}/{0x000087ff, 0xffffffff}rows toLdexpDenormalVectors(expected±0for denorm16 0/1,0x0400/0x8400for 2/3).Everything else matched the hardware bit for bit (input flush, signed zeros, inf, overflow clamp, exponent clamp). Please keep both
vLdexpF16changes when #3012 lands, as already discussed.Also, the branch now carries a merge commit (
78e448c13); please rebase ontomaininstead of merging it in.Imported from boykopovar/AnyPS5. Originally posted by CouchRiv on 2026-10-11T08:37:27Z.
Thanks, you were right. Rebased onto current
main(7b5214d42, no merge commit); the result flush is now decided on the unrounded product.FloatInstructions.cpp:342-345: with denorm16 bit 1 clear, the f32 product's magnitude is compared against0x38800000beforeConvertF16F32rounds it, and a smaller value gives the signed zero. The input flush (:329-332) and the directed rounding from #3012 are unchanged.Float16Rounding.cpp:745-746:{0x000007ff, 0xffffffff}and{0x000087ff, 0xffffffff}added toLdexpDenormalVectors:±0for denorm16 0 and 1,0x0400/0x8400for 2 and 3.Tested (CachyOS, RTX 4070 Ti, Radeon 610M RADV, lavapipe):
agc_driver_float16_rounding: passes on NVIDIA, RADV and lavapipe; it fails against main's libraries (f16 ldexp denormal: denorm16 0 vector 0 (0x00000401, 0xffffffff) is 0xabcd0200, expected 0xabcd0000).0x0000..0x0fffof both signs with exponents -1 and 0 (16384 rows), denorm16 0..3, IEEE 0 and 1: 0 mismatches on the branch on NVIDIA, RADV and lavapipe, including both new rows. Main differs on 6138 rows for modes 0 and 1 and 4090 for mode 2, including those two rows (0x07ff, -1gives0x0400on main,0x0000on hardware). The earlier 328-row grid also has 0 mismatches at round16 0.Imported from boykopovar/AnyPS5. Originally posted by Silverash-i8 on 2026-10-11T08:46:07Z.
Reran the updated head
327bf794on Windows (merged onto currentmain, WinLibs GCC 15.2.0 r7, Release):agc_driver_float16_roundingwith the two newLdexpDenormalVectorsrows passes on both the RTX 5060 and the Arrow Lake iGPU, along with the other 14 f16/half tests on each.AI-assisted (Claude Code); I ran this on my machine.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T08:48:11Z.
Review: APPROVED
Thanks for the fix. Re-measured
v_ldexp_f16on RDNA2 (gfx1035): every half value × 16 exponents (incl. ±65 clamp and high exponent bits) × denorm16 0..3 × IEEE 0/1 matches this lowering bit for bit (only sNaN payloads at IEEE=0 differ, unchanged frommain).agc_driver_float16_roundingpasses on RADV and fails without the change. Merging.