Descend down the tree in more locations in constant folding.
[mesa.git] / builtin_types.sh
1 #!/bin/sh
2 #
3 # Copyright © 2009 Intel Corporation
4 #
5 # Permission is hereby granted, free of charge, to any person obtaining a
6 # copy of this software and associated documentation files (the "Software"),
7 # to deal in the Software without restriction, including without limitation
8 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 # and/or sell copies of the Software, and to permit persons to whom the
10 # Software is furnished to do so, subject to the following conditions:
11 #
12 # The above copyright notice and this permission notice (including the next
13 # paragraph) shall be included in all copies or substantial portions of the
14 # Software.
15 #
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 # DEALINGS IN THE SOFTWARE.
23
24 # gen_integral_type <name> <base_type> <vector elements> <matrix rows>
25 function gen_integral_type
26 {
27 printf ' glsl_type( %17s, %u, %u, "%s"),\n' $2 $3 $4 $1
28 index=$((index + 1))
29 }
30
31 # gen_struct_type <name>
32 function gen_struct_type
33 {
34 elements=$(printf "%s_fields" $1)
35 printf ' glsl_type(%s,\n Elements(%s),\n "%s"),\n' \
36 $elements $elements $1
37 }
38
39 # gen_sampler_type <name> <dimensions> <shadow> <array> <type>
40 function gen_sampler_type
41 {
42 name=$(printf "sampler%s" $1)
43
44 if [ $4 -eq 1 ]; then
45 name=$(printf "%sArray" $name)
46 fi
47
48 if [ $3 -eq 1 ]; then
49 name=$(printf "%sShadow" $name)
50 fi
51
52 if [ $5 == GLSL_TYPE_INT ]; then
53 name=$(printf "i%s" $name)
54 elif [ $5 == GLSL_TYPE_UINT ]; then
55 name=$(printf "u%s" $name)
56 fi
57
58 printf ' glsl_type(%21s, %u, %u, %15s, "%s"),\n' \
59 $2 $3 $4 $5 $name
60 }
61
62 function gen_header
63 {
64 if [ x$1 == x ]; then
65 name="builtin_types"
66 else
67 name="builtin_${1}_types"
68 fi
69
70 printf "\nstatic const struct glsl_type %s[] = {\n" $name
71 }
72
73 function gen_footer
74 {
75 printf "};\n"
76 }
77
78 function gen_struct_field_header
79 {
80 printf "\nstatic const struct glsl_struct_field %s_fields[] = {\n" $1
81 }
82
83 function gen_struct_field_footer
84 {
85 printf "};\n"
86 }
87
88 function gen_struct_field
89 {
90 printf ' { & %s[%2u], "%s" },\n' $1 $2 "$3"
91 }
92
93 cat <<EOF
94 /* THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT! See builtin_types.sh. */
95 /*
96 * Copyright © 2009 Intel Corporation
97 *
98 * Permission is hereby granted, free of charge, to any person obtaining a
99 * copy of this software and associated documentation files (the "Software"),
100 * to deal in the Software without restriction, including without limitation
101 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
102 * and/or sell copies of the Software, and to permit persons to whom the
103 * Software is furnished to do so, subject to the following conditions:
104 *
105 * The above copyright notice and this permission notice (including the next
106 * paragraph) shall be included in all copies or substantial portions of the
107 * Software.
108 *
109 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
110 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
111 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
112 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
113 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
114 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
115 * DEALINGS IN THE SOFTWARE.
116 */
117
118 #ifndef Elements
119 #define Elements(x) (sizeof(x)/sizeof(*(x)))
120 #endif
121
122 static const struct glsl_type _error_type =
123 glsl_type(GLSL_TYPE_ERROR, 0, 0, "");
124
125 static const struct glsl_type void_type =
126 glsl_type(GLSL_TYPE_VOID, 0, 0, "void");
127
128 const glsl_type *const glsl_type::error_type = & _error_type;
129
130 EOF
131
132 echo '/** \name Core built-in types'
133 echo ' *'
134 echo ' * These types exist in all versions of GLSL.'
135 echo ' */'
136 echo '/*@{*/'
137 gen_header "core"
138
139 index=0;
140 bool_index=$index
141 gen_integral_type "bool" "GLSL_TYPE_BOOL" 1 1
142 for i in 2 3 4; do
143 gen_integral_type "bvec$i" "GLSL_TYPE_BOOL" $i 1
144 done
145
146 int_index=$index
147 gen_integral_type "int" "GLSL_TYPE_INT" 1 1
148 for i in 2 3 4; do
149 gen_integral_type "ivec$i" "GLSL_TYPE_INT" $i 1
150 done
151
152 float_index=$index
153 gen_integral_type "float" "GLSL_TYPE_FLOAT" 1 1
154 for i in 2 3 4; do
155 gen_integral_type "vec$i" "GLSL_TYPE_FLOAT" $i 1
156 done
157
158 matX_index=$index
159 for i in 2 3 4; do
160 gen_integral_type "mat$i" "GLSL_TYPE_FLOAT" $i $i
161 done
162
163 for i in "1D" "2D"; do
164 gen_sampler_type $i "GLSL_SAMPLER_DIM_$i" 0 0 "GLSL_TYPE_FLOAT"
165 gen_sampler_type $i "GLSL_SAMPLER_DIM_$i" 1 0 "GLSL_TYPE_FLOAT"
166 done
167
168 gen_sampler_type "3D" "GLSL_SAMPLER_DIM_3D" 0 0 "GLSL_TYPE_FLOAT"
169 gen_sampler_type "Cube" "GLSL_SAMPLER_DIM_CUBE" 0 0 "GLSL_TYPE_FLOAT"
170 gen_sampler_type "2DRect" "GLSL_SAMPLER_DIM_RECT" 0 0 "GLSL_TYPE_FLOAT"
171 gen_sampler_type "2DRect" "GLSL_SAMPLER_DIM_RECT" 1 0 "GLSL_TYPE_FLOAT"
172
173 gen_footer
174
175 echo
176 echo 'const glsl_type *const glsl_type::bool_type = & builtin_core_types['$bool_index'];'
177 echo 'const glsl_type *const glsl_type::int_type = & builtin_core_types['$int_index'];'
178 echo 'const glsl_type *const glsl_type::float_type = & builtin_core_types['$float_index'];'
179 echo 'const glsl_type *const glsl_type::mat2_type = & builtin_core_types['$(($matX_index + 0))'];'
180 echo 'const glsl_type *const glsl_type::mat3_type = & builtin_core_types['$(($matX_index + 1))'];'
181 echo 'const glsl_type *const glsl_type::mat4_type = & builtin_core_types['$(($matX_index + 2))'];'
182 echo '/*@}*/'
183
184 echo
185 echo '/** \name GLSL structures that have not been deprecated.'
186 echo ' */'
187 echo '/*@{*/'
188 gen_struct_field_header gl_DepthRangeParameters
189 gen_struct_field builtin_core_types 8 "near"
190 gen_struct_field builtin_core_types 8 "far"
191 gen_struct_field builtin_core_types 8 "diff"
192 gen_struct_field_footer
193
194 gen_header "structure"
195 gen_struct_type gl_DepthRangeParameters
196 gen_footer
197 echo '/*@}*/'
198
199 echo
200 echo '/** \name GLSL 1.00 / 1.10 structures that are deprecated in GLSL 1.30'
201 echo ' */'
202 echo '/*@{*/'
203 gen_struct_field_header gl_PointParameters
204 gen_struct_field builtin_core_types 8 "size"
205 gen_struct_field builtin_core_types 8 "sizeMin"
206 gen_struct_field builtin_core_types 8 "sizeMax"
207 gen_struct_field builtin_core_types 8 "fadeThresholdSize"
208 gen_struct_field builtin_core_types 8 "distanceConstantAttenuation"
209 gen_struct_field builtin_core_types 8 "distanceLinearAttenuation"
210 gen_struct_field builtin_core_types 8 "distanceQuadraticAttenuation"
211 gen_struct_field_footer
212
213 gen_struct_field_header gl_MaterialParameters
214 gen_struct_field builtin_core_types 11 "emission"
215 gen_struct_field builtin_core_types 11 "ambient"
216 gen_struct_field builtin_core_types 11 "diffuse"
217 gen_struct_field builtin_core_types 11 "specular"
218 gen_struct_field builtin_core_types 8 "shininess"
219 gen_struct_field_footer
220
221 gen_struct_field_header gl_LightSourceParameters
222 gen_struct_field builtin_core_types 11 "ambient"
223 gen_struct_field builtin_core_types 11 "diffuse"
224 gen_struct_field builtin_core_types 11 "specular"
225 gen_struct_field builtin_core_types 11 "position"
226 gen_struct_field builtin_core_types 11 "halfVector"
227 gen_struct_field builtin_core_types 10 "spotDirection"
228 gen_struct_field builtin_core_types 8 "spotExponent"
229 gen_struct_field builtin_core_types 8 "spotCutoff"
230 gen_struct_field builtin_core_types 8 "spotCosCutoff"
231 gen_struct_field builtin_core_types 8 "constantAttenuation"
232 gen_struct_field builtin_core_types 8 "linearAttenuation"
233 gen_struct_field builtin_core_types 8 "quadraticAttenuation"
234 gen_struct_field_footer
235
236 gen_struct_field_header gl_LightModelParameters
237 gen_struct_field builtin_core_types 11 "ambient"
238 gen_struct_field_footer
239
240 gen_struct_field_header gl_LightModelProducts
241 gen_struct_field builtin_core_types 11 "sceneColor"
242 gen_struct_field_footer
243
244 gen_struct_field_header gl_LightProducts
245 gen_struct_field builtin_core_types 11 "ambient"
246 gen_struct_field builtin_core_types 11 "diffuse"
247 gen_struct_field builtin_core_types 11 "specular"
248 gen_struct_field_footer
249
250 gen_struct_field_header gl_FogParameters
251 gen_struct_field builtin_core_types 11 "color"
252 gen_struct_field builtin_core_types 8 "density"
253 gen_struct_field builtin_core_types 8 "start"
254 gen_struct_field builtin_core_types 8 "end"
255 gen_struct_field builtin_core_types 8 "scale"
256 gen_struct_field_footer
257
258 gen_header "110_deprecated_structure"
259 gen_struct_type gl_PointParameters
260 gen_struct_type gl_MaterialParameters
261 gen_struct_type gl_LightSourceParameters
262 gen_struct_type gl_LightModelParameters
263 gen_struct_type gl_LightModelProducts
264 gen_struct_type gl_LightProducts
265 gen_struct_type gl_FogParameters
266 gen_footer
267 echo '/*@}*/'
268
269
270 echo
271 echo '/** \name Types added in GLSL 1.20'
272 echo ' */'
273 echo '/*@{*/'
274 gen_header "120"
275 for c in 2 3 4; do
276 for r in 2 3 4; do
277 if [ $c -ne $r ]; then
278 gen_integral_type "mat${c}x${r}" "GLSL_TYPE_FLOAT" $r $c
279 fi
280 done
281 done
282 gen_footer
283
284 echo 'const glsl_type *const glsl_type::mat2x3_type = & builtin_120_types[0];'
285 echo 'const glsl_type *const glsl_type::mat2x4_type = & builtin_120_types[1];'
286 echo 'const glsl_type *const glsl_type::mat3x2_type = & builtin_120_types[2];'
287 echo 'const glsl_type *const glsl_type::mat3x4_type = & builtin_120_types[3];'
288 echo 'const glsl_type *const glsl_type::mat4x2_type = & builtin_120_types[4];'
289 echo 'const glsl_type *const glsl_type::mat4x3_type = & builtin_120_types[5];'
290 echo '/*@}*/'
291 echo
292 echo '/** \name Types added in GLSL 1.30'
293 echo ' */'
294 echo '/*@{*/'
295 gen_header "130"
296 index=0;
297 uint_index=$index
298 gen_integral_type "uint" "GLSL_TYPE_UINT" 1 1
299 for i in 2 3 4; do
300 gen_integral_type "uvec$i" "GLSL_TYPE_UINT" $i 1
301 done
302
303 echo
304 echo " /* 1D and 2D texture arrays */"
305 for i in "1D" "2D"; do
306 gen_sampler_type $i "GLSL_SAMPLER_DIM_$i" 0 1 "GLSL_TYPE_FLOAT"
307 gen_sampler_type $i "GLSL_SAMPLER_DIM_$i" 0 1 "GLSL_TYPE_INT"
308 gen_sampler_type $i "GLSL_SAMPLER_DIM_$i" 0 1 "GLSL_TYPE_UINT"
309 gen_sampler_type $i "GLSL_SAMPLER_DIM_$i" 1 1 "GLSL_TYPE_FLOAT"
310 done
311
312 echo
313 echo " /* cube shadow samplers */"
314 gen_sampler_type "Cube" "GLSL_SAMPLER_DIM_CUBE" 1 0 "GLSL_TYPE_FLOAT"
315
316 echo
317 echo " /* signed and unsigned integer samplers */"
318 for i in "1D" "2D" "3D"; do
319 gen_sampler_type $i "GLSL_SAMPLER_DIM_$i" 0 0 "GLSL_TYPE_INT"
320 gen_sampler_type $i "GLSL_SAMPLER_DIM_$i" 0 0 "GLSL_TYPE_UINT"
321 done
322
323 gen_sampler_type "Cube" "GLSL_SAMPLER_DIM_CUBE" 0 0 "GLSL_TYPE_INT"
324 gen_sampler_type "Cube" "GLSL_SAMPLER_DIM_CUBE" 0 0 "GLSL_TYPE_UINT"
325
326 gen_footer
327 echo ''
328 echo 'const glsl_type *const glsl_type::uint_type = & builtin_130_types['$uint_index'];'
329 echo '/*@}*/'
330
331 echo
332 echo '/** \name Sampler types added by GL_EXT_texture_buffer_object'
333 echo ' */'
334 echo '/*@{*/'
335 gen_header "EXT_texture_buffer_object"
336 gen_sampler_type "Buffer" "GLSL_SAMPLER_DIM_BUF" 0 0 "GLSL_TYPE_FLOAT"
337 gen_sampler_type "Buffer" "GLSL_SAMPLER_DIM_BUF" 0 0 "GLSL_TYPE_INT"
338 gen_sampler_type "Buffer" "GLSL_SAMPLER_DIM_BUF" 0 0 "GLSL_TYPE_UINT"
339 gen_footer
340 echo '/*@}*/'