fdc22edf133d7f585792f0ae7bc87c80d6c50e2b
[mesa.git] / src / glsl / ir.h
1 /* -*- c++ -*- */
2 /*
3 * Copyright © 2010 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 IR_H
27 #define IR_H
28
29 #include <stdio.h>
30 #include <stdlib.h>
31
32 #include "util/ralloc.h"
33 #include "glsl_types.h"
34 #include "list.h"
35 #include "ir_visitor.h"
36 #include "ir_hierarchical_visitor.h"
37 #include "main/mtypes.h"
38
39 #ifdef __cplusplus
40
41 /**
42 * \defgroup IR Intermediate representation nodes
43 *
44 * @{
45 */
46
47 /**
48 * Class tags
49 *
50 * Each concrete class derived from \c ir_instruction has a value in this
51 * enumerant. The value for the type is stored in \c ir_instruction::ir_type
52 * by the constructor. While using type tags is not very C++, it is extremely
53 * convenient. For example, during debugging you can simply inspect
54 * \c ir_instruction::ir_type to find out the actual type of the object.
55 *
56 * In addition, it is possible to use a switch-statement based on \c
57 * \c ir_instruction::ir_type to select different behavior for different object
58 * types. For functions that have only slight differences for several object
59 * types, this allows writing very straightforward, readable code.
60 */
61 enum ir_node_type {
62 ir_type_dereference_array,
63 ir_type_dereference_record,
64 ir_type_dereference_variable,
65 ir_type_constant,
66 ir_type_expression,
67 ir_type_swizzle,
68 ir_type_texture,
69 ir_type_variable,
70 ir_type_assignment,
71 ir_type_call,
72 ir_type_function,
73 ir_type_function_signature,
74 ir_type_if,
75 ir_type_loop,
76 ir_type_loop_jump,
77 ir_type_return,
78 ir_type_discard,
79 ir_type_emit_vertex,
80 ir_type_end_primitive,
81 ir_type_max, /**< maximum ir_type enum number, for validation */
82 ir_type_unset = ir_type_max
83 };
84
85
86 /**
87 * Base class of all IR instructions
88 */
89 class ir_instruction : public exec_node {
90 public:
91 enum ir_node_type ir_type;
92
93 /**
94 * GCC 4.7+ and clang warn when deleting an ir_instruction unless
95 * there's a virtual destructor present. Because we almost
96 * universally use ralloc for our memory management of
97 * ir_instructions, the destructor doesn't need to do any work.
98 */
99 virtual ~ir_instruction()
100 {
101 }
102
103 /** ir_print_visitor helper for debugging. */
104 void print(void) const;
105 void fprint(FILE *f) const;
106
107 virtual void accept(ir_visitor *) = 0;
108 virtual ir_visitor_status accept(ir_hierarchical_visitor *) = 0;
109 virtual ir_instruction *clone(void *mem_ctx,
110 struct hash_table *ht) const = 0;
111
112 /**
113 * \name IR instruction downcast functions
114 *
115 * These functions either cast the object to a derived class or return
116 * \c NULL if the object's type does not match the specified derived class.
117 * Additional downcast functions will be added as needed.
118 */
119 /*@{*/
120 class ir_rvalue *as_rvalue()
121 {
122 assume(this != NULL);
123 if (ir_type == ir_type_dereference_array ||
124 ir_type == ir_type_dereference_record ||
125 ir_type == ir_type_dereference_variable ||
126 ir_type == ir_type_constant ||
127 ir_type == ir_type_expression ||
128 ir_type == ir_type_swizzle ||
129 ir_type == ir_type_texture)
130 return (class ir_rvalue *) this;
131 return NULL;
132 }
133
134 class ir_dereference *as_dereference()
135 {
136 assume(this != NULL);
137 if (ir_type == ir_type_dereference_array ||
138 ir_type == ir_type_dereference_record ||
139 ir_type == ir_type_dereference_variable)
140 return (class ir_dereference *) this;
141 return NULL;
142 }
143
144 class ir_jump *as_jump()
145 {
146 assume(this != NULL);
147 if (ir_type == ir_type_loop_jump ||
148 ir_type == ir_type_return ||
149 ir_type == ir_type_discard)
150 return (class ir_jump *) this;
151 return NULL;
152 }
153
154 #define AS_CHILD(TYPE) \
155 class ir_##TYPE * as_##TYPE() \
156 { \
157 assume(this != NULL); \
158 return ir_type == ir_type_##TYPE ? (ir_##TYPE *) this : NULL; \
159 }
160 AS_CHILD(variable)
161 AS_CHILD(function)
162 AS_CHILD(dereference_array)
163 AS_CHILD(dereference_variable)
164 AS_CHILD(dereference_record)
165 AS_CHILD(expression)
166 AS_CHILD(loop)
167 AS_CHILD(assignment)
168 AS_CHILD(call)
169 AS_CHILD(return)
170 AS_CHILD(if)
171 AS_CHILD(swizzle)
172 AS_CHILD(texture)
173 AS_CHILD(constant)
174 AS_CHILD(discard)
175 #undef AS_CHILD
176 /*@}*/
177
178 /**
179 * IR equality method: Return true if the referenced instruction would
180 * return the same value as this one.
181 *
182 * This intended to be used for CSE and algebraic optimizations, on rvalues
183 * in particular. No support for other instruction types (assignments,
184 * jumps, calls, etc.) is planned.
185 */
186 virtual bool equals(ir_instruction *ir, enum ir_node_type ignore = ir_type_unset);
187
188 protected:
189 ir_instruction(enum ir_node_type t)
190 : ir_type(t)
191 {
192 }
193
194 private:
195 ir_instruction()
196 {
197 assert(!"Should not get here.");
198 }
199 };
200
201
202 /**
203 * The base class for all "values"/expression trees.
204 */
205 class ir_rvalue : public ir_instruction {
206 public:
207 const struct glsl_type *type;
208
209 virtual ir_rvalue *clone(void *mem_ctx, struct hash_table *) const;
210
211 virtual void accept(ir_visitor *v)
212 {
213 v->visit(this);
214 }
215
216 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
217
218 virtual ir_constant *constant_expression_value(struct hash_table *variable_context = NULL);
219
220 ir_rvalue *as_rvalue_to_saturate();
221
222 virtual bool is_lvalue() const
223 {
224 return false;
225 }
226
227 /**
228 * Get the variable that is ultimately referenced by an r-value
229 */
230 virtual ir_variable *variable_referenced() const
231 {
232 return NULL;
233 }
234
235
236 /**
237 * If an r-value is a reference to a whole variable, get that variable
238 *
239 * \return
240 * Pointer to a variable that is completely dereferenced by the r-value. If
241 * the r-value is not a dereference or the dereference does not access the
242 * entire variable (i.e., it's just one array element, struct field), \c NULL
243 * is returned.
244 */
245 virtual ir_variable *whole_variable_referenced()
246 {
247 return NULL;
248 }
249
250 /**
251 * Determine if an r-value has the value zero
252 *
253 * The base implementation of this function always returns \c false. The
254 * \c ir_constant class over-rides this function to return \c true \b only
255 * for vector and scalar types that have all elements set to the value
256 * zero (or \c false for booleans).
257 *
258 * \sa ir_constant::has_value, ir_rvalue::is_one, ir_rvalue::is_negative_one
259 */
260 virtual bool is_zero() const;
261
262 /**
263 * Determine if an r-value has the value one
264 *
265 * The base implementation of this function always returns \c false. The
266 * \c ir_constant class over-rides this function to return \c true \b only
267 * for vector and scalar types that have all elements set to the value
268 * one (or \c true for booleans).
269 *
270 * \sa ir_constant::has_value, ir_rvalue::is_zero, ir_rvalue::is_negative_one
271 */
272 virtual bool is_one() const;
273
274 /**
275 * Determine if an r-value has the value negative one
276 *
277 * The base implementation of this function always returns \c false. The
278 * \c ir_constant class over-rides this function to return \c true \b only
279 * for vector and scalar types that have all elements set to the value
280 * negative one. For boolean types, the result is always \c false.
281 *
282 * \sa ir_constant::has_value, ir_rvalue::is_zero, ir_rvalue::is_one
283 */
284 virtual bool is_negative_one() const;
285
286 /**
287 * Determine if an r-value is an unsigned integer constant which can be
288 * stored in 16 bits.
289 *
290 * \sa ir_constant::is_uint16_constant.
291 */
292 virtual bool is_uint16_constant() const { return false; }
293
294 /**
295 * Return a generic value of error_type.
296 *
297 * Allocation will be performed with 'mem_ctx' as ralloc owner.
298 */
299 static ir_rvalue *error_value(void *mem_ctx);
300
301 protected:
302 ir_rvalue(enum ir_node_type t);
303 };
304
305
306 /**
307 * Variable storage classes
308 */
309 enum ir_variable_mode {
310 ir_var_auto = 0, /**< Function local variables and globals. */
311 ir_var_uniform, /**< Variable declared as a uniform. */
312 ir_var_shader_in,
313 ir_var_shader_out,
314 ir_var_function_in,
315 ir_var_function_out,
316 ir_var_function_inout,
317 ir_var_const_in, /**< "in" param that must be a constant expression */
318 ir_var_system_value, /**< Ex: front-face, instance-id, etc. */
319 ir_var_temporary, /**< Temporary variable generated during compilation. */
320 ir_var_mode_count /**< Number of variable modes */
321 };
322
323 /**
324 * Enum keeping track of how a variable was declared. For error checking of
325 * the gl_PerVertex redeclaration rules.
326 */
327 enum ir_var_declaration_type {
328 /**
329 * Normal declaration (for most variables, this means an explicit
330 * declaration. Exception: temporaries are always implicitly declared, but
331 * they still use ir_var_declared_normally).
332 *
333 * Note: an ir_variable that represents a named interface block uses
334 * ir_var_declared_normally.
335 */
336 ir_var_declared_normally = 0,
337
338 /**
339 * Variable was explicitly declared (or re-declared) in an unnamed
340 * interface block.
341 */
342 ir_var_declared_in_block,
343
344 /**
345 * Variable is an implicitly declared built-in that has not been explicitly
346 * re-declared by the shader.
347 */
348 ir_var_declared_implicitly,
349
350 /**
351 * Variable is implicitly generated by the compiler and should not be
352 * visible via the API.
353 */
354 ir_var_hidden,
355 };
356
357 /**
358 * \brief Layout qualifiers for gl_FragDepth.
359 *
360 * The AMD/ARB_conservative_depth extensions allow gl_FragDepth to be redeclared
361 * with a layout qualifier.
362 */
363 enum ir_depth_layout {
364 ir_depth_layout_none, /**< No depth layout is specified. */
365 ir_depth_layout_any,
366 ir_depth_layout_greater,
367 ir_depth_layout_less,
368 ir_depth_layout_unchanged
369 };
370
371 /**
372 * \brief Convert depth layout qualifier to string.
373 */
374 const char*
375 depth_layout_string(ir_depth_layout layout);
376
377 /**
378 * Description of built-in state associated with a uniform
379 *
380 * \sa ir_variable::state_slots
381 */
382 struct ir_state_slot {
383 int tokens[5];
384 int swizzle;
385 };
386
387
388 /**
389 * Get the string value for an interpolation qualifier
390 *
391 * \return The string that would be used in a shader to specify \c
392 * mode will be returned.
393 *
394 * This function is used to generate error messages of the form "shader
395 * uses %s interpolation qualifier", so in the case where there is no
396 * interpolation qualifier, it returns "no".
397 *
398 * This function should only be used on a shader input or output variable.
399 */
400 const char *interpolation_string(unsigned interpolation);
401
402
403 class ir_variable : public ir_instruction {
404 public:
405 ir_variable(const struct glsl_type *, const char *, ir_variable_mode);
406
407 virtual ir_variable *clone(void *mem_ctx, struct hash_table *ht) const;
408
409 virtual void accept(ir_visitor *v)
410 {
411 v->visit(this);
412 }
413
414 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
415
416
417 /**
418 * Determine how this variable should be interpolated based on its
419 * interpolation qualifier (if present), whether it is gl_Color or
420 * gl_SecondaryColor, and whether flatshading is enabled in the current GL
421 * state.
422 *
423 * The return value will always be either INTERP_QUALIFIER_SMOOTH,
424 * INTERP_QUALIFIER_NOPERSPECTIVE, or INTERP_QUALIFIER_FLAT.
425 */
426 glsl_interp_qualifier determine_interpolation_mode(bool flat_shade);
427
428 /**
429 * Determine whether or not a variable is part of a uniform block.
430 */
431 inline bool is_in_uniform_block() const
432 {
433 return this->data.mode == ir_var_uniform && this->interface_type != NULL;
434 }
435
436 /**
437 * Determine whether or not a variable is the declaration of an interface
438 * block
439 *
440 * For the first declaration below, there will be an \c ir_variable named
441 * "instance" whose type and whose instance_type will be the same
442 * \cglsl_type. For the second declaration, there will be an \c ir_variable
443 * named "f" whose type is float and whose instance_type is B2.
444 *
445 * "instance" is an interface instance variable, but "f" is not.
446 *
447 * uniform B1 {
448 * float f;
449 * } instance;
450 *
451 * uniform B2 {
452 * float f;
453 * };
454 */
455 inline bool is_interface_instance() const
456 {
457 return this->type->without_array() == this->interface_type;
458 }
459
460 /**
461 * Set this->interface_type on a newly created variable.
462 */
463 void init_interface_type(const struct glsl_type *type)
464 {
465 assert(this->interface_type == NULL);
466 this->interface_type = type;
467 if (this->is_interface_instance()) {
468 this->u.max_ifc_array_access =
469 rzalloc_array(this, unsigned, type->length);
470 }
471 }
472
473 /**
474 * Change this->interface_type on a variable that previously had a
475 * different, but compatible, interface_type. This is used during linking
476 * to set the size of arrays in interface blocks.
477 */
478 void change_interface_type(const struct glsl_type *type)
479 {
480 if (this->u.max_ifc_array_access != NULL) {
481 /* max_ifc_array_access has already been allocated, so make sure the
482 * new interface has the same number of fields as the old one.
483 */
484 assert(this->interface_type->length == type->length);
485 }
486 this->interface_type = type;
487 }
488
489 /**
490 * Change this->interface_type on a variable that previously had a
491 * different, and incompatible, interface_type. This is used during
492 * compilation to handle redeclaration of the built-in gl_PerVertex
493 * interface block.
494 */
495 void reinit_interface_type(const struct glsl_type *type)
496 {
497 if (this->u.max_ifc_array_access != NULL) {
498 #ifndef NDEBUG
499 /* Redeclaring gl_PerVertex is only allowed if none of the built-ins
500 * it defines have been accessed yet; so it's safe to throw away the
501 * old max_ifc_array_access pointer, since all of its values are
502 * zero.
503 */
504 for (unsigned i = 0; i < this->interface_type->length; i++)
505 assert(this->u.max_ifc_array_access[i] == 0);
506 #endif
507 ralloc_free(this->u.max_ifc_array_access);
508 this->u.max_ifc_array_access = NULL;
509 }
510 this->interface_type = NULL;
511 init_interface_type(type);
512 }
513
514 const glsl_type *get_interface_type() const
515 {
516 return this->interface_type;
517 }
518
519 /**
520 * Get the max_ifc_array_access pointer
521 *
522 * A "set" function is not needed because the array is dynmically allocated
523 * as necessary.
524 */
525 inline unsigned *get_max_ifc_array_access()
526 {
527 assert(this->data._num_state_slots == 0);
528 return this->u.max_ifc_array_access;
529 }
530
531 inline unsigned get_num_state_slots() const
532 {
533 assert(!this->is_interface_instance()
534 || this->data._num_state_slots == 0);
535 return this->data._num_state_slots;
536 }
537
538 inline void set_num_state_slots(unsigned n)
539 {
540 assert(!this->is_interface_instance()
541 || n == 0);
542 this->data._num_state_slots = n;
543 }
544
545 inline ir_state_slot *get_state_slots()
546 {
547 return this->is_interface_instance() ? NULL : this->u.state_slots;
548 }
549
550 inline const ir_state_slot *get_state_slots() const
551 {
552 return this->is_interface_instance() ? NULL : this->u.state_slots;
553 }
554
555 inline ir_state_slot *allocate_state_slots(unsigned n)
556 {
557 assert(!this->is_interface_instance());
558
559 this->u.state_slots = ralloc_array(this, ir_state_slot, n);
560 this->data._num_state_slots = 0;
561
562 if (this->u.state_slots != NULL)
563 this->data._num_state_slots = n;
564
565 return this->u.state_slots;
566 }
567
568 inline bool is_name_ralloced() const
569 {
570 return this->name != ir_variable::tmp_name;
571 }
572
573 /**
574 * Enable emitting extension warnings for this variable
575 */
576 void enable_extension_warning(const char *extension);
577
578 /**
579 * Get the extension warning string for this variable
580 *
581 * If warnings are not enabled, \c NULL is returned.
582 */
583 const char *get_extension_warning() const;
584
585 /**
586 * Declared type of the variable
587 */
588 const struct glsl_type *type;
589
590 /**
591 * Declared name of the variable
592 */
593 const char *name;
594
595 struct ir_variable_data {
596
597 /**
598 * Is the variable read-only?
599 *
600 * This is set for variables declared as \c const, shader inputs,
601 * and uniforms.
602 */
603 unsigned read_only:1;
604 unsigned centroid:1;
605 unsigned sample:1;
606 unsigned invariant:1;
607 unsigned precise:1;
608
609 /**
610 * Has this variable been used for reading or writing?
611 *
612 * Several GLSL semantic checks require knowledge of whether or not a
613 * variable has been used. For example, it is an error to redeclare a
614 * variable as invariant after it has been used.
615 *
616 * This is only maintained in the ast_to_hir.cpp path, not in
617 * Mesa's fixed function or ARB program paths.
618 */
619 unsigned used:1;
620
621 /**
622 * Has this variable been statically assigned?
623 *
624 * This answers whether the variable was assigned in any path of
625 * the shader during ast_to_hir. This doesn't answer whether it is
626 * still written after dead code removal, nor is it maintained in
627 * non-ast_to_hir.cpp (GLSL parsing) paths.
628 */
629 unsigned assigned:1;
630
631 /**
632 * Enum indicating how the variable was declared. See
633 * ir_var_declaration_type.
634 *
635 * This is used to detect certain kinds of illegal variable redeclarations.
636 */
637 unsigned how_declared:2;
638
639 /**
640 * Storage class of the variable.
641 *
642 * \sa ir_variable_mode
643 */
644 unsigned mode:4;
645
646 /**
647 * Interpolation mode for shader inputs / outputs
648 *
649 * \sa ir_variable_interpolation
650 */
651 unsigned interpolation:2;
652
653 /**
654 * \name ARB_fragment_coord_conventions
655 * @{
656 */
657 unsigned origin_upper_left:1;
658 unsigned pixel_center_integer:1;
659 /*@}*/
660
661 /**
662 * Was the location explicitly set in the shader?
663 *
664 * If the location is explicitly set in the shader, it \b cannot be changed
665 * by the linker or by the API (e.g., calls to \c glBindAttribLocation have
666 * no effect).
667 */
668 unsigned explicit_location:1;
669 unsigned explicit_index:1;
670
671 /**
672 * Was an initial binding explicitly set in the shader?
673 *
674 * If so, constant_value contains an integer ir_constant representing the
675 * initial binding point.
676 */
677 unsigned explicit_binding:1;
678
679 /**
680 * Does this variable have an initializer?
681 *
682 * This is used by the linker to cross-validiate initializers of global
683 * variables.
684 */
685 unsigned has_initializer:1;
686
687 /**
688 * Is this variable a generic output or input that has not yet been matched
689 * up to a variable in another stage of the pipeline?
690 *
691 * This is used by the linker as scratch storage while assigning locations
692 * to generic inputs and outputs.
693 */
694 unsigned is_unmatched_generic_inout:1;
695
696 /**
697 * If non-zero, then this variable may be packed along with other variables
698 * into a single varying slot, so this offset should be applied when
699 * accessing components. For example, an offset of 1 means that the x
700 * component of this variable is actually stored in component y of the
701 * location specified by \c location.
702 */
703 unsigned location_frac:2;
704
705 /**
706 * Layout of the matrix. Uses glsl_matrix_layout values.
707 */
708 unsigned matrix_layout:2;
709
710 /**
711 * Non-zero if this variable was created by lowering a named interface
712 * block which was not an array.
713 *
714 * Note that this variable and \c from_named_ifc_block_array will never
715 * both be non-zero.
716 */
717 unsigned from_named_ifc_block_nonarray:1;
718
719 /**
720 * Non-zero if this variable was created by lowering a named interface
721 * block which was an array.
722 *
723 * Note that this variable and \c from_named_ifc_block_nonarray will never
724 * both be non-zero.
725 */
726 unsigned from_named_ifc_block_array:1;
727
728 /**
729 * Non-zero if the variable must be a shader input. This is useful for
730 * constraints on function parameters.
731 */
732 unsigned must_be_shader_input:1;
733
734 /**
735 * Output index for dual source blending.
736 *
737 * \note
738 * The GLSL spec only allows the values 0 or 1 for the index in \b dual
739 * source blending.
740 */
741 unsigned index:1;
742
743 /**
744 * \brief Layout qualifier for gl_FragDepth.
745 *
746 * This is not equal to \c ir_depth_layout_none if and only if this
747 * variable is \c gl_FragDepth and a layout qualifier is specified.
748 */
749 ir_depth_layout depth_layout:3;
750
751 /**
752 * ARB_shader_image_load_store qualifiers.
753 */
754 unsigned image_read_only:1; /**< "readonly" qualifier. */
755 unsigned image_write_only:1; /**< "writeonly" qualifier. */
756 unsigned image_coherent:1;
757 unsigned image_volatile:1;
758 unsigned image_restrict:1;
759
760 /**
761 * Emit a warning if this variable is accessed.
762 */
763 private:
764 uint8_t warn_extension_index;
765
766 public:
767 /** Image internal format if specified explicitly, otherwise GL_NONE. */
768 uint16_t image_format;
769
770 private:
771 /**
772 * Number of state slots used
773 *
774 * \note
775 * This could be stored in as few as 7-bits, if necessary. If it is made
776 * smaller, add an assertion to \c ir_variable::allocate_state_slots to
777 * be safe.
778 */
779 uint16_t _num_state_slots;
780
781 public:
782 /**
783 * Initial binding point for a sampler, atomic, or UBO.
784 *
785 * For array types, this represents the binding point for the first element.
786 */
787 int16_t binding;
788
789 /**
790 * Storage location of the base of this variable
791 *
792 * The precise meaning of this field depends on the nature of the variable.
793 *
794 * - Vertex shader input: one of the values from \c gl_vert_attrib.
795 * - Vertex shader output: one of the values from \c gl_varying_slot.
796 * - Geometry shader input: one of the values from \c gl_varying_slot.
797 * - Geometry shader output: one of the values from \c gl_varying_slot.
798 * - Fragment shader input: one of the values from \c gl_varying_slot.
799 * - Fragment shader output: one of the values from \c gl_frag_result.
800 * - Uniforms: Per-stage uniform slot number for default uniform block.
801 * - Uniforms: Index within the uniform block definition for UBO members.
802 * - Other: This field is not currently used.
803 *
804 * If the variable is a uniform, shader input, or shader output, and the
805 * slot has not been assigned, the value will be -1.
806 */
807 int location;
808
809 /**
810 * Vertex stream output identifier.
811 */
812 unsigned stream;
813
814 /**
815 * Location an atomic counter is stored at.
816 */
817 struct {
818 unsigned offset;
819 } atomic;
820
821 /**
822 * Highest element accessed with a constant expression array index
823 *
824 * Not used for non-array variables.
825 */
826 unsigned max_array_access;
827
828 /**
829 * Allow (only) ir_variable direct access private members.
830 */
831 friend class ir_variable;
832 } data;
833
834 /**
835 * Value assigned in the initializer of a variable declared "const"
836 */
837 ir_constant *constant_value;
838
839 /**
840 * Constant expression assigned in the initializer of the variable
841 *
842 * \warning
843 * This field and \c ::constant_value are distinct. Even if the two fields
844 * refer to constants with the same value, they must point to separate
845 * objects.
846 */
847 ir_constant *constant_initializer;
848
849 private:
850 static const char *const warn_extension_table[];
851
852 union {
853 /**
854 * For variables which satisfy the is_interface_instance() predicate,
855 * this points to an array of integers such that if the ith member of
856 * the interface block is an array, max_ifc_array_access[i] is the
857 * maximum array element of that member that has been accessed. If the
858 * ith member of the interface block is not an array,
859 * max_ifc_array_access[i] is unused.
860 *
861 * For variables whose type is not an interface block, this pointer is
862 * NULL.
863 */
864 unsigned *max_ifc_array_access;
865
866 /**
867 * Built-in state that backs this uniform
868 *
869 * Once set at variable creation, \c state_slots must remain invariant.
870 *
871 * If the variable is not a uniform, \c _num_state_slots will be zero
872 * and \c state_slots will be \c NULL.
873 */
874 ir_state_slot *state_slots;
875 } u;
876
877 /**
878 * For variables that are in an interface block or are an instance of an
879 * interface block, this is the \c GLSL_TYPE_INTERFACE type for that block.
880 *
881 * \sa ir_variable::location
882 */
883 const glsl_type *interface_type;
884
885 /**
886 * Name used for anonymous compiler temporaries
887 */
888 static const char tmp_name[];
889
890 public:
891 /**
892 * Should the construct keep names for ir_var_temporary variables?
893 *
894 * When this global is false, names passed to the constructor for
895 * \c ir_var_temporary variables will be dropped. Instead, the variable will
896 * be named "compiler_temp". This name will be in static storage.
897 *
898 * \warning
899 * \b NEVER change the mode of an \c ir_var_temporary.
900 *
901 * \warning
902 * This variable is \b not thread-safe. It is global, \b not
903 * per-context. It begins life false. A context can, at some point, make
904 * it true. From that point on, it will be true forever. This should be
905 * okay since it will only be set true while debugging.
906 */
907 static bool temporaries_allocate_names;
908 };
909
910 /**
911 * A function that returns whether a built-in function is available in the
912 * current shading language (based on version, ES or desktop, and extensions).
913 */
914 typedef bool (*builtin_available_predicate)(const _mesa_glsl_parse_state *);
915
916 /*@{*/
917 /**
918 * The representation of a function instance; may be the full definition or
919 * simply a prototype.
920 */
921 class ir_function_signature : public ir_instruction {
922 /* An ir_function_signature will be part of the list of signatures in
923 * an ir_function.
924 */
925 public:
926 ir_function_signature(const glsl_type *return_type,
927 builtin_available_predicate builtin_avail = NULL);
928
929 virtual ir_function_signature *clone(void *mem_ctx,
930 struct hash_table *ht) const;
931 ir_function_signature *clone_prototype(void *mem_ctx,
932 struct hash_table *ht) const;
933
934 virtual void accept(ir_visitor *v)
935 {
936 v->visit(this);
937 }
938
939 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
940
941 /**
942 * Attempt to evaluate this function as a constant expression,
943 * given a list of the actual parameters and the variable context.
944 * Returns NULL for non-built-ins.
945 */
946 ir_constant *constant_expression_value(exec_list *actual_parameters, struct hash_table *variable_context);
947
948 /**
949 * Get the name of the function for which this is a signature
950 */
951 const char *function_name() const;
952
953 /**
954 * Get a handle to the function for which this is a signature
955 *
956 * There is no setter function, this function returns a \c const pointer,
957 * and \c ir_function_signature::_function is private for a reason. The
958 * only way to make a connection between a function and function signature
959 * is via \c ir_function::add_signature. This helps ensure that certain
960 * invariants (i.e., a function signature is in the list of signatures for
961 * its \c _function) are met.
962 *
963 * \sa ir_function::add_signature
964 */
965 inline const class ir_function *function() const
966 {
967 return this->_function;
968 }
969
970 /**
971 * Check whether the qualifiers match between this signature's parameters
972 * and the supplied parameter list. If not, returns the name of the first
973 * parameter with mismatched qualifiers (for use in error messages).
974 */
975 const char *qualifiers_match(exec_list *params);
976
977 /**
978 * Replace the current parameter list with the given one. This is useful
979 * if the current information came from a prototype, and either has invalid
980 * or missing parameter names.
981 */
982 void replace_parameters(exec_list *new_params);
983
984 /**
985 * Function return type.
986 *
987 * \note This discards the optional precision qualifier.
988 */
989 const struct glsl_type *return_type;
990
991 /**
992 * List of ir_variable of function parameters.
993 *
994 * This represents the storage. The paramaters passed in a particular
995 * call will be in ir_call::actual_paramaters.
996 */
997 struct exec_list parameters;
998
999 /** Whether or not this function has a body (which may be empty). */
1000 unsigned is_defined:1;
1001
1002 /** Whether or not this function signature is a built-in. */
1003 bool is_builtin() const;
1004
1005 /**
1006 * Whether or not this function is an intrinsic to be implemented
1007 * by the driver.
1008 */
1009 bool is_intrinsic;
1010
1011 /** Whether or not a built-in is available for this shader. */
1012 bool is_builtin_available(const _mesa_glsl_parse_state *state) const;
1013
1014 /** Body of instructions in the function. */
1015 struct exec_list body;
1016
1017 private:
1018 /**
1019 * A function pointer to a predicate that answers whether a built-in
1020 * function is available in the current shader. NULL if not a built-in.
1021 */
1022 builtin_available_predicate builtin_avail;
1023
1024 /** Function of which this signature is one overload. */
1025 class ir_function *_function;
1026
1027 /** Function signature of which this one is a prototype clone */
1028 const ir_function_signature *origin;
1029
1030 friend class ir_function;
1031
1032 /**
1033 * Helper function to run a list of instructions for constant
1034 * expression evaluation.
1035 *
1036 * The hash table represents the values of the visible variables.
1037 * There are no scoping issues because the table is indexed on
1038 * ir_variable pointers, not variable names.
1039 *
1040 * Returns false if the expression is not constant, true otherwise,
1041 * and the value in *result if result is non-NULL.
1042 */
1043 bool constant_expression_evaluate_expression_list(const struct exec_list &body,
1044 struct hash_table *variable_context,
1045 ir_constant **result);
1046 };
1047
1048
1049 /**
1050 * Header for tracking multiple overloaded functions with the same name.
1051 * Contains a list of ir_function_signatures representing each of the
1052 * actual functions.
1053 */
1054 class ir_function : public ir_instruction {
1055 public:
1056 ir_function(const char *name);
1057
1058 virtual ir_function *clone(void *mem_ctx, struct hash_table *ht) const;
1059
1060 virtual void accept(ir_visitor *v)
1061 {
1062 v->visit(this);
1063 }
1064
1065 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
1066
1067 void add_signature(ir_function_signature *sig)
1068 {
1069 sig->_function = this;
1070 this->signatures.push_tail(sig);
1071 }
1072
1073 /**
1074 * Find a signature that matches a set of actual parameters, taking implicit
1075 * conversions into account. Also flags whether the match was exact.
1076 */
1077 ir_function_signature *matching_signature(_mesa_glsl_parse_state *state,
1078 const exec_list *actual_param,
1079 bool allow_builtins,
1080 bool *match_is_exact);
1081
1082 /**
1083 * Find a signature that matches a set of actual parameters, taking implicit
1084 * conversions into account.
1085 */
1086 ir_function_signature *matching_signature(_mesa_glsl_parse_state *state,
1087 const exec_list *actual_param,
1088 bool allow_builtins);
1089
1090 /**
1091 * Find a signature that exactly matches a set of actual parameters without
1092 * any implicit type conversions.
1093 */
1094 ir_function_signature *exact_matching_signature(_mesa_glsl_parse_state *state,
1095 const exec_list *actual_ps);
1096
1097 /**
1098 * Name of the function.
1099 */
1100 const char *name;
1101
1102 /** Whether or not this function has a signature that isn't a built-in. */
1103 bool has_user_signature();
1104
1105 /**
1106 * List of ir_function_signature for each overloaded function with this name.
1107 */
1108 struct exec_list signatures;
1109 };
1110
1111 inline const char *ir_function_signature::function_name() const
1112 {
1113 return this->_function->name;
1114 }
1115 /*@}*/
1116
1117
1118 /**
1119 * IR instruction representing high-level if-statements
1120 */
1121 class ir_if : public ir_instruction {
1122 public:
1123 ir_if(ir_rvalue *condition)
1124 : ir_instruction(ir_type_if), condition(condition)
1125 {
1126 }
1127
1128 virtual ir_if *clone(void *mem_ctx, struct hash_table *ht) const;
1129
1130 virtual void accept(ir_visitor *v)
1131 {
1132 v->visit(this);
1133 }
1134
1135 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
1136
1137 ir_rvalue *condition;
1138 /** List of ir_instruction for the body of the then branch */
1139 exec_list then_instructions;
1140 /** List of ir_instruction for the body of the else branch */
1141 exec_list else_instructions;
1142 };
1143
1144
1145 /**
1146 * IR instruction representing a high-level loop structure.
1147 */
1148 class ir_loop : public ir_instruction {
1149 public:
1150 ir_loop();
1151
1152 virtual ir_loop *clone(void *mem_ctx, struct hash_table *ht) const;
1153
1154 virtual void accept(ir_visitor *v)
1155 {
1156 v->visit(this);
1157 }
1158
1159 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
1160
1161 /** List of ir_instruction that make up the body of the loop. */
1162 exec_list body_instructions;
1163 };
1164
1165
1166 class ir_assignment : public ir_instruction {
1167 public:
1168 ir_assignment(ir_rvalue *lhs, ir_rvalue *rhs, ir_rvalue *condition = NULL);
1169
1170 /**
1171 * Construct an assignment with an explicit write mask
1172 *
1173 * \note
1174 * Since a write mask is supplied, the LHS must already be a bare
1175 * \c ir_dereference. The cannot be any swizzles in the LHS.
1176 */
1177 ir_assignment(ir_dereference *lhs, ir_rvalue *rhs, ir_rvalue *condition,
1178 unsigned write_mask);
1179
1180 virtual ir_assignment *clone(void *mem_ctx, struct hash_table *ht) const;
1181
1182 virtual ir_constant *constant_expression_value(struct hash_table *variable_context = NULL);
1183
1184 virtual void accept(ir_visitor *v)
1185 {
1186 v->visit(this);
1187 }
1188
1189 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
1190
1191 /**
1192 * Get a whole variable written by an assignment
1193 *
1194 * If the LHS of the assignment writes a whole variable, the variable is
1195 * returned. Otherwise \c NULL is returned. Examples of whole-variable
1196 * assignment are:
1197 *
1198 * - Assigning to a scalar
1199 * - Assigning to all components of a vector
1200 * - Whole array (or matrix) assignment
1201 * - Whole structure assignment
1202 */
1203 ir_variable *whole_variable_written();
1204
1205 /**
1206 * Set the LHS of an assignment
1207 */
1208 void set_lhs(ir_rvalue *lhs);
1209
1210 /**
1211 * Left-hand side of the assignment.
1212 *
1213 * This should be treated as read only. If you need to set the LHS of an
1214 * assignment, use \c ir_assignment::set_lhs.
1215 */
1216 ir_dereference *lhs;
1217
1218 /**
1219 * Value being assigned
1220 */
1221 ir_rvalue *rhs;
1222
1223 /**
1224 * Optional condition for the assignment.
1225 */
1226 ir_rvalue *condition;
1227
1228
1229 /**
1230 * Component mask written
1231 *
1232 * For non-vector types in the LHS, this field will be zero. For vector
1233 * types, a bit will be set for each component that is written. Note that
1234 * for \c vec2 and \c vec3 types only the lower bits will ever be set.
1235 *
1236 * A partially-set write mask means that each enabled channel gets
1237 * the value from a consecutive channel of the rhs. For example,
1238 * to write just .xyw of gl_FrontColor with color:
1239 *
1240 * (assign (constant bool (1)) (xyw)
1241 * (var_ref gl_FragColor)
1242 * (swiz xyw (var_ref color)))
1243 */
1244 unsigned write_mask:4;
1245 };
1246
1247 /* Update ir_expression::get_num_operands() and operator_strs when
1248 * updating this list.
1249 */
1250 enum ir_expression_operation {
1251 ir_unop_bit_not,
1252 ir_unop_logic_not,
1253 ir_unop_neg,
1254 ir_unop_abs,
1255 ir_unop_sign,
1256 ir_unop_rcp,
1257 ir_unop_rsq,
1258 ir_unop_sqrt,
1259 ir_unop_exp, /**< Log base e on gentype */
1260 ir_unop_log, /**< Natural log on gentype */
1261 ir_unop_exp2,
1262 ir_unop_log2,
1263 ir_unop_f2i, /**< Float-to-integer conversion. */
1264 ir_unop_f2u, /**< Float-to-unsigned conversion. */
1265 ir_unop_i2f, /**< Integer-to-float conversion. */
1266 ir_unop_f2b, /**< Float-to-boolean conversion */
1267 ir_unop_b2f, /**< Boolean-to-float conversion */
1268 ir_unop_i2b, /**< int-to-boolean conversion */
1269 ir_unop_b2i, /**< Boolean-to-int conversion */
1270 ir_unop_u2f, /**< Unsigned-to-float conversion. */
1271 ir_unop_i2u, /**< Integer-to-unsigned conversion. */
1272 ir_unop_u2i, /**< Unsigned-to-integer conversion. */
1273 ir_unop_d2f, /**< Double-to-float conversion. */
1274 ir_unop_f2d, /**< Float-to-double conversion. */
1275 ir_unop_d2i, /**< Double-to-integer conversion. */
1276 ir_unop_i2d, /**< Integer-to-double conversion. */
1277 ir_unop_d2u, /**< Double-to-unsigned conversion. */
1278 ir_unop_u2d, /**< Unsigned-to-double conversion. */
1279 ir_unop_d2b, /**< Double-to-boolean conversion. */
1280 ir_unop_bitcast_i2f, /**< Bit-identical int-to-float "conversion" */
1281 ir_unop_bitcast_f2i, /**< Bit-identical float-to-int "conversion" */
1282 ir_unop_bitcast_u2f, /**< Bit-identical uint-to-float "conversion" */
1283 ir_unop_bitcast_f2u, /**< Bit-identical float-to-uint "conversion" */
1284 ir_unop_any,
1285
1286 /**
1287 * \name Unary floating-point rounding operations.
1288 */
1289 /*@{*/
1290 ir_unop_trunc,
1291 ir_unop_ceil,
1292 ir_unop_floor,
1293 ir_unop_fract,
1294 ir_unop_round_even,
1295 /*@}*/
1296
1297 /**
1298 * \name Trigonometric operations.
1299 */
1300 /*@{*/
1301 ir_unop_sin,
1302 ir_unop_cos,
1303 ir_unop_sin_reduced, /**< Reduced range sin. [-pi, pi] */
1304 ir_unop_cos_reduced, /**< Reduced range cos. [-pi, pi] */
1305 /*@}*/
1306
1307 /**
1308 * \name Partial derivatives.
1309 */
1310 /*@{*/
1311 ir_unop_dFdx,
1312 ir_unop_dFdx_coarse,
1313 ir_unop_dFdx_fine,
1314 ir_unop_dFdy,
1315 ir_unop_dFdy_coarse,
1316 ir_unop_dFdy_fine,
1317 /*@}*/
1318
1319 /**
1320 * \name Floating point pack and unpack operations.
1321 */
1322 /*@{*/
1323 ir_unop_pack_snorm_2x16,
1324 ir_unop_pack_snorm_4x8,
1325 ir_unop_pack_unorm_2x16,
1326 ir_unop_pack_unorm_4x8,
1327 ir_unop_pack_half_2x16,
1328 ir_unop_unpack_snorm_2x16,
1329 ir_unop_unpack_snorm_4x8,
1330 ir_unop_unpack_unorm_2x16,
1331 ir_unop_unpack_unorm_4x8,
1332 ir_unop_unpack_half_2x16,
1333 /*@}*/
1334
1335 /**
1336 * \name Lowered floating point unpacking operations.
1337 *
1338 * \see lower_packing_builtins_visitor::split_unpack_half_2x16
1339 */
1340 /*@{*/
1341 ir_unop_unpack_half_2x16_split_x,
1342 ir_unop_unpack_half_2x16_split_y,
1343 /*@}*/
1344
1345 /**
1346 * \name Bit operations, part of ARB_gpu_shader5.
1347 */
1348 /*@{*/
1349 ir_unop_bitfield_reverse,
1350 ir_unop_bit_count,
1351 ir_unop_find_msb,
1352 ir_unop_find_lsb,
1353 /*@}*/
1354
1355 ir_unop_saturate,
1356
1357 /**
1358 * \name Double packing, part of ARB_gpu_shader_fp64.
1359 */
1360 /*@{*/
1361 ir_unop_pack_double_2x32,
1362 ir_unop_unpack_double_2x32,
1363 /*@}*/
1364
1365 ir_unop_frexp_sig,
1366 ir_unop_frexp_exp,
1367
1368 ir_unop_noise,
1369
1370 /**
1371 * Interpolate fs input at centroid
1372 *
1373 * operand0 is the fs input.
1374 */
1375 ir_unop_interpolate_at_centroid,
1376
1377 /**
1378 * A sentinel marking the last of the unary operations.
1379 */
1380 ir_last_unop = ir_unop_interpolate_at_centroid,
1381
1382 ir_binop_add,
1383 ir_binop_sub,
1384 ir_binop_mul, /**< Floating-point or low 32-bit integer multiply. */
1385 ir_binop_imul_high, /**< Calculates the high 32-bits of a 64-bit multiply. */
1386 ir_binop_div,
1387
1388 /**
1389 * Returns the carry resulting from the addition of the two arguments.
1390 */
1391 /*@{*/
1392 ir_binop_carry,
1393 /*@}*/
1394
1395 /**
1396 * Returns the borrow resulting from the subtraction of the second argument
1397 * from the first argument.
1398 */
1399 /*@{*/
1400 ir_binop_borrow,
1401 /*@}*/
1402
1403 /**
1404 * Takes one of two combinations of arguments:
1405 *
1406 * - mod(vecN, vecN)
1407 * - mod(vecN, float)
1408 *
1409 * Does not take integer types.
1410 */
1411 ir_binop_mod,
1412
1413 /**
1414 * \name Binary comparison operators which return a boolean vector.
1415 * The type of both operands must be equal.
1416 */
1417 /*@{*/
1418 ir_binop_less,
1419 ir_binop_greater,
1420 ir_binop_lequal,
1421 ir_binop_gequal,
1422 ir_binop_equal,
1423 ir_binop_nequal,
1424 /**
1425 * Returns single boolean for whether all components of operands[0]
1426 * equal the components of operands[1].
1427 */
1428 ir_binop_all_equal,
1429 /**
1430 * Returns single boolean for whether any component of operands[0]
1431 * is not equal to the corresponding component of operands[1].
1432 */
1433 ir_binop_any_nequal,
1434 /*@}*/
1435
1436 /**
1437 * \name Bit-wise binary operations.
1438 */
1439 /*@{*/
1440 ir_binop_lshift,
1441 ir_binop_rshift,
1442 ir_binop_bit_and,
1443 ir_binop_bit_xor,
1444 ir_binop_bit_or,
1445 /*@}*/
1446
1447 ir_binop_logic_and,
1448 ir_binop_logic_xor,
1449 ir_binop_logic_or,
1450
1451 ir_binop_dot,
1452 ir_binop_min,
1453 ir_binop_max,
1454
1455 ir_binop_pow,
1456
1457 /**
1458 * \name Lowered floating point packing operations.
1459 *
1460 * \see lower_packing_builtins_visitor::split_pack_half_2x16
1461 */
1462 /*@{*/
1463 ir_binop_pack_half_2x16_split,
1464 /*@}*/
1465
1466 /**
1467 * \name First half of a lowered bitfieldInsert() operation.
1468 *
1469 * \see lower_instructions::bitfield_insert_to_bfm_bfi
1470 */
1471 /*@{*/
1472 ir_binop_bfm,
1473 /*@}*/
1474
1475 /**
1476 * Load a value the size of a given GLSL type from a uniform block.
1477 *
1478 * operand0 is the ir_constant uniform block index in the linked shader.
1479 * operand1 is a byte offset within the uniform block.
1480 */
1481 ir_binop_ubo_load,
1482
1483 /**
1484 * \name Multiplies a number by two to a power, part of ARB_gpu_shader5.
1485 */
1486 /*@{*/
1487 ir_binop_ldexp,
1488 /*@}*/
1489
1490 /**
1491 * Extract a scalar from a vector
1492 *
1493 * operand0 is the vector
1494 * operand1 is the index of the field to read from operand0
1495 */
1496 ir_binop_vector_extract,
1497
1498 /**
1499 * Interpolate fs input at offset
1500 *
1501 * operand0 is the fs input
1502 * operand1 is the offset from the pixel center
1503 */
1504 ir_binop_interpolate_at_offset,
1505
1506 /**
1507 * Interpolate fs input at sample position
1508 *
1509 * operand0 is the fs input
1510 * operand1 is the sample ID
1511 */
1512 ir_binop_interpolate_at_sample,
1513
1514 /**
1515 * A sentinel marking the last of the binary operations.
1516 */
1517 ir_last_binop = ir_binop_interpolate_at_sample,
1518
1519 /**
1520 * \name Fused floating-point multiply-add, part of ARB_gpu_shader5.
1521 */
1522 /*@{*/
1523 ir_triop_fma,
1524 /*@}*/
1525
1526 ir_triop_lrp,
1527
1528 /**
1529 * \name Conditional Select
1530 *
1531 * A vector conditional select instruction (like ?:, but operating per-
1532 * component on vectors).
1533 *
1534 * \see lower_instructions_visitor::ldexp_to_arith
1535 */
1536 /*@{*/
1537 ir_triop_csel,
1538 /*@}*/
1539
1540 /**
1541 * \name Second half of a lowered bitfieldInsert() operation.
1542 *
1543 * \see lower_instructions::bitfield_insert_to_bfm_bfi
1544 */
1545 /*@{*/
1546 ir_triop_bfi,
1547 /*@}*/
1548
1549 ir_triop_bitfield_extract,
1550
1551 /**
1552 * Generate a value with one field of a vector changed
1553 *
1554 * operand0 is the vector
1555 * operand1 is the value to write into the vector result
1556 * operand2 is the index in operand0 to be modified
1557 */
1558 ir_triop_vector_insert,
1559
1560 /**
1561 * A sentinel marking the last of the ternary operations.
1562 */
1563 ir_last_triop = ir_triop_vector_insert,
1564
1565 ir_quadop_bitfield_insert,
1566
1567 ir_quadop_vector,
1568
1569 /**
1570 * A sentinel marking the last of the ternary operations.
1571 */
1572 ir_last_quadop = ir_quadop_vector,
1573
1574 /**
1575 * A sentinel marking the last of all operations.
1576 */
1577 ir_last_opcode = ir_quadop_vector
1578 };
1579
1580 class ir_expression : public ir_rvalue {
1581 public:
1582 ir_expression(int op, const struct glsl_type *type,
1583 ir_rvalue *op0, ir_rvalue *op1 = NULL,
1584 ir_rvalue *op2 = NULL, ir_rvalue *op3 = NULL);
1585
1586 /**
1587 * Constructor for unary operation expressions
1588 */
1589 ir_expression(int op, ir_rvalue *);
1590
1591 /**
1592 * Constructor for binary operation expressions
1593 */
1594 ir_expression(int op, ir_rvalue *op0, ir_rvalue *op1);
1595
1596 /**
1597 * Constructor for ternary operation expressions
1598 */
1599 ir_expression(int op, ir_rvalue *op0, ir_rvalue *op1, ir_rvalue *op2);
1600
1601 virtual bool equals(ir_instruction *ir, enum ir_node_type ignore = ir_type_unset);
1602
1603 virtual ir_expression *clone(void *mem_ctx, struct hash_table *ht) const;
1604
1605 /**
1606 * Attempt to constant-fold the expression
1607 *
1608 * The "variable_context" hash table links ir_variable * to ir_constant *
1609 * that represent the variables' values. \c NULL represents an empty
1610 * context.
1611 *
1612 * If the expression cannot be constant folded, this method will return
1613 * \c NULL.
1614 */
1615 virtual ir_constant *constant_expression_value(struct hash_table *variable_context = NULL);
1616
1617 /**
1618 * Determine the number of operands used by an expression
1619 */
1620 static unsigned int get_num_operands(ir_expression_operation);
1621
1622 /**
1623 * Determine the number of operands used by an expression
1624 */
1625 unsigned int get_num_operands() const
1626 {
1627 return (this->operation == ir_quadop_vector)
1628 ? this->type->vector_elements : get_num_operands(operation);
1629 }
1630
1631 /**
1632 * Return whether the expression operates on vectors horizontally.
1633 */
1634 bool is_horizontal() const
1635 {
1636 return operation == ir_binop_all_equal ||
1637 operation == ir_binop_any_nequal ||
1638 operation == ir_unop_any ||
1639 operation == ir_binop_dot ||
1640 operation == ir_quadop_vector;
1641 }
1642
1643 /**
1644 * Return a string representing this expression's operator.
1645 */
1646 const char *operator_string();
1647
1648 /**
1649 * Return a string representing this expression's operator.
1650 */
1651 static const char *operator_string(ir_expression_operation);
1652
1653
1654 /**
1655 * Do a reverse-lookup to translate the given string into an operator.
1656 */
1657 static ir_expression_operation get_operator(const char *);
1658
1659 virtual void accept(ir_visitor *v)
1660 {
1661 v->visit(this);
1662 }
1663
1664 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
1665
1666 ir_expression_operation operation;
1667 ir_rvalue *operands[4];
1668 };
1669
1670
1671 /**
1672 * HIR instruction representing a high-level function call, containing a list
1673 * of parameters and returning a value in the supplied temporary.
1674 */
1675 class ir_call : public ir_instruction {
1676 public:
1677 ir_call(ir_function_signature *callee,
1678 ir_dereference_variable *return_deref,
1679 exec_list *actual_parameters)
1680 : ir_instruction(ir_type_call), return_deref(return_deref), callee(callee)
1681 {
1682 assert(callee->return_type != NULL);
1683 actual_parameters->move_nodes_to(& this->actual_parameters);
1684 this->use_builtin = callee->is_builtin();
1685 }
1686
1687 virtual ir_call *clone(void *mem_ctx, struct hash_table *ht) const;
1688
1689 virtual ir_constant *constant_expression_value(struct hash_table *variable_context = NULL);
1690
1691 virtual void accept(ir_visitor *v)
1692 {
1693 v->visit(this);
1694 }
1695
1696 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
1697
1698 /**
1699 * Get the name of the function being called.
1700 */
1701 const char *callee_name() const
1702 {
1703 return callee->function_name();
1704 }
1705
1706 /**
1707 * Generates an inline version of the function before @ir,
1708 * storing the return value in return_deref.
1709 */
1710 void generate_inline(ir_instruction *ir);
1711
1712 /**
1713 * Storage for the function's return value.
1714 * This must be NULL if the return type is void.
1715 */
1716 ir_dereference_variable *return_deref;
1717
1718 /**
1719 * The specific function signature being called.
1720 */
1721 ir_function_signature *callee;
1722
1723 /* List of ir_rvalue of paramaters passed in this call. */
1724 exec_list actual_parameters;
1725
1726 /** Should this call only bind to a built-in function? */
1727 bool use_builtin;
1728 };
1729
1730
1731 /**
1732 * \name Jump-like IR instructions.
1733 *
1734 * These include \c break, \c continue, \c return, and \c discard.
1735 */
1736 /*@{*/
1737 class ir_jump : public ir_instruction {
1738 protected:
1739 ir_jump(enum ir_node_type t)
1740 : ir_instruction(t)
1741 {
1742 }
1743 };
1744
1745 class ir_return : public ir_jump {
1746 public:
1747 ir_return()
1748 : ir_jump(ir_type_return), value(NULL)
1749 {
1750 }
1751
1752 ir_return(ir_rvalue *value)
1753 : ir_jump(ir_type_return), value(value)
1754 {
1755 }
1756
1757 virtual ir_return *clone(void *mem_ctx, struct hash_table *) const;
1758
1759 ir_rvalue *get_value() const
1760 {
1761 return value;
1762 }
1763
1764 virtual void accept(ir_visitor *v)
1765 {
1766 v->visit(this);
1767 }
1768
1769 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
1770
1771 ir_rvalue *value;
1772 };
1773
1774
1775 /**
1776 * Jump instructions used inside loops
1777 *
1778 * These include \c break and \c continue. The \c break within a loop is
1779 * different from the \c break within a switch-statement.
1780 *
1781 * \sa ir_switch_jump
1782 */
1783 class ir_loop_jump : public ir_jump {
1784 public:
1785 enum jump_mode {
1786 jump_break,
1787 jump_continue
1788 };
1789
1790 ir_loop_jump(jump_mode mode)
1791 : ir_jump(ir_type_loop_jump)
1792 {
1793 this->mode = mode;
1794 }
1795
1796 virtual ir_loop_jump *clone(void *mem_ctx, struct hash_table *) const;
1797
1798 virtual void accept(ir_visitor *v)
1799 {
1800 v->visit(this);
1801 }
1802
1803 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
1804
1805 bool is_break() const
1806 {
1807 return mode == jump_break;
1808 }
1809
1810 bool is_continue() const
1811 {
1812 return mode == jump_continue;
1813 }
1814
1815 /** Mode selector for the jump instruction. */
1816 enum jump_mode mode;
1817 };
1818
1819 /**
1820 * IR instruction representing discard statements.
1821 */
1822 class ir_discard : public ir_jump {
1823 public:
1824 ir_discard()
1825 : ir_jump(ir_type_discard)
1826 {
1827 this->condition = NULL;
1828 }
1829
1830 ir_discard(ir_rvalue *cond)
1831 : ir_jump(ir_type_discard)
1832 {
1833 this->condition = cond;
1834 }
1835
1836 virtual ir_discard *clone(void *mem_ctx, struct hash_table *ht) const;
1837
1838 virtual void accept(ir_visitor *v)
1839 {
1840 v->visit(this);
1841 }
1842
1843 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
1844
1845 ir_rvalue *condition;
1846 };
1847 /*@}*/
1848
1849
1850 /**
1851 * Texture sampling opcodes used in ir_texture
1852 */
1853 enum ir_texture_opcode {
1854 ir_tex, /**< Regular texture look-up */
1855 ir_txb, /**< Texture look-up with LOD bias */
1856 ir_txl, /**< Texture look-up with explicit LOD */
1857 ir_txd, /**< Texture look-up with partial derivatvies */
1858 ir_txf, /**< Texel fetch with explicit LOD */
1859 ir_txf_ms, /**< Multisample texture fetch */
1860 ir_txs, /**< Texture size */
1861 ir_lod, /**< Texture lod query */
1862 ir_tg4, /**< Texture gather */
1863 ir_query_levels /**< Texture levels query */
1864 };
1865
1866
1867 /**
1868 * IR instruction to sample a texture
1869 *
1870 * The specific form of the IR instruction depends on the \c mode value
1871 * selected from \c ir_texture_opcodes. In the printed IR, these will
1872 * appear as:
1873 *
1874 * Texel offset (0 or an expression)
1875 * | Projection divisor
1876 * | | Shadow comparitor
1877 * | | |
1878 * v v v
1879 * (tex <type> <sampler> <coordinate> 0 1 ( ))
1880 * (txb <type> <sampler> <coordinate> 0 1 ( ) <bias>)
1881 * (txl <type> <sampler> <coordinate> 0 1 ( ) <lod>)
1882 * (txd <type> <sampler> <coordinate> 0 1 ( ) (dPdx dPdy))
1883 * (txf <type> <sampler> <coordinate> 0 <lod>)
1884 * (txf_ms
1885 * <type> <sampler> <coordinate> <sample_index>)
1886 * (txs <type> <sampler> <lod>)
1887 * (lod <type> <sampler> <coordinate>)
1888 * (tg4 <type> <sampler> <coordinate> <offset> <component>)
1889 * (query_levels <type> <sampler>)
1890 */
1891 class ir_texture : public ir_rvalue {
1892 public:
1893 ir_texture(enum ir_texture_opcode op)
1894 : ir_rvalue(ir_type_texture),
1895 op(op), sampler(NULL), coordinate(NULL), projector(NULL),
1896 shadow_comparitor(NULL), offset(NULL)
1897 {
1898 memset(&lod_info, 0, sizeof(lod_info));
1899 }
1900
1901 virtual ir_texture *clone(void *mem_ctx, struct hash_table *) const;
1902
1903 virtual ir_constant *constant_expression_value(struct hash_table *variable_context = NULL);
1904
1905 virtual void accept(ir_visitor *v)
1906 {
1907 v->visit(this);
1908 }
1909
1910 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
1911
1912 virtual bool equals(ir_instruction *ir, enum ir_node_type ignore = ir_type_unset);
1913
1914 /**
1915 * Return a string representing the ir_texture_opcode.
1916 */
1917 const char *opcode_string();
1918
1919 /** Set the sampler and type. */
1920 void set_sampler(ir_dereference *sampler, const glsl_type *type);
1921
1922 /**
1923 * Do a reverse-lookup to translate a string into an ir_texture_opcode.
1924 */
1925 static ir_texture_opcode get_opcode(const char *);
1926
1927 enum ir_texture_opcode op;
1928
1929 /** Sampler to use for the texture access. */
1930 ir_dereference *sampler;
1931
1932 /** Texture coordinate to sample */
1933 ir_rvalue *coordinate;
1934
1935 /**
1936 * Value used for projective divide.
1937 *
1938 * If there is no projective divide (the common case), this will be
1939 * \c NULL. Optimization passes should check for this to point to a constant
1940 * of 1.0 and replace that with \c NULL.
1941 */
1942 ir_rvalue *projector;
1943
1944 /**
1945 * Coordinate used for comparison on shadow look-ups.
1946 *
1947 * If there is no shadow comparison, this will be \c NULL. For the
1948 * \c ir_txf opcode, this *must* be \c NULL.
1949 */
1950 ir_rvalue *shadow_comparitor;
1951
1952 /** Texel offset. */
1953 ir_rvalue *offset;
1954
1955 union {
1956 ir_rvalue *lod; /**< Floating point LOD */
1957 ir_rvalue *bias; /**< Floating point LOD bias */
1958 ir_rvalue *sample_index; /**< MSAA sample index */
1959 ir_rvalue *component; /**< Gather component selector */
1960 struct {
1961 ir_rvalue *dPdx; /**< Partial derivative of coordinate wrt X */
1962 ir_rvalue *dPdy; /**< Partial derivative of coordinate wrt Y */
1963 } grad;
1964 } lod_info;
1965 };
1966
1967
1968 struct ir_swizzle_mask {
1969 unsigned x:2;
1970 unsigned y:2;
1971 unsigned z:2;
1972 unsigned w:2;
1973
1974 /**
1975 * Number of components in the swizzle.
1976 */
1977 unsigned num_components:3;
1978
1979 /**
1980 * Does the swizzle contain duplicate components?
1981 *
1982 * L-value swizzles cannot contain duplicate components.
1983 */
1984 unsigned has_duplicates:1;
1985 };
1986
1987
1988 class ir_swizzle : public ir_rvalue {
1989 public:
1990 ir_swizzle(ir_rvalue *, unsigned x, unsigned y, unsigned z, unsigned w,
1991 unsigned count);
1992
1993 ir_swizzle(ir_rvalue *val, const unsigned *components, unsigned count);
1994
1995 ir_swizzle(ir_rvalue *val, ir_swizzle_mask mask);
1996
1997 virtual ir_swizzle *clone(void *mem_ctx, struct hash_table *) const;
1998
1999 virtual ir_constant *constant_expression_value(struct hash_table *variable_context = NULL);
2000
2001 /**
2002 * Construct an ir_swizzle from the textual representation. Can fail.
2003 */
2004 static ir_swizzle *create(ir_rvalue *, const char *, unsigned vector_length);
2005
2006 virtual void accept(ir_visitor *v)
2007 {
2008 v->visit(this);
2009 }
2010
2011 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
2012
2013 virtual bool equals(ir_instruction *ir, enum ir_node_type ignore = ir_type_unset);
2014
2015 bool is_lvalue() const
2016 {
2017 return val->is_lvalue() && !mask.has_duplicates;
2018 }
2019
2020 /**
2021 * Get the variable that is ultimately referenced by an r-value
2022 */
2023 virtual ir_variable *variable_referenced() const;
2024
2025 ir_rvalue *val;
2026 ir_swizzle_mask mask;
2027
2028 private:
2029 /**
2030 * Initialize the mask component of a swizzle
2031 *
2032 * This is used by the \c ir_swizzle constructors.
2033 */
2034 void init_mask(const unsigned *components, unsigned count);
2035 };
2036
2037
2038 class ir_dereference : public ir_rvalue {
2039 public:
2040 virtual ir_dereference *clone(void *mem_ctx, struct hash_table *) const = 0;
2041
2042 bool is_lvalue() const;
2043
2044 /**
2045 * Get the variable that is ultimately referenced by an r-value
2046 */
2047 virtual ir_variable *variable_referenced() const = 0;
2048
2049 protected:
2050 ir_dereference(enum ir_node_type t)
2051 : ir_rvalue(t)
2052 {
2053 }
2054 };
2055
2056
2057 class ir_dereference_variable : public ir_dereference {
2058 public:
2059 ir_dereference_variable(ir_variable *var);
2060
2061 virtual ir_dereference_variable *clone(void *mem_ctx,
2062 struct hash_table *) const;
2063
2064 virtual ir_constant *constant_expression_value(struct hash_table *variable_context = NULL);
2065
2066 virtual bool equals(ir_instruction *ir, enum ir_node_type ignore = ir_type_unset);
2067
2068 /**
2069 * Get the variable that is ultimately referenced by an r-value
2070 */
2071 virtual ir_variable *variable_referenced() const
2072 {
2073 return this->var;
2074 }
2075
2076 virtual ir_variable *whole_variable_referenced()
2077 {
2078 /* ir_dereference_variable objects always dereference the entire
2079 * variable. However, if this dereference is dereferenced by anything
2080 * else, the complete deferefernce chain is not a whole-variable
2081 * dereference. This method should only be called on the top most
2082 * ir_rvalue in a dereference chain.
2083 */
2084 return this->var;
2085 }
2086
2087 virtual void accept(ir_visitor *v)
2088 {
2089 v->visit(this);
2090 }
2091
2092 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
2093
2094 /**
2095 * Object being dereferenced.
2096 */
2097 ir_variable *var;
2098 };
2099
2100
2101 class ir_dereference_array : public ir_dereference {
2102 public:
2103 ir_dereference_array(ir_rvalue *value, ir_rvalue *array_index);
2104
2105 ir_dereference_array(ir_variable *var, ir_rvalue *array_index);
2106
2107 virtual ir_dereference_array *clone(void *mem_ctx,
2108 struct hash_table *) const;
2109
2110 virtual ir_constant *constant_expression_value(struct hash_table *variable_context = NULL);
2111
2112 virtual bool equals(ir_instruction *ir, enum ir_node_type ignore = ir_type_unset);
2113
2114 /**
2115 * Get the variable that is ultimately referenced by an r-value
2116 */
2117 virtual ir_variable *variable_referenced() const
2118 {
2119 return this->array->variable_referenced();
2120 }
2121
2122 virtual void accept(ir_visitor *v)
2123 {
2124 v->visit(this);
2125 }
2126
2127 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
2128
2129 ir_rvalue *array;
2130 ir_rvalue *array_index;
2131
2132 private:
2133 void set_array(ir_rvalue *value);
2134 };
2135
2136
2137 class ir_dereference_record : public ir_dereference {
2138 public:
2139 ir_dereference_record(ir_rvalue *value, const char *field);
2140
2141 ir_dereference_record(ir_variable *var, const char *field);
2142
2143 virtual ir_dereference_record *clone(void *mem_ctx,
2144 struct hash_table *) const;
2145
2146 virtual ir_constant *constant_expression_value(struct hash_table *variable_context = NULL);
2147
2148 /**
2149 * Get the variable that is ultimately referenced by an r-value
2150 */
2151 virtual ir_variable *variable_referenced() const
2152 {
2153 return this->record->variable_referenced();
2154 }
2155
2156 virtual void accept(ir_visitor *v)
2157 {
2158 v->visit(this);
2159 }
2160
2161 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
2162
2163 ir_rvalue *record;
2164 const char *field;
2165 };
2166
2167
2168 /**
2169 * Data stored in an ir_constant
2170 */
2171 union ir_constant_data {
2172 unsigned u[16];
2173 int i[16];
2174 float f[16];
2175 bool b[16];
2176 double d[16];
2177 };
2178
2179
2180 class ir_constant : public ir_rvalue {
2181 public:
2182 ir_constant(const struct glsl_type *type, const ir_constant_data *data);
2183 ir_constant(bool b, unsigned vector_elements=1);
2184 ir_constant(unsigned int u, unsigned vector_elements=1);
2185 ir_constant(int i, unsigned vector_elements=1);
2186 ir_constant(float f, unsigned vector_elements=1);
2187 ir_constant(double d, unsigned vector_elements=1);
2188
2189 /**
2190 * Construct an ir_constant from a list of ir_constant values
2191 */
2192 ir_constant(const struct glsl_type *type, exec_list *values);
2193
2194 /**
2195 * Construct an ir_constant from a scalar component of another ir_constant
2196 *
2197 * The new \c ir_constant inherits the type of the component from the
2198 * source constant.
2199 *
2200 * \note
2201 * In the case of a matrix constant, the new constant is a scalar, \b not
2202 * a vector.
2203 */
2204 ir_constant(const ir_constant *c, unsigned i);
2205
2206 /**
2207 * Return a new ir_constant of the specified type containing all zeros.
2208 */
2209 static ir_constant *zero(void *mem_ctx, const glsl_type *type);
2210
2211 virtual ir_constant *clone(void *mem_ctx, struct hash_table *) const;
2212
2213 virtual ir_constant *constant_expression_value(struct hash_table *variable_context = NULL);
2214
2215 virtual void accept(ir_visitor *v)
2216 {
2217 v->visit(this);
2218 }
2219
2220 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
2221
2222 virtual bool equals(ir_instruction *ir, enum ir_node_type ignore = ir_type_unset);
2223
2224 /**
2225 * Get a particular component of a constant as a specific type
2226 *
2227 * This is useful, for example, to get a value from an integer constant
2228 * as a float or bool. This appears frequently when constructors are
2229 * called with all constant parameters.
2230 */
2231 /*@{*/
2232 bool get_bool_component(unsigned i) const;
2233 float get_float_component(unsigned i) const;
2234 double get_double_component(unsigned i) const;
2235 int get_int_component(unsigned i) const;
2236 unsigned get_uint_component(unsigned i) const;
2237 /*@}*/
2238
2239 ir_constant *get_array_element(unsigned i) const;
2240
2241 ir_constant *get_record_field(const char *name);
2242
2243 /**
2244 * Copy the values on another constant at a given offset.
2245 *
2246 * The offset is ignored for array or struct copies, it's only for
2247 * scalars or vectors into vectors or matrices.
2248 *
2249 * With identical types on both sides and zero offset it's clone()
2250 * without creating a new object.
2251 */
2252
2253 void copy_offset(ir_constant *src, int offset);
2254
2255 /**
2256 * Copy the values on another constant at a given offset and
2257 * following an assign-like mask.
2258 *
2259 * The mask is ignored for scalars.
2260 *
2261 * Note that this function only handles what assign can handle,
2262 * i.e. at most a vector as source and a column of a matrix as
2263 * destination.
2264 */
2265
2266 void copy_masked_offset(ir_constant *src, int offset, unsigned int mask);
2267
2268 /**
2269 * Determine whether a constant has the same value as another constant
2270 *
2271 * \sa ir_constant::is_zero, ir_constant::is_one,
2272 * ir_constant::is_negative_one
2273 */
2274 bool has_value(const ir_constant *) const;
2275
2276 /**
2277 * Return true if this ir_constant represents the given value.
2278 *
2279 * For vectors, this checks that each component is the given value.
2280 */
2281 virtual bool is_value(float f, int i) const;
2282 virtual bool is_zero() const;
2283 virtual bool is_one() const;
2284 virtual bool is_negative_one() const;
2285
2286 /**
2287 * Return true for constants that could be stored as 16-bit unsigned values.
2288 *
2289 * Note that this will return true even for signed integer ir_constants, as
2290 * long as the value is non-negative and fits in 16-bits.
2291 */
2292 virtual bool is_uint16_constant() const;
2293
2294 /**
2295 * Value of the constant.
2296 *
2297 * The field used to back the values supplied by the constant is determined
2298 * by the type associated with the \c ir_instruction. Constants may be
2299 * scalars, vectors, or matrices.
2300 */
2301 union ir_constant_data value;
2302
2303 /* Array elements */
2304 ir_constant **array_elements;
2305
2306 /* Structure fields */
2307 exec_list components;
2308
2309 private:
2310 /**
2311 * Parameterless constructor only used by the clone method
2312 */
2313 ir_constant(void);
2314 };
2315
2316 /**
2317 * IR instruction to emit a vertex in a geometry shader.
2318 */
2319 class ir_emit_vertex : public ir_instruction {
2320 public:
2321 ir_emit_vertex(ir_rvalue *stream)
2322 : ir_instruction(ir_type_emit_vertex),
2323 stream(stream)
2324 {
2325 assert(stream);
2326 }
2327
2328 virtual void accept(ir_visitor *v)
2329 {
2330 v->visit(this);
2331 }
2332
2333 virtual ir_emit_vertex *clone(void *mem_ctx, struct hash_table *ht) const
2334 {
2335 return new(mem_ctx) ir_emit_vertex(this->stream->clone(mem_ctx, ht));
2336 }
2337
2338 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
2339
2340 int stream_id() const
2341 {
2342 return stream->as_constant()->value.i[0];
2343 }
2344
2345 ir_rvalue *stream;
2346 };
2347
2348 /**
2349 * IR instruction to complete the current primitive and start a new one in a
2350 * geometry shader.
2351 */
2352 class ir_end_primitive : public ir_instruction {
2353 public:
2354 ir_end_primitive(ir_rvalue *stream)
2355 : ir_instruction(ir_type_end_primitive),
2356 stream(stream)
2357 {
2358 assert(stream);
2359 }
2360
2361 virtual void accept(ir_visitor *v)
2362 {
2363 v->visit(this);
2364 }
2365
2366 virtual ir_end_primitive *clone(void *mem_ctx, struct hash_table *ht) const
2367 {
2368 return new(mem_ctx) ir_end_primitive(this->stream->clone(mem_ctx, ht));
2369 }
2370
2371 virtual ir_visitor_status accept(ir_hierarchical_visitor *);
2372
2373 int stream_id() const
2374 {
2375 return stream->as_constant()->value.i[0];
2376 }
2377
2378 ir_rvalue *stream;
2379 };
2380
2381 /*@}*/
2382
2383 /**
2384 * Apply a visitor to each IR node in a list
2385 */
2386 void
2387 visit_exec_list(exec_list *list, ir_visitor *visitor);
2388
2389 /**
2390 * Validate invariants on each IR node in a list
2391 */
2392 void validate_ir_tree(exec_list *instructions);
2393
2394 struct _mesa_glsl_parse_state;
2395 struct gl_shader_program;
2396
2397 /**
2398 * Detect whether an unlinked shader contains static recursion
2399 *
2400 * If the list of instructions is determined to contain static recursion,
2401 * \c _mesa_glsl_error will be called to emit error messages for each function
2402 * that is in the recursion cycle.
2403 */
2404 void
2405 detect_recursion_unlinked(struct _mesa_glsl_parse_state *state,
2406 exec_list *instructions);
2407
2408 /**
2409 * Detect whether a linked shader contains static recursion
2410 *
2411 * If the list of instructions is determined to contain static recursion,
2412 * \c link_error_printf will be called to emit error messages for each function
2413 * that is in the recursion cycle. In addition,
2414 * \c gl_shader_program::LinkStatus will be set to false.
2415 */
2416 void
2417 detect_recursion_linked(struct gl_shader_program *prog,
2418 exec_list *instructions);
2419
2420 /**
2421 * Make a clone of each IR instruction in a list
2422 *
2423 * \param in List of IR instructions that are to be cloned
2424 * \param out List to hold the cloned instructions
2425 */
2426 void
2427 clone_ir_list(void *mem_ctx, exec_list *out, const exec_list *in);
2428
2429 extern void
2430 _mesa_glsl_initialize_variables(exec_list *instructions,
2431 struct _mesa_glsl_parse_state *state);
2432
2433 extern void
2434 _mesa_glsl_initialize_functions(_mesa_glsl_parse_state *state);
2435
2436 extern void
2437 _mesa_glsl_initialize_builtin_functions();
2438
2439 extern ir_function_signature *
2440 _mesa_glsl_find_builtin_function(_mesa_glsl_parse_state *state,
2441 const char *name, exec_list *actual_parameters);
2442
2443 extern ir_function *
2444 _mesa_glsl_find_builtin_function_by_name(_mesa_glsl_parse_state *state,
2445 const char *name);
2446
2447 extern gl_shader *
2448 _mesa_glsl_get_builtin_function_shader(void);
2449
2450 extern void
2451 _mesa_glsl_release_functions(void);
2452
2453 extern void
2454 _mesa_glsl_release_builtin_functions(void);
2455
2456 extern void
2457 reparent_ir(exec_list *list, void *mem_ctx);
2458
2459 struct glsl_symbol_table;
2460
2461 extern void
2462 import_prototypes(const exec_list *source, exec_list *dest,
2463 struct glsl_symbol_table *symbols, void *mem_ctx);
2464
2465 extern bool
2466 ir_has_call(ir_instruction *ir);
2467
2468 extern void
2469 do_set_program_inouts(exec_list *instructions, struct gl_program *prog,
2470 gl_shader_stage shader_stage);
2471
2472 extern char *
2473 prototype_string(const glsl_type *return_type, const char *name,
2474 exec_list *parameters);
2475
2476 const char *
2477 mode_string(const ir_variable *var);
2478
2479 /**
2480 * Built-in / reserved GL variables names start with "gl_"
2481 */
2482 static inline bool
2483 is_gl_identifier(const char *s)
2484 {
2485 return s && s[0] == 'g' && s[1] == 'l' && s[2] == '_';
2486 }
2487
2488 extern "C" {
2489 #endif /* __cplusplus */
2490
2491 extern void _mesa_print_ir(FILE *f, struct exec_list *instructions,
2492 struct _mesa_glsl_parse_state *state);
2493
2494 extern void
2495 fprint_ir(FILE *f, const void *instruction);
2496
2497 #ifdef __cplusplus
2498 } /* extern "C" */
2499 #endif
2500
2501 unsigned
2502 vertices_per_prim(GLenum prim);
2503
2504 #endif /* IR_H */