perf(shader): compute v_fma_f16, v_fmac_f16, v_fmamk_f16 and v_fmaak_f16 with OpFmaKHR #15718
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15718"
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 Nesyth on 2026-11-04T09:30:02Z.
What
The scalar half of step 2 of #11183. #11265 computes
v_pk_fma_f16andv_pk_fmac_f16with one f16vec2OpFmaKHR. The scalar forms (v_fma_f16,v_fmac_f16,v_fmamk_f16,v_fmaak_f16) still take the f32 path: each source is widened to f32 with integer operations, the sum is rounded to odd in f32 and then rounded to f16. That is about 120 SPIR-V instructions per instruction. #3557 kept them there because a plain f16Fmaneed not be fused.OpFmaKHRmust be fused.With this PR they use the same
FPFma16x2op and the same device gate as #11265 (VK_KHR_shader_fmawithshaderFmaFloat16, plus native f16 math). The FLOAT_MODE condition is the one #3557 uses for scalar add and mul: no FLOAT_MODE, or one that rounds f16 to nearest even and keeps f16 denormals. The sources go into the low halves afterop_sel,absandneg, and the result is the low half.OpFmaKHRis correctly rounded and respectsDenormPreserve, and the module declaresRoundingModeRTE16. So every non-NaN result isa * b + crounded once to f16, ties to even, with denormals kept. The f32 round-to-odd path computes exactly that.FP16_OVFLturns an infinite result of finite sources into the largest finite half;clampF16Bits, as for #3557's add and mul.docs/dev/debt/shader.mdalready records for f16 arithmetic. It now comes from the driver's f16 fma rather than its f32 fma.shaderFmaFloat16, keep the f32 path.agc_driver_float16_nativealready runs these seven fma forms (modifiers,op_sel, clamp, inline constant and literal) in ten float modes and compares them bit for bit with the f32 path, accepting another NaN payload only where both results are NaN. It now also requiresOpFmaKHRon f16vec2 in the native modes when the device hasFMAKHR, and none without it or in the flush mode.Tested
Windows 11 Pro 26300, Radeon RX 7900 XTX (AMD Software 26.10.1,
shaderFmaFloat16= true), Ryzen 7 7800X3D, MinGW-w64 GCC 15.2, Ninja, Release,BUILD_TESTING=ON, this head on mainb11c7bf84f.Focused tests (
ctest -R "fma|float16|f16|packed_alu|dx10_clamp|dpp8_pk_fmac|dpp16_operands|request_serializer|agc_shader_memory", 49 tests),ANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1: 48 pass andagc_driver_float16_unused_nan_payloadsskips, as it does onmainon this device (no native f16 conversions with RTE rounding and kept f16 denormals). The same withVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation: 43 layer insertions withVK_LOADER_DEBUG=layer, nowas not foundline, noVUID-line.agc_driver_float16_native:f16 native tests passed (327680 results, 28286 NaN results with another payload, fused f16 fma). Every result that is not a NaN matches the f32 path bit for bit, andagc_driver_f16_fma_invalid_nan(in the set) checks the default NaN of the invalid operations.^agc(-E "^agc_driver_bda_device$",-j12): 1362 of 1364.agc_driver_direct_write_completionandagc_driver_sample_order_grid_referencefail onmainb11c7bf84ftoo.Size, PPSA04264 compute shaders (
agc_shader_replay --spv, requests saved withAPS5_DUMP_SHADERS):mainmain(--shader-fma)--shader-fma)0x25b16a200(the 1440p to 2160p upscale)0x25b16ca00(RCAS)In game, PPSA04264 (city gameplay after the opening, 3840x2160 output,
APS5_PROFILE_GPU, 10 s windows), measured before the rebase; the only change toFloatInstructions.cppbetween that base and this one is #11265 itself, which both have. This head's driver gave the upscale 4.44-4.63 ms of GPU per dispatch and RCAS 0.86 ms. The same program took 8.9 ms with the shader paths before #11265 and 6.9-7.2 ms with #11265's, measured on a local build whose other commits do not touch the shader paths (RCAS 1.0 and 1.0 ms).Frames, within one run (
APS5_AB, 30 s phases, 20 phases, B against the neighbouring A): on a local build, dispatching the upscale four times instead of once (about +7 ms of GPU) costs 11.0 % of the presents (-12.6 +- 5.8 per 10 s) and adds 10.9 +- 5.2 ms per frame. Skipping it costs nothing at 2.4 ms (-2.7 +- 5.1 %), where it gave +11.6 % (SE 3.7) at 8.9 ms. So in this scene the upscale's GPU time is on the frame's path, and #11265, this PR and the next step together are worth about +10 % presents. Comparing whole boots instead (three interleaved pairs, warm caches) only shows the GPU part: GPU busy 39.2 -> 32.8 ms per present, and FPS 7.13 -> 7.26, inside the boot-to-boot noise of that scene.Performance report (Performance report form): PPSA04264 open-world gameplay after the opening, 3840x2160 output, Performance graphics mode,
APS5_TRACE_SECONDS=300:30, no otherAPS5_TRACE_*orAPS5_PROFILE_*switch, the log not redirected. Each build ran the scene once and the title was restarted before its capture, and both captures come from this machine in one session.queue worker 0x0busy 97.8 % and 97.7 %), so the frame time does not move: p50 75.0 ms onmainand 75.6 ms with this PR. The change shows in the GPU time:gpu_busy_ms_per_present29.52 ms onmainand 27.87 ms with this PR.trace_dropped, withtotals_fullfalse), so the summary lines are complete while the traces hold the first 7-16 s of those threads.Traces:
aps5-trace-b11c7bf84f5d-25208.json.gz(main) andaps5-trace-476df725ba14-26272.json.gz(this PR), attached below.tools/trace_digest.pyof themaincaptureseconds 300:30 from present 5059: 393 presents, frame p50 75.0 / p90 80.0 / p99 114.3 / max 207.6 ms, GPU busy 29.5 ms per present
AMD Radeon RX 7900 XTX, AMD proprietary driver 26.10.1 (LLPC), Windows 10.0.26300, 3840x2160, commit
b11c7bf84f, dropped: yesIncomplete trace: recorded data was lost. Slice-based timings, waits and batch inventories cover retained events only; missing slices are not idle time. Summary statistics are reported separately.
Slowest frames (largest slices inside each, inclusive)
Persistent spikes (frame time above the fastest frame that separates it from a longer frame; one entry per stall, not per frame)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): batch 29.5, Graphics.Draw 16.6, Graphics.Draw.draw_and_resource_release 13.5, VideoOut.Flip 13.2, Driver.Present 13.1, VideoOut.Flip.present 13.0, Driver.Packet 11.8, Driver.Present.acquire_image 8.4, Vulkan.Acquire 8.4, Vulkan.Acquire.acquire_fence_wait 8.3
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
tools/trace_digest.pyof this PR's captureseconds 300:30 from present 4887: 390 presents, frame p50 75.6 / p90 80.2 / p99 114.7 / max 139.9 ms, GPU busy 27.9 ms per present
AMD Radeon RX 7900 XTX, AMD proprietary driver 26.10.1 (LLPC), Windows 10.0.26300, 3840x2160, commit
476df725ba, dropped: yesIncomplete trace: recorded data was lost. Slice-based timings, waits and batch inventories cover retained events only; missing slices are not idle time. Summary statistics are reported separately.
Slowest frames (largest slices inside each, inclusive)
Persistent spikes (frame time above the fastest frame that separates it from a longer frame; one entry per stall, not per frame)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): batch 27.9, Graphics.Draw 17.3, Graphics.Draw.draw_and_resource_release 14.2, Driver.Packet 11.2, VideoOut.Flip 10.0, Driver.Present 9.9, VideoOut.Flip.present 9.9, Driver.Packet.draw 6.9, Driver.Draw 6.8, Recorder.Sync 4.8
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
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)