skia2/tests/sksl/folding/VectorVectorFolding.glsl
John Stiles 5676c57220 Optimize away self-comparison in the constant folder.
Expressions like `value == value` or `color.a != color.a` can be
replaced by `true` or `false` on sight. The GLSL spec makes it clear
that checking for NaN is optional:

4.7.1 Range and Precision
"... NaNs are not required to be generated. Support for signaling NaNs
is not required and exceptions are never raised. Operations and built-in
functions that operate on a NaN are not required to return a NaN as the
result."

Change-Id: I2ad9f2dc505b638ea2904bef41b7a79a2b329551
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/381262
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2021-03-08 23:38:29 +00:00

39 lines
987 B
GLSL

out vec4 sk_FragColor;
uniform float unknownInput;
uniform vec4 colorRed;
uniform vec4 colorGreen;
bool test_int() {
int unknown = int(unknownInput);
bool ok = true;
ivec4 val = ivec4(unknown);
val += ivec4(1);
val -= ivec4(1);
val = val + ivec4(1);
val = val - ivec4(1);
ok = ok && val == ivec4(unknown);
val *= ivec4(2);
val /= ivec4(2);
val = val * ivec4(2);
val = val / ivec4(2);
ok = ok && val == ivec4(unknown);
return ok;
}
vec4 main() {
float _0_unknown = unknownInput;
bool _1_ok = true;
vec4 _2_val = vec4(_0_unknown);
_2_val += vec4(1.0);
_2_val -= vec4(1.0);
_2_val = _2_val + vec4(1.0);
_2_val = _2_val - vec4(1.0);
_1_ok = _1_ok && _2_val == vec4(_0_unknown);
_2_val *= vec4(2.0);
_2_val /= vec4(2.0);
_2_val = _2_val * vec4(2.0);
_2_val = _2_val / vec4(2.0);
_1_ok = _1_ok && _2_val == vec4(_0_unknown);
return _1_ok && test_int() ? colorGreen : colorRed;
}