Debian Codegraph @

third_party/spirv-cross/shaders-msl-no-opt/vert/functions_nested.vert

raw
1 #version 450
2 #extension GL_ARB_separate_shader_objects : enable
3
4 layout(std140, set = 0, binding = 0) uniform VertexBuffer
5 {
6 mat4 scale_offset_mat;
7 uint vertex_base_index;
8 ivec4 input_attributes[16];
9 };
10 layout(set=0, binding=3) uniform usamplerBuffer buff_in_1;
11 layout(set=0, binding=4) uniform usamplerBuffer buff_in_2;
12
13 layout(location=10) out vec4 back_color;
14 layout(location=0) out vec4 tc0;
15
16 layout(std140, set=0, binding = 1) uniform VertexConstantsBuffer
17 {
18 vec4 vc[16];
19 };
20
21 struct attr_desc
22 {
23 int type;
24 int attribute_size;
25 int starting_offset;
26 int stride;
27 int swap_bytes;
28 int is_volatile;
29 };
30
31 uint get_bits(uvec4 v, int swap)
32 {
33 if (swap != 0) return (v.w | v.z << 8 | v.y << 16 | v.x << 24);
34 return (v.x | v.y << 8 | v.z << 16 | v.w << 24);
35 }
36
37 vec4 fetch_attr(attr_desc desc, int vertex_id, usamplerBuffer input_stream)
38 {
39 vec4 result = vec4(0.0f, 0.0f, 0.0f, 1.0f);
40 uvec4 tmp;
41 uint bits;
42 bool reverse_order = false;
43
44 int first_byte = (vertex_id * desc.stride) + desc.starting_offset;
45 for (int n = 0; n < 4; n++)
46 {
47 if (n == desc.attribute_size) break;
48
49 switch (desc.type)
50 {
51 case 0:
52 //signed normalized 16-bit
53 tmp.x = texelFetch(input_stream, first_byte++).x;
54 tmp.y = texelFetch(input_stream, first_byte++).x;
55 result[n] = get_bits(tmp, desc.swap_bytes);
56 break;
57 case 1:
58 //float
59 tmp.x = texelFetch(input_stream, first_byte++).x;
60 tmp.y = texelFetch(input_stream, first_byte++).x;
61 tmp.z = texelFetch(input_stream, first_byte++).x;
62 tmp.w = texelFetch(input_stream, first_byte++).x;
63 result[n] = uintBitsToFloat(get_bits(tmp, desc.swap_bytes));
64 break;
65 case 2:
66 //unsigned byte
67 result[n] = texelFetch(input_stream, first_byte++).x;
68 reverse_order = (desc.swap_bytes != 0);
69 break;
70 }
71 }
72
73 return (reverse_order)? result.wzyx: result;
74 }
75
76 attr_desc fetch_desc(int location)
77 {
78 attr_desc result;
79 int attribute_flags = input_attributes[location].w;
80 result.type = input_attributes[location].x;
81 result.attribute_size = input_attributes[location].y;
82 result.starting_offset = input_attributes[location].z;
83 result.stride = attribute_flags & 0xFF;
84 result.swap_bytes = (attribute_flags >> 8) & 0x1;
85 result.is_volatile = (attribute_flags >> 9) & 0x1;
86 return result;
87 }
88
89 vec4 read_location(int location)
90 {
91 attr_desc desc = fetch_desc(location);
92
93 int vertex_id = gl_VertexIndex - int(vertex_base_index);
94 if (desc.is_volatile != 0)
95 return fetch_attr(desc, vertex_id, buff_in_2);
96 else
97 return fetch_attr(desc, vertex_id, buff_in_1);
98 }
99
100 void vs_adjust(inout vec4 dst_reg0, inout vec4 dst_reg1, inout vec4 dst_reg7)
101 {
102 vec4 tmp0;
103 vec4 tmp1;
104 vec4 in_diff_color= read_location(3);
105 vec4 in_pos= read_location(0);
106 vec4 in_tc0= read_location(8);
107 dst_reg1 = (in_diff_color * vc[13]);
108 tmp0.x = vec4(dot(vec4(in_pos.xyzx.xyz, 1.0), vc[4])).x;
109 tmp0.y = vec4(dot(vec4(in_pos.xyzx.xyz, 1.0), vc[5])).y;
110 tmp0.z = vec4(dot(vec4(in_pos.xyzx.xyz, 1.0), vc[6])).z;
111 tmp1.xy = in_tc0.xyxx.xy;
112 tmp1.z = vc[15].xxxx.z;
113 dst_reg7.y = vec4(dot(vec4(tmp1.xyzx.xyz, 1.0), vc[8])).y;
114 dst_reg7.x = vec4(dot(vec4(tmp1.xyzx.xyz, 1.0), vc[7])).x;
115 dst_reg0.y = vec4(dot(vec4(tmp0.xyzx.xyz, 1.0), vc[1])).y;
116 dst_reg0.x = vec4(dot(vec4(tmp0.xyzx.xyz, 1.0), vc[0])).x;
117 }
118
119 void main ()
120 {
121 vec4 dst_reg0= vec4(0.0f, 0.0f, 0.0f, 1.0f);
122 vec4 dst_reg1= vec4(0.0, 0.0, 0.0, 0.0);
123 vec4 dst_reg7= vec4(0.0, 0.0, 0.0, 0.0);
124
125 vs_adjust(dst_reg0, dst_reg1, dst_reg7);
126
127 gl_Position = dst_reg0;
128 back_color = dst_reg1;
129 tc0 = dst_reg7;
130 gl_Position = gl_Position * scale_offset_mat;
131 }
132