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 mtx_unlock(&glsl_type::hash_mutex
);
678 return (const glsl_type
*) entry
->data
;
683 /* Treat GLSL vectors as Nx1 matrices.
691 case GLSL_TYPE_FLOAT
:
693 case GLSL_TYPE_FLOAT16
:
695 case GLSL_TYPE_DOUBLE
:
699 case GLSL_TYPE_UINT64
:
701 case GLSL_TYPE_INT64
:
703 case GLSL_TYPE_UINT16
:
705 case GLSL_TYPE_INT16
:
707 case GLSL_TYPE_UINT8
:
715 if ((base_type
!= GLSL_TYPE_FLOAT
&&
716 base_type
!= GLSL_TYPE_DOUBLE
&&
717 base_type
!= GLSL_TYPE_FLOAT16
) || (rows
== 1))
720 /* GLSL matrix types are named mat{COLUMNS}x{ROWS}. Only the following
721 * combinations are valid:
729 #define IDX(c,r) (((c-1)*3) + (r-1))
732 case GLSL_TYPE_DOUBLE
: {
733 switch (IDX(columns
, rows
)) {
734 case IDX(2,2): return dmat2_type
;
735 case IDX(2,3): return dmat2x3_type
;
736 case IDX(2,4): return dmat2x4_type
;
737 case IDX(3,2): return dmat3x2_type
;
738 case IDX(3,3): return dmat3_type
;
739 case IDX(3,4): return dmat3x4_type
;
740 case IDX(4,2): return dmat4x2_type
;
741 case IDX(4,3): return dmat4x3_type
;
742 case IDX(4,4): return dmat4_type
;
743 default: return error_type
;
746 case GLSL_TYPE_FLOAT
: {
747 switch (IDX(columns
, rows
)) {
748 case IDX(2,2): return mat2_type
;
749 case IDX(2,3): return mat2x3_type
;
750 case IDX(2,4): return mat2x4_type
;
751 case IDX(3,2): return mat3x2_type
;
752 case IDX(3,3): return mat3_type
;
753 case IDX(3,4): return mat3x4_type
;
754 case IDX(4,2): return mat4x2_type
;
755 case IDX(4,3): return mat4x3_type
;
756 case IDX(4,4): return mat4_type
;
757 default: return error_type
;
760 case GLSL_TYPE_FLOAT16
: {
761 switch (IDX(columns
, rows
)) {
762 case IDX(2,2): return f16mat2_type
;
763 case IDX(2,3): return f16mat2x3_type
;
764 case IDX(2,4): return f16mat2x4_type
;
765 case IDX(3,2): return f16mat3x2_type
;
766 case IDX(3,3): return f16mat3_type
;
767 case IDX(3,4): return f16mat3x4_type
;
768 case IDX(4,2): return f16mat4x2_type
;
769 case IDX(4,3): return f16mat4x3_type
;
770 case IDX(4,4): return f16mat4_type
;
771 default: return error_type
;
774 default: return error_type
;
778 assert(!"Should not get here.");
783 glsl_type::get_sampler_instance(enum glsl_sampler_dim dim
,
789 case GLSL_TYPE_FLOAT
:
791 case GLSL_SAMPLER_DIM_1D
:
793 return (array
? sampler1DArrayShadow_type
: sampler1DShadow_type
);
795 return (array
? sampler1DArray_type
: sampler1D_type
);
796 case GLSL_SAMPLER_DIM_2D
:
798 return (array
? sampler2DArrayShadow_type
: sampler2DShadow_type
);
800 return (array
? sampler2DArray_type
: sampler2D_type
);
801 case GLSL_SAMPLER_DIM_3D
:
805 return sampler3D_type
;
806 case GLSL_SAMPLER_DIM_CUBE
:
808 return (array
? samplerCubeArrayShadow_type
: samplerCubeShadow_type
);
810 return (array
? samplerCubeArray_type
: samplerCube_type
);
811 case GLSL_SAMPLER_DIM_RECT
:
815 return sampler2DRectShadow_type
;
817 return sampler2DRect_type
;
818 case GLSL_SAMPLER_DIM_BUF
:
822 return samplerBuffer_type
;
823 case GLSL_SAMPLER_DIM_MS
:
826 return (array
? sampler2DMSArray_type
: sampler2DMS_type
);
827 case GLSL_SAMPLER_DIM_EXTERNAL
:
831 return samplerExternalOES_type
;
832 case GLSL_SAMPLER_DIM_SUBPASS
:
833 case GLSL_SAMPLER_DIM_SUBPASS_MS
:
840 case GLSL_SAMPLER_DIM_1D
:
841 return (array
? isampler1DArray_type
: isampler1D_type
);
842 case GLSL_SAMPLER_DIM_2D
:
843 return (array
? isampler2DArray_type
: isampler2D_type
);
844 case GLSL_SAMPLER_DIM_3D
:
847 return isampler3D_type
;
848 case GLSL_SAMPLER_DIM_CUBE
:
849 return (array
? isamplerCubeArray_type
: isamplerCube_type
);
850 case GLSL_SAMPLER_DIM_RECT
:
853 return isampler2DRect_type
;
854 case GLSL_SAMPLER_DIM_BUF
:
857 return isamplerBuffer_type
;
858 case GLSL_SAMPLER_DIM_MS
:
859 return (array
? isampler2DMSArray_type
: isampler2DMS_type
);
860 case GLSL_SAMPLER_DIM_EXTERNAL
:
862 case GLSL_SAMPLER_DIM_SUBPASS
:
863 case GLSL_SAMPLER_DIM_SUBPASS_MS
:
870 case GLSL_SAMPLER_DIM_1D
:
871 return (array
? usampler1DArray_type
: usampler1D_type
);
872 case GLSL_SAMPLER_DIM_2D
:
873 return (array
? usampler2DArray_type
: usampler2D_type
);
874 case GLSL_SAMPLER_DIM_3D
:
877 return usampler3D_type
;
878 case GLSL_SAMPLER_DIM_CUBE
:
879 return (array
? usamplerCubeArray_type
: usamplerCube_type
);
880 case GLSL_SAMPLER_DIM_RECT
:
883 return usampler2DRect_type
;
884 case GLSL_SAMPLER_DIM_BUF
:
887 return usamplerBuffer_type
;
888 case GLSL_SAMPLER_DIM_MS
:
889 return (array
? usampler2DMSArray_type
: usampler2DMS_type
);
890 case GLSL_SAMPLER_DIM_EXTERNAL
:
892 case GLSL_SAMPLER_DIM_SUBPASS
:
893 case GLSL_SAMPLER_DIM_SUBPASS_MS
:
900 unreachable("switch statement above should be complete");
904 glsl_type::get_image_instance(enum glsl_sampler_dim dim
,
905 bool array
, glsl_base_type type
)
908 case GLSL_TYPE_FLOAT
:
910 case GLSL_SAMPLER_DIM_1D
:
911 return (array
? image1DArray_type
: image1D_type
);
912 case GLSL_SAMPLER_DIM_2D
:
913 return (array
? image2DArray_type
: image2D_type
);
914 case GLSL_SAMPLER_DIM_3D
:
916 case GLSL_SAMPLER_DIM_CUBE
:
917 return (array
? imageCubeArray_type
: imageCube_type
);
918 case GLSL_SAMPLER_DIM_RECT
:
922 return image2DRect_type
;
923 case GLSL_SAMPLER_DIM_BUF
:
927 return imageBuffer_type
;
928 case GLSL_SAMPLER_DIM_MS
:
929 return (array
? image2DMSArray_type
: image2DMS_type
);
930 case GLSL_SAMPLER_DIM_SUBPASS
:
931 return subpassInput_type
;
932 case GLSL_SAMPLER_DIM_SUBPASS_MS
:
933 return subpassInputMS_type
;
934 case GLSL_SAMPLER_DIM_EXTERNAL
:
939 case GLSL_SAMPLER_DIM_1D
:
940 return (array
? iimage1DArray_type
: iimage1D_type
);
941 case GLSL_SAMPLER_DIM_2D
:
942 return (array
? iimage2DArray_type
: iimage2D_type
);
943 case GLSL_SAMPLER_DIM_3D
:
946 return iimage3D_type
;
947 case GLSL_SAMPLER_DIM_CUBE
:
948 return (array
? iimageCubeArray_type
: iimageCube_type
);
949 case GLSL_SAMPLER_DIM_RECT
:
952 return iimage2DRect_type
;
953 case GLSL_SAMPLER_DIM_BUF
:
956 return iimageBuffer_type
;
957 case GLSL_SAMPLER_DIM_MS
:
958 return (array
? iimage2DMSArray_type
: iimage2DMS_type
);
959 case GLSL_SAMPLER_DIM_SUBPASS
:
960 return isubpassInput_type
;
961 case GLSL_SAMPLER_DIM_SUBPASS_MS
:
962 return isubpassInputMS_type
;
963 case GLSL_SAMPLER_DIM_EXTERNAL
:
968 case GLSL_SAMPLER_DIM_1D
:
969 return (array
? uimage1DArray_type
: uimage1D_type
);
970 case GLSL_SAMPLER_DIM_2D
:
971 return (array
? uimage2DArray_type
: uimage2D_type
);
972 case GLSL_SAMPLER_DIM_3D
:
975 return uimage3D_type
;
976 case GLSL_SAMPLER_DIM_CUBE
:
977 return (array
? uimageCubeArray_type
: uimageCube_type
);
978 case GLSL_SAMPLER_DIM_RECT
:
981 return uimage2DRect_type
;
982 case GLSL_SAMPLER_DIM_BUF
:
985 return uimageBuffer_type
;
986 case GLSL_SAMPLER_DIM_MS
:
987 return (array
? uimage2DMSArray_type
: uimage2DMS_type
);
988 case GLSL_SAMPLER_DIM_SUBPASS
:
989 return usubpassInput_type
;
990 case GLSL_SAMPLER_DIM_SUBPASS_MS
:
991 return usubpassInputMS_type
;
992 case GLSL_SAMPLER_DIM_EXTERNAL
:
999 unreachable("switch statement above should be complete");
1003 glsl_type::get_array_instance(const glsl_type
*base
,
1004 unsigned array_size
,
1005 unsigned explicit_stride
)
1007 /* Generate a name using the base type pointer in the key. This is
1008 * done because the name of the base type may not be unique across
1009 * shaders. For example, two shaders may have different record types
1013 snprintf(key
, sizeof(key
), "%p[%u]x%uB", (void *) base
, array_size
,
1016 mtx_lock(&glsl_type::hash_mutex
);
1017 assert(glsl_type_users
> 0);
1019 if (array_types
== NULL
) {
1020 array_types
= _mesa_hash_table_create(NULL
, _mesa_hash_string
,
1021 _mesa_key_string_equal
);
1024 const struct hash_entry
*entry
= _mesa_hash_table_search(array_types
, key
);
1025 if (entry
== NULL
) {
1026 const glsl_type
*t
= new glsl_type(base
, array_size
, explicit_stride
);
1028 entry
= _mesa_hash_table_insert(array_types
,
1033 assert(((glsl_type
*) entry
->data
)->base_type
== GLSL_TYPE_ARRAY
);
1034 assert(((glsl_type
*) entry
->data
)->length
== array_size
);
1035 assert(((glsl_type
*) entry
->data
)->fields
.array
== base
);
1037 mtx_unlock(&glsl_type::hash_mutex
);
1039 return (glsl_type
*) entry
->data
;
1043 glsl_type::compare_no_precision(const glsl_type
*b
) const
1048 if (this->is_array()) {
1049 if (!b
->is_array() || this->length
!= b
->length
)
1052 const glsl_type
*b_no_array
= b
->fields
.array
;
1054 return this->fields
.array
->compare_no_precision(b_no_array
);
1057 if (this->is_struct()) {
1058 if (!b
->is_struct())
1060 } else if (this->is_interface()) {
1061 if (!b
->is_interface())
1067 return record_compare(b
,
1068 true, /* match_name */
1069 true, /* match_locations */
1070 false /* match_precision */);
1074 glsl_type::record_compare(const glsl_type
*b
, bool match_name
,
1075 bool match_locations
, bool match_precision
) const
1077 if (this->length
!= b
->length
)
1080 if (this->interface_packing
!= b
->interface_packing
)
1083 if (this->interface_row_major
!= b
->interface_row_major
)
1086 /* From the GLSL 4.20 specification (Sec 4.2):
1088 * "Structures must have the same name, sequence of type names, and
1089 * type definitions, and field names to be considered the same type."
1091 * GLSL ES behaves the same (Ver 1.00 Sec 4.2.4, Ver 3.00 Sec 4.2.5).
1093 * Section 7.4.1 (Shader Interface Matching) of the OpenGL 4.30 spec says:
1095 * "Variables or block members declared as structures are considered
1096 * to match in type if and only if structure members match in name,
1097 * type, qualification, and declaration order."
1100 if (strcmp(this->name
, b
->name
) != 0)
1103 for (unsigned i
= 0; i
< this->length
; i
++) {
1104 if (match_precision
) {
1105 if (this->fields
.structure
[i
].type
!= b
->fields
.structure
[i
].type
)
1108 const glsl_type
*ta
= this->fields
.structure
[i
].type
;
1109 const glsl_type
*tb
= b
->fields
.structure
[i
].type
;
1110 if (!ta
->compare_no_precision(tb
))
1113 if (strcmp(this->fields
.structure
[i
].name
,
1114 b
->fields
.structure
[i
].name
) != 0)
1116 if (this->fields
.structure
[i
].matrix_layout
1117 != b
->fields
.structure
[i
].matrix_layout
)
1119 if (match_locations
&& this->fields
.structure
[i
].location
1120 != b
->fields
.structure
[i
].location
)
1122 if (this->fields
.structure
[i
].offset
1123 != b
->fields
.structure
[i
].offset
)
1125 if (this->fields
.structure
[i
].interpolation
1126 != b
->fields
.structure
[i
].interpolation
)
1128 if (this->fields
.structure
[i
].centroid
1129 != b
->fields
.structure
[i
].centroid
)
1131 if (this->fields
.structure
[i
].sample
1132 != b
->fields
.structure
[i
].sample
)
1134 if (this->fields
.structure
[i
].patch
1135 != b
->fields
.structure
[i
].patch
)
1137 if (this->fields
.structure
[i
].memory_read_only
1138 != b
->fields
.structure
[i
].memory_read_only
)
1140 if (this->fields
.structure
[i
].memory_write_only
1141 != b
->fields
.structure
[i
].memory_write_only
)
1143 if (this->fields
.structure
[i
].memory_coherent
1144 != b
->fields
.structure
[i
].memory_coherent
)
1146 if (this->fields
.structure
[i
].memory_volatile
1147 != b
->fields
.structure
[i
].memory_volatile
)
1149 if (this->fields
.structure
[i
].memory_restrict
1150 != b
->fields
.structure
[i
].memory_restrict
)
1152 if (this->fields
.structure
[i
].image_format
1153 != b
->fields
.structure
[i
].image_format
)
1155 if (match_precision
&&
1156 this->fields
.structure
[i
].precision
1157 != b
->fields
.structure
[i
].precision
)
1159 if (this->fields
.structure
[i
].explicit_xfb_buffer
1160 != b
->fields
.structure
[i
].explicit_xfb_buffer
)
1162 if (this->fields
.structure
[i
].xfb_buffer
1163 != b
->fields
.structure
[i
].xfb_buffer
)
1165 if (this->fields
.structure
[i
].xfb_stride
1166 != b
->fields
.structure
[i
].xfb_stride
)
1175 glsl_type::record_key_compare(const void *a
, const void *b
)
1177 const glsl_type
*const key1
= (glsl_type
*) a
;
1178 const glsl_type
*const key2
= (glsl_type
*) b
;
1180 return strcmp(key1
->name
, key2
->name
) == 0 &&
1181 key1
->record_compare(key2
, true);
1186 * Generate an integer hash value for a glsl_type structure type.
1189 glsl_type::record_key_hash(const void *a
)
1191 const glsl_type
*const key
= (glsl_type
*) a
;
1192 uintptr_t hash
= key
->length
;
1195 for (unsigned i
= 0; i
< key
->length
; i
++) {
1196 /* casting pointer to uintptr_t */
1197 hash
= (hash
* 13 ) + (uintptr_t) key
->fields
.structure
[i
].type
;
1200 if (sizeof(hash
) == 8)
1201 retval
= (hash
& 0xffffffff) ^ ((uint64_t) hash
>> 32);
1210 glsl_type::get_struct_instance(const glsl_struct_field
*fields
,
1211 unsigned num_fields
,
1215 const glsl_type
key(fields
, num_fields
, name
, packed
);
1217 mtx_lock(&glsl_type::hash_mutex
);
1218 assert(glsl_type_users
> 0);
1220 if (struct_types
== NULL
) {
1221 struct_types
= _mesa_hash_table_create(NULL
, record_key_hash
,
1222 record_key_compare
);
1225 const struct hash_entry
*entry
= _mesa_hash_table_search(struct_types
,
1227 if (entry
== NULL
) {
1228 const glsl_type
*t
= new glsl_type(fields
, num_fields
, name
, packed
);
1230 entry
= _mesa_hash_table_insert(struct_types
, t
, (void *) t
);
1233 assert(((glsl_type
*) entry
->data
)->base_type
== GLSL_TYPE_STRUCT
);
1234 assert(((glsl_type
*) entry
->data
)->length
== num_fields
);
1235 assert(strcmp(((glsl_type
*) entry
->data
)->name
, name
) == 0);
1236 assert(((glsl_type
*) entry
->data
)->packed
== packed
);
1238 mtx_unlock(&glsl_type::hash_mutex
);
1240 return (glsl_type
*) entry
->data
;
1245 glsl_type::get_interface_instance(const glsl_struct_field
*fields
,
1246 unsigned num_fields
,
1247 enum glsl_interface_packing packing
,
1249 const char *block_name
)
1251 const glsl_type
key(fields
, num_fields
, packing
, row_major
, block_name
);
1253 mtx_lock(&glsl_type::hash_mutex
);
1254 assert(glsl_type_users
> 0);
1256 if (interface_types
== NULL
) {
1257 interface_types
= _mesa_hash_table_create(NULL
, record_key_hash
,
1258 record_key_compare
);
1261 const struct hash_entry
*entry
= _mesa_hash_table_search(interface_types
,
1263 if (entry
== NULL
) {
1264 const glsl_type
*t
= new glsl_type(fields
, num_fields
,
1265 packing
, row_major
, block_name
);
1267 entry
= _mesa_hash_table_insert(interface_types
, t
, (void *) t
);
1270 assert(((glsl_type
*) entry
->data
)->base_type
== GLSL_TYPE_INTERFACE
);
1271 assert(((glsl_type
*) entry
->data
)->length
== num_fields
);
1272 assert(strcmp(((glsl_type
*) entry
->data
)->name
, block_name
) == 0);
1274 mtx_unlock(&glsl_type::hash_mutex
);
1276 return (glsl_type
*) entry
->data
;
1280 glsl_type::get_subroutine_instance(const char *subroutine_name
)
1282 const glsl_type
key(subroutine_name
);
1284 mtx_lock(&glsl_type::hash_mutex
);
1285 assert(glsl_type_users
> 0);
1287 if (subroutine_types
== NULL
) {
1288 subroutine_types
= _mesa_hash_table_create(NULL
, record_key_hash
,
1289 record_key_compare
);
1292 const struct hash_entry
*entry
= _mesa_hash_table_search(subroutine_types
,
1294 if (entry
== NULL
) {
1295 const glsl_type
*t
= new glsl_type(subroutine_name
);
1297 entry
= _mesa_hash_table_insert(subroutine_types
, t
, (void *) t
);
1300 assert(((glsl_type
*) entry
->data
)->base_type
== GLSL_TYPE_SUBROUTINE
);
1301 assert(strcmp(((glsl_type
*) entry
->data
)->name
, subroutine_name
) == 0);
1303 mtx_unlock(&glsl_type::hash_mutex
);
1305 return (glsl_type
*) entry
->data
;
1310 function_key_compare(const void *a
, const void *b
)
1312 const glsl_type
*const key1
= (glsl_type
*) a
;
1313 const glsl_type
*const key2
= (glsl_type
*) b
;
1315 if (key1
->length
!= key2
->length
)
1318 return memcmp(key1
->fields
.parameters
, key2
->fields
.parameters
,
1319 (key1
->length
+ 1) * sizeof(*key1
->fields
.parameters
)) == 0;
1324 function_key_hash(const void *a
)
1326 const glsl_type
*const key
= (glsl_type
*) a
;
1327 return _mesa_hash_data(key
->fields
.parameters
,
1328 (key
->length
+ 1) * sizeof(*key
->fields
.parameters
));
1332 glsl_type::get_function_instance(const glsl_type
*return_type
,
1333 const glsl_function_param
*params
,
1334 unsigned num_params
)
1336 const glsl_type
key(return_type
, params
, num_params
);
1338 mtx_lock(&glsl_type::hash_mutex
);
1339 assert(glsl_type_users
> 0);
1341 if (function_types
== NULL
) {
1342 function_types
= _mesa_hash_table_create(NULL
, function_key_hash
,
1343 function_key_compare
);
1346 struct hash_entry
*entry
= _mesa_hash_table_search(function_types
, &key
);
1347 if (entry
== NULL
) {
1348 const glsl_type
*t
= new glsl_type(return_type
, params
, num_params
);
1350 entry
= _mesa_hash_table_insert(function_types
, t
, (void *) t
);
1353 const glsl_type
*t
= (const glsl_type
*)entry
->data
;
1355 assert(t
->base_type
== GLSL_TYPE_FUNCTION
);
1356 assert(t
->length
== num_params
);
1358 mtx_unlock(&glsl_type::hash_mutex
);
1365 glsl_type::get_mul_type(const glsl_type
*type_a
, const glsl_type
*type_b
)
1367 if (type_a
->is_matrix() && type_b
->is_matrix()) {
1368 /* Matrix multiply. The columns of A must match the rows of B. Given
1369 * the other previously tested constraints, this means the vector type
1370 * of a row from A must be the same as the vector type of a column from
1373 if (type_a
->row_type() == type_b
->column_type()) {
1374 /* The resulting matrix has the number of columns of matrix B and
1375 * the number of rows of matrix A. We get the row count of A by
1376 * looking at the size of a vector that makes up a column. The
1377 * transpose (size of a row) is done for B.
1379 const glsl_type
*const type
=
1380 get_instance(type_a
->base_type
,
1381 type_a
->column_type()->vector_elements
,
1382 type_b
->row_type()->vector_elements
);
1383 assert(type
!= error_type
);
1387 } else if (type_a
== type_b
) {
1389 } else if (type_a
->is_matrix()) {
1390 /* A is a matrix and B is a column vector. Columns of A must match
1391 * rows of B. Given the other previously tested constraints, this
1392 * means the vector type of a row from A must be the same as the
1393 * vector the type of B.
1395 if (type_a
->row_type() == type_b
) {
1396 /* The resulting vector has a number of elements equal to
1397 * the number of rows of matrix A. */
1398 const glsl_type
*const type
=
1399 get_instance(type_a
->base_type
,
1400 type_a
->column_type()->vector_elements
,
1402 assert(type
!= error_type
);
1407 assert(type_b
->is_matrix());
1409 /* A is a row vector and B is a matrix. Columns of A must match rows
1410 * of B. Given the other previously tested constraints, this means
1411 * the type of A must be the same as the vector type of a column from
1414 if (type_a
== type_b
->column_type()) {
1415 /* The resulting vector has a number of elements equal to
1416 * the number of columns of matrix B. */
1417 const glsl_type
*const type
=
1418 get_instance(type_a
->base_type
,
1419 type_b
->row_type()->vector_elements
,
1421 assert(type
!= error_type
);
1432 glsl_type::field_type(const char *name
) const
1434 if (this->base_type
!= GLSL_TYPE_STRUCT
1435 && this->base_type
!= GLSL_TYPE_INTERFACE
)
1438 for (unsigned i
= 0; i
< this->length
; i
++) {
1439 if (strcmp(name
, this->fields
.structure
[i
].name
) == 0)
1440 return this->fields
.structure
[i
].type
;
1448 glsl_type::field_index(const char *name
) const
1450 if (this->base_type
!= GLSL_TYPE_STRUCT
1451 && this->base_type
!= GLSL_TYPE_INTERFACE
)
1454 for (unsigned i
= 0; i
< this->length
; i
++) {
1455 if (strcmp(name
, this->fields
.structure
[i
].name
) == 0)
1464 glsl_type::component_slots() const
1466 switch (this->base_type
) {
1467 case GLSL_TYPE_UINT
:
1469 case GLSL_TYPE_UINT8
:
1470 case GLSL_TYPE_INT8
:
1471 case GLSL_TYPE_UINT16
:
1472 case GLSL_TYPE_INT16
:
1473 case GLSL_TYPE_FLOAT
:
1474 case GLSL_TYPE_FLOAT16
:
1475 case GLSL_TYPE_BOOL
:
1476 return this->components();
1478 case GLSL_TYPE_DOUBLE
:
1479 case GLSL_TYPE_UINT64
:
1480 case GLSL_TYPE_INT64
:
1481 return 2 * this->components();
1483 case GLSL_TYPE_STRUCT
:
1484 case GLSL_TYPE_INTERFACE
: {
1487 for (unsigned i
= 0; i
< this->length
; i
++)
1488 size
+= this->fields
.structure
[i
].type
->component_slots();
1493 case GLSL_TYPE_ARRAY
:
1494 return this->length
* this->fields
.array
->component_slots();
1496 case GLSL_TYPE_SAMPLER
:
1497 case GLSL_TYPE_IMAGE
:
1500 case GLSL_TYPE_SUBROUTINE
:
1503 case GLSL_TYPE_FUNCTION
:
1504 case GLSL_TYPE_ATOMIC_UINT
:
1505 case GLSL_TYPE_VOID
:
1506 case GLSL_TYPE_ERROR
:
1514 glsl_type::struct_location_offset(unsigned length
) const
1516 unsigned offset
= 0;
1517 const glsl_type
*t
= this->without_array();
1518 if (t
->is_struct()) {
1519 assert(length
<= t
->length
);
1521 for (unsigned i
= 0; i
< length
; i
++) {
1522 const glsl_type
*st
= t
->fields
.structure
[i
].type
;
1523 const glsl_type
*wa
= st
->without_array();
1524 if (wa
->is_struct()) {
1525 unsigned r_offset
= wa
->struct_location_offset(wa
->length
);
1526 offset
+= st
->is_array() ?
1527 st
->arrays_of_arrays_size() * r_offset
: r_offset
;
1528 } else if (st
->is_array() && st
->fields
.array
->is_array()) {
1529 unsigned outer_array_size
= st
->length
;
1530 const glsl_type
*base_type
= st
->fields
.array
;
1532 /* For arrays of arrays the outer arrays take up a uniform
1533 * slot for each element. The innermost array elements share a
1534 * single slot so we ignore the innermost array when calculating
1537 while (base_type
->fields
.array
->is_array()) {
1538 outer_array_size
= outer_array_size
* base_type
->length
;
1539 base_type
= base_type
->fields
.array
;
1541 offset
+= outer_array_size
;
1543 /* We dont worry about arrays here because unless the array
1544 * contains a structure or another array it only takes up a single
1555 glsl_type::uniform_locations() const
1559 switch (this->base_type
) {
1560 case GLSL_TYPE_UINT
:
1562 case GLSL_TYPE_FLOAT
:
1563 case GLSL_TYPE_FLOAT16
:
1564 case GLSL_TYPE_DOUBLE
:
1565 case GLSL_TYPE_UINT16
:
1566 case GLSL_TYPE_UINT8
:
1567 case GLSL_TYPE_INT16
:
1568 case GLSL_TYPE_INT8
:
1569 case GLSL_TYPE_UINT64
:
1570 case GLSL_TYPE_INT64
:
1571 case GLSL_TYPE_BOOL
:
1572 case GLSL_TYPE_SAMPLER
:
1573 case GLSL_TYPE_IMAGE
:
1574 case GLSL_TYPE_SUBROUTINE
:
1577 case GLSL_TYPE_STRUCT
:
1578 case GLSL_TYPE_INTERFACE
:
1579 for (unsigned i
= 0; i
< this->length
; i
++)
1580 size
+= this->fields
.structure
[i
].type
->uniform_locations();
1582 case GLSL_TYPE_ARRAY
:
1583 return this->length
* this->fields
.array
->uniform_locations();
1590 glsl_type::varying_count() const
1594 switch (this->base_type
) {
1595 case GLSL_TYPE_UINT
:
1597 case GLSL_TYPE_FLOAT
:
1598 case GLSL_TYPE_FLOAT16
:
1599 case GLSL_TYPE_DOUBLE
:
1600 case GLSL_TYPE_BOOL
:
1601 case GLSL_TYPE_UINT16
:
1602 case GLSL_TYPE_UINT8
:
1603 case GLSL_TYPE_INT16
:
1604 case GLSL_TYPE_INT8
:
1605 case GLSL_TYPE_UINT64
:
1606 case GLSL_TYPE_INT64
:
1609 case GLSL_TYPE_STRUCT
:
1610 case GLSL_TYPE_INTERFACE
:
1611 for (unsigned i
= 0; i
< this->length
; i
++)
1612 size
+= this->fields
.structure
[i
].type
->varying_count();
1614 case GLSL_TYPE_ARRAY
:
1615 /* Don't count innermost array elements */
1616 if (this->without_array()->is_struct() ||
1617 this->without_array()->is_interface() ||
1618 this->fields
.array
->is_array())
1619 return this->length
* this->fields
.array
->varying_count();
1621 return this->fields
.array
->varying_count();
1623 assert(!"unsupported varying type");
1629 glsl_type::can_implicitly_convert_to(const glsl_type
*desired
,
1630 _mesa_glsl_parse_state
*state
) const
1632 if (this == desired
)
1635 /* GLSL 1.10 and ESSL do not allow implicit conversions. If there is no
1636 * state, we're doing intra-stage function linking where these checks have
1637 * already been done.
1639 if (state
&& !state
->has_implicit_conversions())
1642 /* There is no conversion among matrix types. */
1643 if (this->matrix_columns
> 1 || desired
->matrix_columns
> 1)
1646 /* Vector size must match. */
1647 if (this->vector_elements
!= desired
->vector_elements
)
1650 /* int and uint can be converted to float. */
1651 if (desired
->is_float() && this->is_integer_32())
1654 /* With GLSL 4.0, ARB_gpu_shader5, or MESA_shader_integer_functions, int
1655 * can be converted to uint. Note that state may be NULL here, when
1656 * resolving function calls in the linker. By this time, all the
1657 * state-dependent checks have already happened though, so allow anything
1658 * that's allowed in any shader version.
1660 if ((!state
|| state
->has_implicit_uint_to_int_conversion()) &&
1661 desired
->base_type
== GLSL_TYPE_UINT
&& this->base_type
== GLSL_TYPE_INT
)
1664 /* No implicit conversions from double. */
1665 if ((!state
|| state
->has_double()) && this->is_double())
1668 /* Conversions from different types to double. */
1669 if ((!state
|| state
->has_double()) && desired
->is_double()) {
1670 if (this->is_float())
1672 if (this->is_integer_32())
1680 glsl_type::std140_base_alignment(bool row_major
) const
1682 unsigned N
= is_64bit() ? 8 : 4;
1684 /* (1) If the member is a scalar consuming <N> basic machine units, the
1685 * base alignment is <N>.
1687 * (2) If the member is a two- or four-component vector with components
1688 * consuming <N> basic machine units, the base alignment is 2<N> or
1689 * 4<N>, respectively.
1691 * (3) If the member is a three-component vector with components consuming
1692 * <N> basic machine units, the base alignment is 4<N>.
1694 if (this->is_scalar() || this->is_vector()) {
1695 switch (this->vector_elements
) {
1706 /* (4) If the member is an array of scalars or vectors, the base alignment
1707 * and array stride are set to match the base alignment of a single
1708 * array element, according to rules (1), (2), and (3), and rounded up
1709 * to the base alignment of a vec4. The array may have padding at the
1710 * end; the base offset of the member following the array is rounded up
1711 * to the next multiple of the base alignment.
1713 * (6) If the member is an array of <S> column-major matrices with <C>
1714 * columns and <R> rows, the matrix is stored identically to a row of
1715 * <S>*<C> column vectors with <R> components each, according to rule
1718 * (8) If the member is an array of <S> row-major matrices with <C> columns
1719 * and <R> rows, the matrix is stored identically to a row of <S>*<R>
1720 * row vectors with <C> components each, according to rule (4).
1722 * (10) If the member is an array of <S> structures, the <S> elements of
1723 * the array are laid out in order, according to rule (9).
1725 if (this->is_array()) {
1726 if (this->fields
.array
->is_scalar() ||
1727 this->fields
.array
->is_vector() ||
1728 this->fields
.array
->is_matrix()) {
1729 return MAX2(this->fields
.array
->std140_base_alignment(row_major
), 16);
1731 assert(this->fields
.array
->is_struct() ||
1732 this->fields
.array
->is_array());
1733 return this->fields
.array
->std140_base_alignment(row_major
);
1737 /* (5) If the member is a column-major matrix with <C> columns and
1738 * <R> rows, the matrix is stored identically to an array of
1739 * <C> column vectors with <R> components each, according to
1742 * (7) If the member is a row-major matrix with <C> columns and <R>
1743 * rows, the matrix is stored identically to an array of <R>
1744 * row vectors with <C> components each, according to rule (4).
1746 if (this->is_matrix()) {
1747 const struct glsl_type
*vec_type
, *array_type
;
1748 int c
= this->matrix_columns
;
1749 int r
= this->vector_elements
;
1752 vec_type
= get_instance(base_type
, c
, 1);
1753 array_type
= glsl_type::get_array_instance(vec_type
, r
);
1755 vec_type
= get_instance(base_type
, r
, 1);
1756 array_type
= glsl_type::get_array_instance(vec_type
, c
);
1759 return array_type
->std140_base_alignment(false);
1762 /* (9) If the member is a structure, the base alignment of the
1763 * structure is <N>, where <N> is the largest base alignment
1764 * value of any of its members, and rounded up to the base
1765 * alignment of a vec4. The individual members of this
1766 * sub-structure are then assigned offsets by applying this set
1767 * of rules recursively, where the base offset of the first
1768 * member of the sub-structure is equal to the aligned offset
1769 * of the structure. The structure may have padding at the end;
1770 * the base offset of the member following the sub-structure is
1771 * rounded up to the next multiple of the base alignment of the
1774 if (this->is_struct()) {
1775 unsigned base_alignment
= 16;
1776 for (unsigned i
= 0; i
< this->length
; i
++) {
1777 bool field_row_major
= row_major
;
1778 const enum glsl_matrix_layout matrix_layout
=
1779 glsl_matrix_layout(this->fields
.structure
[i
].matrix_layout
);
1780 if (matrix_layout
== GLSL_MATRIX_LAYOUT_ROW_MAJOR
) {
1781 field_row_major
= true;
1782 } else if (matrix_layout
== GLSL_MATRIX_LAYOUT_COLUMN_MAJOR
) {
1783 field_row_major
= false;
1786 const struct glsl_type
*field_type
= this->fields
.structure
[i
].type
;
1787 base_alignment
= MAX2(base_alignment
,
1788 field_type
->std140_base_alignment(field_row_major
));
1790 return base_alignment
;
1793 assert(!"not reached");
1798 glsl_type::std140_size(bool row_major
) const
1800 unsigned N
= is_64bit() ? 8 : 4;
1802 /* (1) If the member is a scalar consuming <N> basic machine units, the
1803 * base alignment is <N>.
1805 * (2) If the member is a two- or four-component vector with components
1806 * consuming <N> basic machine units, the base alignment is 2<N> or
1807 * 4<N>, respectively.
1809 * (3) If the member is a three-component vector with components consuming
1810 * <N> basic machine units, the base alignment is 4<N>.
1812 if (this->is_scalar() || this->is_vector()) {
1813 assert(this->explicit_stride
== 0);
1814 return this->vector_elements
* N
;
1817 /* (5) If the member is a column-major matrix with <C> columns and
1818 * <R> rows, the matrix is stored identically to an array of
1819 * <C> column vectors with <R> components each, according to
1822 * (6) If the member is an array of <S> column-major matrices with <C>
1823 * columns and <R> rows, the matrix is stored identically to a row of
1824 * <S>*<C> column vectors with <R> components each, according to rule
1827 * (7) If the member is a row-major matrix with <C> columns and <R>
1828 * rows, the matrix is stored identically to an array of <R>
1829 * row vectors with <C> components each, according to rule (4).
1831 * (8) If the member is an array of <S> row-major matrices with <C> columns
1832 * and <R> rows, the matrix is stored identically to a row of <S>*<R>
1833 * row vectors with <C> components each, according to rule (4).
1835 if (this->without_array()->is_matrix()) {
1836 const struct glsl_type
*element_type
;
1837 const struct glsl_type
*vec_type
;
1838 unsigned int array_len
;
1840 if (this->is_array()) {
1841 element_type
= this->without_array();
1842 array_len
= this->arrays_of_arrays_size();
1844 element_type
= this;
1849 vec_type
= get_instance(element_type
->base_type
,
1850 element_type
->matrix_columns
, 1);
1852 array_len
*= element_type
->vector_elements
;
1854 vec_type
= get_instance(element_type
->base_type
,
1855 element_type
->vector_elements
, 1);
1856 array_len
*= element_type
->matrix_columns
;
1858 const glsl_type
*array_type
= glsl_type::get_array_instance(vec_type
,
1861 return array_type
->std140_size(false);
1864 /* (4) If the member is an array of scalars or vectors, the base alignment
1865 * and array stride are set to match the base alignment of a single
1866 * array element, according to rules (1), (2), and (3), and rounded up
1867 * to the base alignment of a vec4. The array may have padding at the
1868 * end; the base offset of the member following the array is rounded up
1869 * to the next multiple of the base alignment.
1871 * (10) If the member is an array of <S> structures, the <S> elements of
1872 * the array are laid out in order, according to rule (9).
1874 if (this->is_array()) {
1876 if (this->without_array()->is_struct()) {
1877 stride
= this->without_array()->std140_size(row_major
);
1879 unsigned element_base_align
=
1880 this->without_array()->std140_base_alignment(row_major
);
1881 stride
= MAX2(element_base_align
, 16);
1884 unsigned size
= this->arrays_of_arrays_size() * stride
;
1885 assert(this->explicit_stride
== 0 ||
1886 size
== this->length
* this->explicit_stride
);
1890 /* (9) If the member is a structure, the base alignment of the
1891 * structure is <N>, where <N> is the largest base alignment
1892 * value of any of its members, and rounded up to the base
1893 * alignment of a vec4. The individual members of this
1894 * sub-structure are then assigned offsets by applying this set
1895 * of rules recursively, where the base offset of the first
1896 * member of the sub-structure is equal to the aligned offset
1897 * of the structure. The structure may have padding at the end;
1898 * the base offset of the member following the sub-structure is
1899 * rounded up to the next multiple of the base alignment of the
1902 if (this->is_struct() || this->is_interface()) {
1904 unsigned max_align
= 0;
1906 for (unsigned i
= 0; i
< this->length
; i
++) {
1907 bool field_row_major
= row_major
;
1908 const enum glsl_matrix_layout matrix_layout
=
1909 glsl_matrix_layout(this->fields
.structure
[i
].matrix_layout
);
1910 if (matrix_layout
== GLSL_MATRIX_LAYOUT_ROW_MAJOR
) {
1911 field_row_major
= true;
1912 } else if (matrix_layout
== GLSL_MATRIX_LAYOUT_COLUMN_MAJOR
) {
1913 field_row_major
= false;
1916 const struct glsl_type
*field_type
= this->fields
.structure
[i
].type
;
1917 unsigned align
= field_type
->std140_base_alignment(field_row_major
);
1919 /* Ignore unsized arrays when calculating size */
1920 if (field_type
->is_unsized_array())
1923 size
= glsl_align(size
, align
);
1924 size
+= field_type
->std140_size(field_row_major
);
1926 max_align
= MAX2(align
, max_align
);
1928 if (field_type
->is_struct() && (i
+ 1 < this->length
))
1929 size
= glsl_align(size
, 16);
1931 size
= glsl_align(size
, MAX2(max_align
, 16));
1935 assert(!"not reached");
1940 glsl_type::get_explicit_std140_type(bool row_major
) const
1942 if (this->is_vector() || this->is_scalar()) {
1944 } else if (this->is_matrix()) {
1945 const glsl_type
*vec_type
;
1947 vec_type
= get_instance(this->base_type
, this->matrix_columns
, 1);
1949 vec_type
= get_instance(this->base_type
, this->vector_elements
, 1);
1950 unsigned elem_size
= vec_type
->std140_size(false);
1951 unsigned stride
= glsl_align(elem_size
, 16);
1952 return get_instance(this->base_type
, this->vector_elements
,
1953 this->matrix_columns
, stride
, row_major
);
1954 } else if (this->is_array()) {
1955 unsigned elem_size
= this->fields
.array
->std140_size(row_major
);
1956 const glsl_type
*elem_type
=
1957 this->fields
.array
->get_explicit_std140_type(row_major
);
1958 unsigned stride
= glsl_align(elem_size
, 16);
1959 return get_array_instance(elem_type
, this->length
, stride
);
1960 } else if (this->is_struct() || this->is_interface()) {
1961 glsl_struct_field
*fields
= new glsl_struct_field
[this->length
];
1962 unsigned offset
= 0;
1963 for (unsigned i
= 0; i
< length
; i
++) {
1964 fields
[i
] = this->fields
.structure
[i
];
1966 bool field_row_major
= row_major
;
1967 if (fields
[i
].matrix_layout
== GLSL_MATRIX_LAYOUT_COLUMN_MAJOR
) {
1968 field_row_major
= false;
1969 } else if (fields
[i
].matrix_layout
== GLSL_MATRIX_LAYOUT_ROW_MAJOR
) {
1970 field_row_major
= true;
1973 fields
[i
].type
->get_explicit_std140_type(field_row_major
);
1975 unsigned fsize
= fields
[i
].type
->std140_size(field_row_major
);
1976 unsigned falign
= fields
[i
].type
->std140_base_alignment(field_row_major
);
1977 /* From the GLSL 460 spec section "Uniform and Shader Storage Block
1978 * Layout Qualifiers":
1980 * "The actual offset of a member is computed as follows: If
1981 * offset was declared, start with that offset, otherwise start
1982 * with the next available offset. If the resulting offset is not
1983 * a multiple of the actual alignment, increase it to the first
1984 * offset that is a multiple of the actual alignment. This results
1985 * in the actual offset the member will have."
1987 if (fields
[i
].offset
>= 0) {
1988 assert((unsigned)fields
[i
].offset
>= offset
);
1989 offset
= fields
[i
].offset
;
1991 offset
= glsl_align(offset
, falign
);
1992 fields
[i
].offset
= offset
;
1996 const glsl_type
*type
;
1997 if (this->is_struct())
1998 type
= get_struct_instance(fields
, this->length
, this->name
);
2000 type
= get_interface_instance(fields
, this->length
,
2001 (enum glsl_interface_packing
)this->interface_packing
,
2002 this->interface_row_major
,
2008 unreachable("Invalid type for UBO or SSBO");
2013 glsl_type::std430_base_alignment(bool row_major
) const
2016 unsigned N
= is_64bit() ? 8 : 4;
2018 /* (1) If the member is a scalar consuming <N> basic machine units, the
2019 * base alignment is <N>.
2021 * (2) If the member is a two- or four-component vector with components
2022 * consuming <N> basic machine units, the base alignment is 2<N> or
2023 * 4<N>, respectively.
2025 * (3) If the member is a three-component vector with components consuming
2026 * <N> basic machine units, the base alignment is 4<N>.
2028 if (this->is_scalar() || this->is_vector()) {
2029 switch (this->vector_elements
) {
2040 /* OpenGL 4.30 spec, section 7.6.2.2 "Standard Uniform Block Layout":
2042 * "When using the std430 storage layout, shader storage blocks will be
2043 * laid out in buffer storage identically to uniform and shader storage
2044 * blocks using the std140 layout, except that the base alignment and
2045 * stride of arrays of scalars and vectors in rule 4 and of structures
2046 * in rule 9 are not rounded up a multiple of the base alignment of a vec4.
2049 /* (1) If the member is a scalar consuming <N> basic machine units, the
2050 * base alignment is <N>.
2052 * (2) If the member is a two- or four-component vector with components
2053 * consuming <N> basic machine units, the base alignment is 2<N> or
2054 * 4<N>, respectively.
2056 * (3) If the member is a three-component vector with components consuming
2057 * <N> basic machine units, the base alignment is 4<N>.
2059 if (this->is_array())
2060 return this->fields
.array
->std430_base_alignment(row_major
);
2062 /* (5) If the member is a column-major matrix with <C> columns and
2063 * <R> rows, the matrix is stored identically to an array of
2064 * <C> column vectors with <R> components each, according to
2067 * (7) If the member is a row-major matrix with <C> columns and <R>
2068 * rows, the matrix is stored identically to an array of <R>
2069 * row vectors with <C> components each, according to rule (4).
2071 if (this->is_matrix()) {
2072 const struct glsl_type
*vec_type
, *array_type
;
2073 int c
= this->matrix_columns
;
2074 int r
= this->vector_elements
;
2077 vec_type
= get_instance(base_type
, c
, 1);
2078 array_type
= glsl_type::get_array_instance(vec_type
, r
);
2080 vec_type
= get_instance(base_type
, r
, 1);
2081 array_type
= glsl_type::get_array_instance(vec_type
, c
);
2084 return array_type
->std430_base_alignment(false);
2087 /* (9) If the member is a structure, the base alignment of the
2088 * structure is <N>, where <N> is the largest base alignment
2089 * value of any of its members, and rounded up to the base
2090 * alignment of a vec4. The individual members of this
2091 * sub-structure are then assigned offsets by applying this set
2092 * of rules recursively, where the base offset of the first
2093 * member of the sub-structure is equal to the aligned offset
2094 * of the structure. The structure may have padding at the end;
2095 * the base offset of the member following the sub-structure is
2096 * rounded up to the next multiple of the base alignment of the
2099 if (this->is_struct()) {
2100 unsigned base_alignment
= 0;
2101 for (unsigned i
= 0; i
< this->length
; i
++) {
2102 bool field_row_major
= row_major
;
2103 const enum glsl_matrix_layout matrix_layout
=
2104 glsl_matrix_layout(this->fields
.structure
[i
].matrix_layout
);
2105 if (matrix_layout
== GLSL_MATRIX_LAYOUT_ROW_MAJOR
) {
2106 field_row_major
= true;
2107 } else if (matrix_layout
== GLSL_MATRIX_LAYOUT_COLUMN_MAJOR
) {
2108 field_row_major
= false;
2111 const struct glsl_type
*field_type
= this->fields
.structure
[i
].type
;
2112 base_alignment
= MAX2(base_alignment
,
2113 field_type
->std430_base_alignment(field_row_major
));
2115 assert(base_alignment
> 0);
2116 return base_alignment
;
2118 assert(!"not reached");
2123 glsl_type::std430_array_stride(bool row_major
) const
2125 unsigned N
= is_64bit() ? 8 : 4;
2127 /* Notice that the array stride of a vec3 is not 3 * N but 4 * N.
2128 * See OpenGL 4.30 spec, section 7.6.2.2 "Standard Uniform Block Layout"
2130 * (3) If the member is a three-component vector with components consuming
2131 * <N> basic machine units, the base alignment is 4<N>.
2133 if (this->is_vector() && this->vector_elements
== 3)
2136 /* By default use std430_size(row_major) */
2137 unsigned stride
= this->std430_size(row_major
);
2138 assert(this->explicit_stride
== 0 || this->explicit_stride
== stride
);
2142 /* Note that the value returned by this method is only correct if the
2143 * explit offset, and stride values are set, so only with SPIR-V shaders.
2144 * Should not be used with GLSL shaders.
2148 glsl_type::explicit_size(bool align_to_stride
) const
2150 if (this->is_struct() || this->is_interface()) {
2151 if (this->length
> 0) {
2154 for (unsigned i
= 0; i
< this->length
; i
++) {
2155 assert(this->fields
.structure
[i
].offset
>= 0);
2156 unsigned last_byte
= this->fields
.structure
[i
].offset
+
2157 this->fields
.structure
[i
].type
->explicit_size();
2158 size
= MAX2(size
, last_byte
);
2165 } else if (this->is_array()) {
2166 /* From ARB_program_interface_query spec:
2168 * "For the property of BUFFER_DATA_SIZE, then the implementation-dependent
2169 * minimum total buffer object size, in basic machine units, required to
2170 * hold all active variables associated with an active uniform block, shader
2171 * storage block, or atomic counter buffer is written to <params>. If the
2172 * final member of an active shader storage block is array with no declared
2173 * size, the minimum buffer size is computed assuming the array was declared
2174 * as an array with one element."
2177 if (this->is_unsized_array())
2178 return this->explicit_stride
;
2180 assert(this->length
> 0);
2181 unsigned elem_size
= align_to_stride
? this->explicit_stride
: this->fields
.array
->explicit_size();
2182 assert(this->explicit_stride
>= elem_size
);
2184 return this->explicit_stride
* (this->length
- 1) + elem_size
;
2185 } else if (this->is_matrix()) {
2186 const struct glsl_type
*elem_type
;
2189 if (this->interface_row_major
) {
2190 elem_type
= get_instance(this->base_type
,
2191 this->matrix_columns
, 1);
2192 length
= this->vector_elements
;
2194 elem_type
= get_instance(this->base_type
,
2195 this->vector_elements
, 1);
2196 length
= this->matrix_columns
;
2199 unsigned elem_size
= align_to_stride
? this->explicit_stride
: elem_type
->explicit_size();
2201 assert(this->explicit_stride
);
2202 return this->explicit_stride
* (length
- 1) + elem_size
;
2205 unsigned N
= this->bit_size() / 8;
2207 return this->vector_elements
* N
;
2211 glsl_type::std430_size(bool row_major
) const
2213 unsigned N
= is_64bit() ? 8 : 4;
2215 /* OpenGL 4.30 spec, section 7.6.2.2 "Standard Uniform Block Layout":
2217 * "When using the std430 storage layout, shader storage blocks will be
2218 * laid out in buffer storage identically to uniform and shader storage
2219 * blocks using the std140 layout, except that the base alignment and
2220 * stride of arrays of scalars and vectors in rule 4 and of structures
2221 * in rule 9 are not rounded up a multiple of the base alignment of a vec4.
2223 if (this->is_scalar() || this->is_vector()) {
2224 assert(this->explicit_stride
== 0);
2225 return this->vector_elements
* N
;
2228 if (this->without_array()->is_matrix()) {
2229 const struct glsl_type
*element_type
;
2230 const struct glsl_type
*vec_type
;
2231 unsigned int array_len
;
2233 if (this->is_array()) {
2234 element_type
= this->without_array();
2235 array_len
= this->arrays_of_arrays_size();
2237 element_type
= this;
2242 vec_type
= get_instance(element_type
->base_type
,
2243 element_type
->matrix_columns
, 1);
2245 array_len
*= element_type
->vector_elements
;
2247 vec_type
= get_instance(element_type
->base_type
,
2248 element_type
->vector_elements
, 1);
2249 array_len
*= element_type
->matrix_columns
;
2251 const glsl_type
*array_type
= glsl_type::get_array_instance(vec_type
,
2254 return array_type
->std430_size(false);
2257 if (this->is_array()) {
2259 if (this->without_array()->is_struct())
2260 stride
= this->without_array()->std430_size(row_major
);
2262 stride
= this->without_array()->std430_base_alignment(row_major
);
2264 unsigned size
= this->arrays_of_arrays_size() * stride
;
2265 assert(this->explicit_stride
== 0 ||
2266 size
== this->length
* this->explicit_stride
);
2270 if (this->is_struct() || this->is_interface()) {
2272 unsigned max_align
= 0;
2274 for (unsigned i
= 0; i
< this->length
; i
++) {
2275 bool field_row_major
= row_major
;
2276 const enum glsl_matrix_layout matrix_layout
=
2277 glsl_matrix_layout(this->fields
.structure
[i
].matrix_layout
);
2278 if (matrix_layout
== GLSL_MATRIX_LAYOUT_ROW_MAJOR
) {
2279 field_row_major
= true;
2280 } else if (matrix_layout
== GLSL_MATRIX_LAYOUT_COLUMN_MAJOR
) {
2281 field_row_major
= false;
2284 const struct glsl_type
*field_type
= this->fields
.structure
[i
].type
;
2285 unsigned align
= field_type
->std430_base_alignment(field_row_major
);
2286 size
= glsl_align(size
, align
);
2287 size
+= field_type
->std430_size(field_row_major
);
2289 max_align
= MAX2(align
, max_align
);
2291 size
= glsl_align(size
, max_align
);
2295 assert(!"not reached");
2300 glsl_type::get_explicit_std430_type(bool row_major
) const
2302 if (this->is_vector() || this->is_scalar()) {
2304 } else if (this->is_matrix()) {
2305 const glsl_type
*vec_type
;
2307 vec_type
= get_instance(this->base_type
, this->matrix_columns
, 1);
2309 vec_type
= get_instance(this->base_type
, this->vector_elements
, 1);
2310 unsigned stride
= vec_type
->std430_array_stride(false);
2311 return get_instance(this->base_type
, this->vector_elements
,
2312 this->matrix_columns
, stride
, row_major
);
2313 } else if (this->is_array()) {
2314 const glsl_type
*elem_type
=
2315 this->fields
.array
->get_explicit_std430_type(row_major
);
2316 unsigned stride
= this->fields
.array
->std430_array_stride(row_major
);
2317 return get_array_instance(elem_type
, this->length
, stride
);
2318 } else if (this->is_struct() || this->is_interface()) {
2319 glsl_struct_field
*fields
= new glsl_struct_field
[this->length
];
2320 unsigned offset
= 0;
2321 for (unsigned i
= 0; i
< length
; i
++) {
2322 fields
[i
] = this->fields
.structure
[i
];
2324 bool field_row_major
= row_major
;
2325 if (fields
[i
].matrix_layout
== GLSL_MATRIX_LAYOUT_COLUMN_MAJOR
) {
2326 field_row_major
= false;
2327 } else if (fields
[i
].matrix_layout
== GLSL_MATRIX_LAYOUT_ROW_MAJOR
) {
2328 field_row_major
= true;
2331 fields
[i
].type
->get_explicit_std430_type(field_row_major
);
2333 unsigned fsize
= fields
[i
].type
->std430_size(field_row_major
);
2334 unsigned falign
= fields
[i
].type
->std430_base_alignment(field_row_major
);
2335 /* From the GLSL 460 spec section "Uniform and Shader Storage Block
2336 * Layout Qualifiers":
2338 * "The actual offset of a member is computed as follows: If
2339 * offset was declared, start with that offset, otherwise start
2340 * with the next available offset. If the resulting offset is not
2341 * a multiple of the actual alignment, increase it to the first
2342 * offset that is a multiple of the actual alignment. This results
2343 * in the actual offset the member will have."
2345 if (fields
[i
].offset
>= 0) {
2346 assert((unsigned)fields
[i
].offset
>= offset
);
2347 offset
= fields
[i
].offset
;
2349 offset
= glsl_align(offset
, falign
);
2350 fields
[i
].offset
= offset
;
2354 const glsl_type
*type
;
2355 if (this->is_struct())
2356 type
= get_struct_instance(fields
, this->length
, this->name
);
2358 type
= get_interface_instance(fields
, this->length
,
2359 (enum glsl_interface_packing
)this->interface_packing
,
2360 this->interface_row_major
,
2366 unreachable("Invalid type for SSBO");
2371 glsl_type::get_explicit_interface_type(bool supports_std430
) const
2373 enum glsl_interface_packing packing
=
2374 this->get_internal_ifc_packing(supports_std430
);
2375 if (packing
== GLSL_INTERFACE_PACKING_STD140
) {
2376 return this->get_explicit_std140_type(this->interface_row_major
);
2378 assert(packing
== GLSL_INTERFACE_PACKING_STD430
);
2379 return this->get_explicit_std430_type(this->interface_row_major
);
2383 /* This differs from get_explicit_std430_type() in that it:
2384 * - can size arrays slightly smaller ("stride * (len - 1) + elem_size" instead
2385 * of "stride * len")
2386 * - consumes a glsl_type_size_align_func which allows 8 and 16-bit values to be
2387 * packed more tightly
2388 * - overrides any struct field offsets but get_explicit_std430_type() tries to
2389 * respect any existing ones
2392 glsl_type::get_explicit_type_for_size_align(glsl_type_size_align_func type_info
,
2393 unsigned *size
, unsigned *alignment
) const
2395 if (this->is_scalar() || this->is_vector()) {
2396 type_info(this, size
, alignment
);
2398 } else if (this->is_array()) {
2399 unsigned elem_size
, elem_align
;
2400 const struct glsl_type
*explicit_element
=
2401 this->fields
.array
->get_explicit_type_for_size_align(type_info
, &elem_size
, &elem_align
);
2403 unsigned stride
= align(elem_size
, elem_align
);
2405 *size
= stride
* (this->length
- 1) + elem_size
;
2406 *alignment
= elem_align
;
2407 return glsl_type::get_array_instance(explicit_element
, this->length
, stride
);
2408 } else if (this->is_struct()) {
2409 struct glsl_struct_field
*fields
= (struct glsl_struct_field
*)
2410 malloc(sizeof(struct glsl_struct_field
) * this->length
);
2414 for (unsigned i
= 0; i
< this->length
; i
++) {
2415 fields
[i
] = this->fields
.structure
[i
];
2416 assert(fields
[i
].matrix_layout
!= GLSL_MATRIX_LAYOUT_ROW_MAJOR
);
2418 unsigned field_size
, field_align
;
2420 fields
[i
].type
->get_explicit_type_for_size_align(type_info
, &field_size
, &field_align
);
2421 fields
[i
].offset
= align(*size
, field_align
);
2423 *size
= fields
[i
].offset
+ field_size
;
2424 *alignment
= MAX2(*alignment
, field_align
);
2427 const glsl_type
*type
= glsl_type::get_struct_instance(fields
, this->length
, this->name
, false);
2430 } else if (this->is_matrix()) {
2431 unsigned col_size
, col_align
;
2432 type_info(this->column_type(), &col_size
, &col_align
);
2433 unsigned stride
= align(col_size
, col_align
);
2435 *size
= this->matrix_columns
* stride
;
2436 *alignment
= col_align
;
2437 return glsl_type::get_instance(this->base_type
, this->vector_elements
,
2438 this->matrix_columns
, stride
, false);
2440 unreachable("Unhandled type.");
2445 glsl_type::count_vec4_slots(bool is_gl_vertex_input
, bool is_bindless
) const
2447 /* From page 31 (page 37 of the PDF) of the GLSL 1.50 spec:
2449 * "A scalar input counts the same amount against this limit as a vec4,
2450 * so applications may want to consider packing groups of four
2451 * unrelated float inputs together into a vector to better utilize the
2452 * capabilities of the underlying hardware. A matrix input will use up
2453 * multiple locations. The number of locations used will equal the
2454 * number of columns in the matrix."
2456 * The spec does not explicitly say how arrays are counted. However, it
2457 * should be safe to assume the total number of slots consumed by an array
2458 * is the number of entries in the array multiplied by the number of slots
2459 * consumed by a single element of the array.
2461 * The spec says nothing about how structs are counted, because vertex
2462 * attributes are not allowed to be (or contain) structs. However, Mesa
2463 * allows varying structs, the number of varying slots taken up by a
2464 * varying struct is simply equal to the sum of the number of slots taken
2465 * up by each element.
2467 * Doubles are counted different depending on whether they are vertex
2468 * inputs or everything else. Vertex inputs from ARB_vertex_attrib_64bit
2469 * take one location no matter what size they are, otherwise dvec3/4
2470 * take two locations.
2472 switch (this->base_type
) {
2473 case GLSL_TYPE_UINT
:
2475 case GLSL_TYPE_UINT8
:
2476 case GLSL_TYPE_INT8
:
2477 case GLSL_TYPE_UINT16
:
2478 case GLSL_TYPE_INT16
:
2479 case GLSL_TYPE_FLOAT
:
2480 case GLSL_TYPE_FLOAT16
:
2481 case GLSL_TYPE_BOOL
:
2482 return this->matrix_columns
;
2483 case GLSL_TYPE_DOUBLE
:
2484 case GLSL_TYPE_UINT64
:
2485 case GLSL_TYPE_INT64
:
2486 if (this->vector_elements
> 2 && !is_gl_vertex_input
)
2487 return this->matrix_columns
* 2;
2489 return this->matrix_columns
;
2490 case GLSL_TYPE_STRUCT
:
2491 case GLSL_TYPE_INTERFACE
: {
2494 for (unsigned i
= 0; i
< this->length
; i
++) {
2495 const glsl_type
*member_type
= this->fields
.structure
[i
].type
;
2496 size
+= member_type
->count_vec4_slots(is_gl_vertex_input
, is_bindless
);
2502 case GLSL_TYPE_ARRAY
: {
2503 const glsl_type
*element
= this->fields
.array
;
2504 return this->length
* element
->count_vec4_slots(is_gl_vertex_input
,
2508 case GLSL_TYPE_SAMPLER
:
2509 case GLSL_TYPE_IMAGE
:
2515 case GLSL_TYPE_SUBROUTINE
:
2518 case GLSL_TYPE_FUNCTION
:
2519 case GLSL_TYPE_ATOMIC_UINT
:
2520 case GLSL_TYPE_VOID
:
2521 case GLSL_TYPE_ERROR
:
2525 assert(!"Unexpected type in count_attribute_slots()");
2531 glsl_type::count_dword_slots(bool is_bindless
) const
2533 switch (this->base_type
) {
2534 case GLSL_TYPE_UINT
:
2536 case GLSL_TYPE_FLOAT
:
2537 case GLSL_TYPE_BOOL
:
2538 return this->components();
2539 case GLSL_TYPE_UINT16
:
2540 case GLSL_TYPE_INT16
:
2541 case GLSL_TYPE_FLOAT16
:
2542 return DIV_ROUND_UP(this->components(), 2);
2543 case GLSL_TYPE_UINT8
:
2544 case GLSL_TYPE_INT8
:
2545 return DIV_ROUND_UP(this->components(), 4);
2546 case GLSL_TYPE_IMAGE
:
2547 case GLSL_TYPE_SAMPLER
:
2551 case GLSL_TYPE_DOUBLE
:
2552 case GLSL_TYPE_UINT64
:
2553 case GLSL_TYPE_INT64
:
2554 return this->components() * 2;
2555 case GLSL_TYPE_ARRAY
:
2556 return this->fields
.array
->count_dword_slots(is_bindless
) *
2559 case GLSL_TYPE_INTERFACE
:
2560 case GLSL_TYPE_STRUCT
: {
2562 for (unsigned i
= 0; i
< this->length
; i
++) {
2563 size
+= this->fields
.structure
[i
].type
->count_dword_slots(is_bindless
);
2568 case GLSL_TYPE_ATOMIC_UINT
:
2570 case GLSL_TYPE_SUBROUTINE
:
2572 case GLSL_TYPE_VOID
:
2573 case GLSL_TYPE_ERROR
:
2574 case GLSL_TYPE_FUNCTION
:
2576 unreachable("invalid type in st_glsl_type_dword_size()");
2583 glsl_type::coordinate_components() const
2585 enum glsl_sampler_dim dim
= (enum glsl_sampler_dim
)sampler_dimensionality
;
2586 int size
= glsl_get_sampler_dim_coordinate_components(dim
);
2588 /* Array textures need an additional component for the array index, except
2589 * for cubemap array images that behave like a 2D array of interleaved
2592 if (sampler_array
&&
2593 !(is_image() && sampler_dimensionality
== GLSL_SAMPLER_DIM_CUBE
))
2600 * Declarations of type flyweights (glsl_type::_foo_type) and
2601 * convenience pointers (glsl_type::foo_type).
2604 #define DECL_TYPE(NAME, ...) \
2605 const glsl_type glsl_type::_##NAME##_type = glsl_type(__VA_ARGS__, #NAME); \
2606 const glsl_type *const glsl_type::NAME##_type = &glsl_type::_##NAME##_type;
2608 #define STRUCT_TYPE(NAME)
2610 #include "compiler/builtin_type_macros.h"
2614 get_struct_type_field_and_pointer_sizes(size_t *s_field_size
,
2615 size_t *s_field_ptrs
)
2617 *s_field_size
= sizeof(glsl_struct_field
);
2619 sizeof(((glsl_struct_field
*)0)->type
) +
2620 sizeof(((glsl_struct_field
*)0)->name
);
2626 unsigned base_type
:5;
2627 unsigned interface_row_major
:1;
2628 unsigned vector_elements
:3;
2629 unsigned matrix_columns
:3;
2630 unsigned explicit_stride
:20;
2633 unsigned base_type
:5;
2634 unsigned dimensionality
:4;
2637 unsigned sampled_type
:2;
2641 unsigned base_type
:5;
2643 unsigned explicit_stride
:14;
2646 unsigned base_type
:5;
2647 unsigned interface_packing_or_packed
:2;
2648 unsigned interface_row_major
:1;
2654 encode_type_to_blob(struct blob
*blob
, const glsl_type
*type
)
2657 blob_write_uint32(blob
, 0);
2661 STATIC_ASSERT(sizeof(union packed_type
) == 4);
2662 union packed_type encoded
;
2664 encoded
.basic
.base_type
= type
->base_type
;
2666 switch (type
->base_type
) {
2667 case GLSL_TYPE_UINT
:
2669 case GLSL_TYPE_FLOAT
:
2670 case GLSL_TYPE_FLOAT16
:
2671 case GLSL_TYPE_DOUBLE
:
2672 case GLSL_TYPE_UINT8
:
2673 case GLSL_TYPE_INT8
:
2674 case GLSL_TYPE_UINT16
:
2675 case GLSL_TYPE_INT16
:
2676 case GLSL_TYPE_UINT64
:
2677 case GLSL_TYPE_INT64
:
2678 case GLSL_TYPE_BOOL
:
2679 encoded
.basic
.interface_row_major
= type
->interface_row_major
;
2680 assert(type
->matrix_columns
< 8);
2681 if (type
->vector_elements
<= 4)
2682 encoded
.basic
.vector_elements
= type
->vector_elements
;
2683 else if (type
->vector_elements
== 8)
2684 encoded
.basic
.vector_elements
= 5;
2685 else if (type
->vector_elements
== 16)
2686 encoded
.basic
.vector_elements
= 6;
2687 encoded
.basic
.matrix_columns
= type
->matrix_columns
;
2688 encoded
.basic
.explicit_stride
= MIN2(type
->explicit_stride
, 0xfffff);
2689 blob_write_uint32(blob
, encoded
.u32
);
2690 /* If we don't have enough bits for explicit_stride, store it
2693 if (encoded
.basic
.explicit_stride
== 0xfffff)
2694 blob_write_uint32(blob
, type
->explicit_stride
);
2696 case GLSL_TYPE_SAMPLER
:
2697 encoded
.sampler
.dimensionality
= type
->sampler_dimensionality
;
2698 encoded
.sampler
.shadow
= type
->sampler_shadow
;
2699 encoded
.sampler
.array
= type
->sampler_array
;
2700 encoded
.sampler
.sampled_type
= type
->sampled_type
;
2702 case GLSL_TYPE_SUBROUTINE
:
2703 blob_write_uint32(blob
, encoded
.u32
);
2704 blob_write_string(blob
, type
->name
);
2706 case GLSL_TYPE_IMAGE
:
2707 encoded
.sampler
.dimensionality
= type
->sampler_dimensionality
;
2708 encoded
.sampler
.array
= type
->sampler_array
;
2709 encoded
.sampler
.sampled_type
= type
->sampled_type
;
2711 case GLSL_TYPE_ATOMIC_UINT
:
2713 case GLSL_TYPE_ARRAY
:
2714 encoded
.array
.length
= MIN2(type
->length
, 0x1fff);
2715 encoded
.array
.explicit_stride
= MIN2(type
->explicit_stride
, 0x3fff);
2716 blob_write_uint32(blob
, encoded
.u32
);
2717 /* If we don't have enough bits for length or explicit_stride, store it
2720 if (encoded
.array
.length
== 0x1fff)
2721 blob_write_uint32(blob
, type
->length
);
2722 if (encoded
.array
.explicit_stride
== 0x3fff)
2723 blob_write_uint32(blob
, type
->explicit_stride
);
2724 encode_type_to_blob(blob
, type
->fields
.array
);
2726 case GLSL_TYPE_STRUCT
:
2727 case GLSL_TYPE_INTERFACE
:
2728 encoded
.strct
.length
= MIN2(type
->length
, 0xffffff);
2729 if (type
->is_interface()) {
2730 encoded
.strct
.interface_packing_or_packed
= type
->interface_packing
;
2731 encoded
.strct
.interface_row_major
= type
->interface_row_major
;
2733 encoded
.strct
.interface_packing_or_packed
= type
->packed
;
2735 blob_write_uint32(blob
, encoded
.u32
);
2736 blob_write_string(blob
, type
->name
);
2738 /* If we don't have enough bits for length, store it separately. */
2739 if (encoded
.strct
.length
== 0xffffff)
2740 blob_write_uint32(blob
, type
->length
);
2742 size_t s_field_size
, s_field_ptrs
;
2743 get_struct_type_field_and_pointer_sizes(&s_field_size
, &s_field_ptrs
);
2745 for (unsigned i
= 0; i
< type
->length
; i
++) {
2746 encode_type_to_blob(blob
, type
->fields
.structure
[i
].type
);
2747 blob_write_string(blob
, type
->fields
.structure
[i
].name
);
2749 /* Write the struct field skipping the pointers */
2750 blob_write_bytes(blob
,
2751 ((char *)&type
->fields
.structure
[i
]) + s_field_ptrs
,
2752 s_field_size
- s_field_ptrs
);
2755 case GLSL_TYPE_VOID
:
2757 case GLSL_TYPE_ERROR
:
2759 assert(!"Cannot encode type!");
2764 blob_write_uint32(blob
, encoded
.u32
);
2768 decode_type_from_blob(struct blob_reader
*blob
)
2770 union packed_type encoded
;
2771 encoded
.u32
= blob_read_uint32(blob
);
2773 if (encoded
.u32
== 0) {
2777 glsl_base_type base_type
= (glsl_base_type
)encoded
.basic
.base_type
;
2779 switch (base_type
) {
2780 case GLSL_TYPE_UINT
:
2782 case GLSL_TYPE_FLOAT
:
2783 case GLSL_TYPE_FLOAT16
:
2784 case GLSL_TYPE_DOUBLE
:
2785 case GLSL_TYPE_UINT8
:
2786 case GLSL_TYPE_INT8
:
2787 case GLSL_TYPE_UINT16
:
2788 case GLSL_TYPE_INT16
:
2789 case GLSL_TYPE_UINT64
:
2790 case GLSL_TYPE_INT64
:
2791 case GLSL_TYPE_BOOL
: {
2792 unsigned explicit_stride
= encoded
.basic
.explicit_stride
;
2793 if (explicit_stride
== 0xfffff)
2794 explicit_stride
= blob_read_uint32(blob
);
2795 uint32_t vector_elements
= encoded
.basic
.vector_elements
;
2796 if (vector_elements
== 5)
2797 vector_elements
= 8;
2798 else if (vector_elements
== 6)
2799 vector_elements
= 16;
2800 return glsl_type::get_instance(base_type
, encoded
.basic
.vector_elements
,
2801 encoded
.basic
.matrix_columns
,
2803 encoded
.basic
.interface_row_major
);
2805 case GLSL_TYPE_SAMPLER
:
2806 return glsl_type::get_sampler_instance((enum glsl_sampler_dim
)encoded
.sampler
.dimensionality
,
2807 encoded
.sampler
.shadow
,
2808 encoded
.sampler
.array
,
2809 (glsl_base_type
) encoded
.sampler
.sampled_type
);
2810 case GLSL_TYPE_SUBROUTINE
:
2811 return glsl_type::get_subroutine_instance(blob_read_string(blob
));
2812 case GLSL_TYPE_IMAGE
:
2813 return glsl_type::get_image_instance((enum glsl_sampler_dim
)encoded
.sampler
.dimensionality
,
2814 encoded
.sampler
.array
,
2815 (glsl_base_type
) encoded
.sampler
.sampled_type
);
2816 case GLSL_TYPE_ATOMIC_UINT
:
2817 return glsl_type::atomic_uint_type
;
2818 case GLSL_TYPE_ARRAY
: {
2819 unsigned length
= encoded
.array
.length
;
2820 if (length
== 0x1fff)
2821 length
= blob_read_uint32(blob
);
2822 unsigned explicit_stride
= encoded
.array
.explicit_stride
;
2823 if (explicit_stride
== 0x3fff)
2824 explicit_stride
= blob_read_uint32(blob
);
2825 return glsl_type::get_array_instance(decode_type_from_blob(blob
),
2826 length
, explicit_stride
);
2828 case GLSL_TYPE_STRUCT
:
2829 case GLSL_TYPE_INTERFACE
: {
2830 char *name
= blob_read_string(blob
);
2831 unsigned num_fields
= encoded
.strct
.length
;
2832 if (num_fields
== 0xffffff)
2833 num_fields
= blob_read_uint32(blob
);
2835 size_t s_field_size
, s_field_ptrs
;
2836 get_struct_type_field_and_pointer_sizes(&s_field_size
, &s_field_ptrs
);
2838 glsl_struct_field
*fields
=
2839 (glsl_struct_field
*) malloc(s_field_size
* num_fields
);
2840 for (unsigned i
= 0; i
< num_fields
; i
++) {
2841 fields
[i
].type
= decode_type_from_blob(blob
);
2842 fields
[i
].name
= blob_read_string(blob
);
2844 blob_copy_bytes(blob
, ((uint8_t *) &fields
[i
]) + s_field_ptrs
,
2845 s_field_size
- s_field_ptrs
);
2849 if (base_type
== GLSL_TYPE_INTERFACE
) {
2850 enum glsl_interface_packing packing
=
2851 (glsl_interface_packing
) encoded
.strct
.interface_packing_or_packed
;
2852 bool row_major
= encoded
.strct
.interface_row_major
;
2853 t
= glsl_type::get_interface_instance(fields
, num_fields
, packing
,
2856 unsigned packed
= encoded
.strct
.interface_packing_or_packed
;
2857 t
= glsl_type::get_struct_instance(fields
, num_fields
, name
, packed
);
2863 case GLSL_TYPE_VOID
:
2864 return glsl_type::void_type
;
2865 case GLSL_TYPE_ERROR
:
2867 assert(!"Cannot decode type!");
2873 glsl_type::cl_alignment() const
2875 /* vectors unlike arrays are aligned to their size */
2876 if (this->is_scalar() || this->is_vector())
2877 return this->cl_size();
2878 else if (this->is_array())
2879 return this->without_array()->cl_alignment();
2880 else if (this->is_struct()) {
2881 /* Packed Structs are 0x1 aligned despite their size. */
2886 for (unsigned i
= 0; i
< this->length
; ++i
) {
2887 struct glsl_struct_field
&field
= this->fields
.structure
[i
];
2888 res
= MAX2(res
, field
.type
->cl_alignment());
2896 glsl_type::cl_size() const
2898 if (this->is_scalar()) {
2899 return glsl_base_type_get_bit_size(this->base_type
) / 8;
2900 } else if (this->is_vector()) {
2901 unsigned vec_elemns
= this->vector_elements
== 3 ? 4 : this->vector_elements
;
2902 return vec_elemns
* glsl_base_type_get_bit_size(this->base_type
) / 8;
2903 } else if (this->is_array()) {
2904 unsigned size
= this->without_array()->cl_size();
2905 return size
* this->length
;
2906 } else if (this->is_struct()) {
2908 for (unsigned i
= 0; i
< this->length
; ++i
) {
2909 struct glsl_struct_field
&field
= this->fields
.structure
[i
];
2910 /* if a struct is packed, members don't get aligned */
2912 size
= align(size
, field
.type
->cl_alignment());
2913 size
+= field
.type
->cl_size();
2923 glsl_get_sampler_dim_coordinate_components(enum glsl_sampler_dim dim
)
2926 case GLSL_SAMPLER_DIM_1D
:
2927 case GLSL_SAMPLER_DIM_BUF
:
2929 case GLSL_SAMPLER_DIM_2D
:
2930 case GLSL_SAMPLER_DIM_RECT
:
2931 case GLSL_SAMPLER_DIM_MS
:
2932 case GLSL_SAMPLER_DIM_EXTERNAL
:
2933 case GLSL_SAMPLER_DIM_SUBPASS
:
2934 case GLSL_SAMPLER_DIM_SUBPASS_MS
:
2936 case GLSL_SAMPLER_DIM_3D
:
2937 case GLSL_SAMPLER_DIM_CUBE
:
2940 unreachable("Unknown sampler dim");