* DEALINGS IN THE SOFTWARE.
*/
#include <string.h>
-#include "main/core.h" /* for MAX2 */
#include "ir.h"
#include "compiler/glsl_types.h"
#include "glsl_parser_extras.h"
case ir_binop_equal:
case ir_binop_nequal:
- case ir_binop_lequal:
case ir_binop_gequal:
case ir_binop_less:
- case ir_binop_greater:
assert(op0->type == op1->type);
this->type = glsl_type::get_instance(GLSL_TYPE_BOOL,
op0->type->vector_elements, 1);
assert(type->is_scalar() || type->is_vector() || type->is_matrix()
|| type->is_record() || type->is_array());
- if (type->is_array()) {
+ /* If the constant is a record, the types of each of the entries in
+ * value_list must be a 1-for-1 match with the structure components. Each
+ * entry must also be a constant. Just move the nodes from the value_list
+ * to the list in the ir_constant.
+ */
+ if (type->is_array() || type->is_record()) {
this->const_elements = ralloc_array(this, ir_constant *, type->length);
unsigned i = 0;
foreach_in_list(ir_constant, value, value_list) {
return;
}
- /* If the constant is a record, the types of each of the entries in
- * value_list must be a 1-for-1 match with the structure components. Each
- * entry must also be a constant. Just move the nodes from the value_list
- * to the list in the ir_constant.
- */
- /* FINISHME: Should there be some type checking and / or assertions here? */
- /* FINISHME: Should the new constant take ownership of the nodes from
- * FINISHME: value_list, or should it make copies?
- */
- if (type->is_record()) {
- value_list->move_nodes_to(& this->components);
- return;
- }
-
for (unsigned i = 0; i < 16; i++) {
this->value.u[i] = 0;
}
for (unsigned i = 0; i < type->components(); i++)
this->value.b[i] = value->value.b[0];
break;
+ case GLSL_TYPE_SAMPLER:
+ case GLSL_TYPE_IMAGE:
+ this->value.u64[0] = value->value.u64[0];
+ break;
default:
assert(!"Should not get here.");
break;
}
if (type->is_record()) {
+ c->const_elements = ralloc_array(c, ir_constant *, type->length);
+
for (unsigned i = 0; i < type->length; i++) {
- ir_constant *comp = ir_constant::zero(mem_ctx, type->fields.structure[i].type);
- c->components.push_tail(comp);
+ c->const_elements[i] =
+ ir_constant::zero(mem_ctx, type->fields.structure[i].type);
}
}
case GLSL_TYPE_FLOAT: return ((int)this->value.f[i]) != 0;
case GLSL_TYPE_BOOL: return this->value.b[i];
case GLSL_TYPE_DOUBLE: return this->value.d[i] != 0.0;
+ case GLSL_TYPE_SAMPLER:
+ case GLSL_TYPE_IMAGE:
case GLSL_TYPE_UINT64: return this->value.u64[i] != 0;
case GLSL_TYPE_INT64: return this->value.i64[i] != 0;
default: assert(!"Should not get here."); break;
case GLSL_TYPE_FLOAT: return this->value.f[i];
case GLSL_TYPE_BOOL: return this->value.b[i] ? 1.0f : 0.0f;
case GLSL_TYPE_DOUBLE: return (float) this->value.d[i];
+ case GLSL_TYPE_SAMPLER:
+ case GLSL_TYPE_IMAGE:
case GLSL_TYPE_UINT64: return (float) this->value.u64[i];
case GLSL_TYPE_INT64: return (float) this->value.i64[i];
default: assert(!"Should not get here."); break;
case GLSL_TYPE_FLOAT: return (double) this->value.f[i];
case GLSL_TYPE_BOOL: return this->value.b[i] ? 1.0 : 0.0;
case GLSL_TYPE_DOUBLE: return this->value.d[i];
+ case GLSL_TYPE_SAMPLER:
+ case GLSL_TYPE_IMAGE:
case GLSL_TYPE_UINT64: return (double) this->value.u64[i];
case GLSL_TYPE_INT64: return (double) this->value.i64[i];
default: assert(!"Should not get here."); break;
case GLSL_TYPE_FLOAT: return (int) this->value.f[i];
case GLSL_TYPE_BOOL: return this->value.b[i] ? 1 : 0;
case GLSL_TYPE_DOUBLE: return (int) this->value.d[i];
+ case GLSL_TYPE_SAMPLER:
+ case GLSL_TYPE_IMAGE:
case GLSL_TYPE_UINT64: return (int) this->value.u64[i];
case GLSL_TYPE_INT64: return (int) this->value.i64[i];
default: assert(!"Should not get here."); break;
case GLSL_TYPE_FLOAT: return (unsigned) this->value.f[i];
case GLSL_TYPE_BOOL: return this->value.b[i] ? 1 : 0;
case GLSL_TYPE_DOUBLE: return (unsigned) this->value.d[i];
+ case GLSL_TYPE_SAMPLER:
+ case GLSL_TYPE_IMAGE:
case GLSL_TYPE_UINT64: return (unsigned) this->value.u64[i];
case GLSL_TYPE_INT64: return (unsigned) this->value.i64[i];
default: assert(!"Should not get here."); break;
case GLSL_TYPE_FLOAT: return (int64_t) this->value.f[i];
case GLSL_TYPE_BOOL: return this->value.b[i] ? 1 : 0;
case GLSL_TYPE_DOUBLE: return (int64_t) this->value.d[i];
+ case GLSL_TYPE_SAMPLER:
+ case GLSL_TYPE_IMAGE:
case GLSL_TYPE_UINT64: return (int64_t) this->value.u64[i];
case GLSL_TYPE_INT64: return this->value.i64[i];
default: assert(!"Should not get here."); break;
case GLSL_TYPE_FLOAT: return (uint64_t) this->value.f[i];
case GLSL_TYPE_BOOL: return this->value.b[i] ? 1 : 0;
case GLSL_TYPE_DOUBLE: return (uint64_t) this->value.d[i];
+ case GLSL_TYPE_SAMPLER:
+ case GLSL_TYPE_IMAGE:
case GLSL_TYPE_UINT64: return this->value.u64[i];
case GLSL_TYPE_INT64: return (uint64_t) this->value.i64[i];
default: assert(!"Should not get here."); break;
ir_constant *
ir_constant::get_record_field(int idx)
{
- if (idx < 0)
- return NULL;
-
- if (this->components.is_empty())
- return NULL;
-
- exec_node *node = this->components.get_head_raw();
- for (int i = 0; i < idx; i++) {
- node = node->next;
-
- /* If the end of the list is encountered before the element matching the
- * requested field is found, return NULL.
- */
- if (node->is_tail_sentinel())
- return NULL;
- }
+ assert(this->type->is_record());
+ assert(idx >= 0 && (unsigned) idx < this->type->length);
- return (ir_constant *) node;
+ return const_elements[idx];
}
void
case GLSL_TYPE_INT:
case GLSL_TYPE_FLOAT:
case GLSL_TYPE_DOUBLE:
+ case GLSL_TYPE_SAMPLER:
+ case GLSL_TYPE_IMAGE:
case GLSL_TYPE_UINT64:
case GLSL_TYPE_INT64:
case GLSL_TYPE_BOOL: {
case GLSL_TYPE_DOUBLE:
value.d[i+offset] = src->get_double_component(i);
break;
- case GLSL_TYPE_UINT64:
+ case GLSL_TYPE_SAMPLER:
+ case GLSL_TYPE_IMAGE:
+ case GLSL_TYPE_UINT64:
value.u64[i+offset] = src->get_uint64_component(i);
break;
case GLSL_TYPE_INT64:
break;
}
- case GLSL_TYPE_STRUCT: {
- assert (src->type == this->type);
- this->components.make_empty();
- foreach_in_list(ir_constant, orig, &src->components) {
- this->components.push_tail(orig->clone(this, NULL));
- }
- break;
- }
-
+ case GLSL_TYPE_STRUCT:
case GLSL_TYPE_ARRAY: {
assert (src->type == this->type);
for (unsigned i = 0; i < this->type->length; i++) {
case GLSL_TYPE_DOUBLE:
value.d[i+offset] = src->get_double_component(id++);
break;
- case GLSL_TYPE_UINT64:
+ case GLSL_TYPE_SAMPLER:
+ case GLSL_TYPE_IMAGE:
+ case GLSL_TYPE_UINT64:
value.u64[i+offset] = src->get_uint64_component(id++);
break;
case GLSL_TYPE_INT64:
if (this->type != c->type)
return false;
- if (this->type->is_array()) {
+ if (this->type->is_array() || this->type->is_record()) {
for (unsigned i = 0; i < this->type->length; i++) {
if (!this->const_elements[i]->has_value(c->const_elements[i]))
return false;
return true;
}
- if (this->type->is_record()) {
- const exec_node *a_node = this->components.get_head_raw();
- const exec_node *b_node = c->components.get_head_raw();
-
- while (!a_node->is_tail_sentinel()) {
- assert(!b_node->is_tail_sentinel());
-
- const ir_constant *const a_field = (ir_constant *) a_node;
- const ir_constant *const b_field = (ir_constant *) b_node;
-
- if (!a_field->has_value(b_field))
- return false;
-
- a_node = a_node->next;
- b_node = b_node->next;
- }
-
- return true;
- }
-
for (unsigned i = 0; i < this->type->components(); i++) {
switch (this->type->base_type) {
case GLSL_TYPE_UINT:
if (this->value.d[i] != c->value.d[i])
return false;
break;
+ case GLSL_TYPE_SAMPLER:
+ case GLSL_TYPE_IMAGE:
case GLSL_TYPE_UINT64:
if (this->value.u64[i] != c->value.u64[i])
return false;
if (this->value.d[c] != double(f))
return false;
break;
+ case GLSL_TYPE_SAMPLER:
+ case GLSL_TYPE_IMAGE:
case GLSL_TYPE_UINT64:
if (this->value.u64[c] != uint64_t(i))
return false;
this->data.centroid = false;
this->data.sample = false;
this->data.patch = false;
+ this->data.explicit_invariant = false;
this->data.invariant = false;
this->data.how_declared = ir_var_declared_normally;
this->data.mode = mode;
/* The components of aggregate constants are not visited by the normal
* visitor, so steal their values by hand.
*/
- if (constant != NULL) {
- if (constant->type->is_record()) {
- foreach_in_list(ir_constant, field, &constant->components) {
- steal_memory(field, ir);
- }
- } else if (constant->type->is_array()) {
- for (unsigned int i = 0; i < constant->type->length; i++) {
- steal_memory(constant->const_elements[i], ir);
- }
+ if (constant != NULL &&
+ (constant->type->is_array() || constant->type->is_record())) {
+ for (unsigned int i = 0; i < constant->type->length; i++) {
+ steal_memory(constant->const_elements[i], ir);
}
}