skia2/resources/sksl/intrinsics/IsNan.sksl
John Stiles e43714f490 Add ES3 intrinsics isinf/isnan to public SkSL ES3.
The ES3 spec doesn't mandate that `isnan` actually has to do anything,
so the Isnan test is not enabled. (It doesn't work on my personal
machine unless I make the NaN detectable at compile-time.)

We do not support these functions in constant-expressions, as we
currently avoid optimizing anything into a non-finite value; we leave
expressions alone if we calculate a NaN/inf result for their value.

Change-Id: Ibfdfb47b6e6134165c8780db570de04a916d2bfa
Bug: skia:12022
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/441581
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
2021-08-24 19:23:48 +00:00

19 lines
713 B
Plaintext

uniform half4 testInputs; // equals (-1.25, 0, 0.75, 2.25)
uniform half4 colorGreen, colorRed;
half4 main(float2 coords) {
// NOTE: the ES3 spec does not mandate NaN support. This test may not succeed on some GPUs.
half4 valueIsNaN = 0 / testInputs.yyyy;
half4 valueIsNumber = 1 / testInputs;
return ( (isnan(valueIsNaN.x)) &&
all(isnan(valueIsNaN.xy)) &&
all(isnan(valueIsNaN.xyz)) &&
all(isnan(valueIsNaN.xyzw)) &&
! (isnan(valueIsNumber.x)) &&
!any(isnan(valueIsNumber.xy)) &&
!any(isnan(valueIsNumber.xyz)) &&
!any(isnan(valueIsNumber.xyzw))) ? colorGreen : colorRed;
}