Debian Codegraph @

third_party/spirv-cross/reference/shaders-msl/frag/mrt-array.frag

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 main0_out
48 {
49 float4 FragColor_0 [[color(0)]];
50 float4 FragColor_1 [[color(1)]];
51 float4 FragColor_2 [[color(2)]];
52 float4 FragColor_3 [[color(3)]];
53 };
54
55 struct main0_in
56 {
57 float4 vA [[user(locn0)]];
58 float4 vB [[user(locn1)]];
59 };
60
61 // Implementation of the GLSL mod() function, which is slightly different than Metal fmod()
62 template<typename Tx, typename Ty>
63 inline Tx mod(Tx x, Ty y)
64 {
65 return x - y * floor(x / y);
66 }
67
68 static inline __attribute__((always_inline))
69 void write_deeper_in_function(thread spvUnsafeArray<float4, 4> (&FragColor), thread float4& vA, thread float4& vB)
70 {
71 FragColor[3] = vA * vB;
72 }
73
74 static inline __attribute__((always_inline))
75 void write_in_function(thread spvUnsafeArray<float4, 4> (&FragColor), thread float4& vA, thread float4& vB)
76 {
77 FragColor[2] = vA - vB;
78 write_deeper_in_function(FragColor, vA, vB);
79 }
80
81 fragment main0_out main0(main0_in in [[stage_in]])
82 {
83 main0_out out = {};
84 spvUnsafeArray<float4, 4> FragColor = {};
85 FragColor[0] = mod(in.vA, in.vB);
86 FragColor[1] = in.vA + in.vB;
87 write_in_function(FragColor, in.vA, in.vB);
88 out.FragColor_0 = FragColor[0];
89 out.FragColor_1 = FragColor[1];
90 out.FragColor_2 = FragColor[2];
91 out.FragColor_3 = FragColor[3];
92 return out;
93 }
94