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