Merge pull request #37 from alessiodeia/fix/valu-med3-fract-trig

shader: keep fract(NaN) as NaN on NVIDIA and add synthetic GPU VALU tests
This commit is contained in:
Marvis authored and GitHub committed 2026-11-24 01:38:41 +01:00
commit 64c51313af
3 files changed
+686 -6

No files matched your search

+9 -6
View File
@@ -1421,12 +1421,15 @@ impl<'a> Lower<'a> {
/// `a - floor(a)`, which on the hardware never reaches 1.0: where it
/// would round to it (a tiny negative `a`), the result is `below_one`,
/// the largest value under 1.0 in the operation's width. Hosts differ
/// here (some give 1.0). NaN stays NaN.
fn fract(&mut self, a: V, below_one: f32) -> V {
/// here (some give 1.0). Comparing against a `threshold` distinct from
/// `below_one` prevents drivers (observed on NVIDIA) from folding
/// `r > k ? k : r` into `minNum` (`FMNMX`) and swallowing NaN.
fn fract(&mut self, a: V, threshold: f32, below_one: f32) -> V {
let c = self.cur;
let r = self.unary(22, a);
let limit = self.s.m.f32(threshold.to_bits());
let k = self.s.m.f32(below_one.to_bits());
let over = self.s.m.cmp(c, pred::OGT, r, k);
let over = self.s.m.cmp(c, pred::OGE, r, limit);
self.s.m.select(c, over, k, r)
}
@@ -3757,7 +3760,7 @@ impl<'a> Lower<'a> {
};
let r = match op {
12 | 13 => self.trig_turns(a, op == 12),
22 => self.fract(a, f32::from_bits(0x3F7F_FFFF)),
22 => self.fract(a, 1.0, f32::from_bits(0x3F7F_FFFF)),
_ => self.unary(op, a),
};
float(self, r)
@@ -4339,8 +4342,8 @@ impl<'a> Lower<'a> {
};
match op {
12 | 13 => self.trig_turns(a, op == 12),
// 0x3bff as a half: 1 - 2^-11.
22 => self.fract(a, 1.0 - 1.0 / 2048.0),
// Any f16 in (-2^-11, 0) has fract >= 1 - 2^-12; clamp to 0x3bff (1 - 2^-11).
22 => self.fract(a, 1.0 - 1.0 / 4096.0, 1.0 - 1.0 / 2048.0),
_ => self.unary(op, a),
}
}