aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/glsl
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2011-04-14 06:41:54 +0000
committermarha <marha@users.sourceforge.net>2011-04-14 06:41:54 +0000
commit019fc27ce6dc2a1809107be10d4deb80e0fa436b (patch)
tree57bc2571720a5d6e518ef15879d56ea066df494c /mesalib/src/glsl
parent7bcdd32ccff794b9a83a88ff9bc2d0b7b088bd06 (diff)
downloadvcxsrv-019fc27ce6dc2a1809107be10d4deb80e0fa436b.tar.gz
vcxsrv-019fc27ce6dc2a1809107be10d4deb80e0fa436b.tar.bz2
vcxsrv-019fc27ce6dc2a1809107be10d4deb80e0fa436b.zip
server xkeyboard-config mesa git update 14 Apr 2011
Diffstat (limited to 'mesalib/src/glsl')
-rw-r--r--mesalib/src/glsl/ast_to_hir.cpp146
-rw-r--r--mesalib/src/glsl/glsl_parser_extras.cpp2
-rw-r--r--mesalib/src/glsl/opt_copy_propagation_elements.cpp15
3 files changed, 77 insertions, 86 deletions
diff --git a/mesalib/src/glsl/ast_to_hir.cpp b/mesalib/src/glsl/ast_to_hir.cpp
index 9538aa62b..a11bfbab8 100644
--- a/mesalib/src/glsl/ast_to_hir.cpp
+++ b/mesalib/src/glsl/ast_to_hir.cpp
@@ -848,6 +848,36 @@ do_comparison(void *mem_ctx, int operation, ir_rvalue *op0, ir_rvalue *op1)
return cmp;
}
+/* For logical operations, we want to ensure that the operands are
+ * scalar booleans. If it isn't, emit an error and return a constant
+ * boolean to avoid triggering cascading error messages.
+ */
+ir_rvalue *
+get_scalar_boolean_operand(exec_list *instructions,
+ struct _mesa_glsl_parse_state *state,
+ ast_expression *parent_expr,
+ int operand,
+ const char *operand_name,
+ bool *error_emitted)
+{
+ ast_expression *expr = parent_expr->subexpressions[operand];
+ void *ctx = state;
+ ir_rvalue *val = expr->hir(instructions, state);
+
+ if (val->type->is_boolean() && val->type->is_scalar())
+ return val;
+
+ if (!*error_emitted) {
+ YYLTYPE loc = expr->get_location();
+ _mesa_glsl_error(&loc, state, "%s of `%s' must be scalar boolean",
+ operand_name,
+ parent_expr->operator_string(parent_expr->oper));
+ *error_emitted = true;
+ }
+
+ return new(ctx) ir_constant(true);
+}
+
ir_rvalue *
ast_expression::hir(exec_list *instructions,
struct _mesa_glsl_parse_state *state)
@@ -1043,10 +1073,14 @@ ast_expression::hir(exec_list *instructions,
error_emitted = true;
}
- result = do_comparison(ctx, operations[this->oper], op[0], op[1]);
- type = glsl_type::bool_type;
+ if (error_emitted) {
+ result = new(ctx) ir_constant(false);
+ } else {
+ result = do_comparison(ctx, operations[this->oper], op[0], op[1]);
+ assert(result->type == glsl_type::bool_type);
+ type = glsl_type::bool_type;
+ }
- assert(error_emitted || (result->type == glsl_type::bool_type));
break;
case ast_bit_and:
@@ -1079,29 +1113,16 @@ ast_expression::hir(exec_list *instructions,
break;
case ast_logic_and: {
- op[0] = this->subexpressions[0]->hir(instructions, state);
-
- if (!op[0]->type->is_boolean() || !op[0]->type->is_scalar()) {
- YYLTYPE loc = this->subexpressions[0]->get_location();
-
- _mesa_glsl_error(& loc, state, "LHS of `%s' must be scalar boolean",
- operator_string(this->oper));
- error_emitted = true;
- }
+ exec_list rhs_instructions;
+ op[0] = get_scalar_boolean_operand(instructions, state, this, 0,
+ "LHS", &error_emitted);
+ op[1] = get_scalar_boolean_operand(&rhs_instructions, state, this, 1,
+ "RHS", &error_emitted);
ir_constant *op0_const = op[0]->constant_expression_value();
if (op0_const) {
if (op0_const->value.b[0]) {
- op[1] = this->subexpressions[1]->hir(instructions, state);
-
- if (!op[1]->type->is_boolean() || !op[1]->type->is_scalar()) {
- YYLTYPE loc = this->subexpressions[1]->get_location();
-
- _mesa_glsl_error(& loc, state,
- "RHS of `%s' must be scalar boolean",
- operator_string(this->oper));
- error_emitted = true;
- }
+ instructions->append_list(&rhs_instructions);
result = op[1];
} else {
result = op0_const;
@@ -1116,17 +1137,7 @@ ast_expression::hir(exec_list *instructions,
ir_if *const stmt = new(ctx) ir_if(op[0]);
instructions->push_tail(stmt);
- op[1] = this->subexpressions[1]->hir(&stmt->then_instructions, state);
-
- if (!op[1]->type->is_boolean() || !op[1]->type->is_scalar()) {
- YYLTYPE loc = this->subexpressions[1]->get_location();
-
- _mesa_glsl_error(& loc, state,
- "RHS of `%s' must be scalar boolean",
- operator_string(this->oper));
- error_emitted = true;
- }
-
+ stmt->then_instructions.append_list(&rhs_instructions);
ir_dereference *const then_deref = new(ctx) ir_dereference_variable(tmp);
ir_assignment *const then_assign =
new(ctx) ir_assignment(then_deref, op[1], NULL);
@@ -1144,31 +1155,17 @@ ast_expression::hir(exec_list *instructions,
}
case ast_logic_or: {
- op[0] = this->subexpressions[0]->hir(instructions, state);
-
- if (!op[0]->type->is_boolean() || !op[0]->type->is_scalar()) {
- YYLTYPE loc = this->subexpressions[0]->get_location();
-
- _mesa_glsl_error(& loc, state, "LHS of `%s' must be scalar boolean",
- operator_string(this->oper));
- error_emitted = true;
- }
+ exec_list rhs_instructions;
+ op[0] = get_scalar_boolean_operand(instructions, state, this, 0,
+ "LHS", &error_emitted);
+ op[1] = get_scalar_boolean_operand(&rhs_instructions, state, this, 1,
+ "RHS", &error_emitted);
ir_constant *op0_const = op[0]->constant_expression_value();
if (op0_const) {
if (op0_const->value.b[0]) {
result = op0_const;
} else {
- op[1] = this->subexpressions[1]->hir(instructions, state);
-
- if (!op[1]->type->is_boolean() || !op[1]->type->is_scalar()) {
- YYLTYPE loc = this->subexpressions[1]->get_location();
-
- _mesa_glsl_error(& loc, state,
- "RHS of `%s' must be scalar boolean",
- operator_string(this->oper));
- error_emitted = true;
- }
result = op[1];
}
type = glsl_type::bool_type;
@@ -1181,21 +1178,12 @@ ast_expression::hir(exec_list *instructions,
ir_if *const stmt = new(ctx) ir_if(op[0]);
instructions->push_tail(stmt);
- op[1] = this->subexpressions[1]->hir(&stmt->else_instructions, state);
-
- if (!op[1]->type->is_boolean() || !op[1]->type->is_scalar()) {
- YYLTYPE loc = this->subexpressions[1]->get_location();
-
- _mesa_glsl_error(& loc, state, "RHS of `%s' must be scalar boolean",
- operator_string(this->oper));
- error_emitted = true;
- }
-
ir_dereference *const then_deref = new(ctx) ir_dereference_variable(tmp);
ir_assignment *const then_assign =
new(ctx) ir_assignment(then_deref, new(ctx) ir_constant(true), NULL);
stmt->then_instructions.push_tail(then_assign);
+ stmt->else_instructions.append_list(&rhs_instructions);
ir_dereference *const else_deref = new(ctx) ir_dereference_variable(tmp);
ir_assignment *const else_assign =
new(ctx) ir_assignment(else_deref, op[1], NULL);
@@ -1208,9 +1196,16 @@ ast_expression::hir(exec_list *instructions,
}
case ast_logic_xor:
- op[0] = this->subexpressions[0]->hir(instructions, state);
- op[1] = this->subexpressions[1]->hir(instructions, state);
-
+ /* From page 33 (page 39 of the PDF) of the GLSL 1.10 spec:
+ *
+ * "The logical binary operators and (&&), or ( | | ), and
+ * exclusive or (^^). They operate only on two Boolean
+ * expressions and result in a Boolean expression."
+ */
+ op[0] = get_scalar_boolean_operand(instructions, state, this, 0, "LHS",
+ &error_emitted);
+ op[1] = get_scalar_boolean_operand(instructions, state, this, 1, "RHS",
+ &error_emitted);
result = new(ctx) ir_expression(operations[this->oper], glsl_type::bool_type,
op[0], op[1]);
@@ -1218,15 +1213,8 @@ ast_expression::hir(exec_list *instructions,
break;
case ast_logic_not:
- op[0] = this->subexpressions[0]->hir(instructions, state);
-
- if (!op[0]->type->is_boolean() || !op[0]->type->is_scalar()) {
- YYLTYPE loc = this->subexpressions[0]->get_location();
-
- _mesa_glsl_error(& loc, state,
- "operand of `!' must be scalar boolean");
- error_emitted = true;
- }
+ op[0] = get_scalar_boolean_operand(instructions, state, this, 0,
+ "operand", &error_emitted);
result = new(ctx) ir_expression(operations[this->oper], glsl_type::bool_type,
op[0], NULL);
@@ -1313,20 +1301,14 @@ ast_expression::hir(exec_list *instructions,
}
case ast_conditional: {
- op[0] = this->subexpressions[0]->hir(instructions, state);
-
/* From page 59 (page 65 of the PDF) of the GLSL 1.50 spec:
*
* "The ternary selection operator (?:). It operates on three
* expressions (exp1 ? exp2 : exp3). This operator evaluates the
* first expression, which must result in a scalar Boolean."
*/
- if (!op[0]->type->is_boolean() || !op[0]->type->is_scalar()) {
- YYLTYPE loc = this->subexpressions[0]->get_location();
-
- _mesa_glsl_error(& loc, state, "?: condition must be scalar boolean");
- error_emitted = true;
- }
+ op[0] = get_scalar_boolean_operand(instructions, state, this, 0,
+ "condition", &error_emitted);
/* The :? operator is implemented by generating an anonymous temporary
* followed by an if-statement. The last instruction in each branch of
diff --git a/mesalib/src/glsl/glsl_parser_extras.cpp b/mesalib/src/glsl/glsl_parser_extras.cpp
index e8881e4d6..5bb3a6f25 100644
--- a/mesalib/src/glsl/glsl_parser_extras.cpp
+++ b/mesalib/src/glsl/glsl_parser_extras.cpp
@@ -768,7 +768,7 @@ do_common_optimization(exec_list *ir, bool linked, unsigned max_unroll_iteration
progress = do_if_simplification(ir) || progress;
progress = do_discard_simplification(ir) || progress;
progress = do_copy_propagation(ir) || progress;
- /*progress = do_copy_propagation_elements(ir) || progress;*/
+ progress = do_copy_propagation_elements(ir) || progress;
if (linked)
progress = do_dead_code(ir) || progress;
else
diff --git a/mesalib/src/glsl/opt_copy_propagation_elements.cpp b/mesalib/src/glsl/opt_copy_propagation_elements.cpp
index 8541d9a8e..a91e624cb 100644
--- a/mesalib/src/glsl/opt_copy_propagation_elements.cpp
+++ b/mesalib/src/glsl/opt_copy_propagation_elements.cpp
@@ -161,9 +161,16 @@ ir_visitor_status
ir_copy_propagation_elements_visitor::visit_leave(ir_assignment *ir)
{
ir_dereference_variable *lhs = ir->lhs->as_dereference_variable();
+ ir_variable *var = ir->lhs->variable_referenced();
+
+ if (var->type->is_scalar() || var->type->is_vector()) {
+ kill_entry *k;
+
+ if (lhs)
+ k = new(mem_ctx) kill_entry(var, ir->write_mask);
+ else
+ k = new(mem_ctx) kill_entry(var, ~0);
- if (lhs && (lhs->type->is_scalar() || lhs->type->is_vector())) {
- kill_entry *k = new(mem_ctx) kill_entry(lhs->var, ir->write_mask);
kill(k);
}
@@ -383,8 +390,10 @@ ir_copy_propagation_elements_visitor::kill(kill_entry *k)
if (entry->lhs == k->var) {
entry->write_mask = entry->write_mask & ~k->write_mask;
- if (entry->write_mask == 0)
+ if (entry->write_mask == 0) {
entry->remove();
+ continue;
+ }
}
if (entry->rhs == k->var) {
entry->remove();