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