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