glsl: inspect interfaces in contains_foo()
[mesa.git] / src / compiler / glsl_types.cpp
1 /*
2 * Copyright © 2009 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
23
24 #include <stdio.h>
25 #include "main/macros.h"
26 #include "compiler/glsl/glsl_parser_extras.h"
27 #include "glsl_types.h"
28 #include "util/hash_table.h"
29
30
31 mtx_t glsl_type::mutex = _MTX_INITIALIZER_NP;
32 hash_table *glsl_type::array_types = NULL;
33 hash_table *glsl_type::record_types = NULL;
34 hash_table *glsl_type::interface_types = NULL;
35 hash_table *glsl_type::function_types = NULL;
36 hash_table *glsl_type::subroutine_types = NULL;
37 void *glsl_type::mem_ctx = NULL;
38
39 void
40 glsl_type::init_ralloc_type_ctx(void)
41 {
42 if (glsl_type::mem_ctx == NULL) {
43 glsl_type::mem_ctx = ralloc_autofree_context();
44 assert(glsl_type::mem_ctx != NULL);
45 }
46 }
47
48 glsl_type::glsl_type(GLenum gl_type,
49 glsl_base_type base_type, unsigned vector_elements,
50 unsigned matrix_columns, const char *name) :
51 gl_type(gl_type),
52 base_type(base_type),
53 sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
54 sampled_type(0), interface_packing(0), interface_row_major(0),
55 vector_elements(vector_elements), matrix_columns(matrix_columns),
56 length(0)
57 {
58 /* Values of these types must fit in the two bits of
59 * glsl_type::sampled_type.
60 */
61 STATIC_ASSERT((unsigned(GLSL_TYPE_UINT) & 3) == unsigned(GLSL_TYPE_UINT));
62 STATIC_ASSERT((unsigned(GLSL_TYPE_INT) & 3) == unsigned(GLSL_TYPE_INT));
63 STATIC_ASSERT((unsigned(GLSL_TYPE_FLOAT) & 3) == unsigned(GLSL_TYPE_FLOAT));
64
65 mtx_lock(&glsl_type::mutex);
66
67 init_ralloc_type_ctx();
68 assert(name != NULL);
69 this->name = ralloc_strdup(this->mem_ctx, name);
70
71 mtx_unlock(&glsl_type::mutex);
72
73 /* Neither dimension is zero or both dimensions are zero.
74 */
75 assert((vector_elements == 0) == (matrix_columns == 0));
76 memset(& fields, 0, sizeof(fields));
77 }
78
79 glsl_type::glsl_type(GLenum gl_type, glsl_base_type base_type,
80 enum glsl_sampler_dim dim, bool shadow, bool array,
81 unsigned type, const char *name) :
82 gl_type(gl_type),
83 base_type(base_type),
84 sampler_dimensionality(dim), sampler_shadow(shadow),
85 sampler_array(array), sampled_type(type), interface_packing(0),
86 interface_row_major(0), length(0)
87 {
88 mtx_lock(&glsl_type::mutex);
89
90 init_ralloc_type_ctx();
91 assert(name != NULL);
92 this->name = ralloc_strdup(this->mem_ctx, name);
93
94 mtx_unlock(&glsl_type::mutex);
95
96 memset(& fields, 0, sizeof(fields));
97
98 if (base_type == GLSL_TYPE_SAMPLER) {
99 /* Samplers take no storage whatsoever. */
100 matrix_columns = vector_elements = 0;
101 } else {
102 matrix_columns = vector_elements = 1;
103 }
104 }
105
106 glsl_type::glsl_type(const glsl_struct_field *fields, unsigned num_fields,
107 const char *name) :
108 gl_type(0),
109 base_type(GLSL_TYPE_STRUCT),
110 sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
111 sampled_type(0), interface_packing(0), interface_row_major(0),
112 vector_elements(0), matrix_columns(0),
113 length(num_fields)
114 {
115 unsigned int i;
116
117 mtx_lock(&glsl_type::mutex);
118
119 init_ralloc_type_ctx();
120 assert(name != NULL);
121 this->name = ralloc_strdup(this->mem_ctx, name);
122 this->fields.structure = ralloc_array(this->mem_ctx,
123 glsl_struct_field, length);
124
125 for (i = 0; i < length; i++) {
126 this->fields.structure[i].type = fields[i].type;
127 this->fields.structure[i].name = ralloc_strdup(this->fields.structure,
128 fields[i].name);
129 this->fields.structure[i].location = fields[i].location;
130 this->fields.structure[i].offset = fields[i].offset;
131 this->fields.structure[i].interpolation = fields[i].interpolation;
132 this->fields.structure[i].centroid = fields[i].centroid;
133 this->fields.structure[i].sample = fields[i].sample;
134 this->fields.structure[i].matrix_layout = fields[i].matrix_layout;
135 this->fields.structure[i].patch = fields[i].patch;
136 this->fields.structure[i].image_read_only = fields[i].image_read_only;
137 this->fields.structure[i].image_write_only = fields[i].image_write_only;
138 this->fields.structure[i].image_coherent = fields[i].image_coherent;
139 this->fields.structure[i].image_volatile = fields[i].image_volatile;
140 this->fields.structure[i].image_restrict = fields[i].image_restrict;
141 this->fields.structure[i].precision = fields[i].precision;
142 this->fields.structure[i].explicit_xfb_buffer =
143 fields[i].explicit_xfb_buffer;
144 this->fields.structure[i].xfb_buffer = fields[i].xfb_buffer;
145 this->fields.structure[i].xfb_stride = fields[i].xfb_stride;
146 }
147
148 mtx_unlock(&glsl_type::mutex);
149 }
150
151 glsl_type::glsl_type(const glsl_struct_field *fields, unsigned num_fields,
152 enum glsl_interface_packing packing,
153 bool row_major, const char *name) :
154 gl_type(0),
155 base_type(GLSL_TYPE_INTERFACE),
156 sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
157 sampled_type(0), interface_packing((unsigned) packing),
158 interface_row_major((unsigned) row_major),
159 vector_elements(0), matrix_columns(0),
160 length(num_fields)
161 {
162 unsigned int i;
163
164 mtx_lock(&glsl_type::mutex);
165
166 init_ralloc_type_ctx();
167 assert(name != NULL);
168 this->name = ralloc_strdup(this->mem_ctx, name);
169 this->fields.structure = ralloc_array(this->mem_ctx,
170 glsl_struct_field, length);
171 for (i = 0; i < length; i++) {
172 this->fields.structure[i].type = fields[i].type;
173 this->fields.structure[i].name = ralloc_strdup(this->fields.structure,
174 fields[i].name);
175 this->fields.structure[i].location = fields[i].location;
176 this->fields.structure[i].offset = fields[i].offset;
177 this->fields.structure[i].interpolation = fields[i].interpolation;
178 this->fields.structure[i].centroid = fields[i].centroid;
179 this->fields.structure[i].sample = fields[i].sample;
180 this->fields.structure[i].matrix_layout = fields[i].matrix_layout;
181 this->fields.structure[i].patch = fields[i].patch;
182 this->fields.structure[i].image_read_only = fields[i].image_read_only;
183 this->fields.structure[i].image_write_only = fields[i].image_write_only;
184 this->fields.structure[i].image_coherent = fields[i].image_coherent;
185 this->fields.structure[i].image_volatile = fields[i].image_volatile;
186 this->fields.structure[i].image_restrict = fields[i].image_restrict;
187 this->fields.structure[i].precision = fields[i].precision;
188 this->fields.structure[i].explicit_xfb_buffer =
189 fields[i].explicit_xfb_buffer;
190 this->fields.structure[i].xfb_buffer = fields[i].xfb_buffer;
191 this->fields.structure[i].xfb_stride = fields[i].xfb_stride;
192 }
193
194 mtx_unlock(&glsl_type::mutex);
195 }
196
197 glsl_type::glsl_type(const glsl_type *return_type,
198 const glsl_function_param *params, unsigned num_params) :
199 gl_type(0),
200 base_type(GLSL_TYPE_FUNCTION),
201 sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
202 sampled_type(0), interface_packing(0), interface_row_major(0),
203 vector_elements(0), matrix_columns(0),
204 length(num_params)
205 {
206 unsigned int i;
207
208 mtx_lock(&glsl_type::mutex);
209
210 init_ralloc_type_ctx();
211
212 this->fields.parameters = rzalloc_array(this->mem_ctx,
213 glsl_function_param, num_params + 1);
214
215 /* We store the return type as the first parameter */
216 this->fields.parameters[0].type = return_type;
217 this->fields.parameters[0].in = false;
218 this->fields.parameters[0].out = true;
219
220 /* We store the i'th parameter in slot i+1 */
221 for (i = 0; i < length; i++) {
222 this->fields.parameters[i + 1].type = params[i].type;
223 this->fields.parameters[i + 1].in = params[i].in;
224 this->fields.parameters[i + 1].out = params[i].out;
225 }
226
227 mtx_unlock(&glsl_type::mutex);
228 }
229
230 glsl_type::glsl_type(const char *subroutine_name) :
231 gl_type(0),
232 base_type(GLSL_TYPE_SUBROUTINE),
233 sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
234 sampled_type(0), interface_packing(0), interface_row_major(0),
235 vector_elements(1), matrix_columns(1),
236 length(0)
237 {
238 mtx_lock(&glsl_type::mutex);
239
240 init_ralloc_type_ctx();
241 assert(subroutine_name != NULL);
242 this->name = ralloc_strdup(this->mem_ctx, subroutine_name);
243 mtx_unlock(&glsl_type::mutex);
244 }
245
246 bool
247 glsl_type::contains_sampler() const
248 {
249 if (this->is_array()) {
250 return this->fields.array->contains_sampler();
251 } else if (this->is_record() || this->is_interface()) {
252 for (unsigned int i = 0; i < this->length; i++) {
253 if (this->fields.structure[i].type->contains_sampler())
254 return true;
255 }
256 return false;
257 } else {
258 return this->is_sampler();
259 }
260 }
261
262
263 bool
264 glsl_type::contains_integer() const
265 {
266 if (this->is_array()) {
267 return this->fields.array->contains_integer();
268 } else if (this->is_record() || this->is_interface()) {
269 for (unsigned int i = 0; i < this->length; i++) {
270 if (this->fields.structure[i].type->contains_integer())
271 return true;
272 }
273 return false;
274 } else {
275 return this->is_integer();
276 }
277 }
278
279 bool
280 glsl_type::contains_double() const
281 {
282 if (this->is_array()) {
283 return this->fields.array->contains_double();
284 } else if (this->is_record() || this->is_interface()) {
285 for (unsigned int i = 0; i < this->length; i++) {
286 if (this->fields.structure[i].type->contains_double())
287 return true;
288 }
289 return false;
290 } else {
291 return this->is_double();
292 }
293 }
294
295 bool
296 glsl_type::contains_opaque() const {
297 switch (base_type) {
298 case GLSL_TYPE_SAMPLER:
299 case GLSL_TYPE_IMAGE:
300 case GLSL_TYPE_ATOMIC_UINT:
301 return true;
302 case GLSL_TYPE_ARRAY:
303 return fields.array->contains_opaque();
304 case GLSL_TYPE_STRUCT:
305 case GLSL_TYPE_INTERFACE:
306 for (unsigned int i = 0; i < length; i++) {
307 if (fields.structure[i].type->contains_opaque())
308 return true;
309 }
310 return false;
311 default:
312 return false;
313 }
314 }
315
316 bool
317 glsl_type::contains_subroutine() const
318 {
319 if (this->is_array()) {
320 return this->fields.array->contains_subroutine();
321 } else if (this->is_record() || this->is_interface()) {
322 for (unsigned int i = 0; i < this->length; i++) {
323 if (this->fields.structure[i].type->contains_subroutine())
324 return true;
325 }
326 return false;
327 } else {
328 return this->is_subroutine();
329 }
330 }
331
332 gl_texture_index
333 glsl_type::sampler_index() const
334 {
335 const glsl_type *const t = (this->is_array()) ? this->fields.array : this;
336
337 assert(t->is_sampler());
338
339 switch (t->sampler_dimensionality) {
340 case GLSL_SAMPLER_DIM_1D:
341 return (t->sampler_array) ? TEXTURE_1D_ARRAY_INDEX : TEXTURE_1D_INDEX;
342 case GLSL_SAMPLER_DIM_2D:
343 return (t->sampler_array) ? TEXTURE_2D_ARRAY_INDEX : TEXTURE_2D_INDEX;
344 case GLSL_SAMPLER_DIM_3D:
345 return TEXTURE_3D_INDEX;
346 case GLSL_SAMPLER_DIM_CUBE:
347 return (t->sampler_array) ? TEXTURE_CUBE_ARRAY_INDEX : TEXTURE_CUBE_INDEX;
348 case GLSL_SAMPLER_DIM_RECT:
349 return TEXTURE_RECT_INDEX;
350 case GLSL_SAMPLER_DIM_BUF:
351 return TEXTURE_BUFFER_INDEX;
352 case GLSL_SAMPLER_DIM_EXTERNAL:
353 return TEXTURE_EXTERNAL_INDEX;
354 case GLSL_SAMPLER_DIM_MS:
355 return (t->sampler_array) ? TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX : TEXTURE_2D_MULTISAMPLE_INDEX;
356 default:
357 assert(!"Should not get here.");
358 return TEXTURE_BUFFER_INDEX;
359 }
360 }
361
362 bool
363 glsl_type::contains_image() const
364 {
365 if (this->is_array()) {
366 return this->fields.array->contains_image();
367 } else if (this->is_record() || this->is_interface()) {
368 for (unsigned int i = 0; i < this->length; i++) {
369 if (this->fields.structure[i].type->contains_image())
370 return true;
371 }
372 return false;
373 } else {
374 return this->is_image();
375 }
376 }
377
378 const glsl_type *glsl_type::get_base_type() const
379 {
380 switch (base_type) {
381 case GLSL_TYPE_UINT:
382 return uint_type;
383 case GLSL_TYPE_INT:
384 return int_type;
385 case GLSL_TYPE_FLOAT:
386 return float_type;
387 case GLSL_TYPE_DOUBLE:
388 return double_type;
389 case GLSL_TYPE_BOOL:
390 return bool_type;
391 default:
392 return error_type;
393 }
394 }
395
396
397 const glsl_type *glsl_type::get_scalar_type() const
398 {
399 const glsl_type *type = this;
400
401 /* Handle arrays */
402 while (type->base_type == GLSL_TYPE_ARRAY)
403 type = type->fields.array;
404
405 /* Handle vectors and matrices */
406 switch (type->base_type) {
407 case GLSL_TYPE_UINT:
408 return uint_type;
409 case GLSL_TYPE_INT:
410 return int_type;
411 case GLSL_TYPE_FLOAT:
412 return float_type;
413 case GLSL_TYPE_DOUBLE:
414 return double_type;
415 case GLSL_TYPE_BOOL:
416 return bool_type;
417 default:
418 /* Handle everything else */
419 return type;
420 }
421 }
422
423
424 void
425 _mesa_glsl_release_types(void)
426 {
427 /* Should only be called during atexit (either when unloading shared
428 * object, or if process terminates), so no mutex-locking should be
429 * necessary.
430 */
431 if (glsl_type::array_types != NULL) {
432 _mesa_hash_table_destroy(glsl_type::array_types, NULL);
433 glsl_type::array_types = NULL;
434 }
435
436 if (glsl_type::record_types != NULL) {
437 _mesa_hash_table_destroy(glsl_type::record_types, NULL);
438 glsl_type::record_types = NULL;
439 }
440
441 if (glsl_type::interface_types != NULL) {
442 _mesa_hash_table_destroy(glsl_type::interface_types, NULL);
443 glsl_type::interface_types = NULL;
444 }
445 }
446
447
448 glsl_type::glsl_type(const glsl_type *array, unsigned length) :
449 base_type(GLSL_TYPE_ARRAY),
450 sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
451 sampled_type(0), interface_packing(0), interface_row_major(0),
452 vector_elements(0), matrix_columns(0),
453 length(length), name(NULL)
454 {
455 this->fields.array = array;
456 /* Inherit the gl type of the base. The GL type is used for
457 * uniform/statevar handling in Mesa and the arrayness of the type
458 * is represented by the size rather than the type.
459 */
460 this->gl_type = array->gl_type;
461
462 /* Allow a maximum of 10 characters for the array size. This is enough
463 * for 32-bits of ~0. The extra 3 are for the '[', ']', and terminating
464 * NUL.
465 */
466 const unsigned name_length = strlen(array->name) + 10 + 3;
467
468 mtx_lock(&glsl_type::mutex);
469 char *const n = (char *) ralloc_size(this->mem_ctx, name_length);
470 mtx_unlock(&glsl_type::mutex);
471
472 if (length == 0)
473 snprintf(n, name_length, "%s[]", array->name);
474 else {
475 /* insert outermost dimensions in the correct spot
476 * otherwise the dimension order will be backwards
477 */
478 const char *pos = strchr(array->name, '[');
479 if (pos) {
480 int idx = pos - array->name;
481 snprintf(n, idx+1, "%s", array->name);
482 snprintf(n + idx, name_length - idx, "[%u]%s",
483 length, array->name + idx);
484 } else {
485 snprintf(n, name_length, "%s[%u]", array->name, length);
486 }
487 }
488
489 this->name = n;
490 }
491
492
493 const glsl_type *
494 glsl_type::vec(unsigned components)
495 {
496 if (components == 0 || components > 4)
497 return error_type;
498
499 static const glsl_type *const ts[] = {
500 float_type, vec2_type, vec3_type, vec4_type
501 };
502 return ts[components - 1];
503 }
504
505 const glsl_type *
506 glsl_type::dvec(unsigned components)
507 {
508 if (components == 0 || components > 4)
509 return error_type;
510
511 static const glsl_type *const ts[] = {
512 double_type, dvec2_type, dvec3_type, dvec4_type
513 };
514 return ts[components - 1];
515 }
516
517 const glsl_type *
518 glsl_type::ivec(unsigned components)
519 {
520 if (components == 0 || components > 4)
521 return error_type;
522
523 static const glsl_type *const ts[] = {
524 int_type, ivec2_type, ivec3_type, ivec4_type
525 };
526 return ts[components - 1];
527 }
528
529
530 const glsl_type *
531 glsl_type::uvec(unsigned components)
532 {
533 if (components == 0 || components > 4)
534 return error_type;
535
536 static const glsl_type *const ts[] = {
537 uint_type, uvec2_type, uvec3_type, uvec4_type
538 };
539 return ts[components - 1];
540 }
541
542
543 const glsl_type *
544 glsl_type::bvec(unsigned components)
545 {
546 if (components == 0 || components > 4)
547 return error_type;
548
549 static const glsl_type *const ts[] = {
550 bool_type, bvec2_type, bvec3_type, bvec4_type
551 };
552 return ts[components - 1];
553 }
554
555
556 const glsl_type *
557 glsl_type::get_instance(unsigned base_type, unsigned rows, unsigned columns)
558 {
559 if (base_type == GLSL_TYPE_VOID)
560 return void_type;
561
562 if ((rows < 1) || (rows > 4) || (columns < 1) || (columns > 4))
563 return error_type;
564
565 /* Treat GLSL vectors as Nx1 matrices.
566 */
567 if (columns == 1) {
568 switch (base_type) {
569 case GLSL_TYPE_UINT:
570 return uvec(rows);
571 case GLSL_TYPE_INT:
572 return ivec(rows);
573 case GLSL_TYPE_FLOAT:
574 return vec(rows);
575 case GLSL_TYPE_DOUBLE:
576 return dvec(rows);
577 case GLSL_TYPE_BOOL:
578 return bvec(rows);
579 default:
580 return error_type;
581 }
582 } else {
583 if ((base_type != GLSL_TYPE_FLOAT && base_type != GLSL_TYPE_DOUBLE) || (rows == 1))
584 return error_type;
585
586 /* GLSL matrix types are named mat{COLUMNS}x{ROWS}. Only the following
587 * combinations are valid:
588 *
589 * 1 2 3 4
590 * 1
591 * 2 x x x
592 * 3 x x x
593 * 4 x x x
594 */
595 #define IDX(c,r) (((c-1)*3) + (r-1))
596
597 if (base_type == GLSL_TYPE_DOUBLE) {
598 switch (IDX(columns, rows)) {
599 case IDX(2,2): return dmat2_type;
600 case IDX(2,3): return dmat2x3_type;
601 case IDX(2,4): return dmat2x4_type;
602 case IDX(3,2): return dmat3x2_type;
603 case IDX(3,3): return dmat3_type;
604 case IDX(3,4): return dmat3x4_type;
605 case IDX(4,2): return dmat4x2_type;
606 case IDX(4,3): return dmat4x3_type;
607 case IDX(4,4): return dmat4_type;
608 default: return error_type;
609 }
610 } else {
611 switch (IDX(columns, rows)) {
612 case IDX(2,2): return mat2_type;
613 case IDX(2,3): return mat2x3_type;
614 case IDX(2,4): return mat2x4_type;
615 case IDX(3,2): return mat3x2_type;
616 case IDX(3,3): return mat3_type;
617 case IDX(3,4): return mat3x4_type;
618 case IDX(4,2): return mat4x2_type;
619 case IDX(4,3): return mat4x3_type;
620 case IDX(4,4): return mat4_type;
621 default: return error_type;
622 }
623 }
624 }
625
626 assert(!"Should not get here.");
627 return error_type;
628 }
629
630 const glsl_type *
631 glsl_type::get_sampler_instance(enum glsl_sampler_dim dim,
632 bool shadow,
633 bool array,
634 glsl_base_type type)
635 {
636 switch (type) {
637 case GLSL_TYPE_FLOAT:
638 switch (dim) {
639 case GLSL_SAMPLER_DIM_1D:
640 if (shadow)
641 return (array ? sampler1DArrayShadow_type : sampler1DShadow_type);
642 else
643 return (array ? sampler1DArray_type : sampler1D_type);
644 case GLSL_SAMPLER_DIM_2D:
645 if (shadow)
646 return (array ? sampler2DArrayShadow_type : sampler2DShadow_type);
647 else
648 return (array ? sampler2DArray_type : sampler2D_type);
649 case GLSL_SAMPLER_DIM_3D:
650 if (shadow || array)
651 return error_type;
652 else
653 return sampler3D_type;
654 case GLSL_SAMPLER_DIM_CUBE:
655 if (shadow)
656 return (array ? samplerCubeArrayShadow_type : samplerCubeShadow_type);
657 else
658 return (array ? samplerCubeArray_type : samplerCube_type);
659 case GLSL_SAMPLER_DIM_RECT:
660 if (array)
661 return error_type;
662 if (shadow)
663 return sampler2DRectShadow_type;
664 else
665 return sampler2DRect_type;
666 case GLSL_SAMPLER_DIM_BUF:
667 if (shadow || array)
668 return error_type;
669 else
670 return samplerBuffer_type;
671 case GLSL_SAMPLER_DIM_MS:
672 if (shadow)
673 return error_type;
674 return (array ? sampler2DMSArray_type : sampler2DMS_type);
675 case GLSL_SAMPLER_DIM_EXTERNAL:
676 if (shadow || array)
677 return error_type;
678 else
679 return samplerExternalOES_type;
680 case GLSL_SAMPLER_DIM_SUBPASS:
681 return error_type;
682 }
683 case GLSL_TYPE_INT:
684 if (shadow)
685 return error_type;
686 switch (dim) {
687 case GLSL_SAMPLER_DIM_1D:
688 return (array ? isampler1DArray_type : isampler1D_type);
689 case GLSL_SAMPLER_DIM_2D:
690 return (array ? isampler2DArray_type : isampler2D_type);
691 case GLSL_SAMPLER_DIM_3D:
692 if (array)
693 return error_type;
694 return isampler3D_type;
695 case GLSL_SAMPLER_DIM_CUBE:
696 return (array ? isamplerCubeArray_type : isamplerCube_type);
697 case GLSL_SAMPLER_DIM_RECT:
698 if (array)
699 return error_type;
700 return isampler2DRect_type;
701 case GLSL_SAMPLER_DIM_BUF:
702 if (array)
703 return error_type;
704 return isamplerBuffer_type;
705 case GLSL_SAMPLER_DIM_MS:
706 return (array ? isampler2DMSArray_type : isampler2DMS_type);
707 case GLSL_SAMPLER_DIM_EXTERNAL:
708 return error_type;
709 case GLSL_SAMPLER_DIM_SUBPASS:
710 return error_type;
711 }
712 case GLSL_TYPE_UINT:
713 if (shadow)
714 return error_type;
715 switch (dim) {
716 case GLSL_SAMPLER_DIM_1D:
717 return (array ? usampler1DArray_type : usampler1D_type);
718 case GLSL_SAMPLER_DIM_2D:
719 return (array ? usampler2DArray_type : usampler2D_type);
720 case GLSL_SAMPLER_DIM_3D:
721 if (array)
722 return error_type;
723 return usampler3D_type;
724 case GLSL_SAMPLER_DIM_CUBE:
725 return (array ? usamplerCubeArray_type : usamplerCube_type);
726 case GLSL_SAMPLER_DIM_RECT:
727 if (array)
728 return error_type;
729 return usampler2DRect_type;
730 case GLSL_SAMPLER_DIM_BUF:
731 if (array)
732 return error_type;
733 return usamplerBuffer_type;
734 case GLSL_SAMPLER_DIM_MS:
735 return (array ? usampler2DMSArray_type : usampler2DMS_type);
736 case GLSL_SAMPLER_DIM_EXTERNAL:
737 return error_type;
738 case GLSL_SAMPLER_DIM_SUBPASS:
739 return error_type;
740 }
741 default:
742 return error_type;
743 }
744
745 unreachable("switch statement above should be complete");
746 }
747
748 const glsl_type *
749 glsl_type::get_image_instance(enum glsl_sampler_dim dim,
750 bool array, glsl_base_type type)
751 {
752 if (dim == GLSL_SAMPLER_DIM_SUBPASS)
753 return subpassInput_type;
754 switch (type) {
755 case GLSL_TYPE_FLOAT:
756 switch (dim) {
757 case GLSL_SAMPLER_DIM_1D:
758 return (array ? image1DArray_type : image1D_type);
759 case GLSL_SAMPLER_DIM_2D:
760 return (array ? image2DArray_type : image2D_type);
761 case GLSL_SAMPLER_DIM_3D:
762 return image3D_type;
763 case GLSL_SAMPLER_DIM_CUBE:
764 return (array ? imageCubeArray_type : imageCube_type);
765 case GLSL_SAMPLER_DIM_RECT:
766 if (array)
767 return error_type;
768 else
769 return image2DRect_type;
770 case GLSL_SAMPLER_DIM_BUF:
771 if (array)
772 return error_type;
773 else
774 return imageBuffer_type;
775 case GLSL_SAMPLER_DIM_MS:
776 return (array ? image2DMSArray_type : image2DMS_type);
777 case GLSL_SAMPLER_DIM_EXTERNAL:
778 case GLSL_SAMPLER_DIM_SUBPASS:
779 return error_type;
780 }
781 case GLSL_TYPE_INT:
782 switch (dim) {
783 case GLSL_SAMPLER_DIM_1D:
784 return (array ? iimage1DArray_type : iimage1D_type);
785 case GLSL_SAMPLER_DIM_2D:
786 return (array ? iimage2DArray_type : iimage2D_type);
787 case GLSL_SAMPLER_DIM_3D:
788 if (array)
789 return error_type;
790 return iimage3D_type;
791 case GLSL_SAMPLER_DIM_CUBE:
792 return (array ? iimageCubeArray_type : iimageCube_type);
793 case GLSL_SAMPLER_DIM_RECT:
794 if (array)
795 return error_type;
796 return iimage2DRect_type;
797 case GLSL_SAMPLER_DIM_BUF:
798 if (array)
799 return error_type;
800 return iimageBuffer_type;
801 case GLSL_SAMPLER_DIM_MS:
802 return (array ? iimage2DMSArray_type : iimage2DMS_type);
803 case GLSL_SAMPLER_DIM_EXTERNAL:
804 case GLSL_SAMPLER_DIM_SUBPASS:
805 return error_type;
806 }
807 case GLSL_TYPE_UINT:
808 switch (dim) {
809 case GLSL_SAMPLER_DIM_1D:
810 return (array ? uimage1DArray_type : uimage1D_type);
811 case GLSL_SAMPLER_DIM_2D:
812 return (array ? uimage2DArray_type : uimage2D_type);
813 case GLSL_SAMPLER_DIM_3D:
814 if (array)
815 return error_type;
816 return uimage3D_type;
817 case GLSL_SAMPLER_DIM_CUBE:
818 return (array ? uimageCubeArray_type : uimageCube_type);
819 case GLSL_SAMPLER_DIM_RECT:
820 if (array)
821 return error_type;
822 return uimage2DRect_type;
823 case GLSL_SAMPLER_DIM_BUF:
824 if (array)
825 return error_type;
826 return uimageBuffer_type;
827 case GLSL_SAMPLER_DIM_MS:
828 return (array ? uimage2DMSArray_type : uimage2DMS_type);
829 case GLSL_SAMPLER_DIM_EXTERNAL:
830 case GLSL_SAMPLER_DIM_SUBPASS:
831 return error_type;
832 }
833 default:
834 return error_type;
835 }
836
837 unreachable("switch statement above should be complete");
838 }
839
840 const glsl_type *
841 glsl_type::get_array_instance(const glsl_type *base, unsigned array_size)
842 {
843 /* Generate a name using the base type pointer in the key. This is
844 * done because the name of the base type may not be unique across
845 * shaders. For example, two shaders may have different record types
846 * named 'foo'.
847 */
848 char key[128];
849 snprintf(key, sizeof(key), "%p[%u]", (void *) base, array_size);
850
851 mtx_lock(&glsl_type::mutex);
852
853 if (array_types == NULL) {
854 array_types = _mesa_hash_table_create(NULL, _mesa_key_hash_string,
855 _mesa_key_string_equal);
856 }
857
858 const struct hash_entry *entry = _mesa_hash_table_search(array_types, key);
859 if (entry == NULL) {
860 mtx_unlock(&glsl_type::mutex);
861 const glsl_type *t = new glsl_type(base, array_size);
862 mtx_lock(&glsl_type::mutex);
863
864 entry = _mesa_hash_table_insert(array_types,
865 ralloc_strdup(mem_ctx, key),
866 (void *) t);
867 }
868
869 assert(((glsl_type *) entry->data)->base_type == GLSL_TYPE_ARRAY);
870 assert(((glsl_type *) entry->data)->length == array_size);
871 assert(((glsl_type *) entry->data)->fields.array == base);
872
873 mtx_unlock(&glsl_type::mutex);
874
875 return (glsl_type *) entry->data;
876 }
877
878
879 bool
880 glsl_type::record_compare(const glsl_type *b, bool match_locations) const
881 {
882 if (this->length != b->length)
883 return false;
884
885 if (this->interface_packing != b->interface_packing)
886 return false;
887
888 if (this->interface_row_major != b->interface_row_major)
889 return false;
890
891 /* From the GLSL 4.20 specification (Sec 4.2):
892 *
893 * "Structures must have the same name, sequence of type names, and
894 * type definitions, and field names to be considered the same type."
895 *
896 * GLSL ES behaves the same (Ver 1.00 Sec 4.2.4, Ver 3.00 Sec 4.2.5).
897 *
898 * Note that we cannot force type name check when comparing unnamed
899 * structure types, these have a unique name assigned during parsing.
900 */
901 if (!this->is_anonymous() && !b->is_anonymous())
902 if (strcmp(this->name, b->name) != 0)
903 return false;
904
905 for (unsigned i = 0; i < this->length; i++) {
906 if (this->fields.structure[i].type != b->fields.structure[i].type)
907 return false;
908 if (strcmp(this->fields.structure[i].name,
909 b->fields.structure[i].name) != 0)
910 return false;
911 if (this->fields.structure[i].matrix_layout
912 != b->fields.structure[i].matrix_layout)
913 return false;
914 if (match_locations && this->fields.structure[i].location
915 != b->fields.structure[i].location)
916 return false;
917 if (this->fields.structure[i].offset
918 != b->fields.structure[i].offset)
919 return false;
920 if (this->fields.structure[i].interpolation
921 != b->fields.structure[i].interpolation)
922 return false;
923 if (this->fields.structure[i].centroid
924 != b->fields.structure[i].centroid)
925 return false;
926 if (this->fields.structure[i].sample
927 != b->fields.structure[i].sample)
928 return false;
929 if (this->fields.structure[i].patch
930 != b->fields.structure[i].patch)
931 return false;
932 if (this->fields.structure[i].image_read_only
933 != b->fields.structure[i].image_read_only)
934 return false;
935 if (this->fields.structure[i].image_write_only
936 != b->fields.structure[i].image_write_only)
937 return false;
938 if (this->fields.structure[i].image_coherent
939 != b->fields.structure[i].image_coherent)
940 return false;
941 if (this->fields.structure[i].image_volatile
942 != b->fields.structure[i].image_volatile)
943 return false;
944 if (this->fields.structure[i].image_restrict
945 != b->fields.structure[i].image_restrict)
946 return false;
947 if (this->fields.structure[i].precision
948 != b->fields.structure[i].precision)
949 return false;
950 if (this->fields.structure[i].explicit_xfb_buffer
951 != b->fields.structure[i].explicit_xfb_buffer)
952 return false;
953 if (this->fields.structure[i].xfb_buffer
954 != b->fields.structure[i].xfb_buffer)
955 return false;
956 if (this->fields.structure[i].xfb_stride
957 != b->fields.structure[i].xfb_stride)
958 return false;
959 }
960
961 return true;
962 }
963
964
965 bool
966 glsl_type::record_key_compare(const void *a, const void *b)
967 {
968 const glsl_type *const key1 = (glsl_type *) a;
969 const glsl_type *const key2 = (glsl_type *) b;
970
971 return strcmp(key1->name, key2->name) == 0 && key1->record_compare(key2);
972 }
973
974
975 /**
976 * Generate an integer hash value for a glsl_type structure type.
977 */
978 unsigned
979 glsl_type::record_key_hash(const void *a)
980 {
981 const glsl_type *const key = (glsl_type *) a;
982 uintptr_t hash = key->length;
983 unsigned retval;
984
985 for (unsigned i = 0; i < key->length; i++) {
986 /* casting pointer to uintptr_t */
987 hash = (hash * 13 ) + (uintptr_t) key->fields.structure[i].type;
988 }
989
990 if (sizeof(hash) == 8)
991 retval = (hash & 0xffffffff) ^ ((uint64_t) hash >> 32);
992 else
993 retval = hash;
994
995 return retval;
996 }
997
998
999 const glsl_type *
1000 glsl_type::get_record_instance(const glsl_struct_field *fields,
1001 unsigned num_fields,
1002 const char *name)
1003 {
1004 const glsl_type key(fields, num_fields, name);
1005
1006 mtx_lock(&glsl_type::mutex);
1007
1008 if (record_types == NULL) {
1009 record_types = _mesa_hash_table_create(NULL, record_key_hash,
1010 record_key_compare);
1011 }
1012
1013 const struct hash_entry *entry = _mesa_hash_table_search(record_types,
1014 &key);
1015 if (entry == NULL) {
1016 mtx_unlock(&glsl_type::mutex);
1017 const glsl_type *t = new glsl_type(fields, num_fields, name);
1018 mtx_lock(&glsl_type::mutex);
1019
1020 entry = _mesa_hash_table_insert(record_types, t, (void *) t);
1021 }
1022
1023 assert(((glsl_type *) entry->data)->base_type == GLSL_TYPE_STRUCT);
1024 assert(((glsl_type *) entry->data)->length == num_fields);
1025 assert(strcmp(((glsl_type *) entry->data)->name, name) == 0);
1026
1027 mtx_unlock(&glsl_type::mutex);
1028
1029 return (glsl_type *) entry->data;
1030 }
1031
1032
1033 const glsl_type *
1034 glsl_type::get_interface_instance(const glsl_struct_field *fields,
1035 unsigned num_fields,
1036 enum glsl_interface_packing packing,
1037 bool row_major,
1038 const char *block_name)
1039 {
1040 const glsl_type key(fields, num_fields, packing, row_major, block_name);
1041
1042 mtx_lock(&glsl_type::mutex);
1043
1044 if (interface_types == NULL) {
1045 interface_types = _mesa_hash_table_create(NULL, record_key_hash,
1046 record_key_compare);
1047 }
1048
1049 const struct hash_entry *entry = _mesa_hash_table_search(interface_types,
1050 &key);
1051 if (entry == NULL) {
1052 mtx_unlock(&glsl_type::mutex);
1053 const glsl_type *t = new glsl_type(fields, num_fields,
1054 packing, row_major, block_name);
1055 mtx_lock(&glsl_type::mutex);
1056
1057 entry = _mesa_hash_table_insert(interface_types, t, (void *) t);
1058 }
1059
1060 assert(((glsl_type *) entry->data)->base_type == GLSL_TYPE_INTERFACE);
1061 assert(((glsl_type *) entry->data)->length == num_fields);
1062 assert(strcmp(((glsl_type *) entry->data)->name, block_name) == 0);
1063
1064 mtx_unlock(&glsl_type::mutex);
1065
1066 return (glsl_type *) entry->data;
1067 }
1068
1069 const glsl_type *
1070 glsl_type::get_subroutine_instance(const char *subroutine_name)
1071 {
1072 const glsl_type key(subroutine_name);
1073
1074 mtx_lock(&glsl_type::mutex);
1075
1076 if (subroutine_types == NULL) {
1077 subroutine_types = _mesa_hash_table_create(NULL, record_key_hash,
1078 record_key_compare);
1079 }
1080
1081 const struct hash_entry *entry = _mesa_hash_table_search(subroutine_types,
1082 &key);
1083 if (entry == NULL) {
1084 mtx_unlock(&glsl_type::mutex);
1085 const glsl_type *t = new glsl_type(subroutine_name);
1086 mtx_lock(&glsl_type::mutex);
1087
1088 entry = _mesa_hash_table_insert(subroutine_types, t, (void *) t);
1089 }
1090
1091 assert(((glsl_type *) entry->data)->base_type == GLSL_TYPE_SUBROUTINE);
1092 assert(strcmp(((glsl_type *) entry->data)->name, subroutine_name) == 0);
1093
1094 mtx_unlock(&glsl_type::mutex);
1095
1096 return (glsl_type *) entry->data;
1097 }
1098
1099
1100 static bool
1101 function_key_compare(const void *a, const void *b)
1102 {
1103 const glsl_type *const key1 = (glsl_type *) a;
1104 const glsl_type *const key2 = (glsl_type *) b;
1105
1106 if (key1->length != key2->length)
1107 return false;
1108
1109 return memcmp(key1->fields.parameters, key2->fields.parameters,
1110 (key1->length + 1) * sizeof(*key1->fields.parameters)) == 0;
1111 }
1112
1113
1114 static uint32_t
1115 function_key_hash(const void *a)
1116 {
1117 const glsl_type *const key = (glsl_type *) a;
1118 return _mesa_hash_data(key->fields.parameters,
1119 (key->length + 1) * sizeof(*key->fields.parameters));
1120 }
1121
1122 const glsl_type *
1123 glsl_type::get_function_instance(const glsl_type *return_type,
1124 const glsl_function_param *params,
1125 unsigned num_params)
1126 {
1127 const glsl_type key(return_type, params, num_params);
1128
1129 mtx_lock(&glsl_type::mutex);
1130
1131 if (function_types == NULL) {
1132 function_types = _mesa_hash_table_create(NULL, function_key_hash,
1133 function_key_compare);
1134 }
1135
1136 struct hash_entry *entry = _mesa_hash_table_search(function_types, &key);
1137 if (entry == NULL) {
1138 mtx_unlock(&glsl_type::mutex);
1139 const glsl_type *t = new glsl_type(return_type, params, num_params);
1140 mtx_lock(&glsl_type::mutex);
1141
1142 entry = _mesa_hash_table_insert(function_types, t, (void *) t);
1143 }
1144
1145 const glsl_type *t = (const glsl_type *)entry->data;
1146
1147 assert(t->base_type == GLSL_TYPE_FUNCTION);
1148 assert(t->length == num_params);
1149
1150 mtx_unlock(&glsl_type::mutex);
1151
1152 return t;
1153 }
1154
1155
1156 const glsl_type *
1157 glsl_type::get_mul_type(const glsl_type *type_a, const glsl_type *type_b)
1158 {
1159 if (type_a == type_b) {
1160 return type_a;
1161 } else if (type_a->is_matrix() && type_b->is_matrix()) {
1162 /* Matrix multiply. The columns of A must match the rows of B. Given
1163 * the other previously tested constraints, this means the vector type
1164 * of a row from A must be the same as the vector type of a column from
1165 * B.
1166 */
1167 if (type_a->row_type() == type_b->column_type()) {
1168 /* The resulting matrix has the number of columns of matrix B and
1169 * the number of rows of matrix A. We get the row count of A by
1170 * looking at the size of a vector that makes up a column. The
1171 * transpose (size of a row) is done for B.
1172 */
1173 const glsl_type *const type =
1174 get_instance(type_a->base_type,
1175 type_a->column_type()->vector_elements,
1176 type_b->row_type()->vector_elements);
1177 assert(type != error_type);
1178
1179 return type;
1180 }
1181 } else if (type_a->is_matrix()) {
1182 /* A is a matrix and B is a column vector. Columns of A must match
1183 * rows of B. Given the other previously tested constraints, this
1184 * means the vector type of a row from A must be the same as the
1185 * vector the type of B.
1186 */
1187 if (type_a->row_type() == type_b) {
1188 /* The resulting vector has a number of elements equal to
1189 * the number of rows of matrix A. */
1190 const glsl_type *const type =
1191 get_instance(type_a->base_type,
1192 type_a->column_type()->vector_elements,
1193 1);
1194 assert(type != error_type);
1195
1196 return type;
1197 }
1198 } else {
1199 assert(type_b->is_matrix());
1200
1201 /* A is a row vector and B is a matrix. Columns of A must match rows
1202 * of B. Given the other previously tested constraints, this means
1203 * the type of A must be the same as the vector type of a column from
1204 * B.
1205 */
1206 if (type_a == type_b->column_type()) {
1207 /* The resulting vector has a number of elements equal to
1208 * the number of columns of matrix B. */
1209 const glsl_type *const type =
1210 get_instance(type_a->base_type,
1211 type_b->row_type()->vector_elements,
1212 1);
1213 assert(type != error_type);
1214
1215 return type;
1216 }
1217 }
1218
1219 return error_type;
1220 }
1221
1222
1223 const glsl_type *
1224 glsl_type::field_type(const char *name) const
1225 {
1226 if (this->base_type != GLSL_TYPE_STRUCT
1227 && this->base_type != GLSL_TYPE_INTERFACE)
1228 return error_type;
1229
1230 for (unsigned i = 0; i < this->length; i++) {
1231 if (strcmp(name, this->fields.structure[i].name) == 0)
1232 return this->fields.structure[i].type;
1233 }
1234
1235 return error_type;
1236 }
1237
1238
1239 int
1240 glsl_type::field_index(const char *name) const
1241 {
1242 if (this->base_type != GLSL_TYPE_STRUCT
1243 && this->base_type != GLSL_TYPE_INTERFACE)
1244 return -1;
1245
1246 for (unsigned i = 0; i < this->length; i++) {
1247 if (strcmp(name, this->fields.structure[i].name) == 0)
1248 return i;
1249 }
1250
1251 return -1;
1252 }
1253
1254
1255 unsigned
1256 glsl_type::component_slots() const
1257 {
1258 switch (this->base_type) {
1259 case GLSL_TYPE_UINT:
1260 case GLSL_TYPE_INT:
1261 case GLSL_TYPE_FLOAT:
1262 case GLSL_TYPE_BOOL:
1263 return this->components();
1264
1265 case GLSL_TYPE_DOUBLE:
1266 return 2 * this->components();
1267
1268 case GLSL_TYPE_STRUCT:
1269 case GLSL_TYPE_INTERFACE: {
1270 unsigned size = 0;
1271
1272 for (unsigned i = 0; i < this->length; i++)
1273 size += this->fields.structure[i].type->component_slots();
1274
1275 return size;
1276 }
1277
1278 case GLSL_TYPE_ARRAY:
1279 return this->length * this->fields.array->component_slots();
1280
1281 case GLSL_TYPE_IMAGE:
1282 return 1;
1283 case GLSL_TYPE_SUBROUTINE:
1284 return 1;
1285
1286 case GLSL_TYPE_FUNCTION:
1287 case GLSL_TYPE_SAMPLER:
1288 case GLSL_TYPE_ATOMIC_UINT:
1289 case GLSL_TYPE_VOID:
1290 case GLSL_TYPE_ERROR:
1291 break;
1292 }
1293
1294 return 0;
1295 }
1296
1297 unsigned
1298 glsl_type::record_location_offset(unsigned length) const
1299 {
1300 unsigned offset = 0;
1301 const glsl_type *t = this->without_array();
1302 if (t->is_record()) {
1303 assert(length <= t->length);
1304
1305 for (unsigned i = 0; i < length; i++) {
1306 const glsl_type *st = t->fields.structure[i].type;
1307 const glsl_type *wa = st->without_array();
1308 if (wa->is_record()) {
1309 unsigned r_offset = wa->record_location_offset(wa->length);
1310 offset += st->is_array() ?
1311 st->arrays_of_arrays_size() * r_offset : r_offset;
1312 } else if (st->is_array() && st->fields.array->is_array()) {
1313 unsigned outer_array_size = st->length;
1314 const glsl_type *base_type = st->fields.array;
1315
1316 /* For arrays of arrays the outer arrays take up a uniform
1317 * slot for each element. The innermost array elements share a
1318 * single slot so we ignore the innermost array when calculating
1319 * the offset.
1320 */
1321 while (base_type->fields.array->is_array()) {
1322 outer_array_size = outer_array_size * base_type->length;
1323 base_type = base_type->fields.array;
1324 }
1325 offset += outer_array_size;
1326 } else {
1327 /* We dont worry about arrays here because unless the array
1328 * contains a structure or another array it only takes up a single
1329 * uniform slot.
1330 */
1331 offset += 1;
1332 }
1333 }
1334 }
1335 return offset;
1336 }
1337
1338 unsigned
1339 glsl_type::uniform_locations() const
1340 {
1341 unsigned size = 0;
1342
1343 switch (this->base_type) {
1344 case GLSL_TYPE_UINT:
1345 case GLSL_TYPE_INT:
1346 case GLSL_TYPE_FLOAT:
1347 case GLSL_TYPE_DOUBLE:
1348 case GLSL_TYPE_BOOL:
1349 case GLSL_TYPE_SAMPLER:
1350 case GLSL_TYPE_IMAGE:
1351 case GLSL_TYPE_SUBROUTINE:
1352 return 1;
1353
1354 case GLSL_TYPE_STRUCT:
1355 case GLSL_TYPE_INTERFACE:
1356 for (unsigned i = 0; i < this->length; i++)
1357 size += this->fields.structure[i].type->uniform_locations();
1358 return size;
1359 case GLSL_TYPE_ARRAY:
1360 return this->length * this->fields.array->uniform_locations();
1361 default:
1362 return 0;
1363 }
1364 }
1365
1366 unsigned
1367 glsl_type::varying_count() const
1368 {
1369 unsigned size = 0;
1370
1371 switch (this->base_type) {
1372 case GLSL_TYPE_UINT:
1373 case GLSL_TYPE_INT:
1374 case GLSL_TYPE_FLOAT:
1375 case GLSL_TYPE_DOUBLE:
1376 case GLSL_TYPE_BOOL:
1377 return 1;
1378
1379 case GLSL_TYPE_STRUCT:
1380 case GLSL_TYPE_INTERFACE:
1381 for (unsigned i = 0; i < this->length; i++)
1382 size += this->fields.structure[i].type->varying_count();
1383 return size;
1384 case GLSL_TYPE_ARRAY:
1385 /* Don't count innermost array elements */
1386 if (this->without_array()->is_record() ||
1387 this->without_array()->is_interface() ||
1388 this->fields.array->is_array())
1389 return this->length * this->fields.array->varying_count();
1390 else
1391 return this->fields.array->varying_count();
1392 default:
1393 assert(!"unsupported varying type");
1394 return 0;
1395 }
1396 }
1397
1398 bool
1399 glsl_type::can_implicitly_convert_to(const glsl_type *desired,
1400 _mesa_glsl_parse_state *state) const
1401 {
1402 if (this == desired)
1403 return true;
1404
1405 /* GLSL 1.10 and ESSL do not allow implicit conversions. If there is no
1406 * state, we're doing intra-stage function linking where these checks have
1407 * already been done.
1408 */
1409 if (state && (state->es_shader || !state->is_version(120, 0)))
1410 return false;
1411
1412 /* There is no conversion among matrix types. */
1413 if (this->matrix_columns > 1 || desired->matrix_columns > 1)
1414 return false;
1415
1416 /* Vector size must match. */
1417 if (this->vector_elements != desired->vector_elements)
1418 return false;
1419
1420 /* int and uint can be converted to float. */
1421 if (desired->is_float() && this->is_integer())
1422 return true;
1423
1424 /* With GLSL 4.0, ARB_gpu_shader5, or MESA_shader_integer_functions, int
1425 * can be converted to uint. Note that state may be NULL here, when
1426 * resolving function calls in the linker. By this time, all the
1427 * state-dependent checks have already happened though, so allow anything
1428 * that's allowed in any shader version.
1429 */
1430 if ((!state || state->is_version(400, 0) || state->ARB_gpu_shader5_enable ||
1431 state->MESA_shader_integer_functions_enable) &&
1432 desired->base_type == GLSL_TYPE_UINT && this->base_type == GLSL_TYPE_INT)
1433 return true;
1434
1435 /* No implicit conversions from double. */
1436 if ((!state || state->has_double()) && this->is_double())
1437 return false;
1438
1439 /* Conversions from different types to double. */
1440 if ((!state || state->has_double()) && desired->is_double()) {
1441 if (this->is_float())
1442 return true;
1443 if (this->is_integer())
1444 return true;
1445 }
1446
1447 return false;
1448 }
1449
1450 unsigned
1451 glsl_type::std140_base_alignment(bool row_major) const
1452 {
1453 unsigned N = is_64bit() ? 8 : 4;
1454
1455 /* (1) If the member is a scalar consuming <N> basic machine units, the
1456 * base alignment is <N>.
1457 *
1458 * (2) If the member is a two- or four-component vector with components
1459 * consuming <N> basic machine units, the base alignment is 2<N> or
1460 * 4<N>, respectively.
1461 *
1462 * (3) If the member is a three-component vector with components consuming
1463 * <N> basic machine units, the base alignment is 4<N>.
1464 */
1465 if (this->is_scalar() || this->is_vector()) {
1466 switch (this->vector_elements) {
1467 case 1:
1468 return N;
1469 case 2:
1470 return 2 * N;
1471 case 3:
1472 case 4:
1473 return 4 * N;
1474 }
1475 }
1476
1477 /* (4) If the member is an array of scalars or vectors, the base alignment
1478 * and array stride are set to match the base alignment of a single
1479 * array element, according to rules (1), (2), and (3), and rounded up
1480 * to the base alignment of a vec4. The array may have padding at the
1481 * end; the base offset of the member following the array is rounded up
1482 * to the next multiple of the base alignment.
1483 *
1484 * (6) If the member is an array of <S> column-major matrices with <C>
1485 * columns and <R> rows, the matrix is stored identically to a row of
1486 * <S>*<C> column vectors with <R> components each, according to rule
1487 * (4).
1488 *
1489 * (8) If the member is an array of <S> row-major matrices with <C> columns
1490 * and <R> rows, the matrix is stored identically to a row of <S>*<R>
1491 * row vectors with <C> components each, according to rule (4).
1492 *
1493 * (10) If the member is an array of <S> structures, the <S> elements of
1494 * the array are laid out in order, according to rule (9).
1495 */
1496 if (this->is_array()) {
1497 if (this->fields.array->is_scalar() ||
1498 this->fields.array->is_vector() ||
1499 this->fields.array->is_matrix()) {
1500 return MAX2(this->fields.array->std140_base_alignment(row_major), 16);
1501 } else {
1502 assert(this->fields.array->is_record() ||
1503 this->fields.array->is_array());
1504 return this->fields.array->std140_base_alignment(row_major);
1505 }
1506 }
1507
1508 /* (5) If the member is a column-major matrix with <C> columns and
1509 * <R> rows, the matrix is stored identically to an array of
1510 * <C> column vectors with <R> components each, according to
1511 * rule (4).
1512 *
1513 * (7) If the member is a row-major matrix with <C> columns and <R>
1514 * rows, the matrix is stored identically to an array of <R>
1515 * row vectors with <C> components each, according to rule (4).
1516 */
1517 if (this->is_matrix()) {
1518 const struct glsl_type *vec_type, *array_type;
1519 int c = this->matrix_columns;
1520 int r = this->vector_elements;
1521
1522 if (row_major) {
1523 vec_type = get_instance(base_type, c, 1);
1524 array_type = glsl_type::get_array_instance(vec_type, r);
1525 } else {
1526 vec_type = get_instance(base_type, r, 1);
1527 array_type = glsl_type::get_array_instance(vec_type, c);
1528 }
1529
1530 return array_type->std140_base_alignment(false);
1531 }
1532
1533 /* (9) If the member is a structure, the base alignment of the
1534 * structure is <N>, where <N> is the largest base alignment
1535 * value of any of its members, and rounded up to the base
1536 * alignment of a vec4. The individual members of this
1537 * sub-structure are then assigned offsets by applying this set
1538 * of rules recursively, where the base offset of the first
1539 * member of the sub-structure is equal to the aligned offset
1540 * of the structure. The structure may have padding at the end;
1541 * the base offset of the member following the sub-structure is
1542 * rounded up to the next multiple of the base alignment of the
1543 * structure.
1544 */
1545 if (this->is_record()) {
1546 unsigned base_alignment = 16;
1547 for (unsigned i = 0; i < this->length; i++) {
1548 bool field_row_major = row_major;
1549 const enum glsl_matrix_layout matrix_layout =
1550 glsl_matrix_layout(this->fields.structure[i].matrix_layout);
1551 if (matrix_layout == GLSL_MATRIX_LAYOUT_ROW_MAJOR) {
1552 field_row_major = true;
1553 } else if (matrix_layout == GLSL_MATRIX_LAYOUT_COLUMN_MAJOR) {
1554 field_row_major = false;
1555 }
1556
1557 const struct glsl_type *field_type = this->fields.structure[i].type;
1558 base_alignment = MAX2(base_alignment,
1559 field_type->std140_base_alignment(field_row_major));
1560 }
1561 return base_alignment;
1562 }
1563
1564 assert(!"not reached");
1565 return -1;
1566 }
1567
1568 unsigned
1569 glsl_type::std140_size(bool row_major) const
1570 {
1571 unsigned N = is_64bit() ? 8 : 4;
1572
1573 /* (1) If the member is a scalar consuming <N> basic machine units, the
1574 * base alignment is <N>.
1575 *
1576 * (2) If the member is a two- or four-component vector with components
1577 * consuming <N> basic machine units, the base alignment is 2<N> or
1578 * 4<N>, respectively.
1579 *
1580 * (3) If the member is a three-component vector with components consuming
1581 * <N> basic machine units, the base alignment is 4<N>.
1582 */
1583 if (this->is_scalar() || this->is_vector()) {
1584 return this->vector_elements * N;
1585 }
1586
1587 /* (5) If the member is a column-major matrix with <C> columns and
1588 * <R> rows, the matrix is stored identically to an array of
1589 * <C> column vectors with <R> components each, according to
1590 * rule (4).
1591 *
1592 * (6) If the member is an array of <S> column-major matrices with <C>
1593 * columns and <R> rows, the matrix is stored identically to a row of
1594 * <S>*<C> column vectors with <R> components each, according to rule
1595 * (4).
1596 *
1597 * (7) If the member is a row-major matrix with <C> columns and <R>
1598 * rows, the matrix is stored identically to an array of <R>
1599 * row vectors with <C> components each, according to rule (4).
1600 *
1601 * (8) If the member is an array of <S> row-major matrices with <C> columns
1602 * and <R> rows, the matrix is stored identically to a row of <S>*<R>
1603 * row vectors with <C> components each, according to rule (4).
1604 */
1605 if (this->without_array()->is_matrix()) {
1606 const struct glsl_type *element_type;
1607 const struct glsl_type *vec_type;
1608 unsigned int array_len;
1609
1610 if (this->is_array()) {
1611 element_type = this->without_array();
1612 array_len = this->arrays_of_arrays_size();
1613 } else {
1614 element_type = this;
1615 array_len = 1;
1616 }
1617
1618 if (row_major) {
1619 vec_type = get_instance(element_type->base_type,
1620 element_type->matrix_columns, 1);
1621
1622 array_len *= element_type->vector_elements;
1623 } else {
1624 vec_type = get_instance(element_type->base_type,
1625 element_type->vector_elements, 1);
1626 array_len *= element_type->matrix_columns;
1627 }
1628 const glsl_type *array_type = glsl_type::get_array_instance(vec_type,
1629 array_len);
1630
1631 return array_type->std140_size(false);
1632 }
1633
1634 /* (4) If the member is an array of scalars or vectors, the base alignment
1635 * and array stride are set to match the base alignment of a single
1636 * array element, according to rules (1), (2), and (3), and rounded up
1637 * to the base alignment of a vec4. The array may have padding at the
1638 * end; the base offset of the member following the array is rounded up
1639 * to the next multiple of the base alignment.
1640 *
1641 * (10) If the member is an array of <S> structures, the <S> elements of
1642 * the array are laid out in order, according to rule (9).
1643 */
1644 if (this->is_array()) {
1645 if (this->without_array()->is_record()) {
1646 return this->arrays_of_arrays_size() *
1647 this->without_array()->std140_size(row_major);
1648 } else {
1649 unsigned element_base_align =
1650 this->without_array()->std140_base_alignment(row_major);
1651 return this->arrays_of_arrays_size() * MAX2(element_base_align, 16);
1652 }
1653 }
1654
1655 /* (9) If the member is a structure, the base alignment of the
1656 * structure is <N>, where <N> is the largest base alignment
1657 * value of any of its members, and rounded up to the base
1658 * alignment of a vec4. The individual members of this
1659 * sub-structure are then assigned offsets by applying this set
1660 * of rules recursively, where the base offset of the first
1661 * member of the sub-structure is equal to the aligned offset
1662 * of the structure. The structure may have padding at the end;
1663 * the base offset of the member following the sub-structure is
1664 * rounded up to the next multiple of the base alignment of the
1665 * structure.
1666 */
1667 if (this->is_record() || this->is_interface()) {
1668 unsigned size = 0;
1669 unsigned max_align = 0;
1670
1671 for (unsigned i = 0; i < this->length; i++) {
1672 bool field_row_major = row_major;
1673 const enum glsl_matrix_layout matrix_layout =
1674 glsl_matrix_layout(this->fields.structure[i].matrix_layout);
1675 if (matrix_layout == GLSL_MATRIX_LAYOUT_ROW_MAJOR) {
1676 field_row_major = true;
1677 } else if (matrix_layout == GLSL_MATRIX_LAYOUT_COLUMN_MAJOR) {
1678 field_row_major = false;
1679 }
1680
1681 const struct glsl_type *field_type = this->fields.structure[i].type;
1682 unsigned align = field_type->std140_base_alignment(field_row_major);
1683
1684 /* Ignore unsized arrays when calculating size */
1685 if (field_type->is_unsized_array())
1686 continue;
1687
1688 size = glsl_align(size, align);
1689 size += field_type->std140_size(field_row_major);
1690
1691 max_align = MAX2(align, max_align);
1692
1693 if (field_type->is_record() && (i + 1 < this->length))
1694 size = glsl_align(size, 16);
1695 }
1696 size = glsl_align(size, MAX2(max_align, 16));
1697 return size;
1698 }
1699
1700 assert(!"not reached");
1701 return -1;
1702 }
1703
1704 unsigned
1705 glsl_type::std430_base_alignment(bool row_major) const
1706 {
1707
1708 unsigned N = is_64bit() ? 8 : 4;
1709
1710 /* (1) If the member is a scalar consuming <N> basic machine units, the
1711 * base alignment is <N>.
1712 *
1713 * (2) If the member is a two- or four-component vector with components
1714 * consuming <N> basic machine units, the base alignment is 2<N> or
1715 * 4<N>, respectively.
1716 *
1717 * (3) If the member is a three-component vector with components consuming
1718 * <N> basic machine units, the base alignment is 4<N>.
1719 */
1720 if (this->is_scalar() || this->is_vector()) {
1721 switch (this->vector_elements) {
1722 case 1:
1723 return N;
1724 case 2:
1725 return 2 * N;
1726 case 3:
1727 case 4:
1728 return 4 * N;
1729 }
1730 }
1731
1732 /* OpenGL 4.30 spec, section 7.6.2.2 "Standard Uniform Block Layout":
1733 *
1734 * "When using the std430 storage layout, shader storage blocks will be
1735 * laid out in buffer storage identically to uniform and shader storage
1736 * blocks using the std140 layout, except that the base alignment and
1737 * stride of arrays of scalars and vectors in rule 4 and of structures
1738 * in rule 9 are not rounded up a multiple of the base alignment of a vec4.
1739 */
1740
1741 /* (1) If the member is a scalar consuming <N> basic machine units, the
1742 * base alignment is <N>.
1743 *
1744 * (2) If the member is a two- or four-component vector with components
1745 * consuming <N> basic machine units, the base alignment is 2<N> or
1746 * 4<N>, respectively.
1747 *
1748 * (3) If the member is a three-component vector with components consuming
1749 * <N> basic machine units, the base alignment is 4<N>.
1750 */
1751 if (this->is_array())
1752 return this->fields.array->std430_base_alignment(row_major);
1753
1754 /* (5) If the member is a column-major matrix with <C> columns and
1755 * <R> rows, the matrix is stored identically to an array of
1756 * <C> column vectors with <R> components each, according to
1757 * rule (4).
1758 *
1759 * (7) If the member is a row-major matrix with <C> columns and <R>
1760 * rows, the matrix is stored identically to an array of <R>
1761 * row vectors with <C> components each, according to rule (4).
1762 */
1763 if (this->is_matrix()) {
1764 const struct glsl_type *vec_type, *array_type;
1765 int c = this->matrix_columns;
1766 int r = this->vector_elements;
1767
1768 if (row_major) {
1769 vec_type = get_instance(base_type, c, 1);
1770 array_type = glsl_type::get_array_instance(vec_type, r);
1771 } else {
1772 vec_type = get_instance(base_type, r, 1);
1773 array_type = glsl_type::get_array_instance(vec_type, c);
1774 }
1775
1776 return array_type->std430_base_alignment(false);
1777 }
1778
1779 /* (9) If the member is a structure, the base alignment of the
1780 * structure is <N>, where <N> is the largest base alignment
1781 * value of any of its members, and rounded up to the base
1782 * alignment of a vec4. The individual members of this
1783 * sub-structure are then assigned offsets by applying this set
1784 * of rules recursively, where the base offset of the first
1785 * member of the sub-structure is equal to the aligned offset
1786 * of the structure. The structure may have padding at the end;
1787 * the base offset of the member following the sub-structure is
1788 * rounded up to the next multiple of the base alignment of the
1789 * structure.
1790 */
1791 if (this->is_record()) {
1792 unsigned base_alignment = 0;
1793 for (unsigned i = 0; i < this->length; i++) {
1794 bool field_row_major = row_major;
1795 const enum glsl_matrix_layout matrix_layout =
1796 glsl_matrix_layout(this->fields.structure[i].matrix_layout);
1797 if (matrix_layout == GLSL_MATRIX_LAYOUT_ROW_MAJOR) {
1798 field_row_major = true;
1799 } else if (matrix_layout == GLSL_MATRIX_LAYOUT_COLUMN_MAJOR) {
1800 field_row_major = false;
1801 }
1802
1803 const struct glsl_type *field_type = this->fields.structure[i].type;
1804 base_alignment = MAX2(base_alignment,
1805 field_type->std430_base_alignment(field_row_major));
1806 }
1807 assert(base_alignment > 0);
1808 return base_alignment;
1809 }
1810 assert(!"not reached");
1811 return -1;
1812 }
1813
1814 unsigned
1815 glsl_type::std430_array_stride(bool row_major) const
1816 {
1817 unsigned N = is_64bit() ? 8 : 4;
1818
1819 /* Notice that the array stride of a vec3 is not 3 * N but 4 * N.
1820 * See OpenGL 4.30 spec, section 7.6.2.2 "Standard Uniform Block Layout"
1821 *
1822 * (3) If the member is a three-component vector with components consuming
1823 * <N> basic machine units, the base alignment is 4<N>.
1824 */
1825 if (this->is_vector() && this->vector_elements == 3)
1826 return 4 * N;
1827
1828 /* By default use std430_size(row_major) */
1829 return this->std430_size(row_major);
1830 }
1831
1832 unsigned
1833 glsl_type::std430_size(bool row_major) const
1834 {
1835 unsigned N = is_64bit() ? 8 : 4;
1836
1837 /* OpenGL 4.30 spec, section 7.6.2.2 "Standard Uniform Block Layout":
1838 *
1839 * "When using the std430 storage layout, shader storage blocks will be
1840 * laid out in buffer storage identically to uniform and shader storage
1841 * blocks using the std140 layout, except that the base alignment and
1842 * stride of arrays of scalars and vectors in rule 4 and of structures
1843 * in rule 9 are not rounded up a multiple of the base alignment of a vec4.
1844 */
1845 if (this->is_scalar() || this->is_vector())
1846 return this->vector_elements * N;
1847
1848 if (this->without_array()->is_matrix()) {
1849 const struct glsl_type *element_type;
1850 const struct glsl_type *vec_type;
1851 unsigned int array_len;
1852
1853 if (this->is_array()) {
1854 element_type = this->without_array();
1855 array_len = this->arrays_of_arrays_size();
1856 } else {
1857 element_type = this;
1858 array_len = 1;
1859 }
1860
1861 if (row_major) {
1862 vec_type = get_instance(element_type->base_type,
1863 element_type->matrix_columns, 1);
1864
1865 array_len *= element_type->vector_elements;
1866 } else {
1867 vec_type = get_instance(element_type->base_type,
1868 element_type->vector_elements, 1);
1869 array_len *= element_type->matrix_columns;
1870 }
1871 const glsl_type *array_type = glsl_type::get_array_instance(vec_type,
1872 array_len);
1873
1874 return array_type->std430_size(false);
1875 }
1876
1877 if (this->is_array()) {
1878 if (this->without_array()->is_record())
1879 return this->arrays_of_arrays_size() *
1880 this->without_array()->std430_size(row_major);
1881 else
1882 return this->arrays_of_arrays_size() *
1883 this->without_array()->std430_base_alignment(row_major);
1884 }
1885
1886 if (this->is_record() || this->is_interface()) {
1887 unsigned size = 0;
1888 unsigned max_align = 0;
1889
1890 for (unsigned i = 0; i < this->length; i++) {
1891 bool field_row_major = row_major;
1892 const enum glsl_matrix_layout matrix_layout =
1893 glsl_matrix_layout(this->fields.structure[i].matrix_layout);
1894 if (matrix_layout == GLSL_MATRIX_LAYOUT_ROW_MAJOR) {
1895 field_row_major = true;
1896 } else if (matrix_layout == GLSL_MATRIX_LAYOUT_COLUMN_MAJOR) {
1897 field_row_major = false;
1898 }
1899
1900 const struct glsl_type *field_type = this->fields.structure[i].type;
1901 unsigned align = field_type->std430_base_alignment(field_row_major);
1902 size = glsl_align(size, align);
1903 size += field_type->std430_size(field_row_major);
1904
1905 max_align = MAX2(align, max_align);
1906 }
1907 size = glsl_align(size, max_align);
1908 return size;
1909 }
1910
1911 assert(!"not reached");
1912 return -1;
1913 }
1914
1915 unsigned
1916 glsl_type::count_attribute_slots(bool is_vertex_input) const
1917 {
1918 /* From page 31 (page 37 of the PDF) of the GLSL 1.50 spec:
1919 *
1920 * "A scalar input counts the same amount against this limit as a vec4,
1921 * so applications may want to consider packing groups of four
1922 * unrelated float inputs together into a vector to better utilize the
1923 * capabilities of the underlying hardware. A matrix input will use up
1924 * multiple locations. The number of locations used will equal the
1925 * number of columns in the matrix."
1926 *
1927 * The spec does not explicitly say how arrays are counted. However, it
1928 * should be safe to assume the total number of slots consumed by an array
1929 * is the number of entries in the array multiplied by the number of slots
1930 * consumed by a single element of the array.
1931 *
1932 * The spec says nothing about how structs are counted, because vertex
1933 * attributes are not allowed to be (or contain) structs. However, Mesa
1934 * allows varying structs, the number of varying slots taken up by a
1935 * varying struct is simply equal to the sum of the number of slots taken
1936 * up by each element.
1937 *
1938 * Doubles are counted different depending on whether they are vertex
1939 * inputs or everything else. Vertex inputs from ARB_vertex_attrib_64bit
1940 * take one location no matter what size they are, otherwise dvec3/4
1941 * take two locations.
1942 */
1943 switch (this->base_type) {
1944 case GLSL_TYPE_UINT:
1945 case GLSL_TYPE_INT:
1946 case GLSL_TYPE_FLOAT:
1947 case GLSL_TYPE_BOOL:
1948 return this->matrix_columns;
1949 case GLSL_TYPE_DOUBLE:
1950 if (this->vector_elements > 2 && !is_vertex_input)
1951 return this->matrix_columns * 2;
1952 else
1953 return this->matrix_columns;
1954 case GLSL_TYPE_STRUCT:
1955 case GLSL_TYPE_INTERFACE: {
1956 unsigned size = 0;
1957
1958 for (unsigned i = 0; i < this->length; i++)
1959 size += this->fields.structure[i].type->count_attribute_slots(is_vertex_input);
1960
1961 return size;
1962 }
1963
1964 case GLSL_TYPE_ARRAY:
1965 return this->length * this->fields.array->count_attribute_slots(is_vertex_input);
1966
1967 case GLSL_TYPE_FUNCTION:
1968 case GLSL_TYPE_SAMPLER:
1969 case GLSL_TYPE_IMAGE:
1970 case GLSL_TYPE_ATOMIC_UINT:
1971 case GLSL_TYPE_VOID:
1972 case GLSL_TYPE_SUBROUTINE:
1973 case GLSL_TYPE_ERROR:
1974 break;
1975 }
1976
1977 assert(!"Unexpected type in count_attribute_slots()");
1978
1979 return 0;
1980 }
1981
1982 int
1983 glsl_type::coordinate_components() const
1984 {
1985 int size;
1986
1987 switch (sampler_dimensionality) {
1988 case GLSL_SAMPLER_DIM_1D:
1989 case GLSL_SAMPLER_DIM_BUF:
1990 size = 1;
1991 break;
1992 case GLSL_SAMPLER_DIM_2D:
1993 case GLSL_SAMPLER_DIM_RECT:
1994 case GLSL_SAMPLER_DIM_MS:
1995 case GLSL_SAMPLER_DIM_EXTERNAL:
1996 case GLSL_SAMPLER_DIM_SUBPASS:
1997 size = 2;
1998 break;
1999 case GLSL_SAMPLER_DIM_3D:
2000 case GLSL_SAMPLER_DIM_CUBE:
2001 size = 3;
2002 break;
2003 default:
2004 assert(!"Should not get here.");
2005 size = 1;
2006 break;
2007 }
2008
2009 /* Array textures need an additional component for the array index, except
2010 * for cubemap array images that behave like a 2D array of interleaved
2011 * cubemap faces.
2012 */
2013 if (sampler_array &&
2014 !(base_type == GLSL_TYPE_IMAGE &&
2015 sampler_dimensionality == GLSL_SAMPLER_DIM_CUBE))
2016 size += 1;
2017
2018 return size;
2019 }
2020
2021 /**
2022 * Declarations of type flyweights (glsl_type::_foo_type) and
2023 * convenience pointers (glsl_type::foo_type).
2024 * @{
2025 */
2026 #define DECL_TYPE(NAME, ...) \
2027 const glsl_type glsl_type::_##NAME##_type = glsl_type(__VA_ARGS__, #NAME); \
2028 const glsl_type *const glsl_type::NAME##_type = &glsl_type::_##NAME##_type;
2029
2030 #define STRUCT_TYPE(NAME)
2031
2032 #include "compiler/builtin_type_macros.h"
2033 /** @} */