skia2/tests/sksl/folding/MatrixFoldingES2.glsl
John Stiles e6b951247b Add matrix-op-matrix tests to MatrixFoldingES2.
In a followup CL, these will be updated to properly fold.

Change-Id: I20d125c0d54cbbcf12f7d096beda1fdf75e51b65
Bug: skia:12819
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/498617
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2022-01-25 17:52:27 +00:00

84 lines
5.3 KiB
GLSL

out vec4 sk_FragColor;
uniform mat2 testMatrix2x2;
uniform vec4 colorRed;
uniform vec4 colorGreen;
uniform float unknownInput;
bool test_matrix_op_scalar_float_b() {
bool ok = true;
ok = ok && mat3(2.0) + 4.0 == mat3(6.0, 4.0, 4.0, 4.0, 6.0, 4.0, 4.0, 4.0, 6.0);
ok = ok && mat3(2.0) - 4.0 == mat3(-2.0, -4.0, -4.0, -4.0, -2.0, -4.0, -4.0, -4.0, -2.0);
ok = ok && mat3(2.0) * 4.0 == mat3(8.0);
ok = ok && mat3(2.0) / 4.0 == mat3(0.5);
ok = ok && 4.0 + mat3(2.0) == mat3(6.0, 4.0, 4.0, 4.0, 6.0, 4.0, 4.0, 4.0, 6.0);
ok = ok && 4.0 - mat3(2.0) == mat3(2.0, 4.0, 4.0, 4.0, 2.0, 4.0, 4.0, 4.0, 2.0);
ok = ok && 4.0 * mat3(2.0) == mat3(8.0);
ok = ok && 4.0 / mat2(2.0, 2.0, 2.0, 2.0) == mat2(2.0, 2.0, 2.0, 2.0);
return ok;
}
bool test_matrix_op_scalar_half_b() {
bool ok = true;
ok = ok && mat3(2.0) + 4.0 == mat3(6.0, 4.0, 4.0, 4.0, 6.0, 4.0, 4.0, 4.0, 6.0);
ok = ok && mat3(2.0) - 4.0 == mat3(-2.0, -4.0, -4.0, -4.0, -2.0, -4.0, -4.0, -4.0, -2.0);
ok = ok && mat3(2.0) * 4.0 == mat3(8.0);
ok = ok && mat3(2.0) / 4.0 == mat3(0.5);
ok = ok && 4.0 + mat3(2.0) == mat3(6.0, 4.0, 4.0, 4.0, 6.0, 4.0, 4.0, 4.0, 6.0);
ok = ok && 4.0 - mat3(2.0) == mat3(2.0, 4.0, 4.0, 4.0, 2.0, 4.0, 4.0, 4.0, 2.0);
ok = ok && 4.0 * mat3(2.0) == mat3(8.0);
ok = ok && 4.0 / mat2(2.0, 2.0, 2.0, 2.0) == mat2(2.0, 2.0, 2.0, 2.0);
return ok;
}
bool test_matrix_op_matrix_float_b() {
bool ok = true;
const mat3 splat_4 = mat3(4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0);
ok = ok && mat3(2.0) + splat_4 == mat3(6.0, 4.0, 4.0, 4.0, 6.0, 4.0, 4.0, 4.0, 6.0);
ok = ok && mat3(2.0) - splat_4 == mat3(-2.0, -4.0, -4.0, -4.0, -2.0, -4.0, -4.0, -4.0, -2.0);
ok = ok && mat3(2.0) / splat_4 == mat3(0.5);
ok = ok && splat_4 + mat3(2.0) == mat3(6.0, 4.0, 4.0, 4.0, 6.0, 4.0, 4.0, 4.0, 6.0);
ok = ok && splat_4 - mat3(2.0) == mat3(2.0, 4.0, 4.0, 4.0, 2.0, 4.0, 4.0, 4.0, 2.0);
ok = ok && mat2(4.0, 4.0, 4.0, 4.0) / mat2(2.0, 2.0, 2.0, 2.0) == mat2(2.0, 2.0, 2.0, 2.0);
ok = ok && mat4(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0) + mat4(16.0, 15.0, 14.0, 13.0, 12.0, 11.0, 10.0, 9.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0) == mat4(17.0, 17.0, 17.0, 17.0, 17.0, 17.0, 17.0, 17.0, 17.0, 17.0, 17.0, 17.0, 17.0, 17.0, 17.0, 17.0);
ok = ok && mat2(10.0, 20.0, 30.0, 40.0) - mat2(1.0, 2.0, 3.0, 4.0) == mat2(9.0, 18.0, 27.0, 36.0);
ok = ok && mat2(10.0, 20.0, 30.0, 40.0) / mat2(5.0, 4.0, 30.0, 1.0) == mat2(2.0, 5.0, 1.0, 40.0);
ok = ok && mat2(1.0, 2.0, 7.0, 4.0) * mat2(3.0, 5.0, 3.0, 2.0) == mat2(38.0, 26.0, 17.0, 14.0);
ok = ok && mat3(10.0, 4.0, 2.0, 20.0, 5.0, 3.0, 10.0, 6.0, 5.0) * mat3(3.0, 3.0, 4.0, 2.0, 3.0, 4.0, 4.0, 9.0, 2.0) == mat3(130.0, 51.0, 35.0, 120.0, 47.0, 33.0, 240.0, 73.0, 45.0);
return ok;
}
bool test_matrix_op_matrix_half_b() {
bool ok = true;
const mat3 splat_4 = mat3(4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0, 4.0);
ok = ok && mat3(2.0) + splat_4 == mat3(6.0, 4.0, 4.0, 4.0, 6.0, 4.0, 4.0, 4.0, 6.0);
ok = ok && mat3(2.0) - splat_4 == mat3(-2.0, -4.0, -4.0, -4.0, -2.0, -4.0, -4.0, -4.0, -2.0);
ok = ok && mat3(2.0) / splat_4 == mat3(0.5);
ok = ok && splat_4 + mat3(2.0) == mat3(6.0, 4.0, 4.0, 4.0, 6.0, 4.0, 4.0, 4.0, 6.0);
ok = ok && splat_4 - mat3(2.0) == mat3(2.0, 4.0, 4.0, 4.0, 2.0, 4.0, 4.0, 4.0, 2.0);
ok = ok && mat2(4.0, 4.0, 4.0, 4.0) / mat2(2.0, 2.0, 2.0, 2.0) == mat2(2.0, 2.0, 2.0, 2.0);
ok = ok && mat4(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0) + mat4(16.0, 15.0, 14.0, 13.0, 12.0, 11.0, 10.0, 9.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0) == mat4(17.0, 17.0, 17.0, 17.0, 17.0, 17.0, 17.0, 17.0, 17.0, 17.0, 17.0, 17.0, 17.0, 17.0, 17.0, 17.0);
ok = ok && mat2(10.0, 20.0, 30.0, 40.0) - mat2(1.0, 2.0, 3.0, 4.0) == mat2(9.0, 18.0, 27.0, 36.0);
ok = ok && mat2(10.0, 20.0, 30.0, 40.0) / mat2(5.0, 4.0, 30.0, 1.0) == mat2(2.0, 5.0, 1.0, 40.0);
ok = ok && mat2(1.0, 2.0, 7.0, 4.0) * mat2(3.0, 5.0, 3.0, 2.0) == mat2(38.0, 26.0, 17.0, 14.0);
ok = ok && mat3(10.0, 4.0, 2.0, 20.0, 5.0, 3.0, 10.0, 6.0, 5.0) * mat3(3.0, 3.0, 4.0, 2.0, 3.0, 4.0, 4.0, 9.0, 2.0) == mat3(130.0, 51.0, 35.0, 120.0, 47.0, 33.0, 240.0, 73.0, 45.0);
return ok;
}
vec4 main() {
bool _0_ok = true;
_0_ok = _0_ok && mat3(unknownInput) == mat3(mat2(1.0));
_0_ok = _0_ok && mat3(9.0, 0.0, 0.0, 0.0, 9.0, 0.0, 0.0, 0.0, unknownInput) == mat3(mat2(9.0));
_0_ok = _0_ok && vec4(testMatrix2x2) == vec4(1.0, 2.0, 3.0, 4.0);
{
float _3_five = 5.0;
_0_ok = _0_ok && mat3(1.0, 2.0, 3.0, 4.0, _3_five, 6.0, 7.0, 8.0, 9.0)[1] == vec3(4.0, _3_five, 6.0);
}
{
float _4_num = 6.0;
_0_ok = _0_ok && mat3(1.0, 2.0, 3.0, 4.0, 5.0, _4_num++, 7.0, 8.0, 9.0)[0] == vec3(1.0, 2.0, 3.0);
_0_ok = _0_ok && mat3(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, _4_num++, 8.0, 9.0)[1] == vec3(4.0, 5.0, 6.0);
_0_ok = _0_ok && mat3(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, _4_num++, 9.0)[2] == vec3(7.0, 8.0, 9.0);
}
{
_0_ok = _0_ok && mat4(mat3(testMatrix2x2))[0] == vec4(1.0, 2.0, 0.0, 0.0);
_0_ok = _0_ok && mat4(mat3(testMatrix2x2))[1] == vec4(3.0, 4.0, 0.0, 0.0);
}
return (((_0_ok && test_matrix_op_scalar_float_b()) && test_matrix_op_scalar_half_b()) && test_matrix_op_matrix_float_b()) && test_matrix_op_matrix_half_b() ? colorGreen : colorRed;
}