From e617a53a74cd27a322fd2dd05ff1c66c6437fde3 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Fri, 24 Jun 2011 13:17:07 -0700 Subject: glsl: Allow ir_assignment() constructor to not specify condition. We almost never want to specify a condition, and when we do we're already thinking about it (because we're writing a lowering pass generating the condition), so a default argument should make the code more pleasant to read. NOTE: This is a candidate for the 7.11 branch (we want to be able to cherry-pick future code). Reviewed-by: Kenneth Graunke --- src/glsl/ir.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/glsl/ir.h') diff --git a/src/glsl/ir.h b/src/glsl/ir.h index a41984310b3..9d6ce7eaa20 100644 --- a/src/glsl/ir.h +++ b/src/glsl/ir.h @@ -682,7 +682,7 @@ public: class ir_assignment : public ir_instruction { public: - ir_assignment(ir_rvalue *lhs, ir_rvalue *rhs, ir_rvalue *condition); + ir_assignment(ir_rvalue *lhs, ir_rvalue *rhs, ir_rvalue *condition = NULL); /** * Construct an assignment with an explicit write mask -- cgit v1.2.3 From 20ef96c7ff3f17fbf97e0452a37553249b2b005c Mon Sep 17 00:00:00 2001 From: Bryan Cain Date: Tue, 14 Jun 2011 23:34:11 -0700 Subject: glsl: Add ir_unop_i2u and ir_unop_u2i operations. These are necessary to handle int/uint constructor conversions. For example, the following code currently results in a type mismatch: int x = 7; uint y = uint(x); In particular, uint(x) still has type int. This commit simply adds the new operations; it does not generate them, nor does it add backend support for them. Signed-off-by: Kenneth Graunke Reviewed-by: Ian Romanick Reviewed-by: Eric Anholt --- src/glsl/ir.cpp | 8 ++++++++ src/glsl/ir.h | 2 ++ src/glsl/ir_constant_expression.cpp | 13 ++++++++++++- src/glsl/ir_validate.cpp | 8 ++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) (limited to 'src/glsl/ir.h') diff --git a/src/glsl/ir.cpp b/src/glsl/ir.cpp index a3623b31e5d..95689dc10b0 100644 --- a/src/glsl/ir.cpp +++ b/src/glsl/ir.cpp @@ -272,6 +272,7 @@ ir_expression::ir_expression(int op, ir_rvalue *op0) case ir_unop_f2i: case ir_unop_b2i: + case ir_unop_u2i: this->type = glsl_type::get_instance(GLSL_TYPE_INT, op0->type->vector_elements, 1); break; @@ -289,6 +290,11 @@ ir_expression::ir_expression(int op, ir_rvalue *op0) op0->type->vector_elements, 1); break; + case ir_unop_i2u: + this->type = glsl_type::get_instance(GLSL_TYPE_UINT, + op0->type->vector_elements, 1); + break; + case ir_unop_noise: this->type = glsl_type::float_type; break; @@ -419,6 +425,8 @@ static const char *const operator_strs[] = { "i2b", "b2i", "u2f", + "i2u", + "u2i", "any", "trunc", "ceil", diff --git a/src/glsl/ir.h b/src/glsl/ir.h index 9d6ce7eaa20..42a3936976a 100644 --- a/src/glsl/ir.h +++ b/src/glsl/ir.h @@ -789,6 +789,8 @@ 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_i2u, /**< Integer-to-unsigned conversion. */ + ir_unop_u2i, /**< Unsigned-to-integer conversion. */ ir_unop_any, /** diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp index 2a308489656..f0299a2c4a0 100644 --- a/src/glsl/ir_constant_expression.cpp +++ b/src/glsl/ir_constant_expression.cpp @@ -166,7 +166,18 @@ ir_expression::constant_expression_value() data.b[c] = op[0]->value.u[c] ? true : false; } break; - + case ir_unop_u2i: + assert(op[0]->type->base_type == GLSL_TYPE_UINT); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + data.i[c] = op[0]->value.u[c]; + } + break; + case ir_unop_i2u: + assert(op[0]->type->base_type == GLSL_TYPE_INT); + for (unsigned c = 0; c < op[0]->type->components(); c++) { + data.u[c] = op[0]->value.i[c]; + } + break; case ir_unop_any: assert(op[0]->type->is_boolean()); data.b[0] = false; diff --git a/src/glsl/ir_validate.cpp b/src/glsl/ir_validate.cpp index 7b1c19d65aa..41ffdfdbcc7 100644 --- a/src/glsl/ir_validate.cpp +++ b/src/glsl/ir_validate.cpp @@ -280,6 +280,14 @@ ir_validate::visit_leave(ir_expression *ir) assert(ir->operands[0]->type->base_type == GLSL_TYPE_UINT); assert(ir->type->base_type == GLSL_TYPE_FLOAT); break; + case ir_unop_i2u: + assert(ir->operands[0]->type->base_type == GLSL_TYPE_INT); + assert(ir->type->base_type == GLSL_TYPE_UINT); + break; + case ir_unop_u2i: + assert(ir->operands[0]->type->base_type == GLSL_TYPE_UINT); + assert(ir->type->base_type == GLSL_TYPE_INT); + break; case ir_unop_any: assert(ir->operands[0]->type->base_type == GLSL_TYPE_BOOL); -- cgit v1.2.3