Merge remote-tracking branch 'mesa-public/master' into vulkan
[mesa.git] / src / glsl / nir / 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_FUNCTION,
60 GLSL_TYPE_INTERFACE,
61 GLSL_TYPE_ARRAY,
62 GLSL_TYPE_VOID,
63 GLSL_TYPE_SUBROUTINE,
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 sampler_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 "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 * Calculate the number of attribute slots required to hold this type
331 *
332 * This implements the language rules of GLSL 1.50 for counting the number
333 * of slots used by a vertex attribute. It also determines the number of
334 * varying slots the type will use up in the absence of varying packing
335 * (and thus, it can be used to measure the number of varying slots used by
336 * the varyings that are generated by lower_packed_varyings).
337 */
338 unsigned count_attribute_slots() const;
339
340 /**
341 * Alignment in bytes of the start of this type in a std140 uniform
342 * block.
343 */
344 unsigned std140_base_alignment(bool row_major) const;
345
346 /** Size in bytes of this type in a std140 uniform block.
347 *
348 * Note that this is not GL_UNIFORM_SIZE (which is the number of
349 * elements in the array)
350 */
351 unsigned std140_size(bool row_major) const;
352
353 /**
354 * Alignment in bytes of the start of this type in a std430 shader
355 * storage block.
356 */
357 unsigned std430_base_alignment(bool row_major) const;
358
359 /**
360 * Calculate array stride in bytes of this type in a std430 shader storage
361 * block.
362 */
363 unsigned std430_array_stride(bool row_major) const;
364
365 /**
366 * Size in bytes of this type in a std430 shader storage block.
367 *
368 * Note that this is not GL_BUFFER_SIZE
369 */
370 unsigned std430_size(bool row_major) const;
371
372 /**
373 * \brief Can this type be implicitly converted to another?
374 *
375 * \return True if the types are identical or if this type can be converted
376 * to \c desired according to Section 4.1.10 of the GLSL spec.
377 *
378 * \verbatim
379 * From page 25 (31 of the pdf) of the GLSL 1.50 spec, Section 4.1.10
380 * Implicit Conversions:
381 *
382 * In some situations, an expression and its type will be implicitly
383 * converted to a different type. The following table shows all allowed
384 * implicit conversions:
385 *
386 * Type of expression | Can be implicitly converted to
387 * --------------------------------------------------
388 * int float
389 * uint
390 *
391 * ivec2 vec2
392 * uvec2
393 *
394 * ivec3 vec3
395 * uvec3
396 *
397 * ivec4 vec4
398 * uvec4
399 *
400 * There are no implicit array or structure conversions. For example,
401 * an array of int cannot be implicitly converted to an array of float.
402 * There are no implicit conversions between signed and unsigned
403 * integers.
404 * \endverbatim
405 */
406 bool can_implicitly_convert_to(const glsl_type *desired,
407 _mesa_glsl_parse_state *state) const;
408
409 /**
410 * Query whether or not a type is a scalar (non-vector and non-matrix).
411 */
412 bool is_scalar() const
413 {
414 return (vector_elements == 1)
415 && (base_type >= GLSL_TYPE_UINT)
416 && (base_type <= GLSL_TYPE_BOOL);
417 }
418
419 /**
420 * Query whether or not a type is a vector
421 */
422 bool is_vector() const
423 {
424 return (vector_elements > 1)
425 && (matrix_columns == 1)
426 && (base_type >= GLSL_TYPE_UINT)
427 && (base_type <= GLSL_TYPE_BOOL);
428 }
429
430 /**
431 * Query whether or not a type is a matrix
432 */
433 bool is_matrix() const
434 {
435 /* GLSL only has float matrices. */
436 return (matrix_columns > 1) && (base_type == GLSL_TYPE_FLOAT || base_type == GLSL_TYPE_DOUBLE);
437 }
438
439 /**
440 * Query whether or not a type is a non-array numeric type
441 */
442 bool is_numeric() const
443 {
444 return (base_type >= GLSL_TYPE_UINT) && (base_type <= GLSL_TYPE_DOUBLE);
445 }
446
447 /**
448 * Query whether or not a type is an integral type
449 */
450 bool is_integer() const
451 {
452 return (base_type == GLSL_TYPE_UINT) || (base_type == GLSL_TYPE_INT);
453 }
454
455 /**
456 * Query whether or not type is an integral type, or for struct and array
457 * types, contains an integral type.
458 */
459 bool contains_integer() const;
460
461 /**
462 * Query whether or not type is a double type, or for struct and array
463 * types, contains a double type.
464 */
465 bool contains_double() const;
466
467 /**
468 * Query whether or not a type is a float type
469 */
470 bool is_float() const
471 {
472 return base_type == GLSL_TYPE_FLOAT;
473 }
474
475 /**
476 * Query whether or not a type is a double type
477 */
478 bool is_double() const
479 {
480 return base_type == GLSL_TYPE_DOUBLE;
481 }
482
483 /**
484 * Query whether or not a type is a non-array boolean type
485 */
486 bool is_boolean() const
487 {
488 return base_type == GLSL_TYPE_BOOL;
489 }
490
491 /**
492 * Query whether or not a type is a sampler
493 */
494 bool is_sampler() const
495 {
496 return base_type == GLSL_TYPE_SAMPLER;
497 }
498
499 /**
500 * Query whether or not type is a sampler, or for struct and array
501 * types, contains a sampler.
502 */
503 bool contains_sampler() const;
504
505 /**
506 * Get the Mesa texture target index for a sampler type.
507 */
508 gl_texture_index sampler_index() const;
509
510 /**
511 * Query whether or not type is an image, or for struct and array
512 * types, contains an image.
513 */
514 bool contains_image() const;
515
516 /**
517 * Query whether or not a type is an image
518 */
519 bool is_image() const
520 {
521 return base_type == GLSL_TYPE_IMAGE;
522 }
523
524 /**
525 * Query whether or not a type is an array
526 */
527 bool is_array() const
528 {
529 return base_type == GLSL_TYPE_ARRAY;
530 }
531
532 bool is_array_of_arrays() const
533 {
534 return is_array() && fields.array->is_array();
535 }
536
537 /**
538 * Query whether or not a type is a record
539 */
540 bool is_record() const
541 {
542 return base_type == GLSL_TYPE_STRUCT;
543 }
544
545 /**
546 * Query whether or not a type is an interface
547 */
548 bool is_interface() const
549 {
550 return base_type == GLSL_TYPE_INTERFACE;
551 }
552
553 /**
554 * Query whether or not a type is the void type singleton.
555 */
556 bool is_void() const
557 {
558 return base_type == GLSL_TYPE_VOID;
559 }
560
561 /**
562 * Query whether or not a type is the error type singleton.
563 */
564 bool is_error() const
565 {
566 return base_type == GLSL_TYPE_ERROR;
567 }
568
569 /**
570 * Query if a type is unnamed/anonymous (named by the parser)
571 */
572
573 bool is_subroutine() const
574 {
575 return base_type == GLSL_TYPE_SUBROUTINE;
576 }
577 bool contains_subroutine() const;
578
579 bool is_anonymous() const
580 {
581 return !strncmp(name, "#anon", 5);
582 }
583
584 /**
585 * Get the type stripped of any arrays
586 *
587 * \return
588 * Pointer to the type of elements of the first non-array type for array
589 * types, or pointer to itself for non-array types.
590 */
591 const glsl_type *without_array() const
592 {
593 const glsl_type *t = this;
594
595 while (t->is_array())
596 t = t->fields.array;
597
598 return t;
599 }
600
601 /**
602 * Return the total number of elements in an array including the elements
603 * in arrays of arrays.
604 */
605 unsigned arrays_of_arrays_size() const
606 {
607 if (!is_array())
608 return 0;
609
610 unsigned size = length;
611 const glsl_type *base_type = fields.array;
612
613 while (base_type->is_array()) {
614 size = size * base_type->length;
615 base_type = base_type->fields.array;
616 }
617 return size;
618 }
619
620 /**
621 * Return the amount of atomic counter storage required for a type.
622 */
623 unsigned atomic_size() const
624 {
625 if (base_type == GLSL_TYPE_ATOMIC_UINT)
626 return ATOMIC_COUNTER_SIZE;
627 else if (is_array())
628 return length * fields.array->atomic_size();
629 else
630 return 0;
631 }
632
633 /**
634 * Return whether a type contains any atomic counters.
635 */
636 bool contains_atomic() const
637 {
638 return atomic_size() > 0;
639 }
640
641 /**
642 * Return whether a type contains any opaque types.
643 */
644 bool contains_opaque() const;
645
646 /**
647 * Query the full type of a matrix row
648 *
649 * \return
650 * If the type is not a matrix, \c glsl_type::error_type is returned.
651 * Otherwise a type matching the rows of the matrix is returned.
652 */
653 const glsl_type *row_type() const
654 {
655 return is_matrix()
656 ? get_instance(base_type, matrix_columns, 1)
657 : error_type;
658 }
659
660 /**
661 * Query the full type of a matrix column
662 *
663 * \return
664 * If the type is not a matrix, \c glsl_type::error_type is returned.
665 * Otherwise a type matching the columns of the matrix is returned.
666 */
667 const glsl_type *column_type() const
668 {
669 return is_matrix()
670 ? get_instance(base_type, vector_elements, 1)
671 : error_type;
672 }
673
674 /**
675 * Get the type of a structure field
676 *
677 * \return
678 * Pointer to the type of the named field. If the type is not a structure
679 * or the named field does not exist, \c glsl_type::error_type is returned.
680 */
681 const glsl_type *field_type(const char *name) const;
682
683 /**
684 * Get the location of a field within a record type
685 */
686 int field_index(const char *name) const;
687
688 /**
689 * Query the number of elements in an array type
690 *
691 * \return
692 * The number of elements in the array for array types or -1 for non-array
693 * types. If the number of elements in the array has not yet been declared,
694 * zero is returned.
695 */
696 int array_size() const
697 {
698 return is_array() ? length : -1;
699 }
700
701 /**
702 * Query whether the array size for all dimensions has been declared.
703 */
704 bool is_unsized_array() const
705 {
706 return is_array() && length == 0;
707 }
708
709 /**
710 * Return the number of coordinate components needed for this
711 * sampler or image type.
712 *
713 * This is based purely on the sampler's dimensionality. For example, this
714 * returns 1 for sampler1D, and 3 for sampler2DArray.
715 *
716 * Note that this is often different than actual coordinate type used in
717 * a texturing built-in function, since those pack additional values (such
718 * as the shadow comparitor or projector) into the coordinate type.
719 */
720 int coordinate_components() const;
721
722 /**
723 * Compare a record type against another record type.
724 *
725 * This is useful for matching record types declared across shader stages.
726 */
727 bool record_compare(const glsl_type *b) const;
728
729 private:
730
731 static mtx_t mutex;
732
733 /**
734 * ralloc context for all glsl_type allocations
735 *
736 * Set on the first call to \c glsl_type::new.
737 */
738 static void *mem_ctx;
739
740 void init_ralloc_type_ctx(void);
741
742 /** Constructor for vector and matrix types */
743 glsl_type(GLenum gl_type,
744 glsl_base_type base_type, unsigned vector_elements,
745 unsigned matrix_columns, const char *name);
746
747 /** Constructor for sampler or image types */
748 glsl_type(GLenum gl_type, glsl_base_type base_type,
749 enum glsl_sampler_dim dim, bool shadow, bool array,
750 unsigned type, const char *name);
751
752 /** Constructor for record types */
753 glsl_type(const glsl_struct_field *fields, unsigned num_fields,
754 const char *name);
755
756 /** Constructor for interface types */
757 glsl_type(const glsl_struct_field *fields, unsigned num_fields,
758 enum glsl_interface_packing packing, const char *name);
759
760 /** Constructor for interface types */
761 glsl_type(const glsl_type *return_type,
762 const glsl_function_param *params, unsigned num_params);
763
764 /** Constructor for array types */
765 glsl_type(const glsl_type *array, unsigned length);
766
767 /** Constructor for subroutine types */
768 glsl_type(const char *name);
769
770 /** Hash table containing the known array types. */
771 static struct hash_table *array_types;
772
773 /** Hash table containing the known record types. */
774 static struct hash_table *record_types;
775
776 /** Hash table containing the known interface types. */
777 static struct hash_table *interface_types;
778
779 /** Hash table containing the known subroutine types. */
780 static struct hash_table *subroutine_types;
781
782 /** Hash table containing the known function types. */
783 static struct hash_table *function_types;
784
785 static bool record_key_compare(const void *a, const void *b);
786 static unsigned record_key_hash(const void *key);
787
788 /**
789 * \name Built-in type flyweights
790 */
791 /*@{*/
792 #undef DECL_TYPE
793 #define DECL_TYPE(NAME, ...) static const glsl_type _##NAME##_type;
794 #undef STRUCT_TYPE
795 #define STRUCT_TYPE(NAME) static const glsl_type _struct_##NAME##_type;
796 #include "builtin_type_macros.h"
797 /*@}*/
798
799 /**
800 * \name Friend functions.
801 *
802 * These functions are friends because they must have C linkage and the
803 * need to call various private methods or access various private static
804 * data.
805 */
806 /*@{*/
807 friend void _mesa_glsl_initialize_types(struct _mesa_glsl_parse_state *);
808 friend void _mesa_glsl_release_types(void);
809 /*@}*/
810 };
811
812 #undef DECL_TYPE
813 #undef STRUCT_TYPE
814 #endif /* __cplusplus */
815
816 struct glsl_struct_field {
817 const struct glsl_type *type;
818 const char *name;
819
820 /**
821 * For interface blocks, gl_varying_slot corresponding to the input/output
822 * if this is a built-in input/output (i.e. a member of the built-in
823 * gl_PerVertex interface block); -1 otherwise.
824 *
825 * Ignored for structs.
826 */
827 int location;
828
829 /**
830 * For interface blocks, the interpolation mode (as in
831 * ir_variable::interpolation). 0 otherwise.
832 */
833 unsigned interpolation:2;
834
835 /**
836 * For interface blocks, 1 if this variable uses centroid interpolation (as
837 * in ir_variable::centroid). 0 otherwise.
838 */
839 unsigned centroid:1;
840
841 /**
842 * For interface blocks, 1 if this variable uses sample interpolation (as
843 * in ir_variable::sample). 0 otherwise.
844 */
845 unsigned sample:1;
846
847 /**
848 * Layout of the matrix. Uses glsl_matrix_layout values.
849 */
850 unsigned matrix_layout:2;
851
852 /**
853 * For interface blocks, 1 if this variable is a per-patch input or output
854 * (as in ir_variable::patch). 0 otherwise.
855 */
856 unsigned patch:1;
857
858 /**
859 * Precision qualifier
860 */
861 unsigned precision:2;
862
863 /**
864 * Image qualifiers, applicable to buffer variables defined in shader
865 * storage buffer objects (SSBOs)
866 */
867 unsigned image_read_only:1;
868 unsigned image_write_only:1;
869 unsigned image_coherent:1;
870 unsigned image_volatile:1;
871 unsigned image_restrict:1;
872
873 #ifdef __cplusplus
874 glsl_struct_field(const struct glsl_type *_type, const char *_name)
875 : type(_type), name(_name), location(-1), interpolation(0), centroid(0),
876 sample(0), matrix_layout(GLSL_MATRIX_LAYOUT_INHERITED), patch(0),
877 precision(GLSL_PRECISION_NONE)
878 {
879 /* empty */
880 }
881
882 glsl_struct_field()
883 {
884 /* empty */
885 }
886 #endif
887 };
888
889 struct glsl_function_param {
890 const struct glsl_type *type;
891
892 bool in;
893 bool out;
894 };
895
896 static inline unsigned int
897 glsl_align(unsigned int a, unsigned int align)
898 {
899 return (a + align - 1) / align * align;
900 }
901
902 #endif /* GLSL_TYPES_H */