shader: keep V_FRACT results below 1.0 #1212
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!1212
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1212/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-08 13:58 UTC · original
Nawid3333:shader/fract-below-one→main· +70 −7 · 6 files · 2 commits · closed without mergingThis is the change proposed in #1209. If the edge values you captured on hardware say otherwise, tell me and
I'll change it or close it.
Problem
RDNA2's
V_FRACT_F16/F32/F64follow the DX definition of fract (ISA guide 12.8), which returns a value in[+0, 1) for every finite input. Kyty emits
GLSLstd450Fract, i.e.x - floor(x), which rounds to 1.0 fortiny negative inputs: every input in [-2^-54, 0) in double precision, in [-2^-25, 0) in single precision, and
every half in [-2^-12, 0).
On the AMD driver I tested, the result is already the largest value below 1.0 (consistent with it using the
hardware
v_fract); a driver that computesx - floor(x)returns 1.0. Onmain,VectorFractF64CapturedAndEdgesandVectorFractF16CapturedAndEdgesexpect 1.0 at those edges (details in#1209).
Fix
V_FRACT_*now clamps the fract result to the largest value below 1.0 in the instruction's precision, with anordered
>=compare and a select, so NaN results stay NaN. The f16 form is computed in f32 and rounded tohalf later, so its clamp value is the f32 value of the half
0x3bff(0x3f7fe000), which keeps the roundingfrom reaching 1.0. A new
SelectF64IR operation (OpSelect) handles the double case. Sources, output modifiers and the f16 write gothrough the same
ReadOperand/WriteOperand/ReadF16AsF32/WriteF16calls as before.The two tests now expect
0x3feffffffffffffffor -2^-1074 and0x3bfffor the halves0x8001,0x83ffand
0x8c00. The f64 test also counts the clamp in the IR (SelectF64perV_FRACT_F64), because on theAMD driver I tested the readback is already the clamped value. The f16 readback catches a missing clamp on
drivers whose half packing rounds to nearest (and on AMD once #1204 is in). A new
VectorFractF32Edges(runby
--fract-f16-only) checks -2^-24, -2^-25 and -2^-26, which must all give0x3f7fffff(x - floor(x)gives1.0 for the last two), and counts
SelectF32in the IR for the same reason as the f64 test.Testing
Windows 11, clang-cl 19.1.5, Release, AMD RX 9070 XT, this branch on
mainaa3b2cd5:--cmp-eq-f64-onlyand--fract-f16-onlyfail onmainand pass with this change. With the five changedsource files reset to
main(tests kept),--cmp-eq-f64-onlyfails again at the IR count(
SelectF64 count=0, expected=18), and--fract-f16-onlyatVectorFractF32Edges(
SelectF32 count=0, expected=5).--*-onlymodes againstmain(first commit, on4865dd92): 93/110 pass instead of 91/110; onlythese two change.
shader_cfgpasses.Not tested on NVIDIA or Intel, where the readback values themselves change from 1.0 to the clamped values.
AI use (per the README's AI policy): Claude (Anthropic) wrote the change and the test updates and ran the
tests above on my machine.
🤖 Generated with Claude Code
@coderabbitai[bot] on GitHub · 2026-10-08 14:08 UTC · original · edited 2026-10-08 14:47 UTC
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
6e382e8b-9aae-4750-959b-a516844215b9📥 Commits
Reviewing files that changed from the base of the PR and between 796da6f7834bca301b4d1d62e85228394f79cb94 and
ce48db78a3.📒 Files selected for processing (2)
src/graphics/shader/recompiler/frontend/translate/Translator.htests/ShaderRecompilerComputeTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.
📝 Walkthrough
Walkthrough
The change adds
FloatFracttranslation for F16, F32, and F64 vector instructions. It applies precision-specific caps to fractional results and usesSelectF64for F64 selection. The change also adds the corresponding SPIR-V emitter alias and updates compute test expectations.Suggested reviewers:
nmzikPriority: ➖ Normal
Change: Bug fix
Merge Risk: ⚪ Minimal · up to
ce48dThe reviewed changes preserve the precision-specific fract behavior, and the apparent resource-tracking gap cannot be reached by supported resource or SRT expressions. No merge-blocking risk remains.
🚥 Pre-merge checks | ✅ 4 | ❓ 1
❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
Full details: Docstring Coverage
Explanation
Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 4 files. (1 skipped: 1 too large.)
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.@coderabbitai[bot] on GitHub · 2026-10-08 14:08 UTC · original · reviewed
🧹 Nitpick comments (1)
ℹ️ Review info
⚙️ Run configuration
b9f024c6-8b98-4935-992a-b4fd16dc6667📥 Commits
Reviewing files that changed from the base of the PR and between
aa3b2cd57fand 796da6f7834bca301b4d1d62e85228394f79cb94.📒 Files selected for processing (6)
src/graphics/shader/recompiler/backend/spirv/spirvEmitterInstructions.hsrc/graphics/shader/recompiler/frontend/translate/Float.cppsrc/graphics/shader/recompiler/frontend/translate/Translator.hsrc/graphics/shader/recompiler/frontend/translate/Vector.cppsrc/graphics/shader/recompiler/ir/opcodes/ValueOpcodes.inctests/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.
Pull request closed