Debian Codegraph @

third_party/spirv-cross/reference/shaders-msl/comp/composite-array-initialization.comp

raw
1 #pragma clang diagnostic ignored "-Wmissing-prototypes"
2 #pragma clang diagnostic ignored "-Wmissing-braces"
3
4 #include <metal_stdlib>
5 #include <simd/simd.h>
6
7 using namespace metal;
8
9 template<typename T, size_t Num>
10 struct spvUnsafeArray
11 {
12 T elements[Num ? Num : 1];
13
14 thread T& operator [] (size_t pos) thread
15 {
16 return elements[pos];
17 }
18 constexpr const thread T& operator [] (size_t pos) const thread
19 {
20 return elements[pos];
21 }
22
23 device T& operator [] (size_t pos) device
24 {
25 return elements[pos];
26 }
27 constexpr const device T& operator [] (size_t pos) const device
28 {
29 return elements[pos];
30 }
31
32 constexpr const constant T& operator [] (size_t pos) const constant
33 {
34 return elements[pos];
35 }
36
37 threadgroup T& operator [] (size_t pos) threadgroup
38 {
39 return elements[pos];
40 }
41 constexpr const threadgroup T& operator [] (size_t pos) const threadgroup
42 {
43 return elements[pos];
44 }
45 };
46
47 struct Data
48 {
49 float a;
50 float b;
51 };
52
53 constant float X_tmp [[function_constant(0)]];
54 constant float X = is_function_constant_defined(X_tmp) ? X_tmp : 4.0;
55
56 struct Data_1
57 {
58 float a;
59 float b;
60 };
61
62 struct SSBO
63 {
64 Data_1 outdata[1];
65 };
66
67 constant uint3 gl_WorkGroupSize [[maybe_unused]] = uint3(2u, 1u, 1u);
68
69 constant spvUnsafeArray<Data, 2> _25 = spvUnsafeArray<Data, 2>({ Data{ 1.0, 2.0 }, Data{ 3.0, 4.0 } });
70
71 static inline __attribute__((always_inline))
72 Data combine(thread const Data& a, thread const Data& b)
73 {
74 return Data{ a.a + b.a, a.b + b.b };
75 }
76
77 kernel void main0(device SSBO& _53 [[buffer(0)]], uint3 gl_WorkGroupID [[threadgroup_position_in_grid]], uint3 gl_LocalInvocationID [[thread_position_in_threadgroup]])
78 {
79 spvUnsafeArray<Data, 2> data = spvUnsafeArray<Data, 2>({ Data{ 1.0, 2.0 }, Data{ 3.0, 4.0 } });
80 spvUnsafeArray<Data, 2> _31 = spvUnsafeArray<Data, 2>({ Data{ X, 2.0 }, Data{ 3.0, 5.0 } });
81 spvUnsafeArray<Data, 2> data2;
82 data2 = _31;
83 Data param = data[gl_LocalInvocationID.x];
84 Data param_1 = data2[gl_LocalInvocationID.x];
85 Data _73 = combine(param, param_1);
86 _53.outdata[gl_WorkGroupID.x].a = _73.a;
87 _53.outdata[gl_WorkGroupID.x].b = _73.b;
88 }
89