shader: saturate f32-to-int conversions once #1568
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!1568
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1568/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?
@Nawid3333 on GitHub · 2026-10-16 19:06 UTC · original
Nawid3333:shader/f32-to-int-single-saturation→main· +22 −41 · 3 files · 1 commits · closed without mergingAnother one for nmzik's idea in #1534. V_CVT_U32_F32, V_CVT_I32_F32, V_CVT_FLR_I32_F32 and V_CVT_RPI_I32_F32 saturated twice:
ConvertF32ToU32Saturated/ConvertF32ToI32Saturatedclamped the value in IR (NaN test, two compares, trunc, float and integer selects), andEmitF32ToU32clamped it again.Change
ConvertU32F32/ConvertS32F32directly. The 16-bit and byte conversions keep the IR clamp to their own bounds.EmitF32ToU32applies the guest rules (truncate, saturate, NaN -> 0):NClampto the largest in-range float (for i32 after a NaN -> 0 select), soOpConvertFToU/Snever sees an out-of-range value, and one select for inputs >= 2^32 or 2^31.EmitTruncF32Valuealias is removed.Size
Same results
3ff6606fon both GPUs: all compute-suite entries, also with the harness forced to 32-wide subgroups (a local switch), and the 26 graphics cases plus 16 production raster checks give the same status and first mismatch as before;CvtF32ToIntSaturatesNaNAndOutOfRangeandVectorFloatConversionOpspass.NClampis new to Kyty. GLSL.std.450 gives it NMin/NMax semantics, so a NaN input yields the lower bound: that is the guest's NaN -> 0 for the unsigned conversion, while the signed one needs the extra NaN select because its lower bound is -2^31. SPIRV-Cross (MoltenVK) maps it to Metal'sprecise::clamp.#1495 (open) removes the same duplicate from the other side: it skips the backend clamp when the IR already clamped.
If you'd like this done differently, tell me and I'll change it.
Written with Claude Code (AI): it wrote the change and ran the tests and measurements on my PC (driver 26.8.1, Windows 11). I reviewed the diff and this description before opening the PR.
🤖 Generated with Claude Code
@coderabbitai[bot] on GitHub · 2026-10-16 19:10 UTC · original · edited 2026-10-17 00:46 UTC
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
acd39cf3-e96d-4ec1-a055-c472dddf1fcb📥 Commits
Reviewing files that changed from the base of the PR and between
5dec523143andab339f74e4.📒 Files selected for processing: 3
src/graphics/shader/recompiler/backend/spirv/spirvEmitterAlu.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterInternal.hsrc/graphics/shader/recompiler/frontend/translate/Convert.cpp💤 Files with no reviewable changes: 1
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 4 remain after this review.
📝 Walkthrough
The frontend now emits direct float-to-integer conversions for four conversion handlers. The SPIR-V backend clamps float inputs before conversion and applies specified upper-bound results. The signed conversion path maps NaN to zero. The
EmitTruncF32Valuealias was removed.Suggested reviewers:
nmzikPriority: ⬇️ Low
Change: Refactor
Merge Risk: ⚪ Minimal · up to
ab339No actionable issue is established from the supplied changes. The conversion update appears mergeable after normal checks.
Pre-merge checks:
4 ·
1
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.@Nawid3333 on GitHub · 2026-10-24 18:36 UTC · original
Closing:
maincovers this since2d00e13b("rely on the saturating float-to-int conversion instead of re-saturating in the translator") and3bb09ed2("clamp before float-to-int conversion and drop the redundant truncate").Pull request closed