2 * Copyright © 2009 Intel Corporation
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:
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
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.
25 #include "main/macros.h"
26 #include "compiler/glsl/glsl_parser_extras.h"
27 #include "glsl_types.h"
28 #include "util/hash_table.h"
31 mtx_t
glsl_type::hash_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
;
38 glsl_type::glsl_type(GLenum gl_type
,
39 glsl_base_type base_type
, unsigned vector_elements
,
40 unsigned matrix_columns
, const char *name
) :
42 base_type(base_type
), sampled_type(GLSL_TYPE_VOID
),
43 sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
44 interface_packing(0), interface_row_major(0),
45 vector_elements(vector_elements
), matrix_columns(matrix_columns
),
48 /* Values of these types must fit in the two bits of
49 * glsl_type::sampled_type.
51 STATIC_ASSERT((unsigned(GLSL_TYPE_UINT
) & 3) == unsigned(GLSL_TYPE_UINT
));
52 STATIC_ASSERT((unsigned(GLSL_TYPE_INT
) & 3) == unsigned(GLSL_TYPE_INT
));
53 STATIC_ASSERT((unsigned(GLSL_TYPE_FLOAT
) & 3) == unsigned(GLSL_TYPE_FLOAT
));
55 ASSERT_BITFIELD_SIZE(glsl_type
, base_type
, GLSL_TYPE_ERROR
);
56 ASSERT_BITFIELD_SIZE(glsl_type
, sampled_type
, GLSL_TYPE_ERROR
);
57 ASSERT_BITFIELD_SIZE(glsl_type
, sampler_dimensionality
,
58 GLSL_SAMPLER_DIM_SUBPASS_MS
);
60 this->mem_ctx
= ralloc_context(NULL
);
61 assert(this->mem_ctx
!= NULL
);
64 this->name
= ralloc_strdup(this->mem_ctx
, name
);
66 /* Neither dimension is zero or both dimensions are zero.
68 assert((vector_elements
== 0) == (matrix_columns
== 0));
69 memset(& fields
, 0, sizeof(fields
));
72 glsl_type::glsl_type(GLenum gl_type
, glsl_base_type base_type
,
73 enum glsl_sampler_dim dim
, bool shadow
, bool array
,
74 glsl_base_type type
, const char *name
) :
76 base_type(base_type
), sampled_type(type
),
77 sampler_dimensionality(dim
), sampler_shadow(shadow
),
78 sampler_array(array
), interface_packing(0),
79 interface_row_major(0), length(0)
81 this->mem_ctx
= ralloc_context(NULL
);
82 assert(this->mem_ctx
!= NULL
);
85 this->name
= ralloc_strdup(this->mem_ctx
, name
);
87 memset(& fields
, 0, sizeof(fields
));
89 matrix_columns
= vector_elements
= 1;
92 glsl_type::glsl_type(const glsl_struct_field
*fields
, unsigned num_fields
,
95 base_type(GLSL_TYPE_STRUCT
), sampled_type(GLSL_TYPE_VOID
),
96 sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
97 interface_packing(0), interface_row_major(0),
98 vector_elements(0), matrix_columns(0),
103 this->mem_ctx
= ralloc_context(NULL
);
104 assert(this->mem_ctx
!= NULL
);
106 assert(name
!= NULL
);
107 this->name
= ralloc_strdup(this->mem_ctx
, name
);
108 this->fields
.structure
= ralloc_array(this->mem_ctx
,
109 glsl_struct_field
, length
);
111 for (i
= 0; i
< length
; i
++) {
112 this->fields
.structure
[i
] = fields
[i
];
113 this->fields
.structure
[i
].name
= ralloc_strdup(this->fields
.structure
,
118 glsl_type::glsl_type(const glsl_struct_field
*fields
, unsigned num_fields
,
119 enum glsl_interface_packing packing
,
120 bool row_major
, const char *name
) :
122 base_type(GLSL_TYPE_INTERFACE
), sampled_type(GLSL_TYPE_VOID
),
123 sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
124 interface_packing((unsigned) packing
),
125 interface_row_major((unsigned) row_major
),
126 vector_elements(0), matrix_columns(0),
131 this->mem_ctx
= ralloc_context(NULL
);
132 assert(this->mem_ctx
!= NULL
);
134 assert(name
!= NULL
);
135 this->name
= ralloc_strdup(this->mem_ctx
, name
);
136 this->fields
.structure
= rzalloc_array(this->mem_ctx
,
137 glsl_struct_field
, length
);
138 for (i
= 0; i
< length
; i
++) {
139 this->fields
.structure
[i
] = fields
[i
];
140 this->fields
.structure
[i
].name
= ralloc_strdup(this->fields
.structure
,
145 glsl_type::glsl_type(const glsl_type
*return_type
,
146 const glsl_function_param
*params
, unsigned num_params
) :
148 base_type(GLSL_TYPE_FUNCTION
), sampled_type(GLSL_TYPE_VOID
),
149 sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
150 interface_packing(0), interface_row_major(0),
151 vector_elements(0), matrix_columns(0),
156 this->mem_ctx
= ralloc_context(NULL
);
157 assert(this->mem_ctx
!= NULL
);
159 this->fields
.parameters
= rzalloc_array(this->mem_ctx
,
160 glsl_function_param
, num_params
+ 1);
162 /* We store the return type as the first parameter */
163 this->fields
.parameters
[0].type
= return_type
;
164 this->fields
.parameters
[0].in
= false;
165 this->fields
.parameters
[0].out
= true;
167 /* We store the i'th parameter in slot i+1 */
168 for (i
= 0; i
< length
; i
++) {
169 this->fields
.parameters
[i
+ 1].type
= params
[i
].type
;
170 this->fields
.parameters
[i
+ 1].in
= params
[i
].in
;
171 this->fields
.parameters
[i
+ 1].out
= params
[i
].out
;
175 glsl_type::glsl_type(const char *subroutine_name
) :
177 base_type(GLSL_TYPE_SUBROUTINE
), sampled_type(GLSL_TYPE_VOID
),
178 sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
179 interface_packing(0), interface_row_major(0),
180 vector_elements(1), matrix_columns(1),
183 this->mem_ctx
= ralloc_context(NULL
);
184 assert(this->mem_ctx
!= NULL
);
186 assert(subroutine_name
!= NULL
);
187 this->name
= ralloc_strdup(this->mem_ctx
, subroutine_name
);
190 glsl_type::~glsl_type()
192 ralloc_free(this->mem_ctx
);
196 glsl_type::contains_sampler() const
198 if (this->is_array()) {
199 return this->fields
.array
->contains_sampler();
200 } else if (this->is_record() || this->is_interface()) {
201 for (unsigned int i
= 0; i
< this->length
; i
++) {
202 if (this->fields
.structure
[i
].type
->contains_sampler())
207 return this->is_sampler();
212 glsl_type::contains_array() const
214 if (this->is_record() || this->is_interface()) {
215 for (unsigned int i
= 0; i
< this->length
; i
++) {
216 if (this->fields
.structure
[i
].type
->contains_array())
221 return this->is_array();
226 glsl_type::contains_integer() const
228 if (this->is_array()) {
229 return this->fields
.array
->contains_integer();
230 } else if (this->is_record() || this->is_interface()) {
231 for (unsigned int i
= 0; i
< this->length
; i
++) {
232 if (this->fields
.structure
[i
].type
->contains_integer())
237 return this->is_integer();
242 glsl_type::contains_double() const
244 if (this->is_array()) {
245 return this->fields
.array
->contains_double();
246 } else if (this->is_record() || this->is_interface()) {
247 for (unsigned int i
= 0; i
< this->length
; i
++) {
248 if (this->fields
.structure
[i
].type
->contains_double())
253 return this->is_double();
258 glsl_type::contains_opaque() const {
260 case GLSL_TYPE_SAMPLER
:
261 case GLSL_TYPE_IMAGE
:
262 case GLSL_TYPE_ATOMIC_UINT
:
264 case GLSL_TYPE_ARRAY
:
265 return fields
.array
->contains_opaque();
266 case GLSL_TYPE_STRUCT
:
267 case GLSL_TYPE_INTERFACE
:
268 for (unsigned int i
= 0; i
< length
; i
++) {
269 if (fields
.structure
[i
].type
->contains_opaque())
279 glsl_type::contains_subroutine() const
281 if (this->is_array()) {
282 return this->fields
.array
->contains_subroutine();
283 } else if (this->is_record() || this->is_interface()) {
284 for (unsigned int i
= 0; i
< this->length
; i
++) {
285 if (this->fields
.structure
[i
].type
->contains_subroutine())
290 return this->is_subroutine();
295 glsl_type::sampler_index() const
297 const glsl_type
*const t
= (this->is_array()) ? this->fields
.array
: this;
299 assert(t
->is_sampler() || t
->is_image());
301 switch (t
->sampler_dimensionality
) {
302 case GLSL_SAMPLER_DIM_1D
:
303 return (t
->sampler_array
) ? TEXTURE_1D_ARRAY_INDEX
: TEXTURE_1D_INDEX
;
304 case GLSL_SAMPLER_DIM_2D
:
305 return (t
->sampler_array
) ? TEXTURE_2D_ARRAY_INDEX
: TEXTURE_2D_INDEX
;
306 case GLSL_SAMPLER_DIM_3D
:
307 return TEXTURE_3D_INDEX
;
308 case GLSL_SAMPLER_DIM_CUBE
:
309 return (t
->sampler_array
) ? TEXTURE_CUBE_ARRAY_INDEX
: TEXTURE_CUBE_INDEX
;
310 case GLSL_SAMPLER_DIM_RECT
:
311 return TEXTURE_RECT_INDEX
;
312 case GLSL_SAMPLER_DIM_BUF
:
313 return TEXTURE_BUFFER_INDEX
;
314 case GLSL_SAMPLER_DIM_EXTERNAL
:
315 return TEXTURE_EXTERNAL_INDEX
;
316 case GLSL_SAMPLER_DIM_MS
:
317 return (t
->sampler_array
) ? TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
: TEXTURE_2D_MULTISAMPLE_INDEX
;
319 assert(!"Should not get here.");
320 return TEXTURE_BUFFER_INDEX
;
325 glsl_type::contains_image() const
327 if (this->is_array()) {
328 return this->fields
.array
->contains_image();
329 } else if (this->is_record() || this->is_interface()) {
330 for (unsigned int i
= 0; i
< this->length
; i
++) {
331 if (this->fields
.structure
[i
].type
->contains_image())
336 return this->is_image();
340 const glsl_type
*glsl_type::get_base_type() const
345 case GLSL_TYPE_UINT16
:
346 return uint16_t_type
;
349 case GLSL_TYPE_INT16
:
351 case GLSL_TYPE_FLOAT
:
353 case GLSL_TYPE_FLOAT16
:
354 return float16_t_type
;
355 case GLSL_TYPE_DOUBLE
:
359 case GLSL_TYPE_UINT64
:
360 return uint64_t_type
;
361 case GLSL_TYPE_INT64
:
369 const glsl_type
*glsl_type::get_scalar_type() const
371 const glsl_type
*type
= this;
374 while (type
->base_type
== GLSL_TYPE_ARRAY
)
375 type
= type
->fields
.array
;
377 /* Handle vectors and matrices */
378 switch (type
->base_type
) {
381 case GLSL_TYPE_UINT16
:
382 return uint16_t_type
;
385 case GLSL_TYPE_INT16
:
387 case GLSL_TYPE_FLOAT
:
389 case GLSL_TYPE_FLOAT16
:
390 return float16_t_type
;
391 case GLSL_TYPE_DOUBLE
:
395 case GLSL_TYPE_UINT64
:
396 return uint64_t_type
;
397 case GLSL_TYPE_INT64
:
400 /* Handle everything else */
407 hash_free_type_function(struct hash_entry
*entry
)
409 glsl_type
*type
= (glsl_type
*) entry
->data
;
411 if (type
->is_array())
412 free((void*)entry
->key
);
418 _mesa_glsl_release_types(void)
420 /* Should only be called during atexit (either when unloading shared
421 * object, or if process terminates), so no mutex-locking should be
424 if (glsl_type::array_types
!= NULL
) {
425 _mesa_hash_table_destroy(glsl_type::array_types
, hash_free_type_function
);
426 glsl_type::array_types
= NULL
;
429 if (glsl_type::record_types
!= NULL
) {
430 _mesa_hash_table_destroy(glsl_type::record_types
, hash_free_type_function
);
431 glsl_type::record_types
= NULL
;
434 if (glsl_type::interface_types
!= NULL
) {
435 _mesa_hash_table_destroy(glsl_type::interface_types
, hash_free_type_function
);
436 glsl_type::interface_types
= NULL
;
439 if (glsl_type::function_types
!= NULL
) {
440 _mesa_hash_table_destroy(glsl_type::function_types
, hash_free_type_function
);
441 glsl_type::function_types
= NULL
;
444 if (glsl_type::subroutine_types
!= NULL
) {
445 _mesa_hash_table_destroy(glsl_type::subroutine_types
, hash_free_type_function
);
446 glsl_type::subroutine_types
= NULL
;
451 glsl_type::glsl_type(const glsl_type
*array
, unsigned length
) :
452 base_type(GLSL_TYPE_ARRAY
), sampled_type(GLSL_TYPE_VOID
),
453 sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
454 interface_packing(0), interface_row_major(0),
455 vector_elements(0), matrix_columns(0),
456 length(length
), name(NULL
)
458 this->fields
.array
= array
;
459 /* Inherit the gl type of the base. The GL type is used for
460 * uniform/statevar handling in Mesa and the arrayness of the type
461 * is represented by the size rather than the type.
463 this->gl_type
= array
->gl_type
;
465 /* Allow a maximum of 10 characters for the array size. This is enough
466 * for 32-bits of ~0. The extra 3 are for the '[', ']', and terminating
469 const unsigned name_length
= strlen(array
->name
) + 10 + 3;
471 this->mem_ctx
= ralloc_context(NULL
);
472 assert(this->mem_ctx
!= NULL
);
474 char *const n
= (char *) ralloc_size(this->mem_ctx
, name_length
);
477 snprintf(n
, name_length
, "%s[]", array
->name
);
479 /* insert outermost dimensions in the correct spot
480 * otherwise the dimension order will be backwards
482 const char *pos
= strchr(array
->name
, '[');
484 int idx
= pos
- array
->name
;
485 snprintf(n
, idx
+1, "%s", array
->name
);
486 snprintf(n
+ idx
, name_length
- idx
, "[%u]%s",
487 length
, array
->name
+ idx
);
489 snprintf(n
, name_length
, "%s[%u]", array
->name
, length
);
497 glsl_type::vec(unsigned components
, const glsl_type
*const ts
[])
499 unsigned n
= components
;
503 else if (components
== 16)
512 #define VECN(components, sname, vname) ({ \
513 static const glsl_type *const ts[] = { \
514 sname ## _type, vname ## 2_type, \
515 vname ## 3_type, vname ## 4_type, \
516 vname ## 8_type, vname ## 16_type, \
518 glsl_type::vec(components, ts); \
522 glsl_type::vec(unsigned components
)
524 return VECN(components
, float, vec
);
528 glsl_type::f16vec(unsigned components
)
530 return VECN(components
, float16_t
, f16vec
);
534 glsl_type::dvec(unsigned components
)
536 return VECN(components
, double, dvec
);
540 glsl_type::ivec(unsigned components
)
542 return VECN(components
, int, ivec
);
546 glsl_type::uvec(unsigned components
)
548 return VECN(components
, uint
, uvec
);
552 glsl_type::bvec(unsigned components
)
554 return VECN(components
, bool, bvec
);
558 glsl_type::i64vec(unsigned components
)
560 return VECN(components
, int64_t, i64vec
);
565 glsl_type::u64vec(unsigned components
)
567 return VECN(components
, uint64_t, u64vec
);
571 glsl_type::i16vec(unsigned components
)
573 return VECN(components
, int16_t, i16vec
);
578 glsl_type::u16vec(unsigned components
)
580 return VECN(components
, uint16_t, u16vec
);
584 glsl_type::i8vec(unsigned components
)
586 return VECN(components
, int8_t, i8vec
);
591 glsl_type::u8vec(unsigned components
)
593 return VECN(components
, uint8_t, u8vec
);
597 glsl_type::get_instance(unsigned base_type
, unsigned rows
, unsigned columns
)
599 if (base_type
== GLSL_TYPE_VOID
)
602 /* Treat GLSL vectors as Nx1 matrices.
610 case GLSL_TYPE_FLOAT
:
612 case GLSL_TYPE_FLOAT16
:
614 case GLSL_TYPE_DOUBLE
:
618 case GLSL_TYPE_UINT64
:
620 case GLSL_TYPE_INT64
:
622 case GLSL_TYPE_UINT16
:
624 case GLSL_TYPE_INT16
:
626 case GLSL_TYPE_UINT8
:
634 if ((base_type
!= GLSL_TYPE_FLOAT
&&
635 base_type
!= GLSL_TYPE_DOUBLE
&&
636 base_type
!= GLSL_TYPE_FLOAT16
) || (rows
== 1))
639 /* GLSL matrix types are named mat{COLUMNS}x{ROWS}. Only the following
640 * combinations are valid:
648 #define IDX(c,r) (((c-1)*3) + (r-1))
651 case GLSL_TYPE_DOUBLE
: {
652 switch (IDX(columns
, rows
)) {
653 case IDX(2,2): return dmat2_type
;
654 case IDX(2,3): return dmat2x3_type
;
655 case IDX(2,4): return dmat2x4_type
;
656 case IDX(3,2): return dmat3x2_type
;
657 case IDX(3,3): return dmat3_type
;
658 case IDX(3,4): return dmat3x4_type
;
659 case IDX(4,2): return dmat4x2_type
;
660 case IDX(4,3): return dmat4x3_type
;
661 case IDX(4,4): return dmat4_type
;
662 default: return error_type
;
665 case GLSL_TYPE_FLOAT
: {
666 switch (IDX(columns
, rows
)) {
667 case IDX(2,2): return mat2_type
;
668 case IDX(2,3): return mat2x3_type
;
669 case IDX(2,4): return mat2x4_type
;
670 case IDX(3,2): return mat3x2_type
;
671 case IDX(3,3): return mat3_type
;
672 case IDX(3,4): return mat3x4_type
;
673 case IDX(4,2): return mat4x2_type
;
674 case IDX(4,3): return mat4x3_type
;
675 case IDX(4,4): return mat4_type
;
676 default: return error_type
;
679 case GLSL_TYPE_FLOAT16
: {
680 switch (IDX(columns
, rows
)) {
681 case IDX(2,2): return f16mat2_type
;
682 case IDX(2,3): return f16mat2x3_type
;
683 case IDX(2,4): return f16mat2x4_type
;
684 case IDX(3,2): return f16mat3x2_type
;
685 case IDX(3,3): return f16mat3_type
;
686 case IDX(3,4): return f16mat3x4_type
;
687 case IDX(4,2): return f16mat4x2_type
;
688 case IDX(4,3): return f16mat4x3_type
;
689 case IDX(4,4): return f16mat4_type
;
690 default: return error_type
;
693 default: return error_type
;
697 assert(!"Should not get here.");
702 glsl_type::get_sampler_instance(enum glsl_sampler_dim dim
,
708 case GLSL_TYPE_FLOAT
:
710 case GLSL_SAMPLER_DIM_1D
:
712 return (array
? sampler1DArrayShadow_type
: sampler1DShadow_type
);
714 return (array
? sampler1DArray_type
: sampler1D_type
);
715 case GLSL_SAMPLER_DIM_2D
:
717 return (array
? sampler2DArrayShadow_type
: sampler2DShadow_type
);
719 return (array
? sampler2DArray_type
: sampler2D_type
);
720 case GLSL_SAMPLER_DIM_3D
:
724 return sampler3D_type
;
725 case GLSL_SAMPLER_DIM_CUBE
:
727 return (array
? samplerCubeArrayShadow_type
: samplerCubeShadow_type
);
729 return (array
? samplerCubeArray_type
: samplerCube_type
);
730 case GLSL_SAMPLER_DIM_RECT
:
734 return sampler2DRectShadow_type
;
736 return sampler2DRect_type
;
737 case GLSL_SAMPLER_DIM_BUF
:
741 return samplerBuffer_type
;
742 case GLSL_SAMPLER_DIM_MS
:
745 return (array
? sampler2DMSArray_type
: sampler2DMS_type
);
746 case GLSL_SAMPLER_DIM_EXTERNAL
:
750 return samplerExternalOES_type
;
751 case GLSL_SAMPLER_DIM_SUBPASS
:
752 case GLSL_SAMPLER_DIM_SUBPASS_MS
:
759 case GLSL_SAMPLER_DIM_1D
:
760 return (array
? isampler1DArray_type
: isampler1D_type
);
761 case GLSL_SAMPLER_DIM_2D
:
762 return (array
? isampler2DArray_type
: isampler2D_type
);
763 case GLSL_SAMPLER_DIM_3D
:
766 return isampler3D_type
;
767 case GLSL_SAMPLER_DIM_CUBE
:
768 return (array
? isamplerCubeArray_type
: isamplerCube_type
);
769 case GLSL_SAMPLER_DIM_RECT
:
772 return isampler2DRect_type
;
773 case GLSL_SAMPLER_DIM_BUF
:
776 return isamplerBuffer_type
;
777 case GLSL_SAMPLER_DIM_MS
:
778 return (array
? isampler2DMSArray_type
: isampler2DMS_type
);
779 case GLSL_SAMPLER_DIM_EXTERNAL
:
781 case GLSL_SAMPLER_DIM_SUBPASS
:
782 case GLSL_SAMPLER_DIM_SUBPASS_MS
:
789 case GLSL_SAMPLER_DIM_1D
:
790 return (array
? usampler1DArray_type
: usampler1D_type
);
791 case GLSL_SAMPLER_DIM_2D
:
792 return (array
? usampler2DArray_type
: usampler2D_type
);
793 case GLSL_SAMPLER_DIM_3D
:
796 return usampler3D_type
;
797 case GLSL_SAMPLER_DIM_CUBE
:
798 return (array
? usamplerCubeArray_type
: usamplerCube_type
);
799 case GLSL_SAMPLER_DIM_RECT
:
802 return usampler2DRect_type
;
803 case GLSL_SAMPLER_DIM_BUF
:
806 return usamplerBuffer_type
;
807 case GLSL_SAMPLER_DIM_MS
:
808 return (array
? usampler2DMSArray_type
: usampler2DMS_type
);
809 case GLSL_SAMPLER_DIM_EXTERNAL
:
811 case GLSL_SAMPLER_DIM_SUBPASS
:
812 case GLSL_SAMPLER_DIM_SUBPASS_MS
:
819 unreachable("switch statement above should be complete");
823 glsl_type::get_image_instance(enum glsl_sampler_dim dim
,
824 bool array
, glsl_base_type type
)
827 case GLSL_TYPE_FLOAT
:
829 case GLSL_SAMPLER_DIM_1D
:
830 return (array
? image1DArray_type
: image1D_type
);
831 case GLSL_SAMPLER_DIM_2D
:
832 return (array
? image2DArray_type
: image2D_type
);
833 case GLSL_SAMPLER_DIM_3D
:
835 case GLSL_SAMPLER_DIM_CUBE
:
836 return (array
? imageCubeArray_type
: imageCube_type
);
837 case GLSL_SAMPLER_DIM_RECT
:
841 return image2DRect_type
;
842 case GLSL_SAMPLER_DIM_BUF
:
846 return imageBuffer_type
;
847 case GLSL_SAMPLER_DIM_MS
:
848 return (array
? image2DMSArray_type
: image2DMS_type
);
849 case GLSL_SAMPLER_DIM_SUBPASS
:
850 return subpassInput_type
;
851 case GLSL_SAMPLER_DIM_SUBPASS_MS
:
852 return subpassInputMS_type
;
853 case GLSL_SAMPLER_DIM_EXTERNAL
:
858 case GLSL_SAMPLER_DIM_1D
:
859 return (array
? iimage1DArray_type
: iimage1D_type
);
860 case GLSL_SAMPLER_DIM_2D
:
861 return (array
? iimage2DArray_type
: iimage2D_type
);
862 case GLSL_SAMPLER_DIM_3D
:
865 return iimage3D_type
;
866 case GLSL_SAMPLER_DIM_CUBE
:
867 return (array
? iimageCubeArray_type
: iimageCube_type
);
868 case GLSL_SAMPLER_DIM_RECT
:
871 return iimage2DRect_type
;
872 case GLSL_SAMPLER_DIM_BUF
:
875 return iimageBuffer_type
;
876 case GLSL_SAMPLER_DIM_MS
:
877 return (array
? iimage2DMSArray_type
: iimage2DMS_type
);
878 case GLSL_SAMPLER_DIM_SUBPASS
:
879 return isubpassInput_type
;
880 case GLSL_SAMPLER_DIM_SUBPASS_MS
:
881 return isubpassInputMS_type
;
882 case GLSL_SAMPLER_DIM_EXTERNAL
:
887 case GLSL_SAMPLER_DIM_1D
:
888 return (array
? uimage1DArray_type
: uimage1D_type
);
889 case GLSL_SAMPLER_DIM_2D
:
890 return (array
? uimage2DArray_type
: uimage2D_type
);
891 case GLSL_SAMPLER_DIM_3D
:
894 return uimage3D_type
;
895 case GLSL_SAMPLER_DIM_CUBE
:
896 return (array
? uimageCubeArray_type
: uimageCube_type
);
897 case GLSL_SAMPLER_DIM_RECT
:
900 return uimage2DRect_type
;
901 case GLSL_SAMPLER_DIM_BUF
:
904 return uimageBuffer_type
;
905 case GLSL_SAMPLER_DIM_MS
:
906 return (array
? uimage2DMSArray_type
: uimage2DMS_type
);
907 case GLSL_SAMPLER_DIM_SUBPASS
:
908 return usubpassInput_type
;
909 case GLSL_SAMPLER_DIM_SUBPASS_MS
:
910 return usubpassInputMS_type
;
911 case GLSL_SAMPLER_DIM_EXTERNAL
:
918 unreachable("switch statement above should be complete");
922 glsl_type::get_array_instance(const glsl_type
*base
, unsigned array_size
)
924 /* Generate a name using the base type pointer in the key. This is
925 * done because the name of the base type may not be unique across
926 * shaders. For example, two shaders may have different record types
930 snprintf(key
, sizeof(key
), "%p[%u]", (void *) base
, array_size
);
932 mtx_lock(&glsl_type::hash_mutex
);
934 if (array_types
== NULL
) {
935 array_types
= _mesa_hash_table_create(NULL
, _mesa_key_hash_string
,
936 _mesa_key_string_equal
);
939 const struct hash_entry
*entry
= _mesa_hash_table_search(array_types
, key
);
941 const glsl_type
*t
= new glsl_type(base
, array_size
);
943 entry
= _mesa_hash_table_insert(array_types
,
948 assert(((glsl_type
*) entry
->data
)->base_type
== GLSL_TYPE_ARRAY
);
949 assert(((glsl_type
*) entry
->data
)->length
== array_size
);
950 assert(((glsl_type
*) entry
->data
)->fields
.array
== base
);
952 mtx_unlock(&glsl_type::hash_mutex
);
954 return (glsl_type
*) entry
->data
;
959 glsl_type::record_compare(const glsl_type
*b
, bool match_locations
) const
961 if (this->length
!= b
->length
)
964 if (this->interface_packing
!= b
->interface_packing
)
967 if (this->interface_row_major
!= b
->interface_row_major
)
970 /* From the GLSL 4.20 specification (Sec 4.2):
972 * "Structures must have the same name, sequence of type names, and
973 * type definitions, and field names to be considered the same type."
975 * GLSL ES behaves the same (Ver 1.00 Sec 4.2.4, Ver 3.00 Sec 4.2.5).
977 if (strcmp(this->name
, b
->name
) != 0)
980 for (unsigned i
= 0; i
< this->length
; i
++) {
981 if (this->fields
.structure
[i
].type
!= b
->fields
.structure
[i
].type
)
983 if (strcmp(this->fields
.structure
[i
].name
,
984 b
->fields
.structure
[i
].name
) != 0)
986 if (this->fields
.structure
[i
].matrix_layout
987 != b
->fields
.structure
[i
].matrix_layout
)
989 if (match_locations
&& this->fields
.structure
[i
].location
990 != b
->fields
.structure
[i
].location
)
992 if (this->fields
.structure
[i
].offset
993 != b
->fields
.structure
[i
].offset
)
995 if (this->fields
.structure
[i
].interpolation
996 != b
->fields
.structure
[i
].interpolation
)
998 if (this->fields
.structure
[i
].centroid
999 != b
->fields
.structure
[i
].centroid
)
1001 if (this->fields
.structure
[i
].sample
1002 != b
->fields
.structure
[i
].sample
)
1004 if (this->fields
.structure
[i
].patch
1005 != b
->fields
.structure
[i
].patch
)
1007 if (this->fields
.structure
[i
].memory_read_only
1008 != b
->fields
.structure
[i
].memory_read_only
)
1010 if (this->fields
.structure
[i
].memory_write_only
1011 != b
->fields
.structure
[i
].memory_write_only
)
1013 if (this->fields
.structure
[i
].memory_coherent
1014 != b
->fields
.structure
[i
].memory_coherent
)
1016 if (this->fields
.structure
[i
].memory_volatile
1017 != b
->fields
.structure
[i
].memory_volatile
)
1019 if (this->fields
.structure
[i
].memory_restrict
1020 != b
->fields
.structure
[i
].memory_restrict
)
1022 if (this->fields
.structure
[i
].image_format
1023 != b
->fields
.structure
[i
].image_format
)
1025 if (this->fields
.structure
[i
].precision
1026 != b
->fields
.structure
[i
].precision
)
1028 if (this->fields
.structure
[i
].explicit_xfb_buffer
1029 != b
->fields
.structure
[i
].explicit_xfb_buffer
)
1031 if (this->fields
.structure
[i
].xfb_buffer
1032 != b
->fields
.structure
[i
].xfb_buffer
)
1034 if (this->fields
.structure
[i
].xfb_stride
1035 != b
->fields
.structure
[i
].xfb_stride
)
1044 glsl_type::record_key_compare(const void *a
, const void *b
)
1046 const glsl_type
*const key1
= (glsl_type
*) a
;
1047 const glsl_type
*const key2
= (glsl_type
*) b
;
1049 return strcmp(key1
->name
, key2
->name
) == 0 && key1
->record_compare(key2
);
1054 * Generate an integer hash value for a glsl_type structure type.
1057 glsl_type::record_key_hash(const void *a
)
1059 const glsl_type
*const key
= (glsl_type
*) a
;
1060 uintptr_t hash
= key
->length
;
1063 for (unsigned i
= 0; i
< key
->length
; i
++) {
1064 /* casting pointer to uintptr_t */
1065 hash
= (hash
* 13 ) + (uintptr_t) key
->fields
.structure
[i
].type
;
1068 if (sizeof(hash
) == 8)
1069 retval
= (hash
& 0xffffffff) ^ ((uint64_t) hash
>> 32);
1078 glsl_type::get_record_instance(const glsl_struct_field
*fields
,
1079 unsigned num_fields
,
1082 const glsl_type
key(fields
, num_fields
, name
);
1084 mtx_lock(&glsl_type::hash_mutex
);
1086 if (record_types
== NULL
) {
1087 record_types
= _mesa_hash_table_create(NULL
, record_key_hash
,
1088 record_key_compare
);
1091 const struct hash_entry
*entry
= _mesa_hash_table_search(record_types
,
1093 if (entry
== NULL
) {
1094 const glsl_type
*t
= new glsl_type(fields
, num_fields
, name
);
1096 entry
= _mesa_hash_table_insert(record_types
, t
, (void *) t
);
1099 assert(((glsl_type
*) entry
->data
)->base_type
== GLSL_TYPE_STRUCT
);
1100 assert(((glsl_type
*) entry
->data
)->length
== num_fields
);
1101 assert(strcmp(((glsl_type
*) entry
->data
)->name
, name
) == 0);
1103 mtx_unlock(&glsl_type::hash_mutex
);
1105 return (glsl_type
*) entry
->data
;
1110 glsl_type::get_interface_instance(const glsl_struct_field
*fields
,
1111 unsigned num_fields
,
1112 enum glsl_interface_packing packing
,
1114 const char *block_name
)
1116 const glsl_type
key(fields
, num_fields
, packing
, row_major
, block_name
);
1118 mtx_lock(&glsl_type::hash_mutex
);
1120 if (interface_types
== NULL
) {
1121 interface_types
= _mesa_hash_table_create(NULL
, record_key_hash
,
1122 record_key_compare
);
1125 const struct hash_entry
*entry
= _mesa_hash_table_search(interface_types
,
1127 if (entry
== NULL
) {
1128 const glsl_type
*t
= new glsl_type(fields
, num_fields
,
1129 packing
, row_major
, block_name
);
1131 entry
= _mesa_hash_table_insert(interface_types
, t
, (void *) t
);
1134 assert(((glsl_type
*) entry
->data
)->base_type
== GLSL_TYPE_INTERFACE
);
1135 assert(((glsl_type
*) entry
->data
)->length
== num_fields
);
1136 assert(strcmp(((glsl_type
*) entry
->data
)->name
, block_name
) == 0);
1138 mtx_unlock(&glsl_type::hash_mutex
);
1140 return (glsl_type
*) entry
->data
;
1144 glsl_type::get_subroutine_instance(const char *subroutine_name
)
1146 const glsl_type
key(subroutine_name
);
1148 mtx_lock(&glsl_type::hash_mutex
);
1150 if (subroutine_types
== NULL
) {
1151 subroutine_types
= _mesa_hash_table_create(NULL
, record_key_hash
,
1152 record_key_compare
);
1155 const struct hash_entry
*entry
= _mesa_hash_table_search(subroutine_types
,
1157 if (entry
== NULL
) {
1158 const glsl_type
*t
= new glsl_type(subroutine_name
);
1160 entry
= _mesa_hash_table_insert(subroutine_types
, t
, (void *) t
);
1163 assert(((glsl_type
*) entry
->data
)->base_type
== GLSL_TYPE_SUBROUTINE
);
1164 assert(strcmp(((glsl_type
*) entry
->data
)->name
, subroutine_name
) == 0);
1166 mtx_unlock(&glsl_type::hash_mutex
);
1168 return (glsl_type
*) entry
->data
;
1173 function_key_compare(const void *a
, const void *b
)
1175 const glsl_type
*const key1
= (glsl_type
*) a
;
1176 const glsl_type
*const key2
= (glsl_type
*) b
;
1178 if (key1
->length
!= key2
->length
)
1181 return memcmp(key1
->fields
.parameters
, key2
->fields
.parameters
,
1182 (key1
->length
+ 1) * sizeof(*key1
->fields
.parameters
)) == 0;
1187 function_key_hash(const void *a
)
1189 const glsl_type
*const key
= (glsl_type
*) a
;
1190 return _mesa_hash_data(key
->fields
.parameters
,
1191 (key
->length
+ 1) * sizeof(*key
->fields
.parameters
));
1195 glsl_type::get_function_instance(const glsl_type
*return_type
,
1196 const glsl_function_param
*params
,
1197 unsigned num_params
)
1199 const glsl_type
key(return_type
, params
, num_params
);
1201 mtx_lock(&glsl_type::hash_mutex
);
1203 if (function_types
== NULL
) {
1204 function_types
= _mesa_hash_table_create(NULL
, function_key_hash
,
1205 function_key_compare
);
1208 struct hash_entry
*entry
= _mesa_hash_table_search(function_types
, &key
);
1209 if (entry
== NULL
) {
1210 const glsl_type
*t
= new glsl_type(return_type
, params
, num_params
);
1212 entry
= _mesa_hash_table_insert(function_types
, t
, (void *) t
);
1215 const glsl_type
*t
= (const glsl_type
*)entry
->data
;
1217 assert(t
->base_type
== GLSL_TYPE_FUNCTION
);
1218 assert(t
->length
== num_params
);
1220 mtx_unlock(&glsl_type::hash_mutex
);
1227 glsl_type::get_mul_type(const glsl_type
*type_a
, const glsl_type
*type_b
)
1229 if (type_a
== type_b
) {
1231 } else if (type_a
->is_matrix() && type_b
->is_matrix()) {
1232 /* Matrix multiply. The columns of A must match the rows of B. Given
1233 * the other previously tested constraints, this means the vector type
1234 * of a row from A must be the same as the vector type of a column from
1237 if (type_a
->row_type() == type_b
->column_type()) {
1238 /* The resulting matrix has the number of columns of matrix B and
1239 * the number of rows of matrix A. We get the row count of A by
1240 * looking at the size of a vector that makes up a column. The
1241 * transpose (size of a row) is done for B.
1243 const glsl_type
*const type
=
1244 get_instance(type_a
->base_type
,
1245 type_a
->column_type()->vector_elements
,
1246 type_b
->row_type()->vector_elements
);
1247 assert(type
!= error_type
);
1251 } else if (type_a
->is_matrix()) {
1252 /* A is a matrix and B is a column vector. Columns of A must match
1253 * rows of B. Given the other previously tested constraints, this
1254 * means the vector type of a row from A must be the same as the
1255 * vector the type of B.
1257 if (type_a
->row_type() == type_b
) {
1258 /* The resulting vector has a number of elements equal to
1259 * the number of rows of matrix A. */
1260 const glsl_type
*const type
=
1261 get_instance(type_a
->base_type
,
1262 type_a
->column_type()->vector_elements
,
1264 assert(type
!= error_type
);
1269 assert(type_b
->is_matrix());
1271 /* A is a row vector and B is a matrix. Columns of A must match rows
1272 * of B. Given the other previously tested constraints, this means
1273 * the type of A must be the same as the vector type of a column from
1276 if (type_a
== type_b
->column_type()) {
1277 /* The resulting vector has a number of elements equal to
1278 * the number of columns of matrix B. */
1279 const glsl_type
*const type
=
1280 get_instance(type_a
->base_type
,
1281 type_b
->row_type()->vector_elements
,
1283 assert(type
!= error_type
);
1294 glsl_type::field_type(const char *name
) const
1296 if (this->base_type
!= GLSL_TYPE_STRUCT
1297 && this->base_type
!= GLSL_TYPE_INTERFACE
)
1300 for (unsigned i
= 0; i
< this->length
; i
++) {
1301 if (strcmp(name
, this->fields
.structure
[i
].name
) == 0)
1302 return this->fields
.structure
[i
].type
;
1310 glsl_type::field_index(const char *name
) const
1312 if (this->base_type
!= GLSL_TYPE_STRUCT
1313 && this->base_type
!= GLSL_TYPE_INTERFACE
)
1316 for (unsigned i
= 0; i
< this->length
; i
++) {
1317 if (strcmp(name
, this->fields
.structure
[i
].name
) == 0)
1326 glsl_type::component_slots() const
1328 switch (this->base_type
) {
1329 case GLSL_TYPE_UINT
:
1331 case GLSL_TYPE_UINT8
:
1332 case GLSL_TYPE_INT8
:
1333 case GLSL_TYPE_UINT16
:
1334 case GLSL_TYPE_INT16
:
1335 case GLSL_TYPE_FLOAT
:
1336 case GLSL_TYPE_FLOAT16
:
1337 case GLSL_TYPE_BOOL
:
1338 return this->components();
1340 case GLSL_TYPE_DOUBLE
:
1341 case GLSL_TYPE_UINT64
:
1342 case GLSL_TYPE_INT64
:
1343 return 2 * this->components();
1345 case GLSL_TYPE_STRUCT
:
1346 case GLSL_TYPE_INTERFACE
: {
1349 for (unsigned i
= 0; i
< this->length
; i
++)
1350 size
+= this->fields
.structure
[i
].type
->component_slots();
1355 case GLSL_TYPE_ARRAY
:
1356 return this->length
* this->fields
.array
->component_slots();
1358 case GLSL_TYPE_SAMPLER
:
1359 case GLSL_TYPE_IMAGE
:
1362 case GLSL_TYPE_SUBROUTINE
:
1365 case GLSL_TYPE_FUNCTION
:
1366 case GLSL_TYPE_ATOMIC_UINT
:
1367 case GLSL_TYPE_VOID
:
1368 case GLSL_TYPE_ERROR
:
1376 glsl_type::record_location_offset(unsigned length
) const
1378 unsigned offset
= 0;
1379 const glsl_type
*t
= this->without_array();
1380 if (t
->is_record()) {
1381 assert(length
<= t
->length
);
1383 for (unsigned i
= 0; i
< length
; i
++) {
1384 const glsl_type
*st
= t
->fields
.structure
[i
].type
;
1385 const glsl_type
*wa
= st
->without_array();
1386 if (wa
->is_record()) {
1387 unsigned r_offset
= wa
->record_location_offset(wa
->length
);
1388 offset
+= st
->is_array() ?
1389 st
->arrays_of_arrays_size() * r_offset
: r_offset
;
1390 } else if (st
->is_array() && st
->fields
.array
->is_array()) {
1391 unsigned outer_array_size
= st
->length
;
1392 const glsl_type
*base_type
= st
->fields
.array
;
1394 /* For arrays of arrays the outer arrays take up a uniform
1395 * slot for each element. The innermost array elements share a
1396 * single slot so we ignore the innermost array when calculating
1399 while (base_type
->fields
.array
->is_array()) {
1400 outer_array_size
= outer_array_size
* base_type
->length
;
1401 base_type
= base_type
->fields
.array
;
1403 offset
+= outer_array_size
;
1405 /* We dont worry about arrays here because unless the array
1406 * contains a structure or another array it only takes up a single
1417 glsl_type::uniform_locations() const
1421 switch (this->base_type
) {
1422 case GLSL_TYPE_UINT
:
1424 case GLSL_TYPE_FLOAT
:
1425 case GLSL_TYPE_FLOAT16
:
1426 case GLSL_TYPE_DOUBLE
:
1427 case GLSL_TYPE_UINT16
:
1428 case GLSL_TYPE_INT16
:
1429 case GLSL_TYPE_UINT64
:
1430 case GLSL_TYPE_INT64
:
1431 case GLSL_TYPE_BOOL
:
1432 case GLSL_TYPE_SAMPLER
:
1433 case GLSL_TYPE_IMAGE
:
1434 case GLSL_TYPE_SUBROUTINE
:
1437 case GLSL_TYPE_STRUCT
:
1438 case GLSL_TYPE_INTERFACE
:
1439 for (unsigned i
= 0; i
< this->length
; i
++)
1440 size
+= this->fields
.structure
[i
].type
->uniform_locations();
1442 case GLSL_TYPE_ARRAY
:
1443 return this->length
* this->fields
.array
->uniform_locations();
1450 glsl_type::varying_count() const
1454 switch (this->base_type
) {
1455 case GLSL_TYPE_UINT
:
1457 case GLSL_TYPE_FLOAT
:
1458 case GLSL_TYPE_FLOAT16
:
1459 case GLSL_TYPE_DOUBLE
:
1460 case GLSL_TYPE_BOOL
:
1461 case GLSL_TYPE_UINT16
:
1462 case GLSL_TYPE_INT16
:
1463 case GLSL_TYPE_UINT64
:
1464 case GLSL_TYPE_INT64
:
1467 case GLSL_TYPE_STRUCT
:
1468 case GLSL_TYPE_INTERFACE
:
1469 for (unsigned i
= 0; i
< this->length
; i
++)
1470 size
+= this->fields
.structure
[i
].type
->varying_count();
1472 case GLSL_TYPE_ARRAY
:
1473 /* Don't count innermost array elements */
1474 if (this->without_array()->is_record() ||
1475 this->without_array()->is_interface() ||
1476 this->fields
.array
->is_array())
1477 return this->length
* this->fields
.array
->varying_count();
1479 return this->fields
.array
->varying_count();
1481 assert(!"unsupported varying type");
1487 glsl_type::can_implicitly_convert_to(const glsl_type
*desired
,
1488 _mesa_glsl_parse_state
*state
) const
1490 if (this == desired
)
1493 /* GLSL 1.10 and ESSL do not allow implicit conversions. If there is no
1494 * state, we're doing intra-stage function linking where these checks have
1495 * already been done.
1497 if (state
&& (state
->es_shader
|| !state
->is_version(120, 0)))
1500 /* There is no conversion among matrix types. */
1501 if (this->matrix_columns
> 1 || desired
->matrix_columns
> 1)
1504 /* Vector size must match. */
1505 if (this->vector_elements
!= desired
->vector_elements
)
1508 /* int and uint can be converted to float. */
1509 if (desired
->is_float() && this->is_integer())
1512 /* With GLSL 4.0, ARB_gpu_shader5, or MESA_shader_integer_functions, int
1513 * can be converted to uint. Note that state may be NULL here, when
1514 * resolving function calls in the linker. By this time, all the
1515 * state-dependent checks have already happened though, so allow anything
1516 * that's allowed in any shader version.
1518 if ((!state
|| state
->is_version(400, 0) || state
->ARB_gpu_shader5_enable
||
1519 state
->MESA_shader_integer_functions_enable
) &&
1520 desired
->base_type
== GLSL_TYPE_UINT
&& this->base_type
== GLSL_TYPE_INT
)
1523 /* No implicit conversions from double. */
1524 if ((!state
|| state
->has_double()) && this->is_double())
1527 /* Conversions from different types to double. */
1528 if ((!state
|| state
->has_double()) && desired
->is_double()) {
1529 if (this->is_float())
1531 if (this->is_integer())
1539 glsl_type::std140_base_alignment(bool row_major
) const
1541 unsigned N
= is_64bit() ? 8 : 4;
1543 /* (1) If the member is a scalar consuming <N> basic machine units, the
1544 * base alignment is <N>.
1546 * (2) If the member is a two- or four-component vector with components
1547 * consuming <N> basic machine units, the base alignment is 2<N> or
1548 * 4<N>, respectively.
1550 * (3) If the member is a three-component vector with components consuming
1551 * <N> basic machine units, the base alignment is 4<N>.
1553 if (this->is_scalar() || this->is_vector()) {
1554 switch (this->vector_elements
) {
1565 /* (4) If the member is an array of scalars or vectors, the base alignment
1566 * and array stride are set to match the base alignment of a single
1567 * array element, according to rules (1), (2), and (3), and rounded up
1568 * to the base alignment of a vec4. The array may have padding at the
1569 * end; the base offset of the member following the array is rounded up
1570 * to the next multiple of the base alignment.
1572 * (6) If the member is an array of <S> column-major matrices with <C>
1573 * columns and <R> rows, the matrix is stored identically to a row of
1574 * <S>*<C> column vectors with <R> components each, according to rule
1577 * (8) If the member is an array of <S> row-major matrices with <C> columns
1578 * and <R> rows, the matrix is stored identically to a row of <S>*<R>
1579 * row vectors with <C> components each, according to rule (4).
1581 * (10) If the member is an array of <S> structures, the <S> elements of
1582 * the array are laid out in order, according to rule (9).
1584 if (this->is_array()) {
1585 if (this->fields
.array
->is_scalar() ||
1586 this->fields
.array
->is_vector() ||
1587 this->fields
.array
->is_matrix()) {
1588 return MAX2(this->fields
.array
->std140_base_alignment(row_major
), 16);
1590 assert(this->fields
.array
->is_record() ||
1591 this->fields
.array
->is_array());
1592 return this->fields
.array
->std140_base_alignment(row_major
);
1596 /* (5) If the member is a column-major matrix with <C> columns and
1597 * <R> rows, the matrix is stored identically to an array of
1598 * <C> column vectors with <R> components each, according to
1601 * (7) If the member is a row-major matrix with <C> columns and <R>
1602 * rows, the matrix is stored identically to an array of <R>
1603 * row vectors with <C> components each, according to rule (4).
1605 if (this->is_matrix()) {
1606 const struct glsl_type
*vec_type
, *array_type
;
1607 int c
= this->matrix_columns
;
1608 int r
= this->vector_elements
;
1611 vec_type
= get_instance(base_type
, c
, 1);
1612 array_type
= glsl_type::get_array_instance(vec_type
, r
);
1614 vec_type
= get_instance(base_type
, r
, 1);
1615 array_type
= glsl_type::get_array_instance(vec_type
, c
);
1618 return array_type
->std140_base_alignment(false);
1621 /* (9) If the member is a structure, the base alignment of the
1622 * structure is <N>, where <N> is the largest base alignment
1623 * value of any of its members, and rounded up to the base
1624 * alignment of a vec4. The individual members of this
1625 * sub-structure are then assigned offsets by applying this set
1626 * of rules recursively, where the base offset of the first
1627 * member of the sub-structure is equal to the aligned offset
1628 * of the structure. The structure may have padding at the end;
1629 * the base offset of the member following the sub-structure is
1630 * rounded up to the next multiple of the base alignment of the
1633 if (this->is_record()) {
1634 unsigned base_alignment
= 16;
1635 for (unsigned i
= 0; i
< this->length
; i
++) {
1636 bool field_row_major
= row_major
;
1637 const enum glsl_matrix_layout matrix_layout
=
1638 glsl_matrix_layout(this->fields
.structure
[i
].matrix_layout
);
1639 if (matrix_layout
== GLSL_MATRIX_LAYOUT_ROW_MAJOR
) {
1640 field_row_major
= true;
1641 } else if (matrix_layout
== GLSL_MATRIX_LAYOUT_COLUMN_MAJOR
) {
1642 field_row_major
= false;
1645 const struct glsl_type
*field_type
= this->fields
.structure
[i
].type
;
1646 base_alignment
= MAX2(base_alignment
,
1647 field_type
->std140_base_alignment(field_row_major
));
1649 return base_alignment
;
1652 assert(!"not reached");
1657 glsl_type::std140_size(bool row_major
) const
1659 unsigned N
= is_64bit() ? 8 : 4;
1661 /* (1) If the member is a scalar consuming <N> basic machine units, the
1662 * base alignment is <N>.
1664 * (2) If the member is a two- or four-component vector with components
1665 * consuming <N> basic machine units, the base alignment is 2<N> or
1666 * 4<N>, respectively.
1668 * (3) If the member is a three-component vector with components consuming
1669 * <N> basic machine units, the base alignment is 4<N>.
1671 if (this->is_scalar() || this->is_vector()) {
1672 return this->vector_elements
* N
;
1675 /* (5) If the member is a column-major matrix with <C> columns and
1676 * <R> rows, the matrix is stored identically to an array of
1677 * <C> column vectors with <R> components each, according to
1680 * (6) If the member is an array of <S> column-major matrices with <C>
1681 * columns and <R> rows, the matrix is stored identically to a row of
1682 * <S>*<C> column vectors with <R> components each, according to rule
1685 * (7) If the member is a row-major matrix with <C> columns and <R>
1686 * rows, the matrix is stored identically to an array of <R>
1687 * row vectors with <C> components each, according to rule (4).
1689 * (8) If the member is an array of <S> row-major matrices with <C> columns
1690 * and <R> rows, the matrix is stored identically to a row of <S>*<R>
1691 * row vectors with <C> components each, according to rule (4).
1693 if (this->without_array()->is_matrix()) {
1694 const struct glsl_type
*element_type
;
1695 const struct glsl_type
*vec_type
;
1696 unsigned int array_len
;
1698 if (this->is_array()) {
1699 element_type
= this->without_array();
1700 array_len
= this->arrays_of_arrays_size();
1702 element_type
= this;
1707 vec_type
= get_instance(element_type
->base_type
,
1708 element_type
->matrix_columns
, 1);
1710 array_len
*= element_type
->vector_elements
;
1712 vec_type
= get_instance(element_type
->base_type
,
1713 element_type
->vector_elements
, 1);
1714 array_len
*= element_type
->matrix_columns
;
1716 const glsl_type
*array_type
= glsl_type::get_array_instance(vec_type
,
1719 return array_type
->std140_size(false);
1722 /* (4) If the member is an array of scalars or vectors, the base alignment
1723 * and array stride are set to match the base alignment of a single
1724 * array element, according to rules (1), (2), and (3), and rounded up
1725 * to the base alignment of a vec4. The array may have padding at the
1726 * end; the base offset of the member following the array is rounded up
1727 * to the next multiple of the base alignment.
1729 * (10) If the member is an array of <S> structures, the <S> elements of
1730 * the array are laid out in order, according to rule (9).
1732 if (this->is_array()) {
1733 if (this->without_array()->is_record()) {
1734 return this->arrays_of_arrays_size() *
1735 this->without_array()->std140_size(row_major
);
1737 unsigned element_base_align
=
1738 this->without_array()->std140_base_alignment(row_major
);
1739 return this->arrays_of_arrays_size() * MAX2(element_base_align
, 16);
1743 /* (9) If the member is a structure, the base alignment of the
1744 * structure is <N>, where <N> is the largest base alignment
1745 * value of any of its members, and rounded up to the base
1746 * alignment of a vec4. The individual members of this
1747 * sub-structure are then assigned offsets by applying this set
1748 * of rules recursively, where the base offset of the first
1749 * member of the sub-structure is equal to the aligned offset
1750 * of the structure. The structure may have padding at the end;
1751 * the base offset of the member following the sub-structure is
1752 * rounded up to the next multiple of the base alignment of the
1755 if (this->is_record() || this->is_interface()) {
1757 unsigned max_align
= 0;
1759 for (unsigned i
= 0; i
< this->length
; i
++) {
1760 bool field_row_major
= row_major
;
1761 const enum glsl_matrix_layout matrix_layout
=
1762 glsl_matrix_layout(this->fields
.structure
[i
].matrix_layout
);
1763 if (matrix_layout
== GLSL_MATRIX_LAYOUT_ROW_MAJOR
) {
1764 field_row_major
= true;
1765 } else if (matrix_layout
== GLSL_MATRIX_LAYOUT_COLUMN_MAJOR
) {
1766 field_row_major
= false;
1769 const struct glsl_type
*field_type
= this->fields
.structure
[i
].type
;
1770 unsigned align
= field_type
->std140_base_alignment(field_row_major
);
1772 /* Ignore unsized arrays when calculating size */
1773 if (field_type
->is_unsized_array())
1776 size
= glsl_align(size
, align
);
1777 size
+= field_type
->std140_size(field_row_major
);
1779 max_align
= MAX2(align
, max_align
);
1781 if (field_type
->is_record() && (i
+ 1 < this->length
))
1782 size
= glsl_align(size
, 16);
1784 size
= glsl_align(size
, MAX2(max_align
, 16));
1788 assert(!"not reached");
1793 glsl_type::std430_base_alignment(bool row_major
) const
1796 unsigned N
= is_64bit() ? 8 : 4;
1798 /* (1) If the member is a scalar consuming <N> basic machine units, the
1799 * base alignment is <N>.
1801 * (2) If the member is a two- or four-component vector with components
1802 * consuming <N> basic machine units, the base alignment is 2<N> or
1803 * 4<N>, respectively.
1805 * (3) If the member is a three-component vector with components consuming
1806 * <N> basic machine units, the base alignment is 4<N>.
1808 if (this->is_scalar() || this->is_vector()) {
1809 switch (this->vector_elements
) {
1820 /* OpenGL 4.30 spec, section 7.6.2.2 "Standard Uniform Block Layout":
1822 * "When using the std430 storage layout, shader storage blocks will be
1823 * laid out in buffer storage identically to uniform and shader storage
1824 * blocks using the std140 layout, except that the base alignment and
1825 * stride of arrays of scalars and vectors in rule 4 and of structures
1826 * in rule 9 are not rounded up a multiple of the base alignment of a vec4.
1829 /* (1) If the member is a scalar consuming <N> basic machine units, the
1830 * base alignment is <N>.
1832 * (2) If the member is a two- or four-component vector with components
1833 * consuming <N> basic machine units, the base alignment is 2<N> or
1834 * 4<N>, respectively.
1836 * (3) If the member is a three-component vector with components consuming
1837 * <N> basic machine units, the base alignment is 4<N>.
1839 if (this->is_array())
1840 return this->fields
.array
->std430_base_alignment(row_major
);
1842 /* (5) If the member is a column-major matrix with <C> columns and
1843 * <R> rows, the matrix is stored identically to an array of
1844 * <C> column vectors with <R> components each, according to
1847 * (7) If the member is a row-major matrix with <C> columns and <R>
1848 * rows, the matrix is stored identically to an array of <R>
1849 * row vectors with <C> components each, according to rule (4).
1851 if (this->is_matrix()) {
1852 const struct glsl_type
*vec_type
, *array_type
;
1853 int c
= this->matrix_columns
;
1854 int r
= this->vector_elements
;
1857 vec_type
= get_instance(base_type
, c
, 1);
1858 array_type
= glsl_type::get_array_instance(vec_type
, r
);
1860 vec_type
= get_instance(base_type
, r
, 1);
1861 array_type
= glsl_type::get_array_instance(vec_type
, c
);
1864 return array_type
->std430_base_alignment(false);
1867 /* (9) If the member is a structure, the base alignment of the
1868 * structure is <N>, where <N> is the largest base alignment
1869 * value of any of its members, and rounded up to the base
1870 * alignment of a vec4. The individual members of this
1871 * sub-structure are then assigned offsets by applying this set
1872 * of rules recursively, where the base offset of the first
1873 * member of the sub-structure is equal to the aligned offset
1874 * of the structure. The structure may have padding at the end;
1875 * the base offset of the member following the sub-structure is
1876 * rounded up to the next multiple of the base alignment of the
1879 if (this->is_record()) {
1880 unsigned base_alignment
= 0;
1881 for (unsigned i
= 0; i
< this->length
; i
++) {
1882 bool field_row_major
= row_major
;
1883 const enum glsl_matrix_layout matrix_layout
=
1884 glsl_matrix_layout(this->fields
.structure
[i
].matrix_layout
);
1885 if (matrix_layout
== GLSL_MATRIX_LAYOUT_ROW_MAJOR
) {
1886 field_row_major
= true;
1887 } else if (matrix_layout
== GLSL_MATRIX_LAYOUT_COLUMN_MAJOR
) {
1888 field_row_major
= false;
1891 const struct glsl_type
*field_type
= this->fields
.structure
[i
].type
;
1892 base_alignment
= MAX2(base_alignment
,
1893 field_type
->std430_base_alignment(field_row_major
));
1895 assert(base_alignment
> 0);
1896 return base_alignment
;
1898 assert(!"not reached");
1903 glsl_type::std430_array_stride(bool row_major
) const
1905 unsigned N
= is_64bit() ? 8 : 4;
1907 /* Notice that the array stride of a vec3 is not 3 * N but 4 * N.
1908 * See OpenGL 4.30 spec, section 7.6.2.2 "Standard Uniform Block Layout"
1910 * (3) If the member is a three-component vector with components consuming
1911 * <N> basic machine units, the base alignment is 4<N>.
1913 if (this->is_vector() && this->vector_elements
== 3)
1916 /* By default use std430_size(row_major) */
1917 return this->std430_size(row_major
);
1921 glsl_type::std430_size(bool row_major
) const
1923 unsigned N
= is_64bit() ? 8 : 4;
1925 /* OpenGL 4.30 spec, section 7.6.2.2 "Standard Uniform Block Layout":
1927 * "When using the std430 storage layout, shader storage blocks will be
1928 * laid out in buffer storage identically to uniform and shader storage
1929 * blocks using the std140 layout, except that the base alignment and
1930 * stride of arrays of scalars and vectors in rule 4 and of structures
1931 * in rule 9 are not rounded up a multiple of the base alignment of a vec4.
1933 if (this->is_scalar() || this->is_vector())
1934 return this->vector_elements
* N
;
1936 if (this->without_array()->is_matrix()) {
1937 const struct glsl_type
*element_type
;
1938 const struct glsl_type
*vec_type
;
1939 unsigned int array_len
;
1941 if (this->is_array()) {
1942 element_type
= this->without_array();
1943 array_len
= this->arrays_of_arrays_size();
1945 element_type
= this;
1950 vec_type
= get_instance(element_type
->base_type
,
1951 element_type
->matrix_columns
, 1);
1953 array_len
*= element_type
->vector_elements
;
1955 vec_type
= get_instance(element_type
->base_type
,
1956 element_type
->vector_elements
, 1);
1957 array_len
*= element_type
->matrix_columns
;
1959 const glsl_type
*array_type
= glsl_type::get_array_instance(vec_type
,
1962 return array_type
->std430_size(false);
1965 if (this->is_array()) {
1966 if (this->without_array()->is_record())
1967 return this->arrays_of_arrays_size() *
1968 this->without_array()->std430_size(row_major
);
1970 return this->arrays_of_arrays_size() *
1971 this->without_array()->std430_base_alignment(row_major
);
1974 if (this->is_record() || this->is_interface()) {
1976 unsigned max_align
= 0;
1978 for (unsigned i
= 0; i
< this->length
; i
++) {
1979 bool field_row_major
= row_major
;
1980 const enum glsl_matrix_layout matrix_layout
=
1981 glsl_matrix_layout(this->fields
.structure
[i
].matrix_layout
);
1982 if (matrix_layout
== GLSL_MATRIX_LAYOUT_ROW_MAJOR
) {
1983 field_row_major
= true;
1984 } else if (matrix_layout
== GLSL_MATRIX_LAYOUT_COLUMN_MAJOR
) {
1985 field_row_major
= false;
1988 const struct glsl_type
*field_type
= this->fields
.structure
[i
].type
;
1989 unsigned align
= field_type
->std430_base_alignment(field_row_major
);
1990 size
= glsl_align(size
, align
);
1991 size
+= field_type
->std430_size(field_row_major
);
1993 max_align
= MAX2(align
, max_align
);
1995 size
= glsl_align(size
, max_align
);
1999 assert(!"not reached");
2004 glsl_type::count_attribute_slots(bool is_vertex_input
) const
2006 /* From page 31 (page 37 of the PDF) of the GLSL 1.50 spec:
2008 * "A scalar input counts the same amount against this limit as a vec4,
2009 * so applications may want to consider packing groups of four
2010 * unrelated float inputs together into a vector to better utilize the
2011 * capabilities of the underlying hardware. A matrix input will use up
2012 * multiple locations. The number of locations used will equal the
2013 * number of columns in the matrix."
2015 * The spec does not explicitly say how arrays are counted. However, it
2016 * should be safe to assume the total number of slots consumed by an array
2017 * is the number of entries in the array multiplied by the number of slots
2018 * consumed by a single element of the array.
2020 * The spec says nothing about how structs are counted, because vertex
2021 * attributes are not allowed to be (or contain) structs. However, Mesa
2022 * allows varying structs, the number of varying slots taken up by a
2023 * varying struct is simply equal to the sum of the number of slots taken
2024 * up by each element.
2026 * Doubles are counted different depending on whether they are vertex
2027 * inputs or everything else. Vertex inputs from ARB_vertex_attrib_64bit
2028 * take one location no matter what size they are, otherwise dvec3/4
2029 * take two locations.
2031 switch (this->base_type
) {
2032 case GLSL_TYPE_UINT
:
2034 case GLSL_TYPE_UINT8
:
2035 case GLSL_TYPE_INT8
:
2036 case GLSL_TYPE_UINT16
:
2037 case GLSL_TYPE_INT16
:
2038 case GLSL_TYPE_FLOAT
:
2039 case GLSL_TYPE_FLOAT16
:
2040 case GLSL_TYPE_BOOL
:
2041 case GLSL_TYPE_SAMPLER
:
2042 case GLSL_TYPE_IMAGE
:
2043 return this->matrix_columns
;
2044 case GLSL_TYPE_DOUBLE
:
2045 case GLSL_TYPE_UINT64
:
2046 case GLSL_TYPE_INT64
:
2047 if (this->vector_elements
> 2 && !is_vertex_input
)
2048 return this->matrix_columns
* 2;
2050 return this->matrix_columns
;
2051 case GLSL_TYPE_STRUCT
:
2052 case GLSL_TYPE_INTERFACE
: {
2055 for (unsigned i
= 0; i
< this->length
; i
++)
2056 size
+= this->fields
.structure
[i
].type
->count_attribute_slots(is_vertex_input
);
2061 case GLSL_TYPE_ARRAY
:
2062 return this->length
* this->fields
.array
->count_attribute_slots(is_vertex_input
);
2064 case GLSL_TYPE_SUBROUTINE
:
2067 case GLSL_TYPE_FUNCTION
:
2068 case GLSL_TYPE_ATOMIC_UINT
:
2069 case GLSL_TYPE_VOID
:
2070 case GLSL_TYPE_ERROR
:
2074 assert(!"Unexpected type in count_attribute_slots()");
2080 glsl_type::coordinate_components() const
2084 switch (sampler_dimensionality
) {
2085 case GLSL_SAMPLER_DIM_1D
:
2086 case GLSL_SAMPLER_DIM_BUF
:
2089 case GLSL_SAMPLER_DIM_2D
:
2090 case GLSL_SAMPLER_DIM_RECT
:
2091 case GLSL_SAMPLER_DIM_MS
:
2092 case GLSL_SAMPLER_DIM_EXTERNAL
:
2093 case GLSL_SAMPLER_DIM_SUBPASS
:
2096 case GLSL_SAMPLER_DIM_3D
:
2097 case GLSL_SAMPLER_DIM_CUBE
:
2101 assert(!"Should not get here.");
2106 /* Array textures need an additional component for the array index, except
2107 * for cubemap array images that behave like a 2D array of interleaved
2110 if (sampler_array
&&
2111 !(is_image() && sampler_dimensionality
== GLSL_SAMPLER_DIM_CUBE
))
2118 * Declarations of type flyweights (glsl_type::_foo_type) and
2119 * convenience pointers (glsl_type::foo_type).
2122 #define DECL_TYPE(NAME, ...) \
2123 const glsl_type glsl_type::_##NAME##_type = glsl_type(__VA_ARGS__, #NAME); \
2124 const glsl_type *const glsl_type::NAME##_type = &glsl_type::_##NAME##_type;
2126 #define STRUCT_TYPE(NAME)
2128 #include "compiler/builtin_type_macros.h"
2132 get_struct_type_field_and_pointer_sizes(size_t *s_field_size
,
2133 size_t *s_field_ptrs
)
2135 *s_field_size
= sizeof(glsl_struct_field
);
2137 sizeof(((glsl_struct_field
*)0)->type
) +
2138 sizeof(((glsl_struct_field
*)0)->name
);
2142 encode_type_to_blob(struct blob
*blob
, const glsl_type
*type
)
2147 blob_write_uint32(blob
, 0);
2151 switch (type
->base_type
) {
2152 case GLSL_TYPE_UINT
:
2154 case GLSL_TYPE_FLOAT
:
2155 case GLSL_TYPE_BOOL
:
2156 case GLSL_TYPE_DOUBLE
:
2157 case GLSL_TYPE_UINT64
:
2158 case GLSL_TYPE_INT64
:
2159 encoding
= (type
->base_type
<< 24) |
2160 (type
->vector_elements
<< 4) |
2161 (type
->matrix_columns
);
2163 case GLSL_TYPE_SAMPLER
:
2164 encoding
= (type
->base_type
) << 24 |
2165 (type
->sampler_dimensionality
<< 4) |
2166 (type
->sampler_shadow
<< 3) |
2167 (type
->sampler_array
<< 2) |
2168 (type
->sampled_type
);
2170 case GLSL_TYPE_SUBROUTINE
:
2171 encoding
= type
->base_type
<< 24;
2172 blob_write_uint32(blob
, encoding
);
2173 blob_write_string(blob
, type
->name
);
2175 case GLSL_TYPE_IMAGE
:
2176 encoding
= (type
->base_type
) << 24 |
2177 (type
->sampler_dimensionality
<< 3) |
2178 (type
->sampler_array
<< 2) |
2179 (type
->sampled_type
);
2181 case GLSL_TYPE_ATOMIC_UINT
:
2182 encoding
= (type
->base_type
<< 24);
2184 case GLSL_TYPE_ARRAY
:
2185 blob_write_uint32(blob
, (type
->base_type
) << 24);
2186 blob_write_uint32(blob
, type
->length
);
2187 encode_type_to_blob(blob
, type
->fields
.array
);
2189 case GLSL_TYPE_STRUCT
:
2190 case GLSL_TYPE_INTERFACE
:
2191 blob_write_uint32(blob
, (type
->base_type
) << 24);
2192 blob_write_string(blob
, type
->name
);
2193 blob_write_uint32(blob
, type
->length
);
2195 size_t s_field_size
, s_field_ptrs
;
2196 get_struct_type_field_and_pointer_sizes(&s_field_size
, &s_field_ptrs
);
2198 for (unsigned i
= 0; i
< type
->length
; i
++) {
2199 encode_type_to_blob(blob
, type
->fields
.structure
[i
].type
);
2200 blob_write_string(blob
, type
->fields
.structure
[i
].name
);
2202 /* Write the struct field skipping the pointers */
2203 blob_write_bytes(blob
,
2204 ((char *)&type
->fields
.structure
[i
]) + s_field_ptrs
,
2205 s_field_size
- s_field_ptrs
);
2208 if (type
->is_interface()) {
2209 blob_write_uint32(blob
, type
->interface_packing
);
2210 blob_write_uint32(blob
, type
->interface_row_major
);
2213 case GLSL_TYPE_VOID
:
2214 encoding
= (type
->base_type
<< 24);
2216 case GLSL_TYPE_ERROR
:
2218 assert(!"Cannot encode type!");
2223 blob_write_uint32(blob
, encoding
);
2227 decode_type_from_blob(struct blob_reader
*blob
)
2229 uint32_t u
= blob_read_uint32(blob
);
2235 glsl_base_type base_type
= (glsl_base_type
) (u
>> 24);
2237 switch (base_type
) {
2238 case GLSL_TYPE_UINT
:
2240 case GLSL_TYPE_FLOAT
:
2241 case GLSL_TYPE_BOOL
:
2242 case GLSL_TYPE_DOUBLE
:
2243 case GLSL_TYPE_UINT64
:
2244 case GLSL_TYPE_INT64
:
2245 return glsl_type::get_instance(base_type
, (u
>> 4) & 0x0f, u
& 0x0f);
2246 case GLSL_TYPE_SAMPLER
:
2247 return glsl_type::get_sampler_instance((enum glsl_sampler_dim
) ((u
>> 4) & 0x07),
2250 (glsl_base_type
) ((u
>> 0) & 0x03));
2251 case GLSL_TYPE_SUBROUTINE
:
2252 return glsl_type::get_subroutine_instance(blob_read_string(blob
));
2253 case GLSL_TYPE_IMAGE
:
2254 return glsl_type::get_image_instance((enum glsl_sampler_dim
) ((u
>> 3) & 0x07),
2256 (glsl_base_type
) ((u
>> 0) & 0x03));
2257 case GLSL_TYPE_ATOMIC_UINT
:
2258 return glsl_type::atomic_uint_type
;
2259 case GLSL_TYPE_ARRAY
: {
2260 unsigned length
= blob_read_uint32(blob
);
2261 return glsl_type::get_array_instance(decode_type_from_blob(blob
),
2264 case GLSL_TYPE_STRUCT
:
2265 case GLSL_TYPE_INTERFACE
: {
2266 char *name
= blob_read_string(blob
);
2267 unsigned num_fields
= blob_read_uint32(blob
);
2269 size_t s_field_size
, s_field_ptrs
;
2270 get_struct_type_field_and_pointer_sizes(&s_field_size
, &s_field_ptrs
);
2272 glsl_struct_field
*fields
=
2273 (glsl_struct_field
*) malloc(s_field_size
* num_fields
);
2274 for (unsigned i
= 0; i
< num_fields
; i
++) {
2275 fields
[i
].type
= decode_type_from_blob(blob
);
2276 fields
[i
].name
= blob_read_string(blob
);
2278 blob_copy_bytes(blob
, ((uint8_t *) &fields
[i
]) + s_field_ptrs
,
2279 s_field_size
- s_field_ptrs
);
2283 if (base_type
== GLSL_TYPE_INTERFACE
) {
2284 enum glsl_interface_packing packing
=
2285 (glsl_interface_packing
) blob_read_uint32(blob
);
2286 bool row_major
= blob_read_uint32(blob
);
2287 t
= glsl_type::get_interface_instance(fields
, num_fields
, packing
,
2290 t
= glsl_type::get_record_instance(fields
, num_fields
, name
);
2296 case GLSL_TYPE_VOID
:
2297 return glsl_type::void_type
;
2298 case GLSL_TYPE_ERROR
:
2300 assert(!"Cannot decode type!");