fix(shader): flush v_ldexp_f64 denormals by the f64 denormal field #13842
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/13842"
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 Deftera186 on 2026-10-31T09:03:52Z.
What
TranslationContext::float64Unaryflushed the input ofv_floor/ceil/fract/frexp_mant_f64and the result ofv_fract_f64by theFLOAT_MODEf16/f64 denormal field (bits 7:6), butv_ldexp_f64was translated straight throughFPLdexp64and never read that field. A shader in a denormal-flushing mode got the wrong result whenever the scale produced or consumed a subnormal: with f64 denormals flushed,v_ldexp_f64 0x0000000000000001, 54(the minimum denormal scaled up by 2^54) returned0x0030000000000000instead of the hardware's+0, because the denormal input was not flushed first; andv_ldexp_f64 0x3ff0000000000000, -1023(1.0 scaled to 2^-1023) returned the denormal0x0008000000000000instead of+0.float64Unarynow flushes thev_ldexp_f64input with the existingflushF64Bits(bits, 0x40u)helper when bit 0 of the field is clear, and flushes a tiny result to a zero of the input's sign when bit 1 is clear. Tininess is tested before rounding, as the hardware does: the result is tiny when the input is finite and nonzero and its true exponent plus the scale n is below -1022. The input's true exponent isexp - 1023for a normal andmsb(mantissa) - 1074for a kept denormal; n is clamped to [-2200, 2200] first, which cannot change the comparison because the f64 exponent range is narrower and so leaves the sign ofexponent + n + 1022unchanged. The exact-value test keeps the tie right:0x3fffffffffffffff * 2^-1023is below 2^-1022 and flushes to+0in modes 0 and 1 even though it would round up to0x0010000000000000, which is what modes 2 and 3 return. Signaling-NaN quieting is unchanged (IEEE=1 quiets, IEEE=0 keeps), computed from the NaN bits. Onlyv_ldexp_f64is touched; the otherfloat64Unaryopcodes and the decoder's operand support are unchanged, and a shader without a known float mode keeps the previous lowering (mode-3 results).Sources:
FLOAT_MODEcontrols f64 denormals, per the LLVM AMDGPU kernel descriptor documentation.Tested
Measured on RDNA3 (gfx1101, Radeon RX 7700 XT) with tools/hw-oracle; not measured on the PS5's gfx1013 or on RDNA2. All tables are at DX10_CLAMP=1, round to nearest even; both IEEE settings give the same non-NaN results.
F64LdexpDenormalModes.cpp(ctestagc_driver_f64_ldexp_denormal_modes): 20 f64 inputs (signed zeros, denormals, the minimum normal and one above it, 1.0, 1.5, the tininess tie0x3fffffffffffffff, 2.0, the largest finite value, infinities and quiet and signaling NaNs) run through two forms,v_ldexp_f64with a VGPR exponent and with the inline constant -1, in the nine modes of the f64 add/mul test (the four denormal fields at IEEE 0 and 1, and a shader without a known float mode). Expected values are the gfx1101 results.origin/mainand the test present, it fails atAGC graphics: v_ldexp_f64 by v6 f64 denormal mode 0, IEEE mode on of 0x0000000000000001 is 0x0030000000000000, expected 0x0000000000000000(the test throws on the first wrong result). After restoring the fix it passes:f64 ldexp denormal mode tests passed, 0 device-dependent results skipped.probe-main(unfixed) gives 100/45/68/0 in fields 0/1/2/3 at each IEEE setting, 426 total. A further 4096 random rows give 0 mismatches for the fix and 122 for main.VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,VK_LOADER_DEBUG=layer) overagc_driver_f64_ldexp_denormal_modes,agc_driver_nan_quieting(runsv_ldexp_f64),agc_driver_f64_add_mul_denormal_modes,agc_driver_f64_rounding_denormal_modesandagc_driver_div_fixup_f64_denormal_modes. State A (fix reverted, test present): the layer is inserted 5 times, no missing-layer line, 0 VUID messages, and only the new test fails (4 of 5 pass). State B (fix): the layer is inserted 5 times, no missing-layer line, 0 VUID messages, 5 of 5 pass. B's VUID count does not exceed A's.agc_driver_f64_ldexp_denormal_modespasses on llvmpipe (LLVM 20.1.2), Mesa 25.2.8, in an Ubuntu 24.04 container with the Linux CI configuration, in 0.52 s, 0 device-dependent results skipped.Hardware results on gfx1101 (FLOAT_MODE field, IEEE=0, DX10_CLAMP=1, round to nearest even). The recompiler result on
origin/mainis in parentheses where it differed; with the fix every result matches.Fields 0 and 2 clear bit 0, so the denormal src0
0x000fffffffffffffand0x0000000000000001are flushed to+0before scaling; fields 0 and 1 clear bit 1, so the tiny results of rows 3-5 flush to+0. The tie row0x3fffffffffffffffscaled by 2^-1023 is below 2^-1022 and flushes in fields 0 and 1, while fields 2 and 3 return the rounded0x0010000000000000. A signaling NaN src0 (0x7ff0000000000001) is returned unchanged with IEEE=0 and quieted to0x7ff8000000000001with IEEE=1, unchanged by the denormal field.GPUs tested:AMD Radeon RX 7700 XT (gfx1101), RADV, Mesa 26.2.4, Gentoo Linux (kernel 7.2.11); llvmpipe (LLVM 20.1.2), Mesa 25.2.8, Ubuntu 24.04 container with the Linux CI configuration.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)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-31T09:25:56Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The new lowering encodes tininess-before-rounding for f64
v_ldexpfrom gfx1101 results, while the PR explicitly has no RDNA2 or PS5 gfx1013 measurement for this target-sensitive boundary.What I ran
Reviewed head
64dfa4ed4cea684bba15baf45ea4cfe2a9b603a3. GitHub reports PR base809c7fa2dfb1b21e2b31b3114b7d51bc14ee88ab; fresh checks and the merge preview used currentmaind8ffa97effa1ab0113dc265d936e94322045875d, against which the preview was clean. Environment: Linux x86_64, Python 3.11.2, Git 2.39.5; no compiler was invoked.Results
main.main.Selected unedited command output
Conventions:
Merge preview:
Negative control
Findings
Blocking
The test pins
0x3fffffffffffffff * 2^-1023to flush in modes 0 and 1 even though the rounded result is the minimum normal. That is the specific before-rounding behavior implemented in the change. The PR reports hardware measurements only on gfx1101/RDNA3 and says RDNA2 and the PS5's gfx1013 were not measured; the cited ISA references establish the scale operation and denormal controls, but not this rounding-boundary result. Please provide a focused RDNA2 measurement or an authoritative source for this exactv_ldexp_f64boundary before applying the result as general PS5 behavior.Non-blocking
No other source-level defect was confirmed. The author-reported gfx1101 and lavapipe runs, including the negative control, were not independently reproduced here.
Sources
v_ldexp_f64lowering at the reviewed headNot verified
No local build, CTest run, or negative control was performed. The hardware and lavapipe results are author-reported; no RDNA2 or PS5 gfx1013 run was available. The latest hosted Windows and macOS jobs had not finished.
To get this to a good state
Please provide the RDNA2 result or authoritative evidence for the exact rounding boundary, then update the PR. I will rerun the same no-build checks on the new head.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-31T11:42:19Z.
Review: APPROVED
Re-checked — new evidence, looks good
A participant reports that the exact-head denormal test passes on an RX 6700 XT, addressing the hardware-evidence gap from my prior review.
What I ran
Rechecked head
64dfa4ed4cea684bba15baf45ea4cfe2a9b603a3against PR base809c7fa2dfb1b21e2b31b3114b7d51bc14ee88ab; the merge preview was clean against currentmaincbed91529193c47194bef11811906c7cb6054af1. The participant's test usedmain8f55414024c614b32548254e59e80bd3f0085231plus this exact PR head; none of the PR's touched paths changed from that main to current main. Environment: Linux x86_64, Python 3.11.2. I did not build or run C++ tests locally.Results
mainagc_driver_f64_ldexp_denormal_modespassed 3/3 on Windows 11 with the Khronos validation layer loaded 3 times and no VUIDs. I did not run this test.Unedited local convention output
Findings
Blocking
None found on this head. The added lowering's exact rounding-boundary behavior now has reported test evidence on the RX 6700 XT target, and no other source-level blocker was found in my prior review.
Sources
v_ldexp_f64lowering at the reviewed headNot verified
I did not build locally, repeat the Windows GPU run, or test on a physical PS5/gfx1013. The RX 6700 XT result is participant-reported; hosted Linux product tests were skipped.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-31T11:49:31Z.
Review: CHANGES_REQUESTED
Re-checked — changes requested
The denormal test can count an arbitrary wrong result as a device-dependent skip when the device does not support preserving f64 denormals.
What I ran
Reviewed exact head
64dfa4ed4cea684bba15baf45ea4cfe2a9b603a3against PR base809c7fa2dfb1b21e2b31b3114b7d51bc14ee88ab; its preview against currentmain5de1621ff13712e8b3a6d70a2487b008d9ee80c3is clean. Environment: Debian Linux x86_64, Python 3.11.2. I inspected the changed test and ran the no-build precheck; I did not build or run the C++ test.Results
Negative control
0x12345678deadbeeffor the minimum-denormal/scale-54 resultactualwith an allowed flushed result.Findings
Blocking
In
Check,deviceDependentonly asks whether another mode has a different expected value;Require(deviceDependent && !keepsDenormals, ...)then accepts any mismatchingactualwhenever preservation is unsupported. Please requireactualto match an explicitly allowed flush result before counting a skip, and add a negative control showing an unrelated finite value fails. See the exact-head check and the reported mutation.Non-blocking
None identified in this follow-up.
Not verified
I did not compile or run the test locally, independently verify the reported GPU run, or test PS5 hardware. The fresh precheck reports the exact head and base unchanged.
To get this to a good state
Add the allowed-result guard and the unrelated-value negative control, then rerun the focused test on the new head. I’ll re-check the same source and test path after that update.