feat(shader): translate packed f16 in the f16 denormal modes that flush #7038
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7038"
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 thuanquang on 2026-10-17T07:03:40Z.
What
v_pk_add_f16,v_pk_mul_f16,v_pk_fma_f16,v_pk_fmac_f16,v_pk_min_f16andv_pk_max_f16threw "not implemented" in every f16 denormal mode but 3, so a shader using them withFLOAT_MODEf16 denormals flushed could not be translated. On the GPU, at f16 round to nearest even, per lane:inf * 0x0001is an invalid product there;v_pk_add_f16result below 2^-14, and av_pk_mul_f16,v_pk_fma_f16orv_pk_fmac_f16result whose exact value rounded to 11 significant bits with an unbounded exponent is below 2^-14, is flushed to a zero of its sign, the rules the scalarv_add_f16andv_mul_f16follow;v_pk_min_f16andv_pk_max_f16flush only their inputs; flushing their result as well disagrees with the GPU on 3218 to 3622 lanes in mode 1.packedFloat16now flushes the float and bit views of every source lane with the existingflushF16Input/flushF16InputValue, flushes tiny add/mul/fma results in the modes that flush them, and does not use the native f16x2 add and multiply while results are flushed (with results flushed,0x3bff * 0x0400must give 0 where an IEEE f16 multiply rounds to0x0400). It still throws for f16 rounding other than nearest even. Modes that keep f16 denormals, and shaders without a known float mode, are translated as before. #4072 changes howv_pk_fma_f16is computed in the same function; whichever lands second needs a small rebase.Measured
The same instructions were run directly on the GPU with the
tools/hw-oracletemplate, launched through the driver's HIP runtime, and through the recompiler on Vulkan, at IEEE 0 and 1 and f16 denormal modes 0 to 3, withop_sel,op_sel_hi,neg_lo,neg_hiandclampvariants,v_pk_fmac_f16with either accumulator half, all pairs or triples of 26 special halves, products and sums at the 2^-14 boundary and random lanes. With this change every lane matches the GPU:v_pk_add_f16v_pk_mul_f16v_pk_fma_f16v_pk_fmac_f16v_pk_min_f16v_pk_max_f16On
mainthe recompiler throws for every one of these shaders in modes 0 to 2.Tested
Windows 11 26200, AMD Radeon RX 6700 XT (gfx1031), driver 32.0.21045.5002, WinLibs GCC 15.2.0 r7, Release,
BUILD_TESTING=ON,ANYPS5_REQUIRE_VULKAN=1:agc_driver_packed_f16_denormal_modes:v_pk_add_f16,v_pk_mul_f16andv_pk_fma_f16over 32 lanes (denormal inputs, denormal and boundary results, signed zeros,inf * 0x0001) in f16 denormal modes 0 to 3 at IEEE 0 and 1, against the GPU's results for each mode. Onmainit fails:ShaderRecompiler::Recompile: packed f16 at pc 20 in FLOAT_MODE 48 (f16 denormals not kept or rounding not to nearest even) is not implemented. With this change it passes.agc_driver_float16_min_max_bitsnow also runs its packed min/max checks in its two flushing modes (0x30 and 0xb0), with the same flushed-input model as its scalar checks, and passes.agc_driver_packed_aluchecked that flushed f16 denormals are refused; it now checks the refusal of directed f16 rounding (0xf4) and passes.ctest --parallel 4 --timeout 120onmainf8b22edfbwith this change: 1368 tests, 2 fail, both failing onmainon this GPU too:agc_driver_lds_mixed_width_atomics(#5271) andagc_driver_layered_volume_vertex_no_gpl(#4768).agc_driver_packed_float16_native,agc_driver_f16_min_max_nanand the other f16 tests pass.python tools/check_conventions.py --base origin/mainwith this title and body passes.FP16_OVFL=1 andDX10_CLAMP=0 in the flushing modes, other AMD drivers, NVIDIA, Intel, and titles.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 github-actions[bot] on 2026-10-17T07:30:30Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)docs/dev/debt/shader.mdL94-95docs/dev/debt/shader.mdL95Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/shader/recompiler/Translation/src/FloatInstructions.cppcore/shader/recompiler/Translation/src/FloatInstructions.cppdocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mdcore/shader/recompiler/Translation/src/FloatInstructions.cppdocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mdImported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-17T08:09:01Z.
Another AMD driver, since the description lists other AMD drivers as untested.
Windows 11 (26300), Radeon 860M (RDNA 3.5,
1002:1114), driver 32.0.13058.8001, WinLibs GCC 15.2.0, Release,ANYPS5_REQUIRE_VULKAN=1. Tree:main17cfb1f4cwith #7018, #7034, #7036, #7038, #7040, #7041 and #7042 merged together (onlydocs/dev/debt/shader.mdconflicted, for #7040); "main" is the same tree with the six recompiler files reverted tomainand the tests kept.agc_driver_packed_f16_denormal_modes, and the updatedagc_driver_float16_min_max_bitsandagc_driver_packed_alu: all three fail onmain, and pass 3 of 3 with this change.AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T08:24:09Z.
@thuanquang #7040 merged, so this conflicted in docs/dev/debt/shader.md (adjacent lines). I rebased it onto main (maintainer edit): new head
e5cc0bc0fkeeps your 'Packed f16 NaN results' and v_fma_mix lines plus #7040's 'f32 denormals' line. The code is byte-identical to ab41718e3 (same patch-id). Full CI is running on the new head; it merges once that's green.