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 _mesa_glsl_initialize_types(struct _mesa_glsl_parse_state
*state
);
53 _mesa_glsl_release_types(void);
55 void encode_type_to_blob(struct blob
*blob
, const struct glsl_type
*type
);
57 const struct glsl_type
*decode_type_from_blob(struct blob_reader
*blob
);
64 /* Note: GLSL_TYPE_UINT, GLSL_TYPE_INT, and GLSL_TYPE_FLOAT must be 0, 1,
65 * and 2 so that they will fit in the 2 bits of glsl_type::sampled_type.
81 GLSL_TYPE_ATOMIC_UINT
,
91 static inline bool glsl_base_type_is_16bit(enum glsl_base_type type
)
93 return type
== GLSL_TYPE_FLOAT16
||
94 type
== GLSL_TYPE_UINT16
||
95 type
== GLSL_TYPE_INT16
;
98 static inline bool glsl_base_type_is_64bit(enum glsl_base_type type
)
100 return type
== GLSL_TYPE_DOUBLE
||
101 type
== GLSL_TYPE_UINT64
||
102 type
== GLSL_TYPE_INT64
||
103 type
== GLSL_TYPE_IMAGE
||
104 type
== GLSL_TYPE_SAMPLER
;
107 static inline bool glsl_base_type_is_integer(enum glsl_base_type type
)
109 return type
== GLSL_TYPE_UINT
||
110 type
== GLSL_TYPE_INT
||
111 type
== GLSL_TYPE_UINT64
||
112 type
== GLSL_TYPE_INT64
||
113 type
== GLSL_TYPE_BOOL
||
114 type
== GLSL_TYPE_SAMPLER
||
115 type
== GLSL_TYPE_IMAGE
;
118 static inline unsigned int
119 glsl_base_type_get_bit_size(const enum glsl_base_type base_type
)
127 case GLSL_TYPE_FLOAT
: /* TODO handle mediump */
128 case GLSL_TYPE_SUBROUTINE
:
131 case GLSL_TYPE_FLOAT16
:
132 case GLSL_TYPE_UINT16
:
133 case GLSL_TYPE_INT16
:
136 case GLSL_TYPE_UINT8
:
140 case GLSL_TYPE_DOUBLE
:
141 case GLSL_TYPE_INT64
:
142 case GLSL_TYPE_UINT64
:
143 case GLSL_TYPE_IMAGE
:
144 case GLSL_TYPE_SAMPLER
:
148 unreachable("unknown base type");
154 enum glsl_sampler_dim
{
155 GLSL_SAMPLER_DIM_1D
= 0,
158 GLSL_SAMPLER_DIM_CUBE
,
159 GLSL_SAMPLER_DIM_RECT
,
160 GLSL_SAMPLER_DIM_BUF
,
161 GLSL_SAMPLER_DIM_EXTERNAL
,
163 GLSL_SAMPLER_DIM_SUBPASS
, /* for vulkan input attachments */
164 GLSL_SAMPLER_DIM_SUBPASS_MS
, /* for multisampled vulkan input attachments */
167 enum glsl_matrix_layout
{
169 * The layout of the matrix is inherited from the object containing the
170 * matrix (the top level structure or the uniform block).
172 GLSL_MATRIX_LAYOUT_INHERITED
,
175 * Explicit column-major layout
177 * If a uniform block doesn't have an explicit layout set, it will default
180 GLSL_MATRIX_LAYOUT_COLUMN_MAJOR
,
185 GLSL_MATRIX_LAYOUT_ROW_MAJOR
189 GLSL_PRECISION_NONE
= 0,
191 GLSL_PRECISION_MEDIUM
,
197 #include "util/ralloc.h"
198 #include "main/menums.h" /* for gl_texture_index, C++'s enum rules are broken */
202 glsl_base_type base_type
:8;
204 glsl_base_type sampled_type
:8; /**< Type of data returned using this
205 * sampler or image. Only \c
206 * GLSL_TYPE_FLOAT, \c GLSL_TYPE_INT,
207 * and \c GLSL_TYPE_UINT are valid.
210 unsigned sampler_dimensionality
:4; /**< \see glsl_sampler_dim */
211 unsigned sampler_shadow
:1;
212 unsigned sampler_array
:1;
213 unsigned interface_packing
:2;
214 unsigned interface_row_major
:1;
217 * For \c GLSL_TYPE_STRUCT this specifies if the struct is packed or not.
219 * Only used for Compute kernels
224 glsl_type() : mem_ctx(NULL
)
226 // Dummy constructor, just for the sake of ASSERT_BITFIELD_SIZE.
231 * \name Vector and matrix element counts
233 * For scalars, each of these values will be 1. For non-numeric types
237 uint8_t vector_elements
; /**< 1, 2, 3, or 4 vector elements. */
238 uint8_t matrix_columns
; /**< 1, 2, 3, or 4 matrix columns. */
242 * For \c GLSL_TYPE_ARRAY, this is the length of the array. For
243 * \c GLSL_TYPE_STRUCT or \c GLSL_TYPE_INTERFACE, it is the number of
244 * elements in the structure and the number of values pointed to by
245 * \c fields.structure (below).
250 * Name of the data type
252 * Will never be \c NULL.
257 * Explicit array, matrix, or vector stride. This is used to communicate
258 * explicit array layouts from SPIR-V. Should be 0 if the type has no
261 unsigned explicit_stride
;
264 * Subtype of composite data types.
267 const struct glsl_type
*array
; /**< Type of array elements. */
268 struct glsl_function_param
*parameters
; /**< Parameters to function. */
269 struct glsl_struct_field
*structure
; /**< List of struct fields. */
273 * \name Pointers to various public type singletons
277 #define DECL_TYPE(NAME, ...) \
278 static const glsl_type *const NAME##_type;
280 #define STRUCT_TYPE(NAME) \
281 static const glsl_type *const struct_##NAME##_type;
282 #include "compiler/builtin_type_macros.h"
286 * Convenience accessors for vector types (shorter than get_instance()).
289 static const glsl_type
*vec(unsigned components
, const glsl_type
*const ts
[]);
290 static const glsl_type
*vec(unsigned components
);
291 static const glsl_type
*f16vec(unsigned components
);
292 static const glsl_type
*dvec(unsigned components
);
293 static const glsl_type
*ivec(unsigned components
);
294 static const glsl_type
*uvec(unsigned components
);
295 static const glsl_type
*bvec(unsigned components
);
296 static const glsl_type
*i64vec(unsigned components
);
297 static const glsl_type
*u64vec(unsigned components
);
298 static const glsl_type
*i16vec(unsigned components
);
299 static const glsl_type
*u16vec(unsigned components
);
300 static const glsl_type
*i8vec(unsigned components
);
301 static const glsl_type
*u8vec(unsigned components
);
305 * For numeric and boolean derived types returns the basic scalar type
307 * If the type is a numeric or boolean scalar, vector, or matrix type,
308 * this function gets the scalar type of the individual components. For
309 * all other types, including arrays of numeric or boolean types, the
310 * error type is returned.
312 const glsl_type
*get_base_type() const;
315 * Get the basic scalar type which this type aggregates.
317 * If the type is a numeric or boolean scalar, vector, or matrix, or an
318 * array of any of those, this function gets the scalar type of the
319 * individual components. For structs and arrays of structs, this function
320 * returns the struct type. For samplers and arrays of samplers, this
321 * function returns the sampler type.
323 const glsl_type
*get_scalar_type() const;
326 * Gets the "bare" type without any decorations or layout information.
328 const glsl_type
*get_bare_type() const;
331 * Get the instance of a built-in scalar, vector, or matrix type
333 static const glsl_type
*get_instance(unsigned base_type
, unsigned rows
,
335 unsigned explicit_stride
= 0,
336 bool row_major
= false);
339 * Get the instance of a sampler type
341 static const glsl_type
*get_sampler_instance(enum glsl_sampler_dim dim
,
344 glsl_base_type type
);
346 static const glsl_type
*get_image_instance(enum glsl_sampler_dim dim
,
347 bool array
, glsl_base_type type
);
350 * Get the instance of an array type
352 static const glsl_type
*get_array_instance(const glsl_type
*base
,
354 unsigned explicit_stride
= 0);
357 * Get the instance of a record type
359 static const glsl_type
*get_struct_instance(const glsl_struct_field
*fields
,
362 bool packed
= false);
365 * Get the instance of an interface block type
367 static const glsl_type
*get_interface_instance(const glsl_struct_field
*fields
,
369 enum glsl_interface_packing packing
,
371 const char *block_name
);
374 * Get the instance of an subroutine type
376 static const glsl_type
*get_subroutine_instance(const char *subroutine_name
);
379 * Get the instance of a function type
381 static const glsl_type
*get_function_instance(const struct glsl_type
*return_type
,
382 const glsl_function_param
*parameters
,
383 unsigned num_params
);
386 * Get the type resulting from a multiplication of \p type_a * \p type_b
388 static const glsl_type
*get_mul_type(const glsl_type
*type_a
,
389 const glsl_type
*type_b
);
392 * Query the total number of scalars that make up a scalar, vector or matrix
394 unsigned components() const
396 return vector_elements
* matrix_columns
;
400 * Calculate the number of components slots required to hold this type
402 * This is used to determine how many uniform or varying locations a type
405 unsigned component_slots() const;
408 * Calculate offset between the base location of the struct in
409 * uniform storage and a struct member.
410 * For the initial call, length is the index of the member to find the
413 unsigned struct_location_offset(unsigned length
) const;
416 * Calculate the number of unique values from glGetUniformLocation for the
417 * elements of the type.
419 * This is used to allocate slots in the UniformRemapTable, the amount of
420 * locations may not match with actual used storage space by the driver.
422 unsigned uniform_locations() const;
425 * Used to count the number of varyings contained in the type ignoring
426 * innermost array elements.
428 unsigned varying_count() const;
431 * Calculate the number of attribute slots required to hold this type
433 * This implements the language rules of GLSL 1.50 for counting the number
434 * of slots used by a vertex attribute. It also determines the number of
435 * varying slots the type will use up in the absence of varying packing
436 * (and thus, it can be used to measure the number of varying slots used by
437 * the varyings that are generated by lower_packed_varyings).
439 * For vertex shader attributes - doubles only take one slot.
440 * For inter-shader varyings - dvec3/dvec4 take two slots.
442 * Vulkan doesn’t make this distinction so the argument should always be
445 unsigned count_attribute_slots(bool is_gl_vertex_input
) const;
448 * Alignment in bytes of the start of this type in a std140 uniform
451 unsigned std140_base_alignment(bool row_major
) const;
453 /** Size in bytes of this type in a std140 uniform block.
455 * Note that this is not GL_UNIFORM_SIZE (which is the number of
456 * elements in the array)
458 unsigned std140_size(bool row_major
) const;
461 * Gets an explicitly laid out type with the std140 layout.
463 const glsl_type
*get_explicit_std140_type(bool row_major
) const;
466 * Alignment in bytes of the start of this type in a std430 shader
469 unsigned std430_base_alignment(bool row_major
) const;
472 * Calculate array stride in bytes of this type in a std430 shader storage
475 unsigned std430_array_stride(bool row_major
) const;
478 * Size in bytes of this type in a std430 shader storage block.
480 * Note that this is not GL_BUFFER_SIZE
482 unsigned std430_size(bool row_major
) const;
485 * Gets an explicitly laid out type with the std430 layout.
487 const glsl_type
*get_explicit_std430_type(bool row_major
) const;
490 * Gets an explicitly laid out interface type.
492 const glsl_type
*get_explicit_interface_type(bool supports_std430
) const;
495 * Alignment in bytes of the start of this type in OpenCL memory.
497 unsigned cl_alignment() const;
500 * Size in bytes of this type in OpenCL memory
502 unsigned cl_size() const;
505 * \brief Can this type be implicitly converted to another?
507 * \return True if the types are identical or if this type can be converted
508 * to \c desired according to Section 4.1.10 of the GLSL spec.
511 * From page 25 (31 of the pdf) of the GLSL 1.50 spec, Section 4.1.10
512 * Implicit Conversions:
514 * In some situations, an expression and its type will be implicitly
515 * converted to a different type. The following table shows all allowed
516 * implicit conversions:
518 * Type of expression | Can be implicitly converted to
519 * --------------------------------------------------
532 * There are no implicit array or structure conversions. For example,
533 * an array of int cannot be implicitly converted to an array of float.
534 * There are no implicit conversions between signed and unsigned
538 bool can_implicitly_convert_to(const glsl_type
*desired
,
539 _mesa_glsl_parse_state
*state
) const;
542 * Query whether or not a type is a scalar (non-vector and non-matrix).
544 bool is_scalar() const
546 return (vector_elements
== 1)
547 && (base_type
>= GLSL_TYPE_UINT
)
548 && (base_type
<= GLSL_TYPE_IMAGE
);
552 * Query whether or not a type is a vector
554 bool is_vector() const
556 return (vector_elements
> 1)
557 && (matrix_columns
== 1)
558 && (base_type
>= GLSL_TYPE_UINT
)
559 && (base_type
<= GLSL_TYPE_BOOL
);
563 * Query whether or not a type is a matrix
565 bool is_matrix() const
567 /* GLSL only has float matrices. */
568 return (matrix_columns
> 1) && (base_type
== GLSL_TYPE_FLOAT
||
569 base_type
== GLSL_TYPE_DOUBLE
||
570 base_type
== GLSL_TYPE_FLOAT16
);
574 * Query whether or not a type is a non-array numeric type
576 bool is_numeric() const
578 return (base_type
>= GLSL_TYPE_UINT
) && (base_type
<= GLSL_TYPE_INT64
);
582 * Query whether or not a type is an integral type
584 bool is_integer() const
586 return (base_type
== GLSL_TYPE_UINT
) || (base_type
== GLSL_TYPE_INT
);
590 * Query whether or not a type is a 64-bit integer.
592 bool is_integer_64() const
594 return base_type
== GLSL_TYPE_UINT64
|| base_type
== GLSL_TYPE_INT64
;
598 * Query whether or not a type is a 32-bit or 64-bit integer
600 bool is_integer_32_64() const
602 return is_integer() || is_integer_64();
606 * Query whether or not type is an integral type, or for struct and array
607 * types, contains an integral type.
609 bool contains_integer() const;
612 * Query whether or not type is a double type, or for struct, interface and
613 * array types, contains a double type.
615 bool contains_double() const;
618 * Query whether or not type is a 64-bit type, or for struct, interface and
619 * array types, contains a double type.
621 bool contains_64bit() const;
624 * Query whether or not a type is a float type
626 bool is_float() const
628 return base_type
== GLSL_TYPE_FLOAT
;
632 * Query whether or not a type is a double type
634 bool is_double() const
636 return base_type
== GLSL_TYPE_DOUBLE
;
640 * Query whether a 64-bit type takes two slots.
642 bool is_dual_slot() const
644 return is_64bit() && vector_elements
> 2;
648 * Query whether or not a type is 64-bit
650 bool is_64bit() const
652 return glsl_base_type_is_64bit(base_type
);
656 * Query whether or not a type is 16-bit
658 bool is_16bit() const
660 return glsl_base_type_is_16bit(base_type
);
664 * Query whether or not a type is 32-bit
666 bool is_32bit() const
668 return base_type
== GLSL_TYPE_UINT
||
669 base_type
== GLSL_TYPE_INT
||
670 base_type
== GLSL_TYPE_FLOAT
;
674 * Query whether or not a type is a non-array boolean type
676 bool is_boolean() const
678 return base_type
== GLSL_TYPE_BOOL
;
682 * Query whether or not a type is a sampler
684 bool is_sampler() const
686 return base_type
== GLSL_TYPE_SAMPLER
;
690 * Query whether or not type is a sampler, or for struct, interface and
691 * array types, contains a sampler.
693 bool contains_sampler() const;
696 * Query whether or not type is an array or for struct, interface and
697 * array types, contains an array.
699 bool contains_array() const;
702 * Get the Mesa texture target index for a sampler type.
704 gl_texture_index
sampler_index() const;
707 * Query whether or not type is an image, or for struct, interface and
708 * array types, contains an image.
710 bool contains_image() const;
713 * Query whether or not a type is an image
715 bool is_image() const
717 return base_type
== GLSL_TYPE_IMAGE
;
721 * Query whether or not a type is an array
723 bool is_array() const
725 return base_type
== GLSL_TYPE_ARRAY
;
728 bool is_array_of_arrays() const
730 return is_array() && fields
.array
->is_array();
734 * Query whether or not a type is a record
736 bool is_struct() const
738 return base_type
== GLSL_TYPE_STRUCT
;
742 * Query whether or not a type is an interface
744 bool is_interface() const
746 return base_type
== GLSL_TYPE_INTERFACE
;
750 * Query whether or not a type is the void type singleton.
754 return base_type
== GLSL_TYPE_VOID
;
758 * Query whether or not a type is the error type singleton.
760 bool is_error() const
762 return base_type
== GLSL_TYPE_ERROR
;
766 * Query if a type is unnamed/anonymous (named by the parser)
769 bool is_subroutine() const
771 return base_type
== GLSL_TYPE_SUBROUTINE
;
773 bool contains_subroutine() const;
775 bool is_anonymous() const
777 return !strncmp(name
, "#anon", 5);
781 * Get the type stripped of any arrays
784 * Pointer to the type of elements of the first non-array type for array
785 * types, or pointer to itself for non-array types.
787 const glsl_type
*without_array() const
789 const glsl_type
*t
= this;
791 while (t
->is_array())
798 * Return the total number of elements in an array including the elements
799 * in arrays of arrays.
801 unsigned arrays_of_arrays_size() const
806 unsigned size
= length
;
807 const glsl_type
*base_type
= fields
.array
;
809 while (base_type
->is_array()) {
810 size
= size
* base_type
->length
;
811 base_type
= base_type
->fields
.array
;
817 * Query whether or not a type is an atomic_uint.
819 bool is_atomic_uint() const
821 return base_type
== GLSL_TYPE_ATOMIC_UINT
;
825 * Return the amount of atomic counter storage required for a type.
827 unsigned atomic_size() const
829 if (is_atomic_uint())
830 return ATOMIC_COUNTER_SIZE
;
832 return length
* fields
.array
->atomic_size();
838 * Return whether a type contains any atomic counters.
840 bool contains_atomic() const
842 return atomic_size() > 0;
846 * Return whether a type contains any opaque types.
848 bool contains_opaque() const;
851 * Query the full type of a matrix row
854 * If the type is not a matrix, \c glsl_type::error_type is returned.
855 * Otherwise a type matching the rows of the matrix is returned.
857 const glsl_type
*row_type() const
862 if (explicit_stride
&& !interface_row_major
)
863 return get_instance(base_type
, matrix_columns
, 1, explicit_stride
);
865 return get_instance(base_type
, matrix_columns
, 1);
869 * Query the full type of a matrix column
872 * If the type is not a matrix, \c glsl_type::error_type is returned.
873 * Otherwise a type matching the columns of the matrix is returned.
875 const glsl_type
*column_type() const
880 if (explicit_stride
&& interface_row_major
)
881 return get_instance(base_type
, vector_elements
, 1, explicit_stride
);
883 return get_instance(base_type
, vector_elements
, 1);
887 * Get the type of a structure field
890 * Pointer to the type of the named field. If the type is not a structure
891 * or the named field does not exist, \c glsl_type::error_type is returned.
893 const glsl_type
*field_type(const char *name
) const;
896 * Get the location of a field within a record type
898 int field_index(const char *name
) const;
901 * Query the number of elements in an array type
904 * The number of elements in the array for array types or -1 for non-array
905 * types. If the number of elements in the array has not yet been declared,
908 int array_size() const
910 return is_array() ? length
: -1;
914 * Query whether the array size for all dimensions has been declared.
916 bool is_unsized_array() const
918 return is_array() && length
== 0;
922 * Return the number of coordinate components needed for this
923 * sampler or image type.
925 * This is based purely on the sampler's dimensionality. For example, this
926 * returns 1 for sampler1D, and 3 for sampler2DArray.
928 * Note that this is often different than actual coordinate type used in
929 * a texturing built-in function, since those pack additional values (such
930 * as the shadow comparator or projector) into the coordinate type.
932 int coordinate_components() const;
935 * Compare a record type against another record type.
937 * This is useful for matching record types declared on the same shader
938 * stage as well as across different shader stages.
939 * The option to not match name is needed for matching record types
940 * declared across different shader stages.
941 * The option to not match locations is to deal with places where the
942 * same struct is defined in a block which has a location set on it.
944 bool record_compare(const glsl_type
*b
, bool match_name
,
945 bool match_locations
= true) const;
948 * Get the type interface packing.
950 enum glsl_interface_packing
get_interface_packing() const
952 return (enum glsl_interface_packing
)interface_packing
;
956 * Get the type interface packing used internally. For shared and packing
957 * layouts this is implementation defined.
959 enum glsl_interface_packing
get_internal_ifc_packing(bool std430_supported
) const
961 enum glsl_interface_packing packing
= this->get_interface_packing();
962 if (packing
== GLSL_INTERFACE_PACKING_STD140
||
963 (!std430_supported
&&
964 (packing
== GLSL_INTERFACE_PACKING_SHARED
||
965 packing
== GLSL_INTERFACE_PACKING_PACKED
))) {
966 return GLSL_INTERFACE_PACKING_STD140
;
968 assert(packing
== GLSL_INTERFACE_PACKING_STD430
||
970 (packing
== GLSL_INTERFACE_PACKING_SHARED
||
971 packing
== GLSL_INTERFACE_PACKING_PACKED
)));
972 return GLSL_INTERFACE_PACKING_STD430
;
977 * Check if the type interface is row major
979 bool get_interface_row_major() const
981 return (bool) interface_row_major
;
988 static mtx_t hash_mutex
;
991 * ralloc context for the type itself.
995 /** Constructor for vector and matrix types */
996 glsl_type(GLenum gl_type
,
997 glsl_base_type base_type
, unsigned vector_elements
,
998 unsigned matrix_columns
, const char *name
,
999 unsigned explicit_stride
= 0, bool row_major
= false);
1001 /** Constructor for sampler or image types */
1002 glsl_type(GLenum gl_type
, glsl_base_type base_type
,
1003 enum glsl_sampler_dim dim
, bool shadow
, bool array
,
1004 glsl_base_type type
, const char *name
);
1006 /** Constructor for record types */
1007 glsl_type(const glsl_struct_field
*fields
, unsigned num_fields
,
1008 const char *name
, bool packed
= false);
1010 /** Constructor for interface types */
1011 glsl_type(const glsl_struct_field
*fields
, unsigned num_fields
,
1012 enum glsl_interface_packing packing
,
1013 bool row_major
, const char *name
);
1015 /** Constructor for interface types */
1016 glsl_type(const glsl_type
*return_type
,
1017 const glsl_function_param
*params
, unsigned num_params
);
1019 /** Constructors for array types */
1020 glsl_type(const glsl_type
*array
, unsigned length
, unsigned explicit_stride
);
1022 /** Constructor for subroutine types */
1023 glsl_type(const char *name
);
1025 /** Hash table containing the known explicit matrix and vector types. */
1026 static struct hash_table
*explicit_matrix_types
;
1028 /** Hash table containing the known array types. */
1029 static struct hash_table
*array_types
;
1031 /** Hash table containing the known struct types. */
1032 static struct hash_table
*struct_types
;
1034 /** Hash table containing the known interface types. */
1035 static struct hash_table
*interface_types
;
1037 /** Hash table containing the known subroutine types. */
1038 static struct hash_table
*subroutine_types
;
1040 /** Hash table containing the known function types. */
1041 static struct hash_table
*function_types
;
1043 static bool record_key_compare(const void *a
, const void *b
);
1044 static unsigned record_key_hash(const void *key
);
1047 * \name Built-in type flyweights
1051 #define DECL_TYPE(NAME, ...) static const glsl_type _##NAME##_type;
1053 #define STRUCT_TYPE(NAME) static const glsl_type _struct_##NAME##_type;
1054 #include "compiler/builtin_type_macros.h"
1058 * \name Friend functions.
1060 * These functions are friends because they must have C linkage and the
1061 * need to call various private methods or access various private static
1065 friend void _mesa_glsl_initialize_types(struct _mesa_glsl_parse_state
*);
1066 friend void _mesa_glsl_release_types(void);
1072 #endif /* __cplusplus */
1074 struct glsl_struct_field
{
1075 const struct glsl_type
*type
;
1079 * For interface blocks, gl_varying_slot corresponding to the input/output
1080 * if this is a built-in input/output (i.e. a member of the built-in
1081 * gl_PerVertex interface block); -1 otherwise.
1083 * Ignored for structs.
1088 * For interface blocks, members may have an explicit byte offset
1089 * specified; -1 otherwise. Also used for xfb_offset layout qualifier.
1091 * Unless used for xfb_offset this field is ignored for structs.
1096 * For interface blocks, members may define a transform feedback buffer;
1102 * For interface blocks, members may define a transform feedback stride;
1108 * For interface blocks, the interpolation mode (as in
1109 * ir_variable::interpolation). 0 otherwise.
1111 unsigned interpolation
:2;
1114 * For interface blocks, 1 if this variable uses centroid interpolation (as
1115 * in ir_variable::centroid). 0 otherwise.
1117 unsigned centroid
:1;
1120 * For interface blocks, 1 if this variable uses sample interpolation (as
1121 * in ir_variable::sample). 0 otherwise.
1126 * Layout of the matrix. Uses glsl_matrix_layout values.
1128 unsigned matrix_layout
:2;
1131 * For interface blocks, 1 if this variable is a per-patch input or output
1132 * (as in ir_variable::patch). 0 otherwise.
1137 * Precision qualifier
1139 unsigned precision
:2;
1142 * Memory qualifiers, applicable to buffer variables defined in shader
1143 * storage buffer objects (SSBOs)
1145 unsigned memory_read_only
:1;
1146 unsigned memory_write_only
:1;
1147 unsigned memory_coherent
:1;
1148 unsigned memory_volatile
:1;
1149 unsigned memory_restrict
:1;
1152 * Layout format, applicable to image variables only.
1154 unsigned image_format
:16;
1157 * Any of the xfb_* qualifiers trigger the shader to be in transform
1158 * feedback mode so we need to keep track of whether the buffer was
1159 * explicitly set or if its just been assigned the default global value.
1161 unsigned explicit_xfb_buffer
:1;
1163 unsigned implicit_sized_array
:1;
1165 glsl_struct_field(const struct glsl_type
*_type
, const char *_name
)
1166 : type(_type
), name(_name
), location(-1), offset(-1), xfb_buffer(0),
1167 xfb_stride(0), interpolation(0), centroid(0),
1168 sample(0), matrix_layout(GLSL_MATRIX_LAYOUT_INHERITED
), patch(0),
1169 precision(GLSL_PRECISION_NONE
), memory_read_only(0),
1170 memory_write_only(0), memory_coherent(0), memory_volatile(0),
1171 memory_restrict(0), image_format(0), explicit_xfb_buffer(0),
1172 implicit_sized_array(0)
1178 : type(NULL
), name(NULL
), location(-1), offset(-1), xfb_buffer(0),
1179 xfb_stride(0), interpolation(0), centroid(0),
1180 sample(0), matrix_layout(0), patch(0),
1181 precision(0), memory_read_only(0),
1182 memory_write_only(0), memory_coherent(0), memory_volatile(0),
1183 memory_restrict(0), image_format(0), explicit_xfb_buffer(0),
1184 implicit_sized_array(0)
1191 struct glsl_function_param
{
1192 const struct glsl_type
*type
;
1198 static inline unsigned int
1199 glsl_align(unsigned int a
, unsigned int align
)
1201 return (a
+ align
- 1) / align
* align
;
1204 #endif /* GLSL_TYPES_H */