Skip to content

perf(shader): emit exact f32 add, subtract and multiply as fma on MoltenVK - #8612

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
imellag:perf/shader-fused-exact-arithmetic-moltenvk
Oct 23, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
imellag:perf/shader-fused-exact-arithmetic-moltenvk

Conversation

@imellag

@imellag imellag commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

What

The recompiler marks every guest f32 add, subtract and multiply NoContraction, because the guest rounds each one separately. SPIRV-Cross turns each such instruction into a call to a helper that Metal compiles with [[clang::optnone]], so on MoltenVK those calls dominate fragment time, and its multiply helper, fma(a, b, +0.0), also turns a -0.0 product into +0.0.

On MoltenVK the three operations are now GLSL Fma whose second step is exact: a * b is fma(a, b, -0.0), a + b is fma(1.0, a, b) and a - b is fma(-1.0, b, a). Multiplying by ±1 and adding -0.0 are exact, so each form gives the separately rounded IEEE result, including the sign of a zero, whether the driver fuses Fma or not (Vulkan allows either). NaN results are still chosen on the bits (#2083). The sin, cos and log2 series (SpirvAluEmitterMath.cpp) and the offset image coordinates and gather texel scale (SpirvImageEmitter.cpp) use the same forms. The choice is a SpirvTarget flag, fusedExactArithmetic, set for VK_DRIVER_ID_MOLTENVK and part of the shader cache key and of the request serialization (version 42). Other drivers are unchanged.

This is the inline fma of #7332 (a243f0c by @ycarogabriel-lgtm), split out as asked in the #7332 review, ported to current main, with the series and image follow-up posted there. The cost was first reported on #1.

Tests:

  • New agc_driver_f32_separate_rounding: a multiply feeding an add, a subtract and a reverse subtract, 8 results × 32 rows, with no float mode and IEEE=1. In 16 of the rows, fusing the multiply into the following add changes the result, so the test fails if a driver contracts the fused forms.
  • agc_driver_f32_arithmetic_nan (rows measured on RDNA2 in feat(shader): choose f32 arithmetic NaN results on the bits #2083), agc_driver_f32_denormal_flush and the new test also run the fused forms on devices that do not use them, so lavapipe in CI checks them against the same rows. A device that uses the fused forms runs only those.
  • agc_shader_memory gains the recompiler check from feat: macOS on Apple Silicon host support (Rosetta 2 and MoltenVK) #7332 (with the flag, the f32 multiply, add and subtract become Fma and lose NoContraction); it and request_serializer cover version 43 (main uses 42 for the pixel sample order).

The serialization version, the target flag and the ShaderMemory.cpp serialization checks share lines with #6639, #6801, #6879, #7888 and #8004, and the same files with #7410, #8489 and #8564, which conflict with main now; none of them changes the same arithmetic. #8658 changes EmitFPMul32 on Apple hosts to fma(a, b, -0.0) and keeps NoContraction; with this PR, MoltenVK already gets that multiply without the decoration, so whichever lands second drops its version of that function.

Tested

Apple M4 Pro, macOS 27.0.1, x86-64 under Rosetta 2, MoltenVK 1.4.2 (Vulkan SDK 1.4.363.0), Apple clang 21.0.0.

  • Rebased onto main c188e01a42, where version 43 went to the vertex point fields: the flag is now written after them, as version 44. Linux x86-64 (Ubuntu 24.04 amd64 container on the same Mac, GCC 14.2, lavapipe from Mesa 25.2.8, validation layer 1.3.275, ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1): request_serializer, agc_shader_memory, agc_shader_control_flow (and its iteration_selection_off and forced_fallback variants), agc_driver_graphics, agc_driver_depth_bounds_state and agc_driver_pixel_barycentric_emulation pass on main and on this branch, 8/8 each; both logs have the same single VUID-VkDeviceCreateInfo-pNext-pNext line, from main.
  • Earlier, rebased onto main 27bcd6a (serialization version 43). Linux x86-64 (Ubuntu 24.04 amd64 container on the same Mac, GCC 14.2, lavapipe, ANYPS5_REQUIRE_VULKAN=1): request_serializer, agc_shader_memory, agc_driver_f32_separate_rounding, agc_driver_f32_arithmetic_nan and agc_driver_f32_denormal_flush pass. Negative control: reading the flag from version 42 makes request_serializer fail.
  • Before the rebase, on main b77bd58: request_serializer passes. main's libraries do not build on macOS, so agc_shader_memory ran on b77bd58 with a local branch that adds fix(libc): build the host-facing libc code on macOS #4627, fix(libs): build getifaddrs and two tests on macOS hosts #8279 and three libc files and GuestMemory.cpp from mugurc's ci/macos-series-2 only to build libc: passes. Negative controls: without the fused multiply the new recompiler check fails; without writing the flag both tests fail.
  • GPU: mugurc's macOS series ci/macos-series-2 53db0ba (plus feat(libkernel): JIT shared memory on macOS hosts #7937's code commits, needed to build libkernel, and fix(libkernel): keep host fault signals available on macOS #8477), with this change ported except the serialization part (the series has an older request layout). AGC and shader suites on MoltenVK: 761/807 without the change, 775/807 with it. Fixed: dpp16_operands, f16_conversion_float_mode, f16_fma_denormal_modes, f32_output_modifier, float16_fma_rounding, float16_misc, float16_modifiers, float16_rounding, ldexp_f16_inline_constants, packed_alu, packed_f16_denormal_modes, sdwa_float_selectors, sdwa_ldexp_f16, vop2_modifier_forms; none broken. With the test changes there, f32_separate_rounding and f32_arithmetic_nan pass. f32_denormal_flush still fails: without the change at lane 0 (v_mul_f32 v25, |v4|, -v5 gives 0x00000000, expected 0x80000000, the lost -0.0), with it at lane 8 (v_fma_f32 v14, v4, v5, v6 gives 0x00000000, expected 0x00800000): the guest fma, which this change does not touch. On an Apple M1 (macOS 27.0.1, MoltenVK 1.4.2), @Mauro42K ran the same port on top of perf(agc): probe the f32 denormal flush on MoltenVK #8578 (results): the same 14 tests fixed and none broken; f32_separate_rounding and f32_arithmetic_nan pass and f32_denormal_flush stops at the same lane 8.
  • Speed: Planet of Lana (PPSA19450), standing still in the village after a restored save, 3840x2160, warm caches (each build ran once before), APS5_TRACE_SECONDS=140:5 only, base and change alternated twice in one session. The base is the macOS integration head 7cf8c61 (former feat: macOS on Apple Silicon host support (Rosetta 2 and MoltenVK) #7332, which already has a243f0c) with the flag forced off, which is what main emits; the change is 7cf8c61 with the flag on plus the follow-up. Titles do not run from main on macOS. The GPU time per frame falls by more than half and the frame rate rises by about 80%:
capture commit presents in 5 s frame p50 (ms) frame p90 (ms) GPU busy per present (ms) presenter wait (ms/frame) trace
base 1 e3a7f5487 71 71.0 72.8 55.6 38.8 1-base-1-aps5-trace-e3a7f5487a1b-9475.json.gz
change 1 0d228a554 126 39.4 41.6 24.2 8.2 2-change-1-aps5-trace-0d228a554942-11144.json.gz
base 2 e3a7f5487 71 71.1 73.0 49.9 39.5 3-base-2-aps5-trace-e3a7f5487a1b-12908.json.gz
change 2 0d228a554 129 38.8 41.3 15.3 9.5 4-change-2-aps5-trace-0d228a554942-14662.json.gz
Summary lines
{"commit":"e3a7f5487a1b","dirty":false,"env":{"APS5_ASYNC_PIPELINES":"1","APS5_NO_PAD_INPUT":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"140:5"},"gpu":"Apple M4 Pro","driver":"MoltenVK 1.4.2","os":"Darwin 27.0.0","resolution":"3840x2160","window":{"spec":"seconds 140:5","first_present":3067,"ms":5048.078},"presents":71,"frame_ms":{"p50":70.952,"p90":72.849,"p99":83.151,"max":83.151},"gpu_busy_ms_per_present":55.574,"worker_busy_pct":{"queue worker 0x0":43.168},"top_phases_ms_per_frame":{"VideoOut.Flip":39.228,"Driver.Present":38.898,"Driver.Present.render_fence_wait":38.777,"Vulkan.Retire":38.777,"Vulkan.Retire.wait":38.752,"VideoOut.Flip.present":38.343,"Driver.Packet":30.439,"Driver.Packet.draw":24.937},"trace_dropped":false,"trace":"aps5-trace-e3a7f5487a1b-9475.json.gz"}
{"commit":"0d228a554942","dirty":false,"env":{"APS5_ASYNC_PIPELINES":"1","APS5_NO_PAD_INPUT":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"140:5"},"gpu":"Apple M4 Pro","driver":"MoltenVK 1.4.2","os":"Darwin 27.0.0","resolution":"3840x2160","window":{"spec":"seconds 140:5","first_present":5218,"ms":5012.876},"presents":126,"frame_ms":{"p50":39.389,"p90":41.555,"p99":50.188,"max":54.344},"gpu_busy_ms_per_present":24.222,"worker_busy_pct":{"queue worker 0x0":75.114},"top_phases_ms_per_frame":{"Driver.Packet":29.599,"Driver.Packet.draw":23.987,"Driver.Draw":23.764,"Graphics.Draw":16.088,"Driver.Draw.shader_compile_and_link":15.076,"Graphics.Draw.draw_and_resource_release":10.560,"VideoOut.Flip":9.156,"Driver.Present":8.357},"trace_dropped":false,"trace":"aps5-trace-0d228a554942-11144.json.gz"}
{"commit":"e3a7f5487a1b","dirty":false,"env":{"APS5_ASYNC_PIPELINES":"1","APS5_NO_PAD_INPUT":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"140:5"},"gpu":"Apple M4 Pro","driver":"MoltenVK 1.4.2","os":"Darwin 27.0.0","resolution":"3840x2160","window":{"spec":"seconds 140:5","first_present":3100,"ms":5055.060},"presents":71,"frame_ms":{"p50":71.113,"p90":73.039,"p99":79.879,"max":79.879},"gpu_busy_ms_per_present":49.920,"worker_busy_pct":{"queue worker 0x0":42.259},"top_phases_ms_per_frame":{"VideoOut.Flip":39.878,"Driver.Present":39.586,"Driver.Present.render_fence_wait":39.468,"Vulkan.Retire":39.468,"Vulkan.Retire.wait":39.442,"VideoOut.Flip.present":39.022,"Driver.Packet":29.833,"Driver.Packet.draw":24.267},"trace_dropped":false,"trace":"aps5-trace-e3a7f5487a1b-12908.json.gz"}
{"commit":"0d228a554942","dirty":false,"env":{"APS5_ASYNC_PIPELINES":"1","APS5_NO_PAD_INPUT":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"140:5"},"gpu":"Apple M4 Pro","driver":"MoltenVK 1.4.2","os":"Darwin 27.0.0","resolution":"3840x2160","window":{"spec":"seconds 140:5","first_present":5206,"ms":5004.336},"presents":129,"frame_ms":{"p50":38.750,"p90":41.348,"p99":43.505,"max":47.391},"gpu_busy_ms_per_present":15.344,"worker_busy_pct":{"queue worker 0x0":71.816},"top_phases_ms_per_frame":{"Driver.Packet":27.621,"Driver.Packet.draw":22.527,"Driver.Draw":22.337,"Graphics.Draw":14.708,"Driver.Draw.shader_compile_and_link":14.423,"VideoOut.Flip":10.338,"Driver.Present":9.585,"Graphics.Draw.draw_and_resource_release":9.572},"trace_dropped":false,"trace":"aps5-trace-0d228a554942-14662.json.gz"}

God of War: Sons of Sparta (PPSA28997), a new game on Cadet with the dialogue advanced from a pad input file (a cross every 3 s from 46 to 106 s), so that the window at 130 s is the first Cyclops fight (checked with frame dumps), 1920x1080, warm caches, APS5_TRACE_SECONDS=130:10 only, the same two commits alternated twice in one session, the change first. The GPU time per frame falls from 64 to 27 ms and the frame rate rises from 15 to about 34.5 fps (+130%):

capture commit presents in 10 s frame p50 (ms) frame p90 (ms) GPU busy per present (ms) presenter wait (ms/frame) trace
change 1 0d228a554 349 28.6 30.0 26.2 16.2 5-gow-change-1-aps5-trace-0d228a554942-56608.json.gz
base 1 e3a7f5487 150 64.9 72.4 64.3 53.0 6-gow-base-1-aps5-trace-e3a7f5487a1b-59159.json.gz
change 2 0d228a554 340 28.9 31.2 26.9 16.7 7-gow-change-2-aps5-trace-0d228a554942-61538.json.gz
base 2 e3a7f5487 150 65.2 69.4 64.4 52.3 8-gow-base-2-aps5-trace-e3a7f5487a1b-64156.json.gz
Summary lines
{"commit":"0d228a554942","dirty":false,"env":{"APS5_ASYNC_PIPELINES":"1","APS5_NO_PAD_INPUT":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"130:10"},"gpu":"Apple M4 Pro","driver":"MoltenVK 1.4.2","os":"Darwin 27.0.0","resolution":"1920x1080","window":{"spec":"seconds 130:10","first_present":6210,"ms":10017.631},"presents":349,"frame_ms":{"p50":28.570,"p90":29.979,"p99":35.216,"max":39.624},"gpu_busy_ms_per_present":26.206,"worker_busy_pct":{"queue worker 0x0":39.168},"top_phases_ms_per_frame":{"VideoOut.Flip":17.046,"Driver.Present":16.281,"VideoOut.Flip.present":16.239,"Vulkan.Retire":16.166,"Driver.Present.render_fence_wait":16.166,"Vulkan.Retire.wait":16.148,"Driver.Packet":11.201,"Driver.Packet.draw":9.554},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":8.507,"events_lost":45442,"totals_full":false}},"trace":"aps5-trace-0d228a554942-56608.json.gz"}
{"commit":"e3a7f5487a1b","dirty":false,"env":{"APS5_ASYNC_PIPELINES":"1","APS5_NO_PAD_INPUT":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"130:10"},"gpu":"Apple M4 Pro","driver":"MoltenVK 1.4.2","os":"Darwin 27.0.0","resolution":"1920x1080","window":{"spec":"seconds 130:10","first_present":4125,"ms":10014.015},"presents":150,"frame_ms":{"p50":64.876,"p90":72.390,"p99":98.577,"max":102.458},"gpu_busy_ms_per_present":64.311,"worker_busy_pct":{"queue worker 0x0":18.577},"top_phases_ms_per_frame":{"VideoOut.Flip":53.715,"Driver.Present":53.094,"Driver.Present.render_fence_wait":52.974,"Vulkan.Retire":52.974,"Vulkan.Retire.wait":52.947,"VideoOut.Flip.present":52.752,"Driver.Packet":12.356,"Driver.Packet.draw":10.455},"trace_dropped":false,"trace":"aps5-trace-e3a7f5487a1b-59159.json.gz"}
{"commit":"0d228a554942","dirty":false,"env":{"APS5_ASYNC_PIPELINES":"1","APS5_NO_PAD_INPUT":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"130:10"},"gpu":"Apple M4 Pro","driver":"MoltenVK 1.4.2","os":"Darwin 27.0.0","resolution":"1920x1080","window":{"spec":"seconds 130:10","first_present":6190,"ms":10003.664},"presents":340,"frame_ms":{"p50":28.885,"p90":31.227,"p99":40.961,"max":43.108},"gpu_busy_ms_per_present":26.939,"worker_busy_pct":{"queue worker 0x0":38.931},"top_phases_ms_per_frame":{"VideoOut.Flip":17.588,"Driver.Present":16.812,"VideoOut.Flip.present":16.766,"Vulkan.Retire":16.701,"Driver.Present.render_fence_wait":16.700,"Vulkan.Retire.wait":16.683,"Driver.Packet":11.412,"Driver.Packet.draw":9.739},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":8.780,"events_lost":37946,"totals_full":false}},"trace":"aps5-trace-0d228a554942-61538.json.gz"}
{"commit":"e3a7f5487a1b","dirty":false,"env":{"APS5_ASYNC_PIPELINES":"1","APS5_NO_PAD_INPUT":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"130:10"},"gpu":"Apple M4 Pro","driver":"MoltenVK 1.4.2","os":"Darwin 27.0.0","resolution":"1920x1080","window":{"spec":"seconds 130:10","first_present":4143,"ms":10041.977},"presents":150,"frame_ms":{"p50":65.150,"p90":69.407,"p99":98.458,"max":101.327},"gpu_busy_ms_per_present":64.364,"worker_busy_pct":{"queue worker 0x0":19.575},"top_phases_ms_per_frame":{"VideoOut.Flip":53.103,"Driver.Present":52.436,"Vulkan.Retire":52.317,"Driver.Present.render_fence_wait":52.317,"Vulkan.Retire.wait":52.292,"VideoOut.Flip.present":52.099,"Driver.Packet":13.062,"Driver.Packet.draw":11.046},"trace_dropped":false,"trace":"aps5-trace-e3a7f5487a1b-64156.json.gz"}

In both change captures the queue worker's trace buffer filled after 8.5 and 8.8 s (trace_dropped); totals_full is false, so the summary numbers are complete and only the trace files lack that worker's last slices.

Each trace is linked in its table. On the #7332 stack, menu and gameplay frames showed no artifacts with the fused forms, and frame dumps with and without the follow-up were the same apart from timing. Linux and Windows were not run; with other drivers the flag is off outside the three tests that force it.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: Apple M4 Pro, MoltenVK 1.4.2 (Vulkan SDK 1.4.363.0), macOS 27.0.1; Apple M1, MoltenVK 1.4.2, macOS 27.0.1 (test suites, by @Mauro42K)
  • AI-assisted: yes

@github-actions github-actions Bot added the perf Performance change label Oct 20, 2026
@imellag

imellag commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor Author

Traces of the eight captures in the table above, in the same order (each file name matches the trace field of its summary line):

1-base-1-aps5-trace-e3a7f5487a1b-9475.json.gz
2-change-1-aps5-trace-0d228a554942-11144.json.gz
3-base-2-aps5-trace-e3a7f5487a1b-12908.json.gz
4-change-2-aps5-trace-0d228a554942-14662.json.gz

5-gow-change-1-aps5-trace-0d228a554942-56608.json.gz
6-gow-base-1-aps5-trace-e3a7f5487a1b-59159.json.gz
7-gow-change-2-aps5-trace-0d228a554942-61538.json.gz
8-gow-base-2-aps5-trace-e3a7f5487a1b-64156.json.gz

They open in ui.perfetto.dev; python3 tools/trace_digest.py <trace> gives the per-thread table the presenter wait comes from.

@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

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.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 7484 core/shader/recompiler/CacheKey.hpp L299
PR 7888 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp L4901, L5019, L5176, L5183-5184, L5312, L5371-5372
core/shader/recompiler/CacheKey.hpp L299
core/shader/recompiler/ControlFlow/src/RequestSerializer.cpp L835, L872, L881, L934
core/shader/recompiler/Recompiler.cpp L607
core/shader/recompiler/Recompiler.hpp L300
core/shader/recompiler/tests/RequestSerializerTests.cpp L222, L262, L288, L418, L467, L490-492, L497, L559, L596, L608, L617, L624
PR 8489 core/shader/recompiler/CacheKey.hpp L299
core/shader/recompiler/Recompiler.hpp L300
core/shader/recompiler/SpirvBackend/src/SpirvEmitter.cpp L281
PR 8564 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp L4901, L5019, L5175-5176, L5183-5184, L5215-5216, L5230-5231, L5371-5372
core/shader/recompiler/tests/RequestSerializerTests.cpp L222, L262, L288, L418-419, L438-440, L467, L490, L497, L539-542, L608, L616-617
PR 9020 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp L4901, L5019, L5175-5176, L5183-5184, L5215-5216, L5230-5231, L5371-5372
core/shader/recompiler/ControlFlow/src/RequestSerializer.cpp L835, L881
core/shader/recompiler/tests/RequestSerializerTests.cpp L222, L262, L288, L418-419, L438-440, L467, L490, L497, L539-542, L608, L616-617
PR 9335 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp L4901, L5019, L5175-5176, L5183-5184, L5215-5216, L5230-5231, L5371-5372
core/shader/recompiler/ControlFlow/src/RequestSerializer.cpp L835, L881
core/shader/recompiler/tests/RequestSerializerTests.cpp L222, L262, L288, L418-419, L438-440, L467, L490, L497, L539-542, L608, L616-617
PR 10046 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp L1263

Some 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.

Pull request Shared files not compared
PR 907 core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
PR 1395 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 2434 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 4040 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 4072 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/SpirvBackend/src/SpirvAlu/SpirvAluEmitterMath.cpp
PR 4472 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 5021 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hpp
core/shader/recompiler/SpirvBackend/src/SpirvAlu/SpirvAluEmitterMath.cpp
core/shader/recompiler/SpirvBackend/src/SpirvEmitter.cpp
core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
PR 5371 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
PR 5431 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 5441 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 5609 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/Recompiler.hpp
PR 5925 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
core/shader/recompiler/Recompiler.hpp
PR 6188 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
core/shader/recompiler/Recompiler.hpp
PR 6202 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 6235 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/CacheKey.hpp
core/shader/recompiler/ControlFlow/src/RequestSerializer.cpp
core/shader/recompiler/Recompiler.hpp
core/shader/recompiler/tests/RequestSerializerTests.cpp
PR 6280 core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
PR 6412 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/Recompiler.hpp
PR 6488 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/SpirvBackend/src/SpirvEmitter.cpp
core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
PR 6539 core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/Recompiler.hpp
PR 6788 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 6804 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 6924 core/shader/recompiler/Recompiler.cpp
PR 6960 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 6970 core/shader/recompiler/Recompiler.hpp
PR 6977 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 7201 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
core/shader/recompiler/CacheKey.hpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/Recompiler.hpp
core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hpp
PR 7275 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 7369 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 7410 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/CacheKey.hpp
core/shader/recompiler/ControlFlow/src/RequestSerializer.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/Recompiler.hpp
core/shader/recompiler/SpirvBackend/src/SpirvAlu/SpirvAluEmitterMath.cpp
core/shader/recompiler/tests/RequestSerializerTests.cpp
PR 7449 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 7464 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 7622 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 7642 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/CacheKey.hpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/Recompiler.hpp
core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitter.hpp
core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hpp
core/shader/recompiler/SpirvBackend/src/SpirvEmitter.cpp
core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
PR 7643 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 7684 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 7689 core/shader/recompiler/Recompiler.hpp
PR 8004 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/CacheKey.hpp
core/shader/recompiler/ControlFlow/src/RequestSerializer.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/Recompiler.hpp
core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitter.hpp
core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hpp
core/shader/recompiler/SpirvBackend/src/SpirvEmitter.cpp
core/shader/recompiler/tests/RequestSerializerTests.cpp
PR 8014 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 8077 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
PR 8380 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 8658 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
core/shader/recompiler/CacheKey.hpp
core/shader/recompiler/Recompiler.hpp
core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hpp
core/shader/recompiler/SpirvBackend/src/SpirvAlu/SpirvAluEmitterMath.cpp
core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
PR 8735 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 8998 core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
PR 8999 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 9176 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 9287 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 9289 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 9356 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/CacheKey.hpp
core/shader/recompiler/ControlFlow/src/RequestSerializer.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/Recompiler.hpp
core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitter.hpp
core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hpp
core/shader/recompiler/SpirvBackend/src/SpirvEmitter.cpp
core/shader/recompiler/tests/RequestSerializerTests.cpp
PR 9387 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/CacheKey.hpp
core/shader/recompiler/ControlFlow/src/RequestSerializer.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/Recompiler.hpp
core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitter.hpp
core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hpp
core/shader/recompiler/SpirvBackend/src/SpirvEmitter.cpp
core/shader/recompiler/tests/RequestSerializerTests.cpp
PR 9400 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 9431 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 9432 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 9489 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 9508 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/CacheKey.hpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/Recompiler.hpp
core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitter.hpp
core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hpp
core/shader/recompiler/SpirvBackend/src/SpirvEmitter.cpp
core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp
PR 9670 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 9672 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 9673 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 9674 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 9675 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 9676 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 9748 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/CacheKey.hpp
core/shader/recompiler/ControlFlow/src/RequestSerializer.cpp
core/shader/recompiler/Recompiler.cpp
core/shader/recompiler/Recompiler.hpp
core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hpp
core/shader/recompiler/tests/RequestSerializerTests.cpp
PR 9891 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 9892 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 9893 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 9895 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp
PR 9897 core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
core/shader/recompiler/Recompiler.hpp
PR 9898 core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp

@imellag imellag mentioned this pull request Oct 20, 2026
@github-actions github-actions Bot added shader core/shader agc libSceAgc* labels Oct 20, 2026
@adriadam10 adriadam10 self-assigned this Oct 20, 2026
@Mauro42K

Copy link
Copy Markdown

Compared the reference-profile results on a MacBook Pro (Apple M1, macOS 27.0.1), LunarG Vulkan SDK 1.4.363.0, MoltenVK 1.4.2. Both revisions used the filtered ^(agc|shader) CTest suite with -j2.

  • a4a16a6f860afcdc5c2fbbd3d48c3701c33fbc27 (baseline + perf(agc): probe the f32 denormal flush on MoltenVK #8578): 808 tests, 687 passed, 73 skipped, 48 failed/aborted.
  • 42c3fd09a2b67829df8491b5d478444b26b02b52 (integration test commit with both PR changes): 809 tests, 702 passed, 73 skipped, 34 failed/aborted.
  • Fourteen previously failing tests passed at the latter revision; no new failures appeared in this selected suite. The 5472-result float-controls probe continued to report zero differences.

The 14 reference-profile tests that changed from failed to passed were:

  • agc_driver_dpp16_operands
  • agc_driver_f16_conversion_float_mode
  • agc_driver_f16_fma_denormal_modes
  • agc_driver_f32_output_modifier
  • agc_driver_float16_fma_rounding
  • agc_driver_float16_misc
  • agc_driver_float16_modifiers
  • agc_driver_float16_rounding
  • agc_driver_ldexp_f16_inline_constants
  • agc_driver_packed_alu
  • agc_driver_packed_f16_denormal_modes
  • agc_driver_sdwa_float_selectors
  • agc_driver_sdwa_ldexp_f16
  • agc_driver_vop2_modifier_forms

At 42c3fd09a:

  • agc_driver_f32_separate_rounding: passed.
  • agc_driver_f32_arithmetic_nan: passed.
  • agc_driver_f32_denormal_flush: failed at lane 8. First relevant output: AGC graphics: f32 denormal flush: fused lane 8 no float mode v_fma_f32 v14, v4, v5, v6 is 0x00000000, expected 0x00800000.
  • All 615 [float-controls] lines in the captured run report hardware (0 of 5472 probe results differ from the emulated flush).

This lane-8 result matches the M4 Pro result reported in the coordination thread. The M4 Pro reference run reported 46, 46, and 32 failures at the corresponding three revisions; the M1 reference runs reported 51, 48, and 34. These are comparisons of the reported reference-profile totals, not validation-profile totals.

The validation profile is complementary evidence: failures decreased from 64 at a4a16a6f8 to 48 at 42c3fd09a (16 tests changed to passing, with no new failures). It recorded no new VUID identifiers. The same 12 identifiers appeared at both revisions; VUID-VkImageViewCreateInfo-imageViewFormatReinterpretation-04466 increased from 86 to 90 occurrences, while the other identifiers’ counts were unchanged.

42c3fd09a is the integration commit prepared for this test series, not the final commit of PR #8612.

Reference failures at a4a16a6 (48)
  • agc_driver_compute_fs_table_calls
  • agc_driver_dpp16_operands
  • agc_driver_f16_conversion_float_mode
  • agc_driver_f16_fma_denormal_modes
  • agc_driver_f32_constant_factor_tininess
  • agc_driver_f32_denormal_flush
  • agc_driver_f32_output_modifier
  • agc_driver_f64_add_mul_denormal_modes
  • agc_driver_f64_rounding_denormal_modes
  • agc_driver_float16_fma_rounding
  • agc_driver_float16_misc
  • agc_driver_float16_modifiers
  • agc_driver_float16_rounding
  • agc_driver_guest_memory_lifetime
  • agc_driver_guest_memory_lifetime_copy
  • agc_driver_guest_memory_lifetime_direct
  • agc_driver_guest_memory_lifetime_heap
  • agc_driver_guest_memory_lifetime_heap_uncached
  • agc_driver_guest_memory_lifetime_locked
  • agc_driver_image_cache_bits
  • agc_driver_image_plane_bias_on_single_level_volume
  • agc_driver_image_srgb_sample_copy
  • agc_driver_image_srgb_sample_copy_forced
  • agc_driver_image_table_reuse
  • agc_driver_image_texel_status
  • agc_driver_indirect_arguments_pending_producer
  • agc_driver_ldexp_f16_inline_constants
  • agc_driver_multisample_retirement
  • agc_driver_packed_alu
  • agc_driver_packed_f16_denormal_modes
  • agc_driver_pass_input_hazard
  • agc_driver_pixel_interlock
  • agc_driver_pixel_sample_coverage
  • agc_driver_pixel_sample_iteration
  • agc_driver_rect_list_indirect
  • agc_driver_sample_mask_multisample
  • agc_driver_sdwa_float_selectors
  • agc_driver_sdwa_ldexp_f16
  • agc_driver_stencil_ref_export_unused
  • agc_driver_tessellation
  • agc_driver_uint8x4_color_target
  • agc_driver_vertex_clip_cull_distances
  • agc_driver_vertex_clip_cull_draw
  • agc_driver_vertex_clip_cull_draw_no_key
  • agc_driver_vertex_user_data_tail
  • agc_driver_vop2_modifier_forms
  • agc_performance_overlay_statistics
  • agc_write_tracking
Reference failures at 42c3fd0 (34)
  • agc_driver_compute_fs_table_calls
  • agc_driver_f32_constant_factor_tininess
  • agc_driver_f32_denormal_flush
  • agc_driver_f64_add_mul_denormal_modes
  • agc_driver_f64_rounding_denormal_modes
  • agc_driver_guest_memory_lifetime
  • agc_driver_guest_memory_lifetime_copy
  • agc_driver_guest_memory_lifetime_direct
  • agc_driver_guest_memory_lifetime_heap
  • agc_driver_guest_memory_lifetime_heap_uncached
  • agc_driver_guest_memory_lifetime_locked
  • agc_driver_image_cache_bits
  • agc_driver_image_plane_bias_on_single_level_volume
  • agc_driver_image_srgb_sample_copy
  • agc_driver_image_srgb_sample_copy_forced
  • agc_driver_image_table_reuse
  • agc_driver_image_texel_status
  • agc_driver_indirect_arguments_pending_producer
  • agc_driver_multisample_retirement
  • agc_driver_pass_input_hazard
  • agc_driver_pixel_interlock
  • agc_driver_pixel_sample_coverage
  • agc_driver_pixel_sample_iteration
  • agc_driver_rect_list_indirect
  • agc_driver_sample_mask_multisample
  • agc_driver_stencil_ref_export_unused
  • agc_driver_tessellation
  • agc_driver_uint8x4_color_target
  • agc_driver_vertex_clip_cull_distances
  • agc_driver_vertex_clip_cull_draw
  • agc_driver_vertex_clip_cull_draw_no_key
  • agc_driver_vertex_user_data_tail
  • agc_performance_overlay_statistics
  • agc_write_tracking

Tests were run with assistance from OpenAI Codex; results and conclusions were checked against the captured local logs. These test results do not measure game performance.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 21, 2026
@imellag
imellag force-pushed the perf/shader-fused-exact-arithmetic-moltenvk branch from d9e4eed to a87c0fc Compare October 21, 2026 07:16
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 21, 2026
@krishalivaibhav

Copy link
Copy Markdown
Contributor

M2 follow-up to the M1/M4 reports: I tested the published integration comparison on Apple M2 (16 GB), macOS 27.2, x86-64 under Rosetta 2, MoltenVK 1.4.2 / Vulkan SDK 1.4.363.0, Release. These are community macOS integration revisions, not standalone current main.

Focused correctness comparison

Baseline a4a16a6f860a (includes #8578) vs candidate 42c3fd09a2b6 (integration port of this PR):

Test Baseline Candidate
agc_float32_flush_control pass pass
agc_driver_f32_arithmetic_nan pass pass
agc_driver_f32_denormal_flush fails at signed-zero multiply lane 0 gets past that, fails at fused lane 8
agc_driver_f32_separate_rounding absent pass

Both used ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, and VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, with verbose CTest logs. Loader diagnostics confirm the layer actually loaded; neither log contains the missing-layer warning or any VUID- line. This is a focused comparison, not a full-suite claim.

The flush probe reports hardware (0 of 5472 probe results differ from the emulated flush) in both. First failing lines:

Baseline: f32 denormal flush: lane 0 no float mode v_mul_f32 v25, |v4|, -v5 is 0x00000000, expected 0x80000000
Candidate: f32 denormal flush: fused lane 8 no float mode v_fma_f32 v14, v4, v5, v6 is 0x00000000, expected 0x00800000

Preliminary Balatro observation — PPSA21402

At 1920×1080, the candidate reached roughly 49–50 FPS in the menu and about 30 FPS during active tutorial play; some tutorial sections remained 18–20 FPS. Baseline gameplay was about 15–20 FPS. The user observed a brief startup hitch in the candidate, without a gameplay crash in this bounded run.

tools/trace_digest.py on the captures reports candidate active-play intervals of 165 and 153 presents per five seconds (33.0 and 30.6/sec), with 20.9 and 22.1 ms GPU busy per present. The baseline's late intervals average about 17.7 presents/sec, with roughly 55–57 ms GPU busy per present.

Limits: one manual run per revision, unequal run lengths/progression timings and separately warming caches. These are not fixed-scene, warm-cache benchmark results, so I am not claiming a controlled speedup multiplier or sustained 60 FPS. Both runtime packages carried the same local bounded cache of generated barycentric tessellation stages; neither used our earlier private MSL hook. The focused correctness tests above used the clean integration revisions, before applying that common runtime cache. Two packaging attempts were excluded; the valid captures identify the intended commits.

Next: repeat warm-cache, same-scene measurements and investigate the remaining slow tutorial sections. This supports testing this existing PR rather than opening a duplicate arithmetic implementation.

AI-assisted: yes; human gameplay observations are distinguished from trace measurements above.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 21, 2026
@imellag
imellag force-pushed the perf/shader-fused-exact-arithmetic-moltenvk branch from a87c0fc to 5e58f2e Compare October 21, 2026 13:31
@imellag

imellag commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @Mauro42K and @krishalivaibhav for the M1 and M2 runs.

Both match the M4 Pro results. On the M1 the same 14 tests change from failing to passing and nothing new fails. On both chips agc_driver_f32_denormal_flush gets past the signed-zero multiply at lane 0 and then stops at fused lane 8 (v_fma_f32). This PR does not change lane 8: v_fma_f32 is already an fma, and that lane checks the guest fma's tininess, which is a separate gap.

The Balatro numbers are a useful third title next to Planet of Lana and God of War: same direction, about 55 ms of GPU time per present down to about 21 ms in active play.

The branch conflicted with main again, so I rebased it onto main 27bcd6a (now 5e58f2e). main took serialization version 42 for the pixel sample order, so the fused arithmetic flag moves to version 43; the code is otherwise unchanged. On Linux (GCC 14.2, lavapipe, ANYPS5_REQUIRE_VULKAN=1), request_serializer, agc_shader_memory, agc_driver_f32_separate_rounding, agc_driver_f32_arithmetic_nan and agc_driver_f32_denormal_flush pass, and reading the flag from version 42 makes request_serializer fail. The description now also lists #8658, which changes EmitFPMul32 on Apple hosts.

AI-assisted: yes

@imellag

imellag commented Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

Numbers on current main with the macOS port, now that titles run there. The measurements in the description were on the closed #7332 stack.

Setup: Apple M4 Pro, macOS 27.0.1, MoltenVK 1.4.2 (Vulkan SDK 1.4.363.0), x86-64 Release under Rosetta 2.

Scene main stack + this PR GPU busy per present
Planet of Lana (PPSA19450), village, standing still, 110 to 190 s 21.61 / 21.52 fps 29.40 / 30.04 / 29.83 / 29.51 fps (+38%) 34.5 → 16 to 22 ms
God of War Sons of Sparta (PPSA28997), Cyclops fight, 115 to 140 s 26.64 / 27.17 fps 39.45 / 39.47 / 39.72 / 39.57 fps (+47%) 35.0 → 22.8 ms

With this PR, Lana is bound by the queue worker instead of the GPU (busiest worker 51% → 72%).

tools/trace_digest.py rows from one run of each arm:

Lana, main stack (c66b8a2377):

| 13 | 120-130 | 217 | 45.8 | 48.3 | 53.5 | 77.0 | 34.6 | 51 % | Driver.Packet 23.3 |
| 14 | 130-140 | 217 | 45.7 | 48.2 | 64.0 | 79.2 | 34.7 | 51 % | Driver.Packet 23.3 |
| 15 | 140-150 | 217 | 45.9 | 48.3 | 51.1 | 63.9 | 34.4 | 51 % | Driver.Packet 23.5 |

Lana, + this PR (68e5a0be30):

| 12 | 130-140 | 297 | 33.3 | 36.0 | 41.0 | 58.6 | 17.1 | 72 % | Driver.Packet 24.0 |
| 13 | 140-150 | 298 | 33.0 | 36.9 | 53.0 | 67.6 | 13.9 | 72 % | Driver.Packet 23.9 |
| 14 | 150-160 | 294 | 33.6 | 37.3 | 49.7 | 55.6 | 15.4 | 73 % | Driver.Packet 24.6 |

God of War, main stack:

| 25 | 121-126 | 139 | 36.1 | 37.3 | 38.5 | 39.0 | 33.7 | 28 % | VideoOut.Flip 25.8 |
| 26 | 126-131 | 131 | 36.3 | 45.0 | 54.0 | 83.2 | 35.7 | 28 % | VideoOut.Flip 27.6 |

God of War, + this PR:

| 25 | 121-126 | 204 | 24.7 | 25.6 | 26.0 | 26.3 | 22.2 | 39 % | VideoOut.Flip 14.6 |
| 26 | 126-131 | 194 | 24.7 | 29.4 | 35.2 | 80.3 | 23.2 | 39 % | VideoOut.Flip 15.5 |

(columns: interval, seconds, presents, frame p50, p90, p99, max in ms, GPU busy per present in ms, busiest worker, largest phase)

AI-assisted: yes (Claude Code). The runs are from my M4 Pro.

…tenVK

The recompiler marks every guest f32 add, subtract and multiply
NoContraction, because the guest rounds each one separately.
SPIRV-Cross turns each of them into a call to a helper that Metal
compiles without optimization, which dominates fragment time on
MoltenVK, and its multiply helper, fma(a, b, +0.0), turns a -0.0
product into +0.0.

On MoltenVK they are now GLSL Fma whose second step is exact, which
gives the separately rounded result: a * b is fma(a, b, -0.0), a + b
is fma(1.0, a, b) and a - b is fma(-1.0, b, a). The sin, cos and log2
series and the offset image coordinates and gather texel scale use the
same forms. The choice is a SpirvTarget flag set for
VK_DRIVER_ID_MOLTENVK, part of the shader cache key and of the request
serialization (version 44); other drivers are unchanged.

agc_driver_f32_separate_rounding checks a multiply feeding an add or a
subtract on rows where fusing them changes the result. It,
agc_driver_f32_arithmetic_nan and agc_driver_f32_denormal_flush also
run the fused forms on devices that do not use them, so lavapipe checks
them against the same rows.

Co-authored-by: Ycaro Gabriel <ycaro.gabriel@performait.com>
@imellag
imellag force-pushed the perf/shader-fused-exact-arithmetic-moltenvk branch from 5e58f2e to 7410c37 Compare October 23, 2026 10:43
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 23, 2026
@adriadam10
adriadam10 merged commit 6b2d6af into boykopovar:main Oct 23, 2026
12 checks passed
@adriadam10

Copy link
Copy Markdown
Collaborator

Rechecked after the rebase onto current main: serialization version 44 is written and read consistently with the fused-arithmetic flag, the version 44/45 prefixes and the older-version fixtures account for the extra byte, and the fma forms and cache key are unchanged from what I checked before. MoltenVK numbers are the author's, with M1 and M2 confirmations; merged.

oneandonlydean added a commit that referenced this pull request Oct 28, 2026
The DB clamps a pixel shader's exported depth to PA_SC_VPORT_ZMIN_0 and
ZMAX_0 unless DB_RENDER_OVERRIDE.DISABLE_VIEWPORT_CLAMP is set. Vulkan only
clamps with depthClamp, which also drops clipping, so the exported value
reached the depth attachment unclamped.

The pixel stage info now carries the two bounds when the shader exports
depth (0 and 1 otherwise), and the exported value is NClamped to them
before it is stored to gl_FragDepth. With
DISABLE_VIEWPORT_CLAMP the value is stored as exported; non-finite or
inverted bounds are rejected. DB_RENDER_OVERRIDE joins the draw key
registers. The bounds
are part of the recompile cache key (only for depth-exporting shaders, so
other keys do not change), the draw key and its register check, and
recompile requests (serialization version 47).

Tests: the pixel stage decode reads the bounds, passes the disable flag through
and rejects bad bounds, and leaves a draw without depth export at 0 and 1; a
recompiled depth export stores the NClamped value, and its bounds survive
serialization and key the cache.

Request version 47: main is at 44 (#8612) and open PRs also claim 44 to 46 (#8564, #7888, #9193 and the #9020, #9335, #9748 stack). Whichever of these lands second renumbers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* perf Performance change shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants