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