Repository navigation
Conversation
ebe7e25 to
b1393f0
Compare
|
Rebased onto The six PRs in the overlap table don't need to be dependencies. I trial-merged each with this branch. Each conflicts only on lines next to this PR's, and none of them is something this PR builds on:
Whichever merges second needs a rebase of those lines. If one of them merges first, I'll rebase this one. AI-assisted (Claude Code) |
|
Rebase handoff — rebased onto current Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
To pick it up: Head is |
|
Thanks for the rebase handoff. I’ve pushed a packed-f16 special-rules candidate on current upstream as This overlaps the translation and SPIR-V math emitter changed here. I have not opened the PR yet. Would you prefer that I stack it on the |
|
I opened #5057 for #4042. It moves the existing packed-f16 special-value repair behind a guard, including the current f32 FMA fallback. Your PR adds the native Could we land #5057 first, then rebase #4072 and carry the guard over its native-FMA result? If you prefer the reverse order, I can rebase #5057 after your change and add the native-FMA coverage here. I have not measured the Palworld performance change; the issue reporter offered to run that A/B. |
adriadam10
left a comment
There was a problem hiding this comment.
Thanks. I ran this on Linux with RADV (Radeon 660M, Mesa exposes VK_KHR_shader_fma with shaderFmaFloat16 = true), configured like the Linux CI job (-DANYPS5_ENABLE_SPIRV_TOOLS=ON):
- 6 tests fail, this PR's included:
agc_driver_packed_float16_native,agc_driver_float16_fma_rounding,agc_driver_packed_alu,agc_driver_dx10_clamp,agc_driver_dpp8_pk_fmac,agc_driver_dpp16_operands. All of them fail withShaderRecompiler::Recompile: SPIR-V validation before optimization failed: Invalid capability operand: 6030.- The cause is the
3rdparty/SPIRV-Toolssubmodule (v2025.4). Like SPIRV-Headers, it predatesSPV_KHR_fma, so spirv-val rejects theFMAKHRcapability. Every shader with a packed f16 fma then fails to recompile on any device that hasshaderFmaFloat16(current RADV, NVIDIA) in a SPIRV-Tools build. - CI is green only because its lavapipe (Mesa 25.2.8) has no
VK_KHR_shader_fma, so it never takes the new path. Your Windows run doesn't enable SPIRV-Tools. - Suggested fix: update
3rdparty/SPIRV-Headersand3rdparty/SPIRV-Toolsto versions that knowSPV_KHR_fma(Headers 9268f3057, SPIRV-Tools 8f9381775 "spirv-val: Add validation for SPV_KHR_fma", in v2026.1 and later), ideally in a separate PR this one depends on. That also letsSpirvFma.hppand its TechnicalDebt entry go, sincespv::OpFmaKHR/spv::CapabilityFMAKHRwould exist. If the bump has to wait, don't advertiseFMAKHRwhen SPIRV-Tools is enabled.
- The cause is the
ShaderValidation.cpp:247,:295: theFMAKHRcapability andSPV_KHR_fmaare accepted whether or not the device enabledshaderFmaFloat16. The other optional extensions on thatRequireline are gated on their feature (imageInt64Atomics,descriptorIndexing, ...); please gate this one on the enabled feature too.- The branch conflicts with
main(ShaderValidation.cpp,docs/dev/TechnicalDebt.md). Also, #5057 changes the samepackedFloat16path and asks to land first; please agree on an order with @MarcZX100 so the guard covers theOpFmaKHRresult.
…inned revision SPIRV-Tools v2025.4 and the SPIRV-Headers revision before it predate SPV_KHR_fma, so spirv-val rejects the FMAKHR capability (6030) and spv::OpFmaKHR does not exist. v2025.5 is the first release with SPV_KHR_fma validation (8f9381775). SPIRV-Headers moves to b824a462d, the revision v2025.5's DEPS pins, which includes the SPV_KHR_fma headers update (9268f3057). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When the device has native f16 math and VK_KHR_shader_fma with shaderFmaFloat16, a packed f16 fma is one f16vec2 OpFmaKHR (SPV_KHR_fma). Vulkan requires OpFmaKHR to be correctly rounded and to respect RoundingModeRTE and DenormPreserve, so it gives the fused, once-rounded result the f32 round-to-odd sum computes. The NaN, FP16_OVFL and clamp rules still run on the result bits. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
b1393f0 to
28cebd8
Compare
|
Thanks for running it on RADV with SPIRV-Tools, and sorry for the slow reply, busy day. All three points are addressed:
Tested with @MarcZX100 Fine with #5057 landing first. I'll rebase this on it and put the native fma result behind the guard as well. The A/B for #5057 is on that PR. AI-assisted (Claude Code) |
|
Thanks for the update. I checked the current diff: it now gates |
|
I ran this change on NVIDIA, where 28cebd8 no longer applies to main. Cherry-picked onto 2fee39f it conflicts in 10 files, each on neighbouring lines that main added (the per-lane source cache and The PR also needs #5319's submodule pins, which main no longer has: 1db31b9 (#6134, merged 2026-10-18) moved SPIRV-Headers back to 01e057791 and SPIRV-Tools back to 7f2d9ee92 (v2025.4). Without #5319's pins the build fails with Tests, built with GTA V (PPSA04263 01.010.002), Story Mode after Resume Story (the bank), Graphics Mode Performance, 3840x2160. Each side's caches were warmed until its last 60 s built no pipelines. The window is 60 s (
p50 is 7.0 ms lower (-8.8 %), against a spread of 0.6 ms on each side, and GPU time per present is 6.8 ms lower. With Summary lines (A, A, B, B)The summary lines' Driver.EndSubmission (about 2,700 to 2,900 ms per frame) and worker_busbout 3,700 %) are not costs: on the pipelined path the Driver.EndSubmission timer staysopen through the rewind tail, so nested tails are counted many times over (#8092, fixed on main by #8108). Not tested: other GPUs and drivers (RADV included), Windows, other titles and scenes. AI-assisted: yes |
|
@adriadam10 a question on PRs assigned to you: these have been waiting on a rebase for 3+ days with no author activity for over a week: #4072 #5371 #5836 #5609 #6187 #6194 #6197 #6657 #6867. OK if I close them with a reopen-when-rebased note, or would you rather keep any of them open? (#6158 I've already closed as a duplicate of #8417.) |
|
Verified fresh (head
|
Yes, sorry too busy. Please at anytime if im standing in the way of progress just do what feels right |
|
Thanks for the work on this and for the quick reply. Closing it for now since it needs a rebase (and the SPIRV-Headers pin on main lacks OpFmaKHR). Feel free to reopen anytime once it's rebased. |
What
v_pk_fma_f16andv_pk_fmac_f16use one native f16vec2 fused multiply-add when the device hasVK_KHR_shader_fmawithshaderFmaFloat16. Before, each half was converted to f32 and summed with round-to-odd (#2000).This extends #3531, which does the same for
v_pk_add_f16andv_pk_mul_f16. #3531 kept the fma on the f32 path because GLSLFmais not required to be fused, and it namedOpFmaKHR(VK_KHR_shader_fma,shaderFmaFloat16) as the way to get a guaranteed fused f16 fma. NVIDIA 610.74 on Windows exposes it, withshaderFmaFloat16,shaderFmaFloat32andshaderFmaFloat64all true on an RTX 2080 Ti.VulkanDevice: queriesVkPhysicalDeviceShaderFmaFeaturesKHRonly when the f16 path from perf(shader): compute v_pk_add_f16 and v_pk_mul_f16 with native f16 math #3531 is already enabled (Float16, RTE, preserved denormals, preserved signed zero, inf and NaN). IfshaderFmaFloat16is supported, it enables the extension and the feature and adds theFMAKHRcapability andSPV_KHR_fma. Graphics shader validation accepts both only when the device enabledshaderFmaFloat16(Context::fmaFloat16), as for the other optional extensions.FPFma16x2, and the existing NaN,FP16_OVFLand clamp rules run on the result bits unchanged.FPFma16x2is emitted asOpFmaKHRon f16vec2, decoratedNoContraction.spv::OpFmaKHRandspv::CapabilityFMAKHRcome from SPIRV-Headers, and spirv-val accepts them, from build(deps): update SPIRV-Tools to v2025.5 and SPIRV-Headers to its pinned revision #5319 on. This PR depends on it.Why the results don't change:
OpFmaKHRas "Correctly rounded".OpFmaKHRis listed among the instructions that must respectDenormPreserve. The definition of correctly rounded appliesRoundingModeRTE, which this module declares for 16-bit floats.a * b + crounded once to f16, round to nearest even, denormals kept. That is the value the round-to-odd f32 sum produces.This PR is one commit on top of #5319.
Tested
Windows 11 Pro 26300, RTX 2080 Ti (NVIDIA 610.74), MinGW-w64 GCC 15.2.0 (WinLibs r7). Configured like the Linux CI job (
-G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON -DANYPS5_ENABLE_SPIRV_TOOLS=ON), so spirv-val checks every module, at28cebd82bon #5319 (main0214069e3).agc_driver_packed_float16_native(perf(shader): compute v_pk_add_f16 and v_pk_mul_f16 with native f16 math #3531's test, extended). Each FLOAT_MODE compiles the test kernel three ways:OpFmaKHRwhen it hasFMAKHR;FMAKHR, which is perf(shader): compute v_pk_add_f16 and v_pk_mul_f16 with native f16 math #3531's path;Float16, the f32 path.Both native builds must give the f32 path's bits for all 8 instructions. Four of them are fma:
v_pk_fma_f16with op_sel/neg modifiers and with clamp, andv_pk_fmac_f16. The inputs are random halves weighted toward zero, denormals, infinities, NaNs and values near overflow. The test also checks thatOpFmaKHRis emitted exactly when the capability is present. Here:packed f16 native tests passed (589824 halves, fused f16 fma).Hardware oracle:
agc_driver_float16_fma_rounding, which checks against values measured on hardware, passes on theOpFmaKHRpath.The tests catch a double-rounded fma. With the emitter changed to
OpFmaKHR(round(a * b), 1.0, c), three tests fail:agc_driver_float16_fma_rounding:v_pk_fma_f16 ... is 0xf430, expected 0xf431;agc_driver_packed_alu;agc_driver_packed_float16_native.The six tests from the review (
agc_driver_packed_float16_native,agc_driver_float16_fma_rounding,agc_driver_packed_alu,agc_driver_dx10_clamp,agc_driver_dpp8_pk_fmac,agc_driver_dpp16_operands) pass on theOpFmaKHRpath with SPIRV-Tools enabled.Full suite:
ctest --timeout 120 --parallel 12 -E '^agc_driver_bda_device$': 1102 tests passed, 0 failed, 8 skipped.check_skips.py --job windowsflags one of them,guest_video_out_high_frame_rate(current display does not provide 120 Hz), a property of this monitor.agc_driver_bda_devicewas not run. On this machine an earlier run on an older base lost the device, which also resets the display.Repo checks:
check_test_registration.py,check_conventions.pyandgit diff --checkpass.Not tested: Linux, and devices without
VK_KHR_shader_fmaother than by removing the capability from the target, which the test does.Performance
Palworld (PPSA23126) title screen, idle, RTX 2080 Ti,
APS5_PROFILE_GPU, shader cache off. Four runs alternated with and without theFMAKHRcapability (a local switch, not in this PR), three 10 s windows each:OpFmaKHR(run 1 / run 2)0x1bc1…0x1a01…0x1bc1…takes about 2 ms (21%) less per frame in both pairs.0x1a01…shows no consistent change. In both shaders, most of what is left per packed instruction is the NaN rule on the result bits, as in perf(shader): compute v_pk_add_f16 and v_pk_mul_f16 with native f16 math #3531 (see Proposal: evaluate the packed f16 special-value rules only on lanes that can need them #4042).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