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