fix(shader): emit OpFmaKHR for f32 fma when VK_KHR_shader_fma is available #15343
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15343"
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 tablefrogpillow on 2026-11-03T01:52:58Z.
What
FPFma32(guestv_fma_f32/v_fmac_f32/v_fmamk_f32/v_fmaak_f32) emittedGLSLstd450Fma, whose precision is "inherited fromOpFMulfollowed byOpFAdd". Mesa lowers that to a splitfmul+faddon RADV before RDNA2, rounding the product before the add — soagc_driver_f32_fma_denormal_mode2returns0x80000001instead of the fused0x80000002on GCN.EmitFPFma32now emitsOpFmaKHR(correctly rounded) for f32, the same path #11265 added for packed f16. The f16 and f32 FMA signals are carried as separateSpirvTargetflags (fmaFloat16/fmaFloat32), serialized and cache-keyed like the existing target bits, so an f32-only device and an f16-capable one are distinguished — theFMAKHRcapability alone cannot tell them apart.VulkanDevicedetectsVK_KHR_shader_fma'sshaderFmaFloat32alongsideshaderFmaFloat16and declaresFMAKHR+SPV_KHR_fmaonly when a used feature needs it.The f32 path is gated to
VK_DRIVER_ID_MESA_RADV, intentionally: the bug is RADV's splitfmul+faddlowering ofGLSLstd450Fma, so the narrowing excludes AMD's proprietary Windows driver (where f32 fma was reported working in review) and every other driver, which already fuse and keep the unchangedGLSLstd450Fmapath. The f16 path is unchanged from #11265 and not driver-gated.The on-disk
FormatVersionand the request serializer version are bumped for the new serialized flags;FormatVersionis re-checked againstmainat merge, as other open PRs also bump it.Tested
AGC shader recompiler.
agc_driver_f32_fma_denormal_mode2,mainvs this change, same machine and GPU,ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1:main(already carrying #11265): FAIL (v_fmamk_f32 ... is 0x80000001, expected 0x80000002). This change: PASS (both IEEE modes run). The flip is produced by this change.agc_driver_packed_float16_native,request_serializer_testspass on RX Vega 56;PackedFloat16Nativeasserts both directions (FMAKHR present +fmaFloat16off → non-fused; + on → fused).agc_shader_fusionandagc_driver_address_draw_space_reuseon RX Vega 56 (RADV VEGA10) under Khronos validation layer 1.4.363 report noVUID-and nowas not found but was requested. (TheVkShaderModuleCreateInfo-pCode-08737/08739/08741seen earlier were a validation layer older thanVK_KHR_shader_fma.)Checklist
main; no other open PR implements the same functions.mdfiles or images added to the repository🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-03T02:15:48Z.
Review: APPROVED
Windows 11, AMD RX 9070 XT (driver reports
VK_KHR_shader_fmarevision 1), WinLibs GCC,ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, merged onto currentmain:agc_driver_fma_rounding,_fma_legacy,_f32_fma_denormal_mode2,_f32_arithmetic_nan,_f32_arithmetic_nan_fast,_f32_denormal_flush,_dx10_clamp,_f32_output_modifier,_f32_result_clamp,_f32_constant_factor_tininess,_f32_add_mul_denormal_modes,_mullit_f32_denormal_modes). With main's two files restored they pass too; nothing changed in these results.throwadded afterEmitExtension("SPV_KHR_fma")inEmitFPFma32,agc_driver_fma_roundingfails with that message.Non-blocking:
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp:1617adds"SPV_KHR_shader_fma"tospirvExtensions, but the SPIR-V extension isSPV_KHR_fma, which is the name the emitter declares (core/shader/recompiler/SpirvBackend/src/SpirvAlu/SpirvAluEmitterMath.cpp:1938).3rdparty/SPIRV-Headers/include/spirv/unified1/spirv.core.grammar.json:18223listsFMAKHRunderSPV_KHR_fma. On this head the two lines above are the only occurrences of either name undercore/, andEmitFPFma32checksCapabilityFMAKHR, not the extension list; the list also goes into the feature digest (core/shader/recompiler/CacheKey.hpp:72). It's worth correcting before something gates on it.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-03T02:45:31Z.
Review: COMMENTED
Reviewed — no blocking findings
The device feature query, enable chain and FMA emission are consistent with the reported GPU behavior, but a SPIR-V extension-name typo remains and two hosted macOS checks are pending, so I am withholding approval.
What I ran
Reviewed both changed files at head
bd74e5e4ee685eb8c39fb3b066b075f0855bfce1against base7feb37ee3e30e10139b483fb4df689d5b5b69ab8; the current-base merge preview is clean. Environment: Debian Linux x86_64, Python 3.11.2, GCC 12.2.0. I did not build, compile, or run the GPU tests locally. The PR description and a separate review report targeted GPU test results; those are reported evidence, not tests I ran.Results
Full precheck table, unedited precheck output, and hosted checks
The precheck deliberately does not configure, build, or compile AnyPS5.git diff --check 7feb37ee3e30e10139b483fb4df689d5b5b69ab8...bd74e5e4ee685eb8c39fb3b066b075f0855bfce1/usr/bin/python3 tools/check_conventions.py --base 7feb37ee3e30e10139b483fb4df689d5b5b69ab8 --head bd74e5e4ee685eb8c39fb3b066b075f0855bfce1 --title fix(shader): emit OpFmaKHR for f32 fma when VK_KHR_shader_fma is available --body /tmp/anyps5-pr-precheck/15343-20261103/pr-body.md/usr/bin/python3 tools/pr_abi_audit.py --base 7feb37ee3e30e10139b483fb4df689d5b5b69ab8 --head bd74e5e4ee685eb8c39fb3b066b075f0855bfce1 --jsonNo changed Python implementation files.No changed tools/ module has an existing sibling tools/tests/test_<module>.py suite.No changed test_*.py files./usr/bin/python3 /marc/AnyPS5/tools/pr_stack_check.py 15343 --repo boykopovar/AnyPS5 --output-dir /tmp/anyps5-pr-precheck/15343-20261103/stackNot run: C++ tests need exact-head binaries, which require a build; the precheck does not build./usr/bin/python3 /tmp/anyps5-pr-precheck/15343-20261103/head-bd74e5e4ee68-20fe9b8b/tools/pr_test_quality.py --root /tmp/anyps5-pr-precheck/15343-20261103/head-bd74e5e4ee68-20fe9b8b --json core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp core/shader/recompiler/SpirvBackend/src/SpirvAlu/SpirvAluEmitterMath.cppNo changed Python test module in tools/ can be run as a no-build base-source control.conventions_and_pr_template — stdout
conventions_and_pr_template — stderr
changed_export_abi_audit — stdout
changed_export_abi_audit — stderr
live_dependency_and_mergeability_check — stdout
live_dependency_and_mergeability_check — stderr
test_quality_heuristics — stdout
test_quality_heuristics — stderr
Unedited
gh pr checksoutput:Negative control
I did not run a negative control locally because the focused C++ tests require a build. A separate reviewer reports that inserting a throw after the new emitter's
EmitExtension("SPV_KHR_fma")makesagc_driver_fma_roundingfail, which is reported evidence rather than my own run.Findings
Blocking
None found in the two changed files.
Non-blocking
VulkanDevice.cppadds"SPV_KHR_shader_fma"tospirvExtensions, but the SPIR-V extension name isSPV_KHR_fma, which the emitter actually declares. The current FMA path checksCapabilityFMAKHR, so this mismatch does not block the present execution path; correcting the advertised extension name keeps the target's supported-extension metadata accurate.Sources
Not verified
I did not independently reproduce the author's Linux RX Vega 56/RX 7900 GRE results or the other reviewer's Windows RX 9070 XT results. The two macOS relinker jobs are pending. No local build, CTest or console run was performed.
To get this to a good state
No blocking code change is required for this review. Correct the non-blocking extension-name typo when convenient; I will recheck this head and the same hosted checks before considering approval once both macOS jobs complete.
Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-05T17:59:03Z.
Review: COMMENTED
@tablefrogpillow re-review of
7675de4f9a, after the rework onto #11265's plumbing and theShaderValidationfix. My approval was onbd74e5e4ee; I'm not re-approving yet because of one question below. cc @adam25136, whose RTX 5080 run found the validator point.What I ran: this head merged onto
mainfc23faa40a(mergee92afec3a8, clean), Windows 11 Pro 10.0.26300, WinLibs GCC, Release, AMD Radeon RX 9070 XT, AMD proprietary driver 26.10.2 (vulkaninfo:shaderFmaFloat16,shaderFmaFloat32andshaderFmaFloat64all true), withANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validationandctest -V:SpirvAluEmitterMath.cppfrommainagc_driver_f32_fma_denormal_mode2,agc_driver_fma_rounding,agc_driver_fma_legacy,agc_driver_f16_fma_denormal_modes,agc_driver_f16_fma_invalid_nan,agc_driver_float16_fma_rounding,agc_driver_fma_mix_f16_denormal_modes,agc_driver_dpp8_pk_fmac,agc_fma_mix_once,agc_driver_graphicsVUID-ids / layer-not-found linesagc_driver_f32_fma_denormal_mode2prints2 of 2 IEEE modes runin both runs. So on this GPU the test passes withmain's f32 emitter too, and this run shows no regression but doesn't reproduce your Vega red/green.Question (potential bug, from reading this head; not run: this GPU reports every fma bit, per
vulkaninfoabove): the two widths now share one capability.core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp:1726declaresFMAKHRandSPV_KHR_fmawhenfloat16Fma || float32Fma, while:1722and:1723enableshaderFmaFloat16andshaderFmaFloat32separately.core/shader/recompiler/SpirvBackend/src/SpirvAlu/SpirvAluEmitterMath.cpp:1946:EmitFPFma32emits an f32OpFmaKHRwheneverFMAKHRis among the supported capabilities.core/shader/recompiler/Recompiler.cpp:266:nativeFloat16Fma = nativeFloat16 && supports(spv::CapabilityFMAKHR), which leads to the f16OpFmaKHRinEmitFPFma16x2(SpirvAluEmitterMath.cpp:1886).On a device that reports
shaderFmaFloat16withoutshaderFmaFloat32, that would put an f32OpFmaKHRin a shader on a device created withshaderFmaFloat32 = VK_FALSE. A device with onlyshaderFmaFloat32(and the f16 RTE conditions) would get the reverse for f16. Onmain,FMAKHRis declared only withfloat16Fma, and f32 fma never usesOpFmaKHR. Is anOpFmaKHRof a width whose feature isn't enabled allowed byVK_KHR_shader_fma? If not, gating each path on its own bit (passingfmaFloat32to the recompiler target, as the validator now receives it) would keep the two apart. I haven't found a device that reports only one of the two bits.Overlap (
tools/pr_overlap.py --branchon this head): #9508 (perf(agc): GPU descriptor heap) changes the sameShaderValidation.cpplines onmain(L363, the SPIR-V extension check, and L710-711), and neither PR lists the other underDepends on. Whichever lands second will need to redo those lines.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-14T03:28:17Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this change; the review is incomplete because two changed files were excluded from the prepared folder.
What I ran
Reviewed head
be59cbb3707e38c47b44c7fe991e7e89fcc9a231using the prepared diff andrepo_read.py. No build or tests were run.Results
Findings
Blocking
None in the code inspected.
Non-blocking
None.
Not verified
The full text for
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppandcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppwas excluded from the prepared folder. Their changed regions were read throughrepo_read.py, but the rest of each file was not reviewed. The other 14 changed files listed in the manifest were included; targeted ranges were read for the relevant code paths. No build, automated tests, or physical-console behavior was independently verified.To get this to a good state
Nothing is required. Optional: run the build and reported GPU tests on this head, and complete review of the excluded files before treating this as a full review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-16T18:51:41Z.
Review: APPROVED
Reviewed — looks good
The reviewed change adds per-feature FMA target flags and enables f32
OpFmaKHRon RADV when the Vulkan feature is available; no blocking defect was verified in the inspected code.What I ran
No build or tests were run. I read the prepared diff and inspected targeted source ranges at head
4403ff9b3e4c50cd3c02d12502082990db3238e9throughrepo_read.py.Results
Findings
Blocking
None verified in the inspected code.
Non-blocking
None.
Not verified
I read the changed code in
VulkanDevice.cpp,ShaderValidation.cpp,SpirvAluEmitterMath.cpp,RequestSerializer.cpp,CacheKey.hpp,RequestSerializerTests.cpp, and the changed fixture lines inShaderMemory.cpp. The diff and manifest were read; the remaining included changed files were not read in full.files.jsonwas not available as a review document; the manifest identifiesVulkanDevice.cppandShaderMemory.cppas excluded fromreview/files/, and their targeted ranges were read through the reader. No build, unit tests, GPU tests, or validation-layer checks were run; the outcomes in the PR description are author-reported.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T02:35:55Z.
Review: APPROVED
Reviewed — looks good
The reviewed portions of head
2a453f8efe20a39142c7f987c379494cb6d3cc06show consistent feature gating, serialization, cache-keying, emission, and validation for f32 FMA; no tests were run independently.What I ran
Read the prepared diff and targeted source ranges using
repo_read.pyat the pinned head. No build or tests were run. Author-reported test results indescription.mdwere not independently verified.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The full text of
VulkanDevice.cppandShaderMemory.cppwas excluded from the review folder; their changed hunks were read through the pinned reader. All other changed files listed inmanifest.jsonwere read. No full-file review, build, tests, or physical-console verification was performed. The hardware results and validation-layer results in the PR description remain author-reported.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T03:23:31Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this change; the points below are optional.
What I ran
Reviewed head
69e2a4df5c2af5b037a94800a279a7daf4dadc80. No commands or tests were run; repository content was inspected throughrepo_read.py.Results
Findings
Blocking
None in the code inspected.
Non-blocking
None.
Not verified
The changed lines of
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppandcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppwere not read from the pinned repository head. Their full text was excluded from the review folder due to size. The author-reported build, GPU results, and validation checks were not independently verified. No test was run.Read:
description.md,commits.md,manifest.json,diff.patch,core/shader/recompiler/SpirvBackend/src/SpirvAlu/SpirvAluEmitterMath.cpp, and the changed files represented in the diff. Excluded from full-text review:VulkanDevice.cppandShaderMemory.cpp.To get this to a good state
Nothing is required. Optional: independently verify the reported build and GPU tests, and inspect the excluded changed-file lines before treating this as a complete review.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T22:41:09Z.
Review: COMMENTED
I compiled the exact request serializer. The f32 FMA capability flag round-trips here, but main
c1601e56d5rejects the version 64 capture as truncated. This reader also rejects main’s version 64 capture at the emulated-barycentrics field. Please reconcile the format version and replay compatibility along with the conflicts in the serializer, cache, shader validation, and fixtures. The native format check is independent of whether the device can executeOpFmaKHR.AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.