fix(shader): flush v_div_scale_f64 denormals by the f64 denormal field #13846
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/13846"
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:56Z.
What
v_div_scale_f64read its three f64 operands withreadF64Bitsand never looked at FLOAT_MODE bits 7:6, the f16/f64 denormal field, while its f32 analoguev_div_scale_f32reads its sources throughreadOperand(..., IrType::F32)and so flushes f32 denormal inputs by the f32 field. The f64 form kept a denormal input and result in every mode. With value0x0000000000000001and denominator and numerator0x3ff0000000000000, in f64 denormal mode 0 the hardware returns0x0000000000000000and the recompiler returned0x0000000000000001; with value1.0and a denormal denominator, mode 0 returns the default NaN0xfff8000000000000where the recompiler returned the scaled result.vDivScaleF64now flushes the value, denominator and numerator throughflushF64Bits(..., 0x40u)and the final result throughflushF64Bits(..., 0x80u). A flushed denominator or numerator becomes a signed zero, so the existing zero rule returns the default NaN; a denormal result is flushed to a zero of its sign when bit 1 of the field is clear. The VCC path and the NaN quieting are unchanged; shaders without a known float mode keep today's lowering, becauseflushF64Bitsreturns early whenfloatModeis absent.writeF64Result(clamp/omod) is untouched.One set of hardware rows is left as technical debt rather than fixed here: gfx1101 returns an infinity where this helper scales the value operand by 2^-128 and the
FPLdexp64lowering gives a subnormal or a signed zero. That difference appears in every denormal mode, including the keep-both mode on currentmain, so it is a scale-model gap independent of the denormal field, out of scope for this change.Sources:
v_div_scale_f32inFloatInstructions.cpp(the f32 sibling, read throughreadOperand(IrType::F32)), and the existingflushF64Bits/float64Unary/float64Operationf64 flush helpers that follow bit 0 (input) and bit 1 (result) of the field.docs/dev/debt/shader.md: thev_div_scale_f32 and v_div_fixup_f32entry records the matching f32 rule measured on RDNA2.Tested
Gentoo Linux, RX 7700 XT (gfx1101), RADV (Mesa 26.2.4).
Measured on RDNA3 (gfx1101, Radeon RX 7700 XT) with tools/hw-oracle; not measured on the PS5's gfx1013 or on RDNA2. All tables use f32 denormals kept, round to nearest even, DX10_CLAMP=1; FLOAT_MODE byte 0x30 | (field << 6) (mode 0 = 0x30, 1 = 0x70, 2 = 0xb0, 3 = 0xf0); IEEE 0 and 1 give identical results for every row.
F64DivScaleDenormalModes.cpp(ctestagc_driver_f64_div_scale_denormal_modes): 11 operand pairs, each run asv_div_scale_f64(value, denom, num)andv_div_scale_f64(value, value, num), with the result and the VCC written out, over the 9 modes (both IEEE settings, all four fields, and a "without a known float mode" row), with the Float64 capability skip and the device-dependent skip for devices that flush f64 denormals withoutfloat64DenormPreserve.v_div_scale_f64 f64 denormal mode 0, IEEE mode on of div_scale(value, denom, num) with 0x0000000000000001 and 0x3ff0000000000000 is 0x0000000000000001, expected 0x0000000000000000; 46 of the 88 result slots differ. Green (fix): passes.agc_driver_f64_div_scale_denormal_modes|agc_driver_f64_division$|agc_driver_f64_division_modifiers|agc_driver_division_output_modifiers|agc_driver_div_fixup_f64_denormal_modes|agc_driver_f64_add_mul_denormal_modes:agc_driver_f64_div_scale_denormal_modesfails, the other 5 pass; layer inserted 6, missing-layer line 0, VUID 0.llvmpipe (LLVM 20.1.2, 256 bits);agc_driver_div_fixup_f64_denormal_modes0.23s,agc_driver_division_output_modifiers0.15s,agc_driver_f64_add_mul_denormal_modes0.24s,agc_driver_f64_div_scale_denormal_modes0.34s,agc_driver_f64_division0.17s,agc_driver_f64_division_modifiers0.20s.mainhas 13072 value mismatches over the same sweep. All 1628 remaining value differences are the scale-model gap above, where gfx1101 returns an infinity. 1624 of them are bit-identical onmainin every mode, including keep-both. The other 4 (value 0x85ad81d79a575555 with denominator and numerator -max-normal, modes 0 and 1) are a subnormal onmainthat the new result flush turns into a signed zero, so their bits differ frommainwhile the hardware's -inf is missed either way. None of the 1628 was correct onmain.Hardware results,
v_div_scale_f64(value, denom, num)(form 0) andv_div_scale_f64(value, value, num)(form 1), VCC in braces: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:19:21Z.
Review: COMMENTED
Reviewed — additional evidence needed
The implementation and test logic look internally consistent, but the supplied hardware results are from RDNA3 and do not confirm this denormal behavior on the PS5’s RDNA2-class GPU.
What I ran
Reviewed head
3754726cff4cee939ab556ba8b883436f1618685. GitHub reports PR base809c7fa2dfb1b21e2b31b3114b7d51bc14ee88ab; I also checked against the newer currentmaintipc5e389a12647ae98b21b55dc522ab4d6d3d0943b, where the merge preview was clean. Environment: Linux x86_64, Python 3.11.2, Git 2.39.5; no compiler was invoked.Results
git diff --checkagainst currentmainmain.main; no declared dependency found.file(GLOB ... CONFIGURE_DEPENDS ...). The heuristic warning that this test might be unregistered is a false positive.pr_abi_audit.pyandpr_test_quality.pyhelpers. ABI auditing does not apply to these changed paths.Selected unedited command output
check_conventions.py:git merge-tree:Precheck helper errors:
Negative control
Findings
Blocking
No source-code defect was confirmed. I am withholding approval because this change encodes GPU floating-point denormal behavior, while the supplied hardware measurements are from gfx1101/RDNA3 and the author explicitly reports no measurement on gfx1013/RDNA2.
Non-blocking
The implementation routes input and result words through the existing f64 flush helper, and the added test covers the four denormal modes, both IEEE settings, VCC, and unknown float mode. Please add a focused RDNA2 result or pinned evidence that establishes these
v_div_scale_f64denormal rules on that generation; the current RDNA3 and lavapipe results do not establish PS5-specific behavior.Sources
vDivScaleF64implementation at the reviewed headflushF64Bitshelper at the reviewed headNot verified