skia2/tests/sksl/shared/Negation.glsl
John Stiles f89a8122a4 Fix flaws in minus-prefix optimization.
We had a logic bug when attempting to optimize the following code:
    const vecN x = vecN(a, b, c);
    -x;

The goal was to replace `-x` with `vecN(-a, -b, -c)` but we accidentally
tried to cast the `x` VariableReference to a Constructor. We
unfortunately didn't cover this in any of our test cases, but the fuzzer
managed to synthesize it by mixing and matching elements from its new
corpus.

This affected several different constructor types: splat, diagonal-
matrix, compound and array.

Change-Id: I10dd2460ab26ba3e820b0cff5db091368fb7e648
Bug: oss-fuzz:37764, oss-fuzz:37861
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/443407
Commit-Queue: John Stiles <johnstiles@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
2021-08-30 20:40:17 +00:00

24 lines
601 B
GLSL

out vec4 sk_FragColor;
uniform vec4 colorGreen;
uniform vec4 colorRed;
bool test_ivec_b() {
int one = 1;
const int two = 2;
bool ok = true;
ok = ok && -ivec2(-one, one + one) == -ivec2(one - two, 2);
return ok;
}
bool test_mat_b() {
bool ok = true;
return ok;
}
vec4 main() {
const float _0_one = 1.0;
float _1_two = 2.0;
bool _4_ok = true;
_4_ok = _4_ok && -vec4(_1_two) == vec4(-_1_two, vec3(-_1_two));
_4_ok = _4_ok && vec2(1.0, -2.0) == -vec2(_0_one - _1_two, _1_two);
return (_4_ok && test_ivec_b()) && test_mat_b() ? colorGreen : colorRed;
}