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
);
498 glsl_type::vec(unsigned components
)
500 if (components
== 0 || components
> 4)
503 static const glsl_type
*const ts
[] = {
504 float_type
, vec2_type
, vec3_type
, vec4_type
506 return ts
[components
- 1];
510 glsl_type::f16vec(unsigned components
)
512 if (components
== 0 || components
> 4)
515 static const glsl_type
*const ts
[] = {
516 float16_t_type
, f16vec2_type
, f16vec3_type
, f16vec4_type
518 return ts
[components
- 1];
522 glsl_type::dvec(unsigned components
)
524 if (components
== 0 || components
> 4)
527 static const glsl_type
*const ts
[] = {
528 double_type
, dvec2_type
, dvec3_type
, dvec4_type
530 return ts
[components
- 1];
534 glsl_type::ivec(unsigned components
)
536 if (components
== 0 || components
> 4)
539 static const glsl_type
*const ts
[] = {
540 int_type
, ivec2_type
, ivec3_type
, ivec4_type
542 return ts
[components
- 1];
547 glsl_type::uvec(unsigned components
)
549 if (components
== 0 || components
> 4)
552 static const glsl_type
*const ts
[] = {
553 uint_type
, uvec2_type
, uvec3_type
, uvec4_type
555 return ts
[components
- 1];
560 glsl_type::bvec(unsigned components
)
562 if (components
== 0 || components
> 4)
565 static const glsl_type
*const ts
[] = {
566 bool_type
, bvec2_type
, bvec3_type
, bvec4_type
568 return ts
[components
- 1];
573 glsl_type::i64vec(unsigned components
)
575 if (components
== 0 || components
> 4)
578 static const glsl_type
*const ts
[] = {
579 int64_t_type
, i64vec2_type
, i64vec3_type
, i64vec4_type
581 return ts
[components
- 1];
586 glsl_type::u64vec(unsigned components
)
588 if (components
== 0 || components
> 4)
591 static const glsl_type
*const ts
[] = {
592 uint64_t_type
, u64vec2_type
, u64vec3_type
, u64vec4_type
594 return ts
[components
- 1];
598 glsl_type::i16vec(unsigned components
)
600 if (components
== 0 || components
> 4)
603 static const glsl_type
*const ts
[] = {
604 int16_t_type
, i16vec2_type
, i16vec3_type
, i16vec4_type
606 return ts
[components
- 1];
611 glsl_type::u16vec(unsigned components
)
613 if (components
== 0 || components
> 4)
616 static const glsl_type
*const ts
[] = {
617 uint16_t_type
, u16vec2_type
, u16vec3_type
, u16vec4_type
619 return ts
[components
- 1];
623 glsl_type::get_instance(unsigned base_type
, unsigned rows
, unsigned columns
)
625 if (base_type
== GLSL_TYPE_VOID
)
628 if ((rows
< 1) || (rows
> 4) || (columns
< 1) || (columns
> 4))
631 /* Treat GLSL vectors as Nx1 matrices.
639 case GLSL_TYPE_FLOAT
:
641 case GLSL_TYPE_FLOAT16
:
643 case GLSL_TYPE_DOUBLE
:
647 case GLSL_TYPE_UINT64
:
649 case GLSL_TYPE_INT64
:
651 case GLSL_TYPE_UINT16
:
653 case GLSL_TYPE_INT16
:
659 if ((base_type
!= GLSL_TYPE_FLOAT
&&
660 base_type
!= GLSL_TYPE_DOUBLE
&&
661 base_type
!= GLSL_TYPE_FLOAT16
) || (rows
== 1))
664 /* GLSL matrix types are named mat{COLUMNS}x{ROWS}. Only the following
665 * combinations are valid:
673 #define IDX(c,r) (((c-1)*3) + (r-1))
676 case GLSL_TYPE_DOUBLE
: {
677 switch (IDX(columns
, rows
)) {
678 case IDX(2,2): return dmat2_type
;
679 case IDX(2,3): return dmat2x3_type
;
680 case IDX(2,4): return dmat2x4_type
;
681 case IDX(3,2): return dmat3x2_type
;
682 case IDX(3,3): return dmat3_type
;
683 case IDX(3,4): return dmat3x4_type
;
684 case IDX(4,2): return dmat4x2_type
;
685 case IDX(4,3): return dmat4x3_type
;
686 case IDX(4,4): return dmat4_type
;
687 default: return error_type
;
690 case GLSL_TYPE_FLOAT
: {
691 switch (IDX(columns
, rows
)) {
692 case IDX(2,2): return mat2_type
;
693 case IDX(2,3): return mat2x3_type
;
694 case IDX(2,4): return mat2x4_type
;
695 case IDX(3,2): return mat3x2_type
;
696 case IDX(3,3): return mat3_type
;
697 case IDX(3,4): return mat3x4_type
;
698 case IDX(4,2): return mat4x2_type
;
699 case IDX(4,3): return mat4x3_type
;
700 case IDX(4,4): return mat4_type
;
701 default: return error_type
;
704 case GLSL_TYPE_FLOAT16
: {
705 switch (IDX(columns
, rows
)) {
706 case IDX(2,2): return f16mat2_type
;
707 case IDX(2,3): return f16mat2x3_type
;
708 case IDX(2,4): return f16mat2x4_type
;
709 case IDX(3,2): return f16mat3x2_type
;
710 case IDX(3,3): return f16mat3_type
;
711 case IDX(3,4): return f16mat3x4_type
;
712 case IDX(4,2): return f16mat4x2_type
;
713 case IDX(4,3): return f16mat4x3_type
;
714 case IDX(4,4): return f16mat4_type
;
715 default: return error_type
;
718 default: return error_type
;
722 assert(!"Should not get here.");
727 glsl_type::get_sampler_instance(enum glsl_sampler_dim dim
,
733 case GLSL_TYPE_FLOAT
:
735 case GLSL_SAMPLER_DIM_1D
:
737 return (array
? sampler1DArrayShadow_type
: sampler1DShadow_type
);
739 return (array
? sampler1DArray_type
: sampler1D_type
);
740 case GLSL_SAMPLER_DIM_2D
:
742 return (array
? sampler2DArrayShadow_type
: sampler2DShadow_type
);
744 return (array
? sampler2DArray_type
: sampler2D_type
);
745 case GLSL_SAMPLER_DIM_3D
:
749 return sampler3D_type
;
750 case GLSL_SAMPLER_DIM_CUBE
:
752 return (array
? samplerCubeArrayShadow_type
: samplerCubeShadow_type
);
754 return (array
? samplerCubeArray_type
: samplerCube_type
);
755 case GLSL_SAMPLER_DIM_RECT
:
759 return sampler2DRectShadow_type
;
761 return sampler2DRect_type
;
762 case GLSL_SAMPLER_DIM_BUF
:
766 return samplerBuffer_type
;
767 case GLSL_SAMPLER_DIM_MS
:
770 return (array
? sampler2DMSArray_type
: sampler2DMS_type
);
771 case GLSL_SAMPLER_DIM_EXTERNAL
:
775 return samplerExternalOES_type
;
776 case GLSL_SAMPLER_DIM_SUBPASS
:
777 case GLSL_SAMPLER_DIM_SUBPASS_MS
:
784 case GLSL_SAMPLER_DIM_1D
:
785 return (array
? isampler1DArray_type
: isampler1D_type
);
786 case GLSL_SAMPLER_DIM_2D
:
787 return (array
? isampler2DArray_type
: isampler2D_type
);
788 case GLSL_SAMPLER_DIM_3D
:
791 return isampler3D_type
;
792 case GLSL_SAMPLER_DIM_CUBE
:
793 return (array
? isamplerCubeArray_type
: isamplerCube_type
);
794 case GLSL_SAMPLER_DIM_RECT
:
797 return isampler2DRect_type
;
798 case GLSL_SAMPLER_DIM_BUF
:
801 return isamplerBuffer_type
;
802 case GLSL_SAMPLER_DIM_MS
:
803 return (array
? isampler2DMSArray_type
: isampler2DMS_type
);
804 case GLSL_SAMPLER_DIM_EXTERNAL
:
806 case GLSL_SAMPLER_DIM_SUBPASS
:
807 case GLSL_SAMPLER_DIM_SUBPASS_MS
:
814 case GLSL_SAMPLER_DIM_1D
:
815 return (array
? usampler1DArray_type
: usampler1D_type
);
816 case GLSL_SAMPLER_DIM_2D
:
817 return (array
? usampler2DArray_type
: usampler2D_type
);
818 case GLSL_SAMPLER_DIM_3D
:
821 return usampler3D_type
;
822 case GLSL_SAMPLER_DIM_CUBE
:
823 return (array
? usamplerCubeArray_type
: usamplerCube_type
);
824 case GLSL_SAMPLER_DIM_RECT
:
827 return usampler2DRect_type
;
828 case GLSL_SAMPLER_DIM_BUF
:
831 return usamplerBuffer_type
;
832 case GLSL_SAMPLER_DIM_MS
:
833 return (array
? usampler2DMSArray_type
: usampler2DMS_type
);
834 case GLSL_SAMPLER_DIM_EXTERNAL
:
836 case GLSL_SAMPLER_DIM_SUBPASS
:
837 case GLSL_SAMPLER_DIM_SUBPASS_MS
:
844 unreachable("switch statement above should be complete");
848 glsl_type::get_image_instance(enum glsl_sampler_dim dim
,
849 bool array
, glsl_base_type type
)
852 case GLSL_TYPE_FLOAT
:
854 case GLSL_SAMPLER_DIM_1D
:
855 return (array
? image1DArray_type
: image1D_type
);
856 case GLSL_SAMPLER_DIM_2D
:
857 return (array
? image2DArray_type
: image2D_type
);
858 case GLSL_SAMPLER_DIM_3D
:
860 case GLSL_SAMPLER_DIM_CUBE
:
861 return (array
? imageCubeArray_type
: imageCube_type
);
862 case GLSL_SAMPLER_DIM_RECT
:
866 return image2DRect_type
;
867 case GLSL_SAMPLER_DIM_BUF
:
871 return imageBuffer_type
;
872 case GLSL_SAMPLER_DIM_MS
:
873 return (array
? image2DMSArray_type
: image2DMS_type
);
874 case GLSL_SAMPLER_DIM_SUBPASS
:
875 return subpassInput_type
;
876 case GLSL_SAMPLER_DIM_SUBPASS_MS
:
877 return subpassInputMS_type
;
878 case GLSL_SAMPLER_DIM_EXTERNAL
:
883 case GLSL_SAMPLER_DIM_1D
:
884 return (array
? iimage1DArray_type
: iimage1D_type
);
885 case GLSL_SAMPLER_DIM_2D
:
886 return (array
? iimage2DArray_type
: iimage2D_type
);
887 case GLSL_SAMPLER_DIM_3D
:
890 return iimage3D_type
;
891 case GLSL_SAMPLER_DIM_CUBE
:
892 return (array
? iimageCubeArray_type
: iimageCube_type
);
893 case GLSL_SAMPLER_DIM_RECT
:
896 return iimage2DRect_type
;
897 case GLSL_SAMPLER_DIM_BUF
:
900 return iimageBuffer_type
;
901 case GLSL_SAMPLER_DIM_MS
:
902 return (array
? iimage2DMSArray_type
: iimage2DMS_type
);
903 case GLSL_SAMPLER_DIM_SUBPASS
:
904 return isubpassInput_type
;
905 case GLSL_SAMPLER_DIM_SUBPASS_MS
:
906 return isubpassInputMS_type
;
907 case GLSL_SAMPLER_DIM_EXTERNAL
:
912 case GLSL_SAMPLER_DIM_1D
:
913 return (array
? uimage1DArray_type
: uimage1D_type
);
914 case GLSL_SAMPLER_DIM_2D
:
915 return (array
? uimage2DArray_type
: uimage2D_type
);
916 case GLSL_SAMPLER_DIM_3D
:
919 return uimage3D_type
;
920 case GLSL_SAMPLER_DIM_CUBE
:
921 return (array
? uimageCubeArray_type
: uimageCube_type
);
922 case GLSL_SAMPLER_DIM_RECT
:
925 return uimage2DRect_type
;
926 case GLSL_SAMPLER_DIM_BUF
:
929 return uimageBuffer_type
;
930 case GLSL_SAMPLER_DIM_MS
:
931 return (array
? uimage2DMSArray_type
: uimage2DMS_type
);
932 case GLSL_SAMPLER_DIM_SUBPASS
:
933 return usubpassInput_type
;
934 case GLSL_SAMPLER_DIM_SUBPASS_MS
:
935 return usubpassInputMS_type
;
936 case GLSL_SAMPLER_DIM_EXTERNAL
:
943 unreachable("switch statement above should be complete");
947 glsl_type::get_array_instance(const glsl_type
*base
, unsigned array_size
)
949 /* Generate a name using the base type pointer in the key. This is
950 * done because the name of the base type may not be unique across
951 * shaders. For example, two shaders may have different record types
955 snprintf(key
, sizeof(key
), "%p[%u]", (void *) base
, array_size
);
957 mtx_lock(&glsl_type::hash_mutex
);
959 if (array_types
== NULL
) {
960 array_types
= _mesa_hash_table_create(NULL
, _mesa_key_hash_string
,
961 _mesa_key_string_equal
);
964 const struct hash_entry
*entry
= _mesa_hash_table_search(array_types
, key
);
966 const glsl_type
*t
= new glsl_type(base
, array_size
);
968 entry
= _mesa_hash_table_insert(array_types
,
973 assert(((glsl_type
*) entry
->data
)->base_type
== GLSL_TYPE_ARRAY
);
974 assert(((glsl_type
*) entry
->data
)->length
== array_size
);
975 assert(((glsl_type
*) entry
->data
)->fields
.array
== base
);
977 mtx_unlock(&glsl_type::hash_mutex
);
979 return (glsl_type
*) entry
->data
;
984 glsl_type::record_compare(const glsl_type
*b
, bool match_locations
) const
986 if (this->length
!= b
->length
)
989 if (this->interface_packing
!= b
->interface_packing
)
992 if (this->interface_row_major
!= b
->interface_row_major
)
995 /* From the GLSL 4.20 specification (Sec 4.2):
997 * "Structures must have the same name, sequence of type names, and
998 * type definitions, and field names to be considered the same type."
1000 * GLSL ES behaves the same (Ver 1.00 Sec 4.2.4, Ver 3.00 Sec 4.2.5).
1002 if (strcmp(this->name
, b
->name
) != 0)
1005 for (unsigned i
= 0; i
< this->length
; i
++) {
1006 if (this->fields
.structure
[i
].type
!= b
->fields
.structure
[i
].type
)
1008 if (strcmp(this->fields
.structure
[i
].name
,
1009 b
->fields
.structure
[i
].name
) != 0)
1011 if (this->fields
.structure
[i
].matrix_layout
1012 != b
->fields
.structure
[i
].matrix_layout
)
1014 if (match_locations
&& this->fields
.structure
[i
].location
1015 != b
->fields
.structure
[i
].location
)
1017 if (this->fields
.structure
[i
].offset
1018 != b
->fields
.structure
[i
].offset
)
1020 if (this->fields
.structure
[i
].interpolation
1021 != b
->fields
.structure
[i
].interpolation
)
1023 if (this->fields
.structure
[i
].centroid
1024 != b
->fields
.structure
[i
].centroid
)
1026 if (this->fields
.structure
[i
].sample
1027 != b
->fields
.structure
[i
].sample
)
1029 if (this->fields
.structure
[i
].patch
1030 != b
->fields
.structure
[i
].patch
)
1032 if (this->fields
.structure
[i
].memory_read_only
1033 != b
->fields
.structure
[i
].memory_read_only
)
1035 if (this->fields
.structure
[i
].memory_write_only
1036 != b
->fields
.structure
[i
].memory_write_only
)
1038 if (this->fields
.structure
[i
].memory_coherent
1039 != b
->fields
.structure
[i
].memory_coherent
)
1041 if (this->fields
.structure
[i
].memory_volatile
1042 != b
->fields
.structure
[i
].memory_volatile
)
1044 if (this->fields
.structure
[i
].memory_restrict
1045 != b
->fields
.structure
[i
].memory_restrict
)
1047 if (this->fields
.structure
[i
].image_format
1048 != b
->fields
.structure
[i
].image_format
)
1050 if (this->fields
.structure
[i
].precision
1051 != b
->fields
.structure
[i
].precision
)
1053 if (this->fields
.structure
[i
].explicit_xfb_buffer
1054 != b
->fields
.structure
[i
].explicit_xfb_buffer
)
1056 if (this->fields
.structure
[i
].xfb_buffer
1057 != b
->fields
.structure
[i
].xfb_buffer
)
1059 if (this->fields
.structure
[i
].xfb_stride
1060 != b
->fields
.structure
[i
].xfb_stride
)
1069 glsl_type::record_key_compare(const void *a
, const void *b
)
1071 const glsl_type
*const key1
= (glsl_type
*) a
;
1072 const glsl_type
*const key2
= (glsl_type
*) b
;
1074 return strcmp(key1
->name
, key2
->name
) == 0 && key1
->record_compare(key2
);
1079 * Generate an integer hash value for a glsl_type structure type.
1082 glsl_type::record_key_hash(const void *a
)
1084 const glsl_type
*const key
= (glsl_type
*) a
;
1085 uintptr_t hash
= key
->length
;
1088 for (unsigned i
= 0; i
< key
->length
; i
++) {
1089 /* casting pointer to uintptr_t */
1090 hash
= (hash
* 13 ) + (uintptr_t) key
->fields
.structure
[i
].type
;
1093 if (sizeof(hash
) == 8)
1094 retval
= (hash
& 0xffffffff) ^ ((uint64_t) hash
>> 32);
1103 glsl_type::get_record_instance(const glsl_struct_field
*fields
,
1104 unsigned num_fields
,
1107 const glsl_type
key(fields
, num_fields
, name
);
1109 mtx_lock(&glsl_type::hash_mutex
);
1111 if (record_types
== NULL
) {
1112 record_types
= _mesa_hash_table_create(NULL
, record_key_hash
,
1113 record_key_compare
);
1116 const struct hash_entry
*entry
= _mesa_hash_table_search(record_types
,
1118 if (entry
== NULL
) {
1119 const glsl_type
*t
= new glsl_type(fields
, num_fields
, name
);
1121 entry
= _mesa_hash_table_insert(record_types
, t
, (void *) t
);
1124 assert(((glsl_type
*) entry
->data
)->base_type
== GLSL_TYPE_STRUCT
);
1125 assert(((glsl_type
*) entry
->data
)->length
== num_fields
);
1126 assert(strcmp(((glsl_type
*) entry
->data
)->name
, name
) == 0);
1128 mtx_unlock(&glsl_type::hash_mutex
);
1130 return (glsl_type
*) entry
->data
;
1135 glsl_type::get_interface_instance(const glsl_struct_field
*fields
,
1136 unsigned num_fields
,
1137 enum glsl_interface_packing packing
,
1139 const char *block_name
)
1141 const glsl_type
key(fields
, num_fields
, packing
, row_major
, block_name
);
1143 mtx_lock(&glsl_type::hash_mutex
);
1145 if (interface_types
== NULL
) {
1146 interface_types
= _mesa_hash_table_create(NULL
, record_key_hash
,
1147 record_key_compare
);
1150 const struct hash_entry
*entry
= _mesa_hash_table_search(interface_types
,
1152 if (entry
== NULL
) {
1153 const glsl_type
*t
= new glsl_type(fields
, num_fields
,
1154 packing
, row_major
, block_name
);
1156 entry
= _mesa_hash_table_insert(interface_types
, t
, (void *) t
);
1159 assert(((glsl_type
*) entry
->data
)->base_type
== GLSL_TYPE_INTERFACE
);
1160 assert(((glsl_type
*) entry
->data
)->length
== num_fields
);
1161 assert(strcmp(((glsl_type
*) entry
->data
)->name
, block_name
) == 0);
1163 mtx_unlock(&glsl_type::hash_mutex
);
1165 return (glsl_type
*) entry
->data
;
1169 glsl_type::get_subroutine_instance(const char *subroutine_name
)
1171 const glsl_type
key(subroutine_name
);
1173 mtx_lock(&glsl_type::hash_mutex
);
1175 if (subroutine_types
== NULL
) {
1176 subroutine_types
= _mesa_hash_table_create(NULL
, record_key_hash
,
1177 record_key_compare
);
1180 const struct hash_entry
*entry
= _mesa_hash_table_search(subroutine_types
,
1182 if (entry
== NULL
) {
1183 const glsl_type
*t
= new glsl_type(subroutine_name
);
1185 entry
= _mesa_hash_table_insert(subroutine_types
, t
, (void *) t
);
1188 assert(((glsl_type
*) entry
->data
)->base_type
== GLSL_TYPE_SUBROUTINE
);
1189 assert(strcmp(((glsl_type
*) entry
->data
)->name
, subroutine_name
) == 0);
1191 mtx_unlock(&glsl_type::hash_mutex
);
1193 return (glsl_type
*) entry
->data
;
1198 function_key_compare(const void *a
, const void *b
)
1200 const glsl_type
*const key1
= (glsl_type
*) a
;
1201 const glsl_type
*const key2
= (glsl_type
*) b
;
1203 if (key1
->length
!= key2
->length
)
1206 return memcmp(key1
->fields
.parameters
, key2
->fields
.parameters
,
1207 (key1
->length
+ 1) * sizeof(*key1
->fields
.parameters
)) == 0;
1212 function_key_hash(const void *a
)
1214 const glsl_type
*const key
= (glsl_type
*) a
;
1215 return _mesa_hash_data(key
->fields
.parameters
,
1216 (key
->length
+ 1) * sizeof(*key
->fields
.parameters
));
1220 glsl_type::get_function_instance(const glsl_type
*return_type
,
1221 const glsl_function_param
*params
,
1222 unsigned num_params
)
1224 const glsl_type
key(return_type
, params
, num_params
);
1226 mtx_lock(&glsl_type::hash_mutex
);
1228 if (function_types
== NULL
) {
1229 function_types
= _mesa_hash_table_create(NULL
, function_key_hash
,
1230 function_key_compare
);
1233 struct hash_entry
*entry
= _mesa_hash_table_search(function_types
, &key
);
1234 if (entry
== NULL
) {
1235 const glsl_type
*t
= new glsl_type(return_type
, params
, num_params
);
1237 entry
= _mesa_hash_table_insert(function_types
, t
, (void *) t
);
1240 const glsl_type
*t
= (const glsl_type
*)entry
->data
;
1242 assert(t
->base_type
== GLSL_TYPE_FUNCTION
);
1243 assert(t
->length
== num_params
);
1245 mtx_unlock(&glsl_type::hash_mutex
);
1252 glsl_type::get_mul_type(const glsl_type
*type_a
, const glsl_type
*type_b
)
1254 if (type_a
== type_b
) {
1256 } else if (type_a
->is_matrix() && type_b
->is_matrix()) {
1257 /* Matrix multiply. The columns of A must match the rows of B. Given
1258 * the other previously tested constraints, this means the vector type
1259 * of a row from A must be the same as the vector type of a column from
1262 if (type_a
->row_type() == type_b
->column_type()) {
1263 /* The resulting matrix has the number of columns of matrix B and
1264 * the number of rows of matrix A. We get the row count of A by
1265 * looking at the size of a vector that makes up a column. The
1266 * transpose (size of a row) is done for B.
1268 const glsl_type
*const type
=
1269 get_instance(type_a
->base_type
,
1270 type_a
->column_type()->vector_elements
,
1271 type_b
->row_type()->vector_elements
);
1272 assert(type
!= error_type
);
1276 } else if (type_a
->is_matrix()) {
1277 /* A is a matrix and B is a column vector. Columns of A must match
1278 * rows of B. Given the other previously tested constraints, this
1279 * means the vector type of a row from A must be the same as the
1280 * vector the type of B.
1282 if (type_a
->row_type() == type_b
) {
1283 /* The resulting vector has a number of elements equal to
1284 * the number of rows of matrix A. */
1285 const glsl_type
*const type
=
1286 get_instance(type_a
->base_type
,
1287 type_a
->column_type()->vector_elements
,
1289 assert(type
!= error_type
);
1294 assert(type_b
->is_matrix());
1296 /* A is a row vector and B is a matrix. Columns of A must match rows
1297 * of B. Given the other previously tested constraints, this means
1298 * the type of A must be the same as the vector type of a column from
1301 if (type_a
== type_b
->column_type()) {
1302 /* The resulting vector has a number of elements equal to
1303 * the number of columns of matrix B. */
1304 const glsl_type
*const type
=
1305 get_instance(type_a
->base_type
,
1306 type_b
->row_type()->vector_elements
,
1308 assert(type
!= error_type
);
1319 glsl_type::field_type(const char *name
) const
1321 if (this->base_type
!= GLSL_TYPE_STRUCT
1322 && this->base_type
!= GLSL_TYPE_INTERFACE
)
1325 for (unsigned i
= 0; i
< this->length
; i
++) {
1326 if (strcmp(name
, this->fields
.structure
[i
].name
) == 0)
1327 return this->fields
.structure
[i
].type
;
1335 glsl_type::field_index(const char *name
) const
1337 if (this->base_type
!= GLSL_TYPE_STRUCT
1338 && this->base_type
!= GLSL_TYPE_INTERFACE
)
1341 for (unsigned i
= 0; i
< this->length
; i
++) {
1342 if (strcmp(name
, this->fields
.structure
[i
].name
) == 0)
1351 glsl_type::component_slots() const
1353 switch (this->base_type
) {
1354 case GLSL_TYPE_UINT
:
1356 case GLSL_TYPE_UINT16
:
1357 case GLSL_TYPE_INT16
:
1358 case GLSL_TYPE_FLOAT
:
1359 case GLSL_TYPE_FLOAT16
:
1360 case GLSL_TYPE_BOOL
:
1361 return this->components();
1363 case GLSL_TYPE_DOUBLE
:
1364 case GLSL_TYPE_UINT64
:
1365 case GLSL_TYPE_INT64
:
1366 return 2 * this->components();
1368 case GLSL_TYPE_STRUCT
:
1369 case GLSL_TYPE_INTERFACE
: {
1372 for (unsigned i
= 0; i
< this->length
; i
++)
1373 size
+= this->fields
.structure
[i
].type
->component_slots();
1378 case GLSL_TYPE_ARRAY
:
1379 return this->length
* this->fields
.array
->component_slots();
1381 case GLSL_TYPE_SAMPLER
:
1382 case GLSL_TYPE_IMAGE
:
1385 case GLSL_TYPE_SUBROUTINE
:
1388 case GLSL_TYPE_FUNCTION
:
1389 case GLSL_TYPE_ATOMIC_UINT
:
1390 case GLSL_TYPE_VOID
:
1391 case GLSL_TYPE_ERROR
:
1399 glsl_type::record_location_offset(unsigned length
) const
1401 unsigned offset
= 0;
1402 const glsl_type
*t
= this->without_array();
1403 if (t
->is_record()) {
1404 assert(length
<= t
->length
);
1406 for (unsigned i
= 0; i
< length
; i
++) {
1407 const glsl_type
*st
= t
->fields
.structure
[i
].type
;
1408 const glsl_type
*wa
= st
->without_array();
1409 if (wa
->is_record()) {
1410 unsigned r_offset
= wa
->record_location_offset(wa
->length
);
1411 offset
+= st
->is_array() ?
1412 st
->arrays_of_arrays_size() * r_offset
: r_offset
;
1413 } else if (st
->is_array() && st
->fields
.array
->is_array()) {
1414 unsigned outer_array_size
= st
->length
;
1415 const glsl_type
*base_type
= st
->fields
.array
;
1417 /* For arrays of arrays the outer arrays take up a uniform
1418 * slot for each element. The innermost array elements share a
1419 * single slot so we ignore the innermost array when calculating
1422 while (base_type
->fields
.array
->is_array()) {
1423 outer_array_size
= outer_array_size
* base_type
->length
;
1424 base_type
= base_type
->fields
.array
;
1426 offset
+= outer_array_size
;
1428 /* We dont worry about arrays here because unless the array
1429 * contains a structure or another array it only takes up a single
1440 glsl_type::uniform_locations() const
1444 switch (this->base_type
) {
1445 case GLSL_TYPE_UINT
:
1447 case GLSL_TYPE_FLOAT
:
1448 case GLSL_TYPE_FLOAT16
:
1449 case GLSL_TYPE_DOUBLE
:
1450 case GLSL_TYPE_UINT16
:
1451 case GLSL_TYPE_INT16
:
1452 case GLSL_TYPE_UINT64
:
1453 case GLSL_TYPE_INT64
:
1454 case GLSL_TYPE_BOOL
:
1455 case GLSL_TYPE_SAMPLER
:
1456 case GLSL_TYPE_IMAGE
:
1457 case GLSL_TYPE_SUBROUTINE
:
1460 case GLSL_TYPE_STRUCT
:
1461 case GLSL_TYPE_INTERFACE
:
1462 for (unsigned i
= 0; i
< this->length
; i
++)
1463 size
+= this->fields
.structure
[i
].type
->uniform_locations();
1465 case GLSL_TYPE_ARRAY
:
1466 return this->length
* this->fields
.array
->uniform_locations();
1473 glsl_type::varying_count() const
1477 switch (this->base_type
) {
1478 case GLSL_TYPE_UINT
:
1480 case GLSL_TYPE_FLOAT
:
1481 case GLSL_TYPE_FLOAT16
:
1482 case GLSL_TYPE_DOUBLE
:
1483 case GLSL_TYPE_BOOL
:
1484 case GLSL_TYPE_UINT16
:
1485 case GLSL_TYPE_INT16
:
1486 case GLSL_TYPE_UINT64
:
1487 case GLSL_TYPE_INT64
:
1490 case GLSL_TYPE_STRUCT
:
1491 case GLSL_TYPE_INTERFACE
:
1492 for (unsigned i
= 0; i
< this->length
; i
++)
1493 size
+= this->fields
.structure
[i
].type
->varying_count();
1495 case GLSL_TYPE_ARRAY
:
1496 /* Don't count innermost array elements */
1497 if (this->without_array()->is_record() ||
1498 this->without_array()->is_interface() ||
1499 this->fields
.array
->is_array())
1500 return this->length
* this->fields
.array
->varying_count();
1502 return this->fields
.array
->varying_count();
1504 assert(!"unsupported varying type");
1510 glsl_type::can_implicitly_convert_to(const glsl_type
*desired
,
1511 _mesa_glsl_parse_state
*state
) const
1513 if (this == desired
)
1516 /* GLSL 1.10 and ESSL do not allow implicit conversions. If there is no
1517 * state, we're doing intra-stage function linking where these checks have
1518 * already been done.
1520 if (state
&& (state
->es_shader
|| !state
->is_version(120, 0)))
1523 /* There is no conversion among matrix types. */
1524 if (this->matrix_columns
> 1 || desired
->matrix_columns
> 1)
1527 /* Vector size must match. */
1528 if (this->vector_elements
!= desired
->vector_elements
)
1531 /* int and uint can be converted to float. */
1532 if (desired
->is_float() && this->is_integer())
1535 /* With GLSL 4.0, ARB_gpu_shader5, or MESA_shader_integer_functions, int
1536 * can be converted to uint. Note that state may be NULL here, when
1537 * resolving function calls in the linker. By this time, all the
1538 * state-dependent checks have already happened though, so allow anything
1539 * that's allowed in any shader version.
1541 if ((!state
|| state
->is_version(400, 0) || state
->ARB_gpu_shader5_enable
||
1542 state
->MESA_shader_integer_functions_enable
) &&
1543 desired
->base_type
== GLSL_TYPE_UINT
&& this->base_type
== GLSL_TYPE_INT
)
1546 /* No implicit conversions from double. */
1547 if ((!state
|| state
->has_double()) && this->is_double())
1550 /* Conversions from different types to double. */
1551 if ((!state
|| state
->has_double()) && desired
->is_double()) {
1552 if (this->is_float())
1554 if (this->is_integer())
1562 glsl_type::std140_base_alignment(bool row_major
) const
1564 unsigned N
= is_64bit() ? 8 : 4;
1566 /* (1) If the member is a scalar consuming <N> basic machine units, the
1567 * base alignment is <N>.
1569 * (2) If the member is a two- or four-component vector with components
1570 * consuming <N> basic machine units, the base alignment is 2<N> or
1571 * 4<N>, respectively.
1573 * (3) If the member is a three-component vector with components consuming
1574 * <N> basic machine units, the base alignment is 4<N>.
1576 if (this->is_scalar() || this->is_vector()) {
1577 switch (this->vector_elements
) {
1588 /* (4) If the member is an array of scalars or vectors, the base alignment
1589 * and array stride are set to match the base alignment of a single
1590 * array element, according to rules (1), (2), and (3), and rounded up
1591 * to the base alignment of a vec4. The array may have padding at the
1592 * end; the base offset of the member following the array is rounded up
1593 * to the next multiple of the base alignment.
1595 * (6) If the member is an array of <S> column-major matrices with <C>
1596 * columns and <R> rows, the matrix is stored identically to a row of
1597 * <S>*<C> column vectors with <R> components each, according to rule
1600 * (8) If the member is an array of <S> row-major matrices with <C> columns
1601 * and <R> rows, the matrix is stored identically to a row of <S>*<R>
1602 * row vectors with <C> components each, according to rule (4).
1604 * (10) If the member is an array of <S> structures, the <S> elements of
1605 * the array are laid out in order, according to rule (9).
1607 if (this->is_array()) {
1608 if (this->fields
.array
->is_scalar() ||
1609 this->fields
.array
->is_vector() ||
1610 this->fields
.array
->is_matrix()) {
1611 return MAX2(this->fields
.array
->std140_base_alignment(row_major
), 16);
1613 assert(this->fields
.array
->is_record() ||
1614 this->fields
.array
->is_array());
1615 return this->fields
.array
->std140_base_alignment(row_major
);
1619 /* (5) If the member is a column-major matrix with <C> columns and
1620 * <R> rows, the matrix is stored identically to an array of
1621 * <C> column vectors with <R> components each, according to
1624 * (7) If the member is a row-major matrix with <C> columns and <R>
1625 * rows, the matrix is stored identically to an array of <R>
1626 * row vectors with <C> components each, according to rule (4).
1628 if (this->is_matrix()) {
1629 const struct glsl_type
*vec_type
, *array_type
;
1630 int c
= this->matrix_columns
;
1631 int r
= this->vector_elements
;
1634 vec_type
= get_instance(base_type
, c
, 1);
1635 array_type
= glsl_type::get_array_instance(vec_type
, r
);
1637 vec_type
= get_instance(base_type
, r
, 1);
1638 array_type
= glsl_type::get_array_instance(vec_type
, c
);
1641 return array_type
->std140_base_alignment(false);
1644 /* (9) If the member is a structure, the base alignment of the
1645 * structure is <N>, where <N> is the largest base alignment
1646 * value of any of its members, and rounded up to the base
1647 * alignment of a vec4. The individual members of this
1648 * sub-structure are then assigned offsets by applying this set
1649 * of rules recursively, where the base offset of the first
1650 * member of the sub-structure is equal to the aligned offset
1651 * of the structure. The structure may have padding at the end;
1652 * the base offset of the member following the sub-structure is
1653 * rounded up to the next multiple of the base alignment of the
1656 if (this->is_record()) {
1657 unsigned base_alignment
= 16;
1658 for (unsigned i
= 0; i
< this->length
; i
++) {
1659 bool field_row_major
= row_major
;
1660 const enum glsl_matrix_layout matrix_layout
=
1661 glsl_matrix_layout(this->fields
.structure
[i
].matrix_layout
);
1662 if (matrix_layout
== GLSL_MATRIX_LAYOUT_ROW_MAJOR
) {
1663 field_row_major
= true;
1664 } else if (matrix_layout
== GLSL_MATRIX_LAYOUT_COLUMN_MAJOR
) {
1665 field_row_major
= false;
1668 const struct glsl_type
*field_type
= this->fields
.structure
[i
].type
;
1669 base_alignment
= MAX2(base_alignment
,
1670 field_type
->std140_base_alignment(field_row_major
));
1672 return base_alignment
;
1675 assert(!"not reached");
1680 glsl_type::std140_size(bool row_major
) const
1682 unsigned N
= is_64bit() ? 8 : 4;
1684 /* (1) If the member is a scalar consuming <N> basic machine units, the
1685 * base alignment is <N>.
1687 * (2) If the member is a two- or four-component vector with components
1688 * consuming <N> basic machine units, the base alignment is 2<N> or
1689 * 4<N>, respectively.
1691 * (3) If the member is a three-component vector with components consuming
1692 * <N> basic machine units, the base alignment is 4<N>.
1694 if (this->is_scalar() || this->is_vector()) {
1695 return this->vector_elements
* N
;
1698 /* (5) If the member is a column-major matrix with <C> columns and
1699 * <R> rows, the matrix is stored identically to an array of
1700 * <C> column vectors with <R> components each, according to
1703 * (6) If the member is an array of <S> column-major matrices with <C>
1704 * columns and <R> rows, the matrix is stored identically to a row of
1705 * <S>*<C> column vectors with <R> components each, according to rule
1708 * (7) If the member is a row-major matrix with <C> columns and <R>
1709 * rows, the matrix is stored identically to an array of <R>
1710 * row vectors with <C> components each, according to rule (4).
1712 * (8) If the member is an array of <S> row-major matrices with <C> columns
1713 * and <R> rows, the matrix is stored identically to a row of <S>*<R>
1714 * row vectors with <C> components each, according to rule (4).
1716 if (this->without_array()->is_matrix()) {
1717 const struct glsl_type
*element_type
;
1718 const struct glsl_type
*vec_type
;
1719 unsigned int array_len
;
1721 if (this->is_array()) {
1722 element_type
= this->without_array();
1723 array_len
= this->arrays_of_arrays_size();
1725 element_type
= this;
1730 vec_type
= get_instance(element_type
->base_type
,
1731 element_type
->matrix_columns
, 1);
1733 array_len
*= element_type
->vector_elements
;
1735 vec_type
= get_instance(element_type
->base_type
,
1736 element_type
->vector_elements
, 1);
1737 array_len
*= element_type
->matrix_columns
;
1739 const glsl_type
*array_type
= glsl_type::get_array_instance(vec_type
,
1742 return array_type
->std140_size(false);
1745 /* (4) If the member is an array of scalars or vectors, the base alignment
1746 * and array stride are set to match the base alignment of a single
1747 * array element, according to rules (1), (2), and (3), and rounded up
1748 * to the base alignment of a vec4. The array may have padding at the
1749 * end; the base offset of the member following the array is rounded up
1750 * to the next multiple of the base alignment.
1752 * (10) If the member is an array of <S> structures, the <S> elements of
1753 * the array are laid out in order, according to rule (9).
1755 if (this->is_array()) {
1756 if (this->without_array()->is_record()) {
1757 return this->arrays_of_arrays_size() *
1758 this->without_array()->std140_size(row_major
);
1760 unsigned element_base_align
=
1761 this->without_array()->std140_base_alignment(row_major
);
1762 return this->arrays_of_arrays_size() * MAX2(element_base_align
, 16);
1766 /* (9) If the member is a structure, the base alignment of the
1767 * structure is <N>, where <N> is the largest base alignment
1768 * value of any of its members, and rounded up to the base
1769 * alignment of a vec4. The individual members of this
1770 * sub-structure are then assigned offsets by applying this set
1771 * of rules recursively, where the base offset of the first
1772 * member of the sub-structure is equal to the aligned offset
1773 * of the structure. The structure may have padding at the end;
1774 * the base offset of the member following the sub-structure is
1775 * rounded up to the next multiple of the base alignment of the
1778 if (this->is_record() || this->is_interface()) {
1780 unsigned max_align
= 0;
1782 for (unsigned i
= 0; i
< this->length
; i
++) {
1783 bool field_row_major
= row_major
;
1784 const enum glsl_matrix_layout matrix_layout
=
1785 glsl_matrix_layout(this->fields
.structure
[i
].matrix_layout
);
1786 if (matrix_layout
== GLSL_MATRIX_LAYOUT_ROW_MAJOR
) {
1787 field_row_major
= true;
1788 } else if (matrix_layout
== GLSL_MATRIX_LAYOUT_COLUMN_MAJOR
) {
1789 field_row_major
= false;
1792 const struct glsl_type
*field_type
= this->fields
.structure
[i
].type
;
1793 unsigned align
= field_type
->std140_base_alignment(field_row_major
);
1795 /* Ignore unsized arrays when calculating size */
1796 if (field_type
->is_unsized_array())
1799 size
= glsl_align(size
, align
);
1800 size
+= field_type
->std140_size(field_row_major
);
1802 max_align
= MAX2(align
, max_align
);
1804 if (field_type
->is_record() && (i
+ 1 < this->length
))
1805 size
= glsl_align(size
, 16);
1807 size
= glsl_align(size
, MAX2(max_align
, 16));
1811 assert(!"not reached");
1816 glsl_type::std430_base_alignment(bool row_major
) const
1819 unsigned N
= is_64bit() ? 8 : 4;
1821 /* (1) If the member is a scalar consuming <N> basic machine units, the
1822 * base alignment is <N>.
1824 * (2) If the member is a two- or four-component vector with components
1825 * consuming <N> basic machine units, the base alignment is 2<N> or
1826 * 4<N>, respectively.
1828 * (3) If the member is a three-component vector with components consuming
1829 * <N> basic machine units, the base alignment is 4<N>.
1831 if (this->is_scalar() || this->is_vector()) {
1832 switch (this->vector_elements
) {
1843 /* OpenGL 4.30 spec, section 7.6.2.2 "Standard Uniform Block Layout":
1845 * "When using the std430 storage layout, shader storage blocks will be
1846 * laid out in buffer storage identically to uniform and shader storage
1847 * blocks using the std140 layout, except that the base alignment and
1848 * stride of arrays of scalars and vectors in rule 4 and of structures
1849 * in rule 9 are not rounded up a multiple of the base alignment of a vec4.
1852 /* (1) If the member is a scalar consuming <N> basic machine units, the
1853 * base alignment is <N>.
1855 * (2) If the member is a two- or four-component vector with components
1856 * consuming <N> basic machine units, the base alignment is 2<N> or
1857 * 4<N>, respectively.
1859 * (3) If the member is a three-component vector with components consuming
1860 * <N> basic machine units, the base alignment is 4<N>.
1862 if (this->is_array())
1863 return this->fields
.array
->std430_base_alignment(row_major
);
1865 /* (5) If the member is a column-major matrix with <C> columns and
1866 * <R> rows, the matrix is stored identically to an array of
1867 * <C> column vectors with <R> components each, according to
1870 * (7) If the member is a row-major matrix with <C> columns and <R>
1871 * rows, the matrix is stored identically to an array of <R>
1872 * row vectors with <C> components each, according to rule (4).
1874 if (this->is_matrix()) {
1875 const struct glsl_type
*vec_type
, *array_type
;
1876 int c
= this->matrix_columns
;
1877 int r
= this->vector_elements
;
1880 vec_type
= get_instance(base_type
, c
, 1);
1881 array_type
= glsl_type::get_array_instance(vec_type
, r
);
1883 vec_type
= get_instance(base_type
, r
, 1);
1884 array_type
= glsl_type::get_array_instance(vec_type
, c
);
1887 return array_type
->std430_base_alignment(false);
1890 /* (9) If the member is a structure, the base alignment of the
1891 * structure is <N>, where <N> is the largest base alignment
1892 * value of any of its members, and rounded up to the base
1893 * alignment of a vec4. The individual members of this
1894 * sub-structure are then assigned offsets by applying this set
1895 * of rules recursively, where the base offset of the first
1896 * member of the sub-structure is equal to the aligned offset
1897 * of the structure. The structure may have padding at the end;
1898 * the base offset of the member following the sub-structure is
1899 * rounded up to the next multiple of the base alignment of the
1902 if (this->is_record()) {
1903 unsigned base_alignment
= 0;
1904 for (unsigned i
= 0; i
< this->length
; i
++) {
1905 bool field_row_major
= row_major
;
1906 const enum glsl_matrix_layout matrix_layout
=
1907 glsl_matrix_layout(this->fields
.structure
[i
].matrix_layout
);
1908 if (matrix_layout
== GLSL_MATRIX_LAYOUT_ROW_MAJOR
) {
1909 field_row_major
= true;
1910 } else if (matrix_layout
== GLSL_MATRIX_LAYOUT_COLUMN_MAJOR
) {
1911 field_row_major
= false;
1914 const struct glsl_type
*field_type
= this->fields
.structure
[i
].type
;
1915 base_alignment
= MAX2(base_alignment
,
1916 field_type
->std430_base_alignment(field_row_major
));
1918 assert(base_alignment
> 0);
1919 return base_alignment
;
1921 assert(!"not reached");
1926 glsl_type::std430_array_stride(bool row_major
) const
1928 unsigned N
= is_64bit() ? 8 : 4;
1930 /* Notice that the array stride of a vec3 is not 3 * N but 4 * N.
1931 * See OpenGL 4.30 spec, section 7.6.2.2 "Standard Uniform Block Layout"
1933 * (3) If the member is a three-component vector with components consuming
1934 * <N> basic machine units, the base alignment is 4<N>.
1936 if (this->is_vector() && this->vector_elements
== 3)
1939 /* By default use std430_size(row_major) */
1940 return this->std430_size(row_major
);
1944 glsl_type::std430_size(bool row_major
) const
1946 unsigned N
= is_64bit() ? 8 : 4;
1948 /* OpenGL 4.30 spec, section 7.6.2.2 "Standard Uniform Block Layout":
1950 * "When using the std430 storage layout, shader storage blocks will be
1951 * laid out in buffer storage identically to uniform and shader storage
1952 * blocks using the std140 layout, except that the base alignment and
1953 * stride of arrays of scalars and vectors in rule 4 and of structures
1954 * in rule 9 are not rounded up a multiple of the base alignment of a vec4.
1956 if (this->is_scalar() || this->is_vector())
1957 return this->vector_elements
* N
;
1959 if (this->without_array()->is_matrix()) {
1960 const struct glsl_type
*element_type
;
1961 const struct glsl_type
*vec_type
;
1962 unsigned int array_len
;
1964 if (this->is_array()) {
1965 element_type
= this->without_array();
1966 array_len
= this->arrays_of_arrays_size();
1968 element_type
= this;
1973 vec_type
= get_instance(element_type
->base_type
,
1974 element_type
->matrix_columns
, 1);
1976 array_len
*= element_type
->vector_elements
;
1978 vec_type
= get_instance(element_type
->base_type
,
1979 element_type
->vector_elements
, 1);
1980 array_len
*= element_type
->matrix_columns
;
1982 const glsl_type
*array_type
= glsl_type::get_array_instance(vec_type
,
1985 return array_type
->std430_size(false);
1988 if (this->is_array()) {
1989 if (this->without_array()->is_record())
1990 return this->arrays_of_arrays_size() *
1991 this->without_array()->std430_size(row_major
);
1993 return this->arrays_of_arrays_size() *
1994 this->without_array()->std430_base_alignment(row_major
);
1997 if (this->is_record() || this->is_interface()) {
1999 unsigned max_align
= 0;
2001 for (unsigned i
= 0; i
< this->length
; i
++) {
2002 bool field_row_major
= row_major
;
2003 const enum glsl_matrix_layout matrix_layout
=
2004 glsl_matrix_layout(this->fields
.structure
[i
].matrix_layout
);
2005 if (matrix_layout
== GLSL_MATRIX_LAYOUT_ROW_MAJOR
) {
2006 field_row_major
= true;
2007 } else if (matrix_layout
== GLSL_MATRIX_LAYOUT_COLUMN_MAJOR
) {
2008 field_row_major
= false;
2011 const struct glsl_type
*field_type
= this->fields
.structure
[i
].type
;
2012 unsigned align
= field_type
->std430_base_alignment(field_row_major
);
2013 size
= glsl_align(size
, align
);
2014 size
+= field_type
->std430_size(field_row_major
);
2016 max_align
= MAX2(align
, max_align
);
2018 size
= glsl_align(size
, max_align
);
2022 assert(!"not reached");
2027 glsl_type::count_attribute_slots(bool is_vertex_input
) const
2029 /* From page 31 (page 37 of the PDF) of the GLSL 1.50 spec:
2031 * "A scalar input counts the same amount against this limit as a vec4,
2032 * so applications may want to consider packing groups of four
2033 * unrelated float inputs together into a vector to better utilize the
2034 * capabilities of the underlying hardware. A matrix input will use up
2035 * multiple locations. The number of locations used will equal the
2036 * number of columns in the matrix."
2038 * The spec does not explicitly say how arrays are counted. However, it
2039 * should be safe to assume the total number of slots consumed by an array
2040 * is the number of entries in the array multiplied by the number of slots
2041 * consumed by a single element of the array.
2043 * The spec says nothing about how structs are counted, because vertex
2044 * attributes are not allowed to be (or contain) structs. However, Mesa
2045 * allows varying structs, the number of varying slots taken up by a
2046 * varying struct is simply equal to the sum of the number of slots taken
2047 * up by each element.
2049 * Doubles are counted different depending on whether they are vertex
2050 * inputs or everything else. Vertex inputs from ARB_vertex_attrib_64bit
2051 * take one location no matter what size they are, otherwise dvec3/4
2052 * take two locations.
2054 switch (this->base_type
) {
2055 case GLSL_TYPE_UINT
:
2057 case GLSL_TYPE_UINT16
:
2058 case GLSL_TYPE_INT16
:
2059 case GLSL_TYPE_FLOAT
:
2060 case GLSL_TYPE_FLOAT16
:
2061 case GLSL_TYPE_BOOL
:
2062 case GLSL_TYPE_SAMPLER
:
2063 case GLSL_TYPE_IMAGE
:
2064 return this->matrix_columns
;
2065 case GLSL_TYPE_DOUBLE
:
2066 case GLSL_TYPE_UINT64
:
2067 case GLSL_TYPE_INT64
:
2068 if (this->vector_elements
> 2 && !is_vertex_input
)
2069 return this->matrix_columns
* 2;
2071 return this->matrix_columns
;
2072 case GLSL_TYPE_STRUCT
:
2073 case GLSL_TYPE_INTERFACE
: {
2076 for (unsigned i
= 0; i
< this->length
; i
++)
2077 size
+= this->fields
.structure
[i
].type
->count_attribute_slots(is_vertex_input
);
2082 case GLSL_TYPE_ARRAY
:
2083 return this->length
* this->fields
.array
->count_attribute_slots(is_vertex_input
);
2085 case GLSL_TYPE_SUBROUTINE
:
2088 case GLSL_TYPE_FUNCTION
:
2089 case GLSL_TYPE_ATOMIC_UINT
:
2090 case GLSL_TYPE_VOID
:
2091 case GLSL_TYPE_ERROR
:
2095 assert(!"Unexpected type in count_attribute_slots()");
2101 glsl_type::coordinate_components() const
2105 switch (sampler_dimensionality
) {
2106 case GLSL_SAMPLER_DIM_1D
:
2107 case GLSL_SAMPLER_DIM_BUF
:
2110 case GLSL_SAMPLER_DIM_2D
:
2111 case GLSL_SAMPLER_DIM_RECT
:
2112 case GLSL_SAMPLER_DIM_MS
:
2113 case GLSL_SAMPLER_DIM_EXTERNAL
:
2114 case GLSL_SAMPLER_DIM_SUBPASS
:
2117 case GLSL_SAMPLER_DIM_3D
:
2118 case GLSL_SAMPLER_DIM_CUBE
:
2122 assert(!"Should not get here.");
2127 /* Array textures need an additional component for the array index, except
2128 * for cubemap array images that behave like a 2D array of interleaved
2131 if (sampler_array
&&
2132 !(is_image() && sampler_dimensionality
== GLSL_SAMPLER_DIM_CUBE
))
2139 * Declarations of type flyweights (glsl_type::_foo_type) and
2140 * convenience pointers (glsl_type::foo_type).
2143 #define DECL_TYPE(NAME, ...) \
2144 const glsl_type glsl_type::_##NAME##_type = glsl_type(__VA_ARGS__, #NAME); \
2145 const glsl_type *const glsl_type::NAME##_type = &glsl_type::_##NAME##_type;
2147 #define STRUCT_TYPE(NAME)
2149 #include "compiler/builtin_type_macros.h"
2153 get_struct_type_field_and_pointer_sizes(size_t *s_field_size
,
2154 size_t *s_field_ptrs
)
2156 *s_field_size
= sizeof(glsl_struct_field
);
2158 sizeof(((glsl_struct_field
*)0)->type
) +
2159 sizeof(((glsl_struct_field
*)0)->name
);
2163 encode_type_to_blob(struct blob
*blob
, const glsl_type
*type
)
2168 blob_write_uint32(blob
, 0);
2172 switch (type
->base_type
) {
2173 case GLSL_TYPE_UINT
:
2175 case GLSL_TYPE_FLOAT
:
2176 case GLSL_TYPE_BOOL
:
2177 case GLSL_TYPE_DOUBLE
:
2178 case GLSL_TYPE_UINT64
:
2179 case GLSL_TYPE_INT64
:
2180 encoding
= (type
->base_type
<< 24) |
2181 (type
->vector_elements
<< 4) |
2182 (type
->matrix_columns
);
2184 case GLSL_TYPE_SAMPLER
:
2185 encoding
= (type
->base_type
) << 24 |
2186 (type
->sampler_dimensionality
<< 4) |
2187 (type
->sampler_shadow
<< 3) |
2188 (type
->sampler_array
<< 2) |
2189 (type
->sampled_type
);
2191 case GLSL_TYPE_SUBROUTINE
:
2192 encoding
= type
->base_type
<< 24;
2193 blob_write_uint32(blob
, encoding
);
2194 blob_write_string(blob
, type
->name
);
2196 case GLSL_TYPE_IMAGE
:
2197 encoding
= (type
->base_type
) << 24 |
2198 (type
->sampler_dimensionality
<< 3) |
2199 (type
->sampler_array
<< 2) |
2200 (type
->sampled_type
);
2202 case GLSL_TYPE_ATOMIC_UINT
:
2203 encoding
= (type
->base_type
<< 24);
2205 case GLSL_TYPE_ARRAY
:
2206 blob_write_uint32(blob
, (type
->base_type
) << 24);
2207 blob_write_uint32(blob
, type
->length
);
2208 encode_type_to_blob(blob
, type
->fields
.array
);
2210 case GLSL_TYPE_STRUCT
:
2211 case GLSL_TYPE_INTERFACE
:
2212 blob_write_uint32(blob
, (type
->base_type
) << 24);
2213 blob_write_string(blob
, type
->name
);
2214 blob_write_uint32(blob
, type
->length
);
2216 size_t s_field_size
, s_field_ptrs
;
2217 get_struct_type_field_and_pointer_sizes(&s_field_size
, &s_field_ptrs
);
2219 for (unsigned i
= 0; i
< type
->length
; i
++) {
2220 encode_type_to_blob(blob
, type
->fields
.structure
[i
].type
);
2221 blob_write_string(blob
, type
->fields
.structure
[i
].name
);
2223 /* Write the struct field skipping the pointers */
2224 blob_write_bytes(blob
,
2225 ((char *)&type
->fields
.structure
[i
]) + s_field_ptrs
,
2226 s_field_size
- s_field_ptrs
);
2229 if (type
->is_interface()) {
2230 blob_write_uint32(blob
, type
->interface_packing
);
2231 blob_write_uint32(blob
, type
->interface_row_major
);
2234 case GLSL_TYPE_VOID
:
2235 encoding
= (type
->base_type
<< 24);
2237 case GLSL_TYPE_ERROR
:
2239 assert(!"Cannot encode type!");
2244 blob_write_uint32(blob
, encoding
);
2248 decode_type_from_blob(struct blob_reader
*blob
)
2250 uint32_t u
= blob_read_uint32(blob
);
2256 glsl_base_type base_type
= (glsl_base_type
) (u
>> 24);
2258 switch (base_type
) {
2259 case GLSL_TYPE_UINT
:
2261 case GLSL_TYPE_FLOAT
:
2262 case GLSL_TYPE_BOOL
:
2263 case GLSL_TYPE_DOUBLE
:
2264 case GLSL_TYPE_UINT64
:
2265 case GLSL_TYPE_INT64
:
2266 return glsl_type::get_instance(base_type
, (u
>> 4) & 0x0f, u
& 0x0f);
2267 case GLSL_TYPE_SAMPLER
:
2268 return glsl_type::get_sampler_instance((enum glsl_sampler_dim
) ((u
>> 4) & 0x07),
2271 (glsl_base_type
) ((u
>> 0) & 0x03));
2272 case GLSL_TYPE_SUBROUTINE
:
2273 return glsl_type::get_subroutine_instance(blob_read_string(blob
));
2274 case GLSL_TYPE_IMAGE
:
2275 return glsl_type::get_image_instance((enum glsl_sampler_dim
) ((u
>> 3) & 0x07),
2277 (glsl_base_type
) ((u
>> 0) & 0x03));
2278 case GLSL_TYPE_ATOMIC_UINT
:
2279 return glsl_type::atomic_uint_type
;
2280 case GLSL_TYPE_ARRAY
: {
2281 unsigned length
= blob_read_uint32(blob
);
2282 return glsl_type::get_array_instance(decode_type_from_blob(blob
),
2285 case GLSL_TYPE_STRUCT
:
2286 case GLSL_TYPE_INTERFACE
: {
2287 char *name
= blob_read_string(blob
);
2288 unsigned num_fields
= blob_read_uint32(blob
);
2290 size_t s_field_size
, s_field_ptrs
;
2291 get_struct_type_field_and_pointer_sizes(&s_field_size
, &s_field_ptrs
);
2293 glsl_struct_field
*fields
=
2294 (glsl_struct_field
*) malloc(s_field_size
* num_fields
);
2295 for (unsigned i
= 0; i
< num_fields
; i
++) {
2296 fields
[i
].type
= decode_type_from_blob(blob
);
2297 fields
[i
].name
= blob_read_string(blob
);
2299 blob_copy_bytes(blob
, ((uint8_t *) &fields
[i
]) + s_field_ptrs
,
2300 s_field_size
- s_field_ptrs
);
2304 if (base_type
== GLSL_TYPE_INTERFACE
) {
2305 enum glsl_interface_packing packing
=
2306 (glsl_interface_packing
) blob_read_uint32(blob
);
2307 bool row_major
= blob_read_uint32(blob
);
2308 t
= glsl_type::get_interface_instance(fields
, num_fields
, packing
,
2311 t
= glsl_type::get_record_instance(fields
, num_fields
, name
);
2317 case GLSL_TYPE_VOID
:
2318 return glsl_type::void_type
;
2319 case GLSL_TYPE_ERROR
:
2321 assert(!"Cannot decode type!");