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 #ifndef GLSL_TYPES_H
26 #define GLSL_TYPES_H
27
28 #include <string.h>
29 #include <assert.h>
30 #include <stdio.h>
31
32 #include "shader_enums.h"
33 #include "c11/threads.h"
34 #include "util/blob.h"
35 #include "util/format/u_format.h"
36 #include "util/macros.h"
37
38 #ifdef __cplusplus
39 #include "mesa/main/config.h"
40 #endif
41
42 struct glsl_type;
43
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47
48 struct _mesa_glsl_parse_state;
49 struct glsl_symbol_table;
50
51 extern void
52 glsl_type_singleton_init_or_ref();
53
54 extern void
55 glsl_type_singleton_decref();
56
57 extern void
58 _mesa_glsl_initialize_types(struct _mesa_glsl_parse_state *state);
59
60 void
61 glsl_print_type(FILE *f, const struct glsl_type *t);
62
63 void encode_type_to_blob(struct blob *blob, const struct glsl_type *type);
64
65 const struct glsl_type *decode_type_from_blob(struct blob_reader *blob);
66
67 typedef void (*glsl_type_size_align_func)(const struct glsl_type *type,
68 unsigned *size, unsigned *align);
69
70 enum glsl_base_type {
71 /* Note: GLSL_TYPE_UINT, GLSL_TYPE_INT, and GLSL_TYPE_FLOAT must be 0, 1,
72 * and 2 so that they will fit in the 2 bits of glsl_type::sampled_type.
73 */
74 GLSL_TYPE_UINT = 0,
75 GLSL_TYPE_INT,
76 GLSL_TYPE_FLOAT,
77 GLSL_TYPE_FLOAT16,
78 GLSL_TYPE_DOUBLE,
79 GLSL_TYPE_UINT8,
80 GLSL_TYPE_INT8,
81 GLSL_TYPE_UINT16,
82 GLSL_TYPE_INT16,
83 GLSL_TYPE_UINT64,
84 GLSL_TYPE_INT64,
85 GLSL_TYPE_BOOL,
86 GLSL_TYPE_SAMPLER,
87 GLSL_TYPE_TEXTURE,
88 GLSL_TYPE_IMAGE,
89 GLSL_TYPE_ATOMIC_UINT,
90 GLSL_TYPE_STRUCT,
91 GLSL_TYPE_INTERFACE,
92 GLSL_TYPE_ARRAY,
93 GLSL_TYPE_VOID,
94 GLSL_TYPE_SUBROUTINE,
95 GLSL_TYPE_FUNCTION,
96 GLSL_TYPE_ERROR
97 };
98
99 /* Return the bit size of a type. Note that this differs from
100 * glsl_get_bit_size in that it returns 32 bits for bools, whereas at
101 * the NIR level we would want to return 1 bit for bools.
102 */
glsl_base_type_bit_size(enum glsl_base_type type)103 static unsigned glsl_base_type_bit_size(enum glsl_base_type type)
104 {
105 switch (type) {
106 case GLSL_TYPE_BOOL:
107 case GLSL_TYPE_INT:
108 case GLSL_TYPE_UINT:
109 case GLSL_TYPE_FLOAT: /* TODO handle mediump */
110 case GLSL_TYPE_SUBROUTINE:
111 return 32;
112
113 case GLSL_TYPE_FLOAT16:
114 case GLSL_TYPE_UINT16:
115 case GLSL_TYPE_INT16:
116 return 16;
117
118 case GLSL_TYPE_UINT8:
119 case GLSL_TYPE_INT8:
120 return 8;
121
122 case GLSL_TYPE_DOUBLE:
123 case GLSL_TYPE_INT64:
124 case GLSL_TYPE_UINT64:
125 case GLSL_TYPE_IMAGE:
126 case GLSL_TYPE_TEXTURE:
127 case GLSL_TYPE_SAMPLER:
128 return 64;
129
130 default:
131 /* For GLSL_TYPE_STRUCT etc, it should be ok to return 0. This usually
132 * happens when calling this method through is_64bit and is_16bit
133 * methods
134 */
135 return 0;
136 }
137
138 return 0;
139 }
140
glsl_base_type_is_16bit(enum glsl_base_type type)141 static inline bool glsl_base_type_is_16bit(enum glsl_base_type type)
142 {
143 return glsl_base_type_bit_size(type) == 16;
144 }
145
glsl_base_type_is_64bit(enum glsl_base_type type)146 static inline bool glsl_base_type_is_64bit(enum glsl_base_type type)
147 {
148 return glsl_base_type_bit_size(type) == 64;
149 }
150
glsl_base_type_is_integer(enum glsl_base_type type)151 static inline bool glsl_base_type_is_integer(enum glsl_base_type type)
152 {
153 return type == GLSL_TYPE_UINT8 ||
154 type == GLSL_TYPE_INT8 ||
155 type == GLSL_TYPE_UINT16 ||
156 type == GLSL_TYPE_INT16 ||
157 type == GLSL_TYPE_UINT ||
158 type == GLSL_TYPE_INT ||
159 type == GLSL_TYPE_UINT64 ||
160 type == GLSL_TYPE_INT64 ||
161 type == GLSL_TYPE_BOOL ||
162 type == GLSL_TYPE_SAMPLER ||
163 type == GLSL_TYPE_TEXTURE ||
164 type == GLSL_TYPE_IMAGE;
165 }
166
167 static inline unsigned int
glsl_base_type_get_bit_size(const enum glsl_base_type base_type)168 glsl_base_type_get_bit_size(const enum glsl_base_type base_type)
169 {
170 switch (base_type) {
171 case GLSL_TYPE_BOOL:
172 return 1;
173
174 case GLSL_TYPE_INT:
175 case GLSL_TYPE_UINT:
176 case GLSL_TYPE_FLOAT: /* TODO handle mediump */
177 case GLSL_TYPE_SUBROUTINE:
178 return 32;
179
180 case GLSL_TYPE_FLOAT16:
181 case GLSL_TYPE_UINT16:
182 case GLSL_TYPE_INT16:
183 return 16;
184
185 case GLSL_TYPE_UINT8:
186 case GLSL_TYPE_INT8:
187 return 8;
188
189 case GLSL_TYPE_DOUBLE:
190 case GLSL_TYPE_INT64:
191 case GLSL_TYPE_UINT64:
192 case GLSL_TYPE_IMAGE:
193 case GLSL_TYPE_SAMPLER:
194 case GLSL_TYPE_TEXTURE:
195 return 64;
196
197 default:
198 unreachable("unknown base type");
199 }
200
201 return 0;
202 }
203
204 static inline enum glsl_base_type
glsl_unsigned_base_type_of(enum glsl_base_type type)205 glsl_unsigned_base_type_of(enum glsl_base_type type)
206 {
207 switch (type) {
208 case GLSL_TYPE_INT:
209 return GLSL_TYPE_UINT;
210 case GLSL_TYPE_INT8:
211 return GLSL_TYPE_UINT8;
212 case GLSL_TYPE_INT16:
213 return GLSL_TYPE_UINT16;
214 case GLSL_TYPE_INT64:
215 return GLSL_TYPE_UINT64;
216 default:
217 assert(type == GLSL_TYPE_UINT ||
218 type == GLSL_TYPE_UINT8 ||
219 type == GLSL_TYPE_UINT16 ||
220 type == GLSL_TYPE_UINT64);
221 return type;
222 }
223 }
224
225 static inline enum glsl_base_type
glsl_signed_base_type_of(enum glsl_base_type type)226 glsl_signed_base_type_of(enum glsl_base_type type)
227 {
228 switch (type) {
229 case GLSL_TYPE_UINT:
230 return GLSL_TYPE_INT;
231 case GLSL_TYPE_UINT8:
232 return GLSL_TYPE_INT8;
233 case GLSL_TYPE_UINT16:
234 return GLSL_TYPE_INT16;
235 case GLSL_TYPE_UINT64:
236 return GLSL_TYPE_INT64;
237 default:
238 assert(type == GLSL_TYPE_INT ||
239 type == GLSL_TYPE_INT8 ||
240 type == GLSL_TYPE_INT16 ||
241 type == GLSL_TYPE_INT64);
242 return type;
243 }
244 }
245
246 enum glsl_sampler_dim {
247 GLSL_SAMPLER_DIM_1D = 0,
248 GLSL_SAMPLER_DIM_2D,
249 GLSL_SAMPLER_DIM_3D,
250 GLSL_SAMPLER_DIM_CUBE,
251 GLSL_SAMPLER_DIM_RECT,
252 GLSL_SAMPLER_DIM_BUF,
253 GLSL_SAMPLER_DIM_EXTERNAL,
254 GLSL_SAMPLER_DIM_MS,
255 GLSL_SAMPLER_DIM_SUBPASS, /* for vulkan input attachments */
256 GLSL_SAMPLER_DIM_SUBPASS_MS, /* for multisampled vulkan input attachments */
257 };
258
259 int
260 glsl_get_sampler_dim_coordinate_components(enum glsl_sampler_dim dim);
261
262 enum glsl_matrix_layout {
263 /**
264 * The layout of the matrix is inherited from the object containing the
265 * matrix (the top level structure or the uniform block).
266 */
267 GLSL_MATRIX_LAYOUT_INHERITED,
268
269 /**
270 * Explicit column-major layout
271 *
272 * If a uniform block doesn't have an explicit layout set, it will default
273 * to this layout.
274 */
275 GLSL_MATRIX_LAYOUT_COLUMN_MAJOR,
276
277 /**
278 * Row-major layout
279 */
280 GLSL_MATRIX_LAYOUT_ROW_MAJOR
281 };
282
283 enum {
284 GLSL_PRECISION_NONE = 0,
285 GLSL_PRECISION_HIGH,
286 GLSL_PRECISION_MEDIUM,
287 GLSL_PRECISION_LOW
288 };
289
290 #ifdef __cplusplus
291 } /* extern "C" */
292
293 #include "GL/gl.h"
294 #include "util/ralloc.h"
295 #include "mesa/main/menums.h" /* for gl_texture_index, C++'s enum rules are broken */
296
297 struct glsl_type {
298 GLenum gl_type;
299 glsl_base_type base_type:8;
300
301 glsl_base_type sampled_type:8; /**< Type of data returned using this
302 * sampler or image. Only \c
303 * GLSL_TYPE_FLOAT, \c GLSL_TYPE_INT,
304 * and \c GLSL_TYPE_UINT are valid.
305 */
306
307 unsigned sampler_dimensionality:4; /**< \see glsl_sampler_dim */
308 unsigned sampler_shadow:1;
309 unsigned sampler_array:1;
310 unsigned interface_packing:2;
311 unsigned interface_row_major:1;
312
313 /**
314 * For \c GLSL_TYPE_STRUCT this specifies if the struct is packed or not.
315 *
316 * Only used for Compute kernels
317 */
318 unsigned packed:1;
319
320 private:
glsl_typeglsl_type321 glsl_type() : mem_ctx(NULL)
322 {
323 // Dummy constructor, just for the sake of ASSERT_BITFIELD_SIZE.
324 }
325
326 public:
327 /**
328 * \name Vector and matrix element counts
329 *
330 * For scalars, each of these values will be 1. For non-numeric types
331 * these will be 0.
332 */
333 /*@{*/
334 uint8_t vector_elements; /**< 1, 2, 3, or 4 vector elements. */
335 uint8_t matrix_columns; /**< 1, 2, 3, or 4 matrix columns. */
336 /*@}*/
337
338 /**
339 * For \c GLSL_TYPE_ARRAY, this is the length of the array. For
340 * \c GLSL_TYPE_STRUCT or \c GLSL_TYPE_INTERFACE, it is the number of
341 * elements in the structure and the number of values pointed to by
342 * \c fields.structure (below).
343 */
344 unsigned length;
345
346 /**
347 * Name of the data type
348 *
349 * Will never be \c NULL.
350 */
351 const char *name;
352
353 /**
354 * Explicit array, matrix, or vector stride. This is used to communicate
355 * explicit array layouts from SPIR-V. Should be 0 if the type has no
356 * explicit stride.
357 */
358 unsigned explicit_stride;
359
360 /**
361 * Explicit alignment. This is used to communicate explicit alignment
362 * constraints. Should be 0 if the type has no explicit alignment
363 * constraint.
364 */
365 unsigned explicit_alignment;
366
367 /**
368 * Subtype of composite data types.
369 */
370 union {
371 const struct glsl_type *array; /**< Type of array elements. */
372 struct glsl_function_param *parameters; /**< Parameters to function. */
373 struct glsl_struct_field *structure; /**< List of struct fields. */
374 } fields;
375
376 /**
377 * \name Pointers to various public type singletons
378 */
379 /*@{*/
380 #undef DECL_TYPE
381 #define DECL_TYPE(NAME, ...) \
382 static const glsl_type *const NAME##_type;
383 #undef STRUCT_TYPE
384 #define STRUCT_TYPE(NAME) \
385 static const glsl_type *const struct_##NAME##_type;
386 #include "compiler/builtin_type_macros.h"
387 /*@}*/
388
389 /**
390 * Convenience accessors for vector types (shorter than get_instance()).
391 * @{
392 */
393 static const glsl_type *vec(unsigned components, const glsl_type *const ts[]);
394 static const glsl_type *vec(unsigned components);
395 static const glsl_type *f16vec(unsigned components);
396 static const glsl_type *dvec(unsigned components);
397 static const glsl_type *ivec(unsigned components);
398 static const glsl_type *uvec(unsigned components);
399 static const glsl_type *bvec(unsigned components);
400 static const glsl_type *i64vec(unsigned components);
401 static const glsl_type *u64vec(unsigned components);
402 static const glsl_type *i16vec(unsigned components);
403 static const glsl_type *u16vec(unsigned components);
404 static const glsl_type *i8vec(unsigned components);
405 static const glsl_type *u8vec(unsigned components);
406 /**@}*/
407
408 /**
409 * For numeric and boolean derived types returns the basic scalar type
410 *
411 * If the type is a numeric or boolean scalar, vector, or matrix type,
412 * this function gets the scalar type of the individual components. For
413 * all other types, including arrays of numeric or boolean types, the
414 * error type is returned.
415 */
416 const glsl_type *get_base_type() const;
417
418 /**
419 * Get the basic scalar type which this type aggregates.
420 *
421 * If the type is a numeric or boolean scalar, vector, or matrix, or an
422 * array of any of those, this function gets the scalar type of the
423 * individual components. For structs and arrays of structs, this function
424 * returns the struct type. For samplers and arrays of samplers, this
425 * function returns the sampler type.
426 */
427 const glsl_type *get_scalar_type() const;
428
429 /**
430 * Gets the "bare" type without any decorations or layout information.
431 */
432 const glsl_type *get_bare_type() const;
433
434 /**
435 * Gets the float16 version of this type.
436 */
437 const glsl_type *get_float16_type() const;
438
439 /**
440 * Gets the int16 version of this type.
441 */
442 const glsl_type *get_int16_type() const;
443
444 /**
445 * Gets the uint16 version of this type.
446 */
447 const glsl_type *get_uint16_type() const;
448
449 /**
450 * Get the instance of a built-in scalar, vector, or matrix type
451 */
452 static const glsl_type *get_instance(unsigned base_type, unsigned rows,
453 unsigned columns,
454 unsigned explicit_stride = 0,
455 bool row_major = false,
456 unsigned explicit_alignment = 0);
457
458 /**
459 * Get the instance of a sampler type
460 */
461 static const glsl_type *get_sampler_instance(enum glsl_sampler_dim dim,
462 bool shadow,
463 bool array,
464 glsl_base_type type);
465
466 static const glsl_type *get_texture_instance(enum glsl_sampler_dim dim,
467 bool array,
468 glsl_base_type type);
469
470 static const glsl_type *get_image_instance(enum glsl_sampler_dim dim,
471 bool array, glsl_base_type type);
472
473 /**
474 * Get the instance of an array type
475 */
476 static const glsl_type *get_array_instance(const glsl_type *base,
477 unsigned elements,
478 unsigned explicit_stride = 0);
479
480 /**
481 * Get the instance of a record type
482 */
483 static const glsl_type *get_struct_instance(const glsl_struct_field *fields,
484 unsigned num_fields,
485 const char *name,
486 bool packed = false,
487 unsigned explicit_alignment = 0);
488
489 /**
490 * Get the instance of an interface block type
491 */
492 static const glsl_type *get_interface_instance(const glsl_struct_field *fields,
493 unsigned num_fields,
494 enum glsl_interface_packing packing,
495 bool row_major,
496 const char *block_name);
497
498 /**
499 * Get the instance of an subroutine type
500 */
501 static const glsl_type *get_subroutine_instance(const char *subroutine_name);
502
503 /**
504 * Get the instance of a function type
505 */
506 static const glsl_type *get_function_instance(const struct glsl_type *return_type,
507 const glsl_function_param *parameters,
508 unsigned num_params);
509
510 /**
511 * Get the type resulting from a multiplication of \p type_a * \p type_b
512 */
513 static const glsl_type *get_mul_type(const glsl_type *type_a,
514 const glsl_type *type_b);
515
516 /**
517 * Query the total number of scalars that make up a scalar, vector or matrix
518 */
componentsglsl_type519 unsigned components() const
520 {
521 return vector_elements * matrix_columns;
522 }
523
524 /**
525 * Calculate the number of components slots required to hold this type
526 *
527 * This is used to determine how many uniform or varying locations a type
528 * might occupy.
529 */
530 unsigned component_slots() const;
531
532 unsigned component_slots_aligned(unsigned offset) const;
533
534 /**
535 * Calculate offset between the base location of the struct in
536 * uniform storage and a struct member.
537 * For the initial call, length is the index of the member to find the
538 * offset for.
539 */
540 unsigned struct_location_offset(unsigned length) const;
541
542 /**
543 * Calculate the number of unique values from glGetUniformLocation for the
544 * elements of the type.
545 *
546 * This is used to allocate slots in the UniformRemapTable, the amount of
547 * locations may not match with actual used storage space by the driver.
548 */
549 unsigned uniform_locations() const;
550
551 /**
552 * Used to count the number of varyings contained in the type ignoring
553 * innermost array elements.
554 */
555 unsigned varying_count() const;
556
557 /**
558 * Calculate the number of vec4 slots required to hold this type.
559 *
560 * This is the underlying recursive type_size function for
561 * count_attribute_slots() (vertex inputs and varyings) but also for
562 * gallium's !PIPE_CAP_PACKED_UNIFORMS case.
563 */
564 unsigned count_vec4_slots(bool is_gl_vertex_input, bool bindless) const;
565
566 /**
567 * Calculate the number of vec4 slots required to hold this type.
568 *
569 * This is the underlying recursive type_size function for
570 * gallium's PIPE_CAP_PACKED_UNIFORMS case.
571 */
572 unsigned count_dword_slots(bool bindless) const;
573
574 /**
575 * Calculate the number of attribute slots required to hold this type
576 *
577 * This implements the language rules of GLSL 1.50 for counting the number
578 * of slots used by a vertex attribute. It also determines the number of
579 * varying slots the type will use up in the absence of varying packing
580 * (and thus, it can be used to measure the number of varying slots used by
581 * the varyings that are generated by lower_packed_varyings).
582 *
583 * For vertex shader attributes - doubles only take one slot.
584 * For inter-shader varyings - dvec3/dvec4 take two slots.
585 *
586 * Vulkan doesn’t make this distinction so the argument should always be
587 * false.
588 */
count_attribute_slotsglsl_type589 unsigned count_attribute_slots(bool is_gl_vertex_input) const {
590 return count_vec4_slots(is_gl_vertex_input, true);
591 }
592
593 /**
594 * Alignment in bytes of the start of this type in a std140 uniform
595 * block.
596 */
597 unsigned std140_base_alignment(bool row_major) const;
598
599 /** Size in bytes of this type in a std140 uniform block.
600 *
601 * Note that this is not GL_UNIFORM_SIZE (which is the number of
602 * elements in the array)
603 */
604 unsigned std140_size(bool row_major) const;
605
606 /**
607 * Gets an explicitly laid out type with the std140 layout.
608 */
609 const glsl_type *get_explicit_std140_type(bool row_major) const;
610
611 /**
612 * Alignment in bytes of the start of this type in a std430 shader
613 * storage block.
614 */
615 unsigned std430_base_alignment(bool row_major) const;
616
617 /**
618 * Calculate array stride in bytes of this type in a std430 shader storage
619 * block.
620 */
621 unsigned std430_array_stride(bool row_major) const;
622
623 /**
624 * Size in bytes of this type in a std430 shader storage block.
625 *
626 * Note that this is not GL_BUFFER_SIZE
627 */
628 unsigned std430_size(bool row_major) const;
629
630 /**
631 * Gets an explicitly laid out type with the std430 layout.
632 */
633 const glsl_type *get_explicit_std430_type(bool row_major) const;
634
635 /**
636 * Gets an explicitly laid out interface type.
637 */
638 const glsl_type *get_explicit_interface_type(bool supports_std430) const;
639
640 /** Returns an explicitly laid out type given a type and size/align func
641 *
642 * The size/align func is only called for scalar and vector types and the
643 * returned type is otherwise laid out in the natural way as follows:
644 *
645 * - Arrays and matrices have a stride of ALIGN(elem_size, elem_align).
646 *
647 * - Structure types have their elements in-order and as tightly packed as
648 * possible following the alignment required by the size/align func.
649 *
650 * - All composite types (structures, matrices, and arrays) have an
651 * alignment equal to the highest alignment of any member of the composite.
652 *
653 * The types returned by this function are likely not suitable for most UBO
654 * or SSBO layout because they do not add the extra array and substructure
655 * alignment that is required by std140 and std430.
656 */
657 const glsl_type *get_explicit_type_for_size_align(glsl_type_size_align_func type_info,
658 unsigned *size, unsigned *align) const;
659
660 const glsl_type *replace_vec3_with_vec4() const;
661
662 /**
663 * Alignment in bytes of the start of this type in OpenCL memory.
664 */
665 unsigned cl_alignment() const;
666
667 /**
668 * Size in bytes of this type in OpenCL memory
669 */
670 unsigned cl_size() const;
671
672 /**
673 * Size in bytes of this type based on its explicit data.
674 *
675 * When using SPIR-V shaders (ARB_gl_spirv), memory layouts are expressed
676 * through explicit offset, stride and matrix layout, so the size
677 * can/should be computed used those values.
678 *
679 * Note that the value returned by this method is only correct if such
680 * values are set, so only with SPIR-V shaders. Should not be used with
681 * GLSL shaders.
682 */
683 unsigned explicit_size(bool align_to_stride=false) const;
684
685 /**
686 * \brief Can this type be implicitly converted to another?
687 *
688 * \return True if the types are identical or if this type can be converted
689 * to \c desired according to Section 4.1.10 of the GLSL spec.
690 *
691 * \verbatim
692 * From page 25 (31 of the pdf) of the GLSL 1.50 spec, Section 4.1.10
693 * Implicit Conversions:
694 *
695 * In some situations, an expression and its type will be implicitly
696 * converted to a different type. The following table shows all allowed
697 * implicit conversions:
698 *
699 * Type of expression | Can be implicitly converted to
700 * --------------------------------------------------
701 * int float
702 * uint
703 *
704 * ivec2 vec2
705 * uvec2
706 *
707 * ivec3 vec3
708 * uvec3
709 *
710 * ivec4 vec4
711 * uvec4
712 *
713 * There are no implicit array or structure conversions. For example,
714 * an array of int cannot be implicitly converted to an array of float.
715 * There are no implicit conversions between signed and unsigned
716 * integers.
717 * \endverbatim
718 */
719 bool can_implicitly_convert_to(const glsl_type *desired,
720 _mesa_glsl_parse_state *state) const;
721
722 /**
723 * Query whether or not a type is a scalar (non-vector and non-matrix).
724 */
is_scalarglsl_type725 bool is_scalar() const
726 {
727 return (vector_elements == 1)
728 && (base_type >= GLSL_TYPE_UINT)
729 && (base_type <= GLSL_TYPE_IMAGE);
730 }
731
732 /**
733 * Query whether or not a type is a vector
734 */
is_vectorglsl_type735 bool is_vector() const
736 {
737 return (vector_elements > 1)
738 && (matrix_columns == 1)
739 && (base_type >= GLSL_TYPE_UINT)
740 && (base_type <= GLSL_TYPE_BOOL);
741 }
742
743 /**
744 * Query whether or not a type is a matrix
745 */
is_matrixglsl_type746 bool is_matrix() const
747 {
748 /* GLSL only has float matrices. */
749 return (matrix_columns > 1) && (base_type == GLSL_TYPE_FLOAT ||
750 base_type == GLSL_TYPE_DOUBLE ||
751 base_type == GLSL_TYPE_FLOAT16);
752 }
753
754 /**
755 * Query whether or not a type is a non-array numeric type
756 */
is_numericglsl_type757 bool is_numeric() const
758 {
759 return (base_type >= GLSL_TYPE_UINT) && (base_type <= GLSL_TYPE_INT64);
760 }
761
762 /**
763 * Query whether or not a type is an integer.
764 */
is_integerglsl_type765 bool is_integer() const
766 {
767 return glsl_base_type_is_integer(base_type);
768 }
769
770 /**
771 * Query whether or not a type is a 16-bit integer.
772 */
is_integer_16glsl_type773 bool is_integer_16() const
774 {
775 return base_type == GLSL_TYPE_UINT16 || base_type == GLSL_TYPE_INT16;
776 }
777
778 /**
779 * Query whether or not a type is an 32-bit integer.
780 */
is_integer_32glsl_type781 bool is_integer_32() const
782 {
783 return (base_type == GLSL_TYPE_UINT) || (base_type == GLSL_TYPE_INT);
784 }
785
786 /**
787 * Query whether or not a type is a 64-bit integer.
788 */
is_integer_64glsl_type789 bool is_integer_64() const
790 {
791 return base_type == GLSL_TYPE_UINT64 || base_type == GLSL_TYPE_INT64;
792 }
793
794 /**
795 * Query whether or not a type is a 32-bit or 64-bit integer
796 */
is_integer_32_64glsl_type797 bool is_integer_32_64() const
798 {
799 return is_integer_32() || is_integer_64();
800 }
801
802 /**
803 * Query whether or not a type is a 16-bit or 32-bit integer
804 */
is_integer_16_32glsl_type805 bool is_integer_16_32() const
806 {
807 return is_integer_16() || is_integer_32();
808 }
809
810 /**
811 * Query whether or not a type is a 16-bit, 32-bit or 64-bit integer
812 */
is_integer_16_32_64glsl_type813 bool is_integer_16_32_64() const
814 {
815 return is_integer_16() || is_integer_32() || is_integer_64();
816 }
817
818 /**
819 * Query whether or not type is an integral type, or for struct and array
820 * types, contains an integral type.
821 */
822 bool contains_integer() const;
823
824 /**
825 * Query whether or not type is a double type, or for struct, interface and
826 * array types, contains a double type.
827 */
828 bool contains_double() const;
829
830 /**
831 * Query whether or not type is a 64-bit type, or for struct, interface and
832 * array types, contains a double type.
833 */
834 bool contains_64bit() const;
835
836 /**
837 * Query whether or not a type is a float type
838 */
is_floatglsl_type839 bool is_float() const
840 {
841 return base_type == GLSL_TYPE_FLOAT;
842 }
843
844 /**
845 * Query whether or not a type is a half-float or float type
846 */
is_float_16_32glsl_type847 bool is_float_16_32() const
848 {
849 return base_type == GLSL_TYPE_FLOAT16 || is_float();
850 }
851
852 /**
853 * Query whether or not a type is a half-float, float or double
854 */
is_float_16_32_64glsl_type855 bool is_float_16_32_64() const
856 {
857 return base_type == GLSL_TYPE_FLOAT16 || is_float() || is_double();
858 }
859
860 /**
861 * Query whether or not a type is a float or double
862 */
is_float_32_64glsl_type863 bool is_float_32_64() const
864 {
865 return is_float() || is_double();
866 }
867
is_int_16_32_64glsl_type868 bool is_int_16_32_64() const
869 {
870 return base_type == GLSL_TYPE_INT16 ||
871 base_type == GLSL_TYPE_INT ||
872 base_type == GLSL_TYPE_INT64;
873 }
874
is_uint_16_32_64glsl_type875 bool is_uint_16_32_64() const
876 {
877 return base_type == GLSL_TYPE_UINT16 ||
878 base_type == GLSL_TYPE_UINT ||
879 base_type == GLSL_TYPE_UINT64;
880 }
881
is_int_16_32glsl_type882 bool is_int_16_32() const
883 {
884 return base_type == GLSL_TYPE_INT ||
885 base_type == GLSL_TYPE_INT16;
886 }
887
is_uint_16_32glsl_type888 bool is_uint_16_32() const
889 {
890 return base_type == GLSL_TYPE_UINT ||
891 base_type == GLSL_TYPE_UINT16;
892 }
893
894 /**
895 * Query whether or not a type is a double type
896 */
is_doubleglsl_type897 bool is_double() const
898 {
899 return base_type == GLSL_TYPE_DOUBLE;
900 }
901
902 /**
903 * Query whether a 64-bit type takes two slots.
904 */
is_dual_slotglsl_type905 bool is_dual_slot() const
906 {
907 return is_64bit() && vector_elements > 2;
908 }
909
910 /**
911 * Query whether or not a type is 64-bit
912 */
is_64bitglsl_type913 bool is_64bit() const
914 {
915 return glsl_base_type_is_64bit(base_type);
916 }
917
918 /**
919 * Query whether or not a type is 16-bit
920 */
is_16bitglsl_type921 bool is_16bit() const
922 {
923 return glsl_base_type_is_16bit(base_type);
924 }
925
926 /**
927 * Query whether or not a type is 32-bit
928 */
is_32bitglsl_type929 bool is_32bit() const
930 {
931 return base_type == GLSL_TYPE_UINT ||
932 base_type == GLSL_TYPE_INT ||
933 base_type == GLSL_TYPE_FLOAT;
934 }
935
936 /**
937 * Query whether or not a type is a non-array boolean type
938 */
is_booleanglsl_type939 bool is_boolean() const
940 {
941 return base_type == GLSL_TYPE_BOOL;
942 }
943
944 /**
945 * Query whether or not a type is a sampler
946 */
is_samplerglsl_type947 bool is_sampler() const
948 {
949 return base_type == GLSL_TYPE_SAMPLER;
950 }
951
952 /**
953 * Query whether or not a type is a texture
954 */
is_textureglsl_type955 bool is_texture() const
956 {
957 return base_type == GLSL_TYPE_TEXTURE;
958 }
959
960 /**
961 * Query whether or not type is a sampler, or for struct, interface and
962 * array types, contains a sampler.
963 */
964 bool contains_sampler() const;
965
966 /**
967 * Query whether or not type is an array or for struct, interface and
968 * array types, contains an array.
969 */
970 bool contains_array() const;
971
972 /**
973 * Get the Mesa texture target index for a sampler type.
974 */
975 gl_texture_index sampler_index() const;
976
977 /**
978 * Query whether or not type is an image, or for struct, interface and
979 * array types, contains an image.
980 */
981 bool contains_image() const;
982
983 /**
984 * Query whether or not a type is an image
985 */
is_imageglsl_type986 bool is_image() const
987 {
988 return base_type == GLSL_TYPE_IMAGE;
989 }
990
991 /**
992 * Query whether or not a type is an array
993 */
is_arrayglsl_type994 bool is_array() const
995 {
996 return base_type == GLSL_TYPE_ARRAY;
997 }
998
is_array_of_arraysglsl_type999 bool is_array_of_arrays() const
1000 {
1001 return is_array() && fields.array->is_array();
1002 }
1003
1004 /**
1005 * Query whether or not a type is a record
1006 */
is_structglsl_type1007 bool is_struct() const
1008 {
1009 return base_type == GLSL_TYPE_STRUCT;
1010 }
1011
1012 /**
1013 * Query whether or not a type is an interface
1014 */
is_interfaceglsl_type1015 bool is_interface() const
1016 {
1017 return base_type == GLSL_TYPE_INTERFACE;
1018 }
1019
1020 /**
1021 * Query whether or not a type is the void type singleton.
1022 */
is_voidglsl_type1023 bool is_void() const
1024 {
1025 return base_type == GLSL_TYPE_VOID;
1026 }
1027
1028 /**
1029 * Query whether or not a type is the error type singleton.
1030 */
is_errorglsl_type1031 bool is_error() const
1032 {
1033 return base_type == GLSL_TYPE_ERROR;
1034 }
1035
1036 /**
1037 * Query if a type is unnamed/anonymous (named by the parser)
1038 */
1039
is_subroutineglsl_type1040 bool is_subroutine() const
1041 {
1042 return base_type == GLSL_TYPE_SUBROUTINE;
1043 }
1044 bool contains_subroutine() const;
1045
is_anonymousglsl_type1046 bool is_anonymous() const
1047 {
1048 return !strncmp(name, "#anon", 5);
1049 }
1050
1051 /**
1052 * Get the type stripped of any arrays
1053 *
1054 * \return
1055 * Pointer to the type of elements of the first non-array type for array
1056 * types, or pointer to itself for non-array types.
1057 */
without_arrayglsl_type1058 const glsl_type *without_array() const
1059 {
1060 const glsl_type *t = this;
1061
1062 while (t->is_array())
1063 t = t->fields.array;
1064
1065 return t;
1066 }
1067
1068 /**
1069 * Return the total number of elements in an array including the elements
1070 * in arrays of arrays.
1071 */
arrays_of_arrays_sizeglsl_type1072 unsigned arrays_of_arrays_size() const
1073 {
1074 if (!is_array())
1075 return 0;
1076
1077 unsigned size = length;
1078 const glsl_type *array_base_type = fields.array;
1079
1080 while (array_base_type->is_array()) {
1081 size = size * array_base_type->length;
1082 array_base_type = array_base_type->fields.array;
1083 }
1084 return size;
1085 }
1086
1087 /**
1088 * Return bit size for this type.
1089 */
bit_sizeglsl_type1090 unsigned bit_size() const
1091 {
1092 return glsl_base_type_bit_size(this->base_type);
1093 }
1094
1095
1096 /**
1097 * Query whether or not a type is an atomic_uint.
1098 */
is_atomic_uintglsl_type1099 bool is_atomic_uint() const
1100 {
1101 return base_type == GLSL_TYPE_ATOMIC_UINT;
1102 }
1103
1104 /**
1105 * Return the amount of atomic counter storage required for a type.
1106 */
atomic_sizeglsl_type1107 unsigned atomic_size() const
1108 {
1109 if (is_atomic_uint())
1110 return ATOMIC_COUNTER_SIZE;
1111 else if (is_array())
1112 return length * fields.array->atomic_size();
1113 else
1114 return 0;
1115 }
1116
1117 /**
1118 * Return whether a type contains any atomic counters.
1119 */
contains_atomicglsl_type1120 bool contains_atomic() const
1121 {
1122 return atomic_size() > 0;
1123 }
1124
1125 /**
1126 * Return whether a type contains any opaque types.
1127 */
1128 bool contains_opaque() const;
1129
1130 /**
1131 * Query the full type of a matrix row
1132 *
1133 * \return
1134 * If the type is not a matrix, \c glsl_type::error_type is returned.
1135 * Otherwise a type matching the rows of the matrix is returned.
1136 */
row_typeglsl_type1137 const glsl_type *row_type() const
1138 {
1139 if (!is_matrix())
1140 return error_type;
1141
1142 if (explicit_stride && !interface_row_major)
1143 return get_instance(base_type, matrix_columns, 1, explicit_stride);
1144 else
1145 return get_instance(base_type, matrix_columns, 1);
1146 }
1147
1148 /**
1149 * Query the full type of a matrix column
1150 *
1151 * \return
1152 * If the type is not a matrix, \c glsl_type::error_type is returned.
1153 * Otherwise a type matching the columns of the matrix is returned.
1154 */
column_typeglsl_type1155 const glsl_type *column_type() const
1156 {
1157 if (!is_matrix())
1158 return error_type;
1159
1160 if (interface_row_major) {
1161 /* If we're row-major, the vector element stride is the same as the
1162 * matrix stride and we have no alignment (i.e. component-aligned).
1163 */
1164 return get_instance(base_type, vector_elements, 1,
1165 explicit_stride, false, 0);
1166 } else {
1167 /* Otherwise, the vector is tightly packed (stride=0). For
1168 * alignment, we treat a matrix as an array of columns make the same
1169 * assumption that the alignment of the column is the same as the
1170 * alignment of the whole matrix.
1171 */
1172 return get_instance(base_type, vector_elements, 1,
1173 0, false, explicit_alignment);
1174 }
1175 }
1176
1177 /**
1178 * Get the type of a structure field
1179 *
1180 * \return
1181 * Pointer to the type of the named field. If the type is not a structure
1182 * or the named field does not exist, \c glsl_type::error_type is returned.
1183 */
1184 const glsl_type *field_type(const char *name) const;
1185
1186 /**
1187 * Get the location of a field within a record type
1188 */
1189 int field_index(const char *name) const;
1190
1191 /**
1192 * Query the number of elements in an array type
1193 *
1194 * \return
1195 * The number of elements in the array for array types or -1 for non-array
1196 * types. If the number of elements in the array has not yet been declared,
1197 * zero is returned.
1198 */
array_sizeglsl_type1199 int array_size() const
1200 {
1201 return is_array() ? length : -1;
1202 }
1203
1204 /**
1205 * Query whether the array size for all dimensions has been declared.
1206 */
is_unsized_arrayglsl_type1207 bool is_unsized_array() const
1208 {
1209 return is_array() && length == 0;
1210 }
1211
1212 /**
1213 * Return the number of coordinate components needed for this
1214 * sampler or image type.
1215 *
1216 * This is based purely on the sampler's dimensionality. For example, this
1217 * returns 1 for sampler1D, and 3 for sampler2DArray.
1218 *
1219 * Note that this is often different than actual coordinate type used in
1220 * a texturing built-in function, since those pack additional values (such
1221 * as the shadow comparator or projector) into the coordinate type.
1222 */
1223 int coordinate_components() const;
1224
1225 /**
1226 * Compares whether this type matches another type without taking into
1227 * account the precision in structures.
1228 *
1229 * This is applied recursively so that structures containing structure
1230 * members can also ignore the precision.
1231 */
1232 bool compare_no_precision(const glsl_type *b) const;
1233
1234 /**
1235 * Compare a record type against another record type.
1236 *
1237 * This is useful for matching record types declared on the same shader
1238 * stage as well as across different shader stages.
1239 * The option to not match name is needed for matching record types
1240 * declared across different shader stages.
1241 * The option to not match locations is to deal with places where the
1242 * same struct is defined in a block which has a location set on it.
1243 */
1244 bool record_compare(const glsl_type *b, bool match_name,
1245 bool match_locations = true,
1246 bool match_precision = true) const;
1247
1248 /**
1249 * Get the type interface packing.
1250 */
get_interface_packingglsl_type1251 enum glsl_interface_packing get_interface_packing() const
1252 {
1253 return (enum glsl_interface_packing)interface_packing;
1254 }
1255
1256 /**
1257 * Get the type interface packing used internally. For shared and packing
1258 * layouts this is implementation defined.
1259 */
get_internal_ifc_packingglsl_type1260 enum glsl_interface_packing get_internal_ifc_packing(bool std430_supported) const
1261 {
1262 enum glsl_interface_packing packing = this->get_interface_packing();
1263 if (packing == GLSL_INTERFACE_PACKING_STD140 ||
1264 (!std430_supported &&
1265 (packing == GLSL_INTERFACE_PACKING_SHARED ||
1266 packing == GLSL_INTERFACE_PACKING_PACKED))) {
1267 return GLSL_INTERFACE_PACKING_STD140;
1268 } else {
1269 assert(packing == GLSL_INTERFACE_PACKING_STD430 ||
1270 (std430_supported &&
1271 (packing == GLSL_INTERFACE_PACKING_SHARED ||
1272 packing == GLSL_INTERFACE_PACKING_PACKED)));
1273 return GLSL_INTERFACE_PACKING_STD430;
1274 }
1275 }
1276
1277 /**
1278 * Check if the type interface is row major
1279 */
get_interface_row_majorglsl_type1280 bool get_interface_row_major() const
1281 {
1282 return (bool) interface_row_major;
1283 }
1284
1285 ~glsl_type();
1286
1287 private:
1288
1289 static mtx_t hash_mutex;
1290
1291 /**
1292 * ralloc context for the type itself.
1293 */
1294 void *mem_ctx;
1295
1296 /** Constructor for vector and matrix types */
1297 glsl_type(GLenum gl_type,
1298 glsl_base_type base_type, unsigned vector_elements,
1299 unsigned matrix_columns, const char *name,
1300 unsigned explicit_stride = 0, bool row_major = false,
1301 unsigned explicit_alignment = 0);
1302
1303 /** Constructor for sampler or image types */
1304 glsl_type(GLenum gl_type, glsl_base_type base_type,
1305 enum glsl_sampler_dim dim, bool shadow, bool array,
1306 glsl_base_type type, const char *name);
1307
1308 /** Constructor for record types */
1309 glsl_type(const glsl_struct_field *fields, unsigned num_fields,
1310 const char *name, bool packed = false,
1311 unsigned explicit_alignment = 0);
1312
1313 /** Constructor for interface types */
1314 glsl_type(const glsl_struct_field *fields, unsigned num_fields,
1315 enum glsl_interface_packing packing,
1316 bool row_major, const char *name);
1317
1318 /** Constructor for interface types */
1319 glsl_type(const glsl_type *return_type,
1320 const glsl_function_param *params, unsigned num_params);
1321
1322 /** Constructors for array types */
1323 glsl_type(const glsl_type *array, unsigned length, unsigned explicit_stride);
1324
1325 /** Constructor for subroutine types */
1326 glsl_type(const char *name);
1327
1328 /** Hash table containing the known explicit matrix and vector types. */
1329 static struct hash_table *explicit_matrix_types;
1330
1331 /** Hash table containing the known array types. */
1332 static struct hash_table *array_types;
1333
1334 /** Hash table containing the known struct types. */
1335 static struct hash_table *struct_types;
1336
1337 /** Hash table containing the known interface types. */
1338 static struct hash_table *interface_types;
1339
1340 /** Hash table containing the known subroutine types. */
1341 static struct hash_table *subroutine_types;
1342
1343 /** Hash table containing the known function types. */
1344 static struct hash_table *function_types;
1345
1346 static bool record_key_compare(const void *a, const void *b);
1347 static unsigned record_key_hash(const void *key);
1348
1349 /**
1350 * \name Built-in type flyweights
1351 */
1352 /*@{*/
1353 #undef DECL_TYPE
1354 #define DECL_TYPE(NAME, ...) static const glsl_type _##NAME##_type;
1355 #undef STRUCT_TYPE
1356 #define STRUCT_TYPE(NAME) static const glsl_type _struct_##NAME##_type;
1357 #include "compiler/builtin_type_macros.h"
1358 /*@}*/
1359
1360 /**
1361 * \name Friend functions.
1362 *
1363 * These functions are friends because they must have C linkage and the
1364 * need to call various private methods or access various private static
1365 * data.
1366 */
1367 /*@{*/
1368 friend void glsl_type_singleton_init_or_ref(void);
1369 friend void glsl_type_singleton_decref(void);
1370 friend void _mesa_glsl_initialize_types(struct _mesa_glsl_parse_state *);
1371 /*@}*/
1372 };
1373
1374 #undef DECL_TYPE
1375 #undef STRUCT_TYPE
1376 #endif /* __cplusplus */
1377
1378 struct glsl_struct_field {
1379 const struct glsl_type *type;
1380 const char *name;
1381
1382 /**
1383 * For interface blocks, gl_varying_slot corresponding to the input/output
1384 * if this is a built-in input/output (i.e. a member of the built-in
1385 * gl_PerVertex interface block); -1 otherwise.
1386 *
1387 * Ignored for structs.
1388 */
1389 int location;
1390
1391 /**
1392 * For interface blocks, members may explicitly assign the component used
1393 * by a varying. Ignored for structs.
1394 */
1395 int component;
1396
1397 /**
1398 * For interface blocks, members may have an explicit byte offset
1399 * specified; -1 otherwise. Also used for xfb_offset layout qualifier.
1400 *
1401 * Unless used for xfb_offset this field is ignored for structs.
1402 */
1403 int offset;
1404
1405 /**
1406 * For interface blocks, members may define a transform feedback buffer;
1407 * -1 otherwise.
1408 */
1409 int xfb_buffer;
1410
1411 /**
1412 * For interface blocks, members may define a transform feedback stride;
1413 * -1 otherwise.
1414 */
1415 int xfb_stride;
1416
1417 /**
1418 * Layout format, applicable to image variables only.
1419 */
1420 enum pipe_format image_format;
1421
1422 union {
1423 struct {
1424 /**
1425 * For interface blocks, the interpolation mode (as in
1426 * ir_variable::interpolation). 0 otherwise.
1427 */
1428 unsigned interpolation:3;
1429
1430 /**
1431 * For interface blocks, 1 if this variable uses centroid interpolation (as
1432 * in ir_variable::centroid). 0 otherwise.
1433 */
1434 unsigned centroid:1;
1435
1436 /**
1437 * For interface blocks, 1 if this variable uses sample interpolation (as
1438 * in ir_variable::sample). 0 otherwise.
1439 */
1440 unsigned sample:1;
1441
1442 /**
1443 * Layout of the matrix. Uses glsl_matrix_layout values.
1444 */
1445 unsigned matrix_layout:2;
1446
1447 /**
1448 * For interface blocks, 1 if this variable is a per-patch input or output
1449 * (as in ir_variable::patch). 0 otherwise.
1450 */
1451 unsigned patch:1;
1452
1453 /**
1454 * Precision qualifier
1455 */
1456 unsigned precision:2;
1457
1458 /**
1459 * Memory qualifiers, applicable to buffer variables defined in shader
1460 * storage buffer objects (SSBOs)
1461 */
1462 unsigned memory_read_only:1;
1463 unsigned memory_write_only:1;
1464 unsigned memory_coherent:1;
1465 unsigned memory_volatile:1;
1466 unsigned memory_restrict:1;
1467
1468 /**
1469 * Any of the xfb_* qualifiers trigger the shader to be in transform
1470 * feedback mode so we need to keep track of whether the buffer was
1471 * explicitly set or if its just been assigned the default global value.
1472 */
1473 unsigned explicit_xfb_buffer:1;
1474
1475 unsigned implicit_sized_array:1;
1476 };
1477 unsigned flags;
1478 };
1479 #ifdef __cplusplus
1480 #define DEFAULT_CONSTRUCTORS(_type, _name) \
1481 type(_type), name(_name), location(-1), component(-1), offset(-1), \
1482 xfb_buffer(0), xfb_stride(0), image_format(PIPE_FORMAT_NONE), flags(0) \
1483
glsl_struct_fieldglsl_struct_field1484 glsl_struct_field(const struct glsl_type *_type,
1485 int _precision,
1486 const char *_name)
1487 : DEFAULT_CONSTRUCTORS(_type, _name)
1488 {
1489 matrix_layout = GLSL_MATRIX_LAYOUT_INHERITED;
1490 precision = _precision;
1491 }
1492
glsl_struct_fieldglsl_struct_field1493 glsl_struct_field(const struct glsl_type *_type, const char *_name)
1494 : DEFAULT_CONSTRUCTORS(_type, _name)
1495 {
1496 matrix_layout = GLSL_MATRIX_LAYOUT_INHERITED;
1497 precision = GLSL_PRECISION_NONE;
1498 }
1499
glsl_struct_fieldglsl_struct_field1500 glsl_struct_field()
1501 : DEFAULT_CONSTRUCTORS(NULL, NULL)
1502 {
1503 matrix_layout = GLSL_MATRIX_LAYOUT_INHERITED;
1504 precision = GLSL_PRECISION_NONE;
1505 }
1506 #undef DEFAULT_CONSTRUCTORS
1507 #endif
1508 };
1509
1510 struct glsl_function_param {
1511 const struct glsl_type *type;
1512
1513 bool in;
1514 bool out;
1515 };
1516
1517 static inline unsigned int
glsl_align(unsigned int a,unsigned int align)1518 glsl_align(unsigned int a, unsigned int align)
1519 {
1520 return (a + align - 1) / align * align;
1521 }
1522
1523 #endif /* GLSL_TYPES_H */
1524