summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/bgfx/3rdparty/spirv-cross/reference/shaders-msl-no-opt/comp/glsl.std450.comp
blob: 83ac061a706fb397c62321bf48473746578f0bba (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
#pragma clang diagnostic ignored "-Wmissing-prototypes"

#include <metal_stdlib>
#include <simd/simd.h>

using namespace metal;

struct SSBO
{
    float res;
    int ires;
    uint ures;
    float4 f32;
    int4 s32;
    uint4 u32;
    float2x2 m2;
    float3x3 m3;
    float4x4 m4;
};

struct ResType
{
    float _m0;
    int _m1;
};

constant uint3 gl_WorkGroupSize [[maybe_unused]] = uint3(1u);

// Implementation of the GLSL radians() function
template<typename T>
inline T radians(T d)
{
    return d * T(0.01745329251);
}

// Implementation of the GLSL degrees() function
template<typename T>
inline T degrees(T r)
{
    return r * T(57.2957795131);
}

// Implementation of the GLSL findLSB() function
template<typename T>
inline T spvFindLSB(T x)
{
    return select(ctz(x), T(-1), x == T(0));
}

// Implementation of the signed GLSL findMSB() function
template<typename T>
inline T spvFindSMSB(T x)
{
    T v = select(x, T(-1) - x, x < T(0));
    return select(clz(T(0)) - (clz(v) + T(1)), T(-1), v == T(0));
}

// Implementation of the unsigned GLSL findMSB() function
template<typename T>
inline T spvFindUMSB(T x)
{
    return select(clz(T(0)) - (clz(x) + T(1)), T(-1), x == T(0));
}

// Implementation of the GLSL sign() function for integer types
template<typename T, typename E = typename enable_if<is_integral<T>::value>::type>
inline T sign(T x)
{
    return select(select(select(x, T(0), x == T(0)), T(1), x > T(0)), T(-1), x < T(0));
}

// Returns the determinant of a 2x2 matrix.
inline float spvDet2x2(float a1, float a2, float b1, float b2)
{
    return a1 * b2 - b1 * a2;
}

// Returns the determinant of a 3x3 matrix.
inline float spvDet3x3(float a1, float a2, float a3, float b1, float b2, float b3, float c1, float c2, float c3)
{
    return a1 * spvDet2x2(b2, b3, c2, c3) - b1 * spvDet2x2(a2, a3, c2, c3) + c1 * spvDet2x2(a2, a3, b2, b3);
}

// Returns the inverse of a matrix, by using the algorithm of calculating the classical
// adjoint and dividing by the determinant. The contents of the matrix are changed.
inline float4x4 spvInverse4x4(float4x4 m)
{
    float4x4 adj;	// The adjoint matrix (inverse after dividing by determinant)

    // Create the transpose of the cofactors, as the classical adjoint of the matrix.
    adj[0][0] =  spvDet3x3(m[1][1], m[1][2], m[1][3], m[2][1], m[2][2], m[2][3], m[3][1], m[3][2], m[3][3]);
    adj[0][1] = -spvDet3x3(m[0][1], m[0][2], m[0][3], m[2][1], m[2][2], m[2][3], m[3][1], m[3][2], m[3][3]);
    adj[0][2] =  spvDet3x3(m[0][1], m[0][2], m[0][3], m[1][1], m[1][2], m[1][3], m[3][1], m[3][2], m[3][3]);
    adj[0][3] = -spvDet3x3(m[0][1], m[0][2], m[0][3], m[1][1], m[1][2], m[1][3], m[2][1], m[2][2], m[2][3]);

    adj[1][0] = -spvDet3x3(m[1][0], m[1][2], m[1][3], m[2][0], m[2][2], m[2][3], m[3][0], m[3][2], m[3][3]);
    adj[1][1] =  spvDet3x3(m[0][0], m[0][2], m[0][3], m[2][0], m[2][2], m[2][3], m[3][0], m[3][2], m[3][3]);
    adj[1][2] = -spvDet3x3(m[0][0], m[0][2], m[0][3], m[1][0], m[1][2], m[1][3], m[3][0], m[3][2], m[3][3]);
    adj[1][3] =  spvDet3x3(m[0][0], m[0][2], m[0][3], m[1][0], m[1][2], m[1][3], m[2][0], m[2][2], m[2][3]);

    adj[2][0] =  spvDet3x3(m[1][0], m[1][1], m[1][3], m[2][0], m[2][1], m[2][3], m[3][0], m[3][1], m[3][3]);
    adj[2][1] = -spvDet3x3(m[0][0], m[0][1], m[0][3], m[2][0], m[2][1], m[2][3], m[3][0], m[3][1], m[3][3]);
    adj[2][2] =  spvDet3x3(m[0][0], m[0][1], m[0][3], m[1][0], m[1][1], m[1][3], m[3][0], m[3][1], m[3][3]);
    adj[2][3] = -spvDet3x3(m[0][0], m[0][1], m[0][3], m[1][0], m[1][1], m[1][3], m[2][0], m[2][1], m[2][3]);

    adj[3][0] = -spvDet3x3(m[1][0], m[1][1], m[1][2], m[2][0], m[2][1], m[2][2], m[3][0], m[3][1], m[3][2]);
    adj[3][1] =  spvDet3x3(m[0][0], m[0][1], m[0][2], m[2][0], m[2][1], m[2][2], m[3][0], m[3][1], m[3][2]);
    adj[3][2] = -spvDet3x3(m[0][0], m[0][1], m[0][2], m[1][0], m[1][1], m[1][2], m[3][0], m[3][1], m[3][2]);
    adj[3][3] =  spvDet3x3(m[0][0], m[0][1], m[0][2], m[1][0], m[1][1], m[1][2], m[2][0], m[2][1], m[2][2]);

    // Calculate the determinant as a combination of the cofactors of the first row.
    float det = (adj[0][0] * m[0][0]) + (adj[0][1] * m[1][0]) + (adj[0][2] * m[2][0]) + (adj[0][3] * m[3][0]);

    // Divide the classical adjoint matrix by the determinant.
    // If determinant is zero, matrix is not invertable, so leave it unchanged.
    return (det != 0.0f) ? (adj * (1.0f / det)) : m;
}

// Returns the inverse of a matrix, by using the algorithm of calculating the classical
// adjoint and dividing by the determinant. The contents of the matrix are changed.
inline float3x3 spvInverse3x3(float3x3 m)
{
    float3x3 adj;	// The adjoint matrix (inverse after dividing by determinant)

    // Create the transpose of the cofactors, as the classical adjoint of the matrix.
    adj[0][0] =  spvDet2x2(m[1][1], m[1][2], m[2][1], m[2][2]);
    adj[0][1] = -spvDet2x2(m[0][1], m[0][2], m[2][1], m[2][2]);
    adj[0][2] =  spvDet2x2(m[0][1], m[0][2], m[1][1], m[1][2]);

    adj[1][0] = -spvDet2x2(m[1][0], m[1][2], m[2][0], m[2][2]);
    adj[1][1] =  spvDet2x2(m[0][0], m[0][2], m[2][0], m[2][2]);
    adj[1][2] = -spvDet2x2(m[0][0], m[0][2], m[1][0], m[1][2]);

    adj[2][0] =  spvDet2x2(m[1][0], m[1][1], m[2][0], m[2][1]);
    adj[2][1] = -spvDet2x2(m[0][0], m[0][1], m[2][0], m[2][1]);
    adj[2][2] =  spvDet2x2(m[0][0], m[0][1], m[1][0], m[1][1]);

    // Calculate the determinant as a combination of the cofactors of the first row.
    float det = (adj[0][0] * m[0][0]) + (adj[0][1] * m[1][0]) + (adj[0][2] * m[2][0]);

    // Divide the classical adjoint matrix by the determinant.
    // If determinant is zero, matrix is not invertable, so leave it unchanged.
    return (det != 0.0f) ? (adj * (1.0f / det)) : m;
}

// Returns the inverse of a matrix, by using the algorithm of calculating the classical
// adjoint and dividing by the determinant. The contents of the matrix are changed.
inline float2x2 spvInverse2x2(float2x2 m)
{
    float2x2 adj;	// The adjoint matrix (inverse after dividing by determinant)

    // Create the transpose of the cofactors, as the classical adjoint of the matrix.
    adj[0][0] =  m[1][1];
    adj[0][1] = -m[0][1];

    adj[1][0] = -m[1][0];
    adj[1][1] =  m[0][0];

    // Calculate the determinant as a combination of the cofactors of the first row.
    float det = (adj[0][0] * m[0][0]) + (adj[0][1] * m[1][0]);

    // Divide the classical adjoint matrix by the determinant.
    // If determinant is zero, matrix is not invertable, so leave it unchanged.
    return (det != 0.0f) ? (adj * (1.0f / det)) : m;
}

template<typename T>
inline T spvReflect(T i, T n)
{
    return i - T(2) * i * n * n;
}

template<typename T>
inline T spvRefract(T i, T n, T eta)
{
    T NoI = n * i;
    T NoI2 = NoI * NoI;
    T k = T(1) - eta * eta * (T(1) - NoI2);
    if (k < T(0))
    {
        return T(0);
    }
    else
    {
        return eta * i - (eta * NoI + sqrt(k)) * n;
    }
}

template<typename T>
inline T spvFaceForward(T n, T i, T nref)
{
    return i * nref < T(0) ? n : -n;
}

kernel void main0(device SSBO& _19 [[buffer(0)]])
{
    _19.res = round(_19.f32.x);
    _19.res = rint(_19.f32.x);
    _19.res = trunc(_19.f32.x);
    _19.res = abs(_19.f32.x);
    _19.ires = abs(_19.s32.x);
    _19.res = sign(_19.f32.x);
    _19.ires = sign(_19.s32.x);
    _19.res = floor(_19.f32.x);
    _19.res = ceil(_19.f32.x);
    _19.res = fract(_19.f32.x);
    _19.res = radians(_19.f32.x);
    _19.res = degrees(_19.f32.x);
    _19.res = sin(_19.f32.x);
    _19.res = cos(_19.f32.x);
    _19.res = tan(_19.f32.x);
    _19.res = asin(_19.f32.x);
    _19.res = acos(_19.f32.x);
    _19.res = atan(_19.f32.x);
    _19.res = sinh(_19.f32.x);
    _19.res = cosh(_19.f32.x);
    _19.res = tanh(_19.f32.x);
    _19.res = asinh(_19.f32.x);
    _19.res = acosh(_19.f32.x);
    _19.res = atanh(_19.f32.x);
    _19.res = atan2(_19.f32.x, _19.f32.y);
    _19.res = pow(_19.f32.x, _19.f32.y);
    _19.res = exp(_19.f32.x);
    _19.res = log(_19.f32.x);
    _19.res = exp2(_19.f32.x);
    _19.res = log2(_19.f32.x);
    _19.res = sqrt(_19.f32.x);
    _19.res = rsqrt(_19.f32.x);
    _19.res = abs(_19.f32.x);
    _19.res = abs(_19.f32.x - _19.f32.y);
    _19.res = sign(_19.f32.x);
    _19.res = spvFaceForward(_19.f32.x, _19.f32.y, _19.f32.z);
    _19.res = spvReflect(_19.f32.x, _19.f32.y);
    _19.res = spvRefract(_19.f32.x, _19.f32.y, _19.f32.z);
    _19.res = length(_19.f32.xy);
    _19.res = distance(_19.f32.xy, _19.f32.zw);
    float2 v2 = normalize(_19.f32.xy);
    v2 = faceforward(_19.f32.xy, _19.f32.yz, _19.f32.zw);
    v2 = reflect(_19.f32.xy, _19.f32.zw);
    v2 = refract(_19.f32.xy, _19.f32.yz, _19.f32.w);
    float3 v3 = cross(_19.f32.xyz, _19.f32.yzw);
    _19.res = determinant(_19.m2);
    _19.res = determinant(_19.m3);
    _19.res = determinant(_19.m4);
    _19.m2 = spvInverse2x2(_19.m2);
    _19.m3 = spvInverse3x3(_19.m3);
    _19.m4 = spvInverse4x4(_19.m4);
    float tmp;
    float _287 = modf(_19.f32.x, tmp);
    _19.res = _287;
    _19.res = fast::min(_19.f32.x, _19.f32.y);
    _19.ures = min(_19.u32.x, _19.u32.y);
    _19.ires = min(_19.s32.x, _19.s32.y);
    _19.res = fast::max(_19.f32.x, _19.f32.y);
    _19.ures = max(_19.u32.x, _19.u32.y);
    _19.ires = max(_19.s32.x, _19.s32.y);
    _19.res = fast::clamp(_19.f32.x, _19.f32.y, _19.f32.z);
    _19.ures = clamp(_19.u32.x, _19.u32.y, _19.u32.z);
    _19.ires = clamp(_19.s32.x, _19.s32.y, _19.s32.z);
    _19.res = mix(_19.f32.x, _19.f32.y, _19.f32.z);
    _19.res = step(_19.f32.x, _19.f32.y);
    _19.res = smoothstep(_19.f32.x, _19.f32.y, _19.f32.z);
    _19.res = fma(_19.f32.x, _19.f32.y, _19.f32.z);
    ResType _387;
    _387._m0 = frexp(_19.f32.x, _387._m1);
    int itmp = _387._m1;
    _19.res = _387._m0;
    _19.res = ldexp(_19.f32.x, itmp);
    _19.ures = pack_float_to_snorm4x8(_19.f32);
    _19.ures = pack_float_to_unorm4x8(_19.f32);
    _19.ures = pack_float_to_snorm2x16(_19.f32.xy);
    _19.ures = pack_float_to_unorm2x16(_19.f32.xy);
    _19.ures = as_type<uint>(half2(_19.f32.xy));
    v2 = unpack_snorm2x16_to_float(_19.u32.x);
    v2 = unpack_unorm2x16_to_float(_19.u32.x);
    v2 = float2(as_type<half2>(_19.u32.x));
    float4 v4 = unpack_snorm4x8_to_float(_19.u32.x);
    v4 = unpack_unorm4x8_to_float(_19.u32.x);
    _19.s32 = spvFindLSB(_19.s32);
    _19.s32 = int4(spvFindLSB(_19.u32));
    _19.s32 = spvFindSMSB(_19.s32);
    _19.s32 = int4(spvFindUMSB(_19.u32));
}