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"
29 #include "util/u_string.h"
32 mtx_t
glsl_type::hash_mutex
= _MTX_INITIALIZER_NP
;
33 hash_table
*glsl_type::explicit_matrix_types
= NULL
;
34 hash_table
*glsl_type::array_types
= NULL
;
35 hash_table
*glsl_type::struct_types
= NULL
;
36 hash_table
*glsl_type::interface_types
= NULL
;
37 hash_table
*glsl_type::function_types
= NULL
;
38 hash_table
*glsl_type::subroutine_types
= NULL
;
40 /* There might be multiple users for types (e.g. application using OpenGL
41 * and Vulkan simultanously or app using multiple Vulkan instances). Counter
42 * is used to make sure we don't release the types if a user is still present.
44 static uint32_t glsl_type_users
= 0;
46 glsl_type::glsl_type(GLenum gl_type
,
47 glsl_base_type base_type
, unsigned vector_elements
,
48 unsigned matrix_columns
, const char *name
,
49 unsigned explicit_stride
, bool row_major
) :
51 base_type(base_type
), sampled_type(GLSL_TYPE_VOID
),
52 sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
53 interface_packing(0), interface_row_major(row_major
), packed(0),
54 vector_elements(vector_elements
), matrix_columns(matrix_columns
),
55 length(0), explicit_stride(explicit_stride
)
57 /* Values of these types must fit in the two bits of
58 * glsl_type::sampled_type.
60 STATIC_ASSERT((unsigned(GLSL_TYPE_UINT
) & 3) == unsigned(GLSL_TYPE_UINT
));
61 STATIC_ASSERT((unsigned(GLSL_TYPE_INT
) & 3) == unsigned(GLSL_TYPE_INT
));
62 STATIC_ASSERT((unsigned(GLSL_TYPE_FLOAT
) & 3) == unsigned(GLSL_TYPE_FLOAT
));
64 ASSERT_BITFIELD_SIZE(glsl_type
, base_type
, GLSL_TYPE_ERROR
);
65 ASSERT_BITFIELD_SIZE(glsl_type
, sampled_type
, GLSL_TYPE_ERROR
);
66 ASSERT_BITFIELD_SIZE(glsl_type
, sampler_dimensionality
,
67 GLSL_SAMPLER_DIM_SUBPASS_MS
);
69 this->mem_ctx
= ralloc_context(NULL
);
70 assert(this->mem_ctx
!= NULL
);
73 this->name
= ralloc_strdup(this->mem_ctx
, name
);
75 /* Neither dimension is zero or both dimensions are zero.
77 assert((vector_elements
== 0) == (matrix_columns
== 0));
78 memset(& fields
, 0, sizeof(fields
));
81 glsl_type::glsl_type(GLenum gl_type
, glsl_base_type base_type
,
82 enum glsl_sampler_dim dim
, bool shadow
, bool array
,
83 glsl_base_type type
, const char *name
) :
85 base_type(base_type
), sampled_type(type
),
86 sampler_dimensionality(dim
), sampler_shadow(shadow
),
87 sampler_array(array
), interface_packing(0),
88 interface_row_major(0), packed(0),
89 length(0), explicit_stride(0)
91 this->mem_ctx
= ralloc_context(NULL
);
92 assert(this->mem_ctx
!= NULL
);
95 this->name
= ralloc_strdup(this->mem_ctx
, name
);
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
,
103 const char *name
, bool packed
) :
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), packed(packed
),
108 vector_elements(0), matrix_columns(0),
109 length(num_fields
), explicit_stride(0)
113 this->mem_ctx
= ralloc_context(NULL
);
114 assert(this->mem_ctx
!= NULL
);
116 assert(name
!= NULL
);
117 this->name
= ralloc_strdup(this->mem_ctx
, name
);
118 /* Zero-fill to prevent spurious Valgrind errors when serializing NIR
119 * due to uninitialized unused bits in bit fields. */
120 this->fields
.structure
= rzalloc_array(this->mem_ctx
,
121 glsl_struct_field
, length
);
123 for (i
= 0; i
< length
; i
++) {
124 this->fields
.structure
[i
] = fields
[i
];
125 this->fields
.structure
[i
].name
= ralloc_strdup(this->fields
.structure
,
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
), packed(0),
138 vector_elements(0), matrix_columns(0),
139 length(num_fields
), explicit_stride(0)
143 this->mem_ctx
= ralloc_context(NULL
);
144 assert(this->mem_ctx
!= NULL
);
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
,
157 glsl_type::glsl_type(const glsl_type
*return_type
,
158 const glsl_function_param
*params
, unsigned num_params
) :
160 base_type(GLSL_TYPE_FUNCTION
), sampled_type(GLSL_TYPE_VOID
),
161 sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
162 interface_packing(0), interface_row_major(0), packed(0),
163 vector_elements(0), matrix_columns(0),
164 length(num_params
), explicit_stride(0)
168 this->mem_ctx
= ralloc_context(NULL
);
169 assert(this->mem_ctx
!= NULL
);
171 this->fields
.parameters
= rzalloc_array(this->mem_ctx
,
172 glsl_function_param
, num_params
+ 1);
174 /* We store the return type as the first parameter */
175 this->fields
.parameters
[0].type
= return_type
;
176 this->fields
.parameters
[0].in
= false;
177 this->fields
.parameters
[0].out
= true;
179 /* We store the i'th parameter in slot i+1 */
180 for (i
= 0; i
< length
; i
++) {
181 this->fields
.parameters
[i
+ 1].type
= params
[i
].type
;
182 this->fields
.parameters
[i
+ 1].in
= params
[i
].in
;
183 this->fields
.parameters
[i
+ 1].out
= params
[i
].out
;
187 glsl_type::glsl_type(const char *subroutine_name
) :
189 base_type(GLSL_TYPE_SUBROUTINE
), sampled_type(GLSL_TYPE_VOID
),
190 sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
191 interface_packing(0), interface_row_major(0), packed(0),
192 vector_elements(1), matrix_columns(1),
193 length(0), explicit_stride(0)
195 this->mem_ctx
= ralloc_context(NULL
);
196 assert(this->mem_ctx
!= NULL
);
198 assert(subroutine_name
!= NULL
);
199 this->name
= ralloc_strdup(this->mem_ctx
, subroutine_name
);
202 glsl_type::~glsl_type()
204 ralloc_free(this->mem_ctx
);
208 glsl_type::contains_sampler() const
210 if (this->is_array()) {
211 return this->fields
.array
->contains_sampler();
212 } else if (this->is_struct() || this->is_interface()) {
213 for (unsigned int i
= 0; i
< this->length
; i
++) {
214 if (this->fields
.structure
[i
].type
->contains_sampler())
219 return this->is_sampler();
224 glsl_type::contains_array() const
226 if (this->is_struct() || this->is_interface()) {
227 for (unsigned int i
= 0; i
< this->length
; i
++) {
228 if (this->fields
.structure
[i
].type
->contains_array())
233 return this->is_array();
238 glsl_type::contains_integer() const
240 if (this->is_array()) {
241 return this->fields
.array
->contains_integer();
242 } else if (this->is_struct() || this->is_interface()) {
243 for (unsigned int i
= 0; i
< this->length
; i
++) {
244 if (this->fields
.structure
[i
].type
->contains_integer())
249 return this->is_integer();
254 glsl_type::contains_double() const
256 if (this->is_array()) {
257 return this->fields
.array
->contains_double();
258 } else if (this->is_struct() || this->is_interface()) {
259 for (unsigned int i
= 0; i
< this->length
; i
++) {
260 if (this->fields
.structure
[i
].type
->contains_double())
265 return this->is_double();
270 glsl_type::contains_64bit() const
272 if (this->is_array()) {
273 return this->fields
.array
->contains_64bit();
274 } else if (this->is_struct() || this->is_interface()) {
275 for (unsigned int i
= 0; i
< this->length
; i
++) {
276 if (this->fields
.structure
[i
].type
->contains_64bit())
281 return this->is_64bit();
286 glsl_type::contains_opaque() const {
288 case GLSL_TYPE_SAMPLER
:
289 case GLSL_TYPE_IMAGE
:
290 case GLSL_TYPE_ATOMIC_UINT
:
292 case GLSL_TYPE_ARRAY
:
293 return fields
.array
->contains_opaque();
294 case GLSL_TYPE_STRUCT
:
295 case GLSL_TYPE_INTERFACE
:
296 for (unsigned int i
= 0; i
< length
; i
++) {
297 if (fields
.structure
[i
].type
->contains_opaque())
307 glsl_type::contains_subroutine() const
309 if (this->is_array()) {
310 return this->fields
.array
->contains_subroutine();
311 } else if (this->is_struct() || this->is_interface()) {
312 for (unsigned int i
= 0; i
< this->length
; i
++) {
313 if (this->fields
.structure
[i
].type
->contains_subroutine())
318 return this->is_subroutine();
323 glsl_type::sampler_index() const
325 const glsl_type
*const t
= (this->is_array()) ? this->fields
.array
: this;
327 assert(t
->is_sampler() || t
->is_image());
329 switch (t
->sampler_dimensionality
) {
330 case GLSL_SAMPLER_DIM_1D
:
331 return (t
->sampler_array
) ? TEXTURE_1D_ARRAY_INDEX
: TEXTURE_1D_INDEX
;
332 case GLSL_SAMPLER_DIM_2D
:
333 return (t
->sampler_array
) ? TEXTURE_2D_ARRAY_INDEX
: TEXTURE_2D_INDEX
;
334 case GLSL_SAMPLER_DIM_3D
:
335 return TEXTURE_3D_INDEX
;
336 case GLSL_SAMPLER_DIM_CUBE
:
337 return (t
->sampler_array
) ? TEXTURE_CUBE_ARRAY_INDEX
: TEXTURE_CUBE_INDEX
;
338 case GLSL_SAMPLER_DIM_RECT
:
339 return TEXTURE_RECT_INDEX
;
340 case GLSL_SAMPLER_DIM_BUF
:
341 return TEXTURE_BUFFER_INDEX
;
342 case GLSL_SAMPLER_DIM_EXTERNAL
:
343 return TEXTURE_EXTERNAL_INDEX
;
344 case GLSL_SAMPLER_DIM_MS
:
345 return (t
->sampler_array
) ? TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
: TEXTURE_2D_MULTISAMPLE_INDEX
;
347 assert(!"Should not get here.");
348 return TEXTURE_BUFFER_INDEX
;
353 glsl_type::contains_image() const
355 if (this->is_array()) {
356 return this->fields
.array
->contains_image();
357 } else if (this->is_struct() || this->is_interface()) {
358 for (unsigned int i
= 0; i
< this->length
; i
++) {
359 if (this->fields
.structure
[i
].type
->contains_image())
364 return this->is_image();
368 const glsl_type
*glsl_type::get_base_type() const
373 case GLSL_TYPE_UINT16
:
374 return uint16_t_type
;
375 case GLSL_TYPE_UINT8
:
379 case GLSL_TYPE_INT16
:
383 case GLSL_TYPE_FLOAT
:
385 case GLSL_TYPE_FLOAT16
:
386 return float16_t_type
;
387 case GLSL_TYPE_DOUBLE
:
391 case GLSL_TYPE_UINT64
:
392 return uint64_t_type
;
393 case GLSL_TYPE_INT64
:
401 const glsl_type
*glsl_type::get_scalar_type() const
403 const glsl_type
*type
= this;
406 while (type
->base_type
== GLSL_TYPE_ARRAY
)
407 type
= type
->fields
.array
;
409 const glsl_type
*scalar_type
= type
->get_base_type();
410 if (scalar_type
== error_type
)
417 const glsl_type
*glsl_type::get_bare_type() const
419 switch (this->base_type
) {
420 case GLSL_TYPE_UINT8
:
422 case GLSL_TYPE_UINT16
:
423 case GLSL_TYPE_INT16
:
424 case GLSL_TYPE_FLOAT16
:
427 case GLSL_TYPE_FLOAT
:
429 case GLSL_TYPE_DOUBLE
:
430 case GLSL_TYPE_UINT64
:
431 case GLSL_TYPE_INT64
:
432 return get_instance(this->base_type
, this->vector_elements
,
433 this->matrix_columns
);
435 case GLSL_TYPE_STRUCT
:
436 case GLSL_TYPE_INTERFACE
: {
437 glsl_struct_field
*bare_fields
= new glsl_struct_field
[this->length
];
438 for (unsigned i
= 0; i
< this->length
; i
++) {
439 bare_fields
[i
].type
= this->fields
.structure
[i
].type
->get_bare_type();
440 bare_fields
[i
].name
= this->fields
.structure
[i
].name
;
442 const glsl_type
*bare_type
=
443 get_struct_instance(bare_fields
, this->length
, this->name
);
444 delete[] bare_fields
;
448 case GLSL_TYPE_ARRAY
:
449 return get_array_instance(this->fields
.array
->get_bare_type(),
452 case GLSL_TYPE_SAMPLER
:
453 case GLSL_TYPE_IMAGE
:
454 case GLSL_TYPE_ATOMIC_UINT
:
456 case GLSL_TYPE_SUBROUTINE
:
457 case GLSL_TYPE_FUNCTION
:
458 case GLSL_TYPE_ERROR
:
462 unreachable("Invalid base type");
465 const glsl_type
*glsl_type::get_float16_type() const
467 assert(this->base_type
== GLSL_TYPE_FLOAT
);
469 return get_instance(GLSL_TYPE_FLOAT16
,
470 this->vector_elements
,
471 this->matrix_columns
,
472 this->explicit_stride
,
473 this->interface_row_major
);
477 hash_free_type_function(struct hash_entry
*entry
)
479 glsl_type
*type
= (glsl_type
*) entry
->data
;
481 if (type
->is_array())
482 free((void*)entry
->key
);
488 glsl_type_singleton_init_or_ref()
490 mtx_lock(&glsl_type::hash_mutex
);
492 mtx_unlock(&glsl_type::hash_mutex
);
496 glsl_type_singleton_decref()
498 mtx_lock(&glsl_type::hash_mutex
);
499 assert(glsl_type_users
> 0);
501 /* Do not release glsl_types if they are still used. */
502 if (--glsl_type_users
) {
503 mtx_unlock(&glsl_type::hash_mutex
);
507 if (glsl_type::explicit_matrix_types
!= NULL
) {
508 _mesa_hash_table_destroy(glsl_type::explicit_matrix_types
,
509 hash_free_type_function
);
510 glsl_type::explicit_matrix_types
= NULL
;
513 if (glsl_type::array_types
!= NULL
) {
514 _mesa_hash_table_destroy(glsl_type::array_types
, hash_free_type_function
);
515 glsl_type::array_types
= NULL
;
518 if (glsl_type::struct_types
!= NULL
) {
519 _mesa_hash_table_destroy(glsl_type::struct_types
, hash_free_type_function
);
520 glsl_type::struct_types
= NULL
;
523 if (glsl_type::interface_types
!= NULL
) {
524 _mesa_hash_table_destroy(glsl_type::interface_types
, hash_free_type_function
);
525 glsl_type::interface_types
= NULL
;
528 if (glsl_type::function_types
!= NULL
) {
529 _mesa_hash_table_destroy(glsl_type::function_types
, hash_free_type_function
);
530 glsl_type::function_types
= NULL
;
533 if (glsl_type::subroutine_types
!= NULL
) {
534 _mesa_hash_table_destroy(glsl_type::subroutine_types
, hash_free_type_function
);
535 glsl_type::subroutine_types
= NULL
;
538 mtx_unlock(&glsl_type::hash_mutex
);
542 glsl_type::glsl_type(const glsl_type
*array
, unsigned length
,
543 unsigned explicit_stride
) :
544 base_type(GLSL_TYPE_ARRAY
), sampled_type(GLSL_TYPE_VOID
),
545 sampler_dimensionality(0), sampler_shadow(0), sampler_array(0),
546 interface_packing(0), interface_row_major(0), packed(0),
547 vector_elements(0), matrix_columns(0),
548 length(length
), name(NULL
), explicit_stride(explicit_stride
)
550 this->fields
.array
= array
;
551 /* Inherit the gl type of the base. The GL type is used for
552 * uniform/statevar handling in Mesa and the arrayness of the type
553 * is represented by the size rather than the type.
555 this->gl_type
= array
->gl_type
;
557 /* Allow a maximum of 10 characters for the array size. This is enough
558 * for 32-bits of ~0. The extra 3 are for the '[', ']', and terminating
561 const unsigned name_length
= strlen(array
->name
) + 10 + 3;
563 this->mem_ctx
= ralloc_context(NULL
);
564 assert(this->mem_ctx
!= NULL
);
566 char *const n
= (char *) ralloc_size(this->mem_ctx
, name_length
);
569 snprintf(n
, name_length
, "%s[]", array
->name
);
571 /* insert outermost dimensions in the correct spot
572 * otherwise the dimension order will be backwards
574 const char *pos
= strchr(array
->name
, '[');
576 int idx
= pos
- array
->name
;
577 snprintf(n
, idx
+1, "%s", array
->name
);
578 snprintf(n
+ idx
, name_length
- idx
, "[%u]%s",
579 length
, array
->name
+ idx
);
581 snprintf(n
, name_length
, "%s[%u]", array
->name
, length
);
589 glsl_type::vec(unsigned components
, const glsl_type
*const ts
[])
591 unsigned n
= components
;
595 else if (components
== 16)
604 #define VECN(components, sname, vname) \
606 glsl_type:: vname (unsigned components) \
608 static const glsl_type *const ts[] = { \
609 sname ## _type, vname ## 2_type, \
610 vname ## 3_type, vname ## 4_type, \
611 vname ## 8_type, vname ## 16_type, \
613 return glsl_type::vec(components, ts); \
616 VECN(components
, float, vec
)
617 VECN(components
, float16_t
, f16vec
)
618 VECN(components
, double, dvec
)
619 VECN(components
, int, ivec
)
620 VECN(components
, uint
, uvec
)
621 VECN(components
, bool, bvec
)
622 VECN(components
, int64_t, i64vec
)
623 VECN(components
, uint64_t, u64vec
)
624 VECN(components
, int16_t, i16vec
)
625 VECN(components
, uint16_t, u16vec
)
626 VECN(components
, int8_t, i8vec
)
627 VECN(components
, uint8_t, u8vec
)
630 glsl_type::get_instance(unsigned base_type
, unsigned rows
, unsigned columns
,
631 unsigned explicit_stride
, bool row_major
)
633 if (base_type
== GLSL_TYPE_VOID
) {
634 assert(explicit_stride
== 0 && !row_major
);
638 /* Matrix and vector types with explicit strides have to be looked up in a
639 * table so they're handled separately.
641 if (explicit_stride
> 0) {
642 const glsl_type
*bare_type
= get_instance(base_type
, rows
, columns
);
644 assert(columns
> 1 || !row_major
);
647 snprintf(name
, sizeof(name
), "%sx%uB%s", bare_type
->name
,
648 explicit_stride
, row_major
? "RM" : "");
650 mtx_lock(&glsl_type::hash_mutex
);
651 assert(glsl_type_users
> 0);
653 if (explicit_matrix_types
== NULL
) {
654 explicit_matrix_types
=
655 _mesa_hash_table_create(NULL
, _mesa_hash_string
,
656 _mesa_key_string_equal
);
659 const struct hash_entry
*entry
=
660 _mesa_hash_table_search(explicit_matrix_types
, name
);
662 const glsl_type
*t
= new glsl_type(bare_type
->gl_type
,
663 (glsl_base_type
)base_type
,
665 explicit_stride
, row_major
);
667 entry
= _mesa_hash_table_insert(explicit_matrix_types
,
671 assert(((glsl_type
*) entry
->data
)->base_type
== base_type
);
672 assert(((glsl_type
*) entry
->data
)->vector_elements
== rows
);
673 assert(((glsl_type
*) entry
->data
)->matrix_columns
== columns
);
674 assert(((glsl_type
*) entry
->data
)->explicit_stride
== explicit_stride
);
676 const glsl_type
*t
= (const glsl_type
*) entry
->data
;
678 mtx_unlock(&glsl_type::hash_mutex
);
685 /* Treat GLSL vectors as Nx1 matrices.
693 case GLSL_TYPE_FLOAT
:
695 case GLSL_TYPE_FLOAT16
:
697 case GLSL_TYPE_DOUBLE
:
701 case GLSL_TYPE_UINT64
:
703 case GLSL_TYPE_INT64
:
705 case GLSL_TYPE_UINT16
:
707 case GLSL_TYPE_INT16
:
709 case GLSL_TYPE_UINT8
:
717 if ((base_type
!= GLSL_TYPE_FLOAT
&&
718 base_type
!= GLSL_TYPE_DOUBLE
&&
719 base_type
!= GLSL_TYPE_FLOAT16
) || (rows
== 1))
722 /* GLSL matrix types are named mat{COLUMNS}x{ROWS}. Only the following
723 * combinations are valid:
731 #define IDX(c,r) (((c-1)*3) + (r-1))
734 case GLSL_TYPE_DOUBLE
: {
735 switch (IDX(columns
, rows
)) {
736 case IDX(2,2): return dmat2_type
;
737 case IDX(2,3): return dmat2x3_type
;
738 case IDX(2,4): return dmat2x4_type
;
739 case IDX(3,2): return dmat3x2_type
;
740 case IDX(3,3): return dmat3_type
;
741 case IDX(3,4): return dmat3x4_type
;
742 case IDX(4,2): return dmat4x2_type
;
743 case IDX(4,3): return dmat4x3_type
;
744 case IDX(4,4): return dmat4_type
;
745 default: return error_type
;
748 case GLSL_TYPE_FLOAT
: {
749 switch (IDX(columns
, rows
)) {
750 case IDX(2,2): return mat2_type
;
751 case IDX(2,3): return mat2x3_type
;
752 case IDX(2,4): return mat2x4_type
;
753 case IDX(3,2): return mat3x2_type
;
754 case IDX(3,3): return mat3_type
;
755 case IDX(3,4): return mat3x4_type
;
756 case IDX(4,2): return mat4x2_type
;
757 case IDX(4,3): return mat4x3_type
;
758 case IDX(4,4): return mat4_type
;
759 default: return error_type
;
762 case GLSL_TYPE_FLOAT16
: {
763 switch (IDX(columns
, rows
)) {
764 case IDX(2,2): return f16mat2_type
;
765 case IDX(2,3): return f16mat2x3_type
;
766 case IDX(2,4): return f16mat2x4_type
;
767 case IDX(3,2): return f16mat3x2_type
;
768 case IDX(3,3): return f16mat3_type
;
769 case IDX(3,4): return f16mat3x4_type
;
770 case IDX(4,2): return f16mat4x2_type
;
771 case IDX(4,3): return f16mat4x3_type
;
772 case IDX(4,4): return f16mat4_type
;
773 default: return error_type
;
776 default: return error_type
;
780 assert(!"Should not get here.");
785 glsl_type::get_sampler_instance(enum glsl_sampler_dim dim
,
791 case GLSL_TYPE_FLOAT
:
793 case GLSL_SAMPLER_DIM_1D
:
795 return (array
? sampler1DArrayShadow_type
: sampler1DShadow_type
);
797 return (array
? sampler1DArray_type
: sampler1D_type
);
798 case GLSL_SAMPLER_DIM_2D
:
800 return (array
? sampler2DArrayShadow_type
: sampler2DShadow_type
);
802 return (array
? sampler2DArray_type
: sampler2D_type
);
803 case GLSL_SAMPLER_DIM_3D
:
807 return sampler3D_type
;
808 case GLSL_SAMPLER_DIM_CUBE
:
810 return (array
? samplerCubeArrayShadow_type
: samplerCubeShadow_type
);
812 return (array
? samplerCubeArray_type
: samplerCube_type
);
813 case GLSL_SAMPLER_DIM_RECT
:
817 return sampler2DRectShadow_type
;
819 return sampler2DRect_type
;
820 case GLSL_SAMPLER_DIM_BUF
:
824 return samplerBuffer_type
;
825 case GLSL_SAMPLER_DIM_MS
:
828 return (array
? sampler2DMSArray_type
: sampler2DMS_type
);
829 case GLSL_SAMPLER_DIM_EXTERNAL
:
833 return samplerExternalOES_type
;
834 case GLSL_SAMPLER_DIM_SUBPASS
:
835 case GLSL_SAMPLER_DIM_SUBPASS_MS
:
842 case GLSL_SAMPLER_DIM_1D
:
843 return (array
? isampler1DArray_type
: isampler1D_type
);
844 case GLSL_SAMPLER_DIM_2D
:
845 return (array
? isampler2DArray_type
: isampler2D_type
);
846 case GLSL_SAMPLER_DIM_3D
:
849 return isampler3D_type
;
850 case GLSL_SAMPLER_DIM_CUBE
:
851 return (array
? isamplerCubeArray_type
: isamplerCube_type
);
852 case GLSL_SAMPLER_DIM_RECT
:
855 return isampler2DRect_type
;
856 case GLSL_SAMPLER_DIM_BUF
:
859 return isamplerBuffer_type
;
860 case GLSL_SAMPLER_DIM_MS
:
861 return (array
? isampler2DMSArray_type
: isampler2DMS_type
);
862 case GLSL_SAMPLER_DIM_EXTERNAL
:
864 case GLSL_SAMPLER_DIM_SUBPASS
:
865 case GLSL_SAMPLER_DIM_SUBPASS_MS
:
872 case GLSL_SAMPLER_DIM_1D
:
873 return (array
? usampler1DArray_type
: usampler1D_type
);
874 case GLSL_SAMPLER_DIM_2D
:
875 return (array
? usampler2DArray_type
: usampler2D_type
);
876 case GLSL_SAMPLER_DIM_3D
:
879 return usampler3D_type
;
880 case GLSL_SAMPLER_DIM_CUBE
:
881 return (array
? usamplerCubeArray_type
: usamplerCube_type
);
882 case GLSL_SAMPLER_DIM_RECT
:
885 return usampler2DRect_type
;
886 case GLSL_SAMPLER_DIM_BUF
:
889 return usamplerBuffer_type
;
890 case GLSL_SAMPLER_DIM_MS
:
891 return (array
? usampler2DMSArray_type
: usampler2DMS_type
);
892 case GLSL_SAMPLER_DIM_EXTERNAL
:
894 case GLSL_SAMPLER_DIM_SUBPASS
:
895 case GLSL_SAMPLER_DIM_SUBPASS_MS
:
902 unreachable("switch statement above should be complete");
906 glsl_type::get_image_instance(enum glsl_sampler_dim dim
,
907 bool array
, glsl_base_type type
)
910 case GLSL_TYPE_FLOAT
:
912 case GLSL_SAMPLER_DIM_1D
:
913 return (array
? image1DArray_type
: image1D_type
);
914 case GLSL_SAMPLER_DIM_2D
:
915 return (array
? image2DArray_type
: image2D_type
);
916 case GLSL_SAMPLER_DIM_3D
:
918 case GLSL_SAMPLER_DIM_CUBE
:
919 return (array
? imageCubeArray_type
: imageCube_type
);
920 case GLSL_SAMPLER_DIM_RECT
:
924 return image2DRect_type
;
925 case GLSL_SAMPLER_DIM_BUF
:
929 return imageBuffer_type
;
930 case GLSL_SAMPLER_DIM_MS
:
931 return (array
? image2DMSArray_type
: image2DMS_type
);
932 case GLSL_SAMPLER_DIM_SUBPASS
:
933 return subpassInput_type
;
934 case GLSL_SAMPLER_DIM_SUBPASS_MS
:
935 return subpassInputMS_type
;
936 case GLSL_SAMPLER_DIM_EXTERNAL
:
941 case GLSL_SAMPLER_DIM_1D
:
942 return (array
? iimage1DArray_type
: iimage1D_type
);
943 case GLSL_SAMPLER_DIM_2D
:
944 return (array
? iimage2DArray_type
: iimage2D_type
);
945 case GLSL_SAMPLER_DIM_3D
:
948 return iimage3D_type
;
949 case GLSL_SAMPLER_DIM_CUBE
:
950 return (array
? iimageCubeArray_type
: iimageCube_type
);
951 case GLSL_SAMPLER_DIM_RECT
:
954 return iimage2DRect_type
;
955 case GLSL_SAMPLER_DIM_BUF
:
958 return iimageBuffer_type
;
959 case GLSL_SAMPLER_DIM_MS
:
960 return (array
? iimage2DMSArray_type
: iimage2DMS_type
);
961 case GLSL_SAMPLER_DIM_SUBPASS
:
962 return isubpassInput_type
;
963 case GLSL_SAMPLER_DIM_SUBPASS_MS
:
964 return isubpassInputMS_type
;
965 case GLSL_SAMPLER_DIM_EXTERNAL
:
970 case GLSL_SAMPLER_DIM_1D
:
971 return (array
? uimage1DArray_type
: uimage1D_type
);
972 case GLSL_SAMPLER_DIM_2D
:
973 return (array
? uimage2DArray_type
: uimage2D_type
);
974 case GLSL_SAMPLER_DIM_3D
:
977 return uimage3D_type
;
978 case GLSL_SAMPLER_DIM_CUBE
:
979 return (array
? uimageCubeArray_type
: uimageCube_type
);
980 case GLSL_SAMPLER_DIM_RECT
:
983 return uimage2DRect_type
;
984 case GLSL_SAMPLER_DIM_BUF
:
987 return uimageBuffer_type
;
988 case GLSL_SAMPLER_DIM_MS
:
989 return (array
? uimage2DMSArray_type
: uimage2DMS_type
);
990 case GLSL_SAMPLER_DIM_SUBPASS
:
991 return usubpassInput_type
;
992 case GLSL_SAMPLER_DIM_SUBPASS_MS
:
993 return usubpassInputMS_type
;
994 case GLSL_SAMPLER_DIM_EXTERNAL
:
1001 unreachable("switch statement above should be complete");
1005 glsl_type::get_array_instance(const glsl_type
*base
,
1006 unsigned array_size
,
1007 unsigned explicit_stride
)
1009 /* Generate a name using the base type pointer in the key. This is
1010 * done because the name of the base type may not be unique across
1011 * shaders. For example, two shaders may have different record types
1015 snprintf(key
, sizeof(key
), "%p[%u]x%uB", (void *) base
, array_size
,
1018 mtx_lock(&glsl_type::hash_mutex
);
1019 assert(glsl_type_users
> 0);
1021 if (array_types
== NULL
) {
1022 array_types
= _mesa_hash_table_create(NULL
, _mesa_hash_string
,
1023 _mesa_key_string_equal
);
1026 const struct hash_entry
*entry
= _mesa_hash_table_search(array_types
, key
);
1027 if (entry
== NULL
) {
1028 const glsl_type
*t
= new glsl_type(base
, array_size
, explicit_stride
);
1030 entry
= _mesa_hash_table_insert(array_types
,
1035 assert(((glsl_type
*) entry
->data
)->base_type
== GLSL_TYPE_ARRAY
);
1036 assert(((glsl_type
*) entry
->data
)->length
== array_size
);
1037 assert(((glsl_type
*) entry
->data
)->fields
.array
== base
);
1039 glsl_type
*t
= (glsl_type
*) entry
->data
;
1041 mtx_unlock(&glsl_type::hash_mutex
);
1047 glsl_type::compare_no_precision(const glsl_type
*b
) const
1052 if (this->is_array()) {
1053 if (!b
->is_array() || this->length
!= b
->length
)
1056 const glsl_type
*b_no_array
= b
->fields
.array
;
1058 return this->fields
.array
->compare_no_precision(b_no_array
);
1061 if (this->is_struct()) {
1062 if (!b
->is_struct())
1064 } else if (this->is_interface()) {
1065 if (!b
->is_interface())
1071 return record_compare(b
,
1072 true, /* match_name */
1073 true, /* match_locations */
1074 false /* match_precision */);
1078 glsl_type::record_compare(const glsl_type
*b
, bool match_name
,
1079 bool match_locations
, bool match_precision
) const
1081 if (this->length
!= b
->length
)
1084 if (this->interface_packing
!= b
->interface_packing
)
1087 if (this->interface_row_major
!= b
->interface_row_major
)
1090 /* From the GLSL 4.20 specification (Sec 4.2):
1092 * "Structures must have the same name, sequence of type names, and
1093 * type definitions, and field names to be considered the same type."
1095 * GLSL ES behaves the same (Ver 1.00 Sec 4.2.4, Ver 3.00 Sec 4.2.5).
1097 * Section 7.4.1 (Shader Interface Matching) of the OpenGL 4.30 spec says:
1099 * "Variables or block members declared as structures are considered
1100 * to match in type if and only if structure members match in name,
1101 * type, qualification, and declaration order."
1104 if (strcmp(this->name
, b
->name
) != 0)
1107 for (unsigned i
= 0; i
< this->length
; i
++) {
1108 if (match_precision
) {
1109 if (this->fields
.structure
[i
].type
!= b
->fields
.structure
[i
].type
)
1112 const glsl_type
*ta
= this->fields
.structure
[i
].type
;
1113 const glsl_type
*tb
= b
->fields
.structure
[i
].type
;
1114 if (!ta
->compare_no_precision(tb
))
1117 if (strcmp(this->fields
.structure
[i
].name
,
1118 b
->fields
.structure
[i
].name
) != 0)
1120 if (this->fields
.structure
[i
].matrix_layout
1121 != b
->fields
.structure
[i
].matrix_layout
)
1123 if (match_locations
&& this->fields
.structure
[i
].location
1124 != b
->fields
.structure
[i
].location
)
1126 if (this->fields
.structure
[i
].offset
1127 != b
->fields
.structure
[i
].offset
)
1129 if (this->fields
.structure
[i
].interpolation
1130 != b
->fields
.structure
[i
].interpolation
)
1132 if (this->fields
.structure
[i
].centroid
1133 != b
->fields
.structure
[i
].centroid
)
1135 if (this->fields
.structure
[i
].sample
1136 != b
->fields
.structure
[i
].sample
)
1138 if (this->fields
.structure
[i
].patch
1139 != b
->fields
.structure
[i
].patch
)
1141 if (this->fields
.structure
[i
].memory_read_only
1142 != b
->fields
.structure
[i
].memory_read_only
)
1144 if (this->fields
.structure
[i
].memory_write_only
1145 != b
->fields
.structure
[i
].memory_write_only
)
1147 if (this->fields
.structure
[i
].memory_coherent
1148 != b
->fields
.structure
[i
].memory_coherent
)
1150 if (this->fields
.structure
[i
].memory_volatile
1151 != b
->fields
.structure
[i
].memory_volatile
)
1153 if (this->fields
.structure
[i
].memory_restrict
1154 != b
->fields
.structure
[i
].memory_restrict
)
1156 if (this->fields
.structure
[i
].image_format
1157 != b
->fields
.structure
[i
].image_format
)
1159 if (match_precision
&&
1160 this->fields
.structure
[i
].precision
1161 != b
->fields
.structure
[i
].precision
)
1163 if (this->fields
.structure
[i
].explicit_xfb_buffer
1164 != b
->fields
.structure
[i
].explicit_xfb_buffer
)
1166 if (this->fields
.structure
[i
].xfb_buffer
1167 != b
->fields
.structure
[i
].xfb_buffer
)
1169 if (this->fields
.structure
[i
].xfb_stride
1170 != b
->fields
.structure
[i
].xfb_stride
)
1179 glsl_type::record_key_compare(const void *a
, const void *b
)
1181 const glsl_type
*const key1
= (glsl_type
*) a
;
1182 const glsl_type
*const key2
= (glsl_type
*) b
;
1184 return strcmp(key1
->name
, key2
->name
) == 0 &&
1185 key1
->record_compare(key2
, true);
1190 * Generate an integer hash value for a glsl_type structure type.
1193 glsl_type::record_key_hash(const void *a
)
1195 const glsl_type
*const key
= (glsl_type
*) a
;
1196 uintptr_t hash
= key
->length
;
1199 for (unsigned i
= 0; i
< key
->length
; i
++) {
1200 /* casting pointer to uintptr_t */
1201 hash
= (hash
* 13 ) + (uintptr_t) key
->fields
.structure
[i
].type
;
1204 if (sizeof(hash
) == 8)
1205 retval
= (hash
& 0xffffffff) ^ ((uint64_t) hash
>> 32);
1214 glsl_type::get_struct_instance(const glsl_struct_field
*fields
,
1215 unsigned num_fields
,
1219 const glsl_type
key(fields
, num_fields
, name
, packed
);
1221 mtx_lock(&glsl_type::hash_mutex
);
1222 assert(glsl_type_users
> 0);
1224 if (struct_types
== NULL
) {
1225 struct_types
= _mesa_hash_table_create(NULL
, record_key_hash
,
1226 record_key_compare
);
1229 const struct hash_entry
*entry
= _mesa_hash_table_search(struct_types
,
1231 if (entry
== NULL
) {
1232 const glsl_type
*t
= new glsl_type(fields
, num_fields
, name
, packed
);
1234 entry
= _mesa_hash_table_insert(struct_types
, t
, (void *) t
);
1237 assert(((glsl_type
*) entry
->data
)->base_type
== GLSL_TYPE_STRUCT
);
1238 assert(((glsl_type
*) entry
->data
)->length
== num_fields
);
1239 assert(strcmp(((glsl_type
*) entry
->data
)->name
, name
) == 0);
1240 assert(((glsl_type
*) entry
->data
)->packed
== packed
);
1242 glsl_type
*t
= (glsl_type
*) entry
->data
;
1244 mtx_unlock(&glsl_type::hash_mutex
);
1251 glsl_type::get_interface_instance(const glsl_struct_field
*fields
,
1252 unsigned num_fields
,
1253 enum glsl_interface_packing packing
,
1255 const char *block_name
)
1257 const glsl_type
key(fields
, num_fields
, packing
, row_major
, block_name
);
1259 mtx_lock(&glsl_type::hash_mutex
);
1260 assert(glsl_type_users
> 0);
1262 if (interface_types
== NULL
) {
1263 interface_types
= _mesa_hash_table_create(NULL
, record_key_hash
,
1264 record_key_compare
);
1267 const struct hash_entry
*entry
= _mesa_hash_table_search(interface_types
,
1269 if (entry
== NULL
) {
1270 const glsl_type
*t
= new glsl_type(fields
, num_fields
,
1271 packing
, row_major
, block_name
);
1273 entry
= _mesa_hash_table_insert(interface_types
, t
, (void *) t
);
1276 assert(((glsl_type
*) entry
->data
)->base_type
== GLSL_TYPE_INTERFACE
);
1277 assert(((glsl_type
*) entry
->data
)->length
== num_fields
);
1278 assert(strcmp(((glsl_type
*) entry
->data
)->name
, block_name
) == 0);
1280 glsl_type
*t
= (glsl_type
*) entry
->data
;
1282 mtx_unlock(&glsl_type::hash_mutex
);
1288 glsl_type::get_subroutine_instance(const char *subroutine_name
)
1290 const glsl_type
key(subroutine_name
);
1292 mtx_lock(&glsl_type::hash_mutex
);
1293 assert(glsl_type_users
> 0);
1295 if (subroutine_types
== NULL
) {
1296 subroutine_types
= _mesa_hash_table_create(NULL
, record_key_hash
,
1297 record_key_compare
);
1300 const struct hash_entry
*entry
= _mesa_hash_table_search(subroutine_types
,
1302 if (entry
== NULL
) {
1303 const glsl_type
*t
= new glsl_type(subroutine_name
);
1305 entry
= _mesa_hash_table_insert(subroutine_types
, t
, (void *) t
);
1308 assert(((glsl_type
*) entry
->data
)->base_type
== GLSL_TYPE_SUBROUTINE
);
1309 assert(strcmp(((glsl_type
*) entry
->data
)->name
, subroutine_name
) == 0);
1311 glsl_type
*t
= (glsl_type
*) entry
->data
;
1313 mtx_unlock(&glsl_type::hash_mutex
);
1320 function_key_compare(const void *a
, const void *b
)
1322 const glsl_type
*const key1
= (glsl_type
*) a
;
1323 const glsl_type
*const key2
= (glsl_type
*) b
;
1325 if (key1
->length
!= key2
->length
)
1328 return memcmp(key1
->fields
.parameters
, key2
->fields
.parameters
,
1329 (key1
->length
+ 1) * sizeof(*key1
->fields
.parameters
)) == 0;
1334 function_key_hash(const void *a
)
1336 const glsl_type
*const key
= (glsl_type
*) a
;
1337 return _mesa_hash_data(key
->fields
.parameters
,
1338 (key
->length
+ 1) * sizeof(*key
->fields
.parameters
));
1342 glsl_type::get_function_instance(const glsl_type
*return_type
,
1343 const glsl_function_param
*params
,
1344 unsigned num_params
)
1346 const glsl_type
key(return_type
, params
, num_params
);
1348 mtx_lock(&glsl_type::hash_mutex
);
1349 assert(glsl_type_users
> 0);
1351 if (function_types
== NULL
) {
1352 function_types
= _mesa_hash_table_create(NULL
, function_key_hash
,
1353 function_key_compare
);
1356 struct hash_entry
*entry
= _mesa_hash_table_search(function_types
, &key
);
1357 if (entry
== NULL
) {
1358 const glsl_type
*t
= new glsl_type(return_type
, params
, num_params
);
1360 entry
= _mesa_hash_table_insert(function_types
, t
, (void *) t
);
1363 const glsl_type
*t
= (const glsl_type
*)entry
->data
;
1365 assert(t
->base_type
== GLSL_TYPE_FUNCTION
);
1366 assert(t
->length
== num_params
);
1368 mtx_unlock(&glsl_type::hash_mutex
);
1375 glsl_type::get_mul_type(const glsl_type
*type_a
, const glsl_type
*type_b
)
1377 if (type_a
->is_matrix() && type_b
->is_matrix()) {
1378 /* Matrix multiply. The columns of A must match the rows of B. Given
1379 * the other previously tested constraints, this means the vector type
1380 * of a row from A must be the same as the vector type of a column from
1383 if (type_a
->row_type() == type_b
->column_type()) {
1384 /* The resulting matrix has the number of columns of matrix B and
1385 * the number of rows of matrix A. We get the row count of A by
1386 * looking at the size of a vector that makes up a column. The
1387 * transpose (size of a row) is done for B.
1389 const glsl_type
*const type
=
1390 get_instance(type_a
->base_type
,
1391 type_a
->column_type()->vector_elements
,
1392 type_b
->row_type()->vector_elements
);
1393 assert(type
!= error_type
);
1397 } else if (type_a
== type_b
) {
1399 } else if (type_a
->is_matrix()) {
1400 /* A is a matrix and B is a column vector. Columns of A must match
1401 * rows of B. Given the other previously tested constraints, this
1402 * means the vector type of a row from A must be the same as the
1403 * vector the type of B.
1405 if (type_a
->row_type() == type_b
) {
1406 /* The resulting vector has a number of elements equal to
1407 * the number of rows of matrix A. */
1408 const glsl_type
*const type
=
1409 get_instance(type_a
->base_type
,
1410 type_a
->column_type()->vector_elements
,
1412 assert(type
!= error_type
);
1417 assert(type_b
->is_matrix());
1419 /* A is a row vector and B is a matrix. Columns of A must match rows
1420 * of B. Given the other previously tested constraints, this means
1421 * the type of A must be the same as the vector type of a column from
1424 if (type_a
== type_b
->column_type()) {
1425 /* The resulting vector has a number of elements equal to
1426 * the number of columns of matrix B. */
1427 const glsl_type
*const type
=
1428 get_instance(type_a
->base_type
,
1429 type_b
->row_type()->vector_elements
,
1431 assert(type
!= error_type
);
1442 glsl_type::field_type(const char *name
) const
1444 if (this->base_type
!= GLSL_TYPE_STRUCT
1445 && this->base_type
!= GLSL_TYPE_INTERFACE
)
1448 for (unsigned i
= 0; i
< this->length
; i
++) {
1449 if (strcmp(name
, this->fields
.structure
[i
].name
) == 0)
1450 return this->fields
.structure
[i
].type
;
1458 glsl_type::field_index(const char *name
) const
1460 if (this->base_type
!= GLSL_TYPE_STRUCT
1461 && this->base_type
!= GLSL_TYPE_INTERFACE
)
1464 for (unsigned i
= 0; i
< this->length
; i
++) {
1465 if (strcmp(name
, this->fields
.structure
[i
].name
) == 0)
1474 glsl_type::component_slots() const
1476 switch (this->base_type
) {
1477 case GLSL_TYPE_UINT
:
1479 case GLSL_TYPE_UINT8
:
1480 case GLSL_TYPE_INT8
:
1481 case GLSL_TYPE_UINT16
:
1482 case GLSL_TYPE_INT16
:
1483 case GLSL_TYPE_FLOAT
:
1484 case GLSL_TYPE_FLOAT16
:
1485 case GLSL_TYPE_BOOL
:
1486 return this->components();
1488 case GLSL_TYPE_DOUBLE
:
1489 case GLSL_TYPE_UINT64
:
1490 case GLSL_TYPE_INT64
:
1491 return 2 * this->components();
1493 case GLSL_TYPE_STRUCT
:
1494 case GLSL_TYPE_INTERFACE
: {
1497 for (unsigned i
= 0; i
< this->length
; i
++)
1498 size
+= this->fields
.structure
[i
].type
->component_slots();
1503 case GLSL_TYPE_ARRAY
:
1504 return this->length
* this->fields
.array
->component_slots();
1506 case GLSL_TYPE_SAMPLER
:
1507 case GLSL_TYPE_IMAGE
:
1510 case GLSL_TYPE_SUBROUTINE
:
1513 case GLSL_TYPE_FUNCTION
:
1514 case GLSL_TYPE_ATOMIC_UINT
:
1515 case GLSL_TYPE_VOID
:
1516 case GLSL_TYPE_ERROR
:
1524 glsl_type::struct_location_offset(unsigned length
) const
1526 unsigned offset
= 0;
1527 const glsl_type
*t
= this->without_array();
1528 if (t
->is_struct()) {
1529 assert(length
<= t
->length
);
1531 for (unsigned i
= 0; i
< length
; i
++) {
1532 const glsl_type
*st
= t
->fields
.structure
[i
].type
;
1533 const glsl_type
*wa
= st
->without_array();
1534 if (wa
->is_struct()) {
1535 unsigned r_offset
= wa
->struct_location_offset(wa
->length
);
1536 offset
+= st
->is_array() ?
1537 st
->arrays_of_arrays_size() * r_offset
: r_offset
;
1538 } else if (st
->is_array() && st
->fields
.array
->is_array()) {
1539 unsigned outer_array_size
= st
->length
;
1540 const glsl_type
*base_type
= st
->fields
.array
;
1542 /* For arrays of arrays the outer arrays take up a uniform
1543 * slot for each element. The innermost array elements share a
1544 * single slot so we ignore the innermost array when calculating
1547 while (base_type
->fields
.array
->is_array()) {
1548 outer_array_size
= outer_array_size
* base_type
->length
;
1549 base_type
= base_type
->fields
.array
;
1551 offset
+= outer_array_size
;
1553 /* We dont worry about arrays here because unless the array
1554 * contains a structure or another array it only takes up a single
1565 glsl_type::uniform_locations() const
1569 switch (this->base_type
) {
1570 case GLSL_TYPE_UINT
:
1572 case GLSL_TYPE_FLOAT
:
1573 case GLSL_TYPE_FLOAT16
:
1574 case GLSL_TYPE_DOUBLE
:
1575 case GLSL_TYPE_UINT16
:
1576 case GLSL_TYPE_UINT8
:
1577 case GLSL_TYPE_INT16
:
1578 case GLSL_TYPE_INT8
:
1579 case GLSL_TYPE_UINT64
:
1580 case GLSL_TYPE_INT64
:
1581 case GLSL_TYPE_BOOL
:
1582 case GLSL_TYPE_SAMPLER
:
1583 case GLSL_TYPE_IMAGE
:
1584 case GLSL_TYPE_SUBROUTINE
:
1587 case GLSL_TYPE_STRUCT
:
1588 case GLSL_TYPE_INTERFACE
:
1589 for (unsigned i
= 0; i
< this->length
; i
++)
1590 size
+= this->fields
.structure
[i
].type
->uniform_locations();
1592 case GLSL_TYPE_ARRAY
:
1593 return this->length
* this->fields
.array
->uniform_locations();
1600 glsl_type::varying_count() const
1604 switch (this->base_type
) {
1605 case GLSL_TYPE_UINT
:
1607 case GLSL_TYPE_FLOAT
:
1608 case GLSL_TYPE_FLOAT16
:
1609 case GLSL_TYPE_DOUBLE
:
1610 case GLSL_TYPE_BOOL
:
1611 case GLSL_TYPE_UINT16
:
1612 case GLSL_TYPE_UINT8
:
1613 case GLSL_TYPE_INT16
:
1614 case GLSL_TYPE_INT8
:
1615 case GLSL_TYPE_UINT64
:
1616 case GLSL_TYPE_INT64
:
1619 case GLSL_TYPE_STRUCT
:
1620 case GLSL_TYPE_INTERFACE
:
1621 for (unsigned i
= 0; i
< this->length
; i
++)
1622 size
+= this->fields
.structure
[i
].type
->varying_count();
1624 case GLSL_TYPE_ARRAY
:
1625 /* Don't count innermost array elements */
1626 if (this->without_array()->is_struct() ||
1627 this->without_array()->is_interface() ||
1628 this->fields
.array
->is_array())
1629 return this->length
* this->fields
.array
->varying_count();
1631 return this->fields
.array
->varying_count();
1633 assert(!"unsupported varying type");
1639 glsl_type::can_implicitly_convert_to(const glsl_type
*desired
,
1640 _mesa_glsl_parse_state
*state
) const
1642 if (this == desired
)
1645 /* GLSL 1.10 and ESSL do not allow implicit conversions. If there is no
1646 * state, we're doing intra-stage function linking where these checks have
1647 * already been done.
1649 if (state
&& !state
->has_implicit_conversions())
1652 /* There is no conversion among matrix types. */
1653 if (this->matrix_columns
> 1 || desired
->matrix_columns
> 1)
1656 /* Vector size must match. */
1657 if (this->vector_elements
!= desired
->vector_elements
)
1660 /* int and uint can be converted to float. */
1661 if (desired
->is_float() && this->is_integer_32())
1664 /* With GLSL 4.0, ARB_gpu_shader5, or MESA_shader_integer_functions, int
1665 * can be converted to uint. Note that state may be NULL here, when
1666 * resolving function calls in the linker. By this time, all the
1667 * state-dependent checks have already happened though, so allow anything
1668 * that's allowed in any shader version.
1670 if ((!state
|| state
->has_implicit_uint_to_int_conversion()) &&
1671 desired
->base_type
== GLSL_TYPE_UINT
&& this->base_type
== GLSL_TYPE_INT
)
1674 /* No implicit conversions from double. */
1675 if ((!state
|| state
->has_double()) && this->is_double())
1678 /* Conversions from different types to double. */
1679 if ((!state
|| state
->has_double()) && desired
->is_double()) {
1680 if (this->is_float())
1682 if (this->is_integer_32())
1690 glsl_type::std140_base_alignment(bool row_major
) const
1692 unsigned N
= is_64bit() ? 8 : 4;
1694 /* (1) If the member is a scalar consuming <N> basic machine units, the
1695 * base alignment is <N>.
1697 * (2) If the member is a two- or four-component vector with components
1698 * consuming <N> basic machine units, the base alignment is 2<N> or
1699 * 4<N>, respectively.
1701 * (3) If the member is a three-component vector with components consuming
1702 * <N> basic machine units, the base alignment is 4<N>.
1704 if (this->is_scalar() || this->is_vector()) {
1705 switch (this->vector_elements
) {
1716 /* (4) If the member is an array of scalars or vectors, the base alignment
1717 * and array stride are set to match the base alignment of a single
1718 * array element, according to rules (1), (2), and (3), and rounded up
1719 * to the base alignment of a vec4. The array may have padding at the
1720 * end; the base offset of the member following the array is rounded up
1721 * to the next multiple of the base alignment.
1723 * (6) If the member is an array of <S> column-major matrices with <C>
1724 * columns and <R> rows, the matrix is stored identically to a row of
1725 * <S>*<C> column vectors with <R> components each, according to rule
1728 * (8) If the member is an array of <S> row-major matrices with <C> columns
1729 * and <R> rows, the matrix is stored identically to a row of <S>*<R>
1730 * row vectors with <C> components each, according to rule (4).
1732 * (10) If the member is an array of <S> structures, the <S> elements of
1733 * the array are laid out in order, according to rule (9).
1735 if (this->is_array()) {
1736 if (this->fields
.array
->is_scalar() ||
1737 this->fields
.array
->is_vector() ||
1738 this->fields
.array
->is_matrix()) {
1739 return MAX2(this->fields
.array
->std140_base_alignment(row_major
), 16);
1741 assert(this->fields
.array
->is_struct() ||
1742 this->fields
.array
->is_array());
1743 return this->fields
.array
->std140_base_alignment(row_major
);
1747 /* (5) If the member is a column-major matrix with <C> columns and
1748 * <R> rows, the matrix is stored identically to an array of
1749 * <C> column vectors with <R> components each, according to
1752 * (7) If the member is a row-major matrix with <C> columns and <R>
1753 * rows, the matrix is stored identically to an array of <R>
1754 * row vectors with <C> components each, according to rule (4).
1756 if (this->is_matrix()) {
1757 const struct glsl_type
*vec_type
, *array_type
;
1758 int c
= this->matrix_columns
;
1759 int r
= this->vector_elements
;
1762 vec_type
= get_instance(base_type
, c
, 1);
1763 array_type
= glsl_type::get_array_instance(vec_type
, r
);
1765 vec_type
= get_instance(base_type
, r
, 1);
1766 array_type
= glsl_type::get_array_instance(vec_type
, c
);
1769 return array_type
->std140_base_alignment(false);
1772 /* (9) If the member is a structure, the base alignment of the
1773 * structure is <N>, where <N> is the largest base alignment
1774 * value of any of its members, and rounded up to the base
1775 * alignment of a vec4. The individual members of this
1776 * sub-structure are then assigned offsets by applying this set
1777 * of rules recursively, where the base offset of the first
1778 * member of the sub-structure is equal to the aligned offset
1779 * of the structure. The structure may have padding at the end;
1780 * the base offset of the member following the sub-structure is
1781 * rounded up to the next multiple of the base alignment of the
1784 if (this->is_struct()) {
1785 unsigned base_alignment
= 16;
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 base_alignment
= MAX2(base_alignment
,
1798 field_type
->std140_base_alignment(field_row_major
));
1800 return base_alignment
;
1803 assert(!"not reached");
1808 glsl_type::std140_size(bool row_major
) const
1810 unsigned N
= is_64bit() ? 8 : 4;
1812 /* (1) If the member is a scalar consuming <N> basic machine units, the
1813 * base alignment is <N>.
1815 * (2) If the member is a two- or four-component vector with components
1816 * consuming <N> basic machine units, the base alignment is 2<N> or
1817 * 4<N>, respectively.
1819 * (3) If the member is a three-component vector with components consuming
1820 * <N> basic machine units, the base alignment is 4<N>.
1822 if (this->is_scalar() || this->is_vector()) {
1823 assert(this->explicit_stride
== 0);
1824 return this->vector_elements
* N
;
1827 /* (5) If the member is a column-major matrix with <C> columns and
1828 * <R> rows, the matrix is stored identically to an array of
1829 * <C> column vectors with <R> components each, according to
1832 * (6) If the member is an array of <S> column-major matrices with <C>
1833 * columns and <R> rows, the matrix is stored identically to a row of
1834 * <S>*<C> column vectors with <R> components each, according to rule
1837 * (7) If the member is a row-major matrix with <C> columns and <R>
1838 * rows, the matrix is stored identically to an array of <R>
1839 * row vectors with <C> components each, according to rule (4).
1841 * (8) If the member is an array of <S> row-major matrices with <C> columns
1842 * and <R> rows, the matrix is stored identically to a row of <S>*<R>
1843 * row vectors with <C> components each, according to rule (4).
1845 if (this->without_array()->is_matrix()) {
1846 const struct glsl_type
*element_type
;
1847 const struct glsl_type
*vec_type
;
1848 unsigned int array_len
;
1850 if (this->is_array()) {
1851 element_type
= this->without_array();
1852 array_len
= this->arrays_of_arrays_size();
1854 element_type
= this;
1859 vec_type
= get_instance(element_type
->base_type
,
1860 element_type
->matrix_columns
, 1);
1862 array_len
*= element_type
->vector_elements
;
1864 vec_type
= get_instance(element_type
->base_type
,
1865 element_type
->vector_elements
, 1);
1866 array_len
*= element_type
->matrix_columns
;
1868 const glsl_type
*array_type
= glsl_type::get_array_instance(vec_type
,
1871 return array_type
->std140_size(false);
1874 /* (4) If the member is an array of scalars or vectors, the base alignment
1875 * and array stride are set to match the base alignment of a single
1876 * array element, according to rules (1), (2), and (3), and rounded up
1877 * to the base alignment of a vec4. The array may have padding at the
1878 * end; the base offset of the member following the array is rounded up
1879 * to the next multiple of the base alignment.
1881 * (10) If the member is an array of <S> structures, the <S> elements of
1882 * the array are laid out in order, according to rule (9).
1884 if (this->is_array()) {
1886 if (this->without_array()->is_struct()) {
1887 stride
= this->without_array()->std140_size(row_major
);
1889 unsigned element_base_align
=
1890 this->without_array()->std140_base_alignment(row_major
);
1891 stride
= MAX2(element_base_align
, 16);
1894 unsigned size
= this->arrays_of_arrays_size() * stride
;
1895 assert(this->explicit_stride
== 0 ||
1896 size
== this->length
* this->explicit_stride
);
1900 /* (9) If the member is a structure, the base alignment of the
1901 * structure is <N>, where <N> is the largest base alignment
1902 * value of any of its members, and rounded up to the base
1903 * alignment of a vec4. The individual members of this
1904 * sub-structure are then assigned offsets by applying this set
1905 * of rules recursively, where the base offset of the first
1906 * member of the sub-structure is equal to the aligned offset
1907 * of the structure. The structure may have padding at the end;
1908 * the base offset of the member following the sub-structure is
1909 * rounded up to the next multiple of the base alignment of the
1912 if (this->is_struct() || this->is_interface()) {
1914 unsigned max_align
= 0;
1916 for (unsigned i
= 0; i
< this->length
; i
++) {
1917 bool field_row_major
= row_major
;
1918 const enum glsl_matrix_layout matrix_layout
=
1919 glsl_matrix_layout(this->fields
.structure
[i
].matrix_layout
);
1920 if (matrix_layout
== GLSL_MATRIX_LAYOUT_ROW_MAJOR
) {
1921 field_row_major
= true;
1922 } else if (matrix_layout
== GLSL_MATRIX_LAYOUT_COLUMN_MAJOR
) {
1923 field_row_major
= false;
1926 const struct glsl_type
*field_type
= this->fields
.structure
[i
].type
;
1927 unsigned align
= field_type
->std140_base_alignment(field_row_major
);
1929 /* Ignore unsized arrays when calculating size */
1930 if (field_type
->is_unsized_array())
1933 size
= glsl_align(size
, align
);
1934 size
+= field_type
->std140_size(field_row_major
);
1936 max_align
= MAX2(align
, max_align
);
1938 if (field_type
->is_struct() && (i
+ 1 < this->length
))
1939 size
= glsl_align(size
, 16);
1941 size
= glsl_align(size
, MAX2(max_align
, 16));
1945 assert(!"not reached");
1950 glsl_type::get_explicit_std140_type(bool row_major
) const
1952 if (this->is_vector() || this->is_scalar()) {
1954 } else if (this->is_matrix()) {
1955 const glsl_type
*vec_type
;
1957 vec_type
= get_instance(this->base_type
, this->matrix_columns
, 1);
1959 vec_type
= get_instance(this->base_type
, this->vector_elements
, 1);
1960 unsigned elem_size
= vec_type
->std140_size(false);
1961 unsigned stride
= glsl_align(elem_size
, 16);
1962 return get_instance(this->base_type
, this->vector_elements
,
1963 this->matrix_columns
, stride
, row_major
);
1964 } else if (this->is_array()) {
1965 unsigned elem_size
= this->fields
.array
->std140_size(row_major
);
1966 const glsl_type
*elem_type
=
1967 this->fields
.array
->get_explicit_std140_type(row_major
);
1968 unsigned stride
= glsl_align(elem_size
, 16);
1969 return get_array_instance(elem_type
, this->length
, stride
);
1970 } else if (this->is_struct() || this->is_interface()) {
1971 glsl_struct_field
*fields
= new glsl_struct_field
[this->length
];
1972 unsigned offset
= 0;
1973 for (unsigned i
= 0; i
< length
; i
++) {
1974 fields
[i
] = this->fields
.structure
[i
];
1976 bool field_row_major
= row_major
;
1977 if (fields
[i
].matrix_layout
== GLSL_MATRIX_LAYOUT_COLUMN_MAJOR
) {
1978 field_row_major
= false;
1979 } else if (fields
[i
].matrix_layout
== GLSL_MATRIX_LAYOUT_ROW_MAJOR
) {
1980 field_row_major
= true;
1983 fields
[i
].type
->get_explicit_std140_type(field_row_major
);
1985 unsigned fsize
= fields
[i
].type
->std140_size(field_row_major
);
1986 unsigned falign
= fields
[i
].type
->std140_base_alignment(field_row_major
);
1987 /* From the GLSL 460 spec section "Uniform and Shader Storage Block
1988 * Layout Qualifiers":
1990 * "The actual offset of a member is computed as follows: If
1991 * offset was declared, start with that offset, otherwise start
1992 * with the next available offset. If the resulting offset is not
1993 * a multiple of the actual alignment, increase it to the first
1994 * offset that is a multiple of the actual alignment. This results
1995 * in the actual offset the member will have."
1997 if (fields
[i
].offset
>= 0) {
1998 assert((unsigned)fields
[i
].offset
>= offset
);
1999 offset
= fields
[i
].offset
;
2001 offset
= glsl_align(offset
, falign
);
2002 fields
[i
].offset
= offset
;
2006 const glsl_type
*type
;
2007 if (this->is_struct())
2008 type
= get_struct_instance(fields
, this->length
, this->name
);
2010 type
= get_interface_instance(fields
, this->length
,
2011 (enum glsl_interface_packing
)this->interface_packing
,
2012 this->interface_row_major
,
2018 unreachable("Invalid type for UBO or SSBO");
2023 glsl_type::std430_base_alignment(bool row_major
) const
2026 unsigned N
= is_64bit() ? 8 : 4;
2028 /* (1) If the member is a scalar consuming <N> basic machine units, the
2029 * base alignment is <N>.
2031 * (2) If the member is a two- or four-component vector with components
2032 * consuming <N> basic machine units, the base alignment is 2<N> or
2033 * 4<N>, respectively.
2035 * (3) If the member is a three-component vector with components consuming
2036 * <N> basic machine units, the base alignment is 4<N>.
2038 if (this->is_scalar() || this->is_vector()) {
2039 switch (this->vector_elements
) {
2050 /* OpenGL 4.30 spec, section 7.6.2.2 "Standard Uniform Block Layout":
2052 * "When using the std430 storage layout, shader storage blocks will be
2053 * laid out in buffer storage identically to uniform and shader storage
2054 * blocks using the std140 layout, except that the base alignment and
2055 * stride of arrays of scalars and vectors in rule 4 and of structures
2056 * in rule 9 are not rounded up a multiple of the base alignment of a vec4.
2059 /* (1) If the member is a scalar consuming <N> basic machine units, the
2060 * base alignment is <N>.
2062 * (2) If the member is a two- or four-component vector with components
2063 * consuming <N> basic machine units, the base alignment is 2<N> or
2064 * 4<N>, respectively.
2066 * (3) If the member is a three-component vector with components consuming
2067 * <N> basic machine units, the base alignment is 4<N>.
2069 if (this->is_array())
2070 return this->fields
.array
->std430_base_alignment(row_major
);
2072 /* (5) If the member is a column-major matrix with <C> columns and
2073 * <R> rows, the matrix is stored identically to an array of
2074 * <C> column vectors with <R> components each, according to
2077 * (7) If the member is a row-major matrix with <C> columns and <R>
2078 * rows, the matrix is stored identically to an array of <R>
2079 * row vectors with <C> components each, according to rule (4).
2081 if (this->is_matrix()) {
2082 const struct glsl_type
*vec_type
, *array_type
;
2083 int c
= this->matrix_columns
;
2084 int r
= this->vector_elements
;
2087 vec_type
= get_instance(base_type
, c
, 1);
2088 array_type
= glsl_type::get_array_instance(vec_type
, r
);
2090 vec_type
= get_instance(base_type
, r
, 1);
2091 array_type
= glsl_type::get_array_instance(vec_type
, c
);
2094 return array_type
->std430_base_alignment(false);
2097 /* (9) If the member is a structure, the base alignment of the
2098 * structure is <N>, where <N> is the largest base alignment
2099 * value of any of its members, and rounded up to the base
2100 * alignment of a vec4. The individual members of this
2101 * sub-structure are then assigned offsets by applying this set
2102 * of rules recursively, where the base offset of the first
2103 * member of the sub-structure is equal to the aligned offset
2104 * of the structure. The structure may have padding at the end;
2105 * the base offset of the member following the sub-structure is
2106 * rounded up to the next multiple of the base alignment of the
2109 if (this->is_struct()) {
2110 unsigned base_alignment
= 0;
2111 for (unsigned i
= 0; i
< this->length
; i
++) {
2112 bool field_row_major
= row_major
;
2113 const enum glsl_matrix_layout matrix_layout
=
2114 glsl_matrix_layout(this->fields
.structure
[i
].matrix_layout
);
2115 if (matrix_layout
== GLSL_MATRIX_LAYOUT_ROW_MAJOR
) {
2116 field_row_major
= true;
2117 } else if (matrix_layout
== GLSL_MATRIX_LAYOUT_COLUMN_MAJOR
) {
2118 field_row_major
= false;
2121 const struct glsl_type
*field_type
= this->fields
.structure
[i
].type
;
2122 base_alignment
= MAX2(base_alignment
,
2123 field_type
->std430_base_alignment(field_row_major
));
2125 assert(base_alignment
> 0);
2126 return base_alignment
;
2128 assert(!"not reached");
2133 glsl_type::std430_array_stride(bool row_major
) const
2135 unsigned N
= is_64bit() ? 8 : 4;
2137 /* Notice that the array stride of a vec3 is not 3 * N but 4 * N.
2138 * See OpenGL 4.30 spec, section 7.6.2.2 "Standard Uniform Block Layout"
2140 * (3) If the member is a three-component vector with components consuming
2141 * <N> basic machine units, the base alignment is 4<N>.
2143 if (this->is_vector() && this->vector_elements
== 3)
2146 /* By default use std430_size(row_major) */
2147 unsigned stride
= this->std430_size(row_major
);
2148 assert(this->explicit_stride
== 0 || this->explicit_stride
== stride
);
2152 /* Note that the value returned by this method is only correct if the
2153 * explit offset, and stride values are set, so only with SPIR-V shaders.
2154 * Should not be used with GLSL shaders.
2158 glsl_type::explicit_size(bool align_to_stride
) const
2160 if (this->is_struct() || this->is_interface()) {
2161 if (this->length
> 0) {
2164 for (unsigned i
= 0; i
< this->length
; i
++) {
2165 assert(this->fields
.structure
[i
].offset
>= 0);
2166 unsigned last_byte
= this->fields
.structure
[i
].offset
+
2167 this->fields
.structure
[i
].type
->explicit_size();
2168 size
= MAX2(size
, last_byte
);
2175 } else if (this->is_array()) {
2176 /* From ARB_program_interface_query spec:
2178 * "For the property of BUFFER_DATA_SIZE, then the implementation-dependent
2179 * minimum total buffer object size, in basic machine units, required to
2180 * hold all active variables associated with an active uniform block, shader
2181 * storage block, or atomic counter buffer is written to <params>. If the
2182 * final member of an active shader storage block is array with no declared
2183 * size, the minimum buffer size is computed assuming the array was declared
2184 * as an array with one element."
2187 if (this->is_unsized_array())
2188 return this->explicit_stride
;
2190 assert(this->length
> 0);
2191 unsigned elem_size
= align_to_stride
? this->explicit_stride
: this->fields
.array
->explicit_size();
2192 assert(this->explicit_stride
>= elem_size
);
2194 return this->explicit_stride
* (this->length
- 1) + elem_size
;
2195 } else if (this->is_matrix()) {
2196 const struct glsl_type
*elem_type
;
2199 if (this->interface_row_major
) {
2200 elem_type
= get_instance(this->base_type
,
2201 this->matrix_columns
, 1);
2202 length
= this->vector_elements
;
2204 elem_type
= get_instance(this->base_type
,
2205 this->vector_elements
, 1);
2206 length
= this->matrix_columns
;
2209 unsigned elem_size
= align_to_stride
? this->explicit_stride
: elem_type
->explicit_size();
2211 assert(this->explicit_stride
);
2212 return this->explicit_stride
* (length
- 1) + elem_size
;
2215 unsigned N
= this->bit_size() / 8;
2217 return this->vector_elements
* N
;
2221 glsl_type::std430_size(bool row_major
) const
2223 unsigned N
= is_64bit() ? 8 : 4;
2225 /* OpenGL 4.30 spec, section 7.6.2.2 "Standard Uniform Block Layout":
2227 * "When using the std430 storage layout, shader storage blocks will be
2228 * laid out in buffer storage identically to uniform and shader storage
2229 * blocks using the std140 layout, except that the base alignment and
2230 * stride of arrays of scalars and vectors in rule 4 and of structures
2231 * in rule 9 are not rounded up a multiple of the base alignment of a vec4.
2233 if (this->is_scalar() || this->is_vector()) {
2234 assert(this->explicit_stride
== 0);
2235 return this->vector_elements
* N
;
2238 if (this->without_array()->is_matrix()) {
2239 const struct glsl_type
*element_type
;
2240 const struct glsl_type
*vec_type
;
2241 unsigned int array_len
;
2243 if (this->is_array()) {
2244 element_type
= this->without_array();
2245 array_len
= this->arrays_of_arrays_size();
2247 element_type
= this;
2252 vec_type
= get_instance(element_type
->base_type
,
2253 element_type
->matrix_columns
, 1);
2255 array_len
*= element_type
->vector_elements
;
2257 vec_type
= get_instance(element_type
->base_type
,
2258 element_type
->vector_elements
, 1);
2259 array_len
*= element_type
->matrix_columns
;
2261 const glsl_type
*array_type
= glsl_type::get_array_instance(vec_type
,
2264 return array_type
->std430_size(false);
2267 if (this->is_array()) {
2269 if (this->without_array()->is_struct())
2270 stride
= this->without_array()->std430_size(row_major
);
2272 stride
= this->without_array()->std430_base_alignment(row_major
);
2274 unsigned size
= this->arrays_of_arrays_size() * stride
;
2275 assert(this->explicit_stride
== 0 ||
2276 size
== this->length
* this->explicit_stride
);
2280 if (this->is_struct() || this->is_interface()) {
2282 unsigned max_align
= 0;
2284 for (unsigned i
= 0; i
< this->length
; i
++) {
2285 bool field_row_major
= row_major
;
2286 const enum glsl_matrix_layout matrix_layout
=
2287 glsl_matrix_layout(this->fields
.structure
[i
].matrix_layout
);
2288 if (matrix_layout
== GLSL_MATRIX_LAYOUT_ROW_MAJOR
) {
2289 field_row_major
= true;
2290 } else if (matrix_layout
== GLSL_MATRIX_LAYOUT_COLUMN_MAJOR
) {
2291 field_row_major
= false;
2294 const struct glsl_type
*field_type
= this->fields
.structure
[i
].type
;
2295 unsigned align
= field_type
->std430_base_alignment(field_row_major
);
2296 size
= glsl_align(size
, align
);
2297 size
+= field_type
->std430_size(field_row_major
);
2299 max_align
= MAX2(align
, max_align
);
2301 size
= glsl_align(size
, max_align
);
2305 assert(!"not reached");
2310 glsl_type::get_explicit_std430_type(bool row_major
) const
2312 if (this->is_vector() || this->is_scalar()) {
2314 } else if (this->is_matrix()) {
2315 const glsl_type
*vec_type
;
2317 vec_type
= get_instance(this->base_type
, this->matrix_columns
, 1);
2319 vec_type
= get_instance(this->base_type
, this->vector_elements
, 1);
2320 unsigned stride
= vec_type
->std430_array_stride(false);
2321 return get_instance(this->base_type
, this->vector_elements
,
2322 this->matrix_columns
, stride
, row_major
);
2323 } else if (this->is_array()) {
2324 const glsl_type
*elem_type
=
2325 this->fields
.array
->get_explicit_std430_type(row_major
);
2326 unsigned stride
= this->fields
.array
->std430_array_stride(row_major
);
2327 return get_array_instance(elem_type
, this->length
, stride
);
2328 } else if (this->is_struct() || this->is_interface()) {
2329 glsl_struct_field
*fields
= new glsl_struct_field
[this->length
];
2330 unsigned offset
= 0;
2331 for (unsigned i
= 0; i
< length
; i
++) {
2332 fields
[i
] = this->fields
.structure
[i
];
2334 bool field_row_major
= row_major
;
2335 if (fields
[i
].matrix_layout
== GLSL_MATRIX_LAYOUT_COLUMN_MAJOR
) {
2336 field_row_major
= false;
2337 } else if (fields
[i
].matrix_layout
== GLSL_MATRIX_LAYOUT_ROW_MAJOR
) {
2338 field_row_major
= true;
2341 fields
[i
].type
->get_explicit_std430_type(field_row_major
);
2343 unsigned fsize
= fields
[i
].type
->std430_size(field_row_major
);
2344 unsigned falign
= fields
[i
].type
->std430_base_alignment(field_row_major
);
2345 /* From the GLSL 460 spec section "Uniform and Shader Storage Block
2346 * Layout Qualifiers":
2348 * "The actual offset of a member is computed as follows: If
2349 * offset was declared, start with that offset, otherwise start
2350 * with the next available offset. If the resulting offset is not
2351 * a multiple of the actual alignment, increase it to the first
2352 * offset that is a multiple of the actual alignment. This results
2353 * in the actual offset the member will have."
2355 if (fields
[i
].offset
>= 0) {
2356 assert((unsigned)fields
[i
].offset
>= offset
);
2357 offset
= fields
[i
].offset
;
2359 offset
= glsl_align(offset
, falign
);
2360 fields
[i
].offset
= offset
;
2364 const glsl_type
*type
;
2365 if (this->is_struct())
2366 type
= get_struct_instance(fields
, this->length
, this->name
);
2368 type
= get_interface_instance(fields
, this->length
,
2369 (enum glsl_interface_packing
)this->interface_packing
,
2370 this->interface_row_major
,
2376 unreachable("Invalid type for SSBO");
2381 glsl_type::get_explicit_interface_type(bool supports_std430
) const
2383 enum glsl_interface_packing packing
=
2384 this->get_internal_ifc_packing(supports_std430
);
2385 if (packing
== GLSL_INTERFACE_PACKING_STD140
) {
2386 return this->get_explicit_std140_type(this->interface_row_major
);
2388 assert(packing
== GLSL_INTERFACE_PACKING_STD430
);
2389 return this->get_explicit_std430_type(this->interface_row_major
);
2393 /* This differs from get_explicit_std430_type() in that it:
2394 * - can size arrays slightly smaller ("stride * (len - 1) + elem_size" instead
2395 * of "stride * len")
2396 * - consumes a glsl_type_size_align_func which allows 8 and 16-bit values to be
2397 * packed more tightly
2398 * - overrides any struct field offsets but get_explicit_std430_type() tries to
2399 * respect any existing ones
2402 glsl_type::get_explicit_type_for_size_align(glsl_type_size_align_func type_info
,
2403 unsigned *size
, unsigned *alignment
) const
2405 if (this->is_scalar() || this->is_vector()) {
2406 type_info(this, size
, alignment
);
2408 } else if (this->is_array()) {
2409 unsigned elem_size
, elem_align
;
2410 const struct glsl_type
*explicit_element
=
2411 this->fields
.array
->get_explicit_type_for_size_align(type_info
, &elem_size
, &elem_align
);
2413 unsigned stride
= align(elem_size
, elem_align
);
2415 *size
= stride
* (this->length
- 1) + elem_size
;
2416 *alignment
= elem_align
;
2417 return glsl_type::get_array_instance(explicit_element
, this->length
, stride
);
2418 } else if (this->is_struct()) {
2419 struct glsl_struct_field
*fields
= (struct glsl_struct_field
*)
2420 malloc(sizeof(struct glsl_struct_field
) * this->length
);
2424 for (unsigned i
= 0; i
< this->length
; i
++) {
2425 fields
[i
] = this->fields
.structure
[i
];
2426 assert(fields
[i
].matrix_layout
!= GLSL_MATRIX_LAYOUT_ROW_MAJOR
);
2428 unsigned field_size
, field_align
;
2430 fields
[i
].type
->get_explicit_type_for_size_align(type_info
, &field_size
, &field_align
);
2431 fields
[i
].offset
= align(*size
, field_align
);
2433 *size
= fields
[i
].offset
+ field_size
;
2434 *alignment
= MAX2(*alignment
, field_align
);
2437 const glsl_type
*type
= glsl_type::get_struct_instance(fields
, this->length
, this->name
, false);
2440 } else if (this->is_matrix()) {
2441 unsigned col_size
, col_align
;
2442 type_info(this->column_type(), &col_size
, &col_align
);
2443 unsigned stride
= align(col_size
, col_align
);
2445 *size
= this->matrix_columns
* stride
;
2446 *alignment
= col_align
;
2447 return glsl_type::get_instance(this->base_type
, this->vector_elements
,
2448 this->matrix_columns
, stride
, false);
2450 unreachable("Unhandled type.");
2455 glsl_type::count_vec4_slots(bool is_gl_vertex_input
, bool is_bindless
) const
2457 /* From page 31 (page 37 of the PDF) of the GLSL 1.50 spec:
2459 * "A scalar input counts the same amount against this limit as a vec4,
2460 * so applications may want to consider packing groups of four
2461 * unrelated float inputs together into a vector to better utilize the
2462 * capabilities of the underlying hardware. A matrix input will use up
2463 * multiple locations. The number of locations used will equal the
2464 * number of columns in the matrix."
2466 * The spec does not explicitly say how arrays are counted. However, it
2467 * should be safe to assume the total number of slots consumed by an array
2468 * is the number of entries in the array multiplied by the number of slots
2469 * consumed by a single element of the array.
2471 * The spec says nothing about how structs are counted, because vertex
2472 * attributes are not allowed to be (or contain) structs. However, Mesa
2473 * allows varying structs, the number of varying slots taken up by a
2474 * varying struct is simply equal to the sum of the number of slots taken
2475 * up by each element.
2477 * Doubles are counted different depending on whether they are vertex
2478 * inputs or everything else. Vertex inputs from ARB_vertex_attrib_64bit
2479 * take one location no matter what size they are, otherwise dvec3/4
2480 * take two locations.
2482 switch (this->base_type
) {
2483 case GLSL_TYPE_UINT
:
2485 case GLSL_TYPE_UINT8
:
2486 case GLSL_TYPE_INT8
:
2487 case GLSL_TYPE_UINT16
:
2488 case GLSL_TYPE_INT16
:
2489 case GLSL_TYPE_FLOAT
:
2490 case GLSL_TYPE_FLOAT16
:
2491 case GLSL_TYPE_BOOL
:
2492 return this->matrix_columns
;
2493 case GLSL_TYPE_DOUBLE
:
2494 case GLSL_TYPE_UINT64
:
2495 case GLSL_TYPE_INT64
:
2496 if (this->vector_elements
> 2 && !is_gl_vertex_input
)
2497 return this->matrix_columns
* 2;
2499 return this->matrix_columns
;
2500 case GLSL_TYPE_STRUCT
:
2501 case GLSL_TYPE_INTERFACE
: {
2504 for (unsigned i
= 0; i
< this->length
; i
++) {
2505 const glsl_type
*member_type
= this->fields
.structure
[i
].type
;
2506 size
+= member_type
->count_vec4_slots(is_gl_vertex_input
, is_bindless
);
2512 case GLSL_TYPE_ARRAY
: {
2513 const glsl_type
*element
= this->fields
.array
;
2514 return this->length
* element
->count_vec4_slots(is_gl_vertex_input
,
2518 case GLSL_TYPE_SAMPLER
:
2519 case GLSL_TYPE_IMAGE
:
2525 case GLSL_TYPE_SUBROUTINE
:
2528 case GLSL_TYPE_FUNCTION
:
2529 case GLSL_TYPE_ATOMIC_UINT
:
2530 case GLSL_TYPE_VOID
:
2531 case GLSL_TYPE_ERROR
:
2535 assert(!"Unexpected type in count_attribute_slots()");
2541 glsl_type::count_dword_slots(bool is_bindless
) const
2543 switch (this->base_type
) {
2544 case GLSL_TYPE_UINT
:
2546 case GLSL_TYPE_FLOAT
:
2547 case GLSL_TYPE_BOOL
:
2548 return this->components();
2549 case GLSL_TYPE_UINT16
:
2550 case GLSL_TYPE_INT16
:
2551 case GLSL_TYPE_FLOAT16
:
2552 return DIV_ROUND_UP(this->components(), 2);
2553 case GLSL_TYPE_UINT8
:
2554 case GLSL_TYPE_INT8
:
2555 return DIV_ROUND_UP(this->components(), 4);
2556 case GLSL_TYPE_IMAGE
:
2557 case GLSL_TYPE_SAMPLER
:
2561 case GLSL_TYPE_DOUBLE
:
2562 case GLSL_TYPE_UINT64
:
2563 case GLSL_TYPE_INT64
:
2564 return this->components() * 2;
2565 case GLSL_TYPE_ARRAY
:
2566 return this->fields
.array
->count_dword_slots(is_bindless
) *
2569 case GLSL_TYPE_INTERFACE
:
2570 case GLSL_TYPE_STRUCT
: {
2572 for (unsigned i
= 0; i
< this->length
; i
++) {
2573 size
+= this->fields
.structure
[i
].type
->count_dword_slots(is_bindless
);
2578 case GLSL_TYPE_ATOMIC_UINT
:
2580 case GLSL_TYPE_SUBROUTINE
:
2582 case GLSL_TYPE_VOID
:
2583 case GLSL_TYPE_ERROR
:
2584 case GLSL_TYPE_FUNCTION
:
2586 unreachable("invalid type in st_glsl_type_dword_size()");
2593 glsl_type::coordinate_components() const
2595 enum glsl_sampler_dim dim
= (enum glsl_sampler_dim
)sampler_dimensionality
;
2596 int size
= glsl_get_sampler_dim_coordinate_components(dim
);
2598 /* Array textures need an additional component for the array index, except
2599 * for cubemap array images that behave like a 2D array of interleaved
2602 if (sampler_array
&&
2603 !(is_image() && sampler_dimensionality
== GLSL_SAMPLER_DIM_CUBE
))
2610 * Declarations of type flyweights (glsl_type::_foo_type) and
2611 * convenience pointers (glsl_type::foo_type).
2614 #define DECL_TYPE(NAME, ...) \
2615 const glsl_type glsl_type::_##NAME##_type = glsl_type(__VA_ARGS__, #NAME); \
2616 const glsl_type *const glsl_type::NAME##_type = &glsl_type::_##NAME##_type;
2618 #define STRUCT_TYPE(NAME)
2620 #include "compiler/builtin_type_macros.h"
2624 get_struct_type_field_and_pointer_sizes(size_t *s_field_size
,
2625 size_t *s_field_ptrs
)
2627 *s_field_size
= sizeof(glsl_struct_field
);
2629 sizeof(((glsl_struct_field
*)0)->type
) +
2630 sizeof(((glsl_struct_field
*)0)->name
);
2636 unsigned base_type
:5;
2637 unsigned interface_row_major
:1;
2638 unsigned vector_elements
:3;
2639 unsigned matrix_columns
:3;
2640 unsigned explicit_stride
:20;
2643 unsigned base_type
:5;
2644 unsigned dimensionality
:4;
2647 unsigned sampled_type
:2;
2651 unsigned base_type
:5;
2653 unsigned explicit_stride
:14;
2656 unsigned base_type
:5;
2657 unsigned interface_packing_or_packed
:2;
2658 unsigned interface_row_major
:1;
2664 encode_type_to_blob(struct blob
*blob
, const glsl_type
*type
)
2667 blob_write_uint32(blob
, 0);
2671 STATIC_ASSERT(sizeof(union packed_type
) == 4);
2672 union packed_type encoded
;
2674 encoded
.basic
.base_type
= type
->base_type
;
2676 switch (type
->base_type
) {
2677 case GLSL_TYPE_UINT
:
2679 case GLSL_TYPE_FLOAT
:
2680 case GLSL_TYPE_FLOAT16
:
2681 case GLSL_TYPE_DOUBLE
:
2682 case GLSL_TYPE_UINT8
:
2683 case GLSL_TYPE_INT8
:
2684 case GLSL_TYPE_UINT16
:
2685 case GLSL_TYPE_INT16
:
2686 case GLSL_TYPE_UINT64
:
2687 case GLSL_TYPE_INT64
:
2688 case GLSL_TYPE_BOOL
:
2689 encoded
.basic
.interface_row_major
= type
->interface_row_major
;
2690 assert(type
->matrix_columns
< 8);
2691 if (type
->vector_elements
<= 4)
2692 encoded
.basic
.vector_elements
= type
->vector_elements
;
2693 else if (type
->vector_elements
== 8)
2694 encoded
.basic
.vector_elements
= 5;
2695 else if (type
->vector_elements
== 16)
2696 encoded
.basic
.vector_elements
= 6;
2697 encoded
.basic
.matrix_columns
= type
->matrix_columns
;
2698 encoded
.basic
.explicit_stride
= MIN2(type
->explicit_stride
, 0xfffff);
2699 blob_write_uint32(blob
, encoded
.u32
);
2700 /* If we don't have enough bits for explicit_stride, store it
2703 if (encoded
.basic
.explicit_stride
== 0xfffff)
2704 blob_write_uint32(blob
, type
->explicit_stride
);
2706 case GLSL_TYPE_SAMPLER
:
2707 encoded
.sampler
.dimensionality
= type
->sampler_dimensionality
;
2708 encoded
.sampler
.shadow
= type
->sampler_shadow
;
2709 encoded
.sampler
.array
= type
->sampler_array
;
2710 encoded
.sampler
.sampled_type
= type
->sampled_type
;
2712 case GLSL_TYPE_SUBROUTINE
:
2713 blob_write_uint32(blob
, encoded
.u32
);
2714 blob_write_string(blob
, type
->name
);
2716 case GLSL_TYPE_IMAGE
:
2717 encoded
.sampler
.dimensionality
= type
->sampler_dimensionality
;
2718 encoded
.sampler
.array
= type
->sampler_array
;
2719 encoded
.sampler
.sampled_type
= type
->sampled_type
;
2721 case GLSL_TYPE_ATOMIC_UINT
:
2723 case GLSL_TYPE_ARRAY
:
2724 encoded
.array
.length
= MIN2(type
->length
, 0x1fff);
2725 encoded
.array
.explicit_stride
= MIN2(type
->explicit_stride
, 0x3fff);
2726 blob_write_uint32(blob
, encoded
.u32
);
2727 /* If we don't have enough bits for length or explicit_stride, store it
2730 if (encoded
.array
.length
== 0x1fff)
2731 blob_write_uint32(blob
, type
->length
);
2732 if (encoded
.array
.explicit_stride
== 0x3fff)
2733 blob_write_uint32(blob
, type
->explicit_stride
);
2734 encode_type_to_blob(blob
, type
->fields
.array
);
2736 case GLSL_TYPE_STRUCT
:
2737 case GLSL_TYPE_INTERFACE
:
2738 encoded
.strct
.length
= MIN2(type
->length
, 0xffffff);
2739 if (type
->is_interface()) {
2740 encoded
.strct
.interface_packing_or_packed
= type
->interface_packing
;
2741 encoded
.strct
.interface_row_major
= type
->interface_row_major
;
2743 encoded
.strct
.interface_packing_or_packed
= type
->packed
;
2745 blob_write_uint32(blob
, encoded
.u32
);
2746 blob_write_string(blob
, type
->name
);
2748 /* If we don't have enough bits for length, store it separately. */
2749 if (encoded
.strct
.length
== 0xffffff)
2750 blob_write_uint32(blob
, type
->length
);
2752 size_t s_field_size
, s_field_ptrs
;
2753 get_struct_type_field_and_pointer_sizes(&s_field_size
, &s_field_ptrs
);
2755 for (unsigned i
= 0; i
< type
->length
; i
++) {
2756 encode_type_to_blob(blob
, type
->fields
.structure
[i
].type
);
2757 blob_write_string(blob
, type
->fields
.structure
[i
].name
);
2759 /* Write the struct field skipping the pointers */
2760 blob_write_bytes(blob
,
2761 ((char *)&type
->fields
.structure
[i
]) + s_field_ptrs
,
2762 s_field_size
- s_field_ptrs
);
2765 case GLSL_TYPE_VOID
:
2767 case GLSL_TYPE_ERROR
:
2769 assert(!"Cannot encode type!");
2774 blob_write_uint32(blob
, encoded
.u32
);
2778 decode_type_from_blob(struct blob_reader
*blob
)
2780 union packed_type encoded
;
2781 encoded
.u32
= blob_read_uint32(blob
);
2783 if (encoded
.u32
== 0) {
2787 glsl_base_type base_type
= (glsl_base_type
)encoded
.basic
.base_type
;
2789 switch (base_type
) {
2790 case GLSL_TYPE_UINT
:
2792 case GLSL_TYPE_FLOAT
:
2793 case GLSL_TYPE_FLOAT16
:
2794 case GLSL_TYPE_DOUBLE
:
2795 case GLSL_TYPE_UINT8
:
2796 case GLSL_TYPE_INT8
:
2797 case GLSL_TYPE_UINT16
:
2798 case GLSL_TYPE_INT16
:
2799 case GLSL_TYPE_UINT64
:
2800 case GLSL_TYPE_INT64
:
2801 case GLSL_TYPE_BOOL
: {
2802 unsigned explicit_stride
= encoded
.basic
.explicit_stride
;
2803 if (explicit_stride
== 0xfffff)
2804 explicit_stride
= blob_read_uint32(blob
);
2805 uint32_t vector_elements
= encoded
.basic
.vector_elements
;
2806 if (vector_elements
== 5)
2807 vector_elements
= 8;
2808 else if (vector_elements
== 6)
2809 vector_elements
= 16;
2810 return glsl_type::get_instance(base_type
, encoded
.basic
.vector_elements
,
2811 encoded
.basic
.matrix_columns
,
2813 encoded
.basic
.interface_row_major
);
2815 case GLSL_TYPE_SAMPLER
:
2816 return glsl_type::get_sampler_instance((enum glsl_sampler_dim
)encoded
.sampler
.dimensionality
,
2817 encoded
.sampler
.shadow
,
2818 encoded
.sampler
.array
,
2819 (glsl_base_type
) encoded
.sampler
.sampled_type
);
2820 case GLSL_TYPE_SUBROUTINE
:
2821 return glsl_type::get_subroutine_instance(blob_read_string(blob
));
2822 case GLSL_TYPE_IMAGE
:
2823 return glsl_type::get_image_instance((enum glsl_sampler_dim
)encoded
.sampler
.dimensionality
,
2824 encoded
.sampler
.array
,
2825 (glsl_base_type
) encoded
.sampler
.sampled_type
);
2826 case GLSL_TYPE_ATOMIC_UINT
:
2827 return glsl_type::atomic_uint_type
;
2828 case GLSL_TYPE_ARRAY
: {
2829 unsigned length
= encoded
.array
.length
;
2830 if (length
== 0x1fff)
2831 length
= blob_read_uint32(blob
);
2832 unsigned explicit_stride
= encoded
.array
.explicit_stride
;
2833 if (explicit_stride
== 0x3fff)
2834 explicit_stride
= blob_read_uint32(blob
);
2835 return glsl_type::get_array_instance(decode_type_from_blob(blob
),
2836 length
, explicit_stride
);
2838 case GLSL_TYPE_STRUCT
:
2839 case GLSL_TYPE_INTERFACE
: {
2840 char *name
= blob_read_string(blob
);
2841 unsigned num_fields
= encoded
.strct
.length
;
2842 if (num_fields
== 0xffffff)
2843 num_fields
= blob_read_uint32(blob
);
2845 size_t s_field_size
, s_field_ptrs
;
2846 get_struct_type_field_and_pointer_sizes(&s_field_size
, &s_field_ptrs
);
2848 glsl_struct_field
*fields
=
2849 (glsl_struct_field
*) malloc(s_field_size
* num_fields
);
2850 for (unsigned i
= 0; i
< num_fields
; i
++) {
2851 fields
[i
].type
= decode_type_from_blob(blob
);
2852 fields
[i
].name
= blob_read_string(blob
);
2854 blob_copy_bytes(blob
, ((uint8_t *) &fields
[i
]) + s_field_ptrs
,
2855 s_field_size
- s_field_ptrs
);
2859 if (base_type
== GLSL_TYPE_INTERFACE
) {
2860 enum glsl_interface_packing packing
=
2861 (glsl_interface_packing
) encoded
.strct
.interface_packing_or_packed
;
2862 bool row_major
= encoded
.strct
.interface_row_major
;
2863 t
= glsl_type::get_interface_instance(fields
, num_fields
, packing
,
2866 unsigned packed
= encoded
.strct
.interface_packing_or_packed
;
2867 t
= glsl_type::get_struct_instance(fields
, num_fields
, name
, packed
);
2873 case GLSL_TYPE_VOID
:
2874 return glsl_type::void_type
;
2875 case GLSL_TYPE_ERROR
:
2877 assert(!"Cannot decode type!");
2883 glsl_type::cl_alignment() const
2885 /* vectors unlike arrays are aligned to their size */
2886 if (this->is_scalar() || this->is_vector())
2887 return this->cl_size();
2888 else if (this->is_array())
2889 return this->without_array()->cl_alignment();
2890 else if (this->is_struct()) {
2891 /* Packed Structs are 0x1 aligned despite their size. */
2896 for (unsigned i
= 0; i
< this->length
; ++i
) {
2897 struct glsl_struct_field
&field
= this->fields
.structure
[i
];
2898 res
= MAX2(res
, field
.type
->cl_alignment());
2906 glsl_type::cl_size() const
2908 if (this->is_scalar()) {
2909 return glsl_base_type_get_bit_size(this->base_type
) / 8;
2910 } else if (this->is_vector()) {
2911 unsigned vec_elemns
= this->vector_elements
== 3 ? 4 : this->vector_elements
;
2912 return vec_elemns
* glsl_base_type_get_bit_size(this->base_type
) / 8;
2913 } else if (this->is_array()) {
2914 unsigned size
= this->without_array()->cl_size();
2915 return size
* this->length
;
2916 } else if (this->is_struct()) {
2918 for (unsigned i
= 0; i
< this->length
; ++i
) {
2919 struct glsl_struct_field
&field
= this->fields
.structure
[i
];
2920 /* if a struct is packed, members don't get aligned */
2922 size
= align(size
, field
.type
->cl_alignment());
2923 size
+= field
.type
->cl_size();
2933 glsl_get_sampler_dim_coordinate_components(enum glsl_sampler_dim dim
)
2936 case GLSL_SAMPLER_DIM_1D
:
2937 case GLSL_SAMPLER_DIM_BUF
:
2939 case GLSL_SAMPLER_DIM_2D
:
2940 case GLSL_SAMPLER_DIM_RECT
:
2941 case GLSL_SAMPLER_DIM_MS
:
2942 case GLSL_SAMPLER_DIM_EXTERNAL
:
2943 case GLSL_SAMPLER_DIM_SUBPASS
:
2944 case GLSL_SAMPLER_DIM_SUBPASS_MS
:
2946 case GLSL_SAMPLER_DIM_3D
:
2947 case GLSL_SAMPLER_DIM_CUBE
:
2950 unreachable("Unknown sampler dim");