3 * Copyright © 2009 Intel Corporation
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
31 #include "shader_enums.h"
33 #include "c11/threads.h"
34 #include "util/macros.h"
37 #include "main/config.h"
46 struct _mesa_glsl_parse_state
;
47 struct glsl_symbol_table
;
50 glsl_type_singleton_init_or_ref();
53 glsl_type_singleton_decref();
56 _mesa_glsl_initialize_types(struct _mesa_glsl_parse_state
*state
);
58 void encode_type_to_blob(struct blob
*blob
, const struct glsl_type
*type
);
60 const struct glsl_type
*decode_type_from_blob(struct blob_reader
*blob
);
67 /* Note: GLSL_TYPE_UINT, GLSL_TYPE_INT, and GLSL_TYPE_FLOAT must be 0, 1,
68 * and 2 so that they will fit in the 2 bits of glsl_type::sampled_type.
84 GLSL_TYPE_ATOMIC_UINT
,
94 static inline bool glsl_base_type_is_16bit(enum glsl_base_type type
)
96 return type
== GLSL_TYPE_FLOAT16
||
97 type
== GLSL_TYPE_UINT16
||
98 type
== GLSL_TYPE_INT16
;
101 static inline bool glsl_base_type_is_64bit(enum glsl_base_type type
)
103 return type
== GLSL_TYPE_DOUBLE
||
104 type
== GLSL_TYPE_UINT64
||
105 type
== GLSL_TYPE_INT64
||
106 type
== GLSL_TYPE_IMAGE
||
107 type
== GLSL_TYPE_SAMPLER
;
110 static inline bool glsl_base_type_is_integer(enum glsl_base_type type
)
112 return type
== GLSL_TYPE_UINT8
||
113 type
== GLSL_TYPE_INT8
||
114 type
== GLSL_TYPE_UINT16
||
115 type
== GLSL_TYPE_INT16
||
116 type
== GLSL_TYPE_UINT
||
117 type
== GLSL_TYPE_INT
||
118 type
== GLSL_TYPE_UINT64
||
119 type
== GLSL_TYPE_INT64
||
120 type
== GLSL_TYPE_BOOL
||
121 type
== GLSL_TYPE_SAMPLER
||
122 type
== GLSL_TYPE_IMAGE
;
125 static inline unsigned int
126 glsl_base_type_get_bit_size(const enum glsl_base_type base_type
)
134 case GLSL_TYPE_FLOAT
: /* TODO handle mediump */
135 case GLSL_TYPE_SUBROUTINE
:
138 case GLSL_TYPE_FLOAT16
:
139 case GLSL_TYPE_UINT16
:
140 case GLSL_TYPE_INT16
:
143 case GLSL_TYPE_UINT8
:
147 case GLSL_TYPE_DOUBLE
:
148 case GLSL_TYPE_INT64
:
149 case GLSL_TYPE_UINT64
:
150 case GLSL_TYPE_IMAGE
:
151 case GLSL_TYPE_SAMPLER
:
155 unreachable("unknown base type");
161 enum glsl_sampler_dim
{
162 GLSL_SAMPLER_DIM_1D
= 0,
165 GLSL_SAMPLER_DIM_CUBE
,
166 GLSL_SAMPLER_DIM_RECT
,
167 GLSL_SAMPLER_DIM_BUF
,
168 GLSL_SAMPLER_DIM_EXTERNAL
,
170 GLSL_SAMPLER_DIM_SUBPASS
, /* for vulkan input attachments */
171 GLSL_SAMPLER_DIM_SUBPASS_MS
, /* for multisampled vulkan input attachments */
174 enum glsl_matrix_layout
{
176 * The layout of the matrix is inherited from the object containing the
177 * matrix (the top level structure or the uniform block).
179 GLSL_MATRIX_LAYOUT_INHERITED
,
182 * Explicit column-major layout
184 * If a uniform block doesn't have an explicit layout set, it will default
187 GLSL_MATRIX_LAYOUT_COLUMN_MAJOR
,
192 GLSL_MATRIX_LAYOUT_ROW_MAJOR
196 GLSL_PRECISION_NONE
= 0,
198 GLSL_PRECISION_MEDIUM
,
204 #include "util/ralloc.h"
205 #include "main/menums.h" /* for gl_texture_index, C++'s enum rules are broken */
209 glsl_base_type base_type
:8;
211 glsl_base_type sampled_type
:8; /**< Type of data returned using this
212 * sampler or image. Only \c
213 * GLSL_TYPE_FLOAT, \c GLSL_TYPE_INT,
214 * and \c GLSL_TYPE_UINT are valid.
217 unsigned sampler_dimensionality
:4; /**< \see glsl_sampler_dim */
218 unsigned sampler_shadow
:1;
219 unsigned sampler_array
:1;
220 unsigned interface_packing
:2;
221 unsigned interface_row_major
:1;
224 * For \c GLSL_TYPE_STRUCT this specifies if the struct is packed or not.
226 * Only used for Compute kernels
231 glsl_type() : mem_ctx(NULL
)
233 // Dummy constructor, just for the sake of ASSERT_BITFIELD_SIZE.
238 * \name Vector and matrix element counts
240 * For scalars, each of these values will be 1. For non-numeric types
244 uint8_t vector_elements
; /**< 1, 2, 3, or 4 vector elements. */
245 uint8_t matrix_columns
; /**< 1, 2, 3, or 4 matrix columns. */
249 * For \c GLSL_TYPE_ARRAY, this is the length of the array. For
250 * \c GLSL_TYPE_STRUCT or \c GLSL_TYPE_INTERFACE, it is the number of
251 * elements in the structure and the number of values pointed to by
252 * \c fields.structure (below).
257 * Name of the data type
259 * Will never be \c NULL.
264 * Explicit array, matrix, or vector stride. This is used to communicate
265 * explicit array layouts from SPIR-V. Should be 0 if the type has no
268 unsigned explicit_stride
;
271 * Subtype of composite data types.
274 const struct glsl_type
*array
; /**< Type of array elements. */
275 struct glsl_function_param
*parameters
; /**< Parameters to function. */
276 struct glsl_struct_field
*structure
; /**< List of struct fields. */
280 * \name Pointers to various public type singletons
284 #define DECL_TYPE(NAME, ...) \
285 static const glsl_type *const NAME##_type;
287 #define STRUCT_TYPE(NAME) \
288 static const glsl_type *const struct_##NAME##_type;
289 #include "compiler/builtin_type_macros.h"
293 * Convenience accessors for vector types (shorter than get_instance()).
296 static const glsl_type
*vec(unsigned components
, const glsl_type
*const ts
[]);
297 static const glsl_type
*vec(unsigned components
);
298 static const glsl_type
*f16vec(unsigned components
);
299 static const glsl_type
*dvec(unsigned components
);
300 static const glsl_type
*ivec(unsigned components
);
301 static const glsl_type
*uvec(unsigned components
);
302 static const glsl_type
*bvec(unsigned components
);
303 static const glsl_type
*i64vec(unsigned components
);
304 static const glsl_type
*u64vec(unsigned components
);
305 static const glsl_type
*i16vec(unsigned components
);
306 static const glsl_type
*u16vec(unsigned components
);
307 static const glsl_type
*i8vec(unsigned components
);
308 static const glsl_type
*u8vec(unsigned components
);
312 * For numeric and boolean derived types returns the basic scalar type
314 * If the type is a numeric or boolean scalar, vector, or matrix type,
315 * this function gets the scalar type of the individual components. For
316 * all other types, including arrays of numeric or boolean types, the
317 * error type is returned.
319 const glsl_type
*get_base_type() const;
322 * Get the basic scalar type which this type aggregates.
324 * If the type is a numeric or boolean scalar, vector, or matrix, or an
325 * array of any of those, this function gets the scalar type of the
326 * individual components. For structs and arrays of structs, this function
327 * returns the struct type. For samplers and arrays of samplers, this
328 * function returns the sampler type.
330 const glsl_type
*get_scalar_type() const;
333 * Gets the "bare" type without any decorations or layout information.
335 const glsl_type
*get_bare_type() const;
338 * Get the instance of a built-in scalar, vector, or matrix type
340 static const glsl_type
*get_instance(unsigned base_type
, unsigned rows
,
342 unsigned explicit_stride
= 0,
343 bool row_major
= false);
346 * Get the instance of a sampler type
348 static const glsl_type
*get_sampler_instance(enum glsl_sampler_dim dim
,
351 glsl_base_type type
);
353 static const glsl_type
*get_image_instance(enum glsl_sampler_dim dim
,
354 bool array
, glsl_base_type type
);
357 * Get the instance of an array type
359 static const glsl_type
*get_array_instance(const glsl_type
*base
,
361 unsigned explicit_stride
= 0);
364 * Get the instance of a record type
366 static const glsl_type
*get_struct_instance(const glsl_struct_field
*fields
,
369 bool packed
= false);
372 * Get the instance of an interface block type
374 static const glsl_type
*get_interface_instance(const glsl_struct_field
*fields
,
376 enum glsl_interface_packing packing
,
378 const char *block_name
);
381 * Get the instance of an subroutine type
383 static const glsl_type
*get_subroutine_instance(const char *subroutine_name
);
386 * Get the instance of a function type
388 static const glsl_type
*get_function_instance(const struct glsl_type
*return_type
,
389 const glsl_function_param
*parameters
,
390 unsigned num_params
);
393 * Get the type resulting from a multiplication of \p type_a * \p type_b
395 static const glsl_type
*get_mul_type(const glsl_type
*type_a
,
396 const glsl_type
*type_b
);
399 * Query the total number of scalars that make up a scalar, vector or matrix
401 unsigned components() const
403 return vector_elements
* matrix_columns
;
407 * Calculate the number of components slots required to hold this type
409 * This is used to determine how many uniform or varying locations a type
412 unsigned component_slots() const;
415 * Calculate offset between the base location of the struct in
416 * uniform storage and a struct member.
417 * For the initial call, length is the index of the member to find the
420 unsigned struct_location_offset(unsigned length
) const;
423 * Calculate the number of unique values from glGetUniformLocation for the
424 * elements of the type.
426 * This is used to allocate slots in the UniformRemapTable, the amount of
427 * locations may not match with actual used storage space by the driver.
429 unsigned uniform_locations() const;
432 * Used to count the number of varyings contained in the type ignoring
433 * innermost array elements.
435 unsigned varying_count() const;
438 * Calculate the number of attribute slots required to hold this type
440 * This implements the language rules of GLSL 1.50 for counting the number
441 * of slots used by a vertex attribute. It also determines the number of
442 * varying slots the type will use up in the absence of varying packing
443 * (and thus, it can be used to measure the number of varying slots used by
444 * the varyings that are generated by lower_packed_varyings).
446 * For vertex shader attributes - doubles only take one slot.
447 * For inter-shader varyings - dvec3/dvec4 take two slots.
449 * Vulkan doesn’t make this distinction so the argument should always be
452 unsigned count_attribute_slots(bool is_gl_vertex_input
) const;
455 * Alignment in bytes of the start of this type in a std140 uniform
458 unsigned std140_base_alignment(bool row_major
) const;
460 /** Size in bytes of this type in a std140 uniform block.
462 * Note that this is not GL_UNIFORM_SIZE (which is the number of
463 * elements in the array)
465 unsigned std140_size(bool row_major
) const;
468 * Gets an explicitly laid out type with the std140 layout.
470 const glsl_type
*get_explicit_std140_type(bool row_major
) const;
473 * Alignment in bytes of the start of this type in a std430 shader
476 unsigned std430_base_alignment(bool row_major
) const;
479 * Calculate array stride in bytes of this type in a std430 shader storage
482 unsigned std430_array_stride(bool row_major
) const;
485 * Size in bytes of this type in a std430 shader storage block.
487 * Note that this is not GL_BUFFER_SIZE
489 unsigned std430_size(bool row_major
) const;
492 * Gets an explicitly laid out type with the std430 layout.
494 const glsl_type
*get_explicit_std430_type(bool row_major
) const;
497 * Gets an explicitly laid out interface type.
499 const glsl_type
*get_explicit_interface_type(bool supports_std430
) const;
502 * Alignment in bytes of the start of this type in OpenCL memory.
504 unsigned cl_alignment() const;
507 * Size in bytes of this type in OpenCL memory
509 unsigned cl_size() const;
512 * \brief Can this type be implicitly converted to another?
514 * \return True if the types are identical or if this type can be converted
515 * to \c desired according to Section 4.1.10 of the GLSL spec.
518 * From page 25 (31 of the pdf) of the GLSL 1.50 spec, Section 4.1.10
519 * Implicit Conversions:
521 * In some situations, an expression and its type will be implicitly
522 * converted to a different type. The following table shows all allowed
523 * implicit conversions:
525 * Type of expression | Can be implicitly converted to
526 * --------------------------------------------------
539 * There are no implicit array or structure conversions. For example,
540 * an array of int cannot be implicitly converted to an array of float.
541 * There are no implicit conversions between signed and unsigned
545 bool can_implicitly_convert_to(const glsl_type
*desired
,
546 _mesa_glsl_parse_state
*state
) const;
549 * Query whether or not a type is a scalar (non-vector and non-matrix).
551 bool is_scalar() const
553 return (vector_elements
== 1)
554 && (base_type
>= GLSL_TYPE_UINT
)
555 && (base_type
<= GLSL_TYPE_IMAGE
);
559 * Query whether or not a type is a vector
561 bool is_vector() const
563 return (vector_elements
> 1)
564 && (matrix_columns
== 1)
565 && (base_type
>= GLSL_TYPE_UINT
)
566 && (base_type
<= GLSL_TYPE_BOOL
);
570 * Query whether or not a type is a matrix
572 bool is_matrix() const
574 /* GLSL only has float matrices. */
575 return (matrix_columns
> 1) && (base_type
== GLSL_TYPE_FLOAT
||
576 base_type
== GLSL_TYPE_DOUBLE
||
577 base_type
== GLSL_TYPE_FLOAT16
);
581 * Query whether or not a type is a non-array numeric type
583 bool is_numeric() const
585 return (base_type
>= GLSL_TYPE_UINT
) && (base_type
<= GLSL_TYPE_INT64
);
589 * Query whether or not a type is an integral type
591 bool is_integer() const
593 return (base_type
== GLSL_TYPE_UINT
) || (base_type
== GLSL_TYPE_INT
);
597 * Query whether or not a type is a 64-bit integer.
599 bool is_integer_64() const
601 return base_type
== GLSL_TYPE_UINT64
|| base_type
== GLSL_TYPE_INT64
;
605 * Query whether or not a type is a 32-bit or 64-bit integer
607 bool is_integer_32_64() const
609 return is_integer() || is_integer_64();
613 * Query whether or not type is an integral type, or for struct and array
614 * types, contains an integral type.
616 bool contains_integer() const;
619 * Query whether or not type is a double type, or for struct, interface and
620 * array types, contains a double type.
622 bool contains_double() const;
625 * Query whether or not type is a 64-bit type, or for struct, interface and
626 * array types, contains a double type.
628 bool contains_64bit() const;
631 * Query whether or not a type is a float type
633 bool is_float() const
635 return base_type
== GLSL_TYPE_FLOAT
;
639 * Query whether or not a type is a double type
641 bool is_double() const
643 return base_type
== GLSL_TYPE_DOUBLE
;
647 * Query whether a 64-bit type takes two slots.
649 bool is_dual_slot() const
651 return is_64bit() && vector_elements
> 2;
655 * Query whether or not a type is 64-bit
657 bool is_64bit() const
659 return glsl_base_type_is_64bit(base_type
);
663 * Query whether or not a type is 16-bit
665 bool is_16bit() const
667 return glsl_base_type_is_16bit(base_type
);
671 * Query whether or not a type is 32-bit
673 bool is_32bit() const
675 return base_type
== GLSL_TYPE_UINT
||
676 base_type
== GLSL_TYPE_INT
||
677 base_type
== GLSL_TYPE_FLOAT
;
681 * Query whether or not a type is a non-array boolean type
683 bool is_boolean() const
685 return base_type
== GLSL_TYPE_BOOL
;
689 * Query whether or not a type is a sampler
691 bool is_sampler() const
693 return base_type
== GLSL_TYPE_SAMPLER
;
697 * Query whether or not type is a sampler, or for struct, interface and
698 * array types, contains a sampler.
700 bool contains_sampler() const;
703 * Query whether or not type is an array or for struct, interface and
704 * array types, contains an array.
706 bool contains_array() const;
709 * Get the Mesa texture target index for a sampler type.
711 gl_texture_index
sampler_index() const;
714 * Query whether or not type is an image, or for struct, interface and
715 * array types, contains an image.
717 bool contains_image() const;
720 * Query whether or not a type is an image
722 bool is_image() const
724 return base_type
== GLSL_TYPE_IMAGE
;
728 * Query whether or not a type is an array
730 bool is_array() const
732 return base_type
== GLSL_TYPE_ARRAY
;
735 bool is_array_of_arrays() const
737 return is_array() && fields
.array
->is_array();
741 * Query whether or not a type is a record
743 bool is_struct() const
745 return base_type
== GLSL_TYPE_STRUCT
;
749 * Query whether or not a type is an interface
751 bool is_interface() const
753 return base_type
== GLSL_TYPE_INTERFACE
;
757 * Query whether or not a type is the void type singleton.
761 return base_type
== GLSL_TYPE_VOID
;
765 * Query whether or not a type is the error type singleton.
767 bool is_error() const
769 return base_type
== GLSL_TYPE_ERROR
;
773 * Query if a type is unnamed/anonymous (named by the parser)
776 bool is_subroutine() const
778 return base_type
== GLSL_TYPE_SUBROUTINE
;
780 bool contains_subroutine() const;
782 bool is_anonymous() const
784 return !strncmp(name
, "#anon", 5);
788 * Get the type stripped of any arrays
791 * Pointer to the type of elements of the first non-array type for array
792 * types, or pointer to itself for non-array types.
794 const glsl_type
*without_array() const
796 const glsl_type
*t
= this;
798 while (t
->is_array())
805 * Return the total number of elements in an array including the elements
806 * in arrays of arrays.
808 unsigned arrays_of_arrays_size() const
813 unsigned size
= length
;
814 const glsl_type
*base_type
= fields
.array
;
816 while (base_type
->is_array()) {
817 size
= size
* base_type
->length
;
818 base_type
= base_type
->fields
.array
;
824 * Query whether or not a type is an atomic_uint.
826 bool is_atomic_uint() const
828 return base_type
== GLSL_TYPE_ATOMIC_UINT
;
832 * Return the amount of atomic counter storage required for a type.
834 unsigned atomic_size() const
836 if (is_atomic_uint())
837 return ATOMIC_COUNTER_SIZE
;
839 return length
* fields
.array
->atomic_size();
845 * Return whether a type contains any atomic counters.
847 bool contains_atomic() const
849 return atomic_size() > 0;
853 * Return whether a type contains any opaque types.
855 bool contains_opaque() const;
858 * Query the full type of a matrix row
861 * If the type is not a matrix, \c glsl_type::error_type is returned.
862 * Otherwise a type matching the rows of the matrix is returned.
864 const glsl_type
*row_type() const
869 if (explicit_stride
&& !interface_row_major
)
870 return get_instance(base_type
, matrix_columns
, 1, explicit_stride
);
872 return get_instance(base_type
, matrix_columns
, 1);
876 * Query the full type of a matrix column
879 * If the type is not a matrix, \c glsl_type::error_type is returned.
880 * Otherwise a type matching the columns of the matrix is returned.
882 const glsl_type
*column_type() const
887 if (explicit_stride
&& interface_row_major
)
888 return get_instance(base_type
, vector_elements
, 1, explicit_stride
);
890 return get_instance(base_type
, vector_elements
, 1);
894 * Get the type of a structure field
897 * Pointer to the type of the named field. If the type is not a structure
898 * or the named field does not exist, \c glsl_type::error_type is returned.
900 const glsl_type
*field_type(const char *name
) const;
903 * Get the location of a field within a record type
905 int field_index(const char *name
) const;
908 * Query the number of elements in an array type
911 * The number of elements in the array for array types or -1 for non-array
912 * types. If the number of elements in the array has not yet been declared,
915 int array_size() const
917 return is_array() ? length
: -1;
921 * Query whether the array size for all dimensions has been declared.
923 bool is_unsized_array() const
925 return is_array() && length
== 0;
929 * Return the number of coordinate components needed for this
930 * sampler or image type.
932 * This is based purely on the sampler's dimensionality. For example, this
933 * returns 1 for sampler1D, and 3 for sampler2DArray.
935 * Note that this is often different than actual coordinate type used in
936 * a texturing built-in function, since those pack additional values (such
937 * as the shadow comparator or projector) into the coordinate type.
939 int coordinate_components() const;
942 * Compare a record type against another record type.
944 * This is useful for matching record types declared on the same shader
945 * stage as well as across different shader stages.
946 * The option to not match name is needed for matching record types
947 * declared across different shader stages.
948 * The option to not match locations is to deal with places where the
949 * same struct is defined in a block which has a location set on it.
951 bool record_compare(const glsl_type
*b
, bool match_name
,
952 bool match_locations
= true) const;
955 * Get the type interface packing.
957 enum glsl_interface_packing
get_interface_packing() const
959 return (enum glsl_interface_packing
)interface_packing
;
963 * Get the type interface packing used internally. For shared and packing
964 * layouts this is implementation defined.
966 enum glsl_interface_packing
get_internal_ifc_packing(bool std430_supported
) const
968 enum glsl_interface_packing packing
= this->get_interface_packing();
969 if (packing
== GLSL_INTERFACE_PACKING_STD140
||
970 (!std430_supported
&&
971 (packing
== GLSL_INTERFACE_PACKING_SHARED
||
972 packing
== GLSL_INTERFACE_PACKING_PACKED
))) {
973 return GLSL_INTERFACE_PACKING_STD140
;
975 assert(packing
== GLSL_INTERFACE_PACKING_STD430
||
977 (packing
== GLSL_INTERFACE_PACKING_SHARED
||
978 packing
== GLSL_INTERFACE_PACKING_PACKED
)));
979 return GLSL_INTERFACE_PACKING_STD430
;
984 * Check if the type interface is row major
986 bool get_interface_row_major() const
988 return (bool) interface_row_major
;
995 static mtx_t hash_mutex
;
998 * ralloc context for the type itself.
1002 /** Constructor for vector and matrix types */
1003 glsl_type(GLenum gl_type
,
1004 glsl_base_type base_type
, unsigned vector_elements
,
1005 unsigned matrix_columns
, const char *name
,
1006 unsigned explicit_stride
= 0, bool row_major
= false);
1008 /** Constructor for sampler or image types */
1009 glsl_type(GLenum gl_type
, glsl_base_type base_type
,
1010 enum glsl_sampler_dim dim
, bool shadow
, bool array
,
1011 glsl_base_type type
, const char *name
);
1013 /** Constructor for record types */
1014 glsl_type(const glsl_struct_field
*fields
, unsigned num_fields
,
1015 const char *name
, bool packed
= false);
1017 /** Constructor for interface types */
1018 glsl_type(const glsl_struct_field
*fields
, unsigned num_fields
,
1019 enum glsl_interface_packing packing
,
1020 bool row_major
, const char *name
);
1022 /** Constructor for interface types */
1023 glsl_type(const glsl_type
*return_type
,
1024 const glsl_function_param
*params
, unsigned num_params
);
1026 /** Constructors for array types */
1027 glsl_type(const glsl_type
*array
, unsigned length
, unsigned explicit_stride
);
1029 /** Constructor for subroutine types */
1030 glsl_type(const char *name
);
1032 /** Hash table containing the known explicit matrix and vector types. */
1033 static struct hash_table
*explicit_matrix_types
;
1035 /** Hash table containing the known array types. */
1036 static struct hash_table
*array_types
;
1038 /** Hash table containing the known struct types. */
1039 static struct hash_table
*struct_types
;
1041 /** Hash table containing the known interface types. */
1042 static struct hash_table
*interface_types
;
1044 /** Hash table containing the known subroutine types. */
1045 static struct hash_table
*subroutine_types
;
1047 /** Hash table containing the known function types. */
1048 static struct hash_table
*function_types
;
1050 static bool record_key_compare(const void *a
, const void *b
);
1051 static unsigned record_key_hash(const void *key
);
1054 * \name Built-in type flyweights
1058 #define DECL_TYPE(NAME, ...) static const glsl_type _##NAME##_type;
1060 #define STRUCT_TYPE(NAME) static const glsl_type _struct_##NAME##_type;
1061 #include "compiler/builtin_type_macros.h"
1065 * \name Friend functions.
1067 * These functions are friends because they must have C linkage and the
1068 * need to call various private methods or access various private static
1072 friend void glsl_type_singleton_init_or_ref(void);
1073 friend void glsl_type_singleton_decref(void);
1074 friend void _mesa_glsl_initialize_types(struct _mesa_glsl_parse_state
*);
1080 #endif /* __cplusplus */
1082 struct glsl_struct_field
{
1083 const struct glsl_type
*type
;
1087 * For interface blocks, gl_varying_slot corresponding to the input/output
1088 * if this is a built-in input/output (i.e. a member of the built-in
1089 * gl_PerVertex interface block); -1 otherwise.
1091 * Ignored for structs.
1096 * For interface blocks, members may have an explicit byte offset
1097 * specified; -1 otherwise. Also used for xfb_offset layout qualifier.
1099 * Unless used for xfb_offset this field is ignored for structs.
1104 * For interface blocks, members may define a transform feedback buffer;
1110 * For interface blocks, members may define a transform feedback stride;
1116 * For interface blocks, the interpolation mode (as in
1117 * ir_variable::interpolation). 0 otherwise.
1119 unsigned interpolation
:2;
1122 * For interface blocks, 1 if this variable uses centroid interpolation (as
1123 * in ir_variable::centroid). 0 otherwise.
1125 unsigned centroid
:1;
1128 * For interface blocks, 1 if this variable uses sample interpolation (as
1129 * in ir_variable::sample). 0 otherwise.
1134 * Layout of the matrix. Uses glsl_matrix_layout values.
1136 unsigned matrix_layout
:2;
1139 * For interface blocks, 1 if this variable is a per-patch input or output
1140 * (as in ir_variable::patch). 0 otherwise.
1145 * Precision qualifier
1147 unsigned precision
:2;
1150 * Memory qualifiers, applicable to buffer variables defined in shader
1151 * storage buffer objects (SSBOs)
1153 unsigned memory_read_only
:1;
1154 unsigned memory_write_only
:1;
1155 unsigned memory_coherent
:1;
1156 unsigned memory_volatile
:1;
1157 unsigned memory_restrict
:1;
1160 * Layout format, applicable to image variables only.
1162 unsigned image_format
:16;
1165 * Any of the xfb_* qualifiers trigger the shader to be in transform
1166 * feedback mode so we need to keep track of whether the buffer was
1167 * explicitly set or if its just been assigned the default global value.
1169 unsigned explicit_xfb_buffer
:1;
1171 unsigned implicit_sized_array
:1;
1173 glsl_struct_field(const struct glsl_type
*_type
, const char *_name
)
1174 : type(_type
), name(_name
), location(-1), offset(-1), xfb_buffer(0),
1175 xfb_stride(0), interpolation(0), centroid(0),
1176 sample(0), matrix_layout(GLSL_MATRIX_LAYOUT_INHERITED
), patch(0),
1177 precision(GLSL_PRECISION_NONE
), memory_read_only(0),
1178 memory_write_only(0), memory_coherent(0), memory_volatile(0),
1179 memory_restrict(0), image_format(0), explicit_xfb_buffer(0),
1180 implicit_sized_array(0)
1186 : type(NULL
), name(NULL
), location(-1), offset(-1), xfb_buffer(0),
1187 xfb_stride(0), interpolation(0), centroid(0),
1188 sample(0), matrix_layout(0), patch(0),
1189 precision(0), memory_read_only(0),
1190 memory_write_only(0), memory_coherent(0), memory_volatile(0),
1191 memory_restrict(0), image_format(0), explicit_xfb_buffer(0),
1192 implicit_sized_array(0)
1199 struct glsl_function_param
{
1200 const struct glsl_type
*type
;
1206 static inline unsigned int
1207 glsl_align(unsigned int a
, unsigned int align
)
1209 return (a
+ align
- 1) / align
* align
;
1212 #endif /* GLSL_TYPES_H */