fix(shader): preserve f64 denormals when supported by Vulkan #2977
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2977"
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 MarcZX10 on 2026-10-10T19:19:26Z.
What
Fixes #2860. Carry the device's
shaderDenormPreserveFloat64support into shader compilation, emit the SPIR-V 64-bitDenormPreservemode only when the device advertises it, and include the capability in shader cache keys and serialized requests (version 16). The F64 FMA test runs on devices withshaderFloat64; if a device without denorm-preserve support flushes the tested subnormals, it skips that runtime result.DenormPreserve 64is enabled only when Vulkan reportsdenormBehaviorIndependence == VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_ALL. The backend does not yet emit coupled execution modes for32_BIT_ONLYorNONE, so f64 denormal preservation is disabled for those properties. The Vulkan specification requires identical denorm modes for widths that are not independent (reference).A device-independent CTest recompiles the f64 shader with
float64DenormPreserveenabled and disabled and checks for the 64-bitOpExecutionMode DenormPreservein the generated SPIR-V. The existing F64 execution test remains the runtime check on capable hardware.This carries the issue-linked change authored by ThatsLeo; the original commit author is preserved.
Tested
agc_driver_f64_fma_subnormals_testsand dependencies.agc_driver_f64_denorm_preserve_spirvandagc_driver_f64_fma_subnormalscompleted on local llvmpipe.5e00b269merged onto currentmain: on an RTX 5060 Laptop (driver 617.42),agc_driver_f64_fma_subnormalsandagc_driver_f64_denorm_preserve_spirvpassed 3/3 runs each. The device reportsshaderDenormPreserveFloat64 = false; the runtime test now runs and passes without the explicit mode.python3 tools/check_conventions.py --base upstream/mainandgit diff --checkpassed.check_test_registration.pycould not run because Ninja is not installed; CTest configuration discovered and ran the new test.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repositoryImported from boykopovar/AnyPS5. Originally posted by fma-rc on 2026-10-10T22:26:23Z.
Ran 14f96919 on Linux (GCC 16.2.1) on two devices. From
vulkaninfo: the RTX 5080 (NVIDIA 615.78.08) reportsshaderDenormPreserveFloat64 = false, the Radeon 610M on RADV reportstruewithdenormBehaviorIndependence = 32_BIT_ONLY.agc_driver_f64_fma_subnormalsis skipped on the RTX 5080, also withANYPS5_REQUIRE_VULKAN=1, and passes on RADV.agc_shader_memoryandagc_shader_disk_cachepass on both.On RADV all three still pass after I remove the four new lines in
DefineModulethat emitDenormPreserve 64and rebuild, so nothing here goes red if the execution mode is not declared.I did not look at whether declaring it for 64 bits alone is allowed under
32_BIT_ONLY; the device property is not read in this change.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T23:43:49Z.
Review: CHANGES_REQUESTED
Built and ran this merged onto current
main:agc_shader_memory,agc_shader_disk_cacheandagc_driver_f64_fma_subnormalspass on RADV. The plumbing (target field, cache key, serializer v16 with the legacy-version checks) looks right. Two things before merge:SpirvModuleSetup.cpp:150-153(capability +ExecutionModeDenormPreserve 64) and rebuilt: all three tests stay green, as @fma-rc found. RADV preserves f64 denormals anyway and lavapipe/NVIDIA skip, so no device we can run turns red if the mode is missing. Please add a test that recompiles an f64 shader withfloat64DenormPreservetrue and false and scans the SPIR-V forOpExecutionMode ... DenormPreserve 64(like the f16 scan intests/Float16Conversion.cpp:65), so the declaration is pinned on every device.denormBehaviorIndependence. RADV reports32_BIT_ONLY, where 16- and 64-bit float controls must be set identically. A module with f64 but no f16 code now declares 64 without 16, and a module that also uses the native f16 path declares both. Please check this against the spec/validation layer (run the f64 test on RADV with the validation layer on) and, if it matters, gate the flag on the property or declare both widths together, and say which in the description.Once the SPIR-V test is in and the independence question is answered, this looks good to merge.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T01:33:03Z.
Thanks for raising both points. The Vulkan execution-environment rule confirms that
32_BIT_ONLYrequires the 16-bit and 64-bit denorm execution modes to match;NONErequires all widths to match. The current backend does not emit the coupled modes, so I gatedfloat64DenormPreserveonshaderDenormPreserveFloat64anddenormBehaviorIndependence == VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_ALL. Devices reporting other independence values no longer receive a potentially invalid 64-bit mode. The limitation is recorded inTechnicalDebt.mdand the PR description.I also added
agc_driver_f64_denorm_preserve_spirv, which recompiles the f64 shader with the target flag both ways and scans forOpExecutionMode DenormPreserve 64. It passes on Linux GCC 12.2 Release. The existing runtime test skipped on this machine because llvmpipe does not expose the required capability, so I do not have a corrected-head RADV validation-layer result.Pushed the update in
0000e4c20(fix(shader): respect float control independence). The conventions and diff checks pass; the repository's test-registration script could not run because this environment lacks Ninja, but CTest registered and ran the new case.Imported from boykopovar/AnyPS5. Originally posted by Silverash-i8 on 2026-10-11T01:51:04Z.
Windows run, since the PR has no Windows results: Windows 11, WinLibs GCC 15.2.0 r7, Release, head merged onto
maind31b57a4, RTX 5060 Laptop (driver 617.42) and the Arrow Lake iGPU.agc_shader_memoryandagc_shader_disk_cachepass on both GPUs.agc_driver_f64_fma_subnormalsfailed onmain(the device has noshaderFloat64) and now skips, so that one is fixed here.maind31b57a4and now skips with "the device has no shaderDenormPreserveFloat64". This driver reportsshaderDenormPreserveFloat64 = false(vulkaninfo), yet the v_fma_f64 subnormal results come out right without the execution mode. So on NVIDIA here the skip turns a passing check into no check.Maybe the skip could key on the result instead of the property (run it, and skip only when the device lacks
shaderFloat64), or keep running where the property is false and treat a flush as the skip case. #2860 (ThatsLeo'sfix/shader-f64-denorm-preserve) uses the same property check, so the same applies there.AI-assisted (Claude Code); I ran this on my machine.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T03:14:55Z.
Thanks for testing this on both NVIDIA and Intel and for showing that the RTX 5060 passes the f64 subnormal cases without the explicit mode. I updated the runtime test accordingly: it now runs on any device with
shaderFloat64, including whenshaderDenormPreserveFloat64is false. Matching results pass; if such a device flushes subnormals, the test reports a skip; a device advertising preserve support must still pass. On the rebased head5e00b269c, Linux Release build,agc_driver_f64_fma_subnormals, andagc_driver_f64_denorm_preserve_spirvall passed on local llvmpipe. The Windows NVIDIA run predates this adjustment, so I have not claimed corrected-head GPU validation.Imported from boykopovar/AnyPS5. Originally posted by Silverash-i8 on 2026-10-11T03:18:42Z.
@MarcZX100 checked the new head
5e00b269on the RTX 5060 (driver 617.42, which reportsshaderDenormPreserveFloat64 = false): Windows 11, WinLibs GCC 15.2.0 r7, Release, merged onto currentmain.agc_driver_f64_fma_subnormalsnow runs and passes ("v_fma_f64 subnormal tests passed") instead of skipping, andagc_driver_f64_denorm_preserve_spirvpasses, 3/3 runs each.I didn't rerun the Arrow Lake iGPU this time: its driver is in a bad state after a run of GPU watchdog resets earlier tonight (see #2832), so results from it aren't trustworthy until I reset it. It has no
shaderFloat64, so it should still skip there; I'll confirm after the reset.AI-assisted (Claude Code); I ran this on my machine.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T03:20:12Z.
Thanks for validating the corrected head on the RTX 5060. That confirms the test now executes and passes when
shaderDenormPreserveFloat64is false, while the SPIR-V mode test also passes. I updated the Tested section with your Windows 3/3 results; the Arrow Lake run can be added once its driver is stable again.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T04:13:01Z.
I updated the PR description with the corrected-head RTX 5060 results and the exact remaining validation gap. The implementation gates the 64-bit mode on
VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_ALL; the SPIR-V test pins the mode, and the corrected runtime test runs onshaderFloat64devices even whenshaderDenormPreserveFloat64is false. The Windows RTX 5060 run passes both tests 3/3. I could not perform the specifically requested RADV + Khronos validation-layer run in this environment: neither the validation layer nor a Vulkan device node is available here, so I have not claimed that result.Imported from boykopovar/AnyPS5. Originally posted by fma-rc on 2026-10-11T05:04:36Z.
Ran the RADV plus validation layer check on head
5e00b269(it sits onmain961b25fe): Linux, GCC 16.2.1, Radeon 610M on RADV (gfx1036), which reportsshaderDenormPreserveFloat64 = truewithdenormBehaviorIndependence = 32_BIT_ONLY.VK_LAYER_KHRONOS_validation1.4.363 was loaded throughVK_INSTANCE_LAYERS; the loader log shows it inserted and the RADV device selected.All ten f64 tests pass, including
agc_driver_f64_fma_subnormalsandagc_driver_f64_denorm_preserve_spirv, and the layer prints no message. Without the layer the result is the same.As a control I removed the
denormBehaviorIndependence == VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_ALLclause from the gate inVulkanDevice.cpp, so that onlyshaderDenormPreserveFloat64decides on this device, and reran with the layer: the same ten pass and there is still no validation message. So the layer does not separate the two here. I have not checked whether this layer version tests the independence rule at all.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T07:15:30Z.
Review: APPROVED
Built and ran this merged onto current
main:agc_shader_memory,agc_shader_disk_cache,agc_driver_f64_fma_subnormalsand the newagc_driver_f64_denorm_preserve_spirvpass (libSceAgc + libSceAgcDriver scope, 375 tests). With theDenormPreserve 64lines inSpirvModuleSetup.cppdisabled, the new SPIR-V test fails, so the declaration is pinned on every device. ThedenormBehaviorIndependence == ALLgate and the runtime test now running on anyshaderFloat64device cover both points from the earlier review; merging.Imported from boykopovar/AnyPS5. Originally posted by Silverash-i8 on 2026-10-11T13:45:24Z.
Confirming what I said I'd check on the Arrow Lake iGPU (Intel driver 101.8991, no
shaderFloat64), now onmaina11c8f7fwith this PR merged: Windows 11, WinLibs GCC 15.2.0 r7, Release,ANYPS5_GPU=Intel, 3 runs each.agc_driver_f64_fma_subnormalsskips ("skipped, the device has no shaderFloat64"), as expected.agc_driver_f64_denorm_preserve_spirvpasses.AI-assisted (Claude Code); I ran this on my machine.