skia2/resources/sksl/intrinsics/MatrixCompMult.sksl
John Stiles 598c5e5b07 Implement compile-time optimization for matrixCompMult().
$mat matrixCompMult($mat x, $mat y);
$hmat matrixCompMult($hmat x, $hmat y);

This required some minor changes to `evaluate_n_way_intrinsic_of_type`
to allow the inputs to be matrices instead of vectors. Fortunately, most
of the moving parts were already generic/flexible enough that this just
worked, but some explicit checks for `x.isVector` needed to become
`!x.isScalar()`, and `columns` needed to become `slotCount`.

Change-Id: I1e22ecad37a7e187a7171e1f590a720f07cf9832
Bug: skia:12034
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/414436
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2021-06-01 19:35:23 +00:00

20 lines
1.0 KiB
Plaintext

uniform half4 colorGreen, colorRed;
half3x3 a, b;
float4x4 c, d;
void main() {
half2x2 h22 = matrixCompMult(half2x2(5, 5, 5, 5), half2x2(0, 1, 2, 3));
half4x4 h44 = matrixCompMult(half4x4(0.5), half4x4(1, 2, 3, 4,
5, 6, 7, 8,
9, 10,11,12,
13,14,15,16));
float4x3 f43 = matrixCompMult(float4x3(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12),
float4x3(12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1));
sk_FragColor.xyz = matrixCompMult(a, b)[0];
sk_FragColor = half4(matrixCompMult(c, d)[0]);
sk_FragColor = (h22 == half2x2(0, 5, 10, 15) &&
h44 == half4x4(0.5, 0, 0, 0, 0, 3, 0, 0, 0, 0, 5.5, 0, 0, 0, 0, 8) &&
f43 == float4x3(12, 22, 30, 36, 40, 42, 42, 40, 36, 30, 22, 12)) ? colorGreen
: colorRed;
}