Debian Codegraph @

third_party/spirv-cross/reference/shaders-msl/vert/in_out_array_mat.vert

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 UBO
48 {
49 float4x4 projection;
50 float4x4 model;
51 float lodBias;
52 };
53
54 struct main0_out
55 {
56 float3 outPos [[user(locn0)]];
57 float3 outNormal [[user(locn1)]];
58 float4 outTransModel_0 [[user(locn2)]];
59 float4 outTransModel_1 [[user(locn3)]];
60 float4 outTransModel_2 [[user(locn4)]];
61 float4 outTransModel_3 [[user(locn5)]];
62 float outLodBias [[user(locn6)]];
63 float4 color [[user(locn7)]];
64 float4 gl_Position [[position]];
65 };
66
67 struct main0_in
68 {
69 float3 inPos [[attribute(0)]];
70 float4 colors_0 [[attribute(1)]];
71 float4 colors_1 [[attribute(2)]];
72 float4 colors_2 [[attribute(3)]];
73 float3 inNormal [[attribute(4)]];
74 float4 inViewMat_0 [[attribute(5)]];
75 float4 inViewMat_1 [[attribute(6)]];
76 float4 inViewMat_2 [[attribute(7)]];
77 float4 inViewMat_3 [[attribute(8)]];
78 };
79
80 static inline __attribute__((always_inline))
81 void write_deeper_in_function(thread float4x4& outTransModel, constant UBO& ubo, thread float4& color, thread spvUnsafeArray<float4, 3> (&colors))
82 {
83 outTransModel[1].y = ubo.lodBias;
84 color = colors[2];
85 }
86
87 static inline __attribute__((always_inline))
88 void write_in_function(thread float4x4& outTransModel, constant UBO& ubo, thread float4& color, thread spvUnsafeArray<float4, 3> (&colors), thread float3& inNormal)
89 {
90 outTransModel[2] = float4(inNormal, 1.0);
91 write_deeper_in_function(outTransModel, ubo, color, colors);
92 }
93
94 vertex main0_out main0(main0_in in [[stage_in]], constant UBO& ubo [[buffer(0)]])
95 {
96 main0_out out = {};
97 float4x4 outTransModel = {};
98 spvUnsafeArray<float4, 3> colors = {};
99 float4x4 inViewMat = {};
100 colors[0] = in.colors_0;
101 colors[1] = in.colors_1;
102 colors[2] = in.colors_2;
103 inViewMat[0] = in.inViewMat_0;
104 inViewMat[1] = in.inViewMat_1;
105 inViewMat[2] = in.inViewMat_2;
106 inViewMat[3] = in.inViewMat_3;
107 out.gl_Position = (ubo.projection * ubo.model) * float4(in.inPos, 1.0);
108 out.outPos = float3((ubo.model * float4(in.inPos, 1.0)).xyz);
109 out.outNormal = float3x3(float3(float3(ubo.model[0].x, ubo.model[0].y, ubo.model[0].z)), float3(float3(ubo.model[1].x, ubo.model[1].y, ubo.model[1].z)), float3(float3(ubo.model[2].x, ubo.model[2].y, ubo.model[2].z))) * in.inNormal;
110 out.outLodBias = ubo.lodBias;
111 outTransModel = transpose(ubo.model) * inViewMat;
112 write_in_function(outTransModel, ubo, out.color, colors, in.inNormal);
113 out.outTransModel_0 = outTransModel[0];
114 out.outTransModel_1 = outTransModel[1];
115 out.outTransModel_2 = outTransModel[2];
116 out.outTransModel_3 = outTransModel[3];
117 return out;
118 }
119