xref: /aosp_15_r20/external/skia/tests/sksl/shared/MatrixIndexStore.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    float3x3 testMatrix3x3;
11    float4x4 testMatrix4x4;
12};
13struct Inputs {
14};
15struct Outputs {
16    half4 sk_FragColor [[color(0)]];
17};
18
19thread bool operator==(const float3x3 left, const float3x3 right);
20thread bool operator!=(const float3x3 left, const float3x3 right);
21
22thread bool operator==(const float4x4 left, const float4x4 right);
23thread bool operator!=(const float4x4 left, const float4x4 right);
24thread bool operator==(const float3x3 left, const float3x3 right) {
25    return all(left[0] == right[0]) &&
26           all(left[1] == right[1]) &&
27           all(left[2] == right[2]);
28}
29thread bool operator!=(const float3x3 left, const float3x3 right) {
30    return !(left == right);
31}
32thread bool operator==(const float4x4 left, const float4x4 right) {
33    return all(left[0] == right[0]) &&
34           all(left[1] == right[1]) &&
35           all(left[2] == right[2]) &&
36           all(left[3] == right[3]);
37}
38thread bool operator!=(const float4x4 left, const float4x4 right) {
39    return !(left == right);
40}
41bool test3x3_b(Uniforms _uniforms) {
42    float3x3 matrix;
43    float3 values = float3(1.0, 2.0, 3.0);
44    for (int index = 0;index < 3; ++index) {
45        matrix[index] = values;
46        values += 3.0;
47    }
48    return matrix == _uniforms.testMatrix3x3;
49}
50bool test4x4_b(Uniforms _uniforms) {
51    float4x4 matrix;
52    float4 values = float4(1.0, 2.0, 3.0, 4.0);
53    for (int index = 0;index < 4; ++index) {
54        matrix[index] = values;
55        values += 4.0;
56    }
57    return matrix == _uniforms.testMatrix4x4;
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    _out.sk_FragColor = test3x3_b(_uniforms) && test4x4_b(_uniforms) ? _uniforms.colorGreen : _uniforms.colorRed;
63    return _out;
64}
65