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