skia2/tests/sksl/folding/MatrixFoldingES2.glsl
John Stiles 0f5bc280a0 Implement constant folding for componentwise matrix-matrix ops.
Now, constant mat+mat, mat-mat, and mat/mat operations can be optimized
away. mat*mat does not operate componentwise and will need to be
handled differently.

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

48 lines
2.1 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;
return ok;
}
bool test_matrix_op_scalar_half_b() {
bool ok = true;
return ok;
}
bool test_matrix_op_matrix_float_b() {
bool ok = true;
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;
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;
}