shader: preserve f32 denorms when the guest MODE keeps them #1619
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!1619
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1619"
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?
@Nawid3333 on GitHub · 2026-10-17 19:55 UTC · original
Nawid3333:shader/f32-denorm-preserve→main· +137 −14 · 11 files · 1 commits · openCompute shaders run with the MODE that
COMPUTE_PGM_RSRC1.FLOAT_MODEsets. WithFP_DENORM[5:4] = 3(FLOAT_MODE0xf0) the hardware keeps f32 denormal inputs and results. Kyty already reads bit 4 to decide whether compare inputs are flushed, but it never asks the host to keep denormals, so a host that flushes f32 denormals by default turns them into zero. Both of my GPUs do that (RX 9070 XT with LLPC, and the Ryzen 7600X iGPU with AMD's other compiler): in such a shaderV_MUL_F32of0x00800000and 0.5 gives0instead of0x00400000.Change
shaderDenormPreserveFloat32(part of the float-controls propertiesVulkanCreateDevicealready queries) is passed to the recompiler as aSpirv::Profilefield next tomaintenance8(so it is also part of the shader store header, like the rest of the profile). A compute shader withFP_DENORM[5:4] = 3declaresDenormPreserve 32when the device supports it and the device'sdenormBehaviorIndependenceisn'tNONE(withNONEevery float width would need the same mode, VUID-RuntimeSpirv-denormBehaviorIndependence-06290; DXVK checks the same, f5fa7a90).V_MAD_F32/V_MAC_F32, as the existingVectorMadF32FlushesDenormsexpects, and the results ofV_RCP_F32andV_EXP_F32(ISA: "Denormals are flushed"; theV_RCP_F32input was already flushed, and a denormalV_EXP_F32input already gives 1.0, as in your93071ebd). These flushes are only emitted in shaders that declareDenormPreserve 32, so the 3DMiniGolf/NVIDIA note inEmitFPMad32still holds for every other shader. They go through main'sEmitFlushF32DenormToSignedZero, so withrelaxed_floaton they are left out like main's other flushes. NVIDIA's driver reportsshaderDenormPreserveFloat32 = false(gpuinfo), so on NVIDIA the SPIR-V doesn't change at all.DenormFlushToZero 32for mode 0, but on the RX 9070 XTVectorF64ModesModifiersAndExecthen failed (a negativeV_CVT_F32_F64result that is flushed came back as +0 instead of -0), so I left that out. Compute shaders with FP64 instructions still exit unless FLOAT_MODE is0xc0(the existing guard inspirvEmitterModule.cpp), so0xf0with FP64 stays as on main; it needs its own FP64 denorm handling (the F32/F64 conversions flush today) before that guard can change.Tests
VectorF32DenormsPreservedWhenRequested(FLOAT_MODE0xf0,V_MUL_F32/V_ADD_F32with denormal inputs and results; it also checks that the SPIR-V declaresDenormPreserve 32): fails before the change on both GPUs (all four results are 0) and passes after it. It is skipped where the harness device fails the same check asVulkanCreateDevice.VectorF32TranscendentalsFlushDenorms(FLOAT_MODE0xf0):V_RCP_F32of 2^127 gives 0,V_EXP_F32of -130 gives 0,V_RCP_F32of a denormal gives +inf. It passes; with the two result flushes removed it fails on both GPUs (the RX 9070 XT keeps theV_EXP_F32denormal, the iGPU theV_RCP_F32one), so each driver needs one of them.VectorMadF32FlushesDenormskeeps passing; withDenormPreserve 32declared but without the MAD flushes it fails.VectorMed3F32NanUsesMin3Path(FLOAT_MODE0xf0, already on main) fails on the Ryzen iGPU on main: word 89 is0x00000000instead of the denormal0x80000001. With this change it passes there too.shader_cfg_tests(not run by CI): newTestNewShaderRecompilerF32DenormExecutionModechecks that only FLOAT_MODE0xf0on a device that can preserve f32 denormals getsDenormPreserve 32, and that no other denorm mode is declared; passes.763d3be3(the base of this PR then): the whole compute suite (726 entries) and the 30 graphics cases kept their status apart from the two new tests, and the new cases gave no validation-layer messages.Rebased onto main
a0b083c85(one commit; the earlier merge commits are gone)Spirv::Profilegainedray_query, soSerialize.hnow lists nine Profile fields.shader_cfg_testspasses on both;--relaxed-float-onlypasses on both; the full compute run fails the same two existing cases on both (GpuSelectedFormattedRgba16Store,IndirectImageQueryDimensions) and stops on both at the same 2-sample format 129 this GPU cannot create, before the new cases. Run on their own, the two new cases,VectorMadF32FlushesDenorms,VectorMadF32RoundsProductandRelaxedFloatNativeOpspass; the last three pass on main too.252925a(this PR's head): https://github.com/Nawid3333/KytyPS5/actions/runs/45068182146EmitFPMad32,EmitterStateand tests next to the ones of my #1622, so whichever of the two lands second needs a small rebase; I'll do it.If you'd like this done differently, tell me and I'll change it.
Written with Claude Code (AI): it found this with a test, wrote the change and ran the tests on my PC (Windows 11, AMD drivers 26.8.1 and 26.10.1).
🤖 Generated with Claude Code
@coderabbitai[bot] on GitHub · 2026-10-17 20:02 UTC · original · edited 2026-11-22 20:51 UTC
Walkthrough
The change adds an FP32 denormal-preservation setting to the graphics context and SPIR-V profile. Vulkan device support and compute float mode determine whether the emitter enables preservation. The emitter conditionally flushes values in multiply-add, reciprocal, and exponential operations, and adds the SPIR-V capability and execution mode when enabled. Compute and shader configuration tests cover host support, emitted modes, and operation results.
Suggested reviewers:
nmzikChange: Bug fix
Merge Risk:
Minimal · up to
25292This change preserves FP32 denormals for compute shaders that request it, and only on hosts that support it. Other hosts and modes are unchanged. FP64 compute shaders in this float mode were already unsupported before this PR, so no new merge-blocking risk is introduced.
Pre-merge checks:
4
Full details: Title check
Explanation
The title names the main change: preserving f32 denormals in compute shaders when the guest FLOAT_MODE keeps them. It matches the changeset (denorm_preserve_f32 profile flag, DenormPreserve 32 execution mode, and flush handling for MAD, RCP, and EXP), and it is concise and specific.
Full details: Description check
Explanation
The description explains the problem (FLOAT_MODE 0xf0 with FP_DENORM[5:4] = 3 and host flushing of f32 denormals), the device capability plumbing through Spirv::Profile, the SPIR-V DenormPreserve 32 declaration, the retained flushes for MAD, RCP, and EXP, and the tests added and run. It directly describes the changed files.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Share
@NeySlim on GitHub · 2026-10-17 23:09 UTC · original
RADV data point: Radeon 8060S (RDNA 3.5), Mesa 26.2.4, against
763d3be3. RADV reportsshaderDenormPreserveFloat32 = truewithSHADER_FLOAT_CONTROLS_INDEPENDENCE_32_BIT_ONLY, so the new tests run and are not skipped. Without theDenormPreserve 32execution mode,VectorF32DenormsPreservedWhenRequestedgets 0 for all four results; with the PR both new tests pass and the rest of the suite is unchanged.@coderabbitai[bot] on GitHub · 2026-10-28 20:39 UTC · original · reviewed
b05ba456-034d-407d-bd02-191a39db4a67Reviewing files that changed from the base of the PR and between c39c769233d247aa93b346e12580679d748f7820 and 8fe0ac70cf52be99b76a5d3c679837531c148e09.
src/graphics/host_gpu/graphicContext.hsrc/graphics/host_gpu/renderer/pipeline/pipelineCache.cppsrc/graphics/presentation/window/vulkanWindow.cppsrc/graphics/shader/recompiler/backend/spirv/SpirvEmitter.cppsrc/graphics/shader/recompiler/backend/spirv/SpirvEmitter.hsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterAlu.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterInternal.hsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterModule.cppsrc/graphics/shader/recompiler/ir/Serialize.htests/ShaderRecompilerComputeTests.cpptests/shaderCfgTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.
@coderabbitai[bot] on GitHub · 2026-11-22 20:51 UTC · original · reviewed
c9be52b1-efd1-4732-ab73-52bb5b18d94cReviewing files that changed from the base of the PR and between 15f97f1e397ebb84036e98c84812bb5a71d9f23b and
252925add5.src/graphics/host_gpu/graphicContext.hsrc/graphics/host_gpu/renderer/pipeline/pipelineCache.cppsrc/graphics/presentation/window/vulkanWindow.cppsrc/graphics/shader/recompiler/backend/spirv/SpirvEmitter.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterInternal.hsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterModule.cppsrc/graphics/shader/recompiler/ir/Serialize.htests/ShaderRecompilerComputeTests.cpptests/shaderCfgTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
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.