Inspired by a patch from Bryan Cain <bryanca...@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 <kenn...@whitecape.org>
---
 src/glsl/ast_function.cpp |   35 +++++++++++++++++++++++++++++------
 1 files changed, 29 insertions(+), 6 deletions(-)

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

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to