glsl: Use i2u and u2i to implement constructor conversions.

Inspired by a patch from Bryan Cain <bryancain3@gmail.com>.

Fixes piglit tests:
- ctor-int-uint.vert
- ctor-ivec4-uvec4.vert
- ctor-uint-int.vert
- ctor-uvec4-ivec4.vert

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
This commit is contained in:
Kenneth Graunke
2011-06-14 23:23:49 -07:00
parent b633ddeb9f
commit 6b1ba7ccef

View File

@@ -271,17 +271,36 @@ convert_component(ir_rvalue *src, const glsl_type *desired_type)
assert(a <= GLSL_TYPE_BOOL); assert(a <= GLSL_TYPE_BOOL);
assert(b <= GLSL_TYPE_BOOL); assert(b <= GLSL_TYPE_BOOL);
if ((a == b) || (src->type->is_integer() && desired_type->is_integer())) if (a == b)
return src; return src;
switch (a) { switch (a) {
case GLSL_TYPE_UINT: case GLSL_TYPE_UINT:
switch (b) {
case GLSL_TYPE_INT:
result = new(ctx) ir_expression(ir_unop_i2u, src);
break;
case GLSL_TYPE_FLOAT:
result = new(ctx) ir_expression(ir_unop_i2u,
new(ctx) ir_expression(ir_unop_f2i, src));
break;
case GLSL_TYPE_BOOL:
result = new(ctx) ir_expression(ir_unop_i2u,
new(ctx) ir_expression(ir_unop_b2i, src));
break;
}
break;
case GLSL_TYPE_INT: case GLSL_TYPE_INT:
if (b == GLSL_TYPE_FLOAT) switch (b) {
result = new(ctx) ir_expression(ir_unop_f2i, desired_type, src, NULL); case GLSL_TYPE_UINT:
else { result = new(ctx) ir_expression(ir_unop_u2i, src);
assert(b == GLSL_TYPE_BOOL); break;
result = new(ctx) ir_expression(ir_unop_b2i, desired_type, src, NULL); case GLSL_TYPE_FLOAT:
result = new(ctx) ir_expression(ir_unop_f2i, src);
break;
case GLSL_TYPE_BOOL:
result = new(ctx) ir_expression(ir_unop_b2i, src);
break;
} }
break; break;
case GLSL_TYPE_FLOAT: case GLSL_TYPE_FLOAT:
@@ -300,6 +319,9 @@ convert_component(ir_rvalue *src, const glsl_type *desired_type)
case GLSL_TYPE_BOOL: case GLSL_TYPE_BOOL:
switch (b) { switch (b) {
case GLSL_TYPE_UINT: case GLSL_TYPE_UINT:
result = new(ctx) ir_expression(ir_unop_i2b,
new(ctx) ir_expression(ir_unop_u2i, src));
break;
case GLSL_TYPE_INT: case GLSL_TYPE_INT:
result = new(ctx) ir_expression(ir_unop_i2b, desired_type, src, NULL); result = new(ctx) ir_expression(ir_unop_i2b, desired_type, src, NULL);
break; break;
@@ -311,6 +333,7 @@ convert_component(ir_rvalue *src, const glsl_type *desired_type)
} }
assert(result != NULL); assert(result != NULL);
assert(result->type == desired_type);
/* Try constant folding; it may fold in the conversion we just added. */ /* Try constant folding; it may fold in the conversion we just added. */
ir_constant *const constant = result->constant_expression_value(); ir_constant *const constant = result->constant_expression_value();