fix(shader): flush v_fma_f64 and v_div_fmas_f64 denormals by the f64 denormal field #13845
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/13845"
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:13:52Z.
What
v_fma_f64andv_div_fmas_f64ignored theFLOAT_MODEf16/f64 denormal field (bits 7:6): both always kept their denormal operands and results, so a shader compiled with the field flushing (the common0x40/0x00modes) got a denormal where the PS5 GPU family writes a signed zero. For examplev_fma_f64of0x3ff0000000000001 * 0x000fffffffffffff + 0returned0x0010000000000000(the smallest normal) in denormal mode 0, where RDNA3 returns0x0000000000000000: in mode 0 the denormal operand0x000fffffffffffffis flushed to +0 before the multiply, so the product is 0.The lowering now follows the field, matching
v_mul_f64/v_add_f64:v_fma_f64flushes each denormal operand to a zero of its sign (flushF64Bits(.., 0x40), as add/mul do).v_div_fmas_f64keeps its operands, as measured.2^-1022to a zero of the result's sign. Tininess is judged after rounding, not before:0x2000000000000001 * 0x1ffffffffffffffeis exactly2^-1022 - 2^-1126, which rounds to2^-1022and is kept, while0x1fffffffffffffff * 0x2000000000000000is exactly2^-1022 - 2^-1075, below2^-1022after rounding, and is flushed. Forv_div_fmas_f64the test is applied to the final result after the VCC scale by2^±128.docs/dev/debt/shader.mdsaid the field is not read and thatv_fma_f64flushes with tininess before rounding, an RDNA2 (gfx1035) note without published rows. This removes that sentence, dropsv_fma_f64andv_div_fmas_f64from the add/mul entry's "keep the previous lowering" list, and adds a gap-first entry for the measured rule. The two disagree on one kind of row:0x2000000000000001 * 0x1ffffffffffffffeis exactly 2^-1022 - 2^-1126, which gfx1101 rounds to 2^-1022 and keeps, while tininess before rounding would flush it. The rule measured here is the one the add/mul entry already records forv_mul_f64on RDNA2 (gfx1031);v_fma_f64on RDNA2 is not re-measured.The tininess test recomputes the fma scaled up by
2^64through the existing integer-exactFPFmaScale64emitter (scale64forv_fma_f64,power + 64forv_div_fmas_f64, wherepoweris the VCC scale) and compares the magnitude with2^-958(2^64 * 2^-1022), the same shape as thev_mul_f64path. Signaling-NaN quieting is unchanged; it is governed by IEEE mode, not the denormal field, and is out of scope here.Exactness of the scaled recomputation:
FPFmaScale64computesfma(a, b, c)once-rounded with the scale added to the final exponent (it is the integer bit-exact multiply-add already used for the division sequence), soFPFmaScale64(a, b, c, k + 64)isfma(a, b, c) * 2^(k+64)with a single rounding and an unbounded intermediate exponent, which is the value the hardware's tininess decision uses. Scaling by2^64cannot create a false "tiny": if the true result is>= 2^-958the scaled magnitude is>= 2^-958and the test fails; if scaling overflows to infinity the true result was>= 2^958 > 2^-1022and is never tiny; a NaN result has magnitude>= 0x7ff0000000000001, fails the< 2^-958test, and is left unchanged. A zero result has magnitude 0,magnitude - 1wraps above the threshold, and is not flushed, so an exact zero keeps its sign. No operand is scaled individually, so there is no per-operand overflow case.Sources:
fusedMultiplyAddwith denormals preserved) is the existingFPFma64/FPFmaScale64lowering and is unchanged.Tested
Measured on RDNA3 (gfx1101, Radeon RX 7700 XT) with tools/hw-oracle; not measured on the PS5's gfx1013 or on RDNA2. FLOAT_MODE denorm16 field 0..3 (bytes
0x30/0x70/0xb0/0xf0), IEEE 0 and 1, DX10_CLAMP 1, round-to-nearest-even; every row below is identical at IEEE 0 and IEEE 1.mainare compared with the oracle over 300 random f64 triples (biased to denormals and small exponents) in all 8 modes, forv_fma_f64,v_div_fmas_f64with VCC clear and VCC set. Result: fixed0mismatches in scope for all three;mainhad180(v_fma_f64),116(v_div_fmas_f64VCC clear) and84(v_div_fmas_f64VCC set). Excluded,60rows each: signaling-NaN inputs whose quieting depends on IEEE mode, not the denormal field; on those the fixed and themainrecompiler agree, so the fix changes nothing there.inf * denormalrows where the (correct) input flush turnsinf * 0into the default NaN are counted as fixes, not exclusions; the fixed recompiler matches the hardware on them.Float64Instructions.cppandTranslationContext.hppreverted toorigin/mainand the new test present,agc_driver_f64_fma_denormal_modesfails at the first row:v_fma_f64 f64 denormal mode 0, IEEE mode on of 0x3ff0000000000001, 0x000fffffffffffff and 0x0000000000000000 is 0x0010000000000000, expected 0x0000000000000000. With the fix restored it passes (0device-dependent results skipped on RADV).VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ANYPS5_NO_SHADER_CACHE=1,ANYPS5_REQUIRE_VULKAN=1,VK_LOADER_DEBUG=layer), same build dir, regex = the new test plusagc_driver_f64_fma_subnormals,agc_driver_f64_denorm_preserve_spirv(a SPIR-V check that creates no Vulkan instance),agc_driver_f64_division,agc_driver_f64_division_modifiers,agc_driver_division_result_modifiers,agc_driver_f64_arithmetic,agc_driver_f64_add_mul_denormal_modes:agc_driver_f64_fma_denormal_modesfails; the other 7 pass. Layer inserted 7, missing-layer line 0,VUID-0.VUID-0. B's VUID count (0) does not exceed A's (0).agc_driver_f64_fma_denormal_modestakes 0.78 s, the slowest (agc_driver_f64_arithmetic) 3.41 s.New execution test
core/libs/prx/libSceAgcDriver/tests/execution/F64FmaDenormalModes.cpp(ctestagc_driver_f64_fma_denormal_modes): 8 lanes per case, three cases (v_fma_f64,v_div_fmas_f64with VCC clear,v_div_fmas_f64with VCC set), each run in the 9 modes (no known float mode + fields 0..3 at IEEE 0 and 1) with per-field expected tables from the hardware. Rows use three independent operands and cover the discriminators above. It keeps theFloat64capability skip and the device-dependent skip for a device that flushes f64 denormals withoutfloat64DenormPreserve, as the neighbouringF64AddMulDenormalModes.cppdoes.v_fma_f64hardware results, FLOAT_MODE IEEE 0 or 1 / DX10_CLAMP 1, one column per denormal field (identical at IEEE 0 and 1):0x3ff00000000000010x000fffffffffffff0x00000000000000000x00000000000000000x00100000000000000x00000000000000000x00100000000000000x20000000000000010x1ffffffffffffffe0x00000000000000000x00100000000000000x00100000000000000x00100000000000000x00100000000000000x1fffffffffffffff0x20000000000000000x00000000000000000x00000000000000000x00000000000000000x00100000000000000x00100000000000000x20000000000000000x1ff00000000000000x00000000000000000x00000000000000000x00000000000000000x00080000000000000x00080000000000000x000fffffffffffff0x40000000000000000x80000000000000000x00000000000000000x001ffffffffffffe0x00000000000000000x001ffffffffffffe0x3ff00000000000000x00080000000000000x00080000000000010x00000000000000000x00100000000000010x00000000000000000x00100000000000010x40000000000000000x00080000000000000x80080000000000000x00000000000000000x00000000000000000x00000000000000000x00080000000000000x3ff80000000000000x00075555555555560x00000000000000000x00000000000000000x00000000000000000x00000000000000000x000b000000000001Row 1 (
c = +0) is the input-flush discriminator: in fields 0 and 2 operandbis flushed to +0, so the product is 0; in fields 1 and 3 the product2^-1022 + ...is kept. Rows 2 and 3 are the tininess-after-rounding discriminators:2^-1022 - 2^-1126rounds up to the smallest normal and is kept in every mode, while2^-1022 - 2^-1075stays below2^-1022and is flushed in fields 0 and 1.v_div_fmas_f64with VCC clear keeps row 1's product (no input flush) and flushes the same tiny results by bit 1; with VCC set the tininess is measured on the result after the2^±128scale. The fullv_div_fmas_f64tables are in the test.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.
docs/dev/debt/shader.mdline 122 is also edited by #11483 (its DenormPreserve sentence); the sentences differ, the merge is a one-line text conflict.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:22:10Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The code change pins f64 FMA denormal behavior to gfx1101 results despite an unresolved earlier gfx1035 result and no RDNA2 measurement, and the PR also conflicts with open PR #11483 while declaring no dependency.
What I ran
Reviewed head
49198f673f0449e392f4e043486d49cbbba083a7. GitHub reports PR base809c7fa2dfb1b21e2b31b3114b7d51bc14ee88ab; the currentmaintip used for fresh checks and the merge preview was1b917483406cdaeae1d970393bcd21cda5272c9b. The preview against currentmainwas clean. Environment: Linux x86_64, Python 3.11.2, Git 2.39.5; no compiler was invoked.Results
main.maindocs/dev/debt/shader.md; both PRs replace the same existing debt entry. #11483 is open at head80cb2cd3acfdcde0abd374bc3f8886b5bd23e092.file(GLOB ... CONFIGURE_DEPENDS ...); the test-quality helper's possible-unregistered warning is a false positive.pr_abi_audit.pyandpr_test_quality.py; ABI auditing is not applicable to these paths.Selected unedited output
Conventions:
Merge preview against current
main:Pairwise merge with #11483:
Test-quality heuristic:
Precheck helper errors:
Negative control
Float64Instructions.cppandTranslationContext.hppwhile retaining the test.Findings
Blocking
v_fma_f64, based on gfx1101/RDNA3 measurements. The PR says gfx1013 and RDNA2 were not measured, while the previous debt entry records an earlier gfx1035/RDNA2 observation that judged this boundary before rounding. The PR itself says the new rule differs for0x2000000000000001 * 0x1ffffffffffffffe(the new rule keeps the minimum normal; the earlier rule flushes it). Please provide reproducible rows from RDNA2 hardware or another authoritative, generation-applicable source and reconcile the conflicting observation before encoding the behavior globally.Depends on: none. Agree which PR lands first, declare that ordering, and update the debt entry on the resulting head.Suggested checklist correction, if #11483 is to land first:
Non-blocking
No other source-level defect was confirmed. The submitted RDNA3/RADV and lavapipe results, including the reported negative control, are author-provided and were not independently reproduced here.
Sources
v_fma_f64andv_div_fmas_f64loweringNot verified
No local build, CTest run, or negative control was performed. The PR author reports focused paired hardware runs on gfx1101 and lavapipe, but no PS5 gfx1013 or RDNA2 measurement. Windows jobs were still running and macOS relinker jobs were queued in the latest CI snapshot.
To get this to a good state
Please resolve the RDNA2 behavior evidence and #11483 overlap/dependency, then update the PR. I will rerun the same no-build checks against the new head.