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::mem_mutex
= _MTX_INITIALIZER_NP
;
32 mtx_t
glsl_type::hash_mutex
= _MTX_INITIALIZER_NP
;
33 hash_table
*glsl_type::array_types
= NULL
;
34 hash_table
*glsl_type::record_types
= NULL
;
35 hash_table
*glsl_type::interface_types
= NULL
;
36 hash_table
*glsl_type::function_types
= NULL
;
37 hash_table
*glsl_type::subroutine_types
= NULL
;
38 void *glsl_type::mem_ctx
= NULL
;
41 glsl_type::init_ralloc_type_ctx(void)
43 if (glsl_type::mem_ctx
== NULL
) {
44 glsl_type::mem_ctx
= ralloc_context(NULL
);
45 assert(glsl_type::mem_ctx
!= NULL
);
49 glsl_type::glsl_type(GLenum gl_type
,
50 glsl_base_type base_type
, unsigned vector_elements
,
51 unsigned matrix_columns
, const char *name
) :
53 base_type(base_type
), sampled_type(GLSL_TYPE_VOID
),
54 sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
55 interface_packing(0), interface_row_major(0),
56 vector_elements(vector_elements
), matrix_columns(matrix_columns
),
59 /* Values of these types must fit in the two bits of
60 * glsl_type::sampled_type.
62 STATIC_ASSERT((unsigned(GLSL_TYPE_UINT
) & 3) == unsigned(GLSL_TYPE_UINT
));
63 STATIC_ASSERT((unsigned(GLSL_TYPE_INT
) & 3) == unsigned(GLSL_TYPE_INT
));
64 STATIC_ASSERT((unsigned(GLSL_TYPE_FLOAT
) & 3) == unsigned(GLSL_TYPE_FLOAT
));
66 mtx_lock(&glsl_type::mem_mutex
);
68 init_ralloc_type_ctx();
70 this->name
= ralloc_strdup(this->mem_ctx
, name
);
72 mtx_unlock(&glsl_type::mem_mutex
);
74 /* Neither dimension is zero or both dimensions are zero.
76 assert((vector_elements
== 0) == (matrix_columns
== 0));
77 memset(& fields
, 0, sizeof(fields
));
80 glsl_type::glsl_type(GLenum gl_type
, glsl_base_type base_type
,
81 enum glsl_sampler_dim dim
, bool shadow
, bool array
,
82 glsl_base_type type
, const char *name
) :
84 base_type(base_type
), sampled_type(type
),
85 sampler_dimensionality(dim
), sampler_shadow(shadow
),
86 sampler_array(array
), interface_packing(0),
87 interface_row_major(0), length(0)
89 mtx_lock(&glsl_type::mem_mutex
);
91 init_ralloc_type_ctx();
93 this->name
= ralloc_strdup(this->mem_ctx
, name
);
95 mtx_unlock(&glsl_type::mem_mutex
);
97 memset(& fields
, 0, sizeof(fields
));
99 matrix_columns
= vector_elements
= 1;
102 glsl_type::glsl_type(const glsl_struct_field
*fields
, unsigned num_fields
,
105 base_type(GLSL_TYPE_STRUCT
), sampled_type(GLSL_TYPE_VOID
),
106 sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
107 interface_packing(0), interface_row_major(0),
108 vector_elements(0), matrix_columns(0),
113 mtx_lock(&glsl_type::mem_mutex
);
115 init_ralloc_type_ctx();
116 assert(name
!= NULL
);
117 this->name
= ralloc_strdup(this->mem_ctx
, name
);
118 this->fields
.structure
= ralloc_array(this->mem_ctx
,
119 glsl_struct_field
, length
);
121 for (i
= 0; i
< length
; i
++) {
122 this->fields
.structure
[i
] = fields
[i
];
123 this->fields
.structure
[i
].name
= ralloc_strdup(this->fields
.structure
,
127 mtx_unlock(&glsl_type::mem_mutex
);
130 glsl_type::glsl_type(const glsl_struct_field
*fields
, unsigned num_fields
,
131 enum glsl_interface_packing packing
,
132 bool row_major
, const char *name
) :
134 base_type(GLSL_TYPE_INTERFACE
), sampled_type(GLSL_TYPE_VOID
),
135 sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
136 interface_packing((unsigned) packing
),
137 interface_row_major((unsigned) row_major
),
138 vector_elements(0), matrix_columns(0),
143 mtx_lock(&glsl_type::mem_mutex
);
145 init_ralloc_type_ctx();
146 assert(name
!= NULL
);
147 this->name
= ralloc_strdup(this->mem_ctx
, name
);
148 this->fields
.structure
= rzalloc_array(this->mem_ctx
,
149 glsl_struct_field
, length
);
150 for (i
= 0; i
< length
; i
++) {
151 this->fields
.structure
[i
] = fields
[i
];
152 this->fields
.structure
[i
].name
= ralloc_strdup(this->fields
.structure
,
156 mtx_unlock(&glsl_type::mem_mutex
);
159 glsl_type::glsl_type(const glsl_type
*return_type
,
160 const glsl_function_param
*params
, unsigned num_params
) :
162 base_type(GLSL_TYPE_FUNCTION
), sampled_type(GLSL_TYPE_VOID
),
163 sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
164 interface_packing(0), interface_row_major(0),
165 vector_elements(0), matrix_columns(0),
170 mtx_lock(&glsl_type::mem_mutex
);
172 init_ralloc_type_ctx();
174 this->fields
.parameters
= rzalloc_array(this->mem_ctx
,
175 glsl_function_param
, num_params
+ 1);
177 /* We store the return type as the first parameter */
178 this->fields
.parameters
[0].type
= return_type
;
179 this->fields
.parameters
[0].in
= false;
180 this->fields
.parameters
[0].out
= true;
182 /* We store the i'th parameter in slot i+1 */
183 for (i
= 0; i
< length
; i
++) {
184 this->fields
.parameters
[i
+ 1].type
= params
[i
].type
;
185 this->fields
.parameters
[i
+ 1].in
= params
[i
].in
;
186 this->fields
.parameters
[i
+ 1].out
= params
[i
].out
;
189 mtx_unlock(&glsl_type::mem_mutex
);
192 glsl_type::glsl_type(const char *subroutine_name
) :
194 base_type(GLSL_TYPE_SUBROUTINE
), sampled_type(GLSL_TYPE_VOID
),
195 sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
196 interface_packing(0), interface_row_major(0),
197 vector_elements(1), matrix_columns(1),
200 mtx_lock(&glsl_type::mem_mutex
);
202 init_ralloc_type_ctx();
203 assert(subroutine_name
!= NULL
);
204 this->name
= ralloc_strdup(this->mem_ctx
, subroutine_name
);
205 mtx_unlock(&glsl_type::mem_mutex
);
209 glsl_type::contains_sampler() const
211 if (this->is_array()) {
212 return this->fields
.array
->contains_sampler();
213 } else if (this->is_record() || this->is_interface()) {
214 for (unsigned int i
= 0; i
< this->length
; i
++) {
215 if (this->fields
.structure
[i
].type
->contains_sampler())
220 return this->is_sampler();
225 glsl_type::contains_array() const
227 if (this->is_record() || this->is_interface()) {
228 for (unsigned int i
= 0; i
< this->length
; i
++) {
229 if (this->fields
.structure
[i
].type
->contains_array())
234 return this->is_array();
239 glsl_type::contains_integer() const
241 if (this->is_array()) {
242 return this->fields
.array
->contains_integer();
243 } else if (this->is_record() || this->is_interface()) {
244 for (unsigned int i
= 0; i
< this->length
; i
++) {
245 if (this->fields
.structure
[i
].type
->contains_integer())
250 return this->is_integer();
255 glsl_type::contains_double() const
257 if (this->is_array()) {
258 return this->fields
.array
->contains_double();
259 } else if (this->is_record() || this->is_interface()) {
260 for (unsigned int i
= 0; i
< this->length
; i
++) {
261 if (this->fields
.structure
[i
].type
->contains_double())
266 return this->is_double();
271 glsl_type::contains_opaque() const {
273 case GLSL_TYPE_SAMPLER
:
274 case GLSL_TYPE_IMAGE
:
275 case GLSL_TYPE_ATOMIC_UINT
:
277 case GLSL_TYPE_ARRAY
:
278 return fields
.array
->contains_opaque();
279 case GLSL_TYPE_STRUCT
:
280 case GLSL_TYPE_INTERFACE
:
281 for (unsigned int i
= 0; i
< length
; i
++) {
282 if (fields
.structure
[i
].type
->contains_opaque())
292 glsl_type::contains_subroutine() const
294 if (this->is_array()) {
295 return this->fields
.array
->contains_subroutine();
296 } else if (this->is_record() || this->is_interface()) {
297 for (unsigned int i
= 0; i
< this->length
; i
++) {
298 if (this->fields
.structure
[i
].type
->contains_subroutine())
303 return this->is_subroutine();
308 glsl_type::sampler_index() const
310 const glsl_type
*const t
= (this->is_array()) ? this->fields
.array
: this;
312 assert(t
->is_sampler() || t
->is_image());
314 switch (t
->sampler_dimensionality
) {
315 case GLSL_SAMPLER_DIM_1D
:
316 return (t
->sampler_array
) ? TEXTURE_1D_ARRAY_INDEX
: TEXTURE_1D_INDEX
;
317 case GLSL_SAMPLER_DIM_2D
:
318 return (t
->sampler_array
) ? TEXTURE_2D_ARRAY_INDEX
: TEXTURE_2D_INDEX
;
319 case GLSL_SAMPLER_DIM_3D
:
320 return TEXTURE_3D_INDEX
;
321 case GLSL_SAMPLER_DIM_CUBE
:
322 return (t
->sampler_array
) ? TEXTURE_CUBE_ARRAY_INDEX
: TEXTURE_CUBE_INDEX
;
323 case GLSL_SAMPLER_DIM_RECT
:
324 return TEXTURE_RECT_INDEX
;
325 case GLSL_SAMPLER_DIM_BUF
:
326 return TEXTURE_BUFFER_INDEX
;
327 case GLSL_SAMPLER_DIM_EXTERNAL
:
328 return TEXTURE_EXTERNAL_INDEX
;
329 case GLSL_SAMPLER_DIM_MS
:
330 return (t
->sampler_array
) ? TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
: TEXTURE_2D_MULTISAMPLE_INDEX
;
332 assert(!"Should not get here.");
333 return TEXTURE_BUFFER_INDEX
;
338 glsl_type::contains_image() const
340 if (this->is_array()) {
341 return this->fields
.array
->contains_image();
342 } else if (this->is_record() || this->is_interface()) {
343 for (unsigned int i
= 0; i
< this->length
; i
++) {
344 if (this->fields
.structure
[i
].type
->contains_image())
349 return this->is_image();
353 const glsl_type
*glsl_type::get_base_type() const
358 case GLSL_TYPE_UINT16
:
359 return uint16_t_type
;
362 case GLSL_TYPE_INT16
:
364 case GLSL_TYPE_FLOAT
:
366 case GLSL_TYPE_FLOAT16
:
367 return float16_t_type
;
368 case GLSL_TYPE_DOUBLE
:
372 case GLSL_TYPE_UINT64
:
373 return uint64_t_type
;
374 case GLSL_TYPE_INT64
:
382 const glsl_type
*glsl_type::get_scalar_type() const
384 const glsl_type
*type
= this;
387 while (type
->base_type
== GLSL_TYPE_ARRAY
)
388 type
= type
->fields
.array
;
390 /* Handle vectors and matrices */
391 switch (type
->base_type
) {
394 case GLSL_TYPE_UINT16
:
395 return uint16_t_type
;
398 case GLSL_TYPE_INT16
:
400 case GLSL_TYPE_FLOAT
:
402 case GLSL_TYPE_FLOAT16
:
403 return float16_t_type
;
404 case GLSL_TYPE_DOUBLE
:
408 case GLSL_TYPE_UINT64
:
409 return uint64_t_type
;
410 case GLSL_TYPE_INT64
:
413 /* Handle everything else */
420 _mesa_glsl_release_types(void)
422 /* Should only be called during atexit (either when unloading shared
423 * object, or if process terminates), so no mutex-locking should be
426 if (glsl_type::array_types
!= NULL
) {
427 _mesa_hash_table_destroy(glsl_type::array_types
, NULL
);
428 glsl_type::array_types
= NULL
;
431 if (glsl_type::record_types
!= NULL
) {
432 _mesa_hash_table_destroy(glsl_type::record_types
, NULL
);
433 glsl_type::record_types
= NULL
;
436 if (glsl_type::interface_types
!= NULL
) {
437 _mesa_hash_table_destroy(glsl_type::interface_types
, NULL
);
438 glsl_type::interface_types
= NULL
;
441 if (glsl_type::function_types
!= NULL
) {
442 _mesa_hash_table_destroy(glsl_type::function_types
, NULL
);
443 glsl_type::function_types
= NULL
;
446 if (glsl_type::subroutine_types
!= NULL
) {
447 _mesa_hash_table_destroy(glsl_type::subroutine_types
, NULL
);
448 glsl_type::subroutine_types
= NULL
;
451 ralloc_free(glsl_type::mem_ctx
);
452 glsl_type::mem_ctx
= NULL
;
456 glsl_type::glsl_type(const glsl_type
*array
, unsigned length
) :
457 base_type(GLSL_TYPE_ARRAY
), sampled_type(GLSL_TYPE_VOID
),
458 sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
459 interface_packing(0), interface_row_major(0),
460 vector_elements(0), matrix_columns(0),
461 length(length
), name(NULL
)
463 this->fields
.array
= array
;
464 /* Inherit the gl type of the base. The GL type is used for
465 * uniform/statevar handling in Mesa and the arrayness of the type
466 * is represented by the size rather than the type.
468 this->gl_type
= array
->gl_type
;
470 /* Allow a maximum of 10 characters for the array size. This is enough
471 * for 32-bits of ~0. The extra 3 are for the '[', ']', and terminating
474 const unsigned name_length
= strlen(array
->name
) + 10 + 3;
476 mtx_lock(&glsl_type::mem_mutex
);
477 char *const n
= (char *) ralloc_size(this->mem_ctx
, name_length
);
478 mtx_unlock(&glsl_type::mem_mutex
);
481 snprintf(n
, name_length
, "%s[]", array
->name
);
483 /* insert outermost dimensions in the correct spot
484 * otherwise the dimension order will be backwards
486 const char *pos
= strchr(array
->name
, '[');
488 int idx
= pos
- array
->name
;
489 snprintf(n
, idx
+1, "%s", array
->name
);
490 snprintf(n
+ idx
, name_length
- idx
, "[%u]%s",
491 length
, array
->name
+ idx
);
493 snprintf(n
, name_length
, "%s[%u]", array
->name
, length
);
502 glsl_type::vec(unsigned components
)
504 if (components
== 0 || components
> 4)
507 static const glsl_type
*const ts
[] = {
508 float_type
, vec2_type
, vec3_type
, vec4_type
510 return ts
[components
- 1];
514 glsl_type::f16vec(unsigned components
)
516 if (components
== 0 || components
> 4)
519 static const glsl_type
*const ts
[] = {
520 float16_t_type
, f16vec2_type
, f16vec3_type
, f16vec4_type
522 return ts
[components
- 1];
526 glsl_type::dvec(unsigned components
)
528 if (components
== 0 || components
> 4)
531 static const glsl_type
*const ts
[] = {
532 double_type
, dvec2_type
, dvec3_type
, dvec4_type
534 return ts
[components
- 1];
538 glsl_type::ivec(unsigned components
)
540 if (components
== 0 || components
> 4)
543 static const glsl_type
*const ts
[] = {
544 int_type
, ivec2_type
, ivec3_type
, ivec4_type
546 return ts
[components
- 1];
551 glsl_type::uvec(unsigned components
)
553 if (components
== 0 || components
> 4)
556 static const glsl_type
*const ts
[] = {
557 uint_type
, uvec2_type
, uvec3_type
, uvec4_type
559 return ts
[components
- 1];
564 glsl_type::bvec(unsigned components
)
566 if (components
== 0 || components
> 4)
569 static const glsl_type
*const ts
[] = {
570 bool_type
, bvec2_type
, bvec3_type
, bvec4_type
572 return ts
[components
- 1];
577 glsl_type::i64vec(unsigned components
)
579 if (components
== 0 || components
> 4)
582 static const glsl_type
*const ts
[] = {
583 int64_t_type
, i64vec2_type
, i64vec3_type
, i64vec4_type
585 return ts
[components
- 1];
590 glsl_type::u64vec(unsigned components
)
592 if (components
== 0 || components
> 4)
595 static const glsl_type
*const ts
[] = {
596 uint64_t_type
, u64vec2_type
, u64vec3_type
, u64vec4_type
598 return ts
[components
- 1];
602 glsl_type::i16vec(unsigned components
)
604 if (components
== 0 || components
> 4)
607 static const glsl_type
*const ts
[] = {
608 int16_t_type
, i16vec2_type
, i16vec3_type
, i16vec4_type
610 return ts
[components
- 1];
615 glsl_type::u16vec(unsigned components
)
617 if (components
== 0 || components
> 4)
620 static const glsl_type
*const ts
[] = {
621 uint16_t_type
, u16vec2_type
, u16vec3_type
, u16vec4_type
623 return ts
[components
- 1];
627 glsl_type::get_instance(unsigned base_type
, unsigned rows
, unsigned columns
)
629 if (base_type
== GLSL_TYPE_VOID
)
632 if ((rows
< 1) || (rows
> 4) || (columns
< 1) || (columns
> 4))
635 /* Treat GLSL vectors as Nx1 matrices.
643 case GLSL_TYPE_FLOAT
:
645 case GLSL_TYPE_FLOAT16
:
647 case GLSL_TYPE_DOUBLE
:
651 case GLSL_TYPE_UINT64
:
653 case GLSL_TYPE_INT64
:
655 case GLSL_TYPE_UINT16
:
657 case GLSL_TYPE_INT16
:
663 if ((base_type
!= GLSL_TYPE_FLOAT
&&
664 base_type
!= GLSL_TYPE_DOUBLE
&&
665 base_type
!= GLSL_TYPE_FLOAT16
) || (rows
== 1))
668 /* GLSL matrix types are named mat{COLUMNS}x{ROWS}. Only the following
669 * combinations are valid:
677 #define IDX(c,r) (((c-1)*3) + (r-1))
680 case GLSL_TYPE_DOUBLE
: {
681 switch (IDX(columns
, rows
)) {
682 case IDX(2,2): return dmat2_type
;
683 case IDX(2,3): return dmat2x3_type
;
684 case IDX(2,4): return dmat2x4_type
;
685 case IDX(3,2): return dmat3x2_type
;
686 case IDX(3,3): return dmat3_type
;
687 case IDX(3,4): return dmat3x4_type
;
688 case IDX(4,2): return dmat4x2_type
;
689 case IDX(4,3): return dmat4x3_type
;
690 case IDX(4,4): return dmat4_type
;
691 default: return error_type
;
694 case GLSL_TYPE_FLOAT
: {
695 switch (IDX(columns
, rows
)) {
696 case IDX(2,2): return mat2_type
;
697 case IDX(2,3): return mat2x3_type
;
698 case IDX(2,4): return mat2x4_type
;
699 case IDX(3,2): return mat3x2_type
;
700 case IDX(3,3): return mat3_type
;
701 case IDX(3,4): return mat3x4_type
;
702 case IDX(4,2): return mat4x2_type
;
703 case IDX(4,3): return mat4x3_type
;
704 case IDX(4,4): return mat4_type
;
705 default: return error_type
;
708 case GLSL_TYPE_FLOAT16
: {
709 switch (IDX(columns
, rows
)) {
710 case IDX(2,2): return f16mat2_type
;
711 case IDX(2,3): return f16mat2x3_type
;
712 case IDX(2,4): return f16mat2x4_type
;
713 case IDX(3,2): return f16mat3x2_type
;
714 case IDX(3,3): return f16mat3_type
;
715 case IDX(3,4): return f16mat3x4_type
;
716 case IDX(4,2): return f16mat4x2_type
;
717 case IDX(4,3): return f16mat4x3_type
;
718 case IDX(4,4): return f16mat4_type
;
719 default: return error_type
;
722 default: return error_type
;
726 assert(!"Should not get here.");
731 glsl_type::get_sampler_instance(enum glsl_sampler_dim dim
,
737 case GLSL_TYPE_FLOAT
:
739 case GLSL_SAMPLER_DIM_1D
:
741 return (array
? sampler1DArrayShadow_type
: sampler1DShadow_type
);
743 return (array
? sampler1DArray_type
: sampler1D_type
);
744 case GLSL_SAMPLER_DIM_2D
:
746 return (array
? sampler2DArrayShadow_type
: sampler2DShadow_type
);
748 return (array
? sampler2DArray_type
: sampler2D_type
);
749 case GLSL_SAMPLER_DIM_3D
:
753 return sampler3D_type
;
754 case GLSL_SAMPLER_DIM_CUBE
:
756 return (array
? samplerCubeArrayShadow_type
: samplerCubeShadow_type
);
758 return (array
? samplerCubeArray_type
: samplerCube_type
);
759 case GLSL_SAMPLER_DIM_RECT
:
763 return sampler2DRectShadow_type
;
765 return sampler2DRect_type
;
766 case GLSL_SAMPLER_DIM_BUF
:
770 return samplerBuffer_type
;
771 case GLSL_SAMPLER_DIM_MS
:
774 return (array
? sampler2DMSArray_type
: sampler2DMS_type
);
775 case GLSL_SAMPLER_DIM_EXTERNAL
:
779 return samplerExternalOES_type
;
780 case GLSL_SAMPLER_DIM_SUBPASS
:
781 case GLSL_SAMPLER_DIM_SUBPASS_MS
:
788 case GLSL_SAMPLER_DIM_1D
:
789 return (array
? isampler1DArray_type
: isampler1D_type
);
790 case GLSL_SAMPLER_DIM_2D
:
791 return (array
? isampler2DArray_type
: isampler2D_type
);
792 case GLSL_SAMPLER_DIM_3D
:
795 return isampler3D_type
;
796 case GLSL_SAMPLER_DIM_CUBE
:
797 return (array
? isamplerCubeArray_type
: isamplerCube_type
);
798 case GLSL_SAMPLER_DIM_RECT
:
801 return isampler2DRect_type
;
802 case GLSL_SAMPLER_DIM_BUF
:
805 return isamplerBuffer_type
;
806 case GLSL_SAMPLER_DIM_MS
:
807 return (array
? isampler2DMSArray_type
: isampler2DMS_type
);
808 case GLSL_SAMPLER_DIM_EXTERNAL
:
810 case GLSL_SAMPLER_DIM_SUBPASS
:
811 case GLSL_SAMPLER_DIM_SUBPASS_MS
:
818 case GLSL_SAMPLER_DIM_1D
:
819 return (array
? usampler1DArray_type
: usampler1D_type
);
820 case GLSL_SAMPLER_DIM_2D
:
821 return (array
? usampler2DArray_type
: usampler2D_type
);
822 case GLSL_SAMPLER_DIM_3D
:
825 return usampler3D_type
;
826 case GLSL_SAMPLER_DIM_CUBE
:
827 return (array
? usamplerCubeArray_type
: usamplerCube_type
);
828 case GLSL_SAMPLER_DIM_RECT
:
831 return usampler2DRect_type
;
832 case GLSL_SAMPLER_DIM_BUF
:
835 return usamplerBuffer_type
;
836 case GLSL_SAMPLER_DIM_MS
:
837 return (array
? usampler2DMSArray_type
: usampler2DMS_type
);
838 case GLSL_SAMPLER_DIM_EXTERNAL
:
840 case GLSL_SAMPLER_DIM_SUBPASS
:
841 case GLSL_SAMPLER_DIM_SUBPASS_MS
:
848 unreachable("switch statement above should be complete");
852 glsl_type::get_image_instance(enum glsl_sampler_dim dim
,
853 bool array
, glsl_base_type type
)
856 case GLSL_TYPE_FLOAT
:
858 case GLSL_SAMPLER_DIM_1D
:
859 return (array
? image1DArray_type
: image1D_type
);
860 case GLSL_SAMPLER_DIM_2D
:
861 return (array
? image2DArray_type
: image2D_type
);
862 case GLSL_SAMPLER_DIM_3D
:
864 case GLSL_SAMPLER_DIM_CUBE
:
865 return (array
? imageCubeArray_type
: imageCube_type
);
866 case GLSL_SAMPLER_DIM_RECT
:
870 return image2DRect_type
;
871 case GLSL_SAMPLER_DIM_BUF
:
875 return imageBuffer_type
;
876 case GLSL_SAMPLER_DIM_MS
:
877 return (array
? image2DMSArray_type
: image2DMS_type
);
878 case GLSL_SAMPLER_DIM_SUBPASS
:
879 return subpassInput_type
;
880 case GLSL_SAMPLER_DIM_SUBPASS_MS
:
881 return subpassInputMS_type
;
882 case GLSL_SAMPLER_DIM_EXTERNAL
:
887 case GLSL_SAMPLER_DIM_1D
:
888 return (array
? iimage1DArray_type
: iimage1D_type
);
889 case GLSL_SAMPLER_DIM_2D
:
890 return (array
? iimage2DArray_type
: iimage2D_type
);
891 case GLSL_SAMPLER_DIM_3D
:
894 return iimage3D_type
;
895 case GLSL_SAMPLER_DIM_CUBE
:
896 return (array
? iimageCubeArray_type
: iimageCube_type
);
897 case GLSL_SAMPLER_DIM_RECT
:
900 return iimage2DRect_type
;
901 case GLSL_SAMPLER_DIM_BUF
:
904 return iimageBuffer_type
;
905 case GLSL_SAMPLER_DIM_MS
:
906 return (array
? iimage2DMSArray_type
: iimage2DMS_type
);
907 case GLSL_SAMPLER_DIM_SUBPASS
:
908 return isubpassInput_type
;
909 case GLSL_SAMPLER_DIM_SUBPASS_MS
:
910 return isubpassInputMS_type
;
911 case GLSL_SAMPLER_DIM_EXTERNAL
:
916 case GLSL_SAMPLER_DIM_1D
:
917 return (array
? uimage1DArray_type
: uimage1D_type
);
918 case GLSL_SAMPLER_DIM_2D
:
919 return (array
? uimage2DArray_type
: uimage2D_type
);
920 case GLSL_SAMPLER_DIM_3D
:
923 return uimage3D_type
;
924 case GLSL_SAMPLER_DIM_CUBE
:
925 return (array
? uimageCubeArray_type
: uimageCube_type
);
926 case GLSL_SAMPLER_DIM_RECT
:
929 return uimage2DRect_type
;
930 case GLSL_SAMPLER_DIM_BUF
:
933 return uimageBuffer_type
;
934 case GLSL_SAMPLER_DIM_MS
:
935 return (array
? uimage2DMSArray_type
: uimage2DMS_type
);
936 case GLSL_SAMPLER_DIM_SUBPASS
:
937 return usubpassInput_type
;
938 case GLSL_SAMPLER_DIM_SUBPASS_MS
:
939 return usubpassInputMS_type
;
940 case GLSL_SAMPLER_DIM_EXTERNAL
:
947 unreachable("switch statement above should be complete");
951 glsl_type::get_array_instance(const glsl_type
*base
, unsigned array_size
)
953 /* Generate a name using the base type pointer in the key. This is
954 * done because the name of the base type may not be unique across
955 * shaders. For example, two shaders may have different record types
959 snprintf(key
, sizeof(key
), "%p[%u]", (void *) base
, array_size
);
961 mtx_lock(&glsl_type::hash_mutex
);
963 if (array_types
== NULL
) {
964 array_types
= _mesa_hash_table_create(NULL
, _mesa_key_hash_string
,
965 _mesa_key_string_equal
);
968 const struct hash_entry
*entry
= _mesa_hash_table_search(array_types
, key
);
970 const glsl_type
*t
= new glsl_type(base
, array_size
);
972 entry
= _mesa_hash_table_insert(array_types
,
973 ralloc_strdup(mem_ctx
, key
),
977 assert(((glsl_type
*) entry
->data
)->base_type
== GLSL_TYPE_ARRAY
);
978 assert(((glsl_type
*) entry
->data
)->length
== array_size
);
979 assert(((glsl_type
*) entry
->data
)->fields
.array
== base
);
981 mtx_unlock(&glsl_type::hash_mutex
);
983 return (glsl_type
*) entry
->data
;
988 glsl_type::record_compare(const glsl_type
*b
, bool match_locations
) const
990 if (this->length
!= b
->length
)
993 if (this->interface_packing
!= b
->interface_packing
)
996 if (this->interface_row_major
!= b
->interface_row_major
)
999 /* From the GLSL 4.20 specification (Sec 4.2):
1001 * "Structures must have the same name, sequence of type names, and
1002 * type definitions, and field names to be considered the same type."
1004 * GLSL ES behaves the same (Ver 1.00 Sec 4.2.4, Ver 3.00 Sec 4.2.5).
1006 if (strcmp(this->name
, b
->name
) != 0)
1009 for (unsigned i
= 0; i
< this->length
; i
++) {
1010 if (this->fields
.structure
[i
].type
!= b
->fields
.structure
[i
].type
)
1012 if (strcmp(this->fields
.structure
[i
].name
,
1013 b
->fields
.structure
[i
].name
) != 0)
1015 if (this->fields
.structure
[i
].matrix_layout
1016 != b
->fields
.structure
[i
].matrix_layout
)
1018 if (match_locations
&& this->fields
.structure
[i
].location
1019 != b
->fields
.structure
[i
].location
)
1021 if (this->fields
.structure
[i
].offset
1022 != b
->fields
.structure
[i
].offset
)
1024 if (this->fields
.structure
[i
].interpolation
1025 != b
->fields
.structure
[i
].interpolation
)
1027 if (this->fields
.structure
[i
].centroid
1028 != b
->fields
.structure
[i
].centroid
)
1030 if (this->fields
.structure
[i
].sample
1031 != b
->fields
.structure
[i
].sample
)
1033 if (this->fields
.structure
[i
].patch
1034 != b
->fields
.structure
[i
].patch
)
1036 if (this->fields
.structure
[i
].memory_read_only
1037 != b
->fields
.structure
[i
].memory_read_only
)
1039 if (this->fields
.structure
[i
].memory_write_only
1040 != b
->fields
.structure
[i
].memory_write_only
)
1042 if (this->fields
.structure
[i
].memory_coherent
1043 != b
->fields
.structure
[i
].memory_coherent
)
1045 if (this->fields
.structure
[i
].memory_volatile
1046 != b
->fields
.structure
[i
].memory_volatile
)
1048 if (this->fields
.structure
[i
].memory_restrict
1049 != b
->fields
.structure
[i
].memory_restrict
)
1051 if (this->fields
.structure
[i
].image_format
1052 != b
->fields
.structure
[i
].image_format
)
1054 if (this->fields
.structure
[i
].precision
1055 != b
->fields
.structure
[i
].precision
)
1057 if (this->fields
.structure
[i
].explicit_xfb_buffer
1058 != b
->fields
.structure
[i
].explicit_xfb_buffer
)
1060 if (this->fields
.structure
[i
].xfb_buffer
1061 != b
->fields
.structure
[i
].xfb_buffer
)
1063 if (this->fields
.structure
[i
].xfb_stride
1064 != b
->fields
.structure
[i
].xfb_stride
)
1073 glsl_type::record_key_compare(const void *a
, const void *b
)
1075 const glsl_type
*const key1
= (glsl_type
*) a
;
1076 const glsl_type
*const key2
= (glsl_type
*) b
;
1078 return strcmp(key1
->name
, key2
->name
) == 0 && key1
->record_compare(key2
);
1083 * Generate an integer hash value for a glsl_type structure type.
1086 glsl_type::record_key_hash(const void *a
)
1088 const glsl_type
*const key
= (glsl_type
*) a
;
1089 uintptr_t hash
= key
->length
;
1092 for (unsigned i
= 0; i
< key
->length
; i
++) {
1093 /* casting pointer to uintptr_t */
1094 hash
= (hash
* 13 ) + (uintptr_t) key
->fields
.structure
[i
].type
;
1097 if (sizeof(hash
) == 8)
1098 retval
= (hash
& 0xffffffff) ^ ((uint64_t) hash
>> 32);
1107 glsl_type::get_record_instance(const glsl_struct_field
*fields
,
1108 unsigned num_fields
,
1111 const glsl_type
key(fields
, num_fields
, name
);
1113 mtx_lock(&glsl_type::hash_mutex
);
1115 if (record_types
== NULL
) {
1116 record_types
= _mesa_hash_table_create(NULL
, record_key_hash
,
1117 record_key_compare
);
1120 const struct hash_entry
*entry
= _mesa_hash_table_search(record_types
,
1122 if (entry
== NULL
) {
1123 const glsl_type
*t
= new glsl_type(fields
, num_fields
, name
);
1125 entry
= _mesa_hash_table_insert(record_types
, t
, (void *) t
);
1128 assert(((glsl_type
*) entry
->data
)->base_type
== GLSL_TYPE_STRUCT
);
1129 assert(((glsl_type
*) entry
->data
)->length
== num_fields
);
1130 assert(strcmp(((glsl_type
*) entry
->data
)->name
, name
) == 0);
1132 mtx_unlock(&glsl_type::hash_mutex
);
1134 return (glsl_type
*) entry
->data
;
1139 glsl_type::get_interface_instance(const glsl_struct_field
*fields
,
1140 unsigned num_fields
,
1141 enum glsl_interface_packing packing
,
1143 const char *block_name
)
1145 const glsl_type
key(fields
, num_fields
, packing
, row_major
, block_name
);
1147 mtx_lock(&glsl_type::hash_mutex
);
1149 if (interface_types
== NULL
) {
1150 interface_types
= _mesa_hash_table_create(NULL
, record_key_hash
,
1151 record_key_compare
);
1154 const struct hash_entry
*entry
= _mesa_hash_table_search(interface_types
,
1156 if (entry
== NULL
) {
1157 const glsl_type
*t
= new glsl_type(fields
, num_fields
,
1158 packing
, row_major
, block_name
);
1160 entry
= _mesa_hash_table_insert(interface_types
, t
, (void *) t
);
1163 assert(((glsl_type
*) entry
->data
)->base_type
== GLSL_TYPE_INTERFACE
);
1164 assert(((glsl_type
*) entry
->data
)->length
== num_fields
);
1165 assert(strcmp(((glsl_type
*) entry
->data
)->name
, block_name
) == 0);
1167 mtx_unlock(&glsl_type::hash_mutex
);
1169 return (glsl_type
*) entry
->data
;
1173 glsl_type::get_subroutine_instance(const char *subroutine_name
)
1175 const glsl_type
key(subroutine_name
);
1177 mtx_lock(&glsl_type::hash_mutex
);
1179 if (subroutine_types
== NULL
) {
1180 subroutine_types
= _mesa_hash_table_create(NULL
, record_key_hash
,
1181 record_key_compare
);
1184 const struct hash_entry
*entry
= _mesa_hash_table_search(subroutine_types
,
1186 if (entry
== NULL
) {
1187 const glsl_type
*t
= new glsl_type(subroutine_name
);
1189 entry
= _mesa_hash_table_insert(subroutine_types
, t
, (void *) t
);
1192 assert(((glsl_type
*) entry
->data
)->base_type
== GLSL_TYPE_SUBROUTINE
);
1193 assert(strcmp(((glsl_type
*) entry
->data
)->name
, subroutine_name
) == 0);
1195 mtx_unlock(&glsl_type::hash_mutex
);
1197 return (glsl_type
*) entry
->data
;
1202 function_key_compare(const void *a
, const void *b
)
1204 const glsl_type
*const key1
= (glsl_type
*) a
;
1205 const glsl_type
*const key2
= (glsl_type
*) b
;
1207 if (key1
->length
!= key2
->length
)
1210 return memcmp(key1
->fields
.parameters
, key2
->fields
.parameters
,
1211 (key1
->length
+ 1) * sizeof(*key1
->fields
.parameters
)) == 0;
1216 function_key_hash(const void *a
)
1218 const glsl_type
*const key
= (glsl_type
*) a
;
1219 return _mesa_hash_data(key
->fields
.parameters
,
1220 (key
->length
+ 1) * sizeof(*key
->fields
.parameters
));
1224 glsl_type::get_function_instance(const glsl_type
*return_type
,
1225 const glsl_function_param
*params
,
1226 unsigned num_params
)
1228 const glsl_type
key(return_type
, params
, num_params
);
1230 mtx_lock(&glsl_type::hash_mutex
);
1232 if (function_types
== NULL
) {
1233 function_types
= _mesa_hash_table_create(NULL
, function_key_hash
,
1234 function_key_compare
);
1237 struct hash_entry
*entry
= _mesa_hash_table_search(function_types
, &key
);
1238 if (entry
== NULL
) {
1239 const glsl_type
*t
= new glsl_type(return_type
, params
, num_params
);
1241 entry
= _mesa_hash_table_insert(function_types
, t
, (void *) t
);
1244 const glsl_type
*t
= (const glsl_type
*)entry
->data
;
1246 assert(t
->base_type
== GLSL_TYPE_FUNCTION
);
1247 assert(t
->length
== num_params
);
1249 mtx_unlock(&glsl_type::hash_mutex
);
1256 glsl_type::get_mul_type(const glsl_type
*type_a
, const glsl_type
*type_b
)
1258 if (type_a
== type_b
) {
1260 } else if (type_a
->is_matrix() && type_b
->is_matrix()) {
1261 /* Matrix multiply. The columns of A must match the rows of B. Given
1262 * the other previously tested constraints, this means the vector type
1263 * of a row from A must be the same as the vector type of a column from
1266 if (type_a
->row_type() == type_b
->column_type()) {
1267 /* The resulting matrix has the number of columns of matrix B and
1268 * the number of rows of matrix A. We get the row count of A by
1269 * looking at the size of a vector that makes up a column. The
1270 * transpose (size of a row) is done for B.
1272 const glsl_type
*const type
=
1273 get_instance(type_a
->base_type
,
1274 type_a
->column_type()->vector_elements
,
1275 type_b
->row_type()->vector_elements
);
1276 assert(type
!= error_type
);
1280 } else if (type_a
->is_matrix()) {
1281 /* A is a matrix and B is a column vector. Columns of A must match
1282 * rows of B. Given the other previously tested constraints, this
1283 * means the vector type of a row from A must be the same as the
1284 * vector the type of B.
1286 if (type_a
->row_type() == type_b
) {
1287 /* The resulting vector has a number of elements equal to
1288 * the number of rows of matrix A. */
1289 const glsl_type
*const type
=
1290 get_instance(type_a
->base_type
,
1291 type_a
->column_type()->vector_elements
,
1293 assert(type
!= error_type
);
1298 assert(type_b
->is_matrix());
1300 /* A is a row vector and B is a matrix. Columns of A must match rows
1301 * of B. Given the other previously tested constraints, this means
1302 * the type of A must be the same as the vector type of a column from
1305 if (type_a
== type_b
->column_type()) {
1306 /* The resulting vector has a number of elements equal to
1307 * the number of columns of matrix B. */
1308 const glsl_type
*const type
=
1309 get_instance(type_a
->base_type
,
1310 type_b
->row_type()->vector_elements
,
1312 assert(type
!= error_type
);
1323 glsl_type::field_type(const char *name
) const
1325 if (this->base_type
!= GLSL_TYPE_STRUCT
1326 && this->base_type
!= GLSL_TYPE_INTERFACE
)
1329 for (unsigned i
= 0; i
< this->length
; i
++) {
1330 if (strcmp(name
, this->fields
.structure
[i
].name
) == 0)
1331 return this->fields
.structure
[i
].type
;
1339 glsl_type::field_index(const char *name
) const
1341 if (this->base_type
!= GLSL_TYPE_STRUCT
1342 && this->base_type
!= GLSL_TYPE_INTERFACE
)
1345 for (unsigned i
= 0; i
< this->length
; i
++) {
1346 if (strcmp(name
, this->fields
.structure
[i
].name
) == 0)
1355 glsl_type::component_slots() const
1357 switch (this->base_type
) {
1358 case GLSL_TYPE_UINT
:
1360 case GLSL_TYPE_UINT16
:
1361 case GLSL_TYPE_INT16
:
1362 case GLSL_TYPE_FLOAT
:
1363 case GLSL_TYPE_FLOAT16
:
1364 case GLSL_TYPE_BOOL
:
1365 return this->components();
1367 case GLSL_TYPE_DOUBLE
:
1368 case GLSL_TYPE_UINT64
:
1369 case GLSL_TYPE_INT64
:
1370 return 2 * this->components();
1372 case GLSL_TYPE_STRUCT
:
1373 case GLSL_TYPE_INTERFACE
: {
1376 for (unsigned i
= 0; i
< this->length
; i
++)
1377 size
+= this->fields
.structure
[i
].type
->component_slots();
1382 case GLSL_TYPE_ARRAY
:
1383 return this->length
* this->fields
.array
->component_slots();
1385 case GLSL_TYPE_SAMPLER
:
1386 case GLSL_TYPE_IMAGE
:
1389 case GLSL_TYPE_SUBROUTINE
:
1392 case GLSL_TYPE_FUNCTION
:
1393 case GLSL_TYPE_ATOMIC_UINT
:
1394 case GLSL_TYPE_VOID
:
1395 case GLSL_TYPE_ERROR
:
1403 glsl_type::record_location_offset(unsigned length
) const
1405 unsigned offset
= 0;
1406 const glsl_type
*t
= this->without_array();
1407 if (t
->is_record()) {
1408 assert(length
<= t
->length
);
1410 for (unsigned i
= 0; i
< length
; i
++) {
1411 const glsl_type
*st
= t
->fields
.structure
[i
].type
;
1412 const glsl_type
*wa
= st
->without_array();
1413 if (wa
->is_record()) {
1414 unsigned r_offset
= wa
->record_location_offset(wa
->length
);
1415 offset
+= st
->is_array() ?
1416 st
->arrays_of_arrays_size() * r_offset
: r_offset
;
1417 } else if (st
->is_array() && st
->fields
.array
->is_array()) {
1418 unsigned outer_array_size
= st
->length
;
1419 const glsl_type
*base_type
= st
->fields
.array
;
1421 /* For arrays of arrays the outer arrays take up a uniform
1422 * slot for each element. The innermost array elements share a
1423 * single slot so we ignore the innermost array when calculating
1426 while (base_type
->fields
.array
->is_array()) {
1427 outer_array_size
= outer_array_size
* base_type
->length
;
1428 base_type
= base_type
->fields
.array
;
1430 offset
+= outer_array_size
;
1432 /* We dont worry about arrays here because unless the array
1433 * contains a structure or another array it only takes up a single
1444 glsl_type::uniform_locations() const
1448 switch (this->base_type
) {
1449 case GLSL_TYPE_UINT
:
1451 case GLSL_TYPE_FLOAT
:
1452 case GLSL_TYPE_FLOAT16
:
1453 case GLSL_TYPE_DOUBLE
:
1454 case GLSL_TYPE_UINT16
:
1455 case GLSL_TYPE_INT16
:
1456 case GLSL_TYPE_UINT64
:
1457 case GLSL_TYPE_INT64
:
1458 case GLSL_TYPE_BOOL
:
1459 case GLSL_TYPE_SAMPLER
:
1460 case GLSL_TYPE_IMAGE
:
1461 case GLSL_TYPE_SUBROUTINE
:
1464 case GLSL_TYPE_STRUCT
:
1465 case GLSL_TYPE_INTERFACE
:
1466 for (unsigned i
= 0; i
< this->length
; i
++)
1467 size
+= this->fields
.structure
[i
].type
->uniform_locations();
1469 case GLSL_TYPE_ARRAY
:
1470 return this->length
* this->fields
.array
->uniform_locations();
1477 glsl_type::varying_count() const
1481 switch (this->base_type
) {
1482 case GLSL_TYPE_UINT
:
1484 case GLSL_TYPE_FLOAT
:
1485 case GLSL_TYPE_FLOAT16
:
1486 case GLSL_TYPE_DOUBLE
:
1487 case GLSL_TYPE_BOOL
:
1488 case GLSL_TYPE_UINT16
:
1489 case GLSL_TYPE_INT16
:
1490 case GLSL_TYPE_UINT64
:
1491 case GLSL_TYPE_INT64
:
1494 case GLSL_TYPE_STRUCT
:
1495 case GLSL_TYPE_INTERFACE
:
1496 for (unsigned i
= 0; i
< this->length
; i
++)
1497 size
+= this->fields
.structure
[i
].type
->varying_count();
1499 case GLSL_TYPE_ARRAY
:
1500 /* Don't count innermost array elements */
1501 if (this->without_array()->is_record() ||
1502 this->without_array()->is_interface() ||
1503 this->fields
.array
->is_array())
1504 return this->length
* this->fields
.array
->varying_count();
1506 return this->fields
.array
->varying_count();
1508 assert(!"unsupported varying type");
1514 glsl_type::can_implicitly_convert_to(const glsl_type
*desired
,
1515 _mesa_glsl_parse_state
*state
) const
1517 if (this == desired
)
1520 /* GLSL 1.10 and ESSL do not allow implicit conversions. If there is no
1521 * state, we're doing intra-stage function linking where these checks have
1522 * already been done.
1524 if (state
&& (state
->es_shader
|| !state
->is_version(120, 0)))
1527 /* There is no conversion among matrix types. */
1528 if (this->matrix_columns
> 1 || desired
->matrix_columns
> 1)
1531 /* Vector size must match. */
1532 if (this->vector_elements
!= desired
->vector_elements
)
1535 /* int and uint can be converted to float. */
1536 if (desired
->is_float() && this->is_integer())
1539 /* With GLSL 4.0, ARB_gpu_shader5, or MESA_shader_integer_functions, int
1540 * can be converted to uint. Note that state may be NULL here, when
1541 * resolving function calls in the linker. By this time, all the
1542 * state-dependent checks have already happened though, so allow anything
1543 * that's allowed in any shader version.
1545 if ((!state
|| state
->is_version(400, 0) || state
->ARB_gpu_shader5_enable
||
1546 state
->MESA_shader_integer_functions_enable
) &&
1547 desired
->base_type
== GLSL_TYPE_UINT
&& this->base_type
== GLSL_TYPE_INT
)
1550 /* No implicit conversions from double. */
1551 if ((!state
|| state
->has_double()) && this->is_double())
1554 /* Conversions from different types to double. */
1555 if ((!state
|| state
->has_double()) && desired
->is_double()) {
1556 if (this->is_float())
1558 if (this->is_integer())
1566 glsl_type::std140_base_alignment(bool row_major
) const
1568 unsigned N
= is_64bit() ? 8 : 4;
1570 /* (1) If the member is a scalar consuming <N> basic machine units, the
1571 * base alignment is <N>.
1573 * (2) If the member is a two- or four-component vector with components
1574 * consuming <N> basic machine units, the base alignment is 2<N> or
1575 * 4<N>, respectively.
1577 * (3) If the member is a three-component vector with components consuming
1578 * <N> basic machine units, the base alignment is 4<N>.
1580 if (this->is_scalar() || this->is_vector()) {
1581 switch (this->vector_elements
) {
1592 /* (4) If the member is an array of scalars or vectors, the base alignment
1593 * and array stride are set to match the base alignment of a single
1594 * array element, according to rules (1), (2), and (3), and rounded up
1595 * to the base alignment of a vec4. The array may have padding at the
1596 * end; the base offset of the member following the array is rounded up
1597 * to the next multiple of the base alignment.
1599 * (6) If the member is an array of <S> column-major matrices with <C>
1600 * columns and <R> rows, the matrix is stored identically to a row of
1601 * <S>*<C> column vectors with <R> components each, according to rule
1604 * (8) If the member is an array of <S> row-major matrices with <C> columns
1605 * and <R> rows, the matrix is stored identically to a row of <S>*<R>
1606 * row vectors with <C> components each, according to rule (4).
1608 * (10) If the member is an array of <S> structures, the <S> elements of
1609 * the array are laid out in order, according to rule (9).
1611 if (this->is_array()) {
1612 if (this->fields
.array
->is_scalar() ||
1613 this->fields
.array
->is_vector() ||
1614 this->fields
.array
->is_matrix()) {
1615 return MAX2(this->fields
.array
->std140_base_alignment(row_major
), 16);
1617 assert(this->fields
.array
->is_record() ||
1618 this->fields
.array
->is_array());
1619 return this->fields
.array
->std140_base_alignment(row_major
);
1623 /* (5) If the member is a column-major matrix with <C> columns and
1624 * <R> rows, the matrix is stored identically to an array of
1625 * <C> column vectors with <R> components each, according to
1628 * (7) If the member is a row-major matrix with <C> columns and <R>
1629 * rows, the matrix is stored identically to an array of <R>
1630 * row vectors with <C> components each, according to rule (4).
1632 if (this->is_matrix()) {
1633 const struct glsl_type
*vec_type
, *array_type
;
1634 int c
= this->matrix_columns
;
1635 int r
= this->vector_elements
;
1638 vec_type
= get_instance(base_type
, c
, 1);
1639 array_type
= glsl_type::get_array_instance(vec_type
, r
);
1641 vec_type
= get_instance(base_type
, r
, 1);
1642 array_type
= glsl_type::get_array_instance(vec_type
, c
);
1645 return array_type
->std140_base_alignment(false);
1648 /* (9) If the member is a structure, the base alignment of the
1649 * structure is <N>, where <N> is the largest base alignment
1650 * value of any of its members, and rounded up to the base
1651 * alignment of a vec4. The individual members of this
1652 * sub-structure are then assigned offsets by applying this set
1653 * of rules recursively, where the base offset of the first
1654 * member of the sub-structure is equal to the aligned offset
1655 * of the structure. The structure may have padding at the end;
1656 * the base offset of the member following the sub-structure is
1657 * rounded up to the next multiple of the base alignment of the
1660 if (this->is_record()) {
1661 unsigned base_alignment
= 16;
1662 for (unsigned i
= 0; i
< this->length
; i
++) {
1663 bool field_row_major
= row_major
;
1664 const enum glsl_matrix_layout matrix_layout
=
1665 glsl_matrix_layout(this->fields
.structure
[i
].matrix_layout
);
1666 if (matrix_layout
== GLSL_MATRIX_LAYOUT_ROW_MAJOR
) {
1667 field_row_major
= true;
1668 } else if (matrix_layout
== GLSL_MATRIX_LAYOUT_COLUMN_MAJOR
) {
1669 field_row_major
= false;
1672 const struct glsl_type
*field_type
= this->fields
.structure
[i
].type
;
1673 base_alignment
= MAX2(base_alignment
,
1674 field_type
->std140_base_alignment(field_row_major
));
1676 return base_alignment
;
1679 assert(!"not reached");
1684 glsl_type::std140_size(bool row_major
) const
1686 unsigned N
= is_64bit() ? 8 : 4;
1688 /* (1) If the member is a scalar consuming <N> basic machine units, the
1689 * base alignment is <N>.
1691 * (2) If the member is a two- or four-component vector with components
1692 * consuming <N> basic machine units, the base alignment is 2<N> or
1693 * 4<N>, respectively.
1695 * (3) If the member is a three-component vector with components consuming
1696 * <N> basic machine units, the base alignment is 4<N>.
1698 if (this->is_scalar() || this->is_vector()) {
1699 return this->vector_elements
* N
;
1702 /* (5) If the member is a column-major matrix with <C> columns and
1703 * <R> rows, the matrix is stored identically to an array of
1704 * <C> column vectors with <R> components each, according to
1707 * (6) If the member is an array of <S> column-major matrices with <C>
1708 * columns and <R> rows, the matrix is stored identically to a row of
1709 * <S>*<C> column vectors with <R> components each, according to rule
1712 * (7) If the member is a row-major matrix with <C> columns and <R>
1713 * rows, the matrix is stored identically to an array of <R>
1714 * row vectors with <C> components each, according to rule (4).
1716 * (8) If the member is an array of <S> row-major matrices with <C> columns
1717 * and <R> rows, the matrix is stored identically to a row of <S>*<R>
1718 * row vectors with <C> components each, according to rule (4).
1720 if (this->without_array()->is_matrix()) {
1721 const struct glsl_type
*element_type
;
1722 const struct glsl_type
*vec_type
;
1723 unsigned int array_len
;
1725 if (this->is_array()) {
1726 element_type
= this->without_array();
1727 array_len
= this->arrays_of_arrays_size();
1729 element_type
= this;
1734 vec_type
= get_instance(element_type
->base_type
,
1735 element_type
->matrix_columns
, 1);
1737 array_len
*= element_type
->vector_elements
;
1739 vec_type
= get_instance(element_type
->base_type
,
1740 element_type
->vector_elements
, 1);
1741 array_len
*= element_type
->matrix_columns
;
1743 const glsl_type
*array_type
= glsl_type::get_array_instance(vec_type
,
1746 return array_type
->std140_size(false);
1749 /* (4) If the member is an array of scalars or vectors, the base alignment
1750 * and array stride are set to match the base alignment of a single
1751 * array element, according to rules (1), (2), and (3), and rounded up
1752 * to the base alignment of a vec4. The array may have padding at the
1753 * end; the base offset of the member following the array is rounded up
1754 * to the next multiple of the base alignment.
1756 * (10) If the member is an array of <S> structures, the <S> elements of
1757 * the array are laid out in order, according to rule (9).
1759 if (this->is_array()) {
1760 if (this->without_array()->is_record()) {
1761 return this->arrays_of_arrays_size() *
1762 this->without_array()->std140_size(row_major
);
1764 unsigned element_base_align
=
1765 this->without_array()->std140_base_alignment(row_major
);
1766 return this->arrays_of_arrays_size() * MAX2(element_base_align
, 16);
1770 /* (9) If the member is a structure, the base alignment of the
1771 * structure is <N>, where <N> is the largest base alignment
1772 * value of any of its members, and rounded up to the base
1773 * alignment of a vec4. The individual members of this
1774 * sub-structure are then assigned offsets by applying this set
1775 * of rules recursively, where the base offset of the first
1776 * member of the sub-structure is equal to the aligned offset
1777 * of the structure. The structure may have padding at the end;
1778 * the base offset of the member following the sub-structure is
1779 * rounded up to the next multiple of the base alignment of the
1782 if (this->is_record() || this->is_interface()) {
1784 unsigned max_align
= 0;
1786 for (unsigned i
= 0; i
< this->length
; i
++) {
1787 bool field_row_major
= row_major
;
1788 const enum glsl_matrix_layout matrix_layout
=
1789 glsl_matrix_layout(this->fields
.structure
[i
].matrix_layout
);
1790 if (matrix_layout
== GLSL_MATRIX_LAYOUT_ROW_MAJOR
) {
1791 field_row_major
= true;
1792 } else if (matrix_layout
== GLSL_MATRIX_LAYOUT_COLUMN_MAJOR
) {
1793 field_row_major
= false;
1796 const struct glsl_type
*field_type
= this->fields
.structure
[i
].type
;
1797 unsigned align
= field_type
->std140_base_alignment(field_row_major
);
1799 /* Ignore unsized arrays when calculating size */
1800 if (field_type
->is_unsized_array())
1803 size
= glsl_align(size
, align
);
1804 size
+= field_type
->std140_size(field_row_major
);
1806 max_align
= MAX2(align
, max_align
);
1808 if (field_type
->is_record() && (i
+ 1 < this->length
))
1809 size
= glsl_align(size
, 16);
1811 size
= glsl_align(size
, MAX2(max_align
, 16));
1815 assert(!"not reached");
1820 glsl_type::std430_base_alignment(bool row_major
) const
1823 unsigned N
= is_64bit() ? 8 : 4;
1825 /* (1) If the member is a scalar consuming <N> basic machine units, the
1826 * base alignment is <N>.
1828 * (2) If the member is a two- or four-component vector with components
1829 * consuming <N> basic machine units, the base alignment is 2<N> or
1830 * 4<N>, respectively.
1832 * (3) If the member is a three-component vector with components consuming
1833 * <N> basic machine units, the base alignment is 4<N>.
1835 if (this->is_scalar() || this->is_vector()) {
1836 switch (this->vector_elements
) {
1847 /* OpenGL 4.30 spec, section 7.6.2.2 "Standard Uniform Block Layout":
1849 * "When using the std430 storage layout, shader storage blocks will be
1850 * laid out in buffer storage identically to uniform and shader storage
1851 * blocks using the std140 layout, except that the base alignment and
1852 * stride of arrays of scalars and vectors in rule 4 and of structures
1853 * in rule 9 are not rounded up a multiple of the base alignment of a vec4.
1856 /* (1) If the member is a scalar consuming <N> basic machine units, the
1857 * base alignment is <N>.
1859 * (2) If the member is a two- or four-component vector with components
1860 * consuming <N> basic machine units, the base alignment is 2<N> or
1861 * 4<N>, respectively.
1863 * (3) If the member is a three-component vector with components consuming
1864 * <N> basic machine units, the base alignment is 4<N>.
1866 if (this->is_array())
1867 return this->fields
.array
->std430_base_alignment(row_major
);
1869 /* (5) If the member is a column-major matrix with <C> columns and
1870 * <R> rows, the matrix is stored identically to an array of
1871 * <C> column vectors with <R> components each, according to
1874 * (7) If the member is a row-major matrix with <C> columns and <R>
1875 * rows, the matrix is stored identically to an array of <R>
1876 * row vectors with <C> components each, according to rule (4).
1878 if (this->is_matrix()) {
1879 const struct glsl_type
*vec_type
, *array_type
;
1880 int c
= this->matrix_columns
;
1881 int r
= this->vector_elements
;
1884 vec_type
= get_instance(base_type
, c
, 1);
1885 array_type
= glsl_type::get_array_instance(vec_type
, r
);
1887 vec_type
= get_instance(base_type
, r
, 1);
1888 array_type
= glsl_type::get_array_instance(vec_type
, c
);
1891 return array_type
->std430_base_alignment(false);
1894 /* (9) If the member is a structure, the base alignment of the
1895 * structure is <N>, where <N> is the largest base alignment
1896 * value of any of its members, and rounded up to the base
1897 * alignment of a vec4. The individual members of this
1898 * sub-structure are then assigned offsets by applying this set
1899 * of rules recursively, where the base offset of the first
1900 * member of the sub-structure is equal to the aligned offset
1901 * of the structure. The structure may have padding at the end;
1902 * the base offset of the member following the sub-structure is
1903 * rounded up to the next multiple of the base alignment of the
1906 if (this->is_record()) {
1907 unsigned base_alignment
= 0;
1908 for (unsigned i
= 0; i
< this->length
; i
++) {
1909 bool field_row_major
= row_major
;
1910 const enum glsl_matrix_layout matrix_layout
=
1911 glsl_matrix_layout(this->fields
.structure
[i
].matrix_layout
);
1912 if (matrix_layout
== GLSL_MATRIX_LAYOUT_ROW_MAJOR
) {
1913 field_row_major
= true;
1914 } else if (matrix_layout
== GLSL_MATRIX_LAYOUT_COLUMN_MAJOR
) {
1915 field_row_major
= false;
1918 const struct glsl_type
*field_type
= this->fields
.structure
[i
].type
;
1919 base_alignment
= MAX2(base_alignment
,
1920 field_type
->std430_base_alignment(field_row_major
));
1922 assert(base_alignment
> 0);
1923 return base_alignment
;
1925 assert(!"not reached");
1930 glsl_type::std430_array_stride(bool row_major
) const
1932 unsigned N
= is_64bit() ? 8 : 4;
1934 /* Notice that the array stride of a vec3 is not 3 * N but 4 * N.
1935 * See OpenGL 4.30 spec, section 7.6.2.2 "Standard Uniform Block Layout"
1937 * (3) If the member is a three-component vector with components consuming
1938 * <N> basic machine units, the base alignment is 4<N>.
1940 if (this->is_vector() && this->vector_elements
== 3)
1943 /* By default use std430_size(row_major) */
1944 return this->std430_size(row_major
);
1948 glsl_type::std430_size(bool row_major
) const
1950 unsigned N
= is_64bit() ? 8 : 4;
1952 /* OpenGL 4.30 spec, section 7.6.2.2 "Standard Uniform Block Layout":
1954 * "When using the std430 storage layout, shader storage blocks will be
1955 * laid out in buffer storage identically to uniform and shader storage
1956 * blocks using the std140 layout, except that the base alignment and
1957 * stride of arrays of scalars and vectors in rule 4 and of structures
1958 * in rule 9 are not rounded up a multiple of the base alignment of a vec4.
1960 if (this->is_scalar() || this->is_vector())
1961 return this->vector_elements
* N
;
1963 if (this->without_array()->is_matrix()) {
1964 const struct glsl_type
*element_type
;
1965 const struct glsl_type
*vec_type
;
1966 unsigned int array_len
;
1968 if (this->is_array()) {
1969 element_type
= this->without_array();
1970 array_len
= this->arrays_of_arrays_size();
1972 element_type
= this;
1977 vec_type
= get_instance(element_type
->base_type
,
1978 element_type
->matrix_columns
, 1);
1980 array_len
*= element_type
->vector_elements
;
1982 vec_type
= get_instance(element_type
->base_type
,
1983 element_type
->vector_elements
, 1);
1984 array_len
*= element_type
->matrix_columns
;
1986 const glsl_type
*array_type
= glsl_type::get_array_instance(vec_type
,
1989 return array_type
->std430_size(false);
1992 if (this->is_array()) {
1993 if (this->without_array()->is_record())
1994 return this->arrays_of_arrays_size() *
1995 this->without_array()->std430_size(row_major
);
1997 return this->arrays_of_arrays_size() *
1998 this->without_array()->std430_base_alignment(row_major
);
2001 if (this->is_record() || this->is_interface()) {
2003 unsigned max_align
= 0;
2005 for (unsigned i
= 0; i
< this->length
; i
++) {
2006 bool field_row_major
= row_major
;
2007 const enum glsl_matrix_layout matrix_layout
=
2008 glsl_matrix_layout(this->fields
.structure
[i
].matrix_layout
);
2009 if (matrix_layout
== GLSL_MATRIX_LAYOUT_ROW_MAJOR
) {
2010 field_row_major
= true;
2011 } else if (matrix_layout
== GLSL_MATRIX_LAYOUT_COLUMN_MAJOR
) {
2012 field_row_major
= false;
2015 const struct glsl_type
*field_type
= this->fields
.structure
[i
].type
;
2016 unsigned align
= field_type
->std430_base_alignment(field_row_major
);
2017 size
= glsl_align(size
, align
);
2018 size
+= field_type
->std430_size(field_row_major
);
2020 max_align
= MAX2(align
, max_align
);
2022 size
= glsl_align(size
, max_align
);
2026 assert(!"not reached");
2031 glsl_type::count_attribute_slots(bool is_vertex_input
) const
2033 /* From page 31 (page 37 of the PDF) of the GLSL 1.50 spec:
2035 * "A scalar input counts the same amount against this limit as a vec4,
2036 * so applications may want to consider packing groups of four
2037 * unrelated float inputs together into a vector to better utilize the
2038 * capabilities of the underlying hardware. A matrix input will use up
2039 * multiple locations. The number of locations used will equal the
2040 * number of columns in the matrix."
2042 * The spec does not explicitly say how arrays are counted. However, it
2043 * should be safe to assume the total number of slots consumed by an array
2044 * is the number of entries in the array multiplied by the number of slots
2045 * consumed by a single element of the array.
2047 * The spec says nothing about how structs are counted, because vertex
2048 * attributes are not allowed to be (or contain) structs. However, Mesa
2049 * allows varying structs, the number of varying slots taken up by a
2050 * varying struct is simply equal to the sum of the number of slots taken
2051 * up by each element.
2053 * Doubles are counted different depending on whether they are vertex
2054 * inputs or everything else. Vertex inputs from ARB_vertex_attrib_64bit
2055 * take one location no matter what size they are, otherwise dvec3/4
2056 * take two locations.
2058 switch (this->base_type
) {
2059 case GLSL_TYPE_UINT
:
2061 case GLSL_TYPE_UINT16
:
2062 case GLSL_TYPE_INT16
:
2063 case GLSL_TYPE_FLOAT
:
2064 case GLSL_TYPE_FLOAT16
:
2065 case GLSL_TYPE_BOOL
:
2066 case GLSL_TYPE_SAMPLER
:
2067 case GLSL_TYPE_IMAGE
:
2068 return this->matrix_columns
;
2069 case GLSL_TYPE_DOUBLE
:
2070 case GLSL_TYPE_UINT64
:
2071 case GLSL_TYPE_INT64
:
2072 if (this->vector_elements
> 2 && !is_vertex_input
)
2073 return this->matrix_columns
* 2;
2075 return this->matrix_columns
;
2076 case GLSL_TYPE_STRUCT
:
2077 case GLSL_TYPE_INTERFACE
: {
2080 for (unsigned i
= 0; i
< this->length
; i
++)
2081 size
+= this->fields
.structure
[i
].type
->count_attribute_slots(is_vertex_input
);
2086 case GLSL_TYPE_ARRAY
:
2087 return this->length
* this->fields
.array
->count_attribute_slots(is_vertex_input
);
2089 case GLSL_TYPE_SUBROUTINE
:
2092 case GLSL_TYPE_FUNCTION
:
2093 case GLSL_TYPE_ATOMIC_UINT
:
2094 case GLSL_TYPE_VOID
:
2095 case GLSL_TYPE_ERROR
:
2099 assert(!"Unexpected type in count_attribute_slots()");
2105 glsl_type::coordinate_components() const
2109 switch (sampler_dimensionality
) {
2110 case GLSL_SAMPLER_DIM_1D
:
2111 case GLSL_SAMPLER_DIM_BUF
:
2114 case GLSL_SAMPLER_DIM_2D
:
2115 case GLSL_SAMPLER_DIM_RECT
:
2116 case GLSL_SAMPLER_DIM_MS
:
2117 case GLSL_SAMPLER_DIM_EXTERNAL
:
2118 case GLSL_SAMPLER_DIM_SUBPASS
:
2121 case GLSL_SAMPLER_DIM_3D
:
2122 case GLSL_SAMPLER_DIM_CUBE
:
2126 assert(!"Should not get here.");
2131 /* Array textures need an additional component for the array index, except
2132 * for cubemap array images that behave like a 2D array of interleaved
2135 if (sampler_array
&&
2136 !(is_image() && sampler_dimensionality
== GLSL_SAMPLER_DIM_CUBE
))
2143 * Declarations of type flyweights (glsl_type::_foo_type) and
2144 * convenience pointers (glsl_type::foo_type).
2147 #define DECL_TYPE(NAME, ...) \
2148 const glsl_type glsl_type::_##NAME##_type = glsl_type(__VA_ARGS__, #NAME); \
2149 const glsl_type *const glsl_type::NAME##_type = &glsl_type::_##NAME##_type;
2151 #define STRUCT_TYPE(NAME)
2153 #include "compiler/builtin_type_macros.h"
2157 get_struct_type_field_and_pointer_sizes(size_t *s_field_size
,
2158 size_t *s_field_ptrs
)
2160 *s_field_size
= sizeof(glsl_struct_field
);
2162 sizeof(((glsl_struct_field
*)0)->type
) +
2163 sizeof(((glsl_struct_field
*)0)->name
);
2167 encode_type_to_blob(struct blob
*blob
, const glsl_type
*type
)
2172 blob_write_uint32(blob
, 0);
2176 switch (type
->base_type
) {
2177 case GLSL_TYPE_UINT
:
2179 case GLSL_TYPE_FLOAT
:
2180 case GLSL_TYPE_BOOL
:
2181 case GLSL_TYPE_DOUBLE
:
2182 case GLSL_TYPE_UINT64
:
2183 case GLSL_TYPE_INT64
:
2184 encoding
= (type
->base_type
<< 24) |
2185 (type
->vector_elements
<< 4) |
2186 (type
->matrix_columns
);
2188 case GLSL_TYPE_SAMPLER
:
2189 encoding
= (type
->base_type
) << 24 |
2190 (type
->sampler_dimensionality
<< 4) |
2191 (type
->sampler_shadow
<< 3) |
2192 (type
->sampler_array
<< 2) |
2193 (type
->sampled_type
);
2195 case GLSL_TYPE_SUBROUTINE
:
2196 encoding
= type
->base_type
<< 24;
2197 blob_write_uint32(blob
, encoding
);
2198 blob_write_string(blob
, type
->name
);
2200 case GLSL_TYPE_IMAGE
:
2201 encoding
= (type
->base_type
) << 24 |
2202 (type
->sampler_dimensionality
<< 3) |
2203 (type
->sampler_array
<< 2) |
2204 (type
->sampled_type
);
2206 case GLSL_TYPE_ATOMIC_UINT
:
2207 encoding
= (type
->base_type
<< 24);
2209 case GLSL_TYPE_ARRAY
:
2210 blob_write_uint32(blob
, (type
->base_type
) << 24);
2211 blob_write_uint32(blob
, type
->length
);
2212 encode_type_to_blob(blob
, type
->fields
.array
);
2214 case GLSL_TYPE_STRUCT
:
2215 case GLSL_TYPE_INTERFACE
:
2216 blob_write_uint32(blob
, (type
->base_type
) << 24);
2217 blob_write_string(blob
, type
->name
);
2218 blob_write_uint32(blob
, type
->length
);
2220 size_t s_field_size
, s_field_ptrs
;
2221 get_struct_type_field_and_pointer_sizes(&s_field_size
, &s_field_ptrs
);
2223 for (unsigned i
= 0; i
< type
->length
; i
++) {
2224 encode_type_to_blob(blob
, type
->fields
.structure
[i
].type
);
2225 blob_write_string(blob
, type
->fields
.structure
[i
].name
);
2227 /* Write the struct field skipping the pointers */
2228 blob_write_bytes(blob
,
2229 ((char *)&type
->fields
.structure
[i
]) + s_field_ptrs
,
2230 s_field_size
- s_field_ptrs
);
2233 if (type
->is_interface()) {
2234 blob_write_uint32(blob
, type
->interface_packing
);
2235 blob_write_uint32(blob
, type
->interface_row_major
);
2238 case GLSL_TYPE_VOID
:
2239 encoding
= (type
->base_type
<< 24);
2241 case GLSL_TYPE_ERROR
:
2243 assert(!"Cannot encode type!");
2248 blob_write_uint32(blob
, encoding
);
2252 decode_type_from_blob(struct blob_reader
*blob
)
2254 uint32_t u
= blob_read_uint32(blob
);
2260 glsl_base_type base_type
= (glsl_base_type
) (u
>> 24);
2262 switch (base_type
) {
2263 case GLSL_TYPE_UINT
:
2265 case GLSL_TYPE_FLOAT
:
2266 case GLSL_TYPE_BOOL
:
2267 case GLSL_TYPE_DOUBLE
:
2268 case GLSL_TYPE_UINT64
:
2269 case GLSL_TYPE_INT64
:
2270 return glsl_type::get_instance(base_type
, (u
>> 4) & 0x0f, u
& 0x0f);
2271 case GLSL_TYPE_SAMPLER
:
2272 return glsl_type::get_sampler_instance((enum glsl_sampler_dim
) ((u
>> 4) & 0x07),
2275 (glsl_base_type
) ((u
>> 0) & 0x03));
2276 case GLSL_TYPE_SUBROUTINE
:
2277 return glsl_type::get_subroutine_instance(blob_read_string(blob
));
2278 case GLSL_TYPE_IMAGE
:
2279 return glsl_type::get_image_instance((enum glsl_sampler_dim
) ((u
>> 3) & 0x07),
2281 (glsl_base_type
) ((u
>> 0) & 0x03));
2282 case GLSL_TYPE_ATOMIC_UINT
:
2283 return glsl_type::atomic_uint_type
;
2284 case GLSL_TYPE_ARRAY
: {
2285 unsigned length
= blob_read_uint32(blob
);
2286 return glsl_type::get_array_instance(decode_type_from_blob(blob
),
2289 case GLSL_TYPE_STRUCT
:
2290 case GLSL_TYPE_INTERFACE
: {
2291 char *name
= blob_read_string(blob
);
2292 unsigned num_fields
= blob_read_uint32(blob
);
2294 size_t s_field_size
, s_field_ptrs
;
2295 get_struct_type_field_and_pointer_sizes(&s_field_size
, &s_field_ptrs
);
2297 glsl_struct_field
*fields
=
2298 (glsl_struct_field
*) malloc(s_field_size
* num_fields
);
2299 for (unsigned i
= 0; i
< num_fields
; i
++) {
2300 fields
[i
].type
= decode_type_from_blob(blob
);
2301 fields
[i
].name
= blob_read_string(blob
);
2303 blob_copy_bytes(blob
, ((uint8_t *) &fields
[i
]) + s_field_ptrs
,
2304 s_field_size
- s_field_ptrs
);
2308 if (base_type
== GLSL_TYPE_INTERFACE
) {
2309 enum glsl_interface_packing packing
=
2310 (glsl_interface_packing
) blob_read_uint32(blob
);
2311 bool row_major
= blob_read_uint32(blob
);
2312 t
= glsl_type::get_interface_instance(fields
, num_fields
, packing
,
2315 t
= glsl_type::get_record_instance(fields
, num_fields
, name
);
2321 case GLSL_TYPE_VOID
:
2322 return glsl_type::void_type
;
2323 case GLSL_TYPE_ERROR
:
2325 assert(!"Cannot decode type!");