skia2/resources/sksl/shared/VectorToMatrixCast.sksl
John Stiles d361690358 Fix diagonal-matrix assertion discovered by fuzzer.
This was another place where we needed to use
`getConstantSubexpression` to rebuild vectors/matrices; it is a more
robust approach than trying handle each ctor type individually. The
fuzzer found an edge case with double-casting matrices to vectors that
fell through the cracks with the original approach.

In adding additional tests, I also found a case that the constant-folder
seems to ignore, `bool4(x,x,x,x) == bool4(x)`. This does fold for ints
and floats, so this ought to be fixable in a followup, but it's not a
big deal either way; this is very unlikely to occer in real code.

Change-Id: I4d577c87ef7049306685ca95250ecdf93b1dbc06
Bug: oss-fuzz:37464
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/441238
Commit-Queue: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2021-08-23 17:33:42 +00:00

37 lines
1.8 KiB
Plaintext

uniform half4 colorGreen, colorRed;
uniform half4 testInputs;
half4 main(float2 coords) {
bool ok = true;
const half4 vec1234 = half4(1, 2, 3, 4);
ok = ok && half2x2(testInputs) == half2x2(-1.25, 0, 0.75, 2.25);
ok = ok && half2x2(half4(1, 2, 3, 4)) == half2x2(1, 2, 3, 4);
ok = ok && half2x2(vec1234) == half2x2(1, 2, 3, 4);
ok = ok && half2x2(half4(2, 0, 0, 2)) == half2x2(2);
ok = ok && half2x2(half4(2)) == half2x2(2, 2, 2, 2);
ok = ok && float2x2(testInputs) == float2x2(-1.25, 0, 0.75, 2.25);
ok = ok && float2x2(half4(1, 2, 3, 4)) == float2x2(1, 2, 3, 4);
ok = ok && float2x2(vec1234) == float2x2(1, 2, 3, 4);
ok = ok && float2x2(half4(4, 0, 0, 4)) == float2x2(4);
ok = ok && float2x2(half4(4)) == float2x2(4, 4, 4, 4);
ok = ok && half2x2(colorGreen) == half2x2(0, 1, 0, 1);
ok = ok && half2x2(colorGreen) == half2x2(int4(0, 1, 0, 1));
ok = ok && half2x2(int4(colorGreen)) == half2x2(int4(0, 1, 0, 1));
ok = ok && half2x2(0, 1, 0, 1) == half2x2(int4(0, 1, 0, 1));
ok = ok && half2x2(8, 8, 8, 8) == half2x2(int4(8));
ok = ok && half2x2(8) == half2x2(int4(8, 0, 0, 8));
ok = ok && half2x2(colorGreen) == half2x2(false, true, false, true);
ok = ok && half2x2(colorGreen) == half2x2(bool4(false, true, false, true));
ok = ok && half2x2(bool4(colorGreen)) == half2x2(bool4(false, true, false, true));
ok = ok && half2x2(false, true, false, true) == half2x2(bool4(false, true, false, true));
ok = ok && half2x2(true, false, false, true) == half2x2(bool4(true, false, false, true));
ok = ok && half2x2(true, true, true, true) == half2x2(bool4(true));
return ok ? colorGreen : colorRed;
}