shader: emit float min/max as host instructions on AMD GPUs #1761
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!1761
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1761/head"
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?
@Arda501 on GitHub · 2026-10-20 13:42 UTC · original
Arda501:pr/native-float-minmax→main· +141 −23 · 11 files · 6 commits · merged 2026-10-21 19:36 UTCGame and problem
SAROS (PPSA07631, v01.00), Linux (CachyOS), RX 9070 XT, Mesa RADV. The game is GPU-bound in compute shaders; the two heaviest (
0x0c9a138927bbc375, about 3.1 ms per frame, and0x0a5a927c752c1ed7, about 2.2 ms) spend much of their time in float min/max emulation.Cause
V_MIN_F32,V_MAX_F32,V_MIN3_F32andV_MAX3_F32are emitted as a classify-and-select sequence (NaN and zero tests on both operands, an ordered compare and several selects, about a dozen instructions per operation) so that every host returns the guest's results: a NaN operand yields the other operand, and -0 orders below +0. In the RADV ISA of the first shader,v_cndmask_b32is the most frequent instruction.AMD GPUs execute
GLSL.std.450 NMin/NMax(v_min_f32/v_max_f32under ACO) with those same rules.Change
Spirv::SetNativeFloatMinMaxselects hostNMin/NMaxforEmitMinMaxF32Value, which covers MIN, MAX, MIN3 and MAX3. MED3 keeps its exact emulation.GLSL.std.450only guarantees NaN, infinity and signed-zero results for extended instructions withSPV_KHR_float_controls2;SignedZeroInfNanPreservedoes not apply to them. The native instructions are therefore decoratedFPFastMathMode None, and the module declaresSPV_KHR_float_controls2/FloatControls2.CreateVulkanenablesVK_KHR_shader_float_controls2when available, and uses the native path only when the device vendor is AMD (0x1002) andshaderFloatControls2is supported.KYTY_EMULATED_FLOAT_MIN_MAX=1keeps the emulation. Other devices are unchanged.Testing
VectorMinMaxF32RuntimeEdges(wave 32 and 64): MIN/MAX/MIN3/MAX3 on operands loaded from a buffer, so nothing is constant-folded. Cases: quiet and signaling NaN in either operand, NaN with signed zeros, +/-0 in both orders, +/-infinity. Expected values follow the emulated rules.--float-min-max-onlymode (also registered as theshader_recompiler_float_min_maxCTest) runs that case and the existingVectorMinMaxF32NanAndSignedZeroEdgeswith the emulation and, on AMD with float controls 2, with host instructions; the native runs also check that the module declaresFloatControls2. The test harness enablesVK_KHR_shader_float_controls2when available. All pass on RX 9070 XT / RADV (which exposesshaderFloatControls2).shader_recompiler_compute_testsrun stops atIndirectBufferStoreon Linux/RADV, onmain1a053f9eas well, so it does not show this change either way.0x0c9a138927bbc3753.14 ms -> 1.97 ms,0x0a5a927c752c1ed72.21 ms -> 0.91 ms; compute time per frame 23.1 ms -> 18.7 ms. Screenshots with and without the change look the same.mainf492027b) plus #1760, which SAROS needs to reach gameplay on Linux: reaches gameplay and renders the same scene asmain. Not built or tested on Windows.AI use
Claude Code profiled the shaders and wrote the change, i ran the tests and the game runs above. Runs stable at about 16fps on my 9070Xt 7800x3D linux machine with some graphical glitches such as missing textures and shader bugs but it is technicaly playable as far as i have played (about 1h into the game)
🤖 Generated with Claude Code
@coderabbitai[bot] on GitHub · 2026-10-20 13:50 UTC · original · edited 2026-10-21 19:34 UTC
📝 Walkthrough
The SPIR-V recompiler now uses a capability profile for maintenance-8 and native float min/max support. Vulkan initialization stores the physical-device driver ID, and
ProgramCacheenables native min/max for Mesa RADV. The emitter usesNMinandNMaxwhen enabled and retains the existing fallback. Compute tests cover runtime edge cases for wave sizes 32 and 64. CTest registers the targeted test mode.Suggested reviewers:
nmzikPriority: ⚪ Pending latest changes
Change: Feature
Merge Risk: 🟡 Moderate · up to
1aa2fNative float min/max is now the default on AMD RADV, but nothing guarantees it handles NaN and signed zero like the previous implementation. This could cause subtle rendering differences. Gate native emission on the proper float-controls support, or keep emulation, before merging.
Pre-merge checks:
4 ·
1
Full details: Docstring Coverage
Explanation
Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 16 functions across 10 files. (2 skipped: 2 too large.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
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
Comment
@coderabbitai helpto get the list of available commands.@ -116,0 +116,4 @@if (state.profile.native_float_min_max) {const auto result = state.builder.AllocateId();state.builder.AddFunction(spv::OpExtInst, TypeF32(state), result, GlslStd450(state),max_value ? GLSLstd450NMax : GLSLstd450NMin, lhs, rhs);@coderabbitai[bot] on GitHub · 2026-10-20 13:50 UTC · original
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 12985
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 36270
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 41590
🌐 Web query:
official Khronos GLSL.std.450 NMin NMax SignedZeroInfNanPreserve SPV_KHR_float_controls2 semantics💡 Result:
Gate native
NMinandNMaxonSPV_KHR_float_controls2support.GLSL.std.450states thatSignedZeroInfNanPreservedoes not apply to its extended instructions. Special values may be ignored unlessSPV_KHR_float_controls2is used. This module emits onlySPV_KHR_float_controlsand enables native min/max for every AMD vendor-ID match. NaN and signed-zero results can therefore differ from the emulation path. Gate native min/max on the required float-controls2 support, or retain emulation when that support is unavailable.@coderabbitai[bot] on GitHub · 2026-10-20 13:50 UTC · original · reviewed
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
89caa7b4-853e-4475-b518-aa7d6ea3a4d1📥 Commits
Reviewing files that changed from the base of the PR and between
f492027be2and 7306c56e27e1021954d54c61febda8c6f58db6c0.📒 Files selected for processing: 5
CMakeLists.txtsrc/graphics/presentation/window/vulkanWindow.cppsrc/graphics/shader/recompiler/backend/spirv/SpirvEmitter.hsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterAluHelpers.cpptests/ShaderRecompilerComputeTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.
@coderabbitai[bot] on GitHub · 2026-10-21 19:03 UTC · original · edited 2026-10-21 19:25 UTC
On
src/graphics/presentation/window/vulkanWindow.cppline 1038 (outdated):🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Select native min/max after device feature detection.
graphic_ctx.float_controls2_enabledis stillfalsehere.VulkanCreateDevicesets the flag later, at lines 584–585, butCreateVulkandoes not call that function until line 1089. The condition therefore always disables native min/max, including on supported RADV devices. MoveSetNativeFloatMinMaxafter successful device creation so it reads the detected feature value.✅ Addressed in commit 1aa2f47
@coderabbitai[bot] on GitHub · 2026-10-21 19:03 UTC · original · edited 2026-10-21 19:11 UTC
On
tests/ShaderRecompilerComputeTests.cppline 20723 (outdated):🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 5411
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 37444
🌐 Web query:
Vulkan VK_KHR_shader_float_controls2 extension feature shaderFloatControls2 advertised extension feature support official specification💡 Result:
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 19030
🌐 Web query:
site:docs.vulkan.org Vulkan vkCreateDevice VK_ERROR_FEATURE_NOT_PRESENT enabled feature not supported extension advertised feature query💡 Result:
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 1771
Query
shaderFloatControls2before enabling it.The extension does not guarantee that its feature bit is supported. If the extension is advertised but
shaderFloatControls2is false,vkCreateDevicereturnsVK_ERROR_FEATURE_NOT_PRESENT, andRequireVkreports the failure before the float min/max tests run.Set
m_float_controls2only when both the extension and feature bit are supported.Suggested fix
📝 Committable suggestion
✅ Addressed in commit 20bb9c6
@coderabbitai[bot] on GitHub · 2026-10-21 19:03 UTC · original · reviewed
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
22288c15-2be7-4b35-bfd2-d3cc0c50f55b📥 Commits
Reviewing files that changed from the base of the PR and between 7306c56e27e1021954d54c61febda8c6f58db6c0 and 970ebecc7207611e589dcaa1fdb6f1a1e26116e6.
📒 Files selected for processing: 6
CMakeLists.txtsrc/graphics/host_gpu/graphicContext.hsrc/graphics/presentation/window/vulkanWindow.cppsrc/graphics/shader/recompiler/backend/spirv/SpirvEmitter.hsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterAluHelpers.cpptests/ShaderRecompilerComputeTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
@coderabbitai[bot] on GitHub · 2026-10-21 19:17 UTC · original
On
tests/ShaderRecompilerComputeTests.cppline 2010 (outdated):🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 16778
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 28404
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 23624
Gate native execution on the enabled
shaderFloatControls2feature.SupportsNativeFloatMinMax()accepts every RADV device, butVulkanHarness::Initneither queries nor enablesshaderFloatControls2. The selector therefore runs native cases on RADV instead of making them compile-only. Query and enable the feature during device creation, store the enabled state, and require that state inSupportsNativeFloatMinMax().@coderabbitai[bot] on GitHub · 2026-10-21 19:17 UTC · original · reviewed
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
c4265c84-1ffd-438a-a100-d6bbffbb4736📥 Commits
Reviewing files that changed from the base of the PR and between 970ebecc7207611e589dcaa1fdb6f1a1e26116e6 and 20bb9c6a4f461a6fd70490229937b9970e56d19a.
📒 Files selected for processing: 4
src/graphics/presentation/window/vulkanWindow.cppsrc/graphics/shader/recompiler/backend/spirv/SpirvEmitter.hsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterAluHelpers.cpptests/ShaderRecompilerComputeTests.cpp💤 Files with no reviewable changes: 2
🚧 Files skipped from review as they are similar to previous changes: 1
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.
@coderabbitai[bot] on GitHub · 2026-10-21 19:34 UTC · original
On
src/graphics/presentation/window/vulkanWindow.cppline 1016 (outdated):🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 8215
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 3598
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 41829
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 19356
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 16731
Make native
NMin/NMaxconditional on FloatControls2.ProgramCacheselects native emission for every Mesa RADV device based only ondriver_id. The device path does not enableVK_KHR_shader_float_controls2orshaderFloatControls2. The SPIR-V emitter requiresSPV_KHR_float_controls, but it does not declareFloatControls2or applyFPFastMathModetoNMin/NMax.Native special-value behavior is therefore unspecified. Enable the Vulkan feature and emit the required SPIR-V controls before selecting native emission. Otherwise, retain emulation.
@coderabbitai[bot] on GitHub · 2026-10-21 19:34 UTC · original · reviewed
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
414e728f-a8d2-474f-9830-66adb18dcfdf📥 Commits
Reviewing files that changed from the base of the PR and between 72c3f97ecdd6e7fada96d7a14f718ff7b5dc398a and 1aa2f4734be489384937a778b551f6d3017b2580.
📒 Files selected for processing: 12
src/graphics/host_gpu/graphicContext.hsrc/graphics/host_gpu/renderer/pipeline/pipelineCache.cppsrc/graphics/presentation/window/vulkanWindow.cppsrc/graphics/shader/recompiler/ShaderRecompiler.cppsrc/graphics/shader/recompiler/ShaderRecompiler.hsrc/graphics/shader/recompiler/backend/spirv/SpirvEmitter.cppsrc/graphics/shader/recompiler/backend/spirv/SpirvEmitter.hsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterAluHelpers.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterInternal.htests/ShaderRecompilerComputeTests.cpptests/shaderCfgTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 4 remain after this review.