skia2/resources/sksl/shared/MatrixScalarMath.sksl
Julia Lavrova 55c215cfb6 Reland "Better Matrix/Scalar testing"
This reverts commit 455e580b9c.

Reason for revert: Fixing the build break

Original change's description:
> Revert "Better Matrix/Scalar testing"
>
> This reverts commit abb611550e.
>
> Reason for revert: Build break
> Original change's description:
> > Better Matrix/Scalar testing
> >
> > Adding tests for matrix math and comparison
> > bug: skia:12681
> >
> > Change-Id: Ia1537ee2e411383749456fd6ff938b7c9a2e1061
> > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/493416
> > Reviewed-by: John Stiles <johnstiles@google.com>
> > Commit-Queue: Julia Lavrova <jlavrova@google.com>
>
> Change-Id: I70871b4b75c1f10e870dc5e884a42405a80fc0f9
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/494816
> Reviewed-by: John Stiles <johnstiles@google.com>
> Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
> Commit-Queue: Julia Lavrova <jlavrova@google.com>

Change-Id: Idef8dbcd6f5a5bbe84d3fd86888e3eab0f0521ee
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/494817
Reviewed-by: John Stiles <johnstiles@google.com>
Commit-Queue: Julia Lavrova <jlavrova@google.com>
2022-01-14 19:12:00 +00:00

39 lines
1.1 KiB
Plaintext

uniform half4 colorGreen, colorRed;
const int plus = 1;
const int minus = 2;
const int star = 3;
const int slash = 4;
bool test(int op, float m11, float m12, float m21, float m22, float2x2 expected) {
float one = colorRed.r;
float2x2 m2 = float2x2(m11 * one, m12 * one, m21 * one, m22 * one);
switch (op) {
case plus: m2 += 1; break;
case minus: m2 -= 1; break;
case star: m2 *= 2; break;
case slash: m2 /= 2; break;
}
return m2[0][0] == expected[0][0] &&
m2[0][1] == expected[0][1] &&
m2[1][0] == expected[1][0] &&
m2[1][1] == expected[1][1];
}
half4 main(float2 coords) {
float f1 = 1 * colorGreen.g;
float f2 = 2 * colorGreen.g;
float f3 = 3 * colorGreen.g;
float f4 = 4 * colorGreen.g;
return true
&& test(plus, f1, f2, f3, f4, float2x2(f1+1, f2+1, f3+1, f4+1))
&& test(minus, f1, f2, f3, f4, float2x2(f1-1, f2-1, f3-1, f4-1))
&& test(star, f1, f2, f3, f4, float2x2(f1*2, f2*2, f3*2, f4*2))
&& test(slash, f1, f2, f3, f4, float2x2(f1/2, f2/2, f3/2, f4/2))
? colorGreen : colorRed;
}