fix(shader): translate the fused f32 fma forms in f32 denormal mode 2 #12253
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12253"
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 Michael-KD on 2026-10-28T05:06:19Z.
What
v_fma_f32,v_fmac_f32,v_fmamk_f32andv_fmaak_f32threwf32 denormal mode 2 at pc P is not implementedwhen a shader'sFLOAT_MODEflushed f32 denormal inputs and kept denormal results (denormal field 2). This translates mode 2 at round to nearest even, as measured on RDNA2:a * b + conce, with gradual underflow. That is the host'sFmaof the flushed inputs underDenormPreserve 32, so mode 2 throwsneeds DenormPreserve 32without it, asv_add_f32does.0x807fffff * 0x3f7fffff + 0x80000001gives0x80000000on hardware, while the fused result is0x80800000. Implementing it needs the exact residual of the fused operation, so it is recorded in the new debt entry instead.v_mac_f32,v_madmk_f32andv_madak_f32share the decoder opcodes and still throw in both modes; RDNA2 cannot run them.Changes:
VectorInstructions.cpp:f32DenormalFlushForreturns the mode 2 flush for the fused forms at round mode 0.F32FmaDenormalMode2(new execution test): 64 of the measured triples with the hardware's results for the four forms (v_fmamk_f32with factor0x3f7fffff,v_fmaak_f32with addend0x80000001) in mode 2 at IEEE 0 and 1. It is skipped on a device withoutDenormPreserve 32.docs/dev/debt/shader.md: a new entry for the four forms in modes 1 and 2.Measurement, with the hardware oracle:
v_fma_f32 v10, v4, v5, v6,v_fmac_f32 v11, v4, v5on a copy of v6,v_fmamk_f32 v12, v4, 0x3f7fffff, v6andv_fmaak_f32 v13, v4, v5, 0x80000001.0x00000001,0x807fffff,0x00400000, 2^-126,0x80800001, ±1, 1 - 2^-24, 0.5, 2^-64,0x9fffffff, 2^-63, infinity, a NaN), and 1,500 random triples with factors of random sign in [2^-67, 2^-59) and a signed zero or random denormal addend: 5,596. Each was run at IEEE 0 and 1 in every f32 denormal mode.v_fma_f32result whose inputs are finite and whose exact value is nonzero (computed with Python'sfractions). Mode 2 differs from mode 0 on 733v_fma_f32rows, and mode 0 gives a zero on every one of them.v_fma_f32rows where it differs from mode 3, 1,129 are mode 3's result flushed. The other 8 are tiny products with a zero addend, such as0x00800000 * 0x3f7fffff + 0, which gives 0 where the fused result is0x00800000.v_fmaak_f32, whose addend is the denormal0x80000001, has 32 rows like the example above.The translation, run with all 5,596 triples and the hardware's mode 2 results in place of the test's 64 (a local variant of the new test, not committed), gives 0 mismatches for the four forms at IEEE 0 and 1 on the Radeon iGPU. The RTX 5070 Ti offers no
DenormPreserve 32, so mode 2 is refused there and the new test runs no mode.Tested
Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release.
ctest --test-dir build -R '^agc_driver_(f32_fma_denormal_mode2|f32_denormal_flush|division|nan_quieting|f32_add_mul_denormal_modes)$' -VwithANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation(Vulkan SDK 1.4.363.0, insertion confirmed withVK_LOADER_DEBUG=layer) andANYPS5_GPUset to each device. Themainarm is the merge base'sVectorInstructions.cppwith the new test added:main, RTX 5070 Timain, Radeon iGPUagc_driver_f32_fma_denormal_mode2DenormPreserve 32)agc_driver_divisionagc_driver_f32_add_mul_denormal_modesagc_driver_f32_denormal_flushagc_driver_nan_quietingOn
mainthe new test fails on both devices withFLOAT_MODE 0x000000e0: ShaderRecompiler::Recompile: f32 denormal mode 2 at pc 16 is not implemented. No log containswas not found but was requested by env var VK_INSTANCE_LAYERS, no log has aVUID-line, and each log names the selected GPU.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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T08:59:27Z.
Review: APPROVED
The mode-2 fused FMA path is constrained to round-to-nearest-even and explicitly requires
DenormPreserve 32; the separately rounded forms retain their existing path. The implementation is backed by RDNA2 oracle results and execution vectors for all four fused forms, while the debt entry records mode 1 and unsupported separately rounded forms. The reported same-GPU validation-layer runs and current Windows/relinker CI pass. No blocking issue found.