xref: /aosp_15_r20/external/skia/tests/sksl/shared/UnaryPositiveNegative.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 colorWhite;
9    half4 colorGreen;
10    half4 colorRed;
11    float2x2 testMatrix2x2;
12    float3x3 testMatrix3x3;
13    float4x4 testMatrix4x4;
14};
15struct Inputs {
16};
17struct Outputs {
18    half4 sk_FragColor [[color(0)]];
19};
20
21thread bool operator==(const float2x2 left, const float2x2 right);
22thread bool operator!=(const float2x2 left, const float2x2 right);
23
24thread bool operator==(const float3x3 left, const float3x3 right);
25thread bool operator!=(const float3x3 left, const float3x3 right);
26
27thread bool operator==(const float4x4 left, const float4x4 right);
28thread bool operator!=(const float4x4 left, const float4x4 right);
29
30thread bool operator==(const half2x2 left, const half2x2 right);
31thread bool operator!=(const half2x2 left, const half2x2 right);
32
33thread bool operator==(const half3x3 left, const half3x3 right);
34thread bool operator!=(const half3x3 left, const half3x3 right);
35
36thread bool operator==(const half4x4 left, const half4x4 right);
37thread bool operator!=(const half4x4 left, const half4x4 right);
38thread bool operator==(const float2x2 left, const float2x2 right) {
39    return all(left[0] == right[0]) &&
40           all(left[1] == right[1]);
41}
42thread bool operator!=(const float2x2 left, const float2x2 right) {
43    return !(left == right);
44}
45thread bool operator==(const float3x3 left, const float3x3 right) {
46    return all(left[0] == right[0]) &&
47           all(left[1] == right[1]) &&
48           all(left[2] == right[2]);
49}
50thread bool operator!=(const float3x3 left, const float3x3 right) {
51    return !(left == right);
52}
53thread bool operator==(const float4x4 left, const float4x4 right) {
54    return all(left[0] == right[0]) &&
55           all(left[1] == right[1]) &&
56           all(left[2] == right[2]) &&
57           all(left[3] == right[3]);
58}
59thread bool operator!=(const float4x4 left, const float4x4 right) {
60    return !(left == right);
61}
62thread bool operator==(const half2x2 left, const half2x2 right) {
63    return all(left[0] == right[0]) &&
64           all(left[1] == right[1]);
65}
66thread bool operator!=(const half2x2 left, const half2x2 right) {
67    return !(left == right);
68}
69thread bool operator==(const half3x3 left, const half3x3 right) {
70    return all(left[0] == right[0]) &&
71           all(left[1] == right[1]) &&
72           all(left[2] == right[2]);
73}
74thread bool operator!=(const half3x3 left, const half3x3 right) {
75    return !(left == right);
76}
77thread bool operator==(const half4x4 left, const half4x4 right) {
78    return all(left[0] == right[0]) &&
79           all(left[1] == right[1]) &&
80           all(left[2] == right[2]) &&
81           all(left[3] == right[3]);
82}
83thread bool operator!=(const half4x4 left, const half4x4 right) {
84    return !(left == right);
85}
86bool test_iscalar_b(Uniforms _uniforms) {
87    int x = int(_uniforms.colorWhite.x);
88    x = -x;
89    return x == -1;
90}
91bool test_fvec_b(Uniforms _uniforms) {
92    half2 x = _uniforms.colorWhite.xy;
93    x = -x;
94    return all(x == half2(-1.0h));
95}
96bool test_ivec_b(Uniforms _uniforms) {
97    int2 x = int2(int(_uniforms.colorWhite.x));
98    x = -x;
99    return all(x == int2(-1));
100}
101bool test_mat2_b(Uniforms _uniforms) {
102    const float2x2 negated = float2x2(float2(-1.0, -2.0), float2(-3.0, -4.0));
103    float2x2 x = _uniforms.testMatrix2x2;
104    x = (-1.0 * x);
105    return x == negated;
106}
107bool test_mat3_b(Uniforms _uniforms) {
108    const float3x3 negated = float3x3(float3(-1.0, -2.0, -3.0), float3(-4.0, -5.0, -6.0), float3(-7.0, -8.0, -9.0));
109    float3x3 x = _uniforms.testMatrix3x3;
110    x = (-1.0 * x);
111    return x == negated;
112}
113bool test_mat4_b(Uniforms _uniforms) {
114    const float4x4 negated = float4x4(float4(-1.0, -2.0, -3.0, -4.0), float4(-5.0, -6.0, -7.0, -8.0), float4(-9.0, -10.0, -11.0, -12.0), float4(-13.0, -14.0, -15.0, -16.0));
115    float4x4 x = _uniforms.testMatrix4x4;
116    x = (-1.0 * x);
117    return x == negated;
118}
119bool test_hmat2_b(Uniforms _uniforms) {
120    const half2x2 negated = half2x2(half2(-1.0h, -2.0h), half2(-3.0h, -4.0h));
121    half2x2 x = half2x2(_uniforms.testMatrix2x2);
122    x = (-1.0h * x);
123    return x == negated;
124}
125bool test_hmat3_b(Uniforms _uniforms) {
126    const half3x3 negated = half3x3(half3(-1.0h, -2.0h, -3.0h), half3(-4.0h, -5.0h, -6.0h), half3(-7.0h, -8.0h, -9.0h));
127    half3x3 x = half3x3(_uniforms.testMatrix3x3);
128    x = (-1.0h * x);
129    return x == negated;
130}
131bool test_hmat4_b(Uniforms _uniforms) {
132    const half4x4 negated = half4x4(half4(-1.0h, -2.0h, -3.0h, -4.0h), half4(-5.0h, -6.0h, -7.0h, -8.0h), half4(-9.0h, -10.0h, -11.0h, -12.0h), half4(-13.0h, -14.0h, -15.0h, -16.0h));
133    half4x4 x = half4x4(_uniforms.testMatrix4x4);
134    x = (-1.0h * x);
135    return x == negated;
136}
137fragment Outputs fragmentMain(Inputs _in [[stage_in]], constant Uniforms& _uniforms [[buffer(0)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) {
138    Outputs _out;
139    (void)_out;
140    float _0_x = float(_uniforms.colorWhite.x);
141    _0_x = -_0_x;
142    _out.sk_FragColor = ((((((((_0_x == -1.0 && test_iscalar_b(_uniforms)) && test_fvec_b(_uniforms)) && test_ivec_b(_uniforms)) && test_mat2_b(_uniforms)) && test_mat3_b(_uniforms)) && test_mat4_b(_uniforms)) && test_hmat2_b(_uniforms)) && test_hmat3_b(_uniforms)) && test_hmat4_b(_uniforms) ? _uniforms.colorGreen : _uniforms.colorRed;
143    return _out;
144}
145