xref: /aosp_15_r20/external/skia/tests/sksl/shared/PrefixExpressionsES2.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    float2x2 testMatrix2x2;
11};
12struct Inputs {
13};
14struct Outputs {
15    half4 sk_FragColor [[color(0)]];
16};
17
18thread bool operator==(const float3x3 left, const float3x3 right);
19thread bool operator!=(const float3x3 left, const float3x3 right);
20
21thread bool operator==(const float2x2 left, const float2x2 right);
22thread bool operator!=(const float2x2 left, const float2x2 right);
23thread bool operator==(const float3x3 left, const float3x3 right) {
24    return all(left[0] == right[0]) &&
25           all(left[1] == right[1]) &&
26           all(left[2] == right[2]);
27}
28thread bool operator!=(const float3x3 left, const float3x3 right) {
29    return !(left == right);
30}
31thread bool operator==(const float2x2 left, const float2x2 right) {
32    return all(left[0] == right[0]) &&
33           all(left[1] == right[1]);
34}
35thread bool operator!=(const float2x2 left, const float2x2 right) {
36    return !(left == right);
37}
38fragment Outputs fragmentMain(Inputs _in [[stage_in]], constant Uniforms& _uniforms [[buffer(0)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) {
39    Outputs _out;
40    (void)_out;
41    bool ok = true;
42    int i = 5;
43    ++i;
44    ok = ok && i == 6;
45    ok = ok && ++i == 7;
46    ok = ok && --i == 6;
47    --i;
48    ok = ok && i == 5;
49    float f = 0.5;
50    ++f;
51    ok = ok && f == 1.5;
52    ok = ok && ++f == 2.5;
53    ok = ok && --f == 1.5;
54    --f;
55    ok = ok && f == 0.5;
56    float2 f2 = float2(0.5);
57    ++f2.x;
58    ok = ok && f2.x == 1.5;
59    ok = ok && ++f2.x == 2.5;
60    ok = ok && --f2.x == 1.5;
61    --f2.x;
62    ok = ok && f2.x == 0.5;
63    ++f2;
64    ok = ok && all(f2 == float2(1.5));
65    ok = ok && all(++f2 == float2(2.5));
66    ok = ok && all(--f2 == float2(1.5));
67    --f2;
68    ok = ok && all(f2 == float2(0.5));
69    int4 i4 = int4(7, 8, 9, 10);
70    ++i4;
71    ok = ok && all(i4 == int4(8, 9, 10, 11));
72    ok = ok && all(++i4 == int4(9, 10, 11, 12));
73    ok = ok && all(--i4 == int4(8, 9, 10, 11));
74    --i4;
75    ok = ok && all(i4 == int4(7, 8, 9, 10));
76    float3x3 m3x3 = float3x3(float3(1.0, 2.0, 3.0), float3(4.0, 5.0, 6.0), float3(7.0, 8.0, 9.0));
77    (m3x3 += float3x3(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0));
78    ok = ok && m3x3 == float3x3(float3(2.0, 3.0, 4.0), float3(5.0, 6.0, 7.0), float3(8.0, 9.0, 10.0));
79    ok = ok && (m3x3 += float3x3(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)) == float3x3(float3(3.0, 4.0, 5.0), float3(6.0, 7.0, 8.0), float3(9.0, 10.0, 11.0));
80    ok = ok && (m3x3 -= float3x3(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0)) == float3x3(float3(2.0, 3.0, 4.0), float3(5.0, 6.0, 7.0), float3(8.0, 9.0, 10.0));
81    (m3x3 -= float3x3(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0));
82    ok = ok && m3x3 == float3x3(float3(1.0, 2.0, 3.0), float3(4.0, 5.0, 6.0), float3(7.0, 8.0, 9.0));
83    ok = ok && _uniforms.colorGreen.x != 1.0h;
84    ok = ok && -1.0h == -_uniforms.colorGreen.y;
85    ok = ok && all(half4(0.0h, -1.0h, 0.0h, -1.0h) == -_uniforms.colorGreen);
86    ok = ok && float2x2(float2(-1.0, -2.0), float2(-3.0, -4.0)) == (-1.0 * _uniforms.testMatrix2x2);
87    int2 iv = int2(i, -i);
88    ok = ok && -i == -5;
89    ok = ok && all(-iv == int2(-5, 5));
90    _out.sk_FragColor = ok ? _uniforms.colorGreen : _uniforms.colorRed;
91    return _out;
92}
93