ff_fragment_shader: Don't generate swizzles for scalar combiner inputs
authorIan Romanick <ian.d.romanick@intel.com>
Fri, 23 Dec 2011 01:37:26 +0000 (17:37 -0800)
committerIan Romanick <ian.d.romanick@intel.com>
Wed, 4 Jan 2012 03:21:19 +0000 (19:21 -0800)
There are a couple scenarios where the source could be zero and the
operand could be either SRC_ALPHA or ONE_MINUS_SRC_ALPHA.  For
example, if the source was ZERO.  This would result in something like
(0).w, and a later call to ir_validate would get angry.

Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=42517

src/mesa/main/ff_fragment_shader.cpp

index 008da0d0e3dbfaf378fb661bbf9cafc1423e0f14..3e736fa15008b26999bfcfad23ed39e6483327f5 100644 (file)
@@ -632,15 +632,19 @@ emit_combine_source(struct texenv_fragment_program *p,
                                           new(p->mem_ctx) ir_constant(1.0f),
                                           src);
 
-   case OPR_SRC_ALPHA: 
-      return new(p->mem_ctx) ir_swizzle(src, 3, 3, 3, 3, 1);
+   case OPR_SRC_ALPHA:
+      return src->type->is_scalar()
+        ? src : (ir_rvalue *) new(p->mem_ctx) ir_swizzle(src, 3, 3, 3, 3, 1);
+
+   case OPR_ONE_MINUS_SRC_ALPHA: {
+      ir_rvalue *const scalar = (src->type->is_scalar())
+        ? src : (ir_rvalue *) new(p->mem_ctx) ir_swizzle(src, 3, 3, 3, 3, 1);
 
-   case OPR_ONE_MINUS_SRC_ALPHA: 
       return new(p->mem_ctx) ir_expression(ir_binop_sub,
                                           new(p->mem_ctx) ir_constant(1.0f),
-                                          new(p->mem_ctx) ir_swizzle(src,
-                                                                     3, 3,
-                                                                     3, 3, 1));
+                                          scalar);
+   }
+
    case OPR_ZERO:
       return new(p->mem_ctx) ir_constant(0.0f);
    case OPR_ONE: