fix(shader): choose v_fma_mix_f32 NaN results on the bits with f16 sources #19637
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/19637"
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 angrysandhill on 2026-11-13T17:11:42Z.
What
v_fma_mix_f32with an f16 source (anyop_sel_hibit set) left its NaN results to the driver;shader.mdlists this as debt. #7074 (e98cf7f9a0) already gave its invalid operations the default NaN.On RDNA2 (gfx1031, RX 6750 XT), the hardware applies the same rule as the f32 forms do since #2083:
0xffc00000.An f16 NaN source is widened on its bits before its
absandneg: its sign,0x7f800000, and its mantissa shifted left by 13.0x7c01becomes0x7f802000.Main differs from the hardware in three ways:
0x7c01, 0x3c00, 0x3c00give0x7f802000; the hardware gives0x7fc02000.op_sel_hi:[1,1,0]with src20x7f800001gives0x7f800001; the hardware gives0x7fc00001.-a * -b): in the oracle's kernels, which hold that one instruction, the result lost the sign that the negation gives the NaN.-v4, -v5with f160x7c01in src0 gave0x7f802000at IEEE=0; the hardware gives0xff802000.0x7f802000, expected0xff802000.floatTernarynow passes everyv_fma_mix_f32source tonanResultF32. A newmixNanSourceF32, next toreadMixF32, gives an f16 source as its widened NaN bits when the f16 lane is a NaN. It reads the lanereadF16LaneAsF32reads, including the high lane withop_sel. The invalid-product test still uses the flushed values the arithmetic uses. f32-only forms build the same IR as before.With
APS5_FAST_F32set,nanResultF32returns early, as it does for the f32 forms. Since6ef285d9e2(ea27c39e75before the rebase), the select #7074 added for invalid operations runs only in that mode, where it is still the only thing giving them the default NaN. With exact arithmetic,nanResultF32gives the same result.tests/execution/FmaMixF32NanSources.cpp(agc_driver_fma_mix_f32_nan_sources) pins 640 results, all measured on the RX 6750 XT:-v4, -v5,|v4|with-|v6|, the high lanes throughop_sel, and four mixes of f16 and f32 sources withnegandabs;FLOAT_MODE0xc0 and 0xf0 at IEEE 0 and 1, and 0x00 at IEEE 1;F32ArithmeticNanchecks it against its IEEE=0 table;APS5_FAST_F32asF32ArithmeticNandoes.Tested
Windows 10 22H2, AMD Radeon RX 6750 XT (gfx1031), Adrenalin 26.10.1 (driver 32.0.21045.16010), WinLibs GCC 15.2, Release. Main
6e5972c033, changesee609fe080andea27c39e75; the results below are from those unless noted.Rebased on 2026-11-14 onto main
0f4538fa02as951da1b17aand6ef285d9e2, because #16889 edited the shader.md entry above this one. The code diff is unchanged (same patch ID) and the shader.md change is the same line, so the runs posted on the earlier heads still apply. Rerun at6ef285d9e2:Negative control: fails on the same IEEE=1 row,
0x7f802000, expected0x7fc02000.Tests: the 11 below pass 11/11, the 5 under the validation layer with 0
VUID-lines, and fast mode 3/3.Oracle: 0 of the 1,456 rows differ from the hardware.
Full
^(agc_|shader|vector_), 4 at a time: 1,782 tests: 1,759 passed, 21 skipped, 1 failed, 1 not run. Every test has the same outcome as onmain(1,781 tests); the extra one is the new test, which passes.agc_driver_sample_order_grid_referencefails onmaintoo.agc_driver_upload_cache_read_only_flushdoes not build with MinGW onmain(it callssetenv).Hardware oracle, the recompiler (Vulkan runner) against the hardware (HIP), over 1,456 rows:
-v4, -v5,|v4|, |v6|and-|v6|, at IEEE 0 and 1;op_sel) in 4 of the mixes, with no modifiers,-v4, -v5and|v4|, -v5, -|v6|, at IEEE 0 and 1;Tests:
ctest -R '^agc_driver_(fma_mix_f32_nan_sources|f16_fma_invalid_nan|f32_arithmetic_nan|fma_mix_f16_denormal_modes|f32_denormal_flush|fma_rounding|mix_precision|f32_fma_denormal_mode1|f32_fma_denormal_mode2|vop3_mad_clamp|fma_legacy)$'passes 11/11.Fast mode: with
APS5_FAST_F32=1, the new test,agc_driver_f16_fma_invalid_nanandagc_driver_f32_arithmetic_nanpass 3/3.Validation layer: the new test,
f16_fma_invalid_nan,f32_arithmetic_nan,fma_mix_f16_denormal_modesandmix_precisionpass underVK_LAYER_KHRONOS_validation1.4.367 withANYPS5_REQUIRE_VULKAN=1, with 0VUID-lines and no missing-layer warnings.Negative control: with only the new test applied to main, it fails on the first IEEE=1 row:
0x7f802000, expected0x7fc02000. The modes before it pass on main, as the-a * -bnote above explains.Conventions, at
6ef285d9e2:check_conventions.pyreports one warning,debt-lengthonshader.md:167. That entry was already 3,118 characters; this change makes it 3,286.Overlap, rechecked at
6ef285d9e2:pr_overlap.py --branchreports #19710 (f32 directed rounding), which adds its rounding block just above the NaN choice infloatTernary. It is different work. A resolution keeps #19710's block and this change's NaN choice, and drops #19710's ownf32Sources && nanResultF32line, which this change covers..gitattributesmerges the debt files with the union driver, which GitHub ignores, so the tool and local merges miss conflicts there. The earlier note here missed these for that reason. A plain three-way merge ofshader.mdagainst the 98 open PRs that touch it adds conflicts with four:nanResultF32's selects), #15719, #18527 and my own #18469.Linux and NVIDIA were not tested.
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-11-21T03:58:27Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the hardware claims in the description are author-reported, and the code path inspected consistently applies source selection, modifiers, and IEEE quieting.
What I ran
Reviewed head
a64fe0bfa30d850ba5fecc037edd59f9bc55d7ba. Read the prepared description, commits, manifest, diff, and all five changed files; also read targeted context inOperandAccess.cppandDispatchInstructions.cpp. No commands or tests were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The reported RX 6750 XT, Vulkan validation, fast-mode, and negative-control runs were not independently reproduced. Linux, NVIDIA, and PS5 hardware behavior were not verified.
files.jsonwas not available; the file listing reported every changed file as included, and all were read.To get this to a good state
Nothing is required.