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_UINT
||
113 type
== GLSL_TYPE_INT
||
114 type
== GLSL_TYPE_UINT64
||
115 type
== GLSL_TYPE_INT64
||
116 type
== GLSL_TYPE_BOOL
||
117 type
== GLSL_TYPE_SAMPLER
||
118 type
== GLSL_TYPE_IMAGE
;
121 static inline unsigned int
122 glsl_base_type_get_bit_size(const enum glsl_base_type base_type
)
130 case GLSL_TYPE_FLOAT
: /* TODO handle mediump */
131 case GLSL_TYPE_SUBROUTINE
:
134 case GLSL_TYPE_FLOAT16
:
135 case GLSL_TYPE_UINT16
:
136 case GLSL_TYPE_INT16
:
139 case GLSL_TYPE_UINT8
:
143 case GLSL_TYPE_DOUBLE
:
144 case GLSL_TYPE_INT64
:
145 case GLSL_TYPE_UINT64
:
146 case GLSL_TYPE_IMAGE
:
147 case GLSL_TYPE_SAMPLER
:
151 unreachable("unknown base type");
157 enum glsl_sampler_dim
{
158 GLSL_SAMPLER_DIM_1D
= 0,
161 GLSL_SAMPLER_DIM_CUBE
,
162 GLSL_SAMPLER_DIM_RECT
,
163 GLSL_SAMPLER_DIM_BUF
,
164 GLSL_SAMPLER_DIM_EXTERNAL
,
166 GLSL_SAMPLER_DIM_SUBPASS
, /* for vulkan input attachments */
167 GLSL_SAMPLER_DIM_SUBPASS_MS
, /* for multisampled vulkan input attachments */
170 enum glsl_matrix_layout
{
172 * The layout of the matrix is inherited from the object containing the
173 * matrix (the top level structure or the uniform block).
175 GLSL_MATRIX_LAYOUT_INHERITED
,
178 * Explicit column-major layout
180 * If a uniform block doesn't have an explicit layout set, it will default
183 GLSL_MATRIX_LAYOUT_COLUMN_MAJOR
,
188 GLSL_MATRIX_LAYOUT_ROW_MAJOR
192 GLSL_PRECISION_NONE
= 0,
194 GLSL_PRECISION_MEDIUM
,
200 #include "util/ralloc.h"
201 #include "main/menums.h" /* for gl_texture_index, C++'s enum rules are broken */
205 glsl_base_type base_type
:8;
207 glsl_base_type sampled_type
:8; /**< Type of data returned using this
208 * sampler or image. Only \c
209 * GLSL_TYPE_FLOAT, \c GLSL_TYPE_INT,
210 * and \c GLSL_TYPE_UINT are valid.
213 unsigned sampler_dimensionality
:4; /**< \see glsl_sampler_dim */
214 unsigned sampler_shadow
:1;
215 unsigned sampler_array
:1;
216 unsigned interface_packing
:2;
217 unsigned interface_row_major
:1;
220 * For \c GLSL_TYPE_STRUCT this specifies if the struct is packed or not.
222 * Only used for Compute kernels
227 glsl_type() : mem_ctx(NULL
)
229 // Dummy constructor, just for the sake of ASSERT_BITFIELD_SIZE.
234 * \name Vector and matrix element counts
236 * For scalars, each of these values will be 1. For non-numeric types
240 uint8_t vector_elements
; /**< 1, 2, 3, or 4 vector elements. */
241 uint8_t matrix_columns
; /**< 1, 2, 3, or 4 matrix columns. */
245 * For \c GLSL_TYPE_ARRAY, this is the length of the array. For
246 * \c GLSL_TYPE_STRUCT or \c GLSL_TYPE_INTERFACE, it is the number of
247 * elements in the structure and the number of values pointed to by
248 * \c fields.structure (below).
253 * Name of the data type
255 * Will never be \c NULL.
260 * Explicit array, matrix, or vector stride. This is used to communicate
261 * explicit array layouts from SPIR-V. Should be 0 if the type has no
264 unsigned explicit_stride
;
267 * Subtype of composite data types.
270 const struct glsl_type
*array
; /**< Type of array elements. */
271 struct glsl_function_param
*parameters
; /**< Parameters to function. */
272 struct glsl_struct_field
*structure
; /**< List of struct fields. */
276 * \name Pointers to various public type singletons
280 #define DECL_TYPE(NAME, ...) \
281 static const glsl_type *const NAME##_type;
283 #define STRUCT_TYPE(NAME) \
284 static const glsl_type *const struct_##NAME##_type;
285 #include "compiler/builtin_type_macros.h"
289 * Convenience accessors for vector types (shorter than get_instance()).
292 static const glsl_type
*vec(unsigned components
, const glsl_type
*const ts
[]);
293 static const glsl_type
*vec(unsigned components
);
294 static const glsl_type
*f16vec(unsigned components
);
295 static const glsl_type
*dvec(unsigned components
);
296 static const glsl_type
*ivec(unsigned components
);
297 static const glsl_type
*uvec(unsigned components
);
298 static const glsl_type
*bvec(unsigned components
);
299 static const glsl_type
*i64vec(unsigned components
);
300 static const glsl_type
*u64vec(unsigned components
);
301 static const glsl_type
*i16vec(unsigned components
);
302 static const glsl_type
*u16vec(unsigned components
);
303 static const glsl_type
*i8vec(unsigned components
);
304 static const glsl_type
*u8vec(unsigned components
);
308 * For numeric and boolean derived types returns the basic scalar type
310 * If the type is a numeric or boolean scalar, vector, or matrix type,
311 * this function gets the scalar type of the individual components. For
312 * all other types, including arrays of numeric or boolean types, the
313 * error type is returned.
315 const glsl_type
*get_base_type() const;
318 * Get the basic scalar type which this type aggregates.
320 * If the type is a numeric or boolean scalar, vector, or matrix, or an
321 * array of any of those, this function gets the scalar type of the
322 * individual components. For structs and arrays of structs, this function
323 * returns the struct type. For samplers and arrays of samplers, this
324 * function returns the sampler type.
326 const glsl_type
*get_scalar_type() const;
329 * Gets the "bare" type without any decorations or layout information.
331 const glsl_type
*get_bare_type() const;
334 * Get the instance of a built-in scalar, vector, or matrix type
336 static const glsl_type
*get_instance(unsigned base_type
, unsigned rows
,
338 unsigned explicit_stride
= 0,
339 bool row_major
= false);
342 * Get the instance of a sampler type
344 static const glsl_type
*get_sampler_instance(enum glsl_sampler_dim dim
,
347 glsl_base_type type
);
349 static const glsl_type
*get_image_instance(enum glsl_sampler_dim dim
,
350 bool array
, glsl_base_type type
);
353 * Get the instance of an array type
355 static const glsl_type
*get_array_instance(const glsl_type
*base
,
357 unsigned explicit_stride
= 0);
360 * Get the instance of a record type
362 static const glsl_type
*get_struct_instance(const glsl_struct_field
*fields
,
365 bool packed
= false);
368 * Get the instance of an interface block type
370 static const glsl_type
*get_interface_instance(const glsl_struct_field
*fields
,
372 enum glsl_interface_packing packing
,
374 const char *block_name
);
377 * Get the instance of an subroutine type
379 static const glsl_type
*get_subroutine_instance(const char *subroutine_name
);
382 * Get the instance of a function type
384 static const glsl_type
*get_function_instance(const struct glsl_type
*return_type
,
385 const glsl_function_param
*parameters
,
386 unsigned num_params
);
389 * Get the type resulting from a multiplication of \p type_a * \p type_b
391 static const glsl_type
*get_mul_type(const glsl_type
*type_a
,
392 const glsl_type
*type_b
);
395 * Query the total number of scalars that make up a scalar, vector or matrix
397 unsigned components() const
399 return vector_elements
* matrix_columns
;
403 * Calculate the number of components slots required to hold this type
405 * This is used to determine how many uniform or varying locations a type
408 unsigned component_slots() const;
411 * Calculate offset between the base location of the struct in
412 * uniform storage and a struct member.
413 * For the initial call, length is the index of the member to find the
416 unsigned struct_location_offset(unsigned length
) const;
419 * Calculate the number of unique values from glGetUniformLocation for the
420 * elements of the type.
422 * This is used to allocate slots in the UniformRemapTable, the amount of
423 * locations may not match with actual used storage space by the driver.
425 unsigned uniform_locations() const;
428 * Used to count the number of varyings contained in the type ignoring
429 * innermost array elements.
431 unsigned varying_count() const;
434 * Calculate the number of attribute slots required to hold this type
436 * This implements the language rules of GLSL 1.50 for counting the number
437 * of slots used by a vertex attribute. It also determines the number of
438 * varying slots the type will use up in the absence of varying packing
439 * (and thus, it can be used to measure the number of varying slots used by
440 * the varyings that are generated by lower_packed_varyings).
442 * For vertex shader attributes - doubles only take one slot.
443 * For inter-shader varyings - dvec3/dvec4 take two slots.
445 * Vulkan doesn’t make this distinction so the argument should always be
448 unsigned count_attribute_slots(bool is_gl_vertex_input
) const;
451 * Alignment in bytes of the start of this type in a std140 uniform
454 unsigned std140_base_alignment(bool row_major
) const;
456 /** Size in bytes of this type in a std140 uniform block.
458 * Note that this is not GL_UNIFORM_SIZE (which is the number of
459 * elements in the array)
461 unsigned std140_size(bool row_major
) const;
464 * Gets an explicitly laid out type with the std140 layout.
466 const glsl_type
*get_explicit_std140_type(bool row_major
) const;
469 * Alignment in bytes of the start of this type in a std430 shader
472 unsigned std430_base_alignment(bool row_major
) const;
475 * Calculate array stride in bytes of this type in a std430 shader storage
478 unsigned std430_array_stride(bool row_major
) const;
481 * Size in bytes of this type in a std430 shader storage block.
483 * Note that this is not GL_BUFFER_SIZE
485 unsigned std430_size(bool row_major
) const;
488 * Gets an explicitly laid out type with the std430 layout.
490 const glsl_type
*get_explicit_std430_type(bool row_major
) const;
493 * Gets an explicitly laid out interface type.
495 const glsl_type
*get_explicit_interface_type(bool supports_std430
) const;
498 * Alignment in bytes of the start of this type in OpenCL memory.
500 unsigned cl_alignment() const;
503 * Size in bytes of this type in OpenCL memory
505 unsigned cl_size() const;
508 * \brief Can this type be implicitly converted to another?
510 * \return True if the types are identical or if this type can be converted
511 * to \c desired according to Section 4.1.10 of the GLSL spec.
514 * From page 25 (31 of the pdf) of the GLSL 1.50 spec, Section 4.1.10
515 * Implicit Conversions:
517 * In some situations, an expression and its type will be implicitly
518 * converted to a different type. The following table shows all allowed
519 * implicit conversions:
521 * Type of expression | Can be implicitly converted to
522 * --------------------------------------------------
535 * There are no implicit array or structure conversions. For example,
536 * an array of int cannot be implicitly converted to an array of float.
537 * There are no implicit conversions between signed and unsigned
541 bool can_implicitly_convert_to(const glsl_type
*desired
,
542 _mesa_glsl_parse_state
*state
) const;
545 * Query whether or not a type is a scalar (non-vector and non-matrix).
547 bool is_scalar() const
549 return (vector_elements
== 1)
550 && (base_type
>= GLSL_TYPE_UINT
)
551 && (base_type
<= GLSL_TYPE_IMAGE
);
555 * Query whether or not a type is a vector
557 bool is_vector() const
559 return (vector_elements
> 1)
560 && (matrix_columns
== 1)
561 && (base_type
>= GLSL_TYPE_UINT
)
562 && (base_type
<= GLSL_TYPE_BOOL
);
566 * Query whether or not a type is a matrix
568 bool is_matrix() const
570 /* GLSL only has float matrices. */
571 return (matrix_columns
> 1) && (base_type
== GLSL_TYPE_FLOAT
||
572 base_type
== GLSL_TYPE_DOUBLE
||
573 base_type
== GLSL_TYPE_FLOAT16
);
577 * Query whether or not a type is a non-array numeric type
579 bool is_numeric() const
581 return (base_type
>= GLSL_TYPE_UINT
) && (base_type
<= GLSL_TYPE_INT64
);
585 * Query whether or not a type is an integral type
587 bool is_integer() const
589 return (base_type
== GLSL_TYPE_UINT
) || (base_type
== GLSL_TYPE_INT
);
593 * Query whether or not a type is a 64-bit integer.
595 bool is_integer_64() const
597 return base_type
== GLSL_TYPE_UINT64
|| base_type
== GLSL_TYPE_INT64
;
601 * Query whether or not a type is a 32-bit or 64-bit integer
603 bool is_integer_32_64() const
605 return is_integer() || is_integer_64();
609 * Query whether or not type is an integral type, or for struct and array
610 * types, contains an integral type.
612 bool contains_integer() const;
615 * Query whether or not type is a double type, or for struct, interface and
616 * array types, contains a double type.
618 bool contains_double() const;
621 * Query whether or not type is a 64-bit type, or for struct, interface and
622 * array types, contains a double type.
624 bool contains_64bit() const;
627 * Query whether or not a type is a float type
629 bool is_float() const
631 return base_type
== GLSL_TYPE_FLOAT
;
635 * Query whether or not a type is a double type
637 bool is_double() const
639 return base_type
== GLSL_TYPE_DOUBLE
;
643 * Query whether a 64-bit type takes two slots.
645 bool is_dual_slot() const
647 return is_64bit() && vector_elements
> 2;
651 * Query whether or not a type is 64-bit
653 bool is_64bit() const
655 return glsl_base_type_is_64bit(base_type
);
659 * Query whether or not a type is 16-bit
661 bool is_16bit() const
663 return glsl_base_type_is_16bit(base_type
);
667 * Query whether or not a type is 32-bit
669 bool is_32bit() const
671 return base_type
== GLSL_TYPE_UINT
||
672 base_type
== GLSL_TYPE_INT
||
673 base_type
== GLSL_TYPE_FLOAT
;
677 * Query whether or not a type is a non-array boolean type
679 bool is_boolean() const
681 return base_type
== GLSL_TYPE_BOOL
;
685 * Query whether or not a type is a sampler
687 bool is_sampler() const
689 return base_type
== GLSL_TYPE_SAMPLER
;
693 * Query whether or not type is a sampler, or for struct, interface and
694 * array types, contains a sampler.
696 bool contains_sampler() const;
699 * Query whether or not type is an array or for struct, interface and
700 * array types, contains an array.
702 bool contains_array() const;
705 * Get the Mesa texture target index for a sampler type.
707 gl_texture_index
sampler_index() const;
710 * Query whether or not type is an image, or for struct, interface and
711 * array types, contains an image.
713 bool contains_image() const;
716 * Query whether or not a type is an image
718 bool is_image() const
720 return base_type
== GLSL_TYPE_IMAGE
;
724 * Query whether or not a type is an array
726 bool is_array() const
728 return base_type
== GLSL_TYPE_ARRAY
;
731 bool is_array_of_arrays() const
733 return is_array() && fields
.array
->is_array();
737 * Query whether or not a type is a record
739 bool is_struct() const
741 return base_type
== GLSL_TYPE_STRUCT
;
745 * Query whether or not a type is an interface
747 bool is_interface() const
749 return base_type
== GLSL_TYPE_INTERFACE
;
753 * Query whether or not a type is the void type singleton.
757 return base_type
== GLSL_TYPE_VOID
;
761 * Query whether or not a type is the error type singleton.
763 bool is_error() const
765 return base_type
== GLSL_TYPE_ERROR
;
769 * Query if a type is unnamed/anonymous (named by the parser)
772 bool is_subroutine() const
774 return base_type
== GLSL_TYPE_SUBROUTINE
;
776 bool contains_subroutine() const;
778 bool is_anonymous() const
780 return !strncmp(name
, "#anon", 5);
784 * Get the type stripped of any arrays
787 * Pointer to the type of elements of the first non-array type for array
788 * types, or pointer to itself for non-array types.
790 const glsl_type
*without_array() const
792 const glsl_type
*t
= this;
794 while (t
->is_array())
801 * Return the total number of elements in an array including the elements
802 * in arrays of arrays.
804 unsigned arrays_of_arrays_size() const
809 unsigned size
= length
;
810 const glsl_type
*base_type
= fields
.array
;
812 while (base_type
->is_array()) {
813 size
= size
* base_type
->length
;
814 base_type
= base_type
->fields
.array
;
820 * Query whether or not a type is an atomic_uint.
822 bool is_atomic_uint() const
824 return base_type
== GLSL_TYPE_ATOMIC_UINT
;
828 * Return the amount of atomic counter storage required for a type.
830 unsigned atomic_size() const
832 if (is_atomic_uint())
833 return ATOMIC_COUNTER_SIZE
;
835 return length
* fields
.array
->atomic_size();
841 * Return whether a type contains any atomic counters.
843 bool contains_atomic() const
845 return atomic_size() > 0;
849 * Return whether a type contains any opaque types.
851 bool contains_opaque() const;
854 * Query the full type of a matrix row
857 * If the type is not a matrix, \c glsl_type::error_type is returned.
858 * Otherwise a type matching the rows of the matrix is returned.
860 const glsl_type
*row_type() const
865 if (explicit_stride
&& !interface_row_major
)
866 return get_instance(base_type
, matrix_columns
, 1, explicit_stride
);
868 return get_instance(base_type
, matrix_columns
, 1);
872 * Query the full type of a matrix column
875 * If the type is not a matrix, \c glsl_type::error_type is returned.
876 * Otherwise a type matching the columns of the matrix is returned.
878 const glsl_type
*column_type() const
883 if (explicit_stride
&& interface_row_major
)
884 return get_instance(base_type
, vector_elements
, 1, explicit_stride
);
886 return get_instance(base_type
, vector_elements
, 1);
890 * Get the type of a structure field
893 * Pointer to the type of the named field. If the type is not a structure
894 * or the named field does not exist, \c glsl_type::error_type is returned.
896 const glsl_type
*field_type(const char *name
) const;
899 * Get the location of a field within a record type
901 int field_index(const char *name
) const;
904 * Query the number of elements in an array type
907 * The number of elements in the array for array types or -1 for non-array
908 * types. If the number of elements in the array has not yet been declared,
911 int array_size() const
913 return is_array() ? length
: -1;
917 * Query whether the array size for all dimensions has been declared.
919 bool is_unsized_array() const
921 return is_array() && length
== 0;
925 * Return the number of coordinate components needed for this
926 * sampler or image type.
928 * This is based purely on the sampler's dimensionality. For example, this
929 * returns 1 for sampler1D, and 3 for sampler2DArray.
931 * Note that this is often different than actual coordinate type used in
932 * a texturing built-in function, since those pack additional values (such
933 * as the shadow comparator or projector) into the coordinate type.
935 int coordinate_components() const;
938 * Compare a record type against another record type.
940 * This is useful for matching record types declared on the same shader
941 * stage as well as across different shader stages.
942 * The option to not match name is needed for matching record types
943 * declared across different shader stages.
944 * The option to not match locations is to deal with places where the
945 * same struct is defined in a block which has a location set on it.
947 bool record_compare(const glsl_type
*b
, bool match_name
,
948 bool match_locations
= true) const;
951 * Get the type interface packing.
953 enum glsl_interface_packing
get_interface_packing() const
955 return (enum glsl_interface_packing
)interface_packing
;
959 * Get the type interface packing used internally. For shared and packing
960 * layouts this is implementation defined.
962 enum glsl_interface_packing
get_internal_ifc_packing(bool std430_supported
) const
964 enum glsl_interface_packing packing
= this->get_interface_packing();
965 if (packing
== GLSL_INTERFACE_PACKING_STD140
||
966 (!std430_supported
&&
967 (packing
== GLSL_INTERFACE_PACKING_SHARED
||
968 packing
== GLSL_INTERFACE_PACKING_PACKED
))) {
969 return GLSL_INTERFACE_PACKING_STD140
;
971 assert(packing
== GLSL_INTERFACE_PACKING_STD430
||
973 (packing
== GLSL_INTERFACE_PACKING_SHARED
||
974 packing
== GLSL_INTERFACE_PACKING_PACKED
)));
975 return GLSL_INTERFACE_PACKING_STD430
;
980 * Check if the type interface is row major
982 bool get_interface_row_major() const
984 return (bool) interface_row_major
;
991 static mtx_t hash_mutex
;
994 * ralloc context for the type itself.
998 /** Constructor for vector and matrix types */
999 glsl_type(GLenum gl_type
,
1000 glsl_base_type base_type
, unsigned vector_elements
,
1001 unsigned matrix_columns
, const char *name
,
1002 unsigned explicit_stride
= 0, bool row_major
= false);
1004 /** Constructor for sampler or image types */
1005 glsl_type(GLenum gl_type
, glsl_base_type base_type
,
1006 enum glsl_sampler_dim dim
, bool shadow
, bool array
,
1007 glsl_base_type type
, const char *name
);
1009 /** Constructor for record types */
1010 glsl_type(const glsl_struct_field
*fields
, unsigned num_fields
,
1011 const char *name
, bool packed
= false);
1013 /** Constructor for interface types */
1014 glsl_type(const glsl_struct_field
*fields
, unsigned num_fields
,
1015 enum glsl_interface_packing packing
,
1016 bool row_major
, const char *name
);
1018 /** Constructor for interface types */
1019 glsl_type(const glsl_type
*return_type
,
1020 const glsl_function_param
*params
, unsigned num_params
);
1022 /** Constructors for array types */
1023 glsl_type(const glsl_type
*array
, unsigned length
, unsigned explicit_stride
);
1025 /** Constructor for subroutine types */
1026 glsl_type(const char *name
);
1028 /** Hash table containing the known explicit matrix and vector types. */
1029 static struct hash_table
*explicit_matrix_types
;
1031 /** Hash table containing the known array types. */
1032 static struct hash_table
*array_types
;
1034 /** Hash table containing the known struct types. */
1035 static struct hash_table
*struct_types
;
1037 /** Hash table containing the known interface types. */
1038 static struct hash_table
*interface_types
;
1040 /** Hash table containing the known subroutine types. */
1041 static struct hash_table
*subroutine_types
;
1043 /** Hash table containing the known function types. */
1044 static struct hash_table
*function_types
;
1046 static bool record_key_compare(const void *a
, const void *b
);
1047 static unsigned record_key_hash(const void *key
);
1050 * \name Built-in type flyweights
1054 #define DECL_TYPE(NAME, ...) static const glsl_type _##NAME##_type;
1056 #define STRUCT_TYPE(NAME) static const glsl_type _struct_##NAME##_type;
1057 #include "compiler/builtin_type_macros.h"
1061 * \name Friend functions.
1063 * These functions are friends because they must have C linkage and the
1064 * need to call various private methods or access various private static
1068 friend void glsl_type_singleton_init_or_ref(void);
1069 friend void glsl_type_singleton_decref(void);
1070 friend void _mesa_glsl_initialize_types(struct _mesa_glsl_parse_state
*);
1076 #endif /* __cplusplus */
1078 struct glsl_struct_field
{
1079 const struct glsl_type
*type
;
1083 * For interface blocks, gl_varying_slot corresponding to the input/output
1084 * if this is a built-in input/output (i.e. a member of the built-in
1085 * gl_PerVertex interface block); -1 otherwise.
1087 * Ignored for structs.
1092 * For interface blocks, members may have an explicit byte offset
1093 * specified; -1 otherwise. Also used for xfb_offset layout qualifier.
1095 * Unless used for xfb_offset this field is ignored for structs.
1100 * For interface blocks, members may define a transform feedback buffer;
1106 * For interface blocks, members may define a transform feedback stride;
1112 * For interface blocks, the interpolation mode (as in
1113 * ir_variable::interpolation). 0 otherwise.
1115 unsigned interpolation
:2;
1118 * For interface blocks, 1 if this variable uses centroid interpolation (as
1119 * in ir_variable::centroid). 0 otherwise.
1121 unsigned centroid
:1;
1124 * For interface blocks, 1 if this variable uses sample interpolation (as
1125 * in ir_variable::sample). 0 otherwise.
1130 * Layout of the matrix. Uses glsl_matrix_layout values.
1132 unsigned matrix_layout
:2;
1135 * For interface blocks, 1 if this variable is a per-patch input or output
1136 * (as in ir_variable::patch). 0 otherwise.
1141 * Precision qualifier
1143 unsigned precision
:2;
1146 * Memory qualifiers, applicable to buffer variables defined in shader
1147 * storage buffer objects (SSBOs)
1149 unsigned memory_read_only
:1;
1150 unsigned memory_write_only
:1;
1151 unsigned memory_coherent
:1;
1152 unsigned memory_volatile
:1;
1153 unsigned memory_restrict
:1;
1156 * Layout format, applicable to image variables only.
1158 unsigned image_format
:16;
1161 * Any of the xfb_* qualifiers trigger the shader to be in transform
1162 * feedback mode so we need to keep track of whether the buffer was
1163 * explicitly set or if its just been assigned the default global value.
1165 unsigned explicit_xfb_buffer
:1;
1167 unsigned implicit_sized_array
:1;
1169 glsl_struct_field(const struct glsl_type
*_type
, const char *_name
)
1170 : type(_type
), name(_name
), location(-1), offset(-1), xfb_buffer(0),
1171 xfb_stride(0), interpolation(0), centroid(0),
1172 sample(0), matrix_layout(GLSL_MATRIX_LAYOUT_INHERITED
), patch(0),
1173 precision(GLSL_PRECISION_NONE
), memory_read_only(0),
1174 memory_write_only(0), memory_coherent(0), memory_volatile(0),
1175 memory_restrict(0), image_format(0), explicit_xfb_buffer(0),
1176 implicit_sized_array(0)
1182 : type(NULL
), name(NULL
), location(-1), offset(-1), xfb_buffer(0),
1183 xfb_stride(0), interpolation(0), centroid(0),
1184 sample(0), matrix_layout(0), patch(0),
1185 precision(0), memory_read_only(0),
1186 memory_write_only(0), memory_coherent(0), memory_volatile(0),
1187 memory_restrict(0), image_format(0), explicit_xfb_buffer(0),
1188 implicit_sized_array(0)
1195 struct glsl_function_param
{
1196 const struct glsl_type
*type
;
1202 static inline unsigned int
1203 glsl_align(unsigned int a
, unsigned int align
)
1205 return (a
+ align
- 1) / align
* align
;
1208 #endif /* GLSL_TYPES_H */