From 29285882676388aacff123e8bdf025904abf8ea9 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Thu, 24 Jun 2010 15:32:15 -0700 Subject: glsl2: Move the compiler to the subdirectory it will live in in Mesa. --- src/glsl/ir_constant_expression.cpp | 671 ++++++++++++++++++++++++++++++++++++ 1 file changed, 671 insertions(+) create mode 100644 src/glsl/ir_constant_expression.cpp (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp new file mode 100644 index 0000000000..3408f5256a --- /dev/null +++ b/src/glsl/ir_constant_expression.cpp @@ -0,0 +1,671 @@ +/* + * Copyright © 2010 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +/** + * \file ir_constant_expression.cpp + * Evaluate and process constant valued expressions + * + * In GLSL, constant valued expressions are used in several places. These + * must be processed and evaluated very early in the compilation process. + * + * * Sizes of arrays + * * Initializers for uniforms + * * Initializers for \c const variables + */ + +#include +#include "ir.h" +#include "ir_visitor.h" +#include "glsl_types.h" + +/** + * Visitor class for evaluating constant expressions + */ +class ir_constant_visitor : public ir_visitor { +public: + ir_constant_visitor() + : value(NULL) + { + /* empty */ + } + + virtual ~ir_constant_visitor() + { + /* empty */ + } + + /** + * \name Visit methods + * + * As typical for the visitor pattern, there must be one \c visit method for + * each concrete subclass of \c ir_instruction. Virtual base classes within + * the hierarchy should not have \c visit methods. + */ + /*@{*/ + virtual void visit(ir_variable *); + virtual void visit(ir_function_signature *); + virtual void visit(ir_function *); + virtual void visit(ir_expression *); + virtual void visit(ir_texture *); + virtual void visit(ir_swizzle *); + virtual void visit(ir_dereference_variable *); + virtual void visit(ir_dereference_array *); + virtual void visit(ir_dereference_record *); + virtual void visit(ir_assignment *); + virtual void visit(ir_constant *); + virtual void visit(ir_call *); + virtual void visit(ir_return *); + virtual void visit(ir_if *); + virtual void visit(ir_loop *); + virtual void visit(ir_loop_jump *); + /*@}*/ + + /** + * Value of the constant expression. + * + * \note + * This field will be \c NULL if the expression is not constant valued. + */ + /* FINIHSME: This cannot hold values for constant arrays or structures. */ + ir_constant *value; +}; + + +ir_constant * +ir_instruction::constant_expression_value() +{ + ir_constant_visitor visitor; + + this->accept(& visitor); + return visitor.value; +} + + +void +ir_constant_visitor::visit(ir_variable *ir) +{ + (void) ir; + value = NULL; +} + + +void +ir_constant_visitor::visit(ir_function_signature *ir) +{ + (void) ir; + value = NULL; +} + + +void +ir_constant_visitor::visit(ir_function *ir) +{ + (void) ir; + value = NULL; +} + +void +ir_constant_visitor::visit(ir_expression *ir) +{ + value = NULL; + ir_constant *op[2]; + unsigned int operand, c; + ir_constant_data data; + + for (operand = 0; operand < ir->get_num_operands(); operand++) { + op[operand] = ir->operands[operand]->constant_expression_value(); + if (!op[operand]) + return; + } + + switch (ir->operation) { + case ir_unop_logic_not: + assert(op[0]->type->base_type == GLSL_TYPE_BOOL); + for (c = 0; c < ir->operands[0]->type->components(); c++) + data.b[c] = !op[0]->value.b[c]; + break; + + case ir_unop_f2i: + assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); + for (c = 0; c < ir->operands[0]->type->components(); c++) { + data.i[c] = op[0]->value.f[c]; + } + break; + case ir_unop_i2f: + assert(op[0]->type->base_type == GLSL_TYPE_UINT || + op[0]->type->base_type == GLSL_TYPE_INT); + for (c = 0; c < ir->operands[0]->type->components(); c++) { + if (op[0]->type->base_type == GLSL_TYPE_INT) + data.f[c] = op[0]->value.i[c]; + else + data.f[c] = op[0]->value.u[c]; + } + break; + case ir_unop_b2f: + assert(op[0]->type->base_type == GLSL_TYPE_BOOL); + for (c = 0; c < ir->operands[0]->type->components(); c++) { + data.f[c] = op[0]->value.b[c] ? 1.0 : 0.0; + } + break; + case ir_unop_f2b: + assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); + for (c = 0; c < ir->operands[0]->type->components(); c++) { + data.b[c] = bool(op[0]->value.f[c]); + } + break; + case ir_unop_b2i: + assert(op[0]->type->base_type == GLSL_TYPE_BOOL); + for (c = 0; c < ir->operands[0]->type->components(); c++) { + data.u[c] = op[0]->value.b[c] ? 1 : 0; + } + break; + case ir_unop_i2b: + assert(op[0]->type->is_integer()); + for (c = 0; c < ir->operands[0]->type->components(); c++) { + data.b[c] = bool(op[0]->value.u[c]); + } + break; + + case ir_unop_neg: + for (c = 0; c < ir->operands[0]->type->components(); c++) { + switch (ir->type->base_type) { + case GLSL_TYPE_UINT: + data.u[c] = -op[0]->value.u[c]; + break; + case GLSL_TYPE_INT: + data.i[c] = -op[0]->value.i[c]; + break; + case GLSL_TYPE_FLOAT: + data.f[c] = -op[0]->value.f[c]; + break; + default: + assert(0); + } + } + break; + + case ir_unop_abs: + assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); + for (c = 0; c < ir->operands[0]->type->components(); c++) { + switch (ir->type->base_type) { + case GLSL_TYPE_UINT: + data.u[c] = op[0]->value.u[c]; + break; + case GLSL_TYPE_INT: + data.i[c] = op[0]->value.i[c]; + if (data.i[c] < 0) + data.i[c] = -data.i[c]; + break; + case GLSL_TYPE_FLOAT: + data.f[c] = fabs(op[0]->value.f[c]); + break; + default: + assert(0); + } + } + break; + + case ir_unop_rcp: + assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); + for (c = 0; c < ir->operands[0]->type->components(); c++) { + switch (ir->type->base_type) { + case GLSL_TYPE_UINT: + if (op[0]->value.u[c] != 0.0) + data.u[c] = 1 / op[0]->value.u[c]; + break; + case GLSL_TYPE_INT: + if (op[0]->value.i[c] != 0.0) + data.i[c] = 1 / op[0]->value.i[c]; + break; + case GLSL_TYPE_FLOAT: + if (op[0]->value.f[c] != 0.0) + data.f[c] = 1.0 / op[0]->value.f[c]; + break; + default: + assert(0); + } + } + break; + + case ir_unop_rsq: + assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); + for (c = 0; c < ir->operands[0]->type->components(); c++) { + data.f[c] = 1.0 / sqrtf(op[0]->value.f[c]); + } + break; + + case ir_unop_sqrt: + assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); + for (c = 0; c < ir->operands[0]->type->components(); c++) { + data.f[c] = sqrtf(op[0]->value.f[c]); + } + break; + + case ir_unop_exp: + assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); + for (c = 0; c < ir->operands[0]->type->components(); c++) { + data.f[c] = expf(op[0]->value.f[c]); + } + break; + + case ir_unop_log: + assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); + for (c = 0; c < ir->operands[0]->type->components(); c++) { + data.f[c] = logf(op[0]->value.f[c]); + } + break; + + case ir_unop_dFdx: + case ir_unop_dFdy: + assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); + for (c = 0; c < ir->operands[0]->type->components(); c++) { + data.f[c] = 0.0; + } + break; + + case ir_binop_add: + if (ir->operands[0]->type == ir->operands[1]->type) { + for (c = 0; c < ir->operands[0]->type->components(); c++) { + switch (ir->operands[0]->type->base_type) { + case GLSL_TYPE_UINT: + data.u[c] = op[0]->value.u[c] + op[1]->value.u[c]; + break; + case GLSL_TYPE_INT: + data.i[c] = op[0]->value.i[c] + op[1]->value.i[c]; + break; + case GLSL_TYPE_FLOAT: + data.f[c] = op[0]->value.f[c] + op[1]->value.f[c]; + break; + default: + assert(0); + } + } + } else + /* FINISHME: Support operations with non-equal types. */ + return; + + break; + case ir_binop_sub: + if (ir->operands[0]->type == ir->operands[1]->type) { + for (c = 0; c < ir->operands[0]->type->components(); c++) { + switch (ir->operands[0]->type->base_type) { + case GLSL_TYPE_UINT: + data.u[c] = op[0]->value.u[c] - op[1]->value.u[c]; + break; + case GLSL_TYPE_INT: + data.i[c] = op[0]->value.i[c] - op[1]->value.i[c]; + break; + case GLSL_TYPE_FLOAT: + data.f[c] = op[0]->value.f[c] - op[1]->value.f[c]; + break; + default: + assert(0); + } + } + } else + /* FINISHME: Support operations with non-equal types. */ + return; + + break; + case ir_binop_mul: + if (ir->operands[0]->type == ir->operands[1]->type && + !ir->operands[0]->type->is_matrix()) { + for (c = 0; c < ir->operands[0]->type->components(); c++) { + switch (ir->operands[0]->type->base_type) { + case GLSL_TYPE_UINT: + data.u[c] = op[0]->value.u[c] * op[1]->value.u[c]; + break; + case GLSL_TYPE_INT: + data.i[c] = op[0]->value.i[c] * op[1]->value.i[c]; + break; + case GLSL_TYPE_FLOAT: + data.f[c] = op[0]->value.f[c] * op[1]->value.f[c]; + break; + default: + assert(0); + } + } + } else + /* FINISHME: Support operations with non-equal types. */ + return; + + break; + case ir_binop_div: + if (ir->operands[0]->type == ir->operands[1]->type) { + for (c = 0; c < ir->operands[0]->type->components(); c++) { + switch (ir->operands[0]->type->base_type) { + case GLSL_TYPE_UINT: + data.u[c] = op[0]->value.u[c] / op[1]->value.u[c]; + break; + case GLSL_TYPE_INT: + data.i[c] = op[0]->value.i[c] / op[1]->value.i[c]; + break; + case GLSL_TYPE_FLOAT: + data.f[c] = op[0]->value.f[c] / op[1]->value.f[c]; + break; + default: + assert(0); + } + } + } else + /* FINISHME: Support operations with non-equal types. */ + return; + + break; + case ir_binop_logic_and: + assert(op[0]->type->base_type == GLSL_TYPE_BOOL); + for (c = 0; c < ir->operands[0]->type->components(); c++) + data.b[c] = op[0]->value.b[c] && op[1]->value.b[c]; + break; + case ir_binop_logic_xor: + assert(op[0]->type->base_type == GLSL_TYPE_BOOL); + for (c = 0; c < ir->operands[0]->type->components(); c++) + data.b[c] = op[0]->value.b[c] ^ op[1]->value.b[c]; + break; + case ir_binop_logic_or: + assert(op[0]->type->base_type == GLSL_TYPE_BOOL); + for (c = 0; c < ir->operands[0]->type->components(); c++) + data.b[c] = op[0]->value.b[c] || op[1]->value.b[c]; + break; + + case ir_binop_less: + switch (ir->operands[0]->type->base_type) { + case GLSL_TYPE_UINT: + data.b[0] = op[0]->value.u[0] < op[1]->value.u[0]; + break; + case GLSL_TYPE_INT: + data.b[0] = op[0]->value.i[0] < op[1]->value.i[0]; + break; + case GLSL_TYPE_FLOAT: + data.b[0] = op[0]->value.f[0] < op[1]->value.f[0]; + break; + default: + assert(0); + } + break; + case ir_binop_greater: + switch (ir->operands[0]->type->base_type) { + case GLSL_TYPE_UINT: + data.b[0] = op[0]->value.u[0] > op[1]->value.u[0]; + break; + case GLSL_TYPE_INT: + data.b[0] = op[0]->value.i[0] > op[1]->value.i[0]; + break; + case GLSL_TYPE_FLOAT: + data.b[0] = op[0]->value.f[0] > op[1]->value.f[0]; + break; + default: + assert(0); + } + break; + case ir_binop_lequal: + switch (ir->operands[0]->type->base_type) { + case GLSL_TYPE_UINT: + data.b[0] = op[0]->value.u[0] <= op[1]->value.u[0]; + break; + case GLSL_TYPE_INT: + data.b[0] = op[0]->value.i[0] <= op[1]->value.i[0]; + break; + case GLSL_TYPE_FLOAT: + data.b[0] = op[0]->value.f[0] <= op[1]->value.f[0]; + break; + default: + assert(0); + } + break; + case ir_binop_gequal: + switch (ir->operands[0]->type->base_type) { + case GLSL_TYPE_UINT: + data.b[0] = op[0]->value.u[0] >= op[1]->value.u[0]; + break; + case GLSL_TYPE_INT: + data.b[0] = op[0]->value.i[0] >= op[1]->value.i[0]; + break; + case GLSL_TYPE_FLOAT: + data.b[0] = op[0]->value.f[0] >= op[1]->value.f[0]; + break; + default: + assert(0); + } + break; + + case ir_binop_equal: + data.b[0] = true; + for (c = 0; c < ir->operands[0]->type->components(); c++) { + switch (ir->operands[0]->type->base_type) { + case GLSL_TYPE_UINT: + data.b[0] = data.b[0] && op[0]->value.u[c] == op[1]->value.u[c]; + break; + case GLSL_TYPE_INT: + data.b[0] = data.b[0] && op[0]->value.i[c] == op[1]->value.i[c]; + break; + case GLSL_TYPE_FLOAT: + data.b[0] = data.b[0] && op[0]->value.f[c] == op[1]->value.f[c]; + break; + case GLSL_TYPE_BOOL: + data.b[0] = data.b[0] && op[0]->value.b[c] == op[1]->value.b[c]; + break; + default: + assert(0); + } + } + break; + case ir_binop_nequal: + data.b[0] = false; + for (c = 0; c < ir->operands[0]->type->components(); c++) { + switch (ir->operands[0]->type->base_type) { + case GLSL_TYPE_UINT: + data.b[0] = data.b[0] || op[0]->value.u[c] != op[1]->value.u[c]; + break; + case GLSL_TYPE_INT: + data.b[0] = data.b[0] || op[0]->value.i[c] != op[1]->value.i[c]; + break; + case GLSL_TYPE_FLOAT: + data.b[0] = data.b[0] || op[0]->value.f[c] != op[1]->value.f[c]; + break; + case GLSL_TYPE_BOOL: + data.b[0] = data.b[0] || op[0]->value.b[c] != op[1]->value.b[c]; + break; + default: + assert(0); + } + } + break; + + default: + /* FINISHME: Should handle all expression types. */ + return; + } + + void *ctx = talloc_parent(ir); + this->value = new(ctx) ir_constant(ir->type, &data); +} + + +void +ir_constant_visitor::visit(ir_texture *ir) +{ + // FINISHME: Do stuff with texture lookups + (void) ir; + value = NULL; +} + + +void +ir_constant_visitor::visit(ir_swizzle *ir) +{ + ir_constant *v = ir->val->constant_expression_value(); + + this->value = NULL; + + if (v != NULL) { + ir_constant_data data; + + const unsigned swiz_idx[4] = { + ir->mask.x, ir->mask.y, ir->mask.z, ir->mask.w + }; + + for (unsigned i = 0; i < ir->mask.num_components; i++) { + switch (v->type->base_type) { + case GLSL_TYPE_UINT: + case GLSL_TYPE_INT: data.u[i] = v->value.u[swiz_idx[i]]; break; + case GLSL_TYPE_FLOAT: data.f[i] = v->value.f[swiz_idx[i]]; break; + case GLSL_TYPE_BOOL: data.b[i] = v->value.b[swiz_idx[i]]; break; + default: assert(!"Should not get here."); break; + } + } + + void *ctx = talloc_parent(ir); + this->value = new(ctx) ir_constant(ir->type, &data); + } +} + + +void +ir_constant_visitor::visit(ir_dereference_variable *ir) +{ + value = NULL; + + ir_variable *var = ir->variable_referenced(); + if (var && var->constant_value) + value = (ir_constant *)var->constant_value->clone(NULL); +} + + +void +ir_constant_visitor::visit(ir_dereference_array *ir) +{ + void *ctx = talloc_parent(ir); + ir_constant *array = ir->array->constant_expression_value(); + ir_constant *idx = ir->array_index->constant_expression_value(); + + this->value = NULL; + + if ((array != NULL) && (idx != NULL)) { + if (array->type->is_matrix()) { + /* Array access of a matrix results in a vector. + */ + const unsigned column = idx->value.u[0]; + + const glsl_type *const column_type = array->type->column_type(); + + /* Offset in the constant matrix to the first element of the column + * to be extracted. + */ + const unsigned mat_idx = column * column_type->vector_elements; + + ir_constant_data data; + + switch (column_type->base_type) { + case GLSL_TYPE_UINT: + case GLSL_TYPE_INT: + for (unsigned i = 0; i < column_type->vector_elements; i++) + data.u[i] = array->value.u[mat_idx + i]; + + break; + + case GLSL_TYPE_FLOAT: + for (unsigned i = 0; i < column_type->vector_elements; i++) + data.f[i] = array->value.f[mat_idx + i]; + + break; + + default: + assert(!"Should not get here."); + break; + } + + this->value = new(ctx) ir_constant(column_type, &data); + } else if (array->type->is_vector()) { + const unsigned component = idx->value.u[0]; + + this->value = new(ctx) ir_constant(array, component); + } else { + /* FINISHME: Handle access of constant arrays. */ + } + } +} + + +void +ir_constant_visitor::visit(ir_dereference_record *ir) +{ + ir_constant *v = ir->record->constant_expression_value(); + + this->value = (v != NULL) ? v->get_record_field(ir->field) : NULL; +} + + +void +ir_constant_visitor::visit(ir_assignment *ir) +{ + (void) ir; + value = NULL; +} + + +void +ir_constant_visitor::visit(ir_constant *ir) +{ + value = ir; +} + + +void +ir_constant_visitor::visit(ir_call *ir) +{ + (void) ir; + value = NULL; +} + + +void +ir_constant_visitor::visit(ir_return *ir) +{ + (void) ir; + value = NULL; +} + + +void +ir_constant_visitor::visit(ir_if *ir) +{ + (void) ir; + value = NULL; +} + + +void +ir_constant_visitor::visit(ir_loop *ir) +{ + (void) ir; + value = NULL; +} + + +void +ir_constant_visitor::visit(ir_loop_jump *ir) +{ + (void) ir; + value = NULL; +} -- cgit v1.2.3 From 16efab1c4dee6e6a827ba5f1c482378159545ae5 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Wed, 30 Jun 2010 10:47:34 -0700 Subject: glsl2: Define new ir_discard instruction. --- src/glsl/ir.h | 27 +++++++++++++++++++++++++++ src/glsl/ir_clone.cpp | 12 ++++++++++++ src/glsl/ir_constant_expression.cpp | 9 +++++++++ src/glsl/ir_constant_folding.cpp | 8 ++++++++ src/glsl/ir_hierarchical_visitor.cpp | 16 ++++++++++++++++ src/glsl/ir_hierarchical_visitor.h | 2 ++ src/glsl/ir_hv_accept.cpp | 17 +++++++++++++++++ src/glsl/ir_print_visitor.cpp | 14 ++++++++++++++ src/glsl/ir_print_visitor.h | 1 + src/glsl/ir_visitor.h | 1 + src/mesa/shader/ir_to_mesa.cpp | 8 ++++++++ 11 files changed, 115 insertions(+) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir.h b/src/glsl/ir.h index 65026ef1f5..00b0076c17 100644 --- a/src/glsl/ir.h +++ b/src/glsl/ir.h @@ -793,6 +793,33 @@ private: /** Loop containing this break instruction. */ ir_loop *loop; }; + +/** + * IR instruction representing discard statements. + */ +class ir_discard : public ir_jump { +public: + ir_discard() + { + this->condition = NULL; + } + + ir_discard(ir_rvalue *cond) + { + this->condition = cond; + } + + virtual ir_instruction *clone(struct hash_table *ht) const; + + virtual void accept(ir_visitor *v) + { + v->visit(this); + } + + virtual ir_visitor_status accept(ir_hierarchical_visitor *); + + ir_rvalue *condition; +}; /*@}*/ diff --git a/src/glsl/ir_clone.cpp b/src/glsl/ir_clone.cpp index 01a1ce3a6d..74cc858bda 100644 --- a/src/glsl/ir_clone.cpp +++ b/src/glsl/ir_clone.cpp @@ -74,6 +74,18 @@ ir_return::clone(struct hash_table *ht) const return new(ctx) ir_return(new_value); } +ir_instruction * +ir_discard::clone(struct hash_table *ht) const +{ + void *ctx = talloc_parent(this); + ir_rvalue *new_condition = NULL; + + if (this->condition != NULL) + new_condition = (ir_rvalue *) this->condition->clone(ht); + + return new(ctx) ir_discard(new_condition); +} + ir_instruction * ir_loop_jump::clone(struct hash_table *ht) const { diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index 3408f5256a..c6348ac434 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -75,6 +75,7 @@ public: virtual void visit(ir_constant *); virtual void visit(ir_call *); virtual void visit(ir_return *); + virtual void visit(ir_discard *); virtual void visit(ir_if *); virtual void visit(ir_loop *); virtual void visit(ir_loop_jump *); @@ -647,6 +648,14 @@ ir_constant_visitor::visit(ir_return *ir) } +void +ir_constant_visitor::visit(ir_discard *ir) +{ + (void) ir; + value = NULL; +} + + void ir_constant_visitor::visit(ir_if *ir) { diff --git a/src/glsl/ir_constant_folding.cpp b/src/glsl/ir_constant_folding.cpp index 342d027bbe..2daa6fde38 100644 --- a/src/glsl/ir_constant_folding.cpp +++ b/src/glsl/ir_constant_folding.cpp @@ -68,6 +68,7 @@ public: virtual void visit(ir_constant *); virtual void visit(ir_call *); virtual void visit(ir_return *); + virtual void visit(ir_discard *); virtual void visit(ir_if *); virtual void visit(ir_loop *); virtual void visit(ir_loop_jump *); @@ -190,6 +191,13 @@ ir_constant_folding_visitor::visit(ir_return *ir) } +void +ir_constant_folding_visitor::visit(ir_discard *ir) +{ + (void) ir; +} + + void ir_constant_folding_visitor::visit(ir_if *ir) { diff --git a/src/glsl/ir_hierarchical_visitor.cpp b/src/glsl/ir_hierarchical_visitor.cpp index 0d520b127f..9afb12a4a2 100644 --- a/src/glsl/ir_hierarchical_visitor.cpp +++ b/src/glsl/ir_hierarchical_visitor.cpp @@ -242,6 +242,22 @@ ir_hierarchical_visitor::visit_leave(ir_return *ir) return visit_continue; } +ir_visitor_status +ir_hierarchical_visitor::visit_enter(ir_discard *ir) +{ + if (this->callback != NULL) + this->callback(ir, this->data); + + return visit_continue; +} + +ir_visitor_status +ir_hierarchical_visitor::visit_leave(ir_discard *ir) +{ + (void) ir; + return visit_continue; +} + ir_visitor_status ir_hierarchical_visitor::visit_enter(ir_if *ir) { diff --git a/src/glsl/ir_hierarchical_visitor.h b/src/glsl/ir_hierarchical_visitor.h index 8b9e49dab1..2c4590d4b1 100644 --- a/src/glsl/ir_hierarchical_visitor.h +++ b/src/glsl/ir_hierarchical_visitor.h @@ -129,6 +129,8 @@ public: virtual ir_visitor_status visit_leave(class ir_call *); virtual ir_visitor_status visit_enter(class ir_return *); virtual ir_visitor_status visit_leave(class ir_return *); + virtual ir_visitor_status visit_enter(class ir_discard *); + virtual ir_visitor_status visit_leave(class ir_discard *); virtual ir_visitor_status visit_enter(class ir_if *); virtual ir_visitor_status visit_leave(class ir_if *); /*@}*/ diff --git a/src/glsl/ir_hv_accept.cpp b/src/glsl/ir_hv_accept.cpp index f936b3500e..7b5cc5234c 100644 --- a/src/glsl/ir_hv_accept.cpp +++ b/src/glsl/ir_hv_accept.cpp @@ -321,6 +321,23 @@ ir_return::accept(ir_hierarchical_visitor *v) } +ir_visitor_status +ir_discard::accept(ir_hierarchical_visitor *v) +{ + ir_visitor_status s = v->visit_enter(this); + if (s != visit_continue) + return (s == visit_continue_with_parent) ? visit_continue : s; + + if (this->condition != NULL) { + s = this->condition->accept(v); + if (s != visit_continue) + return (s == visit_continue_with_parent) ? visit_continue : s; + } + + return v->visit_leave(this); +} + + ir_visitor_status ir_if::accept(ir_hierarchical_visitor *v) { diff --git a/src/glsl/ir_print_visitor.cpp b/src/glsl/ir_print_visitor.cpp index be5a843f67..6f867e3253 100644 --- a/src/glsl/ir_print_visitor.cpp +++ b/src/glsl/ir_print_visitor.cpp @@ -314,6 +314,20 @@ ir_print_visitor::visit(ir_return *ir) } +void +ir_print_visitor::visit(ir_discard *ir) +{ + printf("(discard "); + + if (ir->condition != NULL) { + printf(" "); + ir->condition->accept(this); + } + + printf(")"); +} + + void ir_print_visitor::visit(ir_if *ir) { diff --git a/src/glsl/ir_print_visitor.h b/src/glsl/ir_print_visitor.h index e97b823522..3db42e24ca 100644 --- a/src/glsl/ir_print_visitor.h +++ b/src/glsl/ir_print_visitor.h @@ -69,6 +69,7 @@ public: virtual void visit(ir_constant *); virtual void visit(ir_call *); virtual void visit(ir_return *); + virtual void visit(ir_discard *); virtual void visit(ir_if *); virtual void visit(ir_loop *); virtual void visit(ir_loop_jump *); diff --git a/src/glsl/ir_visitor.h b/src/glsl/ir_visitor.h index a6f9d2b7ee..b87d737318 100644 --- a/src/glsl/ir_visitor.h +++ b/src/glsl/ir_visitor.h @@ -57,6 +57,7 @@ public: virtual void visit(class ir_constant *) = 0; virtual void visit(class ir_call *) = 0; virtual void visit(class ir_return *) = 0; + virtual void visit(class ir_discard *) = 0; virtual void visit(class ir_if *) = 0; virtual void visit(class ir_loop *) = 0; virtual void visit(class ir_loop_jump *) = 0; diff --git a/src/mesa/shader/ir_to_mesa.cpp b/src/mesa/shader/ir_to_mesa.cpp index ef9a96e2f5..8c074a8bd9 100644 --- a/src/mesa/shader/ir_to_mesa.cpp +++ b/src/mesa/shader/ir_to_mesa.cpp @@ -134,6 +134,7 @@ public: virtual void visit(ir_constant *); virtual void visit(ir_call *); virtual void visit(ir_return *); + virtual void visit(ir_discard *); virtual void visit(ir_texture *); virtual void visit(ir_if *); /*@}*/ @@ -1321,6 +1322,13 @@ ir_to_mesa_visitor::visit(ir_return *ir) ir->get_value()->accept(this); } +void +ir_to_mesa_visitor::visit(ir_discard *ir) +{ + assert(0); + + ir->condition->accept(this); +} void ir_to_mesa_visitor::visit(ir_if *ir) -- cgit v1.2.3 From d925c9173009e9e5d48df30b30aaef22753183aa Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Thu, 1 Jul 2010 10:37:11 -0700 Subject: glsl2: Add ir_unop_fract as an expression type. Most backends will prefer seeing this to seeing (a - floor(a)), so represent it explicitly. --- src/glsl/builtin_function.cpp | 8 ++++---- src/glsl/builtins/110/fract | 8 ++++---- src/glsl/ir.cpp | 2 ++ src/glsl/ir.h | 1 + src/glsl/ir_constant_expression.cpp | 18 ++++++++++++++++++ src/mesa/shader/ir_to_mesa.cpp | 4 ++++ 6 files changed, 33 insertions(+), 8 deletions(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/builtin_function.cpp b/src/glsl/builtin_function.cpp index b7dbc6b34f..30ba6a5267 100644 --- a/src/glsl/builtin_function.cpp +++ b/src/glsl/builtin_function.cpp @@ -781,22 +781,22 @@ static const char *builtins_110_fract = { " (signature float\n" " (parameters\n" " (declare (in) float x))\n" - " ((return (expression float - (var_ref x) (expression float floor (var_ref x))))))\n" + " ((return (expression float fract (var_ref x)))))\n" "\n" " (signature vec2\n" " (parameters\n" " (declare (in) vec2 x))\n" - " ((return (expression vec2 - (var_ref x) (expression vec2 floor (var_ref x))))))\n" + " ((return (expression vec2 fract (var_ref x)))))\n" "\n" " (signature vec3\n" " (parameters\n" " (declare (in) vec3 x))\n" - " ((return (expression vec3 - (var_ref x) (expression vec3 floor (var_ref x))))))\n" + " ((return (expression vec3 fract (var_ref x)))))\n" "\n" " (signature vec4\n" " (parameters\n" " (declare (in) vec4 x))\n" - " ((return (expression vec4 - (var_ref x) (expression vec4 floor (var_ref x))))))\n" + " ((return (expression vec4 fract (var_ref x)))))\n" "))\n" "\n" }; diff --git a/src/glsl/builtins/110/fract b/src/glsl/builtins/110/fract index 46741bb3cb..3f0763d1b3 100644 --- a/src/glsl/builtins/110/fract +++ b/src/glsl/builtins/110/fract @@ -2,21 +2,21 @@ (signature float (parameters (declare (in) float x)) - ((return (expression float - (var_ref x) (expression float floor (var_ref x)))))) + ((return (expression float fract (var_ref x))))) (signature vec2 (parameters (declare (in) vec2 x)) - ((return (expression vec2 - (var_ref x) (expression vec2 floor (var_ref x)))))) + ((return (expression vec2 fract (var_ref x))))) (signature vec3 (parameters (declare (in) vec3 x)) - ((return (expression vec3 - (var_ref x) (expression vec3 floor (var_ref x)))))) + ((return (expression vec3 fract (var_ref x))))) (signature vec4 (parameters (declare (in) vec4 x)) - ((return (expression vec4 - (var_ref x) (expression vec4 floor (var_ref x)))))) + ((return (expression vec4 fract (var_ref x))))) )) diff --git a/src/glsl/ir.cpp b/src/glsl/ir.cpp index 60ee36d17c..4257842583 100644 --- a/src/glsl/ir.cpp +++ b/src/glsl/ir.cpp @@ -72,6 +72,7 @@ ir_expression::get_num_operands(ir_expression_operation op) 1, /* ir_unop_trunc */ 1, /* ir_unop_ceil */ 1, /* ir_unop_floor */ + 1, /* ir_unop_fract */ 1, /* ir_unop_sin */ 1, /* ir_unop_cos */ @@ -137,6 +138,7 @@ static const char *const operator_strs[] = { "trunc", "ceil", "floor", + "fract", "sin", "cos", "dFdx", diff --git a/src/glsl/ir.h b/src/glsl/ir.h index 00b0076c17..f47813786b 100644 --- a/src/glsl/ir.h +++ b/src/glsl/ir.h @@ -528,6 +528,7 @@ enum ir_expression_operation { ir_unop_trunc, ir_unop_ceil, ir_unop_floor, + ir_unop_fract, /*@}*/ /** diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index c6348ac434..548217cddd 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -187,6 +187,24 @@ ir_constant_visitor::visit(ir_expression *ir) } break; + case ir_unop_fract: + for (c = 0; c < ir->operands[0]->type->components(); c++) { + switch (ir->type->base_type) { + case GLSL_TYPE_UINT: + data.u[c] = 0; + break; + case GLSL_TYPE_INT: + data.i[c] = 0; + break; + case GLSL_TYPE_FLOAT: + data.f[c] = op[0]->value.f[c] - floor(op[0]->value.f[c]); + break; + default: + assert(0); + } + } + break; + case ir_unop_neg: for (c = 0; c < ir->operands[0]->type->components(); c++) { switch (ir->type->base_type) { diff --git a/src/mesa/shader/ir_to_mesa.cpp b/src/mesa/shader/ir_to_mesa.cpp index b270e2da41..2f2096ef97 100644 --- a/src/mesa/shader/ir_to_mesa.cpp +++ b/src/mesa/shader/ir_to_mesa.cpp @@ -782,6 +782,10 @@ ir_to_mesa_visitor::visit(ir_expression *ir) case ir_unop_floor: ir_to_mesa_emit_op1(ir, OPCODE_FLR, result_dst, op[0]); break; + case ir_unop_fract: + ir_to_mesa_emit_op1(ir, OPCODE_FRC, result_dst, op[0]); + break; + case ir_binop_min: ir_to_mesa_emit_op2(ir, OPCODE_MIN, result_dst, op[0], op[1]); break; -- cgit v1.2.3 From c63a1db81f56cc2021fe1fb2411c327f720b0e09 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Mon, 5 Jul 2010 22:33:35 -0700 Subject: ir_constant_expression: Initialize all components of constant data to 0. This is probably just a good idea, and will come in useful when implementing things like matrix multiplication. --- src/glsl/ir_constant_expression.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index 548217cddd..1b81017698 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -133,6 +133,8 @@ ir_constant_visitor::visit(ir_expression *ir) unsigned int operand, c; ir_constant_data data; + memset(&data, 0, sizeof(data)); + for (operand = 0; operand < ir->get_num_operands(); operand++) { op[operand] = ir->operands[operand]->constant_expression_value(); if (!op[operand]) -- cgit v1.2.3 From 6bc432e14e12c280bc53e57338bf86fbf8d26885 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Fri, 2 Jul 2010 17:12:23 -0700 Subject: ir_constant_expression: Initialize op[0] and op[1] to NULL. This makes it easy to check if there is a second argument. --- src/glsl/ir_constant_expression.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index 1b81017698..6d6ee093d7 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -129,7 +129,7 @@ void ir_constant_visitor::visit(ir_expression *ir) { value = NULL; - ir_constant *op[2]; + ir_constant *op[2] = { NULL, NULL }; unsigned int operand, c; ir_constant_data data; -- cgit v1.2.3 From 6fc983b9bb5555e2906d2680bc3cbd11c43b63f6 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Tue, 6 Jul 2010 02:39:57 -0700 Subject: ir_constant_expression: Assert that both operands share a base type. --- src/glsl/ir_constant_expression.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index 6d6ee093d7..610d9479a9 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -141,6 +141,9 @@ ir_constant_visitor::visit(ir_expression *ir) return; } + if (op[1] != NULL) + assert(op[0]->type->base_type == op[1]->type->base_type); + switch (ir->operation) { case ir_unop_logic_not: assert(op[0]->type->base_type == GLSL_TYPE_BOOL); -- cgit v1.2.3 From e74dcd7924901e5cb3d0952f46e955e15d0b3207 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Tue, 6 Jul 2010 02:48:16 -0700 Subject: ir_constant_expression: Support scalar + vector and scalar + matrix. Fixes piglit tests const-vec-scalar-01.frag, const-vec-scalar-05.frag, and const-mat-scalar-01.frag. --- src/glsl/ir_constant_expression.cpp | 46 ++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 18 deletions(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index 610d9479a9..033eee1d72 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -144,6 +144,16 @@ ir_constant_visitor::visit(ir_expression *ir) if (op[1] != NULL) assert(op[0]->type->base_type == op[1]->type->base_type); + bool op0_scalar = op[0]->type->is_scalar(); + bool op1_scalar = op[1] != NULL && op[1]->type->is_scalar(); + + /* When iterating over a vector or matrix's components, we want to increase + * the loop counter. However, for scalars, we want to stay at 0. + */ + unsigned c0_inc = op0_scalar ? 1 : 0; + unsigned c1_inc = op1_scalar ? 1 : 0; + unsigned components = op[op1_scalar ? 0 : 1]->type->components(); + switch (ir->operation) { case ir_unop_logic_not: assert(op[0]->type->base_type == GLSL_TYPE_BOOL); @@ -308,25 +318,25 @@ ir_constant_visitor::visit(ir_expression *ir) break; case ir_binop_add: - if (ir->operands[0]->type == ir->operands[1]->type) { - for (c = 0; c < ir->operands[0]->type->components(); c++) { - switch (ir->operands[0]->type->base_type) { - case GLSL_TYPE_UINT: - data.u[c] = op[0]->value.u[c] + op[1]->value.u[c]; - break; - case GLSL_TYPE_INT: - data.i[c] = op[0]->value.i[c] + op[1]->value.i[c]; - break; - case GLSL_TYPE_FLOAT: - data.f[c] = op[0]->value.f[c] + op[1]->value.f[c]; - break; - default: - assert(0); - } + assert(op[0]->type == op[1]->type || op0_scalar || op1_scalar); + for (unsigned c = 0, c0 = 0, c1 = 0; + c < components; + c0 += c0_inc, c1 += c1_inc, c++) { + + switch (ir->operands[0]->type->base_type) { + case GLSL_TYPE_UINT: + data.u[c] = op[0]->value.u[c0] + op[1]->value.u[c1]; + break; + case GLSL_TYPE_INT: + data.i[c] = op[0]->value.i[c0] + op[1]->value.i[c1]; + break; + case GLSL_TYPE_FLOAT: + data.f[c] = op[0]->value.f[c0] + op[1]->value.f[c1]; + break; + default: + assert(0); } - } else - /* FINISHME: Support operations with non-equal types. */ - return; + } break; case ir_binop_sub: -- cgit v1.2.3 From 97b44f040abc9cbf257aba1b7fdaa11134dcc70b Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Tue, 6 Jul 2010 02:53:29 -0700 Subject: ir_constant_expression: Support scalar - vector and scalar - matrix. Fixes piglit tests const-vec-scalar-02.frag and const-mat-scalar-02.frag. --- src/glsl/ir_constant_expression.cpp | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index 033eee1d72..fbf06f1325 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -340,25 +340,25 @@ ir_constant_visitor::visit(ir_expression *ir) break; case ir_binop_sub: - if (ir->operands[0]->type == ir->operands[1]->type) { - for (c = 0; c < ir->operands[0]->type->components(); c++) { - switch (ir->operands[0]->type->base_type) { - case GLSL_TYPE_UINT: - data.u[c] = op[0]->value.u[c] - op[1]->value.u[c]; - break; - case GLSL_TYPE_INT: - data.i[c] = op[0]->value.i[c] - op[1]->value.i[c]; - break; - case GLSL_TYPE_FLOAT: - data.f[c] = op[0]->value.f[c] - op[1]->value.f[c]; - break; - default: - assert(0); - } + assert(op[0]->type == op[1]->type || op0_scalar || op1_scalar); + for (unsigned c = 0, c0 = 0, c1 = 0; + c < components; + c0 += c0_inc, c1 += c1_inc, c++) { + + switch (ir->operands[0]->type->base_type) { + case GLSL_TYPE_UINT: + data.u[c] = op[0]->value.u[c0] - op[1]->value.u[c1]; + break; + case GLSL_TYPE_INT: + data.i[c] = op[0]->value.i[c0] - op[1]->value.i[c1]; + break; + case GLSL_TYPE_FLOAT: + data.f[c] = op[0]->value.f[c0] - op[1]->value.f[c1]; + break; + default: + assert(0); } - } else - /* FINISHME: Support operations with non-equal types. */ - return; + } break; case ir_binop_mul: -- cgit v1.2.3 From dad35eb8b0c7378588d9dca1c1091aaede83a83f Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Tue, 6 Jul 2010 02:56:36 -0700 Subject: ir_constant_expression: Support scalar / vector and scalar / matrix. Fixes piglit tests const-vec-scalar-04.frag and const-mat-scalar-04.frag. --- src/glsl/ir_constant_expression.cpp | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index fbf06f1325..2fab03bb60 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -385,25 +385,25 @@ ir_constant_visitor::visit(ir_expression *ir) break; case ir_binop_div: - if (ir->operands[0]->type == ir->operands[1]->type) { - for (c = 0; c < ir->operands[0]->type->components(); c++) { - switch (ir->operands[0]->type->base_type) { - case GLSL_TYPE_UINT: - data.u[c] = op[0]->value.u[c] / op[1]->value.u[c]; - break; - case GLSL_TYPE_INT: - data.i[c] = op[0]->value.i[c] / op[1]->value.i[c]; - break; - case GLSL_TYPE_FLOAT: - data.f[c] = op[0]->value.f[c] / op[1]->value.f[c]; - break; - default: - assert(0); - } + assert(op[0]->type == op[1]->type || op0_scalar || op1_scalar); + for (unsigned c = 0, c0 = 0, c1 = 0; + c < components; + c0 += c0_inc, c1 += c1_inc, c++) { + + switch (ir->operands[0]->type->base_type) { + case GLSL_TYPE_UINT: + data.u[c] = op[0]->value.u[c0] / op[1]->value.u[c1]; + break; + case GLSL_TYPE_INT: + data.i[c] = op[0]->value.i[c0] / op[1]->value.i[c1]; + break; + case GLSL_TYPE_FLOAT: + data.f[c] = op[0]->value.f[c0] / op[1]->value.f[c1]; + break; + default: + assert(0); } - } else - /* FINISHME: Support operations with non-equal types. */ - return; + } break; case ir_binop_logic_and: -- cgit v1.2.3 From 37b3f9d0edb55807f822c02292348e20a8369c43 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Tue, 6 Jul 2010 03:01:15 -0700 Subject: ir_constant_expression: Support scalar * vector and scalar * matrix. The test here is slightly different since we need to keep matrix multiplication separate. Fixes piglit tests const-vec-scalar-03.frag and const-mat-scalar-03.frag. --- src/glsl/ir_constant_expression.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index 2fab03bb60..e039504d4e 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -362,25 +362,28 @@ ir_constant_visitor::visit(ir_expression *ir) break; case ir_binop_mul: - if (ir->operands[0]->type == ir->operands[1]->type && - !ir->operands[0]->type->is_matrix()) { - for (c = 0; c < ir->operands[0]->type->components(); c++) { + if ((op[0]->type == op[1]->type && !op[0]->type->is_matrix()) + || op0_scalar || op1_scalar) { + for (unsigned c = 0, c0 = 0, c1 = 0; + c < components; + c0 += c0_inc, c1 += c1_inc, c++) { + switch (ir->operands[0]->type->base_type) { case GLSL_TYPE_UINT: - data.u[c] = op[0]->value.u[c] * op[1]->value.u[c]; + data.u[c] = op[0]->value.u[c0] * op[1]->value.u[c1]; break; case GLSL_TYPE_INT: - data.i[c] = op[0]->value.i[c] * op[1]->value.i[c]; + data.i[c] = op[0]->value.i[c0] * op[1]->value.i[c1]; break; case GLSL_TYPE_FLOAT: - data.f[c] = op[0]->value.f[c] * op[1]->value.f[c]; + data.f[c] = op[0]->value.f[c0] * op[1]->value.f[c1]; break; default: assert(0); } } } else - /* FINISHME: Support operations with non-equal types. */ + /* FINISHME: Support vector/matrix and matrix multiplication. */ return; break; -- cgit v1.2.3 From cf80a4d177225345c2238d8e545f8ae02b41da71 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Mon, 5 Jul 2010 23:19:56 -0700 Subject: ir_constant_expression: Add support for matrix multiplication. Also handles matrix/vector and vector/matrix multiplication. Fixes piglit tests const-matrix-multiply-01.frag, const-matrix-multiply-02.frag, and const-vec-mat.frag. --- src/glsl/ir_constant_expression.cpp | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index e039504d4e..d05aa104f8 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -362,6 +362,7 @@ ir_constant_visitor::visit(ir_expression *ir) break; case ir_binop_mul: + /* Check for equal types, or unequal types involving scalars */ if ((op[0]->type == op[1]->type && !op[0]->type->is_matrix()) || op0_scalar || op1_scalar) { for (unsigned c = 0, c0 = 0, c1 = 0; @@ -382,9 +383,30 @@ ir_constant_visitor::visit(ir_expression *ir) assert(0); } } - } else - /* FINISHME: Support vector/matrix and matrix multiplication. */ - return; + } else { + assert(op[0]->type->is_matrix() || op[1]->type->is_matrix()); + + /* Multiply an N-by-M matrix with an M-by-P matrix. Since either + * matrix can be a GLSL vector, either N or P can be 1. + * + * For vec*mat, the vector is treated as a row vector. This + * means the vector is a 1-row x M-column matrix. + * + * For mat*vec, the vector is treated as a column vector. Since + * matrix_columns is 1 for vectors, this just works. + */ + const unsigned n = op[0]->type->is_vector() + ? 1 : op[0]->type->vector_elements; + const unsigned m = op[1]->type->vector_elements; + const unsigned p = op[1]->type->matrix_columns; + for (unsigned j = 0; j < p; j++) { + for (unsigned i = 0; i < n; i++) { + for (unsigned k = 0; k < m; k++) { + data.f[i+n*j] += op[0]->value.f[i+n*k]*op[1]->value.f[k+m*j]; + } + } + } + } break; case ir_binop_div: -- cgit v1.2.3 From 3f4a0b8bb0cfa36cc6f9968c8aab03f1cb0678ff Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Mon, 5 Jul 2010 21:15:32 -0700 Subject: ir_constant_expression: Add support for dot products. --- src/glsl/ir_constant_expression.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index d05aa104f8..5c2e3629e1 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -317,6 +317,26 @@ ir_constant_visitor::visit(ir_expression *ir) } break; + case ir_binop_dot: + assert(op[0]->type->is_vector() && op[1]->type->is_vector()); + data.f[0] = 0; + for (c = 0; c < op[0]->type->components(); c++) { + switch (ir->operands[0]->type->base_type) { + case GLSL_TYPE_UINT: + data.u[0] += op[0]->value.u[c] * op[1]->value.u[c]; + break; + case GLSL_TYPE_INT: + data.i[0] += op[0]->value.i[c] * op[1]->value.i[c]; + break; + case GLSL_TYPE_FLOAT: + data.f[0] += op[0]->value.f[c] * op[1]->value.f[c]; + break; + default: + assert(0); + } + } + + break; case ir_binop_add: assert(op[0]->type == op[1]->type || op0_scalar || op1_scalar); for (unsigned c = 0, c0 = 0, c1 = 0; -- cgit v1.2.3 From f14e596f11b4e44c75a880536efb1e8c5a72da7d Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Tue, 6 Jul 2010 16:26:11 -0700 Subject: ir_constant_expression: Declare loop counting variables in the loops. Fixes "name lookup of 'c' changed" warning. --- src/glsl/ir_constant_expression.cpp | 47 ++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 24 deletions(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index 5c2e3629e1..11c810bc48 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -130,12 +130,11 @@ ir_constant_visitor::visit(ir_expression *ir) { value = NULL; ir_constant *op[2] = { NULL, NULL }; - unsigned int operand, c; ir_constant_data data; memset(&data, 0, sizeof(data)); - for (operand = 0; operand < ir->get_num_operands(); operand++) { + for (unsigned operand = 0; operand < ir->get_num_operands(); operand++) { op[operand] = ir->operands[operand]->constant_expression_value(); if (!op[operand]) return; @@ -157,20 +156,20 @@ ir_constant_visitor::visit(ir_expression *ir) switch (ir->operation) { case ir_unop_logic_not: assert(op[0]->type->base_type == GLSL_TYPE_BOOL); - for (c = 0; c < ir->operands[0]->type->components(); c++) + for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) data.b[c] = !op[0]->value.b[c]; break; case ir_unop_f2i: assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); - for (c = 0; c < ir->operands[0]->type->components(); c++) { + for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { data.i[c] = op[0]->value.f[c]; } break; case ir_unop_i2f: assert(op[0]->type->base_type == GLSL_TYPE_UINT || op[0]->type->base_type == GLSL_TYPE_INT); - for (c = 0; c < ir->operands[0]->type->components(); c++) { + for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { if (op[0]->type->base_type == GLSL_TYPE_INT) data.f[c] = op[0]->value.i[c]; else @@ -179,31 +178,31 @@ ir_constant_visitor::visit(ir_expression *ir) break; case ir_unop_b2f: assert(op[0]->type->base_type == GLSL_TYPE_BOOL); - for (c = 0; c < ir->operands[0]->type->components(); c++) { + for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { data.f[c] = op[0]->value.b[c] ? 1.0 : 0.0; } break; case ir_unop_f2b: assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); - for (c = 0; c < ir->operands[0]->type->components(); c++) { + for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { data.b[c] = bool(op[0]->value.f[c]); } break; case ir_unop_b2i: assert(op[0]->type->base_type == GLSL_TYPE_BOOL); - for (c = 0; c < ir->operands[0]->type->components(); c++) { + for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { data.u[c] = op[0]->value.b[c] ? 1 : 0; } break; case ir_unop_i2b: assert(op[0]->type->is_integer()); - for (c = 0; c < ir->operands[0]->type->components(); c++) { + for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { data.b[c] = bool(op[0]->value.u[c]); } break; case ir_unop_fract: - for (c = 0; c < ir->operands[0]->type->components(); c++) { + for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { switch (ir->type->base_type) { case GLSL_TYPE_UINT: data.u[c] = 0; @@ -221,7 +220,7 @@ ir_constant_visitor::visit(ir_expression *ir) break; case ir_unop_neg: - for (c = 0; c < ir->operands[0]->type->components(); c++) { + for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { switch (ir->type->base_type) { case GLSL_TYPE_UINT: data.u[c] = -op[0]->value.u[c]; @@ -240,7 +239,7 @@ ir_constant_visitor::visit(ir_expression *ir) case ir_unop_abs: assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); - for (c = 0; c < ir->operands[0]->type->components(); c++) { + for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { switch (ir->type->base_type) { case GLSL_TYPE_UINT: data.u[c] = op[0]->value.u[c]; @@ -261,7 +260,7 @@ ir_constant_visitor::visit(ir_expression *ir) case ir_unop_rcp: assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); - for (c = 0; c < ir->operands[0]->type->components(); c++) { + for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { switch (ir->type->base_type) { case GLSL_TYPE_UINT: if (op[0]->value.u[c] != 0.0) @@ -283,28 +282,28 @@ ir_constant_visitor::visit(ir_expression *ir) case ir_unop_rsq: assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); - for (c = 0; c < ir->operands[0]->type->components(); c++) { + for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { data.f[c] = 1.0 / sqrtf(op[0]->value.f[c]); } break; case ir_unop_sqrt: assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); - for (c = 0; c < ir->operands[0]->type->components(); c++) { + for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { data.f[c] = sqrtf(op[0]->value.f[c]); } break; case ir_unop_exp: assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); - for (c = 0; c < ir->operands[0]->type->components(); c++) { + for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { data.f[c] = expf(op[0]->value.f[c]); } break; case ir_unop_log: assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); - for (c = 0; c < ir->operands[0]->type->components(); c++) { + for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { data.f[c] = logf(op[0]->value.f[c]); } break; @@ -312,7 +311,7 @@ ir_constant_visitor::visit(ir_expression *ir) case ir_unop_dFdx: case ir_unop_dFdy: assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); - for (c = 0; c < ir->operands[0]->type->components(); c++) { + for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { data.f[c] = 0.0; } break; @@ -320,7 +319,7 @@ ir_constant_visitor::visit(ir_expression *ir) case ir_binop_dot: assert(op[0]->type->is_vector() && op[1]->type->is_vector()); data.f[0] = 0; - for (c = 0; c < op[0]->type->components(); c++) { + for (unsigned c = 0; c < op[0]->type->components(); c++) { switch (ir->operands[0]->type->base_type) { case GLSL_TYPE_UINT: data.u[0] += op[0]->value.u[c] * op[1]->value.u[c]; @@ -453,17 +452,17 @@ ir_constant_visitor::visit(ir_expression *ir) break; case ir_binop_logic_and: assert(op[0]->type->base_type == GLSL_TYPE_BOOL); - for (c = 0; c < ir->operands[0]->type->components(); c++) + for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) data.b[c] = op[0]->value.b[c] && op[1]->value.b[c]; break; case ir_binop_logic_xor: assert(op[0]->type->base_type == GLSL_TYPE_BOOL); - for (c = 0; c < ir->operands[0]->type->components(); c++) + for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) data.b[c] = op[0]->value.b[c] ^ op[1]->value.b[c]; break; case ir_binop_logic_or: assert(op[0]->type->base_type == GLSL_TYPE_BOOL); - for (c = 0; c < ir->operands[0]->type->components(); c++) + for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) data.b[c] = op[0]->value.b[c] || op[1]->value.b[c]; break; @@ -530,7 +529,7 @@ ir_constant_visitor::visit(ir_expression *ir) case ir_binop_equal: data.b[0] = true; - for (c = 0; c < ir->operands[0]->type->components(); c++) { + for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { switch (ir->operands[0]->type->base_type) { case GLSL_TYPE_UINT: data.b[0] = data.b[0] && op[0]->value.u[c] == op[1]->value.u[c]; @@ -551,7 +550,7 @@ ir_constant_visitor::visit(ir_expression *ir) break; case ir_binop_nequal: data.b[0] = false; - for (c = 0; c < ir->operands[0]->type->components(); c++) { + for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { switch (ir->operands[0]->type->base_type) { case GLSL_TYPE_UINT: data.b[0] = data.b[0] || op[0]->value.u[c] != op[1]->value.u[c]; -- cgit v1.2.3 From ca088cc277ce9f986693c857f3961dc0e1a4d91c Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Tue, 6 Jul 2010 17:41:02 -0700 Subject: glsl2: Clone methods return the type of the thing being cloned This is as opposed to returning the type of the base class of the hierarchy. --- src/glsl/ast_to_hir.cpp | 10 +++++----- src/glsl/ir.h | 38 ++++++++++++++++++++----------------- src/glsl/ir_clone.cpp | 34 ++++++++++++++++----------------- src/glsl/ir_constant_expression.cpp | 2 +- src/glsl/ir_function_inlining.cpp | 2 +- 5 files changed, 45 insertions(+), 41 deletions(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp index 3bd0bd6591..f5e93b0254 100644 --- a/src/glsl/ast_to_hir.cpp +++ b/src/glsl/ast_to_hir.cpp @@ -961,7 +961,7 @@ ast_expression::hir(exec_list *instructions, op[0], op[1]); result = do_assignment(instructions, state, - (ir_rvalue *)op[0]->clone(NULL), temp_rhs, + op[0]->clone(NULL), temp_rhs, this->subexpressions[0]->get_location()); type = result->type; error_emitted = (op[0]->type->is_error()); @@ -987,7 +987,7 @@ ast_expression::hir(exec_list *instructions, op[0], op[1]); result = do_assignment(instructions, state, - (ir_rvalue *)op[0]->clone(NULL), temp_rhs, + op[0]->clone(NULL), temp_rhs, this->subexpressions[0]->get_location()); type = result->type; error_emitted = type->is_error(); @@ -1107,7 +1107,7 @@ ast_expression::hir(exec_list *instructions, op[0], op[1]); result = do_assignment(instructions, state, - (ir_rvalue *)op[0]->clone(NULL), temp_rhs, + op[0]->clone(NULL), temp_rhs, this->subexpressions[0]->get_location()); type = result->type; error_emitted = op[0]->type->is_error(); @@ -1133,10 +1133,10 @@ ast_expression::hir(exec_list *instructions, /* Get a temporary of a copy of the lvalue before it's modified. * This may get thrown away later. */ - result = get_lvalue_copy(instructions, (ir_rvalue *)op[0]->clone(NULL)); + result = get_lvalue_copy(instructions, op[0]->clone(NULL)); (void)do_assignment(instructions, state, - (ir_rvalue *)op[0]->clone(NULL), temp_rhs, + op[0]->clone(NULL), temp_rhs, this->subexpressions[0]->get_location()); type = result->type; diff --git a/src/glsl/ir.h b/src/glsl/ir.h index c19bd417c3..500a8c7a00 100644 --- a/src/glsl/ir.h +++ b/src/glsl/ir.h @@ -94,6 +94,8 @@ protected: class ir_rvalue : public ir_instruction { public: + virtual ir_rvalue *clone(struct hash_table *) const = 0; + virtual ir_rvalue * as_rvalue() { return this; @@ -154,7 +156,7 @@ class ir_variable : public ir_instruction { public: ir_variable(const struct glsl_type *, const char *); - virtual ir_instruction *clone(struct hash_table *ht) const; + virtual ir_variable *clone(struct hash_table *ht) const; virtual ir_variable *as_variable() { @@ -258,7 +260,7 @@ class ir_function_signature : public ir_instruction { public: ir_function_signature(const glsl_type *return_type); - virtual ir_instruction *clone(struct hash_table *ht) const; + virtual ir_function_signature *clone(struct hash_table *ht) const; virtual void accept(ir_visitor *v) { @@ -324,7 +326,7 @@ class ir_function : public ir_instruction { public: ir_function(const char *name); - virtual ir_instruction *clone(struct hash_table *ht) const; + virtual ir_function *clone(struct hash_table *ht) const; virtual ir_function *as_function() { @@ -394,7 +396,7 @@ public: /* empty */ } - virtual ir_instruction *clone(struct hash_table *ht) const; + virtual ir_if *clone(struct hash_table *ht) const; virtual ir_if *as_if() { @@ -426,7 +428,7 @@ public: /* empty */ } - virtual ir_instruction *clone(struct hash_table *ht) const; + virtual ir_loop *clone(struct hash_table *ht) const; virtual void accept(ir_visitor *v) { @@ -467,7 +469,7 @@ class ir_assignment : public ir_rvalue { public: ir_assignment(ir_rvalue *lhs, ir_rvalue *rhs, ir_rvalue *condition); - virtual ir_instruction *clone(struct hash_table *ht) const; + virtual ir_assignment *clone(struct hash_table *ht) const; virtual void accept(ir_visitor *v) { @@ -601,7 +603,7 @@ public: ir_expression(int op, const struct glsl_type *type, ir_rvalue *, ir_rvalue *); - virtual ir_instruction *clone(struct hash_table *ht) const; + virtual ir_expression *clone(struct hash_table *ht) const; static unsigned int get_num_operands(ir_expression_operation); unsigned int get_num_operands() const @@ -644,7 +646,7 @@ public: actual_parameters->move_nodes_to(& this->actual_parameters); } - virtual ir_instruction *clone(struct hash_table *ht) const; + virtual ir_call *clone(struct hash_table *ht) const; virtual ir_call *as_call() { @@ -734,7 +736,7 @@ public: /* empty */ } - virtual ir_instruction *clone(struct hash_table *) const; + virtual ir_return *clone(struct hash_table *) const; virtual ir_return *as_return() { @@ -778,7 +780,7 @@ public: this->loop = loop; } - virtual ir_instruction *clone(struct hash_table *) const; + virtual ir_loop_jump *clone(struct hash_table *) const; virtual void accept(ir_visitor *v) { @@ -819,7 +821,7 @@ public: this->condition = cond; } - virtual ir_instruction *clone(struct hash_table *ht) const; + virtual ir_discard *clone(struct hash_table *ht) const; virtual void accept(ir_visitor *v) { @@ -871,7 +873,7 @@ public: /* empty */ } - virtual ir_instruction *clone(struct hash_table *) const; + virtual ir_texture *clone(struct hash_table *) const; virtual void accept(ir_visitor *v) { @@ -961,7 +963,7 @@ public: ir_swizzle(ir_rvalue *val, ir_swizzle_mask mask); - virtual ir_instruction *clone(struct hash_table *) const; + virtual ir_swizzle *clone(struct hash_table *) const; virtual ir_swizzle *as_swizzle() { @@ -1005,6 +1007,8 @@ private: class ir_dereference : public ir_rvalue { public: + virtual ir_dereference *clone(struct hash_table *) const = 0; + virtual ir_dereference *as_dereference() { return this; @@ -1023,7 +1027,7 @@ class ir_dereference_variable : public ir_dereference { public: ir_dereference_variable(ir_variable *var); - virtual ir_instruction *clone(struct hash_table *) const; + virtual ir_dereference_variable *clone(struct hash_table *) const; virtual ir_dereference_variable *as_dereference_variable() { @@ -1069,7 +1073,7 @@ public: ir_dereference_array(ir_variable *var, ir_rvalue *array_index); - virtual ir_instruction *clone(struct hash_table *) const; + virtual ir_dereference_array *clone(struct hash_table *) const; virtual ir_dereference_array *as_dereference_array() { @@ -1105,7 +1109,7 @@ public: ir_dereference_record(ir_variable *var, const char *field); - virtual ir_instruction *clone(struct hash_table *) const; + virtual ir_dereference_record *clone(struct hash_table *) const; /** * Get the variable that is ultimately referenced by an r-value @@ -1163,7 +1167,7 @@ public: */ ir_constant(const ir_constant *c, unsigned i); - virtual ir_instruction *clone(struct hash_table *) const; + virtual ir_constant *clone(struct hash_table *) const; virtual ir_constant *as_constant() { diff --git a/src/glsl/ir_clone.cpp b/src/glsl/ir_clone.cpp index 74cc858bda..cf21c24d73 100644 --- a/src/glsl/ir_clone.cpp +++ b/src/glsl/ir_clone.cpp @@ -35,7 +35,7 @@ extern "C" { * This will probably be made \c virtual and moved to the base class * eventually. */ -ir_instruction * +ir_variable * ir_variable::clone(struct hash_table *ht) const { void *ctx = talloc_parent(this); @@ -55,14 +55,14 @@ ir_variable::clone(struct hash_table *ht) const return var; } -ir_instruction * +ir_swizzle * ir_swizzle::clone(struct hash_table *ht) const { void *ctx = talloc_parent(this); return new(ctx) ir_swizzle((ir_rvalue *)this->val->clone(ht), this->mask); } -ir_instruction * +ir_return * ir_return::clone(struct hash_table *ht) const { void *ctx = talloc_parent(this); @@ -74,7 +74,7 @@ ir_return::clone(struct hash_table *ht) const return new(ctx) ir_return(new_value); } -ir_instruction * +ir_discard * ir_discard::clone(struct hash_table *ht) const { void *ctx = talloc_parent(this); @@ -86,7 +86,7 @@ ir_discard::clone(struct hash_table *ht) const return new(ctx) ir_discard(new_condition); } -ir_instruction * +ir_loop_jump * ir_loop_jump::clone(struct hash_table *ht) const { void *ctx = talloc_parent(this); @@ -95,7 +95,7 @@ ir_loop_jump::clone(struct hash_table *ht) const return new(ctx) ir_loop_jump(this->mode); } -ir_instruction * +ir_if * ir_if::clone(struct hash_table *ht) const { void *ctx = talloc_parent(this); @@ -114,7 +114,7 @@ ir_if::clone(struct hash_table *ht) const return new_if; } -ir_instruction * +ir_loop * ir_loop::clone(struct hash_table *ht) const { void *ctx = talloc_parent(this); @@ -136,7 +136,7 @@ ir_loop::clone(struct hash_table *ht) const return new_loop; } -ir_instruction * +ir_call * ir_call::clone(struct hash_table *ht) const { void *ctx = talloc_parent(this); @@ -150,7 +150,7 @@ ir_call::clone(struct hash_table *ht) const return new(ctx) ir_call(this->callee, &new_parameters); } -ir_instruction * +ir_expression * ir_expression::clone(struct hash_table *ht) const { void *ctx = talloc_parent(this); @@ -164,7 +164,7 @@ ir_expression::clone(struct hash_table *ht) const return new(ctx) ir_expression(this->operation, this->type, op[0], op[1]); } -ir_instruction * +ir_dereference_variable * ir_dereference_variable::clone(struct hash_table *ht) const { void *ctx = talloc_parent(this); @@ -181,7 +181,7 @@ ir_dereference_variable::clone(struct hash_table *ht) const return new(ctx) ir_dereference_variable(new_var); } -ir_instruction * +ir_dereference_array * ir_dereference_array::clone(struct hash_table *ht) const { void *ctx = talloc_parent(this); @@ -189,7 +189,7 @@ ir_dereference_array::clone(struct hash_table *ht) const (ir_rvalue *)this->array_index->clone(ht)); } -ir_instruction * +ir_dereference_record * ir_dereference_record::clone(struct hash_table *ht) const { void *ctx = talloc_parent(this); @@ -197,7 +197,7 @@ ir_dereference_record::clone(struct hash_table *ht) const this->field); } -ir_instruction * +ir_texture * ir_texture::clone(struct hash_table *ht) const { void *ctx = talloc_parent(this); @@ -236,7 +236,7 @@ ir_texture::clone(struct hash_table *ht) const return new_tex; } -ir_instruction * +ir_assignment * ir_assignment::clone(struct hash_table *ht) const { ir_rvalue *new_condition = NULL; @@ -250,7 +250,7 @@ ir_assignment::clone(struct hash_table *ht) const new_condition); } -ir_instruction * +ir_function * ir_function::clone(struct hash_table *ht) const { (void)ht; @@ -258,7 +258,7 @@ ir_function::clone(struct hash_table *ht) const abort(); } -ir_instruction * +ir_function_signature * ir_function_signature::clone(struct hash_table *ht) const { (void)ht; @@ -266,7 +266,7 @@ ir_function_signature::clone(struct hash_table *ht) const abort(); } -ir_instruction * +ir_constant * ir_constant::clone(struct hash_table *ht) const { void *ctx = talloc_parent(this); diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index 11c810bc48..541398a91c 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -626,7 +626,7 @@ ir_constant_visitor::visit(ir_dereference_variable *ir) ir_variable *var = ir->variable_referenced(); if (var && var->constant_value) - value = (ir_constant *)var->constant_value->clone(NULL); + value = var->constant_value->clone(NULL); } diff --git a/src/glsl/ir_function_inlining.cpp b/src/glsl/ir_function_inlining.cpp index b3d1f1d167..6fe1264b0a 100644 --- a/src/glsl/ir_function_inlining.cpp +++ b/src/glsl/ir_function_inlining.cpp @@ -137,7 +137,7 @@ ir_call::generate_inline(ir_instruction *next_ir) ir_rvalue *param = (ir_rvalue *) param_iter.get(); /* Generate a new variable for the parameter. */ - parameters[i] = (ir_variable *)sig_param->clone(ht); + parameters[i] = sig_param->clone(ht); parameters[i]->mode = ir_var_auto; next_ir->insert_before(parameters[i]); -- cgit v1.2.3 From 570dc0d4004bf09d257b3e4c8664d3c26a8af510 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Wed, 7 Jul 2010 09:07:09 -0700 Subject: glsl2: Avoid null deref in scalar constant unop expressions. --- src/glsl/ir_constant_expression.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index 541398a91c..98cbb6cec6 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -151,7 +151,12 @@ ir_constant_visitor::visit(ir_expression *ir) */ unsigned c0_inc = op0_scalar ? 1 : 0; unsigned c1_inc = op1_scalar ? 1 : 0; - unsigned components = op[op1_scalar ? 0 : 1]->type->components(); + unsigned components; + if (op1_scalar || !op[1]) { + components = op[0]->type->components(); + } else { + components = op[1]->type->components(); + } switch (ir->operation) { case ir_unop_logic_not: -- cgit v1.2.3 From acf88f2769c15c9185abe5bd76a885218f431e58 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Wed, 7 Jul 2010 12:08:23 -0700 Subject: ir_constant_expression: Fix loop increments. --- src/glsl/ir_constant_expression.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index 98cbb6cec6..0fe93adcea 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -149,8 +149,8 @@ ir_constant_visitor::visit(ir_expression *ir) /* When iterating over a vector or matrix's components, we want to increase * the loop counter. However, for scalars, we want to stay at 0. */ - unsigned c0_inc = op0_scalar ? 1 : 0; - unsigned c1_inc = op1_scalar ? 1 : 0; + unsigned c0_inc = op0_scalar ? 0 : 1; + unsigned c1_inc = op1_scalar ? 0 : 1; unsigned components; if (op1_scalar || !op[1]) { components = op[0]->type->components(); -- cgit v1.2.3 From 5e840dba4412b33ae49289efd357a60098ac2611 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Thu, 8 Jul 2010 23:09:48 -0700 Subject: ir_constant_expression: Remove bogus assert in ir_unop_abs case. abs is defined for integral types; it's even implemented. --- src/glsl/ir_constant_expression.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index 0fe93adcea..06d7dd8fbe 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -243,7 +243,6 @@ ir_constant_visitor::visit(ir_expression *ir) break; case ir_unop_abs: - assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { switch (ir->type->base_type) { case GLSL_TYPE_UINT: -- cgit v1.2.3 From 14b7b2660c771aa090477c11f85da998ec3d2570 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Thu, 8 Jul 2010 23:11:14 -0700 Subject: ir_constant_expression: Add support for ir_unop_sign. --- src/glsl/ir_constant_expression.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index 06d7dd8fbe..5ba6264dd6 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -262,6 +262,24 @@ ir_constant_visitor::visit(ir_expression *ir) } break; + case ir_unop_sign: + for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { + switch (ir->type->base_type) { + case GLSL_TYPE_UINT: + data.u[c] = op[0]->value.i[c] > 0; + break; + case GLSL_TYPE_INT: + data.i[c] = (op[0]->value.i[c] > 0) - (op[0]->value.i[c] < 0); + break; + case GLSL_TYPE_FLOAT: + data.f[c] = float((op[0]->value.f[c] > 0)-(op[0]->value.f[c] < 0)); + break; + default: + assert(0); + } + } + break; + case ir_unop_rcp: assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { -- cgit v1.2.3 From aca01edc8336fd14005a7ac853e7158f31a74940 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Thu, 8 Jul 2010 23:14:32 -0700 Subject: ir_constant_expression: Add support for ir_unop_exp2. This uses a C99 function. --- src/glsl/ir_constant_expression.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index 5ba6264dd6..871bce43b7 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -323,6 +323,13 @@ ir_constant_visitor::visit(ir_expression *ir) } break; + case ir_unop_exp2: + assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); + for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { + data.f[c] = exp2f(op[0]->value.f[c]); + } + break; + case ir_unop_log: assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { -- cgit v1.2.3 From cb63929df4ce17e94e8ead0316a00d48b51944c9 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Thu, 8 Jul 2010 23:18:09 -0700 Subject: ir_constant_expression: Add support for ir_unop_log2. This uses a C99 function. --- src/glsl/ir_constant_expression.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index 871bce43b7..292461e5eb 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -337,6 +337,13 @@ ir_constant_visitor::visit(ir_expression *ir) } break; + case ir_unop_log2: + assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); + for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { + data.f[c] = log2f(op[0]->value.f[c]); + } + break; + case ir_unop_dFdx: case ir_unop_dFdy: assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); -- cgit v1.2.3 From 323d909ab21c9f378903e2027fcfef5ba9e890f9 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Thu, 8 Jul 2010 23:21:36 -0700 Subject: ir_constant_expression: Add support for ir_unop_trunc. This uses a C99 function. --- src/glsl/ir_constant_expression.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index 292461e5eb..09bc5b6bbf 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -206,6 +206,13 @@ ir_constant_visitor::visit(ir_expression *ir) } break; + case ir_unop_trunc: + assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); + for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { + data.f[c] = truncf(op[0]->value.f[c]); + } + break; + case ir_unop_fract: for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { switch (ir->type->base_type) { -- cgit v1.2.3 From c1ee30a14590d73217f7dbd35e6a1839435cc5b4 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Thu, 8 Jul 2010 23:22:36 -0700 Subject: ir_constant_expression: Add support for ir_unop_ceil. --- src/glsl/ir_constant_expression.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index 09bc5b6bbf..19498a3bf9 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -213,6 +213,13 @@ ir_constant_visitor::visit(ir_expression *ir) } break; + case ir_unop_ceil: + assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); + for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { + data.f[c] = ceilf(op[0]->value.f[c]); + } + break; + case ir_unop_fract: for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { switch (ir->type->base_type) { -- cgit v1.2.3 From 074720477ce9de3b4dafceffd7406bcebae1a3b9 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Thu, 8 Jul 2010 23:23:23 -0700 Subject: ir_constant_expression: Add support for ir_unop_floor. --- src/glsl/ir_constant_expression.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index 19498a3bf9..44a69854ad 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -220,6 +220,13 @@ ir_constant_visitor::visit(ir_expression *ir) } break; + case ir_unop_floor: + assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); + for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { + data.f[c] = floorf(op[0]->value.f[c]); + } + break; + case ir_unop_fract: for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { switch (ir->type->base_type) { -- cgit v1.2.3 From 908afd16d1f6b5283a2535e388b6dcb77e6504d2 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Thu, 8 Jul 2010 23:28:50 -0700 Subject: ir_constant_expression: Add support for ir_unop_sin. --- src/glsl/ir_constant_expression.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index 44a69854ad..3d0a5e5fe0 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -245,6 +245,13 @@ ir_constant_visitor::visit(ir_expression *ir) } break; + case ir_unop_sin: + assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); + for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { + data.f[c] = sinf(op[0]->value.f[c]); + } + break; + case ir_unop_neg: for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { switch (ir->type->base_type) { -- cgit v1.2.3 From 3fab376bef8c5f407d4011b89a17ea4fd414f213 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Thu, 8 Jul 2010 23:29:37 -0700 Subject: ir_constant_expression: Add support for ir_unop_cos. --- src/glsl/ir_constant_expression.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index 3d0a5e5fe0..ef8661baf5 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -252,6 +252,13 @@ ir_constant_visitor::visit(ir_expression *ir) } break; + case ir_unop_cos: + assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); + for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { + data.f[c] = cosf(op[0]->value.f[c]); + } + break; + case ir_unop_neg: for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { switch (ir->type->base_type) { -- cgit v1.2.3 From 891a0647e419c0cd2b67e43540936bf0ac94f840 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Thu, 8 Jul 2010 23:35:09 -0700 Subject: ir_constant_expression: Add support for ir_binop_pow. --- src/glsl/ir_constant_expression.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index ef8661baf5..437a3805de 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -387,6 +387,13 @@ ir_constant_visitor::visit(ir_expression *ir) } break; + case ir_binop_pow: + assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); + for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { + data.f[c] = powf(op[0]->value.f[c], op[1]->value.f[c]); + } + break; + case ir_binop_dot: assert(op[0]->type->is_vector() && op[1]->type->is_vector()); data.f[0] = 0; -- cgit v1.2.3 From 79fed377f4625da9ce6a0a32c1e7277a2e90e914 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Fri, 9 Jul 2010 11:53:56 -0700 Subject: ir_constant_expression: Add support for ir_binop_min and ir_binop_max. These now work on scalar/vector combos. Semantically, if a is a scalar, min(a, vec2(x,y)) == vec2(min(a,x), min(a,y)) --- src/glsl/ir_constant_expression.cpp | 47 +++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index 437a3805de..7e276e1c25 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -38,6 +38,9 @@ #include "ir_visitor.h" #include "glsl_types.h" +#define min(x,y) (x) < (y) ? (x) : (y) +#define max(x,y) (x) > (y) ? (x) : (y) + /** * Visitor class for evaluating constant expressions */ @@ -413,6 +416,50 @@ ir_constant_visitor::visit(ir_expression *ir) } } + break; + case ir_binop_min: + assert(op[0]->type == op[1]->type || op0_scalar || op1_scalar); + for (unsigned c = 0, c0 = 0, c1 = 0; + c < components; + c0 += c0_inc, c1 += c1_inc, c++) { + + switch (ir->operands[0]->type->base_type) { + case GLSL_TYPE_UINT: + data.u[c] = min(op[0]->value.u[c0], op[1]->value.u[c1]); + break; + case GLSL_TYPE_INT: + data.i[c] = min(op[0]->value.i[c0], op[1]->value.i[c1]); + break; + case GLSL_TYPE_FLOAT: + data.f[c] = min(op[0]->value.f[c0], op[1]->value.f[c1]); + break; + default: + assert(0); + } + } + + break; + case ir_binop_max: + assert(op[0]->type == op[1]->type || op0_scalar || op1_scalar); + for (unsigned c = 0, c0 = 0, c1 = 0; + c < components; + c0 += c0_inc, c1 += c1_inc, c++) { + + switch (ir->operands[0]->type->base_type) { + case GLSL_TYPE_UINT: + data.u[c] = max(op[0]->value.u[c0], op[1]->value.u[c1]); + break; + case GLSL_TYPE_INT: + data.i[c] = max(op[0]->value.i[c0], op[1]->value.i[c1]); + break; + case GLSL_TYPE_FLOAT: + data.f[c] = max(op[0]->value.f[c0], op[1]->value.f[c1]); + break; + default: + assert(0); + } + } + break; case ir_binop_add: assert(op[0]->type == op[1]->type || op0_scalar || op1_scalar); -- cgit v1.2.3 From ce5ae5f49d82b545ab204b9fdb9a8f939e0a6d78 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Wed, 14 Jul 2010 11:28:40 -0700 Subject: ir_constant_expression: Add support for ir_binop_mod. --- src/glsl/ir_constant_expression.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index 7e276e1c25..c0fe47067b 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -575,6 +575,33 @@ ir_constant_visitor::visit(ir_expression *ir) } break; + case ir_binop_mod: + assert(op[0]->type == op[1]->type || op0_scalar || op1_scalar); + for (unsigned c = 0, c0 = 0, c1 = 0; + c < components; + c0 += c0_inc, c1 += c1_inc, c++) { + + switch (ir->operands[0]->type->base_type) { + case GLSL_TYPE_UINT: + data.u[c] = op[0]->value.u[c0] % op[1]->value.u[c1]; + break; + case GLSL_TYPE_INT: + data.i[c] = op[0]->value.i[c0] % op[1]->value.i[c1]; + break; + case GLSL_TYPE_FLOAT: + /* We don't use fmod because it rounds toward zero; GLSL specifies + * the use of floor. + */ + data.f[c] = (op[0]->value.f[c0] - op[1]->value.f[c1]) + * floorf(op[0]->value.f[c0] / op[1]->value.f[c1]); + break; + default: + assert(0); + } + } + + break; + case ir_binop_logic_and: assert(op[0]->type->base_type == GLSL_TYPE_BOOL); for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) -- cgit v1.2.3 From 9be7f638130f46a9df2bfbcd4a03b36de9e4f3aa Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Tue, 13 Jul 2010 15:37:57 -0700 Subject: glsl2: Make cross() be an expression operation. ARB_fp, ARB_vp, Mesa IR, and the 965 vertex shader all have instructions for cross. Shaves 12 Mesa instructions off of a 66-instruction shader I have. --- src/glsl/builtin_function.cpp | 12 +----------- src/glsl/builtins/110/cross | 12 +----------- src/glsl/ir.cpp | 2 ++ src/glsl/ir.h | 1 + src/glsl/ir_constant_expression.cpp | 11 +++++++++++ src/mesa/shader/ir_to_mesa.cpp | 5 +++++ 6 files changed, 21 insertions(+), 22 deletions(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/builtin_function.cpp b/src/glsl/builtin_function.cpp index 1cf88ada16..b3a283306d 100644 --- a/src/glsl/builtin_function.cpp +++ b/src/glsl/builtin_function.cpp @@ -486,17 +486,7 @@ static const char *builtins_110_cross = { " (parameters\n" " (declare (in) vec3 arg0)\n" " (declare (in) vec3 arg1))\n" - " ((declare () vec3 t)\n" - " (assign (constant bool (1)) (swiz x (var_ref t))\n" - " (expression float - (expression float * (swiz y (var_ref arg0)) (swiz z (var_ref arg1)))\n" - " (expression float * (swiz y (var_ref arg1)) (swiz z (var_ref arg0)))))\n" - " (assign (constant bool (1)) (swiz y (var_ref t))\n" - " (expression float - (expression float * (swiz z (var_ref arg0)) (swiz x (var_ref arg1)))\n" - " (expression float * (swiz z (var_ref arg1)) (swiz x (var_ref arg0)))))\n" - " (assign (constant bool (1)) (swiz z (var_ref t))\n" - " (expression float - (expression float * (swiz x (var_ref arg0)) (swiz y (var_ref arg1)))\n" - " (expression float * (swiz x (var_ref arg1)) (swiz y (var_ref arg0)))))\n" - " (return (var_ref t))))\n" + " ((return (expression vec3 cross (var_ref arg0) (var_ref arg1)))))\n" "))\n" }; diff --git a/src/glsl/builtins/110/cross b/src/glsl/builtins/110/cross index deb2f952bf..24717a2183 100644 --- a/src/glsl/builtins/110/cross +++ b/src/glsl/builtins/110/cross @@ -3,15 +3,5 @@ (parameters (declare (in) vec3 arg0) (declare (in) vec3 arg1)) - ((declare () vec3 t) - (assign (constant bool (1)) (swiz x (var_ref t)) - (expression float - (expression float * (swiz y (var_ref arg0)) (swiz z (var_ref arg1))) - (expression float * (swiz y (var_ref arg1)) (swiz z (var_ref arg0))))) - (assign (constant bool (1)) (swiz y (var_ref t)) - (expression float - (expression float * (swiz z (var_ref arg0)) (swiz x (var_ref arg1))) - (expression float * (swiz z (var_ref arg1)) (swiz x (var_ref arg0))))) - (assign (constant bool (1)) (swiz z (var_ref t)) - (expression float - (expression float * (swiz x (var_ref arg0)) (swiz y (var_ref arg1))) - (expression float * (swiz x (var_ref arg1)) (swiz y (var_ref arg0))))) - (return (var_ref t)))) + ((return (expression vec3 cross (var_ref arg0) (var_ref arg1))))) )) diff --git a/src/glsl/ir.cpp b/src/glsl/ir.cpp index 6d89913286..fcf5deced8 100644 --- a/src/glsl/ir.cpp +++ b/src/glsl/ir.cpp @@ -104,6 +104,7 @@ ir_expression::get_num_operands(ir_expression_operation op) 2, /* ir_binop_logic_or */ 2, /* ir_binop_dot */ + 2, /* ir_binop_cross */ 2, /* ir_binop_min */ 2, /* ir_binop_max */ @@ -163,6 +164,7 @@ static const char *const operator_strs[] = { "^^", "||", "dot", + "cross", "min", "max", "pow", diff --git a/src/glsl/ir.h b/src/glsl/ir.h index 790173ed6b..9d7af2dcab 100644 --- a/src/glsl/ir.h +++ b/src/glsl/ir.h @@ -609,6 +609,7 @@ enum ir_expression_operation { ir_binop_logic_or, ir_binop_dot, + ir_binop_cross, ir_binop_min, ir_binop_max, diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index c0fe47067b..ca834978f4 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -459,8 +459,19 @@ ir_constant_visitor::visit(ir_expression *ir) assert(0); } } + break; + case ir_binop_cross: + assert(op[0]->type == glsl_type::vec3_type); + assert(op[1]->type == glsl_type::vec3_type); + data.f[0] = (op[0]->value.f[1] * op[1]->value.f[2] - + op[1]->value.f[1] * op[0]->value.f[2]); + data.f[1] = (op[0]->value.f[2] * op[1]->value.f[0] - + op[1]->value.f[2] * op[0]->value.f[0]); + data.f[2] = (op[0]->value.f[0] * op[1]->value.f[1] - + op[1]->value.f[0] * op[0]->value.f[1]); break; + case ir_binop_add: assert(op[0]->type == op[1]->type || op0_scalar || op1_scalar); for (unsigned c = 0, c0 = 0, c1 = 0; diff --git a/src/mesa/shader/ir_to_mesa.cpp b/src/mesa/shader/ir_to_mesa.cpp index 6ecc6d317c..f99a1fc450 100644 --- a/src/mesa/shader/ir_to_mesa.cpp +++ b/src/mesa/shader/ir_to_mesa.cpp @@ -781,6 +781,11 @@ ir_to_mesa_visitor::visit(ir_expression *ir) op[0], op[1]); } break; + + case ir_binop_cross: + ir_to_mesa_emit_op2(ir, OPCODE_XPD, result_dst, op[0], op[1]); + break; + case ir_unop_sqrt: ir_to_mesa_emit_scalar_op1(ir, OPCODE_RSQ, result_dst, op[0]); ir_to_mesa_emit_scalar_op1(ir, OPCODE_RCP, result_dst, result_src); -- cgit v1.2.3 From e340854115f2562109c91fa908ffe6628432f989 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Mon, 12 Jul 2010 13:55:10 -0700 Subject: glsl2: Move constant_expression_value method to ir_rvalue. This prevents top-level callers from asking for the value of something that is guaranteed not to have one. --- src/glsl/ir.h | 4 ++-- src/glsl/ir_constant_expression.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir.h b/src/glsl/ir.h index 1d667be89c..b6cd1bae31 100644 --- a/src/glsl/ir.h +++ b/src/glsl/ir.h @@ -71,8 +71,6 @@ public: enum ir_node_type ir_type; const struct glsl_type *type; - class ir_constant *constant_expression_value(); - /** ir_print_visitor helper for debugging. */ void print(void) const; @@ -114,6 +112,8 @@ protected: class ir_rvalue : public ir_instruction { public: + class ir_constant *constant_expression_value(); + virtual ir_rvalue *clone(struct hash_table *) const = 0; virtual ir_rvalue * as_rvalue() diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index ca834978f4..44f4a64209 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -96,7 +96,7 @@ public: ir_constant * -ir_instruction::constant_expression_value() +ir_rvalue::constant_expression_value() { ir_constant_visitor visitor; -- cgit v1.2.3 From fb2ffd2846b48cb50128fb74df56f2ee63179832 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Thu, 15 Jul 2010 10:09:09 -0700 Subject: ir_constant_expression: Convert from a visitor to a virtual function. The constant_expression_wrapper was already the only external API, and much of the internal code used it anyway. Also, it wouldn't ever visit non-rvalue ir_instructions, so using a visitor seemed a bit unnecessary. This uses "ir_foo *ir = this;" lines to avoid code churn. These should be removed. --- src/glsl/ir.h | 22 +++- src/glsl/ir_constant_expression.cpp | 207 +++++++----------------------------- 2 files changed, 60 insertions(+), 169 deletions(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir.h b/src/glsl/ir.h index b6cd1bae31..3be096270d 100644 --- a/src/glsl/ir.h +++ b/src/glsl/ir.h @@ -112,10 +112,10 @@ protected: class ir_rvalue : public ir_instruction { public: - class ir_constant *constant_expression_value(); - virtual ir_rvalue *clone(struct hash_table *) const = 0; + virtual ir_constant *constant_expression_value() = 0; + virtual ir_rvalue * as_rvalue() { return this; @@ -511,6 +511,8 @@ public: virtual ir_assignment *clone(struct hash_table *ht) const; + virtual ir_constant *constant_expression_value(); + virtual void accept(ir_visitor *v) { v->visit(this); @@ -651,6 +653,8 @@ public: virtual ir_expression *clone(struct hash_table *ht) const; + virtual ir_constant *constant_expression_value(); + static unsigned int get_num_operands(ir_expression_operation); unsigned int get_num_operands() const { @@ -695,6 +699,8 @@ public: virtual ir_call *clone(struct hash_table *ht) const; + virtual ir_constant *constant_expression_value(); + virtual ir_call *as_call() { return this; @@ -929,6 +935,8 @@ public: virtual ir_texture *clone(struct hash_table *) const; + virtual ir_constant *constant_expression_value(); + virtual void accept(ir_visitor *v) { v->visit(this); @@ -1019,6 +1027,8 @@ public: virtual ir_swizzle *clone(struct hash_table *) const; + virtual ir_constant *constant_expression_value(); + virtual ir_swizzle *as_swizzle() { return this; @@ -1083,6 +1093,8 @@ public: virtual ir_dereference_variable *clone(struct hash_table *) const; + virtual ir_constant *constant_expression_value(); + virtual ir_dereference_variable *as_dereference_variable() { return this; @@ -1129,6 +1141,8 @@ public: virtual ir_dereference_array *clone(struct hash_table *) const; + virtual ir_constant *constant_expression_value(); + virtual ir_dereference_array *as_dereference_array() { return this; @@ -1165,6 +1179,8 @@ public: virtual ir_dereference_record *clone(struct hash_table *) const; + virtual ir_constant *constant_expression_value(); + /** * Get the variable that is ultimately referenced by an r-value */ @@ -1223,6 +1239,8 @@ public: virtual ir_constant *clone(struct hash_table *) const; + virtual ir_constant *constant_expression_value(); + virtual ir_constant *as_constant() { return this; diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index 44f4a64209..e3e717a14e 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -41,97 +41,10 @@ #define min(x,y) (x) < (y) ? (x) : (y) #define max(x,y) (x) > (y) ? (x) : (y) -/** - * Visitor class for evaluating constant expressions - */ -class ir_constant_visitor : public ir_visitor { -public: - ir_constant_visitor() - : value(NULL) - { - /* empty */ - } - - virtual ~ir_constant_visitor() - { - /* empty */ - } - - /** - * \name Visit methods - * - * As typical for the visitor pattern, there must be one \c visit method for - * each concrete subclass of \c ir_instruction. Virtual base classes within - * the hierarchy should not have \c visit methods. - */ - /*@{*/ - virtual void visit(ir_variable *); - virtual void visit(ir_function_signature *); - virtual void visit(ir_function *); - virtual void visit(ir_expression *); - virtual void visit(ir_texture *); - virtual void visit(ir_swizzle *); - virtual void visit(ir_dereference_variable *); - virtual void visit(ir_dereference_array *); - virtual void visit(ir_dereference_record *); - virtual void visit(ir_assignment *); - virtual void visit(ir_constant *); - virtual void visit(ir_call *); - virtual void visit(ir_return *); - virtual void visit(ir_discard *); - virtual void visit(ir_if *); - virtual void visit(ir_loop *); - virtual void visit(ir_loop_jump *); - /*@}*/ - - /** - * Value of the constant expression. - * - * \note - * This field will be \c NULL if the expression is not constant valued. - */ - /* FINIHSME: This cannot hold values for constant arrays or structures. */ - ir_constant *value; -}; - - ir_constant * -ir_rvalue::constant_expression_value() -{ - ir_constant_visitor visitor; - - this->accept(& visitor); - return visitor.value; -} - - -void -ir_constant_visitor::visit(ir_variable *ir) -{ - (void) ir; - value = NULL; -} - - -void -ir_constant_visitor::visit(ir_function_signature *ir) -{ - (void) ir; - value = NULL; -} - - -void -ir_constant_visitor::visit(ir_function *ir) +ir_expression::constant_expression_value() { - (void) ir; - value = NULL; -} - -void -ir_constant_visitor::visit(ir_expression *ir) -{ - value = NULL; + ir_expression *ir = this; ir_constant *op[2] = { NULL, NULL }; ir_constant_data data; @@ -140,7 +53,7 @@ ir_constant_visitor::visit(ir_expression *ir) for (unsigned operand = 0; operand < ir->get_num_operands(); operand++) { op[operand] = ir->operands[operand]->constant_expression_value(); if (!op[operand]) - return; + return NULL; } if (op[1] != NULL) @@ -735,30 +648,28 @@ ir_constant_visitor::visit(ir_expression *ir) default: /* FINISHME: Should handle all expression types. */ - return; + return NULL; } void *ctx = talloc_parent(ir); - this->value = new(ctx) ir_constant(ir->type, &data); + return new(ctx) ir_constant(ir->type, &data); } -void -ir_constant_visitor::visit(ir_texture *ir) +ir_constant * +ir_texture::constant_expression_value() { - // FINISHME: Do stuff with texture lookups - (void) ir; - value = NULL; + /* texture lookups aren't constant expressions */ + return NULL; } -void -ir_constant_visitor::visit(ir_swizzle *ir) +ir_constant * +ir_swizzle::constant_expression_value() { + ir_swizzle *ir = this; ir_constant *v = ir->val->constant_expression_value(); - this->value = NULL; - if (v != NULL) { ir_constant_data data; @@ -777,31 +688,30 @@ ir_constant_visitor::visit(ir_swizzle *ir) } void *ctx = talloc_parent(ir); - this->value = new(ctx) ir_constant(ir->type, &data); + return new(ctx) ir_constant(ir->type, &data); } + return NULL; } -void -ir_constant_visitor::visit(ir_dereference_variable *ir) +ir_constant * +ir_dereference_variable::constant_expression_value() { - value = NULL; - - ir_variable *var = ir->variable_referenced(); + ir_variable *var = this->variable_referenced(); if (var && var->constant_value) - value = var->constant_value->clone(NULL); + return var->constant_value->clone(NULL); + return NULL; } -void -ir_constant_visitor::visit(ir_dereference_array *ir) +ir_constant * +ir_dereference_array::constant_expression_value() { + ir_dereference_array *ir = this; void *ctx = talloc_parent(ir); ir_constant *array = ir->array->constant_expression_value(); ir_constant *idx = ir->array_index->constant_expression_value(); - this->value = NULL; - if ((array != NULL) && (idx != NULL)) { if (array->type->is_matrix()) { /* Array access of a matrix results in a vector. @@ -836,85 +746,48 @@ ir_constant_visitor::visit(ir_dereference_array *ir) break; } - this->value = new(ctx) ir_constant(column_type, &data); + return new(ctx) ir_constant(column_type, &data); } else if (array->type->is_vector()) { const unsigned component = idx->value.u[0]; - this->value = new(ctx) ir_constant(array, component); + return new(ctx) ir_constant(array, component); } else { /* FINISHME: Handle access of constant arrays. */ } } + return NULL; } -void -ir_constant_visitor::visit(ir_dereference_record *ir) +ir_constant * +ir_dereference_record::constant_expression_value() { + ir_dereference_record *ir = this; ir_constant *v = ir->record->constant_expression_value(); - this->value = (v != NULL) ? v->get_record_field(ir->field) : NULL; -} - - -void -ir_constant_visitor::visit(ir_assignment *ir) -{ - (void) ir; - value = NULL; -} - - -void -ir_constant_visitor::visit(ir_constant *ir) -{ - value = ir; -} - - -void -ir_constant_visitor::visit(ir_call *ir) -{ - (void) ir; - value = NULL; -} - - -void -ir_constant_visitor::visit(ir_return *ir) -{ - (void) ir; - value = NULL; + return (v != NULL) ? v->get_record_field(ir->field) : NULL; } -void -ir_constant_visitor::visit(ir_discard *ir) +ir_constant * +ir_assignment::constant_expression_value() { - (void) ir; - value = NULL; + /* FINISHME: Handle CEs involving assignment (return RHS) */ + return NULL; } -void -ir_constant_visitor::visit(ir_if *ir) +ir_constant * +ir_constant::constant_expression_value() { - (void) ir; - value = NULL; + return this; } -void -ir_constant_visitor::visit(ir_loop *ir) +ir_constant * +ir_call::constant_expression_value() { - (void) ir; - value = NULL; + /* FINISHME: Handle CEs involving builtin function calls. */ + return NULL; } - -void -ir_constant_visitor::visit(ir_loop_jump *ir) -{ - (void) ir; - value = NULL; -} -- cgit v1.2.3 From 98f32a13bef1eef732304eb8e2781e08835ff69a Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Thu, 15 Jul 2010 10:20:51 -0700 Subject: ir_constant_expression: Use "this" pointer directly. In ir_expression's signature, I replaced ir->operands[i] with op[i] as it is more concise; an assertion already ensures these are equal. --- src/glsl/ir_constant_expression.cpp | 132 +++++++++++++++++------------------- 1 file changed, 64 insertions(+), 68 deletions(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index e3e717a14e..186d0c48c1 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -44,14 +44,13 @@ ir_constant * ir_expression::constant_expression_value() { - ir_expression *ir = this; ir_constant *op[2] = { NULL, NULL }; ir_constant_data data; memset(&data, 0, sizeof(data)); - for (unsigned operand = 0; operand < ir->get_num_operands(); operand++) { - op[operand] = ir->operands[operand]->constant_expression_value(); + for (unsigned operand = 0; operand < this->get_num_operands(); operand++) { + op[operand] = this->operands[operand]->constant_expression_value(); if (!op[operand]) return NULL; } @@ -74,23 +73,23 @@ ir_expression::constant_expression_value() components = op[1]->type->components(); } - switch (ir->operation) { + switch (this->operation) { case ir_unop_logic_not: assert(op[0]->type->base_type == GLSL_TYPE_BOOL); - for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) + for (unsigned c = 0; c < op[0]->type->components(); c++) data.b[c] = !op[0]->value.b[c]; break; case ir_unop_f2i: assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); - for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { + for (unsigned c = 0; c < op[0]->type->components(); c++) { data.i[c] = op[0]->value.f[c]; } break; case ir_unop_i2f: assert(op[0]->type->base_type == GLSL_TYPE_UINT || op[0]->type->base_type == GLSL_TYPE_INT); - for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { + for (unsigned c = 0; c < op[0]->type->components(); c++) { if (op[0]->type->base_type == GLSL_TYPE_INT) data.f[c] = op[0]->value.i[c]; else @@ -99,53 +98,53 @@ ir_expression::constant_expression_value() break; case ir_unop_b2f: assert(op[0]->type->base_type == GLSL_TYPE_BOOL); - for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { + for (unsigned c = 0; c < op[0]->type->components(); c++) { data.f[c] = op[0]->value.b[c] ? 1.0 : 0.0; } break; case ir_unop_f2b: assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); - for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { + for (unsigned c = 0; c < op[0]->type->components(); c++) { data.b[c] = bool(op[0]->value.f[c]); } break; case ir_unop_b2i: assert(op[0]->type->base_type == GLSL_TYPE_BOOL); - for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { + for (unsigned c = 0; c < op[0]->type->components(); c++) { data.u[c] = op[0]->value.b[c] ? 1 : 0; } break; case ir_unop_i2b: assert(op[0]->type->is_integer()); - for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { + for (unsigned c = 0; c < op[0]->type->components(); c++) { data.b[c] = bool(op[0]->value.u[c]); } break; case ir_unop_trunc: assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); - for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { + for (unsigned c = 0; c < op[0]->type->components(); c++) { data.f[c] = truncf(op[0]->value.f[c]); } break; case ir_unop_ceil: assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); - for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { + for (unsigned c = 0; c < op[0]->type->components(); c++) { data.f[c] = ceilf(op[0]->value.f[c]); } break; case ir_unop_floor: assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); - for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { + for (unsigned c = 0; c < op[0]->type->components(); c++) { data.f[c] = floorf(op[0]->value.f[c]); } break; case ir_unop_fract: - for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { - switch (ir->type->base_type) { + for (unsigned c = 0; c < op[0]->type->components(); c++) { + switch (this->type->base_type) { case GLSL_TYPE_UINT: data.u[c] = 0; break; @@ -163,21 +162,21 @@ ir_expression::constant_expression_value() case ir_unop_sin: assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); - for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { + for (unsigned c = 0; c < op[0]->type->components(); c++) { data.f[c] = sinf(op[0]->value.f[c]); } break; case ir_unop_cos: assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); - for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { + for (unsigned c = 0; c < op[0]->type->components(); c++) { data.f[c] = cosf(op[0]->value.f[c]); } break; case ir_unop_neg: - for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { - switch (ir->type->base_type) { + for (unsigned c = 0; c < op[0]->type->components(); c++) { + switch (this->type->base_type) { case GLSL_TYPE_UINT: data.u[c] = -op[0]->value.u[c]; break; @@ -194,8 +193,8 @@ ir_expression::constant_expression_value() break; case ir_unop_abs: - for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { - switch (ir->type->base_type) { + for (unsigned c = 0; c < op[0]->type->components(); c++) { + switch (this->type->base_type) { case GLSL_TYPE_UINT: data.u[c] = op[0]->value.u[c]; break; @@ -214,8 +213,8 @@ ir_expression::constant_expression_value() break; case ir_unop_sign: - for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { - switch (ir->type->base_type) { + for (unsigned c = 0; c < op[0]->type->components(); c++) { + switch (this->type->base_type) { case GLSL_TYPE_UINT: data.u[c] = op[0]->value.i[c] > 0; break; @@ -233,8 +232,8 @@ ir_expression::constant_expression_value() case ir_unop_rcp: assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); - for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { - switch (ir->type->base_type) { + for (unsigned c = 0; c < op[0]->type->components(); c++) { + switch (this->type->base_type) { case GLSL_TYPE_UINT: if (op[0]->value.u[c] != 0.0) data.u[c] = 1 / op[0]->value.u[c]; @@ -255,42 +254,42 @@ ir_expression::constant_expression_value() case ir_unop_rsq: assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); - for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { + for (unsigned c = 0; c < op[0]->type->components(); c++) { data.f[c] = 1.0 / sqrtf(op[0]->value.f[c]); } break; case ir_unop_sqrt: assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); - for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { + for (unsigned c = 0; c < op[0]->type->components(); c++) { data.f[c] = sqrtf(op[0]->value.f[c]); } break; case ir_unop_exp: assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); - for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { + for (unsigned c = 0; c < op[0]->type->components(); c++) { data.f[c] = expf(op[0]->value.f[c]); } break; case ir_unop_exp2: assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); - for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { + for (unsigned c = 0; c < op[0]->type->components(); c++) { data.f[c] = exp2f(op[0]->value.f[c]); } break; case ir_unop_log: assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); - for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { + for (unsigned c = 0; c < op[0]->type->components(); c++) { data.f[c] = logf(op[0]->value.f[c]); } break; case ir_unop_log2: assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); - for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { + for (unsigned c = 0; c < op[0]->type->components(); c++) { data.f[c] = log2f(op[0]->value.f[c]); } break; @@ -298,14 +297,14 @@ ir_expression::constant_expression_value() case ir_unop_dFdx: case ir_unop_dFdy: assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); - for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { + for (unsigned c = 0; c < op[0]->type->components(); c++) { data.f[c] = 0.0; } break; case ir_binop_pow: assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); - for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { + for (unsigned c = 0; c < op[0]->type->components(); c++) { data.f[c] = powf(op[0]->value.f[c], op[1]->value.f[c]); } break; @@ -314,7 +313,7 @@ ir_expression::constant_expression_value() assert(op[0]->type->is_vector() && op[1]->type->is_vector()); data.f[0] = 0; for (unsigned c = 0; c < op[0]->type->components(); c++) { - switch (ir->operands[0]->type->base_type) { + switch (op[0]->type->base_type) { case GLSL_TYPE_UINT: data.u[0] += op[0]->value.u[c] * op[1]->value.u[c]; break; @@ -336,7 +335,7 @@ ir_expression::constant_expression_value() c < components; c0 += c0_inc, c1 += c1_inc, c++) { - switch (ir->operands[0]->type->base_type) { + switch (op[0]->type->base_type) { case GLSL_TYPE_UINT: data.u[c] = min(op[0]->value.u[c0], op[1]->value.u[c1]); break; @@ -358,7 +357,7 @@ ir_expression::constant_expression_value() c < components; c0 += c0_inc, c1 += c1_inc, c++) { - switch (ir->operands[0]->type->base_type) { + switch (op[0]->type->base_type) { case GLSL_TYPE_UINT: data.u[c] = max(op[0]->value.u[c0], op[1]->value.u[c1]); break; @@ -391,7 +390,7 @@ ir_expression::constant_expression_value() c < components; c0 += c0_inc, c1 += c1_inc, c++) { - switch (ir->operands[0]->type->base_type) { + switch (op[0]->type->base_type) { case GLSL_TYPE_UINT: data.u[c] = op[0]->value.u[c0] + op[1]->value.u[c1]; break; @@ -413,7 +412,7 @@ ir_expression::constant_expression_value() c < components; c0 += c0_inc, c1 += c1_inc, c++) { - switch (ir->operands[0]->type->base_type) { + switch (op[0]->type->base_type) { case GLSL_TYPE_UINT: data.u[c] = op[0]->value.u[c0] - op[1]->value.u[c1]; break; @@ -437,7 +436,7 @@ ir_expression::constant_expression_value() c < components; c0 += c0_inc, c1 += c1_inc, c++) { - switch (ir->operands[0]->type->base_type) { + switch (op[0]->type->base_type) { case GLSL_TYPE_UINT: data.u[c] = op[0]->value.u[c0] * op[1]->value.u[c1]; break; @@ -483,7 +482,7 @@ ir_expression::constant_expression_value() c < components; c0 += c0_inc, c1 += c1_inc, c++) { - switch (ir->operands[0]->type->base_type) { + switch (op[0]->type->base_type) { case GLSL_TYPE_UINT: data.u[c] = op[0]->value.u[c0] / op[1]->value.u[c1]; break; @@ -505,7 +504,7 @@ ir_expression::constant_expression_value() c < components; c0 += c0_inc, c1 += c1_inc, c++) { - switch (ir->operands[0]->type->base_type) { + switch (op[0]->type->base_type) { case GLSL_TYPE_UINT: data.u[c] = op[0]->value.u[c0] % op[1]->value.u[c1]; break; @@ -528,22 +527,22 @@ ir_expression::constant_expression_value() case ir_binop_logic_and: assert(op[0]->type->base_type == GLSL_TYPE_BOOL); - for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) + for (unsigned c = 0; c < op[0]->type->components(); c++) data.b[c] = op[0]->value.b[c] && op[1]->value.b[c]; break; case ir_binop_logic_xor: assert(op[0]->type->base_type == GLSL_TYPE_BOOL); - for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) + for (unsigned c = 0; c < op[0]->type->components(); c++) data.b[c] = op[0]->value.b[c] ^ op[1]->value.b[c]; break; case ir_binop_logic_or: assert(op[0]->type->base_type == GLSL_TYPE_BOOL); - for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) + for (unsigned c = 0; c < op[0]->type->components(); c++) data.b[c] = op[0]->value.b[c] || op[1]->value.b[c]; break; case ir_binop_less: - switch (ir->operands[0]->type->base_type) { + switch (op[0]->type->base_type) { case GLSL_TYPE_UINT: data.b[0] = op[0]->value.u[0] < op[1]->value.u[0]; break; @@ -558,7 +557,7 @@ ir_expression::constant_expression_value() } break; case ir_binop_greater: - switch (ir->operands[0]->type->base_type) { + switch (op[0]->type->base_type) { case GLSL_TYPE_UINT: data.b[0] = op[0]->value.u[0] > op[1]->value.u[0]; break; @@ -573,7 +572,7 @@ ir_expression::constant_expression_value() } break; case ir_binop_lequal: - switch (ir->operands[0]->type->base_type) { + switch (op[0]->type->base_type) { case GLSL_TYPE_UINT: data.b[0] = op[0]->value.u[0] <= op[1]->value.u[0]; break; @@ -588,7 +587,7 @@ ir_expression::constant_expression_value() } break; case ir_binop_gequal: - switch (ir->operands[0]->type->base_type) { + switch (op[0]->type->base_type) { case GLSL_TYPE_UINT: data.b[0] = op[0]->value.u[0] >= op[1]->value.u[0]; break; @@ -605,8 +604,8 @@ ir_expression::constant_expression_value() case ir_binop_equal: data.b[0] = true; - for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { - switch (ir->operands[0]->type->base_type) { + for (unsigned c = 0; c < op[0]->type->components(); c++) { + switch (op[0]->type->base_type) { case GLSL_TYPE_UINT: data.b[0] = data.b[0] && op[0]->value.u[c] == op[1]->value.u[c]; break; @@ -626,8 +625,8 @@ ir_expression::constant_expression_value() break; case ir_binop_nequal: data.b[0] = false; - for (unsigned c = 0; c < ir->operands[0]->type->components(); c++) { - switch (ir->operands[0]->type->base_type) { + for (unsigned c = 0; c < op[0]->type->components(); c++) { + switch (op[0]->type->base_type) { case GLSL_TYPE_UINT: data.b[0] = data.b[0] || op[0]->value.u[c] != op[1]->value.u[c]; break; @@ -651,8 +650,8 @@ ir_expression::constant_expression_value() return NULL; } - void *ctx = talloc_parent(ir); - return new(ctx) ir_constant(ir->type, &data); + void *ctx = talloc_parent(this); + return new(ctx) ir_constant(this->type, &data); } @@ -667,17 +666,16 @@ ir_texture::constant_expression_value() ir_constant * ir_swizzle::constant_expression_value() { - ir_swizzle *ir = this; - ir_constant *v = ir->val->constant_expression_value(); + ir_constant *v = this->val->constant_expression_value(); if (v != NULL) { ir_constant_data data; const unsigned swiz_idx[4] = { - ir->mask.x, ir->mask.y, ir->mask.z, ir->mask.w + this->mask.x, this->mask.y, this->mask.z, this->mask.w }; - for (unsigned i = 0; i < ir->mask.num_components; i++) { + for (unsigned i = 0; i < this->mask.num_components; i++) { switch (v->type->base_type) { case GLSL_TYPE_UINT: case GLSL_TYPE_INT: data.u[i] = v->value.u[swiz_idx[i]]; break; @@ -687,8 +685,8 @@ ir_swizzle::constant_expression_value() } } - void *ctx = talloc_parent(ir); - return new(ctx) ir_constant(ir->type, &data); + void *ctx = talloc_parent(this); + return new(ctx) ir_constant(this->type, &data); } return NULL; } @@ -707,10 +705,9 @@ ir_dereference_variable::constant_expression_value() ir_constant * ir_dereference_array::constant_expression_value() { - ir_dereference_array *ir = this; - void *ctx = talloc_parent(ir); - ir_constant *array = ir->array->constant_expression_value(); - ir_constant *idx = ir->array_index->constant_expression_value(); + void *ctx = talloc_parent(this); + ir_constant *array = this->array->constant_expression_value(); + ir_constant *idx = this->array_index->constant_expression_value(); if ((array != NULL) && (idx != NULL)) { if (array->type->is_matrix()) { @@ -762,10 +759,9 @@ ir_dereference_array::constant_expression_value() ir_constant * ir_dereference_record::constant_expression_value() { - ir_dereference_record *ir = this; - ir_constant *v = ir->record->constant_expression_value(); + ir_constant *v = this->record->constant_expression_value(); - return (v != NULL) ? v->get_record_field(ir->field) : NULL; + return (v != NULL) ? v->get_record_field(this->field) : NULL; } -- cgit v1.2.3 From e4768eecd5da6f9e955aa7c3892810813623f0dc Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Thu, 15 Jul 2010 10:27:53 -0700 Subject: ir_constant_expression: Remove pointless use of variable_referenced. ir_dereference_variable always references an ir_variable, so there's no point in calling a function and NULL-checking the result. --- src/glsl/ir_constant_expression.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index 186d0c48c1..cb07f38128 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -695,10 +695,7 @@ ir_swizzle::constant_expression_value() ir_constant * ir_dereference_variable::constant_expression_value() { - ir_variable *var = this->variable_referenced(); - if (var && var->constant_value) - return var->constant_value->clone(NULL); - return NULL; + return var->constant_value ? var->constant_value->clone(NULL) : NULL; } -- cgit v1.2.3 From 3163f87463e6d0123c4f95bd76a658cb1e5d0843 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Tue, 20 Jul 2010 03:01:54 -0700 Subject: ir_constant_expression: Remove open coded equality comparisons. The ir_constant::has_value method already does this. --- src/glsl/ir_constant_expression.cpp | 40 ++----------------------------------- 1 file changed, 2 insertions(+), 38 deletions(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index cb07f38128..b0333dbebb 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -603,46 +603,10 @@ ir_expression::constant_expression_value() break; case ir_binop_equal: - data.b[0] = true; - for (unsigned c = 0; c < op[0]->type->components(); c++) { - switch (op[0]->type->base_type) { - case GLSL_TYPE_UINT: - data.b[0] = data.b[0] && op[0]->value.u[c] == op[1]->value.u[c]; - break; - case GLSL_TYPE_INT: - data.b[0] = data.b[0] && op[0]->value.i[c] == op[1]->value.i[c]; - break; - case GLSL_TYPE_FLOAT: - data.b[0] = data.b[0] && op[0]->value.f[c] == op[1]->value.f[c]; - break; - case GLSL_TYPE_BOOL: - data.b[0] = data.b[0] && op[0]->value.b[c] == op[1]->value.b[c]; - break; - default: - assert(0); - } - } + data.b[0] = op[0]->has_value(op[1]); break; case ir_binop_nequal: - data.b[0] = false; - for (unsigned c = 0; c < op[0]->type->components(); c++) { - switch (op[0]->type->base_type) { - case GLSL_TYPE_UINT: - data.b[0] = data.b[0] || op[0]->value.u[c] != op[1]->value.u[c]; - break; - case GLSL_TYPE_INT: - data.b[0] = data.b[0] || op[0]->value.i[c] != op[1]->value.i[c]; - break; - case GLSL_TYPE_FLOAT: - data.b[0] = data.b[0] || op[0]->value.f[c] != op[1]->value.f[c]; - break; - case GLSL_TYPE_BOOL: - data.b[0] = data.b[0] || op[0]->value.b[c] != op[1]->value.b[c]; - break; - default: - assert(0); - } - } + data.b[0] = !op[0]->has_value(op[1]); break; default: -- cgit v1.2.3 From 46d6b8d1ba09d9d6844ce99a30416283004f77c6 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Tue, 20 Jul 2010 13:01:56 -0700 Subject: ir_constant_expression: Add support for ir_unop_u2f. Also make ir_unop_i2f only operate on signed integers. --- src/glsl/ir_constant_expression.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index b0333dbebb..acfbb86459 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -87,13 +87,15 @@ ir_expression::constant_expression_value() } break; case ir_unop_i2f: - assert(op[0]->type->base_type == GLSL_TYPE_UINT || - op[0]->type->base_type == GLSL_TYPE_INT); + assert(op[0]->type->base_type == GLSL_TYPE_INT); for (unsigned c = 0; c < op[0]->type->components(); c++) { - if (op[0]->type->base_type == GLSL_TYPE_INT) - data.f[c] = op[0]->value.i[c]; - else - data.f[c] = op[0]->value.u[c]; + data.f[c] = op[0]->value.i[c]; + } + break; + case ir_unop_u2f: + assert(op[0]->type->base_type == GLSL_TYPE_UINT); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + data.f[c] = op[0]->value.u[c]; } break; case ir_unop_b2f: -- cgit v1.2.3 From a096fa747611472965cf0f953bfe2757fc80383c Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Tue, 20 Jul 2010 01:31:29 -0700 Subject: ir_constant_expression: Add support for constant arrays. Fixes piglit test const-array-02.frag. --- src/glsl/ir_constant_expression.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index acfbb86459..d72a57c66a 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -712,7 +712,8 @@ ir_dereference_array::constant_expression_value() return new(ctx) ir_constant(array, component); } else { - /* FINISHME: Handle access of constant arrays. */ + const unsigned index = idx->value.u[0]; + return array->get_array_element(index)->clone(NULL); } } return NULL; -- cgit v1.2.3 From 9a6d40fbfb679f01412c1fcc9d767c20a22246d8 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Tue, 20 Jul 2010 03:08:32 -0700 Subject: ir_constant_expression: Add support for array == and !=. Piglit parser tests const-array-03.frag and const-array-04.frag now generate the correct code. --- src/glsl/ir.cpp | 11 ++++++++--- src/glsl/ir_constant_expression.cpp | 17 ++++++++++++++++- 2 files changed, 24 insertions(+), 4 deletions(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir.cpp b/src/glsl/ir.cpp index d3f7302b54..5054ec725c 100644 --- a/src/glsl/ir.cpp +++ b/src/glsl/ir.cpp @@ -430,9 +430,14 @@ ir_constant::has_value(const ir_constant *c) const if (this->type != c->type) return false; - /* FINISHME: This will probably also handle constant arrays as soon as those - * FINISHME: are supported. - */ + if (this->type->is_array()) { + for (unsigned i = 0; i < this->type->length; i++) { + if (this->array_elements[i]->has_value(c->array_elements[i])) + return false; + } + return true; + } + if (this->type->base_type == GLSL_TYPE_STRUCT) { const exec_node *a_node = this->components.head; const exec_node *b_node = c->components.head; diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index d72a57c66a..5bef17c755 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -73,6 +73,22 @@ ir_expression::constant_expression_value() components = op[1]->type->components(); } + void *ctx = talloc_parent(this); + + /* Handle array operations here, rather than below. */ + if (op[0]->type->is_array()) { + assert(op[1] != NULL && op[1]->type->is_array()); + switch (this->operation) { + case ir_binop_equal: + return new(ctx) ir_constant(op[0]->has_value(op[1])); + case ir_binop_nequal: + return new(ctx) ir_constant(!op[0]->has_value(op[1])); + default: + break; + } + return NULL; + } + switch (this->operation) { case ir_unop_logic_not: assert(op[0]->type->base_type == GLSL_TYPE_BOOL); @@ -616,7 +632,6 @@ ir_expression::constant_expression_value() return NULL; } - void *ctx = talloc_parent(this); return new(ctx) ir_constant(this->type, &data); } -- cgit v1.2.3 From 3e882ec84a2493da74c55d105010a37de521e593 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Thu, 22 Jul 2010 17:44:34 -0700 Subject: ir_constant_expression: Fix broken code for floating point modulus. It's supposed to be x - y * floor(x/y), not (x - y) * floor(x/y). --- src/glsl/ir_constant_expression.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index 5bef17c755..f15530ae89 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -533,7 +533,7 @@ ir_expression::constant_expression_value() /* We don't use fmod because it rounds toward zero; GLSL specifies * the use of floor. */ - data.f[c] = (op[0]->value.f[c0] - op[1]->value.f[c1]) + data.f[c] = op[0]->value.f[c0] - op[1]->value.f[c1] * floorf(op[0]->value.f[c0] / op[1]->value.f[c1]); break; default: -- cgit v1.2.3 From 54f583a206a15b1a92c547333adfae29ced796ef Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Tue, 27 Jul 2010 12:10:50 -0700 Subject: glsl2: Don't dereference a NULL var in CE handling during a compile error. If an undeclared variable was dereferenced in an expression that needed constant expression handling, we would walk off a null ir->var pointer. Fixes: glsl1-TIntermediate::addUnaryMath --- src/glsl/ir_constant_expression.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index f15530ae89..6a07f4e189 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -676,6 +676,10 @@ ir_swizzle::constant_expression_value() ir_constant * ir_dereference_variable::constant_expression_value() { + /* This may occur during compile and var->type is glsl_type::error_type */ + if (!var) + return NULL; + return var->constant_value ? var->constant_value->clone(NULL) : NULL; } -- cgit v1.2.3 From f914915d8e86f492cfcbbf834df601251bbba033 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Wed, 21 Jul 2010 21:56:13 -0700 Subject: ir_constant_expression: Use Mesa's MIN2/MAX2 instead of our own. --- src/glsl/ir_constant_expression.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index 6a07f4e189..9309b61898 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -34,13 +34,11 @@ */ #include +#include "main/macros.h" #include "ir.h" #include "ir_visitor.h" #include "glsl_types.h" -#define min(x,y) (x) < (y) ? (x) : (y) -#define max(x,y) (x) > (y) ? (x) : (y) - ir_constant * ir_expression::constant_expression_value() { @@ -355,13 +353,13 @@ ir_expression::constant_expression_value() switch (op[0]->type->base_type) { case GLSL_TYPE_UINT: - data.u[c] = min(op[0]->value.u[c0], op[1]->value.u[c1]); + data.u[c] = MIN2(op[0]->value.u[c0], op[1]->value.u[c1]); break; case GLSL_TYPE_INT: - data.i[c] = min(op[0]->value.i[c0], op[1]->value.i[c1]); + data.i[c] = MIN2(op[0]->value.i[c0], op[1]->value.i[c1]); break; case GLSL_TYPE_FLOAT: - data.f[c] = min(op[0]->value.f[c0], op[1]->value.f[c1]); + data.f[c] = MIN2(op[0]->value.f[c0], op[1]->value.f[c1]); break; default: assert(0); @@ -377,13 +375,13 @@ ir_expression::constant_expression_value() switch (op[0]->type->base_type) { case GLSL_TYPE_UINT: - data.u[c] = max(op[0]->value.u[c0], op[1]->value.u[c1]); + data.u[c] = MAX2(op[0]->value.u[c0], op[1]->value.u[c1]); break; case GLSL_TYPE_INT: - data.i[c] = max(op[0]->value.i[c0], op[1]->value.i[c1]); + data.i[c] = MAX2(op[0]->value.i[c0], op[1]->value.i[c1]); break; case GLSL_TYPE_FLOAT: - data.f[c] = max(op[0]->value.f[c0], op[1]->value.f[c1]); + data.f[c] = MAX2(op[0]->value.f[c0], op[1]->value.f[c1]); break; default: assert(0); -- cgit v1.2.3 From bafd89fa0f026cef12024382b154a41d90d00373 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Wed, 21 Jul 2010 16:55:46 -0700 Subject: ir_constant_expression: Stub out support for constant builtins. --- src/glsl/ir_constant_expression.cpp | 151 +++++++++++++++++++++++++++++++++++- 1 file changed, 148 insertions(+), 3 deletions(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index 9309b61898..aa53d8d186 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -764,7 +764,152 @@ ir_constant::constant_expression_value() ir_constant * ir_call::constant_expression_value() { - /* FINISHME: Handle CEs involving builtin function calls. */ - return NULL; -} + if (this->type == glsl_type::error_type) + return NULL; + + /* From the GLSL 1.20 spec, page 23: + * "Function calls to user-defined functions (non-built-in functions) + * cannot be used to form constant expressions." + */ + if (!this->callee->is_built_in) + return NULL; + + unsigned num_parameters = 0; + + /* Check if all parameters are constant */ + ir_constant *op[3]; + foreach_list(n, &this->actual_parameters) { + ir_constant *constant = ((ir_rvalue *) n)->constant_expression_value(); + if (constant == NULL) + return NULL; + + op[num_parameters] = constant; + + assert(num_parameters < 3); + num_parameters++; + } + /* Individual cases below can either: + * - Assign "expr" a new ir_expression to evaluate (for basic opcodes) + * - Fill "data" with appopriate constant data + * - Return an ir_constant directly. + */ + void *mem_ctx = talloc_parent(this); + ir_expression *expr = NULL; + + ir_constant_data data; + memset(&data, 0, sizeof(data)); + + const char *callee = this->callee_name(); + if (strcmp(callee, "abs") == 0) { + return NULL; /* FINISHME: implement this */ + } else if (strcmp(callee, "all") == 0) { + return NULL; /* FINISHME: implement this */ + } else if (strcmp(callee, "any") == 0) { + return NULL; /* FINISHME: implement this */ + } else if (strcmp(callee, "asin") == 0) { + return NULL; /* FINISHME: implement this */ + } else if (strcmp(callee, "atan") == 0) { + return NULL; /* FINISHME: implement this */ + } else if (strcmp(callee, "dFdx") == 0 || strcmp(callee, "dFdy") == 0) { + return NULL; /* FINISHME: implement this */ + } else if (strcmp(callee, "ceil") == 0) { + return NULL; /* FINISHME: implement this */ + } else if (strcmp(callee, "clamp") == 0) { + return NULL; /* FINISHME: implement this */ + } else if (strcmp(callee, "cos") == 0) { + return NULL; /* FINISHME: implement this */ + } else if (strcmp(callee, "cosh") == 0) { + return NULL; /* FINISHME: implement this */ + } else if (strcmp(callee, "cross") == 0) { + return NULL; /* FINISHME: implement this */ + } else if (strcmp(callee, "degrees") == 0) { + return NULL; /* FINISHME: implement this */ + } else if (strcmp(callee, "distance") == 0) { + return NULL; /* FINISHME: implement this */ + } else if (strcmp(callee, "dot") == 0) { + return NULL; /* FINISHME: implement this */ + } else if (strcmp(callee, "equal") == 0) { + return NULL; /* FINISHME: implement this */ + } else if (strcmp(callee, "exp") == 0) { + return NULL; /* FINISHME: implement this */ + } else if (strcmp(callee, "exp2") == 0) { + return NULL; /* FINISHME: implement this */ + } else if (strcmp(callee, "faceforward") == 0) { + return NULL; /* FINISHME: implement this */ + } else if (strcmp(callee, "floor") == 0) { + return NULL; /* FINISHME: implement this */ + } else if (strcmp(callee, "fract") == 0) { + return NULL; /* FINISHME: implement this */ + } else if (strcmp(callee, "fwidth") == 0) { + return NULL; /* FINISHME: implement this */ + } else if (strcmp(callee, "greaterThan") == 0) { + return NULL; /* FINISHME: implement this */ + } else if (strcmp(callee, "greaterThanEqual") == 0) { + return NULL; /* FINISHME: implement this */ + } else if (strcmp(callee, "inversesqrt") == 0) { + return NULL; /* FINISHME: implement this */ + } else if (strcmp(callee, "length") == 0) { + return NULL; /* FINISHME: implement this */ + } else if (strcmp(callee, "lessThan") == 0) { + return NULL; /* FINISHME: implement this */ + } else if (strcmp(callee, "lessThanEqual") == 0) { + return NULL; /* FINISHME: implement this */ + } else if (strcmp(callee, "log") == 0) { + return NULL; /* FINISHME: implement this */ + } else if (strcmp(callee, "log2") == 0) { + return NULL; /* FINISHME: implement this */ + } else if (strcmp(callee, "matrixCompMult") == 0) { + return NULL; /* FINISHME: implement this */ + } else if (strcmp(callee, "max") == 0) { + return NULL; /* FINISHME: implement this */ + } else if (strcmp(callee, "min") == 0) { + return NULL; /* FINISHME: implement this */ + } else if (strcmp(callee, "mix") == 0) { + return NULL; /* FINISHME: implement this */ + } else if (strcmp(callee, "mod") == 0) { + return NULL; /* FINISHME: implement this */ + } else if (strcmp(callee, "normalize") == 0) { + return NULL; /* FINISHME: implement this */ + } else if (strcmp(callee, "not") == 0) { + return NULL; /* FINISHME: implement this */ + } else if (strcmp(callee, "notEqual") == 0) { + return NULL; /* FINISHME: implement this */ + } else if (strcmp(callee, "outerProduct") == 0) { + return NULL; /* FINISHME: implement this */ + } else if (strcmp(callee, "pow") == 0) { + return NULL; /* FINISHME: implement this */ + } else if (strcmp(callee, "radians") == 0) { + return NULL; /* FINISHME: implement this */ + } else if (strcmp(callee, "reflect") == 0) { + return NULL; /* FINISHME: implement this */ + } else if (strcmp(callee, "refract") == 0) { + return NULL; /* FINISHME: implement this */ + } else if (strcmp(callee, "sign") == 0) { + return NULL; /* FINISHME: implement this */ + } else if (strcmp(callee, "sin") == 0) { + return NULL; /* FINISHME: implement this */ + } else if (strcmp(callee, "sinh") == 0) { + return NULL; /* FINISHME: implement this */ + } else if (strcmp(callee, "smoothstep") == 0) { + return NULL; /* FINISHME: implement this */ + } else if (strcmp(callee, "sqrt") == 0) { + return NULL; /* FINISHME: implement this */ + } else if (strcmp(callee, "step") == 0) { + return NULL; /* FINISHME: implement this */ + } else if (strcmp(callee, "tan") == 0) { + return NULL; /* FINISHME: implement this */ + } else if (strcmp(callee, "tanh") == 0) { + return NULL; /* FINISHME: implement this */ + } else if (strcmp(callee, "transpose") == 0) { + return NULL; /* FINISHME: implement this */ + } else { + /* Unsupported builtin - some are not allowed in constant expressions. */ + return NULL; + } + + if (expr != NULL) + return expr->constant_expression_value(); + + return new(mem_ctx) ir_constant(this->type, &data); +} -- cgit v1.2.3 From 38cb1b273f55f98349d981445cfe06351322b032 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Wed, 21 Jul 2010 16:57:10 -0700 Subject: ir_constant_expression: Add support for builtins dFdx, dFdy, and fwidth. These always return zero (the derivative of a constant). --- src/glsl/ir_constant_expression.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index aa53d8d186..641589ed07 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -812,7 +812,7 @@ ir_call::constant_expression_value() } else if (strcmp(callee, "atan") == 0) { return NULL; /* FINISHME: implement this */ } else if (strcmp(callee, "dFdx") == 0 || strcmp(callee, "dFdy") == 0) { - return NULL; /* FINISHME: implement this */ + return ir_constant::zero(mem_ctx, this->type); } else if (strcmp(callee, "ceil") == 0) { return NULL; /* FINISHME: implement this */ } else if (strcmp(callee, "clamp") == 0) { @@ -842,7 +842,7 @@ ir_call::constant_expression_value() } else if (strcmp(callee, "fract") == 0) { return NULL; /* FINISHME: implement this */ } else if (strcmp(callee, "fwidth") == 0) { - return NULL; /* FINISHME: implement this */ + return ir_constant::zero(mem_ctx, this->type); } else if (strcmp(callee, "greaterThan") == 0) { return NULL; /* FINISHME: implement this */ } else if (strcmp(callee, "greaterThanEqual") == 0) { -- cgit v1.2.3 From 8b1680acc38cfbb6d2fc80ddab3f3eed24e2522a Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Wed, 21 Jul 2010 16:57:53 -0700 Subject: ir_constant_expression: Implement builtins that wrap an expression. These builtin functions are represented by ir_expression_operations, so we can just create one of those and ask for its value. --- src/glsl/ir_constant_expression.cpp | 40 ++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index 641589ed07..0ffa1f0097 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -802,7 +802,7 @@ ir_call::constant_expression_value() const char *callee = this->callee_name(); if (strcmp(callee, "abs") == 0) { - return NULL; /* FINISHME: implement this */ + expr = new(mem_ctx) ir_expression(ir_unop_abs, type, op[0], NULL); } else if (strcmp(callee, "all") == 0) { return NULL; /* FINISHME: implement this */ } else if (strcmp(callee, "any") == 0) { @@ -814,33 +814,33 @@ ir_call::constant_expression_value() } else if (strcmp(callee, "dFdx") == 0 || strcmp(callee, "dFdy") == 0) { return ir_constant::zero(mem_ctx, this->type); } else if (strcmp(callee, "ceil") == 0) { - return NULL; /* FINISHME: implement this */ + expr = new(mem_ctx) ir_expression(ir_unop_ceil, type, op[0], NULL); } else if (strcmp(callee, "clamp") == 0) { return NULL; /* FINISHME: implement this */ } else if (strcmp(callee, "cos") == 0) { - return NULL; /* FINISHME: implement this */ + expr = new(mem_ctx) ir_expression(ir_unop_cos, type, op[0], NULL); } else if (strcmp(callee, "cosh") == 0) { return NULL; /* FINISHME: implement this */ } else if (strcmp(callee, "cross") == 0) { - return NULL; /* FINISHME: implement this */ + expr = new(mem_ctx) ir_expression(ir_binop_cross, type, op[0], op[1]); } else if (strcmp(callee, "degrees") == 0) { return NULL; /* FINISHME: implement this */ } else if (strcmp(callee, "distance") == 0) { return NULL; /* FINISHME: implement this */ } else if (strcmp(callee, "dot") == 0) { - return NULL; /* FINISHME: implement this */ + expr = new(mem_ctx) ir_expression(ir_binop_dot, type, op[0], op[1]); } else if (strcmp(callee, "equal") == 0) { return NULL; /* FINISHME: implement this */ } else if (strcmp(callee, "exp") == 0) { - return NULL; /* FINISHME: implement this */ + expr = new(mem_ctx) ir_expression(ir_unop_exp, type, op[0], NULL); } else if (strcmp(callee, "exp2") == 0) { - return NULL; /* FINISHME: implement this */ + expr = new(mem_ctx) ir_expression(ir_unop_exp2, type, op[0], NULL); } else if (strcmp(callee, "faceforward") == 0) { return NULL; /* FINISHME: implement this */ } else if (strcmp(callee, "floor") == 0) { - return NULL; /* FINISHME: implement this */ + expr = new(mem_ctx) ir_expression(ir_unop_floor, type, op[0], NULL); } else if (strcmp(callee, "fract") == 0) { - return NULL; /* FINISHME: implement this */ + expr = new(mem_ctx) ir_expression(ir_unop_fract, type, op[0], NULL); } else if (strcmp(callee, "fwidth") == 0) { return ir_constant::zero(mem_ctx, this->type); } else if (strcmp(callee, "greaterThan") == 0) { @@ -848,7 +848,7 @@ ir_call::constant_expression_value() } else if (strcmp(callee, "greaterThanEqual") == 0) { return NULL; /* FINISHME: implement this */ } else if (strcmp(callee, "inversesqrt") == 0) { - return NULL; /* FINISHME: implement this */ + expr = new(mem_ctx) ir_expression(ir_unop_rsq, type, op[0], NULL); } else if (strcmp(callee, "length") == 0) { return NULL; /* FINISHME: implement this */ } else if (strcmp(callee, "lessThan") == 0) { @@ -856,29 +856,29 @@ ir_call::constant_expression_value() } else if (strcmp(callee, "lessThanEqual") == 0) { return NULL; /* FINISHME: implement this */ } else if (strcmp(callee, "log") == 0) { - return NULL; /* FINISHME: implement this */ + expr = new(mem_ctx) ir_expression(ir_unop_log, type, op[0], NULL); } else if (strcmp(callee, "log2") == 0) { - return NULL; /* FINISHME: implement this */ + expr = new(mem_ctx) ir_expression(ir_unop_log2, type, op[0], NULL); } else if (strcmp(callee, "matrixCompMult") == 0) { return NULL; /* FINISHME: implement this */ } else if (strcmp(callee, "max") == 0) { - return NULL; /* FINISHME: implement this */ + expr = new(mem_ctx) ir_expression(ir_binop_max, type, op[0], op[1]); } else if (strcmp(callee, "min") == 0) { - return NULL; /* FINISHME: implement this */ + expr = new(mem_ctx) ir_expression(ir_binop_min, type, op[0], op[1]); } else if (strcmp(callee, "mix") == 0) { return NULL; /* FINISHME: implement this */ } else if (strcmp(callee, "mod") == 0) { - return NULL; /* FINISHME: implement this */ + expr = new(mem_ctx) ir_expression(ir_binop_mod, type, op[0], op[1]); } else if (strcmp(callee, "normalize") == 0) { return NULL; /* FINISHME: implement this */ } else if (strcmp(callee, "not") == 0) { - return NULL; /* FINISHME: implement this */ + expr = new(mem_ctx) ir_expression(ir_unop_logic_not, type, op[0], NULL); } else if (strcmp(callee, "notEqual") == 0) { return NULL; /* FINISHME: implement this */ } else if (strcmp(callee, "outerProduct") == 0) { return NULL; /* FINISHME: implement this */ } else if (strcmp(callee, "pow") == 0) { - return NULL; /* FINISHME: implement this */ + expr = new(mem_ctx) ir_expression(ir_binop_pow, type, op[0], op[1]); } else if (strcmp(callee, "radians") == 0) { return NULL; /* FINISHME: implement this */ } else if (strcmp(callee, "reflect") == 0) { @@ -886,15 +886,15 @@ ir_call::constant_expression_value() } else if (strcmp(callee, "refract") == 0) { return NULL; /* FINISHME: implement this */ } else if (strcmp(callee, "sign") == 0) { - return NULL; /* FINISHME: implement this */ + expr = new(mem_ctx) ir_expression(ir_unop_sign, type, op[0], NULL); } else if (strcmp(callee, "sin") == 0) { - return NULL; /* FINISHME: implement this */ + expr = new(mem_ctx) ir_expression(ir_unop_sin, type, op[0], NULL); } else if (strcmp(callee, "sinh") == 0) { return NULL; /* FINISHME: implement this */ } else if (strcmp(callee, "smoothstep") == 0) { return NULL; /* FINISHME: implement this */ } else if (strcmp(callee, "sqrt") == 0) { - return NULL; /* FINISHME: implement this */ + expr = new(mem_ctx) ir_expression(ir_unop_sqrt, type, op[0], NULL); } else if (strcmp(callee, "step") == 0) { return NULL; /* FINISHME: implement this */ } else if (strcmp(callee, "tan") == 0) { -- cgit v1.2.3 From aca7e95222ac33e5eda84ecc566da609f6f6ce8e Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Wed, 21 Jul 2010 17:34:32 -0700 Subject: ir_constant_expression: Add support for "all" builtin. --- src/glsl/ir_constant_expression.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index 0ffa1f0097..bce6747e87 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -804,7 +804,12 @@ ir_call::constant_expression_value() if (strcmp(callee, "abs") == 0) { expr = new(mem_ctx) ir_expression(ir_unop_abs, type, op[0], NULL); } else if (strcmp(callee, "all") == 0) { - return NULL; /* FINISHME: implement this */ + assert(op[0]->type->is_boolean()); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + if (!op[0]->value.b[c]) + return new(mem_ctx) ir_constant(false); + } + return new(mem_ctx) ir_constant(true); } else if (strcmp(callee, "any") == 0) { return NULL; /* FINISHME: implement this */ } else if (strcmp(callee, "asin") == 0) { -- cgit v1.2.3 From d6792a7f7c2b73486987d2bc07fc77d46456b65d Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Wed, 21 Jul 2010 17:35:52 -0700 Subject: ir_constant_expression: Add support for "any" builtin. --- src/glsl/ir_constant_expression.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index bce6747e87..e4c4a4d897 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -811,7 +811,12 @@ ir_call::constant_expression_value() } return new(mem_ctx) ir_constant(true); } else if (strcmp(callee, "any") == 0) { - return NULL; /* FINISHME: implement this */ + assert(op[0]->type->is_boolean()); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + if (op[0]->value.b[c]) + return new(mem_ctx) ir_constant(true); + } + return new(mem_ctx) ir_constant(false); } else if (strcmp(callee, "asin") == 0) { return NULL; /* FINISHME: implement this */ } else if (strcmp(callee, "atan") == 0) { -- cgit v1.2.3 From 3b6c29b8f00a2475b24022cace69f372b470a9b1 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Wed, 21 Jul 2010 17:38:38 -0700 Subject: ir_constant_expression: Add support for "asin" builtin. --- src/glsl/ir_constant_expression.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index e4c4a4d897..2276f4d32e 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -818,7 +818,9 @@ ir_call::constant_expression_value() } return new(mem_ctx) ir_constant(false); } else if (strcmp(callee, "asin") == 0) { - return NULL; /* FINISHME: implement this */ + assert(op[0]->type->is_float()); + for (unsigned c = 0; c < op[0]->type->components(); c++) + data.f[c] = asinf(op[0]->value.f[c]); } else if (strcmp(callee, "atan") == 0) { return NULL; /* FINISHME: implement this */ } else if (strcmp(callee, "dFdx") == 0 || strcmp(callee, "dFdy") == 0) { -- cgit v1.2.3 From f6ea9dfe473ccb0b5121461653696fe07ee4f328 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Wed, 21 Jul 2010 17:39:47 -0700 Subject: ir_constant_expression: Add support for "acos" builtin. --- src/glsl/ir_constant_expression.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index 2276f4d32e..301bfa8025 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -817,6 +817,10 @@ ir_call::constant_expression_value() return new(mem_ctx) ir_constant(true); } return new(mem_ctx) ir_constant(false); + } else if (strcmp(callee, "acos") == 0) { + assert(op[0]->type->is_float()); + for (unsigned c = 0; c < op[0]->type->components(); c++) + data.f[c] = acosf(op[0]->value.f[c]); } else if (strcmp(callee, "asin") == 0) { assert(op[0]->type->is_float()); for (unsigned c = 0; c < op[0]->type->components(); c++) -- cgit v1.2.3 From 13f8758e9c3babdee3fc0b8b8e1d4a7e13ef9694 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Wed, 21 Jul 2010 17:42:23 -0700 Subject: ir_constant_expression: Add support for "atan" builtins. --- src/glsl/ir_constant_expression.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index 301bfa8025..a6ce339e3e 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -826,7 +826,15 @@ ir_call::constant_expression_value() for (unsigned c = 0; c < op[0]->type->components(); c++) data.f[c] = asinf(op[0]->value.f[c]); } else if (strcmp(callee, "atan") == 0) { - return NULL; /* FINISHME: implement this */ + assert(op[0]->type->is_float()); + if (num_parameters == 2) { + assert(op[1]->type->is_float()); + for (unsigned c = 0; c < op[0]->type->components(); c++) + data.f[c] = atan2f(op[0]->value.f[c], op[1]->value.f[c]); + } else { + for (unsigned c = 0; c < op[0]->type->components(); c++) + data.f[c] = atanf(op[0]->value.f[c]); + } } else if (strcmp(callee, "dFdx") == 0 || strcmp(callee, "dFdy") == 0) { return ir_constant::zero(mem_ctx, this->type); } else if (strcmp(callee, "ceil") == 0) { -- cgit v1.2.3 From ba4178345a1eb8e697a8cb01b5594c0a3b4b1d29 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Wed, 21 Jul 2010 17:47:55 -0700 Subject: ir_constant_expression: Add support for the "cosh" builtin. --- src/glsl/ir_constant_expression.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index a6ce339e3e..ee99ed2cdd 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -844,7 +844,9 @@ ir_call::constant_expression_value() } else if (strcmp(callee, "cos") == 0) { expr = new(mem_ctx) ir_expression(ir_unop_cos, type, op[0], NULL); } else if (strcmp(callee, "cosh") == 0) { - return NULL; /* FINISHME: implement this */ + assert(op[0]->type->is_float()); + for (unsigned c = 0; c < op[0]->type->components(); c++) + data.f[c] = coshf(op[0]->value.f[c]); } else if (strcmp(callee, "cross") == 0) { expr = new(mem_ctx) ir_expression(ir_binop_cross, type, op[0], op[1]); } else if (strcmp(callee, "degrees") == 0) { -- cgit v1.2.3 From 5d551daf38e30d6cb863038afe1a8e32c806e6ae Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Wed, 21 Jul 2010 17:49:56 -0700 Subject: ir_constant_expression: Add support for the "sinh" builtin. --- src/glsl/ir_constant_expression.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index ee99ed2cdd..b7ceefc393 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -916,7 +916,9 @@ ir_call::constant_expression_value() } else if (strcmp(callee, "sin") == 0) { expr = new(mem_ctx) ir_expression(ir_unop_sin, type, op[0], NULL); } else if (strcmp(callee, "sinh") == 0) { - return NULL; /* FINISHME: implement this */ + assert(op[0]->type->is_float()); + for (unsigned c = 0; c < op[0]->type->components(); c++) + data.f[c] = sinhf(op[0]->value.f[c]); } else if (strcmp(callee, "smoothstep") == 0) { return NULL; /* FINISHME: implement this */ } else if (strcmp(callee, "sqrt") == 0) { -- cgit v1.2.3 From 9c9f8b2d69094fb308de0d6a28bcd60cdf8aedf6 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Wed, 21 Jul 2010 17:50:50 -0700 Subject: ir_constant_expression: Add support for the "tan" builtin. --- src/glsl/ir_constant_expression.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index b7ceefc393..bcf87e000f 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -926,7 +926,9 @@ ir_call::constant_expression_value() } else if (strcmp(callee, "step") == 0) { return NULL; /* FINISHME: implement this */ } else if (strcmp(callee, "tan") == 0) { - return NULL; /* FINISHME: implement this */ + assert(op[0]->type->is_float()); + for (unsigned c = 0; c < op[0]->type->components(); c++) + data.f[c] = tanf(op[0]->value.f[c]); } else if (strcmp(callee, "tanh") == 0) { return NULL; /* FINISHME: implement this */ } else if (strcmp(callee, "transpose") == 0) { -- cgit v1.2.3 From 20970f7dea220a2f44c180579630f453729ab31b Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Wed, 21 Jul 2010 17:51:23 -0700 Subject: ir_constant_expression: Add support for the "tanh" builtin. --- src/glsl/ir_constant_expression.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index bcf87e000f..aedc661025 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -930,7 +930,9 @@ ir_call::constant_expression_value() for (unsigned c = 0; c < op[0]->type->components(); c++) data.f[c] = tanf(op[0]->value.f[c]); } else if (strcmp(callee, "tanh") == 0) { - return NULL; /* FINISHME: implement this */ + assert(op[0]->type->is_float()); + for (unsigned c = 0; c < op[0]->type->components(); c++) + data.f[c] = tanhf(op[0]->value.f[c]); } else if (strcmp(callee, "transpose") == 0) { return NULL; /* FINISHME: implement this */ } else { -- cgit v1.2.3 From 0afe3493221c6a676bcc045aca508bb08f58a4f4 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Wed, 21 Jul 2010 17:58:03 -0700 Subject: ir_constant_expression: Add support for the "radians" builtin. --- src/glsl/ir_constant_expression.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index aedc661025..bc1261b0b9 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -906,7 +906,9 @@ ir_call::constant_expression_value() } else if (strcmp(callee, "pow") == 0) { expr = new(mem_ctx) ir_expression(ir_binop_pow, type, op[0], op[1]); } else if (strcmp(callee, "radians") == 0) { - return NULL; /* FINISHME: implement this */ + assert(op[0]->type->is_float()); + for (unsigned c = 0; c < op[0]->type->components(); c++) + data.f[c] = M_PI/180.0 * op[0]->value.f[c]; } else if (strcmp(callee, "reflect") == 0) { return NULL; /* FINISHME: implement this */ } else if (strcmp(callee, "refract") == 0) { -- cgit v1.2.3 From 7bcaa3828f8d3d39cfece5d91e47ed2a135a9471 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Wed, 21 Jul 2010 17:59:00 -0700 Subject: ir_constant_expression: Add support for the "degrees" builtin. --- src/glsl/ir_constant_expression.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index bc1261b0b9..e68a7b1a2a 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -850,7 +850,9 @@ ir_call::constant_expression_value() } else if (strcmp(callee, "cross") == 0) { expr = new(mem_ctx) ir_expression(ir_binop_cross, type, op[0], op[1]); } else if (strcmp(callee, "degrees") == 0) { - return NULL; /* FINISHME: implement this */ + assert(op[0]->type->is_float()); + for (unsigned c = 0; c < op[0]->type->components(); c++) + data.f[c] = 180.0/M_PI * op[0]->value.f[c]; } else if (strcmp(callee, "distance") == 0) { return NULL; /* FINISHME: implement this */ } else if (strcmp(callee, "dot") == 0) { -- cgit v1.2.3 From 2eaf31642c83086b06dce057997ae4bc4b1bce2c Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Wed, 21 Jul 2010 18:01:22 -0700 Subject: ir_constant_expression: Add support for the "distance" builtin. --- src/glsl/ir_constant_expression.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index e68a7b1a2a..52f53d9ff4 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -854,7 +854,13 @@ ir_call::constant_expression_value() for (unsigned c = 0; c < op[0]->type->components(); c++) data.f[c] = 180.0/M_PI * op[0]->value.f[c]; } else if (strcmp(callee, "distance") == 0) { - return NULL; /* FINISHME: implement this */ + assert(op[0]->type->is_float() && op[1]->type->is_float()); + float length_squared = 0.0; + for (unsigned c = 0; c < op[0]->type->components(); c++) { + float t = op[0]->value.f[c] - op[1]->value.f[c]; + length_squared += t * t; + } + return new(mem_ctx) ir_constant(sqrtf(length_squared)); } else if (strcmp(callee, "dot") == 0) { expr = new(mem_ctx) ir_expression(ir_binop_dot, type, op[0], op[1]); } else if (strcmp(callee, "equal") == 0) { -- cgit v1.2.3 From 0b6ef6ef6e1930b6ec03dae7ace53372bb239981 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Wed, 21 Jul 2010 18:04:22 -0700 Subject: ir_constant_expression: Add support for the "equal" builtin. --- src/glsl/ir_constant_expression.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index 52f53d9ff4..e6f9558b62 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -864,7 +864,22 @@ ir_call::constant_expression_value() } else if (strcmp(callee, "dot") == 0) { expr = new(mem_ctx) ir_expression(ir_binop_dot, type, op[0], op[1]); } else if (strcmp(callee, "equal") == 0) { - return NULL; /* FINISHME: implement this */ + assert(op[0]->type->is_vector() && op[1] && op[1]->type->is_vector()); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + switch (op[0]->type->base_type) { + case GLSL_TYPE_UINT: + data.b[c] = op[0]->value.u[c] == op[1]->value.u[c]; + break; + case GLSL_TYPE_INT: + data.b[c] = op[0]->value.i[c] == op[1]->value.i[c]; + break; + case GLSL_TYPE_FLOAT: + data.b[c] = op[0]->value.f[c] == op[1]->value.f[c]; + break; + default: + assert(!"Should not get here."); + } + } } else if (strcmp(callee, "exp") == 0) { expr = new(mem_ctx) ir_expression(ir_unop_exp, type, op[0], NULL); } else if (strcmp(callee, "exp2") == 0) { -- cgit v1.2.3 From 48a69ba05794f3d253114b452174710a15eefadf Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Wed, 21 Jul 2010 18:05:36 -0700 Subject: ir_constant_expression: Add support for the "notEqual" builtin. --- src/glsl/ir_constant_expression.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index e6f9558b62..4a5eb7540a 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -923,7 +923,22 @@ ir_call::constant_expression_value() } else if (strcmp(callee, "not") == 0) { expr = new(mem_ctx) ir_expression(ir_unop_logic_not, type, op[0], NULL); } else if (strcmp(callee, "notEqual") == 0) { - return NULL; /* FINISHME: implement this */ + assert(op[0]->type->is_vector() && op[1] && op[1]->type->is_vector()); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + switch (op[0]->type->base_type) { + case GLSL_TYPE_UINT: + data.b[c] = op[0]->value.u[c] != op[1]->value.u[c]; + break; + case GLSL_TYPE_INT: + data.b[c] = op[0]->value.i[c] != op[1]->value.i[c]; + break; + case GLSL_TYPE_FLOAT: + data.b[c] = op[0]->value.f[c] != op[1]->value.f[c]; + break; + default: + assert(!"Should not get here."); + } + } } else if (strcmp(callee, "outerProduct") == 0) { return NULL; /* FINISHME: implement this */ } else if (strcmp(callee, "pow") == 0) { -- cgit v1.2.3 From 6d897f07cf7ed8492ef5f0da90259856fdac5bf6 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Wed, 21 Jul 2010 18:06:18 -0700 Subject: ir_constant_expression: Add support for the "lessThan" builtin. --- src/glsl/ir_constant_expression.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index 4a5eb7540a..032214eb3c 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -901,7 +901,22 @@ ir_call::constant_expression_value() } else if (strcmp(callee, "length") == 0) { return NULL; /* FINISHME: implement this */ } else if (strcmp(callee, "lessThan") == 0) { - return NULL; /* FINISHME: implement this */ + assert(op[0]->type->is_vector() && op[1] && op[1]->type->is_vector()); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + switch (op[0]->type->base_type) { + case GLSL_TYPE_UINT: + data.b[c] = op[0]->value.u[c] < op[1]->value.u[c]; + break; + case GLSL_TYPE_INT: + data.b[c] = op[0]->value.i[c] < op[1]->value.i[c]; + break; + case GLSL_TYPE_FLOAT: + data.b[c] = op[0]->value.f[c] < op[1]->value.f[c]; + break; + default: + assert(!"Should not get here."); + } + } } else if (strcmp(callee, "lessThanEqual") == 0) { return NULL; /* FINISHME: implement this */ } else if (strcmp(callee, "log") == 0) { -- cgit v1.2.3 From 319f4949e0a5f1daa3a760fc84096c041e3ce815 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Wed, 21 Jul 2010 18:07:09 -0700 Subject: ir_constant_expression: Add support for the "lessThanEqual" builtin. --- src/glsl/ir_constant_expression.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index 032214eb3c..9c543d48ed 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -918,7 +918,22 @@ ir_call::constant_expression_value() } } } else if (strcmp(callee, "lessThanEqual") == 0) { - return NULL; /* FINISHME: implement this */ + assert(op[0]->type->is_vector() && op[1] && op[1]->type->is_vector()); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + switch (op[0]->type->base_type) { + case GLSL_TYPE_UINT: + data.b[c] = op[0]->value.u[c] <= op[1]->value.u[c]; + break; + case GLSL_TYPE_INT: + data.b[c] = op[0]->value.i[c] <= op[1]->value.i[c]; + break; + case GLSL_TYPE_FLOAT: + data.b[c] = op[0]->value.f[c] <= op[1]->value.f[c]; + break; + default: + assert(!"Should not get here."); + } + } } else if (strcmp(callee, "log") == 0) { expr = new(mem_ctx) ir_expression(ir_unop_log, type, op[0], NULL); } else if (strcmp(callee, "log2") == 0) { -- cgit v1.2.3 From 7f042b98126b1710c819091512621c642f8fcbbc Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Wed, 21 Jul 2010 18:07:43 -0700 Subject: ir_constant_expression: Add support for the "greaterThan" builtin. --- src/glsl/ir_constant_expression.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index 9c543d48ed..d40322252e 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -893,7 +893,22 @@ ir_call::constant_expression_value() } else if (strcmp(callee, "fwidth") == 0) { return ir_constant::zero(mem_ctx, this->type); } else if (strcmp(callee, "greaterThan") == 0) { - return NULL; /* FINISHME: implement this */ + assert(op[0]->type->is_vector() && op[1] && op[1]->type->is_vector()); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + switch (op[0]->type->base_type) { + case GLSL_TYPE_UINT: + data.b[c] = op[0]->value.u[c] > op[1]->value.u[c]; + break; + case GLSL_TYPE_INT: + data.b[c] = op[0]->value.i[c] > op[1]->value.i[c]; + break; + case GLSL_TYPE_FLOAT: + data.b[c] = op[0]->value.f[c] > op[1]->value.f[c]; + break; + default: + assert(!"Should not get here."); + } + } } else if (strcmp(callee, "greaterThanEqual") == 0) { return NULL; /* FINISHME: implement this */ } else if (strcmp(callee, "inversesqrt") == 0) { -- cgit v1.2.3 From 557827340aedbf64d2486226924d00c94107c9e8 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Wed, 21 Jul 2010 18:08:05 -0700 Subject: ir_constant_expression: Add support for the "greaterThanEqual" builtin. --- src/glsl/ir_constant_expression.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index d40322252e..cce13139b7 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -910,7 +910,22 @@ ir_call::constant_expression_value() } } } else if (strcmp(callee, "greaterThanEqual") == 0) { - return NULL; /* FINISHME: implement this */ + assert(op[0]->type->is_vector() && op[1] && op[1]->type->is_vector()); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + switch (op[0]->type->base_type) { + case GLSL_TYPE_UINT: + data.b[c] = op[0]->value.u[c] >= op[1]->value.u[c]; + break; + case GLSL_TYPE_INT: + data.b[c] = op[0]->value.i[c] >= op[1]->value.i[c]; + break; + case GLSL_TYPE_FLOAT: + data.b[c] = op[0]->value.f[c] >= op[1]->value.f[c]; + break; + default: + assert(!"Should not get here."); + } + } } else if (strcmp(callee, "inversesqrt") == 0) { expr = new(mem_ctx) ir_expression(ir_unop_rsq, type, op[0], NULL); } else if (strcmp(callee, "length") == 0) { -- cgit v1.2.3 From 4b1d77ea966771dc5fbdac90dfec1b6066afe3f8 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Wed, 21 Jul 2010 18:18:16 -0700 Subject: ir_constant_expression: Remove support for dot products of integers. This shouldn't be required since dot is only defined for floating point types, even in GLSL 4.0. --- src/glsl/ir_constant_expression.cpp | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index cce13139b7..799bd4a60b 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -327,21 +327,10 @@ ir_expression::constant_expression_value() case ir_binop_dot: assert(op[0]->type->is_vector() && op[1]->type->is_vector()); + assert(op[0]->type->is_float() && op[1]->type->is_float()); data.f[0] = 0; for (unsigned c = 0; c < op[0]->type->components(); c++) { - switch (op[0]->type->base_type) { - case GLSL_TYPE_UINT: - data.u[0] += op[0]->value.u[c] * op[1]->value.u[c]; - break; - case GLSL_TYPE_INT: - data.i[0] += op[0]->value.i[c] * op[1]->value.i[c]; - break; - case GLSL_TYPE_FLOAT: - data.f[0] += op[0]->value.f[c] * op[1]->value.f[c]; - break; - default: - assert(0); - } + data.f[0] += op[0]->value.f[c] * op[1]->value.f[c]; } break; -- cgit v1.2.3 From ffcec135997545b4dc2b3393ccb02558083373a0 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Wed, 21 Jul 2010 20:09:21 -0700 Subject: ir_constant_expression: Extract dot product calculation for reuse. --- src/glsl/ir_constant_expression.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index 799bd4a60b..c4a416aa35 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -39,6 +39,18 @@ #include "ir_visitor.h" #include "glsl_types.h" +static float +dot(ir_constant *op0, ir_constant *op1) +{ + assert(op0->type->is_float() && op1->type->is_float()); + + float result = 0; + for (unsigned c = 0; c < op0->type->components(); c++) + result += op0->value.f[c] * op1->value.f[c]; + + return result; +} + ir_constant * ir_expression::constant_expression_value() { @@ -326,14 +338,9 @@ ir_expression::constant_expression_value() break; case ir_binop_dot: - assert(op[0]->type->is_vector() && op[1]->type->is_vector()); - assert(op[0]->type->is_float() && op[1]->type->is_float()); - data.f[0] = 0; - for (unsigned c = 0; c < op[0]->type->components(); c++) { - data.f[0] += op[0]->value.f[c] * op[1]->value.f[c]; - } - + data.f[0] = dot(op[0], op[1]); break; + case ir_binop_min: assert(op[0]->type == op[1]->type || op0_scalar || op1_scalar); for (unsigned c = 0, c0 = 0, c1 = 0; -- cgit v1.2.3 From 5489ad086f77e548905c98ccd27cd626d706d5f9 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Wed, 21 Jul 2010 18:26:00 -0700 Subject: ir_constant_expression: Add support for the "length" builtin. --- src/glsl/ir_constant_expression.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index c4a416aa35..83d1b34bed 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -925,7 +925,7 @@ ir_call::constant_expression_value() } else if (strcmp(callee, "inversesqrt") == 0) { expr = new(mem_ctx) ir_expression(ir_unop_rsq, type, op[0], NULL); } else if (strcmp(callee, "length") == 0) { - return NULL; /* FINISHME: implement this */ + return new(mem_ctx) ir_constant(sqrtf(dot(op[0], op[0]))); } else if (strcmp(callee, "lessThan") == 0) { assert(op[0]->type->is_vector() && op[1] && op[1]->type->is_vector()); for (unsigned c = 0; c < op[0]->type->components(); c++) { -- cgit v1.2.3 From a7650af706b359056db8b9da6d1d83669106d463 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Wed, 21 Jul 2010 20:12:43 -0700 Subject: ir_constant_expression: Simplify code that implements the "dot" builtin. There's no need to use an ir_expression; we have a handy C function. --- src/glsl/ir_constant_expression.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index 83d1b34bed..d20d1953e2 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -858,7 +858,7 @@ ir_call::constant_expression_value() } return new(mem_ctx) ir_constant(sqrtf(length_squared)); } else if (strcmp(callee, "dot") == 0) { - expr = new(mem_ctx) ir_expression(ir_binop_dot, type, op[0], op[1]); + return new(mem_ctx) ir_constant(dot(op[0], op[1])); } else if (strcmp(callee, "equal") == 0) { assert(op[0]->type->is_vector() && op[1] && op[1]->type->is_vector()); for (unsigned c = 0; c < op[0]->type->components(); c++) { -- cgit v1.2.3 From 8fe5f30645e1b6a87497c1abc408ade633e9ebc1 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Wed, 21 Jul 2010 20:03:55 -0700 Subject: ir_constant_expression: Add support for the "matrixCompMult" builtin. --- src/glsl/ir_constant_expression.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index d20d1953e2..2c80c8b5e0 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -965,7 +965,9 @@ ir_call::constant_expression_value() } else if (strcmp(callee, "log2") == 0) { expr = new(mem_ctx) ir_expression(ir_unop_log2, type, op[0], NULL); } else if (strcmp(callee, "matrixCompMult") == 0) { - return NULL; /* FINISHME: implement this */ + assert(op[0]->type->is_float() && op[1]->type->is_float()); + for (unsigned c = 0; c < op[0]->type->components(); c++) + data.f[c] = op[0]->value.f[c] * op[1]->value.f[c]; } else if (strcmp(callee, "max") == 0) { expr = new(mem_ctx) ir_expression(ir_binop_max, type, op[0], op[1]); } else if (strcmp(callee, "min") == 0) { -- cgit v1.2.3 From 53f306d573ce6393062cf86d4fe31148eacc5e1e Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Wed, 21 Jul 2010 20:19:32 -0700 Subject: ir_constant_expression: Add support for the "normalize" builtin. --- src/glsl/ir_constant_expression.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index 2c80c8b5e0..809ea609a3 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -977,7 +977,14 @@ ir_call::constant_expression_value() } else if (strcmp(callee, "mod") == 0) { expr = new(mem_ctx) ir_expression(ir_binop_mod, type, op[0], op[1]); } else if (strcmp(callee, "normalize") == 0) { - return NULL; /* FINISHME: implement this */ + assert(op[0]->type->is_float()); + float length = sqrtf(dot(op[0], op[0])); + + if (length == 0) + return ir_constant::zero(mem_ctx, this->type); + + for (unsigned c = 0; c < op[0]->type->components(); c++) + data.f[c] = op[0]->value.f[c] / length; } else if (strcmp(callee, "not") == 0) { expr = new(mem_ctx) ir_expression(ir_unop_logic_not, type, op[0], NULL); } else if (strcmp(callee, "notEqual") == 0) { -- cgit v1.2.3 From d60b2b03da30093ae85458f1d0be3cc5c33d992c Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Wed, 21 Jul 2010 20:24:29 -0700 Subject: ir_constant_expression: Add support for the "reflect" builtin. --- src/glsl/ir_constant_expression.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index 809ea609a3..c8320814a3 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -1013,7 +1013,10 @@ ir_call::constant_expression_value() for (unsigned c = 0; c < op[0]->type->components(); c++) data.f[c] = M_PI/180.0 * op[0]->value.f[c]; } else if (strcmp(callee, "reflect") == 0) { - return NULL; /* FINISHME: implement this */ + assert(op[0]->type->is_float()); + float dot_NI = dot(op[1], op[0]); + for (unsigned c = 0; c < op[0]->type->components(); c++) + data.f[c] = op[0]->value.f[c] - 2 * dot_NI * op[1]->value.f[c]; } else if (strcmp(callee, "refract") == 0) { return NULL; /* FINISHME: implement this */ } else if (strcmp(callee, "sign") == 0) { -- cgit v1.2.3 From 04b3643dbf2e0d25e67c86845b2506ad1d26939d Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Wed, 21 Jul 2010 20:33:42 -0700 Subject: ir_constant_expression: Add support for the "refract" builtin. --- src/glsl/ir_constant_expression.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index c8320814a3..580ef1d4fa 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -1018,7 +1018,17 @@ ir_call::constant_expression_value() for (unsigned c = 0; c < op[0]->type->components(); c++) data.f[c] = op[0]->value.f[c] - 2 * dot_NI * op[1]->value.f[c]; } else if (strcmp(callee, "refract") == 0) { - return NULL; /* FINISHME: implement this */ + const float eta = op[2]->value.f[0]; + const float dot_NI = dot(op[1], op[0]); + const float k = 1.0 - eta * eta * (1.0 - dot_NI * dot_NI); + if (k < 0.0) { + return ir_constant::zero(mem_ctx, this->type); + } else { + for (unsigned c = 0; c < type->components(); c++) { + data.f[c] = eta * op[0]->value.f[c] - (eta * dot_NI + sqrtf(k)) + * op[1]->value.f[c]; + } + } } else if (strcmp(callee, "sign") == 0) { expr = new(mem_ctx) ir_expression(ir_unop_sign, type, op[0], NULL); } else if (strcmp(callee, "sin") == 0) { -- cgit v1.2.3 From 3d5c2f0adbd72a68d4fe3900b0d3e267510950ef Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Wed, 21 Jul 2010 21:46:16 -0700 Subject: ir_constant_expression: Add support for the "faceforward" builtin. --- src/glsl/ir_constant_expression.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index 580ef1d4fa..c939690129 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -881,7 +881,10 @@ ir_call::constant_expression_value() } else if (strcmp(callee, "exp2") == 0) { expr = new(mem_ctx) ir_expression(ir_unop_exp2, type, op[0], NULL); } else if (strcmp(callee, "faceforward") == 0) { - return NULL; /* FINISHME: implement this */ + if (dot(op[2], op[1]) < 0) + return op[0]; + for (unsigned c = 0; c < op[0]->type->components(); c++) + data.f[c] = -op[0]->value.f[c]; } else if (strcmp(callee, "floor") == 0) { expr = new(mem_ctx) ir_expression(ir_unop_floor, type, op[0], NULL); } else if (strcmp(callee, "fract") == 0) { -- cgit v1.2.3 From ff58b7c9b6f513ed8bf57b3e4283b67b06fd9d34 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Wed, 21 Jul 2010 21:53:40 -0700 Subject: ir_constant_expression: Add support for the "step" builtin. --- src/glsl/ir_constant_expression.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index c939690129..5485d79a88 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -1045,7 +1045,11 @@ ir_call::constant_expression_value() } else if (strcmp(callee, "sqrt") == 0) { expr = new(mem_ctx) ir_expression(ir_unop_sqrt, type, op[0], NULL); } else if (strcmp(callee, "step") == 0) { - return NULL; /* FINISHME: implement this */ + assert(op[0]->type->is_float() && op[1]->type->is_float()); + /* op[0] (edge) may be either a scalar or a vector */ + const unsigned c0_inc = op[0]->type->is_scalar() ? 0 : 1; + for (unsigned c = 0, c0 = 0; c < type->components(); c0 += c0_inc, c++) + data.f[c] = (op[1]->value.f[c] < op[0]->value.f[c0]) ? 0.0 : 1.0; } else if (strcmp(callee, "tan") == 0) { assert(op[0]->type->is_float()); for (unsigned c = 0; c < op[0]->type->components(); c++) -- cgit v1.2.3 From a4ca1cfb66160c4ea2325f503ff025a4adc35084 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Wed, 21 Jul 2010 22:23:17 -0700 Subject: ir_constant_expression: Add support for the "clamp" builtin. --- src/glsl/ir_constant_expression.cpp | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index 5485d79a88..a2748a726c 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -836,7 +836,30 @@ ir_call::constant_expression_value() } else if (strcmp(callee, "ceil") == 0) { expr = new(mem_ctx) ir_expression(ir_unop_ceil, type, op[0], NULL); } else if (strcmp(callee, "clamp") == 0) { - return NULL; /* FINISHME: implement this */ + assert(num_parameters == 3); + unsigned c1_inc = op[1]->type->is_scalar() ? 0 : 1; + unsigned c2_inc = op[2]->type->is_scalar() ? 0 : 1; + for (unsigned c = 0, c1 = 0, c2 = 0; + c < op[0]->type->components(); + c1 += c1_inc, c2 += c2_inc, c++) { + + switch (op[0]->type->base_type) { + case GLSL_TYPE_UINT: + data.u[c] = CLAMP(op[0]->value.u[c], op[1]->value.u[c1], + op[2]->value.u[c2]); + break; + case GLSL_TYPE_INT: + data.i[c] = CLAMP(op[0]->value.i[c], op[1]->value.i[c1], + op[2]->value.u[c2]); + break; + case GLSL_TYPE_FLOAT: + data.f[c] = CLAMP(op[0]->value.f[c], op[1]->value.f[c1], + op[2]->value.f[c2]); + break; + default: + assert(!"Should not get here."); + } + } } else if (strcmp(callee, "cos") == 0) { expr = new(mem_ctx) ir_expression(ir_unop_cos, type, op[0], NULL); } else if (strcmp(callee, "cosh") == 0) { -- cgit v1.2.3 From 546f3a27540c408c9d83368c5f6144e13167dcb3 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Wed, 21 Jul 2010 22:37:50 -0700 Subject: ir_constant_expression: Add support for the "smoothstep" builtin. --- src/glsl/ir_constant_expression.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index a2748a726c..b6cb2d8672 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -1064,7 +1064,21 @@ ir_call::constant_expression_value() for (unsigned c = 0; c < op[0]->type->components(); c++) data.f[c] = sinhf(op[0]->value.f[c]); } else if (strcmp(callee, "smoothstep") == 0) { - return NULL; /* FINISHME: implement this */ + assert(num_parameters == 3); + assert(op[1]->type == op[0]->type); + unsigned edge_inc = op[0]->type->is_scalar() ? 0 : 1; + for (unsigned c = 0, e = 0; c < type->components(); e += edge_inc, c++) { + const float edge0 = op[0]->value.f[e]; + const float edge1 = op[1]->value.f[e]; + if (edge0 == edge1) { + data.f[c] = 0.0; /* Avoid a crash - results are undefined anyway */ + } else { + const float numerator = op[2]->value.f[c] - edge0; + const float denominator = edge1 - edge0; + const float t = CLAMP(numerator/denominator, 0, 1); + data.f[c] = t * t * (3 - 2 * t); + } + } } else if (strcmp(callee, "sqrt") == 0) { expr = new(mem_ctx) ir_expression(ir_unop_sqrt, type, op[0], NULL); } else if (strcmp(callee, "step") == 0) { -- cgit v1.2.3 From b09ae5dd3f9b8e380e2608f4ee3a7902f5ecc15e Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Thu, 22 Jul 2010 15:34:49 -0700 Subject: ir_constant_expression: Add support for the "transpose" builtin. --- src/glsl/ir_constant_expression.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index b6cb2d8672..c4e6d837b0 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -1096,7 +1096,14 @@ ir_call::constant_expression_value() for (unsigned c = 0; c < op[0]->type->components(); c++) data.f[c] = tanhf(op[0]->value.f[c]); } else if (strcmp(callee, "transpose") == 0) { - return NULL; /* FINISHME: implement this */ + assert(op[0]->type->is_matrix()); + const unsigned n = op[0]->type->vector_elements; + const unsigned m = op[0]->type->matrix_columns; + for (unsigned j = 0; j < m; j++) { + for (unsigned i = 0; i < n; i++) { + data.f[m*i+j] += op[0]->value.f[i+n*j]; + } + } } else { /* Unsupported builtin - some are not allowed in constant expressions. */ return NULL; -- cgit v1.2.3 From 5d255e24b29930e78321c1ba807df71fea12174a Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Fri, 23 Jul 2010 12:36:50 -0700 Subject: ir_constant_expression: Add support for the "mix" builtin. Both 1.10 and 1.30 variants. --- src/glsl/ir_constant_expression.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index c4e6d837b0..9fc37b3777 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -999,7 +999,19 @@ ir_call::constant_expression_value() } else if (strcmp(callee, "min") == 0) { expr = new(mem_ctx) ir_expression(ir_binop_min, type, op[0], op[1]); } else if (strcmp(callee, "mix") == 0) { - return NULL; /* FINISHME: implement this */ + assert(op[0]->type->is_float() && op[1]->type->is_float()); + if (op[2]->type->is_float()) { + unsigned c2_inc = op[2]->type->is_scalar() ? 0 : 1; + unsigned components = op[0]->type->components(); + for (unsigned c = 0, c2 = 0; c < components; c2 += c2_inc, c++) { + data.f[c] = op[0]->value.f[c] * (1 - op[2]->value.f[c2]) + + op[1]->value.f[c] * op[2]->value.f[c2]; + } + } else { + assert(op[2]->type->is_boolean()); + for (unsigned c = 0; c < op[0]->type->components(); c++) + data.f[c] = op[op[2]->value.b[c] ? 1 : 0]->value.f[c]; + } } else if (strcmp(callee, "mod") == 0) { expr = new(mem_ctx) ir_expression(ir_binop_mod, type, op[0], op[1]); } else if (strcmp(callee, "normalize") == 0) { -- cgit v1.2.3 From 7ddee6a535f7323d7c6131e52e7933130d886ae4 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Fri, 23 Jul 2010 13:24:09 -0700 Subject: ir_constant_expression: Add support for the "outerProduct" builtin. --- src/glsl/ir_constant_expression.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index 9fc37b3777..f02cd3127e 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -1043,7 +1043,14 @@ ir_call::constant_expression_value() } } } else if (strcmp(callee, "outerProduct") == 0) { - return NULL; /* FINISHME: implement this */ + assert(op[0]->type->is_vector() && op[1]->type->is_vector()); + const unsigned m = op[0]->type->vector_elements; + const unsigned n = op[1]->type->vector_elements; + for (unsigned j = 0; j < n; j++) { + for (unsigned i = 0; i < m; i++) { + data.f[i+m*j] = op[0]->value.f[i] * op[1]->value.f[j]; + } + } } else if (strcmp(callee, "pow") == 0) { expr = new(mem_ctx) ir_expression(ir_binop_pow, type, op[0], op[1]); } else if (strcmp(callee, "radians") == 0) { -- cgit v1.2.3 From 5704ed27dd2ebc88639cbd32ac971939ef3c267a Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Mon, 2 Aug 2010 15:31:28 -0700 Subject: glsl2: Don't consider uniform initializers as constant expressions. We were happily optimizing away the body of glsl-uniform-initializer-* to never use the uniforms. --- src/glsl/ir_constant_expression.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index f02cd3127e..915d362b15 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -674,6 +674,12 @@ ir_dereference_variable::constant_expression_value() if (!var) return NULL; + /* The constant_value of a uniform variable is its initializer, + * not the lifetime constant value of the uniform. + */ + if (var->mode == ir_var_uniform) + return NULL; + return var->constant_value ? var->constant_value->clone(NULL) : NULL; } -- cgit v1.2.3 From c8babd5d9bba75c9f38f384f9cb3587e3543cc28 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Mon, 2 Aug 2010 17:49:01 -0700 Subject: glsl2: Fix typo in clamp() constant builtin using uint instead of int. I take back the bad things I've said about the signed/unsigned comparison warning now. --- src/glsl/ir_constant_expression.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index 915d362b15..06bea2bef6 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -856,7 +856,7 @@ ir_call::constant_expression_value() break; case GLSL_TYPE_INT: data.i[c] = CLAMP(op[0]->value.i[c], op[1]->value.i[c1], - op[2]->value.u[c2]); + op[2]->value.i[c2]); break; case GLSL_TYPE_FLOAT: data.f[c] = CLAMP(op[0]->value.f[c], op[1]->value.f[c1], -- cgit v1.2.3 From 8273bd46877e2ea2b8a02b87a11c68102d07e1f2 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Wed, 4 Aug 2010 12:34:56 -0700 Subject: glsl2: Make the clone() method take a talloc context. In most cases, we needed to be reparenting the cloned IR to a different context (for example, to the linked shader instead of the unlinked shader), or optimization before the reparent would cause memory usage of the original object to grow and grow. --- src/glsl/ast_to_hir.cpp | 10 +-- src/glsl/ir.h | 47 +++++----- src/glsl/ir_clone.cpp | 150 ++++++++++++++----------------- src/glsl/ir_constant_expression.cpp | 7 +- src/glsl/ir_function_inlining.cpp | 6 +- src/glsl/ir_import_prototypes.cpp | 2 +- src/glsl/ir_vec_index_to_cond_assign.cpp | 8 +- src/glsl/link_functions.cpp | 6 +- src/glsl/linker.cpp | 25 +++--- 9 files changed, 130 insertions(+), 131 deletions(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp index 3522f55aac..b65a323a8d 100644 --- a/src/glsl/ast_to_hir.cpp +++ b/src/glsl/ast_to_hir.cpp @@ -966,7 +966,7 @@ ast_expression::hir(exec_list *instructions, op[0], op[1]); result = do_assignment(instructions, state, - op[0]->clone(NULL), temp_rhs, + op[0]->clone(ctx, NULL), temp_rhs, this->subexpressions[0]->get_location()); type = result->type; error_emitted = (op[0]->type->is_error()); @@ -992,7 +992,7 @@ ast_expression::hir(exec_list *instructions, op[0], op[1]); result = do_assignment(instructions, state, - op[0]->clone(NULL), temp_rhs, + op[0]->clone(ctx, NULL), temp_rhs, this->subexpressions[0]->get_location()); type = result->type; error_emitted = type->is_error(); @@ -1113,7 +1113,7 @@ ast_expression::hir(exec_list *instructions, op[0], op[1]); result = do_assignment(instructions, state, - op[0]->clone(NULL), temp_rhs, + op[0]->clone(ctx, NULL), temp_rhs, this->subexpressions[0]->get_location()); type = result->type; error_emitted = op[0]->type->is_error(); @@ -1139,10 +1139,10 @@ ast_expression::hir(exec_list *instructions, /* Get a temporary of a copy of the lvalue before it's modified. * This may get thrown away later. */ - result = get_lvalue_copy(instructions, op[0]->clone(NULL)); + result = get_lvalue_copy(instructions, op[0]->clone(ctx, NULL)); (void)do_assignment(instructions, state, - op[0]->clone(NULL), temp_rhs, + op[0]->clone(ctx, NULL), temp_rhs, this->subexpressions[0]->get_location()); type = result->type; diff --git a/src/glsl/ir.h b/src/glsl/ir.h index f88a243cc0..f964b36083 100644 --- a/src/glsl/ir.h +++ b/src/glsl/ir.h @@ -76,7 +76,8 @@ public: virtual void accept(ir_visitor *) = 0; virtual ir_visitor_status accept(ir_hierarchical_visitor *) = 0; - virtual ir_instruction *clone(struct hash_table *ht) const = 0; + virtual ir_instruction *clone(void *mem_ctx, + struct hash_table *ht) const = 0; /** * \name IR instruction downcast functions @@ -113,7 +114,7 @@ protected: class ir_rvalue : public ir_instruction { public: - virtual ir_rvalue *clone(struct hash_table *) const = 0; + virtual ir_rvalue *clone(void *mem_ctx, struct hash_table *) const = 0; virtual ir_constant *constant_expression_value() = 0; @@ -175,7 +176,7 @@ class ir_variable : public ir_instruction { public: ir_variable(const struct glsl_type *, const char *, ir_variable_mode); - virtual ir_variable *clone(struct hash_table *ht) const; + virtual ir_variable *clone(void *mem_ctx, struct hash_table *ht) const; virtual ir_variable *as_variable() { @@ -283,7 +284,8 @@ class ir_function_signature : public ir_instruction { public: ir_function_signature(const glsl_type *return_type); - virtual ir_function_signature *clone(struct hash_table *ht) const; + virtual ir_function_signature *clone(void *mem_ctx, + struct hash_table *ht) const; virtual void accept(ir_visitor *v) { @@ -369,7 +371,7 @@ class ir_function : public ir_instruction { public: ir_function(const char *name); - virtual ir_function *clone(struct hash_table *ht) const; + virtual ir_function *clone(void *mem_ctx, struct hash_table *ht) const; virtual ir_function *as_function() { @@ -439,7 +441,7 @@ public: ir_type = ir_type_if; } - virtual ir_if *clone(struct hash_table *ht) const; + virtual ir_if *clone(void *mem_ctx, struct hash_table *ht) const; virtual ir_if *as_if() { @@ -471,7 +473,7 @@ public: ir_type = ir_type_loop; } - virtual ir_loop *clone(struct hash_table *ht) const; + virtual ir_loop *clone(void *mem_ctx, struct hash_table *ht) const; virtual void accept(ir_visitor *v) { @@ -512,7 +514,7 @@ class ir_assignment : public ir_instruction { public: ir_assignment(ir_rvalue *lhs, ir_rvalue *rhs, ir_rvalue *condition); - virtual ir_assignment *clone(struct hash_table *ht) const; + virtual ir_assignment *clone(void *mem_ctx, struct hash_table *ht) const; virtual ir_constant *constant_expression_value(); @@ -662,7 +664,7 @@ public: return this; } - virtual ir_expression *clone(struct hash_table *ht) const; + virtual ir_expression *clone(void *mem_ctx, struct hash_table *ht) const; virtual ir_constant *constant_expression_value(); @@ -708,7 +710,7 @@ public: actual_parameters->move_nodes_to(& this->actual_parameters); } - virtual ir_call *clone(struct hash_table *ht) const; + virtual ir_call *clone(void *mem_ctx, struct hash_table *ht) const; virtual ir_constant *constant_expression_value(); @@ -805,7 +807,7 @@ public: this->ir_type = ir_type_return; } - virtual ir_return *clone(struct hash_table *) const; + virtual ir_return *clone(void *mem_ctx, struct hash_table *) const; virtual ir_return *as_return() { @@ -850,7 +852,7 @@ public: this->loop = loop; } - virtual ir_loop_jump *clone(struct hash_table *) const; + virtual ir_loop_jump *clone(void *mem_ctx, struct hash_table *) const; virtual void accept(ir_visitor *v) { @@ -893,7 +895,7 @@ public: this->condition = cond; } - virtual ir_discard *clone(struct hash_table *ht) const; + virtual ir_discard *clone(void *mem_ctx, struct hash_table *ht) const; virtual void accept(ir_visitor *v) { @@ -945,7 +947,7 @@ public: this->ir_type = ir_type_texture; } - virtual ir_texture *clone(struct hash_table *) const; + virtual ir_texture *clone(void *mem_ctx, struct hash_table *) const; virtual ir_constant *constant_expression_value(); @@ -1037,7 +1039,7 @@ public: ir_swizzle(ir_rvalue *val, ir_swizzle_mask mask); - virtual ir_swizzle *clone(struct hash_table *) const; + virtual ir_swizzle *clone(void *mem_ctx, struct hash_table *) const; virtual ir_constant *constant_expression_value(); @@ -1083,7 +1085,7 @@ private: class ir_dereference : public ir_rvalue { public: - virtual ir_dereference *clone(struct hash_table *) const = 0; + virtual ir_dereference *clone(void *mem_ctx, struct hash_table *) const = 0; virtual ir_dereference *as_dereference() { @@ -1103,7 +1105,8 @@ class ir_dereference_variable : public ir_dereference { public: ir_dereference_variable(ir_variable *var); - virtual ir_dereference_variable *clone(struct hash_table *) const; + virtual ir_dereference_variable *clone(void *mem_ctx, + struct hash_table *) const; virtual ir_constant *constant_expression_value(); @@ -1151,7 +1154,8 @@ public: ir_dereference_array(ir_variable *var, ir_rvalue *array_index); - virtual ir_dereference_array *clone(struct hash_table *) const; + virtual ir_dereference_array *clone(void *mem_ctx, + struct hash_table *) const; virtual ir_constant *constant_expression_value(); @@ -1189,7 +1193,8 @@ public: ir_dereference_record(ir_variable *var, const char *field); - virtual ir_dereference_record *clone(struct hash_table *) const; + virtual ir_dereference_record *clone(void *mem_ctx, + struct hash_table *) const; virtual ir_constant *constant_expression_value(); @@ -1254,7 +1259,7 @@ public: */ static ir_constant *zero(void *mem_ctx, const glsl_type *type); - virtual ir_constant *clone(struct hash_table *) const; + virtual ir_constant *clone(void *mem_ctx, struct hash_table *) const; virtual ir_constant *constant_expression_value(); @@ -1327,7 +1332,7 @@ void validate_ir_tree(exec_list *instructions); * \param out List to hold the cloned instructions */ void -clone_ir_list(exec_list *out, const exec_list *in); +clone_ir_list(void *mem_ctx, exec_list *out, const exec_list *in); extern void _mesa_glsl_initialize_variables(exec_list *instructions, diff --git a/src/glsl/ir_clone.cpp b/src/glsl/ir_clone.cpp index 5ea3a79afc..59831834bd 100644 --- a/src/glsl/ir_clone.cpp +++ b/src/glsl/ir_clone.cpp @@ -36,11 +36,10 @@ extern "C" { * eventually. */ ir_variable * -ir_variable::clone(struct hash_table *ht) const +ir_variable::clone(void *mem_ctx, struct hash_table *ht) const { - void *ctx = talloc_parent(this); - ir_variable *var = new(ctx) ir_variable(this->type, this->name, - (ir_variable_mode) this->mode); + ir_variable *var = new(mem_ctx) ir_variable(this->type, this->name, + (ir_variable_mode) this->mode); var->max_array_access = this->max_array_access; var->read_only = this->read_only; @@ -56,7 +55,7 @@ ir_variable::clone(struct hash_table *ht) const var->pixel_center_integer = this->pixel_center_integer; if (this->constant_value) - var->constant_value = this->constant_value->clone(ht); + var->constant_value = this->constant_value->clone(mem_ctx, ht); if (ht) { hash_table_insert(ht, var, (void *)const_cast(this)); @@ -66,118 +65,109 @@ ir_variable::clone(struct hash_table *ht) const } ir_swizzle * -ir_swizzle::clone(struct hash_table *ht) const +ir_swizzle::clone(void *mem_ctx, struct hash_table *ht) const { - void *ctx = talloc_parent(this); - return new(ctx) ir_swizzle(this->val->clone(ht), this->mask); + return new(mem_ctx) ir_swizzle(this->val->clone(mem_ctx, ht), this->mask); } ir_return * -ir_return::clone(struct hash_table *ht) const +ir_return::clone(void *mem_ctx, struct hash_table *ht) const { - void *ctx = talloc_parent(this); ir_rvalue *new_value = NULL; if (this->value) - new_value = this->value->clone(ht); + new_value = this->value->clone(mem_ctx, ht); - return new(ctx) ir_return(new_value); + return new(mem_ctx) ir_return(new_value); } ir_discard * -ir_discard::clone(struct hash_table *ht) const +ir_discard::clone(void *mem_ctx, struct hash_table *ht) const { - void *ctx = talloc_parent(this); ir_rvalue *new_condition = NULL; if (this->condition != NULL) - new_condition = this->condition->clone(ht); + new_condition = this->condition->clone(mem_ctx, ht); - return new(ctx) ir_discard(new_condition); + return new(mem_ctx) ir_discard(new_condition); } ir_loop_jump * -ir_loop_jump::clone(struct hash_table *ht) const +ir_loop_jump::clone(void *mem_ctx, struct hash_table *ht) const { - void *ctx = talloc_parent(this); (void)ht; - return new(ctx) ir_loop_jump(this->mode); + return new(mem_ctx) ir_loop_jump(this->mode); } ir_if * -ir_if::clone(struct hash_table *ht) const +ir_if::clone(void *mem_ctx, struct hash_table *ht) const { - void *ctx = talloc_parent(this); - ir_if *new_if = new(ctx) ir_if(this->condition->clone(ht)); + ir_if *new_if = new(mem_ctx) ir_if(this->condition->clone(mem_ctx, ht)); foreach_iter(exec_list_iterator, iter, this->then_instructions) { ir_instruction *ir = (ir_instruction *)iter.get(); - new_if->then_instructions.push_tail(ir->clone(ht)); + new_if->then_instructions.push_tail(ir->clone(mem_ctx, ht)); } foreach_iter(exec_list_iterator, iter, this->else_instructions) { ir_instruction *ir = (ir_instruction *)iter.get(); - new_if->else_instructions.push_tail(ir->clone(ht)); + new_if->else_instructions.push_tail(ir->clone(mem_ctx, ht)); } return new_if; } ir_loop * -ir_loop::clone(struct hash_table *ht) const +ir_loop::clone(void *mem_ctx, struct hash_table *ht) const { - void *ctx = talloc_parent(this); - ir_loop *new_loop = new(ctx) ir_loop(); + ir_loop *new_loop = new(mem_ctx) ir_loop(); if (this->from) - new_loop->from = this->from->clone(ht); + new_loop->from = this->from->clone(mem_ctx, ht); if (this->to) - new_loop->to = this->to->clone(ht); + new_loop->to = this->to->clone(mem_ctx, ht); if (this->increment) - new_loop->increment = this->increment->clone(ht); + new_loop->increment = this->increment->clone(mem_ctx, ht); new_loop->counter = counter; foreach_iter(exec_list_iterator, iter, this->body_instructions) { ir_instruction *ir = (ir_instruction *)iter.get(); - new_loop->body_instructions.push_tail(ir->clone(ht)); + new_loop->body_instructions.push_tail(ir->clone(mem_ctx, ht)); } return new_loop; } ir_call * -ir_call::clone(struct hash_table *ht) const +ir_call::clone(void *mem_ctx, struct hash_table *ht) const { - void *ctx = talloc_parent(this); exec_list new_parameters; foreach_iter(exec_list_iterator, iter, this->actual_parameters) { ir_instruction *ir = (ir_instruction *)iter.get(); - new_parameters.push_tail(ir->clone(ht)); + new_parameters.push_tail(ir->clone(mem_ctx, ht)); } - return new(ctx) ir_call(this->callee, &new_parameters); + return new(mem_ctx) ir_call(this->callee, &new_parameters); } ir_expression * -ir_expression::clone(struct hash_table *ht) const +ir_expression::clone(void *mem_ctx, struct hash_table *ht) const { - void *ctx = talloc_parent(this); ir_rvalue *op[2] = {NULL, NULL}; unsigned int i; for (i = 0; i < get_num_operands(); i++) { - op[i] = this->operands[i]->clone(ht); + op[i] = this->operands[i]->clone(mem_ctx, ht); } - return new(ctx) ir_expression(this->operation, this->type, op[0], op[1]); + return new(mem_ctx) ir_expression(this->operation, this->type, op[0], op[1]); } ir_dereference_variable * -ir_dereference_variable::clone(struct hash_table *ht) const +ir_dereference_variable::clone(void *mem_ctx, struct hash_table *ht) const { - void *ctx = talloc_parent(this); ir_variable *new_var; if (ht) { @@ -188,38 +178,36 @@ ir_dereference_variable::clone(struct hash_table *ht) const new_var = this->var; } - return new(ctx) ir_dereference_variable(new_var); + return new(mem_ctx) ir_dereference_variable(new_var); } ir_dereference_array * -ir_dereference_array::clone(struct hash_table *ht) const +ir_dereference_array::clone(void *mem_ctx, struct hash_table *ht) const { - void *ctx = talloc_parent(this); - return new(ctx) ir_dereference_array(this->array->clone(ht), - this->array_index->clone(ht)); + return new(mem_ctx) ir_dereference_array(this->array->clone(mem_ctx, ht), + this->array_index->clone(mem_ctx, + ht)); } ir_dereference_record * -ir_dereference_record::clone(struct hash_table *ht) const +ir_dereference_record::clone(void *mem_ctx, struct hash_table *ht) const { - void *ctx = talloc_parent(this); - return new(ctx) ir_dereference_record(this->record->clone(ht), - this->field); + return new(mem_ctx) ir_dereference_record(this->record->clone(mem_ctx, ht), + this->field); } ir_texture * -ir_texture::clone(struct hash_table *ht) const +ir_texture::clone(void *mem_ctx, struct hash_table *ht) const { - void *ctx = talloc_parent(this); - ir_texture *new_tex = new(ctx) ir_texture(this->op); + ir_texture *new_tex = new(mem_ctx) ir_texture(this->op); new_tex->type = this->type; - new_tex->sampler = this->sampler->clone(ht); - new_tex->coordinate = this->coordinate->clone(ht); + new_tex->sampler = this->sampler->clone(mem_ctx, ht); + new_tex->coordinate = this->coordinate->clone(mem_ctx, ht); if (this->projector) - new_tex->projector = this->projector->clone(ht); + new_tex->projector = this->projector->clone(mem_ctx, ht); if (this->shadow_comparitor) { - new_tex->shadow_comparitor = this->shadow_comparitor->clone(ht); + new_tex->shadow_comparitor = this->shadow_comparitor->clone(mem_ctx, ht); } for (int i = 0; i < 3; i++) @@ -229,15 +217,15 @@ ir_texture::clone(struct hash_table *ht) const case ir_tex: break; case ir_txb: - new_tex->lod_info.bias = this->lod_info.bias->clone(ht); + new_tex->lod_info.bias = this->lod_info.bias->clone(mem_ctx, ht); break; case ir_txl: case ir_txf: - new_tex->lod_info.lod = this->lod_info.lod->clone(ht); + new_tex->lod_info.lod = this->lod_info.lod->clone(mem_ctx, ht); break; case ir_txd: - new_tex->lod_info.grad.dPdx = this->lod_info.grad.dPdx->clone(ht); - new_tex->lod_info.grad.dPdy = this->lod_info.grad.dPdy->clone(ht); + new_tex->lod_info.grad.dPdx = this->lod_info.grad.dPdx->clone(mem_ctx, ht); + new_tex->lod_info.grad.dPdy = this->lod_info.grad.dPdy->clone(mem_ctx, ht); break; } @@ -245,30 +233,28 @@ ir_texture::clone(struct hash_table *ht) const } ir_assignment * -ir_assignment::clone(struct hash_table *ht) const +ir_assignment::clone(void *mem_ctx, struct hash_table *ht) const { ir_rvalue *new_condition = NULL; if (this->condition) - new_condition = this->condition->clone(ht); + new_condition = this->condition->clone(mem_ctx, ht); - void *ctx = talloc_parent(this); - return new(ctx) ir_assignment(this->lhs->clone(ht), - this->rhs->clone(ht), - new_condition); + return new(mem_ctx) ir_assignment(this->lhs->clone(mem_ctx, ht), + this->rhs->clone(mem_ctx, ht), + new_condition); } ir_function * -ir_function::clone(struct hash_table *ht) const +ir_function::clone(void *mem_ctx, struct hash_table *ht) const { - void *mem_ctx = talloc_parent(this); ir_function *copy = new(mem_ctx) ir_function(this->name); foreach_list_const(node, &this->signatures) { const ir_function_signature *const sig = (const ir_function_signature *const) node; - ir_function_signature *sig_copy = sig->clone(ht); + ir_function_signature *sig_copy = sig->clone(mem_ctx, ht); copy->add_signature(sig_copy); if (ht != NULL) @@ -280,9 +266,8 @@ ir_function::clone(struct hash_table *ht) const } ir_function_signature * -ir_function_signature::clone(struct hash_table *ht) const +ir_function_signature::clone(void *mem_ctx, struct hash_table *ht) const { - void *mem_ctx = talloc_parent(this); ir_function_signature *copy = new(mem_ctx) ir_function_signature(this->return_type); @@ -296,7 +281,7 @@ ir_function_signature::clone(struct hash_table *ht) const assert(const_cast(param)->as_variable() != NULL); - ir_variable *const param_copy = param->clone(ht); + ir_variable *const param_copy = param->clone(mem_ctx, ht); copy->parameters.push_tail(param_copy); } @@ -305,7 +290,7 @@ ir_function_signature::clone(struct hash_table *ht) const foreach_list_const(node, &this->body) { const ir_instruction *const inst = (const ir_instruction *) node; - ir_instruction *const inst_copy = inst->clone(ht); + ir_instruction *const inst_copy = inst->clone(mem_ctx, ht); copy->body.push_tail(inst_copy); } @@ -313,9 +298,8 @@ ir_function_signature::clone(struct hash_table *ht) const } ir_constant * -ir_constant::clone(struct hash_table *ht) const +ir_constant::clone(void *mem_ctx, struct hash_table *ht) const { - void *ctx = talloc_parent(this); (void)ht; switch (this->type->base_type) { @@ -323,10 +307,10 @@ ir_constant::clone(struct hash_table *ht) const case GLSL_TYPE_INT: case GLSL_TYPE_FLOAT: case GLSL_TYPE_BOOL: - return new(ctx) ir_constant(this->type, &this->value); + return new(mem_ctx) ir_constant(this->type, &this->value); case GLSL_TYPE_STRUCT: { - ir_constant *c = new(ctx) ir_constant; + ir_constant *c = new(mem_ctx) ir_constant; c->type = this->type; for (exec_node *node = this->components.head @@ -334,19 +318,19 @@ ir_constant::clone(struct hash_table *ht) const ; node = node->next) { ir_constant *const orig = (ir_constant *) node; - c->components.push_tail(orig->clone(NULL)); + c->components.push_tail(orig->clone(mem_ctx, NULL)); } return c; } case GLSL_TYPE_ARRAY: { - ir_constant *c = new(ctx) ir_constant; + ir_constant *c = new(mem_ctx) ir_constant; c->type = this->type; c->array_elements = talloc_array(c, ir_constant *, this->type->length); for (unsigned i = 0; i < this->type->length; i++) { - c->array_elements[i] = this->array_elements[i]->clone(NULL); + c->array_elements[i] = this->array_elements[i]->clone(mem_ctx, NULL); } return c; } @@ -395,14 +379,14 @@ fixup_function_calls(struct hash_table *ht, exec_list *instructions) void -clone_ir_list(exec_list *out, const exec_list *in) +clone_ir_list(void *mem_ctx, exec_list *out, const exec_list *in) { struct hash_table *ht = hash_table_ctor(0, hash_table_pointer_hash, hash_table_pointer_compare); foreach_list_const(node, in) { const ir_instruction *const original = (ir_instruction *) node; - ir_instruction *copy = original->clone(ht); + ir_instruction *copy = original->clone(mem_ctx, ht); out->push_tail(copy); } diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index 06bea2bef6..677353e542 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -680,7 +680,10 @@ ir_dereference_variable::constant_expression_value() if (var->mode == ir_var_uniform) return NULL; - return var->constant_value ? var->constant_value->clone(NULL) : NULL; + if (!var->constant_value) + return NULL; + + return var->constant_value->clone(talloc_parent(var), NULL); } @@ -732,7 +735,7 @@ ir_dereference_array::constant_expression_value() return new(ctx) ir_constant(array, component); } else { const unsigned index = idx->value.u[0]; - return array->get_array_element(index)->clone(NULL); + return array->get_array_element(index)->clone(ctx, NULL); } } return NULL; diff --git a/src/glsl/ir_function_inlining.cpp b/src/glsl/ir_function_inlining.cpp index 9599306243..973813774e 100644 --- a/src/glsl/ir_function_inlining.cpp +++ b/src/glsl/ir_function_inlining.cpp @@ -147,7 +147,7 @@ ir_call::generate_inline(ir_instruction *next_ir) parameters[i] = NULL; hash_table_insert(ht, param->variable_referenced(), sig_param); } else { - parameters[i] = sig_param->clone(ht); + parameters[i] = sig_param->clone(ctx, ht); parameters[i]->mode = ir_var_auto; next_ir->insert_before(parameters[i]); } @@ -169,7 +169,7 @@ ir_call::generate_inline(ir_instruction *next_ir) /* Generate the inlined body of the function. */ foreach_iter(exec_list_iterator, iter, callee->body) { ir_instruction *ir = (ir_instruction *)iter.get(); - ir_instruction *new_ir = ir->clone(ht); + ir_instruction *new_ir = ir->clone(ctx, ht); next_ir->insert_before(new_ir); visit_tree(new_ir, replace_return_with_assignment, retval); @@ -190,7 +190,7 @@ ir_call::generate_inline(ir_instruction *next_ir) sig_param->mode == ir_var_inout)) { ir_assignment *assign; - assign = new(ctx) ir_assignment(param->clone(NULL)->as_rvalue(), + assign = new(ctx) ir_assignment(param->clone(ctx, NULL)->as_rvalue(), new(ctx) ir_dereference_variable(parameters[i]), NULL); next_ir->insert_before(assign); diff --git a/src/glsl/ir_import_prototypes.cpp b/src/glsl/ir_import_prototypes.cpp index 5c5dc00ad7..e553e12a49 100644 --- a/src/glsl/ir_import_prototypes.cpp +++ b/src/glsl/ir_import_prototypes.cpp @@ -95,7 +95,7 @@ public: assert(const_cast(param)->as_variable() != NULL); - ir_variable *const param_copy = param->clone(NULL); + ir_variable *const param_copy = param->clone(mem_ctx, NULL); copy->parameters.push_tail(param_copy); } diff --git a/src/glsl/ir_vec_index_to_cond_assign.cpp b/src/glsl/ir_vec_index_to_cond_assign.cpp index dbc6f9ada8..cd8dedf2fe 100644 --- a/src/glsl/ir_vec_index_to_cond_assign.cpp +++ b/src/glsl/ir_vec_index_to_cond_assign.cpp @@ -82,6 +82,8 @@ ir_vec_index_to_cond_assign_visitor::convert_vec_index_to_cond_assign(ir_rvalue orig_deref->array->type->is_array()) return ir; + void *mem_ctx = talloc_parent(ir); + assert(orig_deref->array_index->type->base_type == GLSL_TYPE_INT); /* Store the index to a temporary to avoid reusing its tree. */ @@ -109,7 +111,7 @@ ir_vec_index_to_cond_assign_visitor::convert_vec_index_to_cond_assign(ir_rvalue /* Just clone the rest of the deref chain when trying to get at the * underlying variable. */ - swizzle = new(base_ir) ir_swizzle(orig_deref->array->clone(NULL), + swizzle = new(base_ir) ir_swizzle(orig_deref->array->clone(mem_ctx, NULL), i, 0, 0, 0, 1); deref = new(base_ir) ir_dereference_variable(var); @@ -165,6 +167,8 @@ ir_vec_index_to_cond_assign_visitor::visit_leave(ir_assignment *ir) orig_deref->array->type->is_array()) return visit_continue; + void *mem_ctx = talloc_parent(ir); + assert(orig_deref->array_index->type->base_type == GLSL_TYPE_INT); /* Store the index to a temporary to avoid reusing its tree. */ @@ -196,7 +200,7 @@ ir_vec_index_to_cond_assign_visitor::visit_leave(ir_assignment *ir) /* Just clone the rest of the deref chain when trying to get at the * underlying variable. */ - swizzle = new(ir) ir_swizzle(orig_deref->array->clone(NULL), + swizzle = new(ir) ir_swizzle(orig_deref->array->clone(mem_ctx, NULL), i, 0, 0, 0, 1); deref = new(ir) ir_dereference_variable(var); diff --git a/src/glsl/link_functions.cpp b/src/glsl/link_functions.cpp index fdf886f662..dfda05fcbe 100644 --- a/src/glsl/link_functions.cpp +++ b/src/glsl/link_functions.cpp @@ -143,7 +143,7 @@ public: const ir_instruction *const original = (ir_instruction *) node; assert(const_cast(original)->as_variable()); - ir_instruction *copy = original->clone(ht); + ir_instruction *copy = original->clone(linked, ht); formal_parameters.push_tail(copy); } @@ -152,7 +152,7 @@ public: foreach_list_const(node, &sig->body) { const ir_instruction *const original = (ir_instruction *) node; - ir_instruction *copy = original->clone(ht); + ir_instruction *copy = original->clone(linked, ht); linked_sig->body.push_tail(copy); } @@ -182,7 +182,7 @@ public: /* Clone the ir_variable that the dereference already has and add * it to the linked shader. */ - var = ir->var->clone(NULL); + var = ir->var->clone(linked, NULL); linked->symbols->add_variable(var->name, var); linked->ir->push_head(var); } diff --git a/src/glsl/linker.cpp b/src/glsl/linker.cpp index a5faff2be7..65f3697d35 100644 --- a/src/glsl/linker.cpp +++ b/src/glsl/linker.cpp @@ -323,7 +323,8 @@ cross_validate_globals(struct gl_shader_program *prog, * FINISHME: modify the shader, and linking with the second * FINISHME: will fail. */ - existing->constant_value = var->constant_value->clone(NULL); + existing->constant_value = + var->constant_value->clone(talloc_parent(existing), NULL); } } else variables.add_variable(var->name, var); @@ -488,16 +489,17 @@ populate_symbol_table(gl_shader *sh) * should be added. */ void -remap_variables(ir_instruction *inst, glsl_symbol_table *symbols, - exec_list *instructions, hash_table *temps) +remap_variables(ir_instruction *inst, struct gl_shader *target, + hash_table *temps) { class remap_visitor : public ir_hierarchical_visitor { public: - remap_visitor(glsl_symbol_table *symbols, exec_list *instructions, + remap_visitor(struct gl_shader *target, hash_table *temps) { - this->symbols = symbols; - this->instructions = instructions; + this->target = target; + this->symbols = target->symbols; + this->instructions = target->ir; this->temps = temps; } @@ -516,7 +518,7 @@ remap_variables(ir_instruction *inst, glsl_symbol_table *symbols, if (existing != NULL) ir->var = existing; else { - ir_variable *copy = ir->var->clone(NULL); + ir_variable *copy = ir->var->clone(this->target, NULL); this->symbols->add_variable(copy->name, copy); this->instructions->push_head(copy); @@ -527,12 +529,13 @@ remap_variables(ir_instruction *inst, glsl_symbol_table *symbols, } private: + struct gl_shader *target; glsl_symbol_table *symbols; exec_list *instructions; hash_table *temps; }; - remap_visitor v(symbols, instructions, temps); + remap_visitor v(target, temps); inst->accept(&v); } @@ -583,12 +586,12 @@ move_non_declarations(exec_list *instructions, exec_node *last, || ((var != NULL) && (var->mode == ir_var_temporary))); if (make_copies) { - inst = inst->clone(NULL); + inst = inst->clone(target, NULL); if (var != NULL) hash_table_insert(temps, inst, var); else - remap_variables(inst, target->symbols, target->ir, temps); + remap_variables(inst, target, temps); } else { inst->remove(); } @@ -713,7 +716,7 @@ link_intrastage_shaders(struct gl_shader_program *prog, gl_shader *const linked = _mesa_new_shader(NULL, 0, main->Type); linked->ir = new(linked) exec_list; - clone_ir_list(linked->ir, main->ir); + clone_ir_list(linked, linked->ir, main->ir); populate_symbol_table(linked); -- cgit v1.2.3 From 952d0f88e1741d51b641be75f7c5a6565e245a69 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Wed, 4 Aug 2010 12:57:58 -0700 Subject: glsl2: Skip talloc_parent in constant_expression of non-constant arrays. --- src/glsl/ir_constant_expression.cpp | 2 +- src/mesa/program/ir_to_mesa.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index 677353e542..0a924246da 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -690,11 +690,11 @@ ir_dereference_variable::constant_expression_value() ir_constant * ir_dereference_array::constant_expression_value() { - void *ctx = talloc_parent(this); ir_constant *array = this->array->constant_expression_value(); ir_constant *idx = this->array_index->constant_expression_value(); if ((array != NULL) && (idx != NULL)) { + void *ctx = talloc_parent(this); if (array->type->is_matrix()) { /* Array access of a matrix results in a vector. */ diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp index ba0934c446..dcf8c497c6 100644 --- a/src/mesa/program/ir_to_mesa.cpp +++ b/src/mesa/program/ir_to_mesa.cpp @@ -2622,7 +2622,7 @@ _mesa_glsl_compile_shader(GLcontext *ctx, struct gl_shader *shader) progress = do_constant_folding(shader->ir) || progress; progress = do_algebraic(shader->ir) || progress; progress = do_if_return(shader->ir) || progress; - if (ctx->Shader.EmitNoIfs) + if (1 || ctx->Shader.EmitNoIfs) progress = do_if_to_cond_assign(shader->ir) || progress; progress = do_vec_index_to_swizzle(shader->ir) || progress; -- cgit v1.2.3 From d12cb77d85ec726a67c2099c4105df63829b45a4 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Wed, 18 Aug 2010 12:06:25 -0700 Subject: ir_constant_expression: Implement equal/notEqual for booleans. Calls to equal(bvec, bvec) or notEqual(bvec, bvec) previously caused an assertion. Fixes piglit tests glsl-const-builtin-equal-bool and glsl-const-builtin-notEqual-bool. --- src/glsl/ir_constant_expression.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index 0a924246da..54f14d1a54 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -904,6 +904,9 @@ ir_call::constant_expression_value() case GLSL_TYPE_FLOAT: data.b[c] = op[0]->value.f[c] == op[1]->value.f[c]; break; + case GLSL_TYPE_BOOL: + data.b[c] = op[0]->value.b[c] == op[1]->value.b[c]; + break; default: assert(!"Should not get here."); } @@ -1047,6 +1050,9 @@ ir_call::constant_expression_value() case GLSL_TYPE_FLOAT: data.b[c] = op[0]->value.f[c] != op[1]->value.f[c]; break; + case GLSL_TYPE_BOOL: + data.b[c] = op[0]->value.b[c] != op[1]->value.b[c]; + break; default: assert(!"Should not get here."); } -- cgit v1.2.3 From 5e9ac94cc44ef4f97063d7b696411b2a4be16f36 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Mon, 23 Aug 2010 12:21:33 -0700 Subject: mesa: Add new ir_unop_any() expression operation. The previous any() implementation would generate arg0.x || arg0.y || arg0.z. Having an expression operation for this makes it easy for the backend to generate something easier (DPn + SNE for 915 FS, .any predication on 965 VS) --- src/glsl/README | 1 + src/glsl/builtins/ir/any | 6 +++--- src/glsl/ir.cpp | 2 ++ src/glsl/ir.h | 1 + src/glsl/ir_constant_expression.cpp | 9 +++++++++ src/glsl/ir_validate.cpp | 5 +++++ src/mesa/program/ir_to_mesa.cpp | 20 ++++++++++++++++++++ 7 files changed, 41 insertions(+), 3 deletions(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/README b/src/glsl/README index 74520321b2..2e501d6206 100644 --- a/src/glsl/README +++ b/src/glsl/README @@ -180,6 +180,7 @@ ir.h (new enum) ir.cpp:get_num_operands() (used for ir_reader) ir.cpp:operator_strs (used for ir_reader) ir_constant_expression.cpp (you probably want to be able to constant fold) +ir_validate.cpp (check users have the right types) You may also need to update the backends if they will see the new expr type: diff --git a/src/glsl/builtins/ir/any b/src/glsl/builtins/ir/any index f10e8a7b47..cc6038a315 100644 --- a/src/glsl/builtins/ir/any +++ b/src/glsl/builtins/ir/any @@ -2,15 +2,15 @@ (signature bool (parameters (declare (in) bvec2 arg0)) - ((return (expression bool || (swiz x (var_ref arg0))(swiz y (var_ref arg0)))))) + ((return (expression bool any (var_ref arg0))))) (signature bool (parameters (declare (in) bvec3 arg0)) - ((return (expression bool || (expression bool || (swiz x (var_ref arg0))(swiz y (var_ref arg0))) (swiz z (var_ref arg0)))))) + ((return (expression bool any (var_ref arg0))))) (signature bool (parameters (declare (in) bvec4 arg0)) - ((return (expression bool || (expression bool || (expression bool || (swiz x (var_ref arg0))(swiz y (var_ref arg0))) (swiz z (var_ref arg0))) (swiz w (var_ref arg0)))))) + ((return (expression bool any (var_ref arg0))))) )) diff --git a/src/glsl/ir.cpp b/src/glsl/ir.cpp index ebb592792b..4622a1f939 100644 --- a/src/glsl/ir.cpp +++ b/src/glsl/ir.cpp @@ -184,6 +184,7 @@ ir_expression::get_num_operands(ir_expression_operation op) 1, /* ir_unop_i2b */ 1, /* ir_unop_b2i */ 1, /* ir_unop_u2f */ + 1, /* ir_unop_any */ 1, /* ir_unop_trunc */ 1, /* ir_unop_ceil */ @@ -252,6 +253,7 @@ static const char *const operator_strs[] = { "i2b", "b2i", "u2f", + "any", "trunc", "ceil", "floor", diff --git a/src/glsl/ir.h b/src/glsl/ir.h index b04222893c..500b152408 100644 --- a/src/glsl/ir.h +++ b/src/glsl/ir.h @@ -604,6 +604,7 @@ enum ir_expression_operation { ir_unop_i2b, /**< int-to-boolean conversion */ ir_unop_b2i, /**< Boolean-to-int conversion */ ir_unop_u2f, /**< Unsigned-to-float conversion. */ + ir_unop_any, /** * \name Unary floating-point rounding operations. diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index 54f14d1a54..942f198360 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -149,6 +149,15 @@ ir_expression::constant_expression_value() } break; + case ir_unop_any: + assert(op[0]->type->is_boolean()); + data.b[0] = false; + for (unsigned c = 0; c < op[0]->type->components(); c++) { + if (op[0]->value.b[c]) + data.b[0] = true; + } + break; + case ir_unop_trunc: assert(op[0]->type->base_type == GLSL_TYPE_FLOAT); for (unsigned c = 0; c < op[0]->type->components(); c++) { diff --git a/src/glsl/ir_validate.cpp b/src/glsl/ir_validate.cpp index 6e08fa4025..9ea11dd400 100644 --- a/src/glsl/ir_validate.cpp +++ b/src/glsl/ir_validate.cpp @@ -223,6 +223,11 @@ ir_validate::visit_leave(ir_expression *ir) assert(ir->type->base_type == GLSL_TYPE_FLOAT); break; + case ir_unop_any: + assert(ir->operands[0]->type->base_type == GLSL_TYPE_BOOL); + assert(ir->type == glsl_type::bool_type); + break; + case ir_unop_trunc: case ir_unop_ceil: case ir_unop_floor: diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp index 7a615f2d58..ea2560af3e 100644 --- a/src/mesa/program/ir_to_mesa.cpp +++ b/src/mesa/program/ir_to_mesa.cpp @@ -844,6 +844,26 @@ ir_to_mesa_visitor::visit(ir_expression *ir) ir_to_mesa_emit_op2(ir, OPCODE_SNE, result_dst, op[0], op[1]); } break; + + case ir_unop_any: + switch (ir->operands[0]->type->vector_elements) { + case 4: + ir_to_mesa_emit_op2(ir, OPCODE_DP4, result_dst, op[0], op[0]); + break; + case 3: + ir_to_mesa_emit_op2(ir, OPCODE_DP3, result_dst, op[0], op[0]); + break; + case 2: + ir_to_mesa_emit_op2(ir, OPCODE_DP2, result_dst, op[0], op[0]); + break; + default: + assert(!"unreached: ir_unop_any of non-bvec"); + break; + } + ir_to_mesa_emit_op2(ir, OPCODE_SNE, + result_dst, result_src, src_reg_for_float(0.0)); + break; + case ir_binop_logic_xor: ir_to_mesa_emit_op2(ir, OPCODE_SNE, result_dst, op[0], op[1]); break; -- cgit v1.2.3 From bfd7c9ac228c7ed8aec04c3b3aa33f40ee00b035 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Mon, 23 Aug 2010 17:51:42 +0800 Subject: glsl: Include main/core.h. Make glsl include only main/core.h from core mesa. --- src/glsl/ast_function.cpp | 2 +- src/glsl/ast_to_hir.cpp | 3 +-- src/glsl/builtin_function.cpp | 2 +- src/glsl/builtin_variables.h | 2 +- src/glsl/builtins/tools/generate_builtins.py | 2 +- src/glsl/glcpp/glcpp-parse.c | 2 +- src/glsl/glcpp/glcpp-parse.y | 2 +- src/glsl/glsl_parser_extras.cpp | 2 +- src/glsl/glsl_types.cpp | 3 +-- src/glsl/hir_field_selection.cpp | 1 - src/glsl/ir.cpp | 3 +-- src/glsl/ir_constant_expression.cpp | 2 +- src/glsl/ir_explog_to_explog2.cpp | 2 +- src/glsl/ir_set_program_inouts.cpp | 2 +- src/glsl/ir_variable.cpp | 1 - src/glsl/link_functions.cpp | 2 +- src/glsl/linker.cpp | 5 +---- src/glsl/program.h | 8 +------- 18 files changed, 16 insertions(+), 30 deletions(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ast_function.cpp b/src/glsl/ast_function.cpp index f85b308c1b..34b0f70d41 100644 --- a/src/glsl/ast_function.cpp +++ b/src/glsl/ast_function.cpp @@ -25,7 +25,7 @@ #include "ast.h" #include "glsl_types.h" #include "ir.h" -#include "main/macros.h" +#include "main/core.h" /* for MIN2 */ static ir_rvalue * convert_component(ir_rvalue *src, const glsl_type *desired_type); diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp index 57e331742e..64b142fa35 100644 --- a/src/glsl/ast_to_hir.cpp +++ b/src/glsl/ast_to_hir.cpp @@ -49,8 +49,7 @@ * parser (and lexer) sources. */ -#include "main/imports.h" -#include "main/extensions.h" +#include "main/core.h" /* for struct gl_extensions */ #include "glsl_symbol_table.h" #include "glsl_parser_extras.h" #include "ast.h" diff --git a/src/glsl/builtin_function.cpp b/src/glsl/builtin_function.cpp index 5471ba6020..a277ed6e8d 100644 --- a/src/glsl/builtin_function.cpp +++ b/src/glsl/builtin_function.cpp @@ -23,7 +23,7 @@ */ #include -#include "main/compiler.h" +#include "main/core.h" /* for struct gl_shader */ #include "glsl_parser_extras.h" #include "ir_reader.h" #include "program.h" diff --git a/src/glsl/builtin_variables.h b/src/glsl/builtin_variables.h index 2ec7d621bb..a7dbe480e9 100644 --- a/src/glsl/builtin_variables.h +++ b/src/glsl/builtin_variables.h @@ -21,7 +21,7 @@ * DEALINGS IN THE SOFTWARE. */ -#include "main/mtypes.h" +#include "main/core.h" /* for slot numbers */ struct builtin_variable { enum ir_variable_mode mode; diff --git a/src/glsl/builtins/tools/generate_builtins.py b/src/glsl/builtins/tools/generate_builtins.py index 2a763d784b..c72b5b3bc1 100755 --- a/src/glsl/builtins/tools/generate_builtins.py +++ b/src/glsl/builtins/tools/generate_builtins.py @@ -116,7 +116,7 @@ if __name__ == "__main__": */ #include -#include "main/compiler.h" +#include "main/core.h" /* for struct gl_shader */ #include "glsl_parser_extras.h" #include "ir_reader.h" #include "program.h" diff --git a/src/glsl/glcpp/glcpp-parse.c b/src/glsl/glcpp/glcpp-parse.c index 2c04d7d71b..91eb0bf972 100644 --- a/src/glsl/glcpp/glcpp-parse.c +++ b/src/glsl/glcpp/glcpp-parse.c @@ -100,7 +100,7 @@ #include #include "glcpp.h" -#include "main/mtypes.h" +#include "main/core.h" /* for struct gl_extensions */ #define glcpp_print(stream, str) stream = talloc_strdup_append(stream, str) #define glcpp_printf(stream, fmt, args, ...) \ diff --git a/src/glsl/glcpp/glcpp-parse.y b/src/glsl/glcpp/glcpp-parse.y index 3275496d99..3c28edf688 100644 --- a/src/glsl/glcpp/glcpp-parse.y +++ b/src/glsl/glcpp/glcpp-parse.y @@ -29,7 +29,7 @@ #include #include "glcpp.h" -#include "main/mtypes.h" +#include "main/core.h" /* for struct gl_extensions */ #define glcpp_print(stream, str) stream = talloc_strdup_append(stream, str) #define glcpp_printf(stream, fmt, args, ...) \ diff --git a/src/glsl/glsl_parser_extras.cpp b/src/glsl/glsl_parser_extras.cpp index b864218d50..bc56e4fcaf 100644 --- a/src/glsl/glsl_parser_extras.cpp +++ b/src/glsl/glsl_parser_extras.cpp @@ -27,7 +27,7 @@ extern "C" { #include -#include "main/mtypes.h" +#include "main/core.h" /* for struct __GLcontextRec */ } #include "ast.h" diff --git a/src/glsl/glsl_types.cpp b/src/glsl/glsl_types.cpp index c488f5c271..1da2fd76de 100644 --- a/src/glsl/glsl_types.cpp +++ b/src/glsl/glsl_types.cpp @@ -23,13 +23,12 @@ #include #include -#include "main/compiler.h" +#include "main/core.h" /* for Elements */ #include "glsl_symbol_table.h" #include "glsl_parser_extras.h" #include "glsl_types.h" #include "builtin_types.h" extern "C" { -#include "main/imports.h" #include "program/hash_table.h" } diff --git a/src/glsl/hir_field_selection.cpp b/src/glsl/hir_field_selection.cpp index 23045ff182..3c33127b5f 100644 --- a/src/glsl/hir_field_selection.cpp +++ b/src/glsl/hir_field_selection.cpp @@ -22,7 +22,6 @@ */ #include "ir.h" -#include "main/imports.h" #include "program/symbol_table.h" #include "glsl_parser_extras.h" #include "ast.h" diff --git a/src/glsl/ir.cpp b/src/glsl/ir.cpp index 4622a1f939..e5ed10d3e4 100644 --- a/src/glsl/ir.cpp +++ b/src/glsl/ir.cpp @@ -21,8 +21,7 @@ * DEALINGS IN THE SOFTWARE. */ #include -#include "main/imports.h" -#include "main/macros.h" +#include "main/core.h" /* for MAX2 */ #include "ir.h" #include "ir_visitor.h" #include "glsl_types.h" diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index 942f198360..f1c175c97a 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -34,7 +34,7 @@ */ #include -#include "main/macros.h" +#include "main/core.h" /* for MAX2, MIN2, CLAMP */ #include "ir.h" #include "ir_visitor.h" #include "glsl_types.h" diff --git a/src/glsl/ir_explog_to_explog2.cpp b/src/glsl/ir_explog_to_explog2.cpp index 9bf8271081..78694a2029 100644 --- a/src/glsl/ir_explog_to_explog2.cpp +++ b/src/glsl/ir_explog_to_explog2.cpp @@ -29,7 +29,7 @@ * and log2 operations. */ -#include "main/imports.h" +#include "main/core.h" /* for log2f on MSVC */ #include "ir.h" #include "glsl_types.h" diff --git a/src/glsl/ir_set_program_inouts.cpp b/src/glsl/ir_set_program_inouts.cpp index 534f602128..b3f1cc0d8b 100644 --- a/src/glsl/ir_set_program_inouts.cpp +++ b/src/glsl/ir_set_program_inouts.cpp @@ -35,7 +35,7 @@ */ extern "C" { -#include "main/mtypes.h" +#include "main/core.h" /* for struct gl_program */ #include "program/hash_table.h" } #include "ir.h" diff --git a/src/glsl/ir_variable.cpp b/src/glsl/ir_variable.cpp index 917c06743b..e638c9602f 100644 --- a/src/glsl/ir_variable.cpp +++ b/src/glsl/ir_variable.cpp @@ -21,7 +21,6 @@ * DEALINGS IN THE SOFTWARE. */ -#include "main/compiler.h" #include "ir.h" #include "glsl_parser_extras.h" #include "glsl_symbol_table.h" diff --git a/src/glsl/link_functions.cpp b/src/glsl/link_functions.cpp index dfda05fcbe..6374573e61 100644 --- a/src/glsl/link_functions.cpp +++ b/src/glsl/link_functions.cpp @@ -29,7 +29,7 @@ extern "C" { #include } -#include "main/mtypes.h" +#include "main/core.h" #include "glsl_symbol_table.h" #include "glsl_parser_extras.h" #include "ir.h" diff --git a/src/glsl/linker.cpp b/src/glsl/linker.cpp index 38d19c4c71..c5c8c9cdd6 100644 --- a/src/glsl/linker.cpp +++ b/src/glsl/linker.cpp @@ -72,10 +72,7 @@ extern "C" { #include } -#include "main/compiler.h" -#include "main/mtypes.h" -#include "main/macros.h" -#include "main/shaderobj.h" +#include "main/core.h" #include "glsl_symbol_table.h" #include "ir.h" #include "program.h" diff --git a/src/glsl/program.h b/src/glsl/program.h index ea2c4ab0dd..893169b6cc 100644 --- a/src/glsl/program.h +++ b/src/glsl/program.h @@ -21,13 +21,7 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include -#include "main/mtypes.h" - -extern "C" { -#include "program/prog_parameter.h" -#include "program/prog_uniform.h" -} +#include "main/core.h" extern void link_shaders(GLcontext *ctx, struct gl_shader_program *prog); -- cgit v1.2.3 From b6f15869b324ae64a00d0fe46fa3c8c62c1edb6c Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Fri, 20 Aug 2010 20:04:39 -0700 Subject: glsl: Move is_built_in flag from ir_function_signature to ir_function. Also rename it to "is_builtin" for consistency. Signed-off-by: Ian Romanick --- src/glsl/ir.cpp | 2 +- src/glsl/ir.h | 6 +++--- src/glsl/ir_clone.cpp | 3 ++- src/glsl/ir_constant_expression.cpp | 2 +- src/glsl/ir_import_prototypes.cpp | 2 +- src/glsl/ir_print_visitor.cpp | 10 ++-------- src/glsl/ir_reader.cpp | 2 +- src/glsl/linker.cpp | 4 ++-- 8 files changed, 13 insertions(+), 18 deletions(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir.cpp b/src/glsl/ir.cpp index 31e40cac8c..8779ec73c9 100644 --- a/src/glsl/ir.cpp +++ b/src/glsl/ir.cpp @@ -982,7 +982,6 @@ ir_function_signature::ir_function_signature(const glsl_type *return_type) : return_type(return_type), is_defined(false), _function(NULL) { this->ir_type = ir_type_function_signature; - this->is_built_in = false; } @@ -1034,6 +1033,7 @@ ir_function::ir_function(const char *name) { this->ir_type = ir_type_function; this->name = talloc_strdup(this, name); + this->is_builtin = false; } diff --git a/src/glsl/ir.h b/src/glsl/ir.h index 500b152408..0f887a9327 100644 --- a/src/glsl/ir.h +++ b/src/glsl/ir.h @@ -342,9 +342,6 @@ public: /** Whether or not this function has a body (which may be empty). */ unsigned is_defined:1; - /** Whether or not this function signature is a built-in. */ - unsigned is_built_in:1; - /** Body of instructions in the function. */ struct exec_list body; @@ -410,6 +407,9 @@ public: */ const char *name; + /** Whether or not this function is a built-in. */ + unsigned is_builtin:1; + /** * List of ir_function_signature for each overloaded function with this name. */ diff --git a/src/glsl/ir_clone.cpp b/src/glsl/ir_clone.cpp index 0a9e25a295..1d690a4da7 100644 --- a/src/glsl/ir_clone.cpp +++ b/src/glsl/ir_clone.cpp @@ -249,6 +249,8 @@ ir_function::clone(void *mem_ctx, struct hash_table *ht) const { ir_function *copy = new(mem_ctx) ir_function(this->name); + copy->is_builtin = this->is_builtin; + foreach_list_const(node, &this->signatures) { const ir_function_signature *const sig = (const ir_function_signature *const) node; @@ -271,7 +273,6 @@ ir_function_signature::clone(void *mem_ctx, struct hash_table *ht) const new(mem_ctx) ir_function_signature(this->return_type); copy->is_defined = this->is_defined; - copy->is_built_in = this->is_built_in; /* Clone the parameter list. */ diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index f1c175c97a..5ec60c522f 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -785,7 +785,7 @@ ir_call::constant_expression_value() * "Function calls to user-defined functions (non-built-in functions) * cannot be used to form constant expressions." */ - if (!this->callee->is_built_in) + if (!this->callee->function()->is_builtin) return NULL; unsigned num_parameters = 0; diff --git a/src/glsl/ir_import_prototypes.cpp b/src/glsl/ir_import_prototypes.cpp index e553e12a49..a39b384071 100644 --- a/src/glsl/ir_import_prototypes.cpp +++ b/src/glsl/ir_import_prototypes.cpp @@ -59,6 +59,7 @@ public: this->function = this->symbols->get_function(ir->name); if (!this->function) { this->function = new(this->mem_ctx) ir_function(ir->name); + this->function->is_builtin = ir->is_builtin; list->push_tail(this->function); @@ -86,7 +87,6 @@ public: new(mem_ctx) ir_function_signature(ir->return_type); copy->is_defined = false; - copy->is_built_in = ir->is_built_in; /* Clone the parameter list, but NOT the body. */ diff --git a/src/glsl/ir_print_visitor.cpp b/src/glsl/ir_print_visitor.cpp index 83e6403272..f47ad87550 100644 --- a/src/glsl/ir_print_visitor.cpp +++ b/src/glsl/ir_print_visitor.cpp @@ -153,14 +153,8 @@ void ir_print_visitor::visit(ir_function_signature *ir) void ir_print_visitor::visit(ir_function *ir) { - bool found_non_builtin_proto = false; - - foreach_iter(exec_list_iterator, iter, *ir) { - ir_function_signature *const sig = (ir_function_signature *) iter.get(); - if (sig->is_defined || !sig->is_built_in) - found_non_builtin_proto = true; - } - if (!found_non_builtin_proto) + /* Don't print built-in functions as part of the IR. */ + if (ir->is_builtin) return; printf("(function %s\n", ir->name); diff --git a/src/glsl/ir_reader.cpp b/src/glsl/ir_reader.cpp index 3e221c0e5f..366db32774 100644 --- a/src/glsl/ir_reader.cpp +++ b/src/glsl/ir_reader.cpp @@ -209,6 +209,7 @@ read_function(_mesa_glsl_parse_state *st, s_list *list, bool skip_body) ir_function *f = st->symbols->get_function(name->value()); if (f == NULL) { f = new(ctx) ir_function(name->value()); + f->is_builtin = true; added = st->symbols->add_function(f->name, f); assert(added); } @@ -281,7 +282,6 @@ read_function_sig(_mesa_glsl_parse_state *st, ir_function *f, s_list *list, if (sig == NULL && skip_body) { /* If scanning for prototypes, generate a new signature. */ sig = new(ctx) ir_function_signature(return_type); - sig->is_built_in = true; f->add_signature(sig); } else if (sig != NULL) { const char *badvar = sig->qualifiers_match(&hir_parameters); diff --git a/src/glsl/linker.cpp b/src/glsl/linker.cpp index 0348bd01e8..3de069b531 100644 --- a/src/glsl/linker.cpp +++ b/src/glsl/linker.cpp @@ -726,14 +726,14 @@ link_intrastage_shaders(GLcontext *ctx, ir_function_signature *sig = (ir_function_signature *) iter.get(); - if (!sig->is_defined || sig->is_built_in) + if (!sig->is_defined || f->is_builtin) continue; ir_function_signature *other_sig = other->exact_matching_signature(& sig->parameters); if ((other_sig != NULL) && other_sig->is_defined - && !other_sig->is_built_in) { + && !other_sig->function()->is_builtin) { linker_error_printf(prog, "function `%s' is multiply defined", f->name); -- cgit v1.2.3 From 2d0ef6bfee64b6889cbfb69762f167a6dfc20131 Mon Sep 17 00:00:00 2001 From: Vinson Lee Date: Sun, 29 Aug 2010 12:19:57 -0700 Subject: glsl: Initialize variable in ir_swizzle::constant_expression_value. Complete initialize data passed to ir_constant constructor. Fixes piglit glsl-mat-from-int-ctor-02 valgrind unintialized variable error with softpipe and llvmpipe. --- src/glsl/ir_constant_expression.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/glsl/ir_constant_expression.cpp') diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index 5ec60c522f..458dca7977 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -653,7 +653,7 @@ ir_swizzle::constant_expression_value() ir_constant *v = this->val->constant_expression_value(); if (v != NULL) { - ir_constant_data data; + ir_constant_data data = { { 0 } }; const unsigned swiz_idx[4] = { this->mask.x, this->mask.y, this->mask.z, this->mask.w -- cgit v1.2.3