2 * Copyright © 2010 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
25 * \file ir_constant_expression.cpp
26 * Evaluate and process constant valued expressions
28 * In GLSL, constant valued expressions are used in several places. These
29 * must be processed and evaluated very early in the compilation process.
32 * * Initializers for uniforms
33 * * Initializers for \c const variables
37 #include "util/rounding.h" /* for _mesa_roundeven */
38 #include "util/half_float.h"
40 #include "compiler/glsl_types.h"
41 #include "util/hash_table.h"
42 #include "util/u_math.h"
45 dot_f(ir_constant
*op0
, ir_constant
*op1
)
47 assert(op0
->type
->is_float() && op1
->type
->is_float());
50 for (unsigned c
= 0; c
< op0
->type
->components(); c
++)
51 result
+= op0
->value
.f
[c
] * op1
->value
.f
[c
];
57 dot_d(ir_constant
*op0
, ir_constant
*op1
)
59 assert(op0
->type
->is_double() && op1
->type
->is_double());
62 for (unsigned c
= 0; c
< op0
->type
->components(); c
++)
63 result
+= op0
->value
.d
[c
] * op1
->value
.d
[c
];
68 /* This method is the only one supported by gcc. Unions in particular
69 * are iffy, and read-through-converted-pointer is killed by strict
70 * aliasing. OTOH, the compiler sees through the memcpy, so the
71 * resulting asm is reasonable.
74 bitcast_u2f(unsigned int u
)
76 assert(sizeof(float) == sizeof(unsigned int));
78 memcpy(&f
, &u
, sizeof(f
));
85 assert(sizeof(float) == sizeof(unsigned int));
87 memcpy(&u
, &f
, sizeof(f
));
92 bitcast_u642d(uint64_t u
)
94 assert(sizeof(double) == sizeof(uint64_t));
96 memcpy(&d
, &u
, sizeof(d
));
101 bitcast_i642d(int64_t i
)
103 assert(sizeof(double) == sizeof(int64_t));
105 memcpy(&d
, &i
, sizeof(d
));
110 bitcast_d2u64(double d
)
112 assert(sizeof(double) == sizeof(uint64_t));
114 memcpy(&u
, &d
, sizeof(d
));
119 bitcast_d2i64(double d
)
121 assert(sizeof(double) == sizeof(int64_t));
123 memcpy(&i
, &d
, sizeof(d
));
128 * Evaluate one component of a floating-point 4x8 unpacking function.
131 (*pack_1x8_func_t
)(float);
134 * Evaluate one component of a floating-point 2x16 unpacking function.
137 (*pack_1x16_func_t
)(float);
140 * Evaluate one component of a floating-point 4x8 unpacking function.
143 (*unpack_1x8_func_t
)(uint8_t);
146 * Evaluate one component of a floating-point 2x16 unpacking function.
149 (*unpack_1x16_func_t
)(uint16_t);
152 * Evaluate a 2x16 floating-point packing function.
155 pack_2x16(pack_1x16_func_t pack_1x16
,
158 /* From section 8.4 of the GLSL ES 3.00 spec:
162 * The first component of the vector will be written to the least
163 * significant bits of the output; the last component will be written to
164 * the most significant bits.
166 * The specifications for the other packing functions contain similar
170 u
|= ((uint32_t) pack_1x16(x
) << 0);
171 u
|= ((uint32_t) pack_1x16(y
) << 16);
176 * Evaluate a 4x8 floating-point packing function.
179 pack_4x8(pack_1x8_func_t pack_1x8
,
180 float x
, float y
, float z
, float w
)
182 /* From section 8.4 of the GLSL 4.30 spec:
186 * The first component of the vector will be written to the least
187 * significant bits of the output; the last component will be written to
188 * the most significant bits.
190 * The specifications for the other packing functions contain similar
194 u
|= ((uint32_t) pack_1x8(x
) << 0);
195 u
|= ((uint32_t) pack_1x8(y
) << 8);
196 u
|= ((uint32_t) pack_1x8(z
) << 16);
197 u
|= ((uint32_t) pack_1x8(w
) << 24);
202 * Evaluate a 2x16 floating-point unpacking function.
205 unpack_2x16(unpack_1x16_func_t unpack_1x16
,
209 /* From section 8.4 of the GLSL ES 3.00 spec:
213 * The first component of the returned vector will be extracted from
214 * the least significant bits of the input; the last component will be
215 * extracted from the most significant bits.
217 * The specifications for the other unpacking functions contain similar
220 *x
= unpack_1x16((uint16_t) (u
& 0xffff));
221 *y
= unpack_1x16((uint16_t) (u
>> 16));
225 * Evaluate a 4x8 floating-point unpacking function.
228 unpack_4x8(unpack_1x8_func_t unpack_1x8
, uint32_t u
,
229 float *x
, float *y
, float *z
, float *w
)
231 /* From section 8.4 of the GLSL 4.30 spec:
235 * The first component of the returned vector will be extracted from
236 * the least significant bits of the input; the last component will be
237 * extracted from the most significant bits.
239 * The specifications for the other unpacking functions contain similar
242 *x
= unpack_1x8((uint8_t) (u
& 0xff));
243 *y
= unpack_1x8((uint8_t) (u
>> 8));
244 *z
= unpack_1x8((uint8_t) (u
>> 16));
245 *w
= unpack_1x8((uint8_t) (u
>> 24));
249 * Evaluate one component of packSnorm4x8.
252 pack_snorm_1x8(float x
)
254 /* From section 8.4 of the GLSL 4.30 spec:
258 * The conversion for component c of v to fixed point is done as
261 * packSnorm4x8: round(clamp(c, -1, +1) * 127.0)
264 _mesa_lroundevenf(CLAMP(x
, -1.0f
, +1.0f
) * 127.0f
);
268 * Evaluate one component of packSnorm2x16.
271 pack_snorm_1x16(float x
)
273 /* From section 8.4 of the GLSL ES 3.00 spec:
277 * The conversion for component c of v to fixed point is done as
280 * packSnorm2x16: round(clamp(c, -1, +1) * 32767.0)
283 _mesa_lroundevenf(CLAMP(x
, -1.0f
, +1.0f
) * 32767.0f
);
287 * Evaluate one component of unpackSnorm4x8.
290 unpack_snorm_1x8(uint8_t u
)
292 /* From section 8.4 of the GLSL 4.30 spec:
296 * The conversion for unpacked fixed-point value f to floating point is
299 * unpackSnorm4x8: clamp(f / 127.0, -1, +1)
301 return CLAMP((int8_t) u
/ 127.0f
, -1.0f
, +1.0f
);
305 * Evaluate one component of unpackSnorm2x16.
308 unpack_snorm_1x16(uint16_t u
)
310 /* From section 8.4 of the GLSL ES 3.00 spec:
314 * The conversion for unpacked fixed-point value f to floating point is
317 * unpackSnorm2x16: clamp(f / 32767.0, -1, +1)
319 return CLAMP((int16_t) u
/ 32767.0f
, -1.0f
, +1.0f
);
323 * Evaluate one component packUnorm4x8.
326 pack_unorm_1x8(float x
)
328 /* From section 8.4 of the GLSL 4.30 spec:
332 * The conversion for component c of v to fixed point is done as
335 * packUnorm4x8: round(clamp(c, 0, +1) * 255.0)
337 return (uint8_t) (int) _mesa_roundevenf(CLAMP(x
, 0.0f
, 1.0f
) * 255.0f
);
341 * Evaluate one component packUnorm2x16.
344 pack_unorm_1x16(float x
)
346 /* From section 8.4 of the GLSL ES 3.00 spec:
350 * The conversion for component c of v to fixed point is done as
353 * packUnorm2x16: round(clamp(c, 0, +1) * 65535.0)
355 return (uint16_t) (int)
356 _mesa_roundevenf(CLAMP(x
, 0.0f
, 1.0f
) * 65535.0f
);
360 * Evaluate one component of unpackUnorm4x8.
363 unpack_unorm_1x8(uint8_t u
)
365 /* From section 8.4 of the GLSL 4.30 spec:
369 * The conversion for unpacked fixed-point value f to floating point is
372 * unpackUnorm4x8: f / 255.0
374 return (float) u
/ 255.0f
;
378 * Evaluate one component of unpackUnorm2x16.
381 unpack_unorm_1x16(uint16_t u
)
383 /* From section 8.4 of the GLSL ES 3.00 spec:
387 * The conversion for unpacked fixed-point value f to floating point is
390 * unpackUnorm2x16: f / 65535.0
392 return (float) u
/ 65535.0f
;
396 * Evaluate one component of packHalf2x16.
399 pack_half_1x16(float x
)
401 return _mesa_float_to_half(x
);
405 * Evaluate one component of unpackHalf2x16.
408 unpack_half_1x16(uint16_t u
)
410 return _mesa_half_to_float(u
);
414 * Get the constant that is ultimately referenced by an r-value, in a constant
415 * expression evaluation context.
417 * The offset is used when the reference is to a specific column of a matrix.
420 constant_referenced(const ir_dereference
*deref
,
421 struct hash_table
*variable_context
,
422 ir_constant
*&store
, int &offset
)
427 if (variable_context
== NULL
)
430 switch (deref
->ir_type
) {
431 case ir_type_dereference_array
: {
432 const ir_dereference_array
*const da
=
433 (const ir_dereference_array
*) deref
;
435 ir_constant
*const index_c
=
436 da
->array_index
->constant_expression_value(variable_context
);
438 if (!index_c
|| !index_c
->type
->is_scalar() ||
439 !index_c
->type
->is_integer_32())
442 const int index
= index_c
->type
->base_type
== GLSL_TYPE_INT
?
443 index_c
->get_int_component(0) :
444 index_c
->get_uint_component(0);
446 ir_constant
*substore
;
449 const ir_dereference
*const deref
= da
->array
->as_dereference();
453 if (!constant_referenced(deref
, variable_context
, substore
, suboffset
))
456 const glsl_type
*const vt
= da
->array
->type
;
457 if (vt
->is_array()) {
458 store
= substore
->get_array_element(index
);
460 } else if (vt
->is_matrix()) {
462 offset
= index
* vt
->vector_elements
;
463 } else if (vt
->is_vector()) {
465 offset
= suboffset
+ index
;
471 case ir_type_dereference_record
: {
472 const ir_dereference_record
*const dr
=
473 (const ir_dereference_record
*) deref
;
475 const ir_dereference
*const deref
= dr
->record
->as_dereference();
479 ir_constant
*substore
;
482 if (!constant_referenced(deref
, variable_context
, substore
, suboffset
))
485 /* Since we're dropping it on the floor...
487 assert(suboffset
== 0);
489 store
= substore
->get_record_field(dr
->field_idx
);
493 case ir_type_dereference_variable
: {
494 const ir_dereference_variable
*const dv
=
495 (const ir_dereference_variable
*) deref
;
497 hash_entry
*entry
= _mesa_hash_table_search(variable_context
, dv
->var
);
499 store
= (ir_constant
*) entry
->data
;
504 assert(!"Should not get here.");
508 return store
!= NULL
;
513 ir_rvalue::constant_expression_value(void *, struct hash_table
*)
515 assert(this->type
->is_error());
520 bitfield_reverse(uint32_t v
)
522 /* http://graphics.stanford.edu/~seander/bithacks.html#BitReverseObvious */
523 uint32_t r
= v
; // r will be reversed bits of v; first get LSB of v
524 int s
= sizeof(v
) * CHAR_BIT
- 1; // extra shift needed at end
526 for (v
>>= 1; v
; v
>>= 1) {
531 r
<<= s
; // shift when v's highest bits are zero
537 find_msb_uint(uint32_t v
)
541 /* If v == 0, then the loop will terminate when count == 32. In that case
542 * 31-count will produce the -1 result required by GLSL findMSB().
544 while (((v
& (1u << 31)) == 0) && count
!= 32) {
553 find_msb_int(int32_t v
)
555 /* If v is signed, findMSB() returns the position of the most significant
558 return find_msb_uint(v
< 0 ? ~v
: v
);
562 ldexpf_flush_subnormal(float x
, int exp
)
564 const float result
= ldexpf(x
, exp
);
566 /* Flush subnormal values to zero. */
567 return !isnormal(result
) ? copysignf(0.0f
, x
) : result
;
571 ldexp_flush_subnormal(double x
, int exp
)
573 const double result
= ldexp(x
, exp
);
575 /* Flush subnormal values to zero. */
576 return !isnormal(result
) ? copysign(0.0, x
) : result
;
580 bitfield_extract_uint(uint32_t value
, int offset
, int bits
)
584 else if (offset
< 0 || bits
< 0)
585 return 0; /* Undefined, per spec. */
586 else if (offset
+ bits
> 32)
587 return 0; /* Undefined, per spec. */
589 value
<<= 32 - bits
- offset
;
596 bitfield_extract_int(int32_t value
, int offset
, int bits
)
600 else if (offset
< 0 || bits
< 0)
601 return 0; /* Undefined, per spec. */
602 else if (offset
+ bits
> 32)
603 return 0; /* Undefined, per spec. */
605 value
<<= 32 - bits
- offset
;
612 bitfield_insert(uint32_t base
, uint32_t insert
, int offset
, int bits
)
616 else if (offset
< 0 || bits
< 0)
617 return 0; /* Undefined, per spec. */
618 else if (offset
+ bits
> 32)
619 return 0; /* Undefined, per spec. */
621 unsigned insert_mask
= ((1ull << bits
) - 1) << offset
;
624 insert
&= insert_mask
;
625 base
&= ~insert_mask
;
627 return base
| insert
;
632 ir_expression::constant_expression_value(void *mem_ctx
,
633 struct hash_table
*variable_context
)
637 if (this->type
->is_error())
640 ir_constant
*op
[ARRAY_SIZE(this->operands
)] = { NULL
, };
641 ir_constant_data data
;
643 memset(&data
, 0, sizeof(data
));
645 for (unsigned operand
= 0; operand
< this->num_operands
; operand
++) {
647 this->operands
[operand
]->constant_expression_value(mem_ctx
,
654 switch (this->operation
) {
655 case ir_binop_lshift
:
656 case ir_binop_rshift
:
658 case ir_binop_interpolate_at_offset
:
659 case ir_binop_interpolate_at_sample
:
660 case ir_binop_vector_extract
:
662 case ir_triop_bitfield_extract
:
666 assert(op
[0]->type
->base_type
== op
[1]->type
->base_type
);
670 bool op0_scalar
= op
[0]->type
->is_scalar();
671 bool op1_scalar
= op
[1] != NULL
&& op
[1]->type
->is_scalar();
673 /* When iterating over a vector or matrix's components, we want to increase
674 * the loop counter. However, for scalars, we want to stay at 0.
676 unsigned c0_inc
= op0_scalar
? 0 : 1;
677 unsigned c1_inc
= op1_scalar
? 0 : 1;
679 if (op1_scalar
|| !op
[1]) {
680 components
= op
[0]->type
->components();
682 components
= op
[1]->type
->components();
685 /* Handle array operations here, rather than below. */
686 if (op
[0]->type
->is_array()) {
687 assert(op
[1] != NULL
&& op
[1]->type
->is_array());
688 switch (this->operation
) {
689 case ir_binop_all_equal
:
690 return new(mem_ctx
) ir_constant(op
[0]->has_value(op
[1]));
691 case ir_binop_any_nequal
:
692 return new(mem_ctx
) ir_constant(!op
[0]->has_value(op
[1]));
699 #include "ir_expression_operation_constant.h"
701 return new(mem_ctx
) ir_constant(this->type
, &data
);
706 ir_texture::constant_expression_value(void *, struct hash_table
*)
708 /* texture lookups aren't constant expressions */
714 ir_swizzle::constant_expression_value(void *mem_ctx
,
715 struct hash_table
*variable_context
)
719 ir_constant
*v
= this->val
->constant_expression_value(mem_ctx
,
723 ir_constant_data data
= { { 0 } };
725 const unsigned swiz_idx
[4] = {
726 this->mask
.x
, this->mask
.y
, this->mask
.z
, this->mask
.w
729 for (unsigned i
= 0; i
< this->mask
.num_components
; i
++) {
730 switch (v
->type
->base_type
) {
732 case GLSL_TYPE_INT
: data
.u
[i
] = v
->value
.u
[swiz_idx
[i
]]; break;
733 case GLSL_TYPE_FLOAT
: data
.f
[i
] = v
->value
.f
[swiz_idx
[i
]]; break;
734 case GLSL_TYPE_BOOL
: data
.b
[i
] = v
->value
.b
[swiz_idx
[i
]]; break;
735 case GLSL_TYPE_DOUBLE
:data
.d
[i
] = v
->value
.d
[swiz_idx
[i
]]; break;
736 case GLSL_TYPE_UINT64
:data
.u64
[i
] = v
->value
.u64
[swiz_idx
[i
]]; break;
737 case GLSL_TYPE_INT64
: data
.i64
[i
] = v
->value
.i64
[swiz_idx
[i
]]; break;
738 default: assert(!"Should not get here."); break;
742 return new(mem_ctx
) ir_constant(this->type
, &data
);
749 ir_dereference_variable::constant_expression_value(void *mem_ctx
,
750 struct hash_table
*variable_context
)
755 /* Give priority to the context hashtable, if it exists */
756 if (variable_context
) {
757 hash_entry
*entry
= _mesa_hash_table_search(variable_context
, var
);
760 return (ir_constant
*) entry
->data
;
763 /* The constant_value of a uniform variable is its initializer,
764 * not the lifetime constant value of the uniform.
766 if (var
->data
.mode
== ir_var_uniform
)
769 if (!var
->constant_value
)
772 return var
->constant_value
->clone(mem_ctx
, NULL
);
777 ir_dereference_array::constant_expression_value(void *mem_ctx
,
778 struct hash_table
*variable_context
)
782 ir_constant
*array
= this->array
->constant_expression_value(mem_ctx
, variable_context
);
783 ir_constant
*idx
= this->array_index
->constant_expression_value(mem_ctx
, variable_context
);
785 if ((array
!= NULL
) && (idx
!= NULL
)) {
786 if (array
->type
->is_matrix()) {
787 /* Array access of a matrix results in a vector.
789 const unsigned column
= idx
->value
.u
[0];
791 const glsl_type
*const column_type
= array
->type
->column_type();
793 /* Offset in the constant matrix to the first element of the column
796 const unsigned mat_idx
= column
* column_type
->vector_elements
;
798 ir_constant_data data
= { { 0 } };
800 switch (column_type
->base_type
) {
803 for (unsigned i
= 0; i
< column_type
->vector_elements
; i
++)
804 data
.u
[i
] = array
->value
.u
[mat_idx
+ i
];
808 case GLSL_TYPE_FLOAT
:
809 for (unsigned i
= 0; i
< column_type
->vector_elements
; i
++)
810 data
.f
[i
] = array
->value
.f
[mat_idx
+ i
];
814 case GLSL_TYPE_DOUBLE
:
815 for (unsigned i
= 0; i
< column_type
->vector_elements
; i
++)
816 data
.d
[i
] = array
->value
.d
[mat_idx
+ i
];
821 assert(!"Should not get here.");
825 return new(mem_ctx
) ir_constant(column_type
, &data
);
826 } else if (array
->type
->is_vector()) {
827 const unsigned component
= idx
->value
.u
[0];
829 return new(mem_ctx
) ir_constant(array
, component
);
830 } else if (array
->type
->is_array()) {
831 const unsigned index
= idx
->value
.u
[0];
832 return array
->get_array_element(index
)->clone(mem_ctx
, NULL
);
840 ir_dereference_record::constant_expression_value(void *mem_ctx
,
845 ir_constant
*v
= this->record
->constant_expression_value(mem_ctx
);
847 return (v
!= NULL
) ? v
->get_record_field(this->field_idx
) : NULL
;
852 ir_assignment::constant_expression_value(void *, struct hash_table
*)
854 /* FINISHME: Handle CEs involving assignment (return RHS) */
860 ir_constant::constant_expression_value(void *, struct hash_table
*)
867 ir_call::constant_expression_value(void *mem_ctx
, struct hash_table
*variable_context
)
871 return this->callee
->constant_expression_value(mem_ctx
,
872 &this->actual_parameters
,
877 bool ir_function_signature::constant_expression_evaluate_expression_list(void *mem_ctx
,
878 const struct exec_list
&body
,
879 struct hash_table
*variable_context
,
880 ir_constant
**result
)
884 foreach_in_list(ir_instruction
, inst
, &body
) {
885 switch(inst
->ir_type
) {
887 /* (declare () type symbol) */
888 case ir_type_variable
: {
889 ir_variable
*var
= inst
->as_variable();
890 _mesa_hash_table_insert(variable_context
, var
, ir_constant::zero(this, var
->type
));
894 /* (assign [condition] (write-mask) (ref) (value)) */
895 case ir_type_assignment
: {
896 ir_assignment
*asg
= inst
->as_assignment();
897 if (asg
->condition
) {
899 asg
->condition
->constant_expression_value(mem_ctx
,
903 if (!cond
->get_bool_component(0))
907 ir_constant
*store
= NULL
;
910 if (!constant_referenced(asg
->lhs
, variable_context
, store
, offset
))
914 asg
->rhs
->constant_expression_value(mem_ctx
, variable_context
);
919 store
->copy_masked_offset(value
, offset
, asg
->write_mask
);
923 /* (return (expression)) */
927 inst
->as_return()->value
->constant_expression_value(mem_ctx
,
929 return *result
!= NULL
;
931 /* (call name (ref) (params))*/
933 ir_call
*call
= inst
->as_call();
935 /* Just say no to void functions in constant expressions. We
936 * don't need them at that point.
939 if (!call
->return_deref
)
942 ir_constant
*store
= NULL
;
945 if (!constant_referenced(call
->return_deref
, variable_context
,
950 call
->constant_expression_value(mem_ctx
, variable_context
);
955 store
->copy_offset(value
, offset
);
959 /* (if condition (then-instructions) (else-instructions)) */
961 ir_if
*iif
= inst
->as_if();
964 iif
->condition
->constant_expression_value(mem_ctx
,
966 if (!cond
|| !cond
->type
->is_boolean())
969 exec_list
&branch
= cond
->get_bool_component(0) ? iif
->then_instructions
: iif
->else_instructions
;
972 if (!constant_expression_evaluate_expression_list(mem_ctx
, branch
,
977 /* If there was a return in the branch chosen, drop out now. */
984 /* Every other expression type, we drop out. */
990 /* Reaching the end of the block is not an error condition */
998 ir_function_signature::constant_expression_value(void *mem_ctx
,
999 exec_list
*actual_parameters
,
1000 struct hash_table
*variable_context
)
1004 const glsl_type
*type
= this->return_type
;
1005 if (type
== glsl_type::void_type
)
1008 /* From the GLSL 1.20 spec, page 23:
1009 * "Function calls to user-defined functions (non-built-in functions)
1010 * cannot be used to form constant expressions."
1012 if (!this->is_builtin())
1016 * Of the builtin functions, only the texture lookups and the noise
1017 * ones must not be used in constant expressions. They all include
1018 * specific opcodes so they don't need to be special-cased at this
1022 /* Initialize the table of dereferencable names with the function
1023 * parameters. Verify their const-ness on the way.
1025 * We expect the correctness of the number of parameters to have
1026 * been checked earlier.
1028 hash_table
*deref_hash
= _mesa_pointer_hash_table_create(NULL
);
1030 /* If "origin" is non-NULL, then the function body is there. So we
1031 * have to use the variable objects from the object with the body,
1032 * but the parameter instanciation on the current object.
1034 const exec_node
*parameter_info
= origin
? origin
->parameters
.get_head_raw() : parameters
.get_head_raw();
1036 foreach_in_list(ir_rvalue
, n
, actual_parameters
) {
1037 ir_constant
*constant
=
1038 n
->constant_expression_value(mem_ctx
, variable_context
);
1039 if (constant
== NULL
) {
1040 _mesa_hash_table_destroy(deref_hash
, NULL
);
1045 ir_variable
*var
= (ir_variable
*)parameter_info
;
1046 _mesa_hash_table_insert(deref_hash
, var
, constant
);
1048 parameter_info
= parameter_info
->next
;
1051 ir_constant
*result
= NULL
;
1053 /* Now run the builtin function until something non-constant
1054 * happens or we get the result.
1056 if (constant_expression_evaluate_expression_list(mem_ctx
, origin
? origin
->body
: body
, deref_hash
, &result
) &&
1058 result
= result
->clone(mem_ctx
, NULL
);
1060 _mesa_hash_table_destroy(deref_hash
, NULL
);