glsl: inspect interfaces in contains_foo()
[mesa.git] / src / compiler / glsl_types.h
1 /* -*- c++ -*- */
2 /*
3 * Copyright © 2009 Intel Corporation
4 *
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:
11 *
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
14 * Software.
15 *
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.
23 */
24
25 #pragma once
26 #ifndef GLSL_TYPES_H
27 #define GLSL_TYPES_H
28
29 #include <string.h>
30 #include <assert.h>
31
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35
36 struct _mesa_glsl_parse_state;
37 struct glsl_symbol_table;
38
39 extern void
40 _mesa_glsl_initialize_types(struct _mesa_glsl_parse_state *state);
41
42 extern void
43 _mesa_glsl_release_types(void);
44
45 #ifdef __cplusplus
46 }
47 #endif
48
49 enum glsl_base_type {
50 /* Note: GLSL_TYPE_UINT, GLSL_TYPE_INT, and GLSL_TYPE_FLOAT must be 0, 1,
51 * and 2 so that they will fit in the 2 bits of glsl_type::sampled_type.
52 */
53 GLSL_TYPE_UINT = 0,
54 GLSL_TYPE_INT,
55 GLSL_TYPE_FLOAT,
56 GLSL_TYPE_DOUBLE,
57 GLSL_TYPE_BOOL,
58 GLSL_TYPE_SAMPLER,
59 GLSL_TYPE_IMAGE,
60 GLSL_TYPE_ATOMIC_UINT,
61 GLSL_TYPE_STRUCT,
62 GLSL_TYPE_INTERFACE,
63 GLSL_TYPE_ARRAY,
64 GLSL_TYPE_VOID,
65 GLSL_TYPE_SUBROUTINE,
66 GLSL_TYPE_FUNCTION,
67 GLSL_TYPE_ERROR
68 };
69
70 static inline bool glsl_base_type_is_64bit(enum glsl_base_type type)
71 {
72 return type == GLSL_TYPE_DOUBLE;
73 }
74
75 enum glsl_sampler_dim {
76 GLSL_SAMPLER_DIM_1D = 0,
77 GLSL_SAMPLER_DIM_2D,
78 GLSL_SAMPLER_DIM_3D,
79 GLSL_SAMPLER_DIM_CUBE,
80 GLSL_SAMPLER_DIM_RECT,
81 GLSL_SAMPLER_DIM_BUF,
82 GLSL_SAMPLER_DIM_EXTERNAL,
83 GLSL_SAMPLER_DIM_MS,
84 GLSL_SAMPLER_DIM_SUBPASS, /* for vulkan input attachments */
85 };
86
87 enum glsl_interface_packing {
88 GLSL_INTERFACE_PACKING_STD140,
89 GLSL_INTERFACE_PACKING_SHARED,
90 GLSL_INTERFACE_PACKING_PACKED,
91 GLSL_INTERFACE_PACKING_STD430
92 };
93
94 enum glsl_matrix_layout {
95 /**
96 * The layout of the matrix is inherited from the object containing the
97 * matrix (the top level structure or the uniform block).
98 */
99 GLSL_MATRIX_LAYOUT_INHERITED,
100
101 /**
102 * Explicit column-major layout
103 *
104 * If a uniform block doesn't have an explicit layout set, it will default
105 * to this layout.
106 */
107 GLSL_MATRIX_LAYOUT_COLUMN_MAJOR,
108
109 /**
110 * Row-major layout
111 */
112 GLSL_MATRIX_LAYOUT_ROW_MAJOR
113 };
114
115 enum {
116 GLSL_PRECISION_NONE = 0,
117 GLSL_PRECISION_HIGH,
118 GLSL_PRECISION_MEDIUM,
119 GLSL_PRECISION_LOW
120 };
121
122 #ifdef __cplusplus
123 #include "GL/gl.h"
124 #include "util/ralloc.h"
125 #include "main/mtypes.h" /* for gl_texture_index, C++'s enum rules are broken */
126
127 struct glsl_type {
128 GLenum gl_type;
129 glsl_base_type base_type;
130
131 unsigned sampler_dimensionality:4; /**< \see glsl_sampler_dim */
132 unsigned sampler_shadow:1;
133 unsigned sampler_array:1;
134 unsigned sampled_type:2; /**< Type of data returned using this
135 * sampler or image. Only \c
136 * GLSL_TYPE_FLOAT, \c GLSL_TYPE_INT,
137 * and \c GLSL_TYPE_UINT are valid.
138 */
139 unsigned interface_packing:2;
140 unsigned interface_row_major:1;
141
142 /* Callers of this ralloc-based new need not call delete. It's
143 * easier to just ralloc_free 'mem_ctx' (or any of its ancestors). */
144 static void* operator new(size_t size)
145 {
146 mtx_lock(&glsl_type::mutex);
147
148 /* mem_ctx should have been created by the static members */
149 assert(glsl_type::mem_ctx != NULL);
150
151 void *type;
152
153 type = ralloc_size(glsl_type::mem_ctx, size);
154 assert(type != NULL);
155
156 mtx_unlock(&glsl_type::mutex);
157
158 return type;
159 }
160
161 /* If the user *does* call delete, that's OK, we will just
162 * ralloc_free in that case. */
163 static void operator delete(void *type)
164 {
165 mtx_lock(&glsl_type::mutex);
166 ralloc_free(type);
167 mtx_unlock(&glsl_type::mutex);
168 }
169
170 /**
171 * \name Vector and matrix element counts
172 *
173 * For scalars, each of these values will be 1. For non-numeric types
174 * these will be 0.
175 */
176 /*@{*/
177 uint8_t vector_elements; /**< 1, 2, 3, or 4 vector elements. */
178 uint8_t matrix_columns; /**< 1, 2, 3, or 4 matrix columns. */
179 /*@}*/
180
181 /**
182 * For \c GLSL_TYPE_ARRAY, this is the length of the array. For
183 * \c GLSL_TYPE_STRUCT or \c GLSL_TYPE_INTERFACE, it is the number of
184 * elements in the structure and the number of values pointed to by
185 * \c fields.structure (below).
186 */
187 unsigned length;
188
189 /**
190 * Name of the data type
191 *
192 * Will never be \c NULL.
193 */
194 const char *name;
195
196 /**
197 * Subtype of composite data types.
198 */
199 union {
200 const struct glsl_type *array; /**< Type of array elements. */
201 struct glsl_function_param *parameters; /**< Parameters to function. */
202 struct glsl_struct_field *structure; /**< List of struct fields. */
203 } fields;
204
205 /**
206 * \name Pointers to various public type singletons
207 */
208 /*@{*/
209 #undef DECL_TYPE
210 #define DECL_TYPE(NAME, ...) \
211 static const glsl_type *const NAME##_type;
212 #undef STRUCT_TYPE
213 #define STRUCT_TYPE(NAME) \
214 static const glsl_type *const struct_##NAME##_type;
215 #include "compiler/builtin_type_macros.h"
216 /*@}*/
217
218 /**
219 * Convenience accessors for vector types (shorter than get_instance()).
220 * @{
221 */
222 static const glsl_type *vec(unsigned components);
223 static const glsl_type *dvec(unsigned components);
224 static const glsl_type *ivec(unsigned components);
225 static const glsl_type *uvec(unsigned components);
226 static const glsl_type *bvec(unsigned components);
227 /**@}*/
228
229 /**
230 * For numeric and boolean derived types returns the basic scalar type
231 *
232 * If the type is a numeric or boolean scalar, vector, or matrix type,
233 * this function gets the scalar type of the individual components. For
234 * all other types, including arrays of numeric or boolean types, the
235 * error type is returned.
236 */
237 const glsl_type *get_base_type() const;
238
239 /**
240 * Get the basic scalar type which this type aggregates.
241 *
242 * If the type is a numeric or boolean scalar, vector, or matrix, or an
243 * array of any of those, this function gets the scalar type of the
244 * individual components. For structs and arrays of structs, this function
245 * returns the struct type. For samplers and arrays of samplers, this
246 * function returns the sampler type.
247 */
248 const glsl_type *get_scalar_type() const;
249
250 /**
251 * Get the instance of a built-in scalar, vector, or matrix type
252 */
253 static const glsl_type *get_instance(unsigned base_type, unsigned rows,
254 unsigned columns);
255
256 /**
257 * Get the instance of a sampler type
258 */
259 static const glsl_type *get_sampler_instance(enum glsl_sampler_dim dim,
260 bool shadow,
261 bool array,
262 glsl_base_type type);
263
264 static const glsl_type *get_image_instance(enum glsl_sampler_dim dim,
265 bool array, glsl_base_type type);
266
267 /**
268 * Get the instance of an array type
269 */
270 static const glsl_type *get_array_instance(const glsl_type *base,
271 unsigned elements);
272
273 /**
274 * Get the instance of a record type
275 */
276 static const glsl_type *get_record_instance(const glsl_struct_field *fields,
277 unsigned num_fields,
278 const char *name);
279
280 /**
281 * Get the instance of an interface block type
282 */
283 static const glsl_type *get_interface_instance(const glsl_struct_field *fields,
284 unsigned num_fields,
285 enum glsl_interface_packing packing,
286 bool row_major,
287 const char *block_name);
288
289 /**
290 * Get the instance of an subroutine type
291 */
292 static const glsl_type *get_subroutine_instance(const char *subroutine_name);
293
294 /**
295 * Get the instance of a function type
296 */
297 static const glsl_type *get_function_instance(const struct glsl_type *return_type,
298 const glsl_function_param *parameters,
299 unsigned num_params);
300
301 /**
302 * Get the type resulting from a multiplication of \p type_a * \p type_b
303 */
304 static const glsl_type *get_mul_type(const glsl_type *type_a,
305 const glsl_type *type_b);
306
307 /**
308 * Query the total number of scalars that make up a scalar, vector or matrix
309 */
310 unsigned components() const
311 {
312 return vector_elements * matrix_columns;
313 }
314
315 /**
316 * Calculate the number of components slots required to hold this type
317 *
318 * This is used to determine how many uniform or varying locations a type
319 * might occupy.
320 */
321 unsigned component_slots() const;
322
323 /**
324 * Calculate offset between the base location of the struct in
325 * uniform storage and a struct member.
326 * For the initial call, length is the index of the member to find the
327 * offset for.
328 */
329 unsigned record_location_offset(unsigned length) const;
330
331 /**
332 * Calculate the number of unique values from glGetUniformLocation for the
333 * elements of the type.
334 *
335 * This is used to allocate slots in the UniformRemapTable, the amount of
336 * locations may not match with actual used storage space by the driver.
337 */
338 unsigned uniform_locations() const;
339
340 /**
341 * Used to count the number of varyings contained in the type ignoring
342 * innermost array elements.
343 */
344 unsigned varying_count() const;
345
346 /**
347 * Calculate the number of attribute slots required to hold this type
348 *
349 * This implements the language rules of GLSL 1.50 for counting the number
350 * of slots used by a vertex attribute. It also determines the number of
351 * varying slots the type will use up in the absence of varying packing
352 * (and thus, it can be used to measure the number of varying slots used by
353 * the varyings that are generated by lower_packed_varyings).
354 *
355 * For vertex shader attributes - doubles only take one slot.
356 * For inter-shader varyings - dvec3/dvec4 take two slots.
357 */
358 unsigned count_attribute_slots(bool is_vertex_input) const;
359
360 /**
361 * Alignment in bytes of the start of this type in a std140 uniform
362 * block.
363 */
364 unsigned std140_base_alignment(bool row_major) const;
365
366 /** Size in bytes of this type in a std140 uniform block.
367 *
368 * Note that this is not GL_UNIFORM_SIZE (which is the number of
369 * elements in the array)
370 */
371 unsigned std140_size(bool row_major) const;
372
373 /**
374 * Alignment in bytes of the start of this type in a std430 shader
375 * storage block.
376 */
377 unsigned std430_base_alignment(bool row_major) const;
378
379 /**
380 * Calculate array stride in bytes of this type in a std430 shader storage
381 * block.
382 */
383 unsigned std430_array_stride(bool row_major) const;
384
385 /**
386 * Size in bytes of this type in a std430 shader storage block.
387 *
388 * Note that this is not GL_BUFFER_SIZE
389 */
390 unsigned std430_size(bool row_major) const;
391
392 /**
393 * \brief Can this type be implicitly converted to another?
394 *
395 * \return True if the types are identical or if this type can be converted
396 * to \c desired according to Section 4.1.10 of the GLSL spec.
397 *
398 * \verbatim
399 * From page 25 (31 of the pdf) of the GLSL 1.50 spec, Section 4.1.10
400 * Implicit Conversions:
401 *
402 * In some situations, an expression and its type will be implicitly
403 * converted to a different type. The following table shows all allowed
404 * implicit conversions:
405 *
406 * Type of expression | Can be implicitly converted to
407 * --------------------------------------------------
408 * int float
409 * uint
410 *
411 * ivec2 vec2
412 * uvec2
413 *
414 * ivec3 vec3
415 * uvec3
416 *
417 * ivec4 vec4
418 * uvec4
419 *
420 * There are no implicit array or structure conversions. For example,
421 * an array of int cannot be implicitly converted to an array of float.
422 * There are no implicit conversions between signed and unsigned
423 * integers.
424 * \endverbatim
425 */
426 bool can_implicitly_convert_to(const glsl_type *desired,
427 _mesa_glsl_parse_state *state) const;
428
429 /**
430 * Query whether or not a type is a scalar (non-vector and non-matrix).
431 */
432 bool is_scalar() const
433 {
434 return (vector_elements == 1)
435 && (base_type >= GLSL_TYPE_UINT)
436 && (base_type <= GLSL_TYPE_BOOL);
437 }
438
439 /**
440 * Query whether or not a type is a vector
441 */
442 bool is_vector() const
443 {
444 return (vector_elements > 1)
445 && (matrix_columns == 1)
446 && (base_type >= GLSL_TYPE_UINT)
447 && (base_type <= GLSL_TYPE_BOOL);
448 }
449
450 /**
451 * Query whether or not a type is a matrix
452 */
453 bool is_matrix() const
454 {
455 /* GLSL only has float matrices. */
456 return (matrix_columns > 1) && (base_type == GLSL_TYPE_FLOAT || base_type == GLSL_TYPE_DOUBLE);
457 }
458
459 /**
460 * Query whether or not a type is a non-array numeric type
461 */
462 bool is_numeric() const
463 {
464 return (base_type >= GLSL_TYPE_UINT) && (base_type <= GLSL_TYPE_DOUBLE);
465 }
466
467 /**
468 * Query whether or not a type is an integral type
469 */
470 bool is_integer() const
471 {
472 return (base_type == GLSL_TYPE_UINT) || (base_type == GLSL_TYPE_INT);
473 }
474
475 /**
476 * Query whether or not type is an integral type, or for struct, interface
477 * and array types, contains an integral type.
478 */
479 bool contains_integer() const;
480
481 /**
482 * Query whether or not type is a double type, or for struct, interface and
483 * array types, contains a double type.
484 */
485 bool contains_double() const;
486
487 /**
488 * Query whether or not a type is a float type
489 */
490 bool is_float() const
491 {
492 return base_type == GLSL_TYPE_FLOAT;
493 }
494
495 /**
496 * Query whether or not a type is a double type
497 */
498 bool is_double() const
499 {
500 return base_type == GLSL_TYPE_DOUBLE;
501 }
502
503 /**
504 * Query whether a 64-bit type takes two slots.
505 */
506 bool is_dual_slot() const
507 {
508 return is_64bit() && vector_elements > 2;
509 }
510
511 /**
512 * Query whether or not a type is 64-bit
513 */
514 bool is_64bit() const
515 {
516 return glsl_base_type_is_64bit(base_type);
517 }
518
519 /**
520 * Query whether or not a type is a non-array boolean type
521 */
522 bool is_boolean() const
523 {
524 return base_type == GLSL_TYPE_BOOL;
525 }
526
527 /**
528 * Query whether or not a type is a sampler
529 */
530 bool is_sampler() const
531 {
532 return base_type == GLSL_TYPE_SAMPLER;
533 }
534
535 /**
536 * Query whether or not type is a sampler, or for struct, interface and
537 * array types, contains a sampler.
538 */
539 bool contains_sampler() const;
540
541 /**
542 * Get the Mesa texture target index for a sampler type.
543 */
544 gl_texture_index sampler_index() const;
545
546 /**
547 * Query whether or not type is an image, or for struct, interface and
548 * array types, contains an image.
549 */
550 bool contains_image() const;
551
552 /**
553 * Query whether or not a type is an image
554 */
555 bool is_image() const
556 {
557 return base_type == GLSL_TYPE_IMAGE;
558 }
559
560 /**
561 * Query whether or not a type is an array
562 */
563 bool is_array() const
564 {
565 return base_type == GLSL_TYPE_ARRAY;
566 }
567
568 bool is_array_of_arrays() const
569 {
570 return is_array() && fields.array->is_array();
571 }
572
573 /**
574 * Query whether or not a type is a record
575 */
576 bool is_record() const
577 {
578 return base_type == GLSL_TYPE_STRUCT;
579 }
580
581 /**
582 * Query whether or not a type is an interface
583 */
584 bool is_interface() const
585 {
586 return base_type == GLSL_TYPE_INTERFACE;
587 }
588
589 /**
590 * Query whether or not a type is the void type singleton.
591 */
592 bool is_void() const
593 {
594 return base_type == GLSL_TYPE_VOID;
595 }
596
597 /**
598 * Query whether or not a type is the error type singleton.
599 */
600 bool is_error() const
601 {
602 return base_type == GLSL_TYPE_ERROR;
603 }
604
605 /**
606 * Query if a type is unnamed/anonymous (named by the parser)
607 */
608
609 bool is_subroutine() const
610 {
611 return base_type == GLSL_TYPE_SUBROUTINE;
612 }
613 bool contains_subroutine() const;
614
615 bool is_anonymous() const
616 {
617 return !strncmp(name, "#anon", 5);
618 }
619
620 /**
621 * Get the type stripped of any arrays
622 *
623 * \return
624 * Pointer to the type of elements of the first non-array type for array
625 * types, or pointer to itself for non-array types.
626 */
627 const glsl_type *without_array() const
628 {
629 const glsl_type *t = this;
630
631 while (t->is_array())
632 t = t->fields.array;
633
634 return t;
635 }
636
637 /**
638 * Return the total number of elements in an array including the elements
639 * in arrays of arrays.
640 */
641 unsigned arrays_of_arrays_size() const
642 {
643 if (!is_array())
644 return 0;
645
646 unsigned size = length;
647 const glsl_type *base_type = fields.array;
648
649 while (base_type->is_array()) {
650 size = size * base_type->length;
651 base_type = base_type->fields.array;
652 }
653 return size;
654 }
655
656 /**
657 * Return the amount of atomic counter storage required for a type.
658 */
659 unsigned atomic_size() const
660 {
661 if (base_type == GLSL_TYPE_ATOMIC_UINT)
662 return ATOMIC_COUNTER_SIZE;
663 else if (is_array())
664 return length * fields.array->atomic_size();
665 else
666 return 0;
667 }
668
669 /**
670 * Return whether a type contains any atomic counters.
671 */
672 bool contains_atomic() const
673 {
674 return atomic_size() > 0;
675 }
676
677 /**
678 * Return whether a type contains any opaque types.
679 */
680 bool contains_opaque() const;
681
682 /**
683 * Query the full type of a matrix row
684 *
685 * \return
686 * If the type is not a matrix, \c glsl_type::error_type is returned.
687 * Otherwise a type matching the rows of the matrix is returned.
688 */
689 const glsl_type *row_type() const
690 {
691 return is_matrix()
692 ? get_instance(base_type, matrix_columns, 1)
693 : error_type;
694 }
695
696 /**
697 * Query the full type of a matrix column
698 *
699 * \return
700 * If the type is not a matrix, \c glsl_type::error_type is returned.
701 * Otherwise a type matching the columns of the matrix is returned.
702 */
703 const glsl_type *column_type() const
704 {
705 return is_matrix()
706 ? get_instance(base_type, vector_elements, 1)
707 : error_type;
708 }
709
710 /**
711 * Get the type of a structure field
712 *
713 * \return
714 * Pointer to the type of the named field. If the type is not a structure
715 * or the named field does not exist, \c glsl_type::error_type is returned.
716 */
717 const glsl_type *field_type(const char *name) const;
718
719 /**
720 * Get the location of a field within a record type
721 */
722 int field_index(const char *name) const;
723
724 /**
725 * Query the number of elements in an array type
726 *
727 * \return
728 * The number of elements in the array for array types or -1 for non-array
729 * types. If the number of elements in the array has not yet been declared,
730 * zero is returned.
731 */
732 int array_size() const
733 {
734 return is_array() ? length : -1;
735 }
736
737 /**
738 * Query whether the array size for all dimensions has been declared.
739 */
740 bool is_unsized_array() const
741 {
742 return is_array() && length == 0;
743 }
744
745 /**
746 * Return the number of coordinate components needed for this
747 * sampler or image type.
748 *
749 * This is based purely on the sampler's dimensionality. For example, this
750 * returns 1 for sampler1D, and 3 for sampler2DArray.
751 *
752 * Note that this is often different than actual coordinate type used in
753 * a texturing built-in function, since those pack additional values (such
754 * as the shadow comparitor or projector) into the coordinate type.
755 */
756 int coordinate_components() const;
757
758 /**
759 * Compare a record type against another record type.
760 *
761 * This is useful for matching record types declared across shader stages.
762 * The option to not match locations is to deal with places where the
763 * same struct is defined in a block which has a location set on it.
764 */
765 bool record_compare(const glsl_type *b, bool match_locations = true) const;
766
767 /**
768 * Get the type interface packing.
769 */
770 enum glsl_interface_packing get_interface_packing() const
771 {
772 return (enum glsl_interface_packing)interface_packing;
773 }
774
775 /**
776 * Check if the type interface is row major
777 */
778 bool get_interface_row_major() const
779 {
780 return (bool) interface_row_major;
781 }
782
783 private:
784
785 static mtx_t mutex;
786
787 /**
788 * ralloc context for all glsl_type allocations
789 *
790 * Set on the first call to \c glsl_type::new.
791 */
792 static void *mem_ctx;
793
794 void init_ralloc_type_ctx(void);
795
796 /** Constructor for vector and matrix types */
797 glsl_type(GLenum gl_type,
798 glsl_base_type base_type, unsigned vector_elements,
799 unsigned matrix_columns, const char *name);
800
801 /** Constructor for sampler or image types */
802 glsl_type(GLenum gl_type, glsl_base_type base_type,
803 enum glsl_sampler_dim dim, bool shadow, bool array,
804 unsigned type, const char *name);
805
806 /** Constructor for record types */
807 glsl_type(const glsl_struct_field *fields, unsigned num_fields,
808 const char *name);
809
810 /** Constructor for interface types */
811 glsl_type(const glsl_struct_field *fields, unsigned num_fields,
812 enum glsl_interface_packing packing,
813 bool row_major, const char *name);
814
815 /** Constructor for interface types */
816 glsl_type(const glsl_type *return_type,
817 const glsl_function_param *params, unsigned num_params);
818
819 /** Constructor for array types */
820 glsl_type(const glsl_type *array, unsigned length);
821
822 /** Constructor for subroutine types */
823 glsl_type(const char *name);
824
825 /** Hash table containing the known array types. */
826 static struct hash_table *array_types;
827
828 /** Hash table containing the known record types. */
829 static struct hash_table *record_types;
830
831 /** Hash table containing the known interface types. */
832 static struct hash_table *interface_types;
833
834 /** Hash table containing the known subroutine types. */
835 static struct hash_table *subroutine_types;
836
837 /** Hash table containing the known function types. */
838 static struct hash_table *function_types;
839
840 static bool record_key_compare(const void *a, const void *b);
841 static unsigned record_key_hash(const void *key);
842
843 /**
844 * \name Built-in type flyweights
845 */
846 /*@{*/
847 #undef DECL_TYPE
848 #define DECL_TYPE(NAME, ...) static const glsl_type _##NAME##_type;
849 #undef STRUCT_TYPE
850 #define STRUCT_TYPE(NAME) static const glsl_type _struct_##NAME##_type;
851 #include "compiler/builtin_type_macros.h"
852 /*@}*/
853
854 /**
855 * \name Friend functions.
856 *
857 * These functions are friends because they must have C linkage and the
858 * need to call various private methods or access various private static
859 * data.
860 */
861 /*@{*/
862 friend void _mesa_glsl_initialize_types(struct _mesa_glsl_parse_state *);
863 friend void _mesa_glsl_release_types(void);
864 /*@}*/
865 };
866
867 #undef DECL_TYPE
868 #undef STRUCT_TYPE
869 #endif /* __cplusplus */
870
871 struct glsl_struct_field {
872 const struct glsl_type *type;
873 const char *name;
874
875 /**
876 * For interface blocks, gl_varying_slot corresponding to the input/output
877 * if this is a built-in input/output (i.e. a member of the built-in
878 * gl_PerVertex interface block); -1 otherwise.
879 *
880 * Ignored for structs.
881 */
882 int location;
883
884 /**
885 * For interface blocks, members may have an explicit byte offset
886 * specified; -1 otherwise. Also used for xfb_offset layout qualifier.
887 *
888 * Unless used for xfb_offset this field is ignored for structs.
889 */
890 int offset;
891
892 /**
893 * For interface blocks, members may define a transform feedback buffer;
894 * -1 otherwise.
895 */
896 int xfb_buffer;
897
898 /**
899 * For interface blocks, members may define a transform feedback stride;
900 * -1 otherwise.
901 */
902 int xfb_stride;
903
904 /**
905 * For interface blocks, the interpolation mode (as in
906 * ir_variable::interpolation). 0 otherwise.
907 */
908 unsigned interpolation:2;
909
910 /**
911 * For interface blocks, 1 if this variable uses centroid interpolation (as
912 * in ir_variable::centroid). 0 otherwise.
913 */
914 unsigned centroid:1;
915
916 /**
917 * For interface blocks, 1 if this variable uses sample interpolation (as
918 * in ir_variable::sample). 0 otherwise.
919 */
920 unsigned sample:1;
921
922 /**
923 * Layout of the matrix. Uses glsl_matrix_layout values.
924 */
925 unsigned matrix_layout:2;
926
927 /**
928 * For interface blocks, 1 if this variable is a per-patch input or output
929 * (as in ir_variable::patch). 0 otherwise.
930 */
931 unsigned patch:1;
932
933 /**
934 * Precision qualifier
935 */
936 unsigned precision:2;
937
938 /**
939 * Image qualifiers, applicable to buffer variables defined in shader
940 * storage buffer objects (SSBOs)
941 */
942 unsigned image_read_only:1;
943 unsigned image_write_only:1;
944 unsigned image_coherent:1;
945 unsigned image_volatile:1;
946 unsigned image_restrict:1;
947
948 /**
949 * Any of the xfb_* qualifiers trigger the shader to be in transform
950 * feedback mode so we need to keep track of whether the buffer was
951 * explicitly set or if its just been assigned the default global value.
952 */
953 unsigned explicit_xfb_buffer:1;
954
955 unsigned implicit_sized_array:1;
956 #ifdef __cplusplus
957 glsl_struct_field(const struct glsl_type *_type, const char *_name)
958 : type(_type), name(_name), location(-1), interpolation(0), centroid(0),
959 sample(0), matrix_layout(GLSL_MATRIX_LAYOUT_INHERITED), patch(0),
960 precision(GLSL_PRECISION_NONE), image_read_only(0), image_write_only(0),
961 image_coherent(0), image_volatile(0), image_restrict(0)
962 {
963 /* empty */
964 }
965
966 glsl_struct_field()
967 {
968 /* empty */
969 }
970 #endif
971 };
972
973 struct glsl_function_param {
974 const struct glsl_type *type;
975
976 bool in;
977 bool out;
978 };
979
980 static inline unsigned int
981 glsl_align(unsigned int a, unsigned int align)
982 {
983 return (a + align - 1) / align * align;
984 }
985
986 #endif /* GLSL_TYPES_H */