• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#pragma clang diagnostic ignored "-Wmissing-prototypes"
2
3#include <metal_stdlib>
4#include <simd/simd.h>
5
6using namespace metal;
7
8struct attr_desc
9{
10    int type;
11    int attribute_size;
12    int starting_offset;
13    int stride;
14    int swap_bytes;
15    int is_volatile;
16};
17
18struct VertexBuffer
19{
20    float4x4 scale_offset_mat;
21    uint vertex_base_index;
22    int4 input_attributes[16];
23};
24
25struct VertexConstantsBuffer
26{
27    float4 vc[16];
28};
29
30struct main0_out
31{
32    float4 tc0 [[user(locn0)]];
33    float4 back_color [[user(locn10)]];
34    float4 gl_Position [[position]];
35};
36
37// Returns 2D texture coords corresponding to 1D texel buffer coords
38static inline __attribute__((always_inline))
39uint2 spvTexelBufferCoord(uint tc)
40{
41    return uint2(tc % 4096, tc / 4096);
42}
43
44static inline __attribute__((always_inline))
45attr_desc fetch_desc(thread const int& location, constant VertexBuffer& v_227)
46{
47    int attribute_flags = v_227.input_attributes[location].w;
48    attr_desc result;
49    result.type = v_227.input_attributes[location].x;
50    result.attribute_size = v_227.input_attributes[location].y;
51    result.starting_offset = v_227.input_attributes[location].z;
52    result.stride = attribute_flags & 255;
53    result.swap_bytes = (attribute_flags >> 8) & 1;
54    result.is_volatile = (attribute_flags >> 9) & 1;
55    return result;
56}
57
58static inline __attribute__((always_inline))
59uint get_bits(thread const uint4& v, thread const int& swap)
60{
61    if (swap != 0)
62    {
63        return ((v.w | (v.z << uint(8))) | (v.y << uint(16))) | (v.x << uint(24));
64    }
65    return ((v.x | (v.y << uint(8))) | (v.z << uint(16))) | (v.w << uint(24));
66}
67
68static inline __attribute__((always_inline))
69float4 fetch_attr(thread const attr_desc& desc, thread const int& vertex_id, thread const texture2d<uint> input_stream)
70{
71    float4 result = float4(0.0, 0.0, 0.0, 1.0);
72    bool reverse_order = false;
73    int first_byte = (vertex_id * desc.stride) + desc.starting_offset;
74    uint4 tmp;
75    for (int n = 0; n < 4; n++)
76    {
77        if (n == desc.attribute_size)
78        {
79            break;
80        }
81        switch (desc.type)
82        {
83            case 0:
84            {
85                int _131 = first_byte;
86                first_byte = _131 + 1;
87                tmp.x = input_stream.read(spvTexelBufferCoord(_131)).x;
88                int _138 = first_byte;
89                first_byte = _138 + 1;
90                tmp.y = input_stream.read(spvTexelBufferCoord(_138)).x;
91                uint4 param = tmp;
92                int param_1 = desc.swap_bytes;
93                result[n] = float(get_bits(param, param_1));
94                break;
95            }
96            case 1:
97            {
98                int _156 = first_byte;
99                first_byte = _156 + 1;
100                tmp.x = input_stream.read(spvTexelBufferCoord(_156)).x;
101                int _163 = first_byte;
102                first_byte = _163 + 1;
103                tmp.y = input_stream.read(spvTexelBufferCoord(_163)).x;
104                int _170 = first_byte;
105                first_byte = _170 + 1;
106                tmp.z = input_stream.read(spvTexelBufferCoord(_170)).x;
107                int _177 = first_byte;
108                first_byte = _177 + 1;
109                tmp.w = input_stream.read(spvTexelBufferCoord(_177)).x;
110                uint4 param_2 = tmp;
111                int param_3 = desc.swap_bytes;
112                result[n] = as_type<float>(get_bits(param_2, param_3));
113                break;
114            }
115            case 2:
116            {
117                int _195 = first_byte;
118                first_byte = _195 + 1;
119                result[n] = float(input_stream.read(spvTexelBufferCoord(_195)).x);
120                reverse_order = desc.swap_bytes != 0;
121                break;
122            }
123        }
124    }
125    float4 _210;
126    if (reverse_order)
127    {
128        _210 = result.wzyx;
129    }
130    else
131    {
132        _210 = result;
133    }
134    return _210;
135}
136
137static inline __attribute__((always_inline))
138float4 read_location(thread const int& location, constant VertexBuffer& v_227, thread uint& gl_VertexIndex, thread texture2d<uint> buff_in_2, thread texture2d<uint> buff_in_1)
139{
140    int param = location;
141    attr_desc desc = fetch_desc(param, v_227);
142    int vertex_id = int(gl_VertexIndex) - int(v_227.vertex_base_index);
143    if (desc.is_volatile != 0)
144    {
145        attr_desc param_1 = desc;
146        int param_2 = vertex_id;
147        return fetch_attr(param_1, param_2, buff_in_2);
148    }
149    else
150    {
151        attr_desc param_3 = desc;
152        int param_4 = vertex_id;
153        return fetch_attr(param_3, param_4, buff_in_1);
154    }
155}
156
157static inline __attribute__((always_inline))
158void vs_adjust(thread float4& dst_reg0, thread float4& dst_reg1, thread float4& dst_reg7, constant VertexBuffer& v_227, thread uint& gl_VertexIndex, thread texture2d<uint> buff_in_2, thread texture2d<uint> buff_in_1, constant VertexConstantsBuffer& v_309)
159{
160    int param = 3;
161    float4 in_diff_color = read_location(param, v_227, gl_VertexIndex, buff_in_2, buff_in_1);
162    int param_1 = 0;
163    float4 in_pos = read_location(param_1, v_227, gl_VertexIndex, buff_in_2, buff_in_1);
164    int param_2 = 8;
165    float4 in_tc0 = read_location(param_2, v_227, gl_VertexIndex, buff_in_2, buff_in_1);
166    dst_reg1 = in_diff_color * v_309.vc[13];
167    float4 tmp0;
168    tmp0.x = float4(dot(float4(in_pos.xyz, 1.0), v_309.vc[4])).x;
169    tmp0.y = float4(dot(float4(in_pos.xyz, 1.0), v_309.vc[5])).y;
170    tmp0.z = float4(dot(float4(in_pos.xyz, 1.0), v_309.vc[6])).z;
171    float4 tmp1;
172    tmp1 = float4(in_tc0.xy.x, in_tc0.xy.y, tmp1.z, tmp1.w);
173    tmp1.z = v_309.vc[15].x;
174    dst_reg7.y = float4(dot(float4(tmp1.xyz, 1.0), v_309.vc[8])).y;
175    dst_reg7.x = float4(dot(float4(tmp1.xyz, 1.0), v_309.vc[7])).x;
176    dst_reg0.y = float4(dot(float4(tmp0.xyz, 1.0), v_309.vc[1])).y;
177    dst_reg0.x = float4(dot(float4(tmp0.xyz, 1.0), v_309.vc[0])).x;
178}
179
180vertex main0_out main0(constant VertexBuffer& v_227 [[buffer(0)]], constant VertexConstantsBuffer& v_309 [[buffer(1)]], texture2d<uint> buff_in_2 [[texture(0)]], texture2d<uint> buff_in_1 [[texture(1)]], uint gl_VertexIndex [[vertex_id]])
181{
182    main0_out out = {};
183    float4 dst_reg0 = float4(0.0, 0.0, 0.0, 1.0);
184    float4 dst_reg1 = float4(0.0);
185    float4 dst_reg7 = float4(0.0);
186    float4 param = dst_reg0;
187    float4 param_1 = dst_reg1;
188    float4 param_2 = dst_reg7;
189    vs_adjust(param, param_1, param_2, v_227, gl_VertexIndex, buff_in_2, buff_in_1, v_309);
190    dst_reg0 = param;
191    dst_reg1 = param_1;
192    dst_reg7 = param_2;
193    out.gl_Position = dst_reg0;
194    out.back_color = dst_reg1;
195    out.tc0 = dst_reg7;
196    out.gl_Position *= v_227.scale_offset_mat;
197    return out;
198}
199
200