xref: /aosp_15_r20/external/skia/tests/sksl/intrinsics/MatrixCompMultES3.metal (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1#include <metal_stdlib>
2#include <simd/simd.h>
3#ifdef __clang__
4#pragma clang diagnostic ignored "-Wall"
5#endif
6using namespace metal;
7struct Uniforms {
8    half4 colorGreen;
9    half4 colorRed;
10};
11struct Inputs {
12};
13struct Outputs {
14    half4 sk_FragColor [[color(0)]];
15};
16
17thread bool operator==(const half2x4 left, const half2x4 right);
18thread bool operator!=(const half2x4 left, const half2x4 right);
19
20thread bool operator==(const half4x2 left, const half4x2 right);
21thread bool operator!=(const half4x2 left, const half4x2 right);
22
23thread bool operator==(const float4x3 left, const float4x3 right);
24thread bool operator!=(const float4x3 left, const float4x3 right);
25
26template <typename T, int C, int R>
27matrix<T, C, R> matrixCompMult(matrix<T, C, R> a, const matrix<T, C, R> b) {
28 for (int c = 0; c < C; ++c) { a[c] *= b[c]; }
29 return a;
30}
31half4x2 half4x2_from_half4_half4(half4 x0, half4 x1) {
32    return half4x2(half2(x0.xy), half2(x0.zw), half2(x1.xy), half2(x1.zw));
33}
34thread bool operator==(const half2x4 left, const half2x4 right) {
35    return all(left[0] == right[0]) &&
36           all(left[1] == right[1]);
37}
38thread bool operator!=(const half2x4 left, const half2x4 right) {
39    return !(left == right);
40}
41thread bool operator==(const half4x2 left, const half4x2 right) {
42    return all(left[0] == right[0]) &&
43           all(left[1] == right[1]) &&
44           all(left[2] == right[2]) &&
45           all(left[3] == right[3]);
46}
47thread bool operator!=(const half4x2 left, const half4x2 right) {
48    return !(left == right);
49}
50thread bool operator==(const float4x3 left, const float4x3 right) {
51    return all(left[0] == right[0]) &&
52           all(left[1] == right[1]) &&
53           all(left[2] == right[2]) &&
54           all(left[3] == right[3]);
55}
56thread bool operator!=(const float4x3 left, const float4x3 right) {
57    return !(left == right);
58}
59fragment Outputs fragmentMain(Inputs _in [[stage_in]], constant Uniforms& _uniforms [[buffer(0)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) {
60    Outputs _out;
61    (void)_out;
62    half2x4 h24 = matrixCompMult(half2x4(half4(9.0h, 9.0h, 9.0h, 9.0h), half4(9.0h, 9.0h, 9.0h, 9.0h)), half2x4(_uniforms.colorRed, _uniforms.colorGreen));
63    half4x2 h42 = matrixCompMult(half4x2(half2(1.0h, 2.0h), half2(3.0h, 4.0h), half2(5.0h, 6.0h), half2(7.0h, 8.0h)), half4x2_from_half4_half4(_uniforms.colorRed, _uniforms.colorGreen));
64    float4x3 f43 = float4x3(float3(12.0, 22.0, 30.0), float3(36.0, 40.0, 42.0), float3(42.0, 40.0, 36.0), float3(30.0, 22.0, 12.0));
65    _out.sk_FragColor = (h24 == half2x4(half4(9.0h, 0.0h, 0.0h, 9.0h), half4(0.0h, 9.0h, 0.0h, 9.0h)) && h42 == half4x2(half2(1.0h, 0.0h), half2(0.0h, 4.0h), half2(0.0h, 6.0h), half2(0.0h, 8.0h))) && f43 == float4x3(float3(12.0, 22.0, 30.0), float3(36.0, 40.0, 42.0), float3(42.0, 40.0, 36.0), float3(30.0, 22.0, 12.0)) ? _uniforms.colorGreen : _uniforms.colorRed;
66    return _out;
67}
68