shader: keep fract(NaN) as NaN on NVIDIA and add synthetic GPU VALU tests
Fixes a real-hardware NVIDIA bug in fract() from 36eb0b4 and adds synthetic GFX10 -> DXIL -> GPU/WARP regression tests for the RDNA2 VALU lowerings from #2:
- fract(): select(OGT(r, k), k, r) is folded by NVIDIA's DXIL compiler into FMNMX (minNum), which swallows NaN and turns v_fract_f32(NaN) into 0x3f7fffff (and v_fract_f16(NaN) into 0x3bff). Comparing with pred::OGE against a distinct threshold (1.0 for f32, 1 - 2^-12 for f16) prevents the minNum fold and preserves NaN and +/-inf -> NaN on both NVIDIA hardware and WARP.
- valu_tests.rs: builds minimal synthetic GFX10 compute shaders, lowers them through the full pipeline (ir::build -> resource::track -> io::raise -> structure -> lower), validates with dxil.dll when present, and executes them via Host::dispatch on both hardware GPU and WARP without requiring console dxc. Covers v_fract_f32/f16, v_med3_f32/f16, v_sin/v_cos_f32/f16, and v_bfe_i32/u32 + s_bfe_i32.
Co-authored-by: BlueKaiman <[email protected]>
This commit is contained in:
1 parent
d222b87c08
commit
2e5001cf9d
3 files changed
+686
-6
No files matched your search
@@ -1409,12 +1409,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)
|
||||
}
|
||||
|
||||
@@ -3711,7 +3714,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)
|
||||
@@ -4312,8 +4315,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),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user