コード例 #1
0
ファイル: sp_quad_blend.c プロジェクト: CPFDSoftware-Tony/gmv
static void
blend_quad(struct quad_stage *qs, 
           float (*quadColor)[4],
           float (*dest)[4],
           unsigned cbuf)
{
   static const float zero[4] = { 0, 0, 0, 0 };
   static const float one[4] = { 1, 1, 1, 1 };
   struct softpipe_context *softpipe = qs->softpipe;
   float source[4][QUAD_SIZE] = { { 0 } };

   /*
    * Compute src/first term RGB
    */
   switch (softpipe->blend->rt[cbuf].rgb_src_factor) {
   case PIPE_BLENDFACTOR_ONE:
      VEC4_COPY(source[0], quadColor[0]); /* R */
      VEC4_COPY(source[1], quadColor[1]); /* G */
      VEC4_COPY(source[2], quadColor[2]); /* B */
      break;
   case PIPE_BLENDFACTOR_SRC_COLOR:
      VEC4_MUL(source[0], quadColor[0], quadColor[0]); /* R */
      VEC4_MUL(source[1], quadColor[1], quadColor[1]); /* G */
      VEC4_MUL(source[2], quadColor[2], quadColor[2]); /* B */
      break;
   case PIPE_BLENDFACTOR_SRC_ALPHA:
   {
      const float *alpha = quadColor[3];
      VEC4_MUL(source[0], quadColor[0], alpha); /* R */
      VEC4_MUL(source[1], quadColor[1], alpha); /* G */
      VEC4_MUL(source[2], quadColor[2], alpha); /* B */
   }
   break;
   case PIPE_BLENDFACTOR_DST_COLOR:
      VEC4_MUL(source[0], quadColor[0], dest[0]); /* R */
      VEC4_MUL(source[1], quadColor[1], dest[1]); /* G */
      VEC4_MUL(source[2], quadColor[2], dest[2]); /* B */
      break;
   case PIPE_BLENDFACTOR_DST_ALPHA:
   {
      const float *alpha = dest[3];
      VEC4_MUL(source[0], quadColor[0], alpha); /* R */
      VEC4_MUL(source[1], quadColor[1], alpha); /* G */
      VEC4_MUL(source[2], quadColor[2], alpha); /* B */
   }
   break;
   case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE:
   {
      const float *alpha = quadColor[3];
      float diff[4], temp[4];
      VEC4_SUB(diff, one, dest[3]);
      VEC4_MIN(temp, alpha, diff);
      VEC4_MUL(source[0], quadColor[0], temp); /* R */
      VEC4_MUL(source[1], quadColor[1], temp); /* G */
      VEC4_MUL(source[2], quadColor[2], temp); /* B */
   }
   break;
   case PIPE_BLENDFACTOR_CONST_COLOR:
   {
      float comp[4];
      VEC4_SCALAR(comp, softpipe->blend_color.color[0]); /* R */
      VEC4_MUL(source[0], quadColor[0], comp); /* R */
      VEC4_SCALAR(comp, softpipe->blend_color.color[1]); /* G */
      VEC4_MUL(source[1], quadColor[1], comp); /* G */
      VEC4_SCALAR(comp, softpipe->blend_color.color[2]); /* B */
      VEC4_MUL(source[2], quadColor[2], comp); /* B */
   }
   break;
   case PIPE_BLENDFACTOR_CONST_ALPHA:
   {
      float alpha[4];
      VEC4_SCALAR(alpha, softpipe->blend_color.color[3]);
      VEC4_MUL(source[0], quadColor[0], alpha); /* R */
      VEC4_MUL(source[1], quadColor[1], alpha); /* G */
      VEC4_MUL(source[2], quadColor[2], alpha); /* B */
   }
   break;
   case PIPE_BLENDFACTOR_SRC1_COLOR:
      assert(0); /* to do */
      break;
   case PIPE_BLENDFACTOR_SRC1_ALPHA:
      assert(0); /* to do */
      break;
   case PIPE_BLENDFACTOR_ZERO:
      VEC4_COPY(source[0], zero); /* R */
      VEC4_COPY(source[1], zero); /* G */
      VEC4_COPY(source[2], zero); /* B */
      break;
   case PIPE_BLENDFACTOR_INV_SRC_COLOR:
   {
      float inv_comp[4];
      VEC4_SUB(inv_comp, one, quadColor[0]); /* R */
      VEC4_MUL(source[0], quadColor[0], inv_comp); /* R */
      VEC4_SUB(inv_comp, one, quadColor[1]); /* G */
      VEC4_MUL(source[1], quadColor[1], inv_comp); /* G */
      VEC4_SUB(inv_comp, one, quadColor[2]); /* B */
      VEC4_MUL(source[2], quadColor[2], inv_comp); /* B */
   }
   break;
   case PIPE_BLENDFACTOR_INV_SRC_ALPHA:
   {
      float inv_alpha[4];
      VEC4_SUB(inv_alpha, one, quadColor[3]);
      VEC4_MUL(source[0], quadColor[0], inv_alpha); /* R */
      VEC4_MUL(source[1], quadColor[1], inv_alpha); /* G */
      VEC4_MUL(source[2], quadColor[2], inv_alpha); /* B */
   }
   break;
   case PIPE_BLENDFACTOR_INV_DST_ALPHA:
   {
      float inv_alpha[4];
      VEC4_SUB(inv_alpha, one, dest[3]);
      VEC4_MUL(source[0], quadColor[0], inv_alpha); /* R */
      VEC4_MUL(source[1], quadColor[1], inv_alpha); /* G */
      VEC4_MUL(source[2], quadColor[2], inv_alpha); /* B */
   }
   break;
   case PIPE_BLENDFACTOR_INV_DST_COLOR:
   {
      float inv_comp[4];
      VEC4_SUB(inv_comp, one, dest[0]); /* R */
      VEC4_MUL(source[0], quadColor[0], inv_comp); /* R */
      VEC4_SUB(inv_comp, one, dest[1]); /* G */
      VEC4_MUL(source[1], quadColor[1], inv_comp); /* G */
      VEC4_SUB(inv_comp, one, dest[2]); /* B */
      VEC4_MUL(source[2], quadColor[2], inv_comp); /* B */
   }
   break;
   case PIPE_BLENDFACTOR_INV_CONST_COLOR:
   {
      float inv_comp[4];
      /* R */
      VEC4_SCALAR(inv_comp, 1.0f - softpipe->blend_color.color[0]);
      VEC4_MUL(source[0], quadColor[0], inv_comp);
      /* G */
      VEC4_SCALAR(inv_comp, 1.0f - softpipe->blend_color.color[1]);
      VEC4_MUL(source[1], quadColor[1], inv_comp);
      /* B */
      VEC4_SCALAR(inv_comp, 1.0f - softpipe->blend_color.color[2]);
      VEC4_MUL(source[2], quadColor[2], inv_comp);
   }
   break;
   case PIPE_BLENDFACTOR_INV_CONST_ALPHA:
   {
      float inv_alpha[4];
      VEC4_SCALAR(inv_alpha, 1.0f - softpipe->blend_color.color[3]);
      VEC4_MUL(source[0], quadColor[0], inv_alpha); /* R */
      VEC4_MUL(source[1], quadColor[1], inv_alpha); /* G */
      VEC4_MUL(source[2], quadColor[2], inv_alpha); /* B */
   }
   break;
   case PIPE_BLENDFACTOR_INV_SRC1_COLOR:
      assert(0); /* to do */
      break;
   case PIPE_BLENDFACTOR_INV_SRC1_ALPHA:
      assert(0); /* to do */
      break;
   default:
      assert(0);
   }

   /*
    * Compute src/first term A
    */
   switch (softpipe->blend->rt[cbuf].alpha_src_factor) {
   case PIPE_BLENDFACTOR_ONE:
      VEC4_COPY(source[3], quadColor[3]); /* A */
      break;
   case PIPE_BLENDFACTOR_SRC_COLOR:
      /* fall-through */
   case PIPE_BLENDFACTOR_SRC_ALPHA:
   {
      const float *alpha = quadColor[3];
      VEC4_MUL(source[3], quadColor[3], alpha); /* A */
   }
   break;
   case PIPE_BLENDFACTOR_DST_COLOR:
      /* fall-through */
   case PIPE_BLENDFACTOR_DST_ALPHA:
      VEC4_MUL(source[3], quadColor[3], dest[3]); /* A */
      break;
   case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE:
      /* multiply alpha by 1.0 */
      VEC4_COPY(source[3], quadColor[3]); /* A */
      break;
   case PIPE_BLENDFACTOR_CONST_COLOR:
      /* fall-through */
   case PIPE_BLENDFACTOR_CONST_ALPHA:
   {
      float comp[4];
      VEC4_SCALAR(comp, softpipe->blend_color.color[3]); /* A */
      VEC4_MUL(source[3], quadColor[3], comp); /* A */
   }
   break;
   case PIPE_BLENDFACTOR_ZERO:
      VEC4_COPY(source[3], zero); /* A */
      break;
   case PIPE_BLENDFACTOR_INV_SRC_COLOR:
      /* fall-through */
   case PIPE_BLENDFACTOR_INV_SRC_ALPHA:
   {
      float inv_alpha[4];
      VEC4_SUB(inv_alpha, one, quadColor[3]);
      VEC4_MUL(source[3], quadColor[3], inv_alpha); /* A */
   }
   break;
   case PIPE_BLENDFACTOR_INV_DST_COLOR:
      /* fall-through */
   case PIPE_BLENDFACTOR_INV_DST_ALPHA:
   {
      float inv_alpha[4];
      VEC4_SUB(inv_alpha, one, dest[3]);
      VEC4_MUL(source[3], quadColor[3], inv_alpha); /* A */
   }
   break;
   case PIPE_BLENDFACTOR_INV_CONST_COLOR:
      /* fall-through */
   case PIPE_BLENDFACTOR_INV_CONST_ALPHA:
   {
      float inv_comp[4];
      /* A */
      VEC4_SCALAR(inv_comp, 1.0f - softpipe->blend_color.color[3]);
      VEC4_MUL(source[3], quadColor[3], inv_comp);
   }
   break;
   default:
      assert(0);
   }


   /*
    * Compute dest/second term RGB
    */
   switch (softpipe->blend->rt[cbuf].rgb_dst_factor) {
   case PIPE_BLENDFACTOR_ONE:
      /* dest = dest * 1   NO-OP, leave dest as-is */
      break;
   case PIPE_BLENDFACTOR_SRC_COLOR:
      VEC4_MUL(dest[0], dest[0], quadColor[0]); /* R */
      VEC4_MUL(dest[1], dest[1], quadColor[1]); /* G */
      VEC4_MUL(dest[2], dest[2], quadColor[2]); /* B */
      break;
   case PIPE_BLENDFACTOR_SRC_ALPHA:
      VEC4_MUL(dest[0], dest[0], quadColor[3]); /* R * A */
      VEC4_MUL(dest[1], dest[1], quadColor[3]); /* G * A */
      VEC4_MUL(dest[2], dest[2], quadColor[3]); /* B * A */
      break;
   case PIPE_BLENDFACTOR_DST_ALPHA:
      VEC4_MUL(dest[0], dest[0], dest[3]); /* R * A */
      VEC4_MUL(dest[1], dest[1], dest[3]); /* G * A */
      VEC4_MUL(dest[2], dest[2], dest[3]); /* B * A */
      break;
   case PIPE_BLENDFACTOR_DST_COLOR:
      VEC4_MUL(dest[0], dest[0], dest[0]); /* R */
      VEC4_MUL(dest[1], dest[1], dest[1]); /* G */
      VEC4_MUL(dest[2], dest[2], dest[2]); /* B */
      break;
   case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE:
   {
      const float *alpha = quadColor[3];
      float diff[4], temp[4];
      VEC4_SUB(diff, one, dest[3]);
      VEC4_MIN(temp, alpha, diff);
      VEC4_MUL(dest[0], quadColor[0], temp); /* R */
      VEC4_MUL(dest[1], quadColor[1], temp); /* G */
      VEC4_MUL(dest[2], quadColor[2], temp); /* B */
   }
      break;
   case PIPE_BLENDFACTOR_CONST_COLOR:
   {
      float comp[4];
      VEC4_SCALAR(comp, softpipe->blend_color.color[0]); /* R */
      VEC4_MUL(dest[0], dest[0], comp); /* R */
      VEC4_SCALAR(comp, softpipe->blend_color.color[1]); /* G */
      VEC4_MUL(dest[1], dest[1], comp); /* G */
      VEC4_SCALAR(comp, softpipe->blend_color.color[2]); /* B */
      VEC4_MUL(dest[2], dest[2], comp); /* B */
   }
   break;
   case PIPE_BLENDFACTOR_CONST_ALPHA:
   {
      float comp[4];
      VEC4_SCALAR(comp, softpipe->blend_color.color[3]); /* A */
      VEC4_MUL(dest[0], dest[0], comp); /* R */
      VEC4_MUL(dest[1], dest[1], comp); /* G */
      VEC4_MUL(dest[2], dest[2], comp); /* B */
   }
   break;
   case PIPE_BLENDFACTOR_ZERO:
      VEC4_COPY(dest[0], zero); /* R */
      VEC4_COPY(dest[1], zero); /* G */
      VEC4_COPY(dest[2], zero); /* B */
      break;
   case PIPE_BLENDFACTOR_SRC1_COLOR:
   case PIPE_BLENDFACTOR_SRC1_ALPHA:
      /* XXX what are these? */
      assert(0);
      break;
   case PIPE_BLENDFACTOR_INV_SRC_COLOR:
   {
      float inv_comp[4];
      VEC4_SUB(inv_comp, one, quadColor[0]); /* R */
      VEC4_MUL(dest[0], inv_comp, dest[0]); /* R */
      VEC4_SUB(inv_comp, one, quadColor[1]); /* G */
      VEC4_MUL(dest[1], inv_comp, dest[1]); /* G */
      VEC4_SUB(inv_comp, one, quadColor[2]); /* B */
      VEC4_MUL(dest[2], inv_comp, dest[2]); /* B */
   }
   break;
   case PIPE_BLENDFACTOR_INV_SRC_ALPHA:
   {
      float one_minus_alpha[QUAD_SIZE];
      VEC4_SUB(one_minus_alpha, one, quadColor[3]);
      VEC4_MUL(dest[0], dest[0], one_minus_alpha); /* R */
      VEC4_MUL(dest[1], dest[1], one_minus_alpha); /* G */
      VEC4_MUL(dest[2], dest[2], one_minus_alpha); /* B */
   }
   break;
   case PIPE_BLENDFACTOR_INV_DST_ALPHA:
   {
      float inv_comp[4];
      VEC4_SUB(inv_comp, one, dest[3]); /* A */
      VEC4_MUL(dest[0], inv_comp, dest[0]); /* R */
      VEC4_MUL(dest[1], inv_comp, dest[1]); /* G */
      VEC4_MUL(dest[2], inv_comp, dest[2]); /* B */
   }
   break;
   case PIPE_BLENDFACTOR_INV_DST_COLOR:
   {
      float inv_comp[4];
      VEC4_SUB(inv_comp, one, dest[0]); /* R */
      VEC4_MUL(dest[0], dest[0], inv_comp); /* R */
      VEC4_SUB(inv_comp, one, dest[1]); /* G */
      VEC4_MUL(dest[1], dest[1], inv_comp); /* G */
      VEC4_SUB(inv_comp, one, dest[2]); /* B */
      VEC4_MUL(dest[2], dest[2], inv_comp); /* B */
   }
   break;
   case PIPE_BLENDFACTOR_INV_CONST_COLOR:
   {
      float inv_comp[4];
      /* R */
      VEC4_SCALAR(inv_comp, 1.0f - softpipe->blend_color.color[0]);
      VEC4_MUL(dest[0], dest[0], inv_comp);
      /* G */
      VEC4_SCALAR(inv_comp, 1.0f - softpipe->blend_color.color[1]);
      VEC4_MUL(dest[1], dest[1], inv_comp);
      /* B */
      VEC4_SCALAR(inv_comp, 1.0f - softpipe->blend_color.color[2]);
      VEC4_MUL(dest[2], dest[2], inv_comp);
   }
   break;
   case PIPE_BLENDFACTOR_INV_CONST_ALPHA:
   {
      float inv_comp[4];
      VEC4_SCALAR(inv_comp, 1.0f - softpipe->blend_color.color[3]);
      VEC4_MUL(dest[0], dest[0], inv_comp);
      VEC4_MUL(dest[1], dest[1], inv_comp);
      VEC4_MUL(dest[2], dest[2], inv_comp);
   }
   break;
   case PIPE_BLENDFACTOR_INV_SRC1_COLOR:
   case PIPE_BLENDFACTOR_INV_SRC1_ALPHA:
      /* XXX what are these? */
      assert(0);
      break;
   default:
      assert(0);
   }

   /*
    * Compute dest/second term A
    */
   switch (softpipe->blend->rt[cbuf].alpha_dst_factor) {
   case PIPE_BLENDFACTOR_ONE:
      /* dest = dest * 1   NO-OP, leave dest as-is */
      break;
   case PIPE_BLENDFACTOR_SRC_COLOR:
      /* fall-through */
   case PIPE_BLENDFACTOR_SRC_ALPHA:
      VEC4_MUL(dest[3], dest[3], quadColor[3]); /* A * A */
      break;
   case PIPE_BLENDFACTOR_DST_COLOR:
      /* fall-through */
   case PIPE_BLENDFACTOR_DST_ALPHA:
      VEC4_MUL(dest[3], dest[3], dest[3]); /* A */
      break;
   case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE:
      /* dest = dest * 1   NO-OP, leave dest as-is */
      break;
   case PIPE_BLENDFACTOR_CONST_COLOR:
      /* fall-through */
   case PIPE_BLENDFACTOR_CONST_ALPHA:
   {
      float comp[4];
      VEC4_SCALAR(comp, softpipe->blend_color.color[3]); /* A */
      VEC4_MUL(dest[3], dest[3], comp); /* A */
   }
   break;
   case PIPE_BLENDFACTOR_ZERO:
      VEC4_COPY(dest[3], zero); /* A */
      break;
   case PIPE_BLENDFACTOR_INV_SRC_COLOR:
      /* fall-through */
   case PIPE_BLENDFACTOR_INV_SRC_ALPHA:
   {
      float one_minus_alpha[QUAD_SIZE];
      VEC4_SUB(one_minus_alpha, one, quadColor[3]);
      VEC4_MUL(dest[3], dest[3], one_minus_alpha); /* A */
   }
   break;
   case PIPE_BLENDFACTOR_INV_DST_COLOR:
      /* fall-through */
   case PIPE_BLENDFACTOR_INV_DST_ALPHA:
   {
      float inv_comp[4];
      VEC4_SUB(inv_comp, one, dest[3]); /* A */
      VEC4_MUL(dest[3], inv_comp, dest[3]); /* A */
   }
   break;
   case PIPE_BLENDFACTOR_INV_CONST_COLOR:
      /* fall-through */
   case PIPE_BLENDFACTOR_INV_CONST_ALPHA:
   {
      float inv_comp[4];
      VEC4_SCALAR(inv_comp, 1.0f - softpipe->blend_color.color[3]);
      VEC4_MUL(dest[3], dest[3], inv_comp);
   }
   break;
   default:
      assert(0);
   }

   /*
    * Combine RGB terms
    */
   switch (softpipe->blend->rt[cbuf].rgb_func) {
   case PIPE_BLEND_ADD:
      VEC4_ADD_SAT(quadColor[0], source[0], dest[0]); /* R */
      VEC4_ADD_SAT(quadColor[1], source[1], dest[1]); /* G */
      VEC4_ADD_SAT(quadColor[2], source[2], dest[2]); /* B */
      break;
   case PIPE_BLEND_SUBTRACT:
      VEC4_SUB_SAT(quadColor[0], source[0], dest[0]); /* R */
      VEC4_SUB_SAT(quadColor[1], source[1], dest[1]); /* G */
      VEC4_SUB_SAT(quadColor[2], source[2], dest[2]); /* B */
      break;
   case PIPE_BLEND_REVERSE_SUBTRACT:
      VEC4_SUB_SAT(quadColor[0], dest[0], source[0]); /* R */
      VEC4_SUB_SAT(quadColor[1], dest[1], source[1]); /* G */
      VEC4_SUB_SAT(quadColor[2], dest[2], source[2]); /* B */
      break;
   case PIPE_BLEND_MIN:
      VEC4_MIN(quadColor[0], source[0], dest[0]); /* R */
      VEC4_MIN(quadColor[1], source[1], dest[1]); /* G */
      VEC4_MIN(quadColor[2], source[2], dest[2]); /* B */
      break;
   case PIPE_BLEND_MAX:
      VEC4_MAX(quadColor[0], source[0], dest[0]); /* R */
      VEC4_MAX(quadColor[1], source[1], dest[1]); /* G */
      VEC4_MAX(quadColor[2], source[2], dest[2]); /* B */
      break;
   default:
      assert(0);
   }

   /*
    * Combine A terms
    */
   switch (softpipe->blend->rt[cbuf].alpha_func) {
   case PIPE_BLEND_ADD:
      VEC4_ADD_SAT(quadColor[3], source[3], dest[3]); /* A */
      break;
   case PIPE_BLEND_SUBTRACT:
      VEC4_SUB_SAT(quadColor[3], source[3], dest[3]); /* A */
      break;
   case PIPE_BLEND_REVERSE_SUBTRACT:
      VEC4_SUB_SAT(quadColor[3], dest[3], source[3]); /* A */
      break;
   case PIPE_BLEND_MIN:
      VEC4_MIN(quadColor[3], source[3], dest[3]); /* A */
      break;
   case PIPE_BLEND_MAX:
      VEC4_MAX(quadColor[3], source[3], dest[3]); /* A */
      break;
   default:
      assert(0);
   }
}
コード例 #2
0
/**
 * Do blending for a 2x2 quad for one color buffer.
 * \param quadColor  the incoming quad colors
 * \param dest  the destination/framebuffer quad colors
 * \param const_blend_color  the constant blend color
 * \param blend_index  which set of blending terms to use
 */
static void
blend_quad(struct quad_stage *qs, 
           float (*quadColor)[4],
           float (*quadColor2)[4],
           float (*dest)[4],
           const float const_blend_color[4],
           unsigned blend_index)
{
   static const float zero[4] = { 0, 0, 0, 0 };
   static const float one[4] = { 1, 1, 1, 1 };
   struct softpipe_context *softpipe = qs->softpipe;
   float source[4][TGSI_QUAD_SIZE] = { { 0 } };
   float blend_dest[4][TGSI_QUAD_SIZE];

   /*
    * Compute src/first term RGB
    */
   switch (softpipe->blend->rt[blend_index].rgb_src_factor) {
   case PIPE_BLENDFACTOR_ONE:
      VEC4_COPY(source[0], quadColor[0]); /* R */
      VEC4_COPY(source[1], quadColor[1]); /* G */
      VEC4_COPY(source[2], quadColor[2]); /* B */
      break;
   case PIPE_BLENDFACTOR_SRC_COLOR:
      VEC4_MUL(source[0], quadColor[0], quadColor[0]); /* R */
      VEC4_MUL(source[1], quadColor[1], quadColor[1]); /* G */
      VEC4_MUL(source[2], quadColor[2], quadColor[2]); /* B */
      break;
   case PIPE_BLENDFACTOR_SRC_ALPHA:
      {
         const float *alpha = quadColor[3];
         VEC4_MUL(source[0], quadColor[0], alpha); /* R */
         VEC4_MUL(source[1], quadColor[1], alpha); /* G */
         VEC4_MUL(source[2], quadColor[2], alpha); /* B */
      }
      break;
   case PIPE_BLENDFACTOR_DST_COLOR:
      VEC4_MUL(source[0], quadColor[0], dest[0]); /* R */
      VEC4_MUL(source[1], quadColor[1], dest[1]); /* G */
      VEC4_MUL(source[2], quadColor[2], dest[2]); /* B */
      break;
   case PIPE_BLENDFACTOR_DST_ALPHA:
      {
         const float *alpha = dest[3];
         VEC4_MUL(source[0], quadColor[0], alpha); /* R */
         VEC4_MUL(source[1], quadColor[1], alpha); /* G */
         VEC4_MUL(source[2], quadColor[2], alpha); /* B */
      } 
      break;
   case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE:
      {
         const float *alpha = quadColor[3];
         float diff[4], temp[4];
         VEC4_SUB(diff, one, dest[3]);
         VEC4_MIN(temp, alpha, diff);
         VEC4_MUL(source[0], quadColor[0], temp); /* R */
         VEC4_MUL(source[1], quadColor[1], temp); /* G */
         VEC4_MUL(source[2], quadColor[2], temp); /* B */
      }
      break;
   case PIPE_BLENDFACTOR_CONST_COLOR:
      {
         float comp[4];
         VEC4_SCALAR(comp, const_blend_color[0]); /* R */
         VEC4_MUL(source[0], quadColor[0], comp); /* R */
         VEC4_SCALAR(comp, const_blend_color[1]); /* G */
         VEC4_MUL(source[1], quadColor[1], comp); /* G */
         VEC4_SCALAR(comp, const_blend_color[2]); /* B */
         VEC4_MUL(source[2], quadColor[2], comp); /* B */
      }
      break;
   case PIPE_BLENDFACTOR_CONST_ALPHA:
      {
         float alpha[4];
         VEC4_SCALAR(alpha, const_blend_color[3]);
         VEC4_MUL(source[0], quadColor[0], alpha); /* R */
         VEC4_MUL(source[1], quadColor[1], alpha); /* G */
         VEC4_MUL(source[2], quadColor[2], alpha); /* B */
      }
      break;
   case PIPE_BLENDFACTOR_SRC1_COLOR:
      VEC4_MUL(source[0], quadColor[0], quadColor2[0]); /* R */
      VEC4_MUL(source[1], quadColor[1], quadColor2[1]); /* G */
      VEC4_MUL(source[2], quadColor[2], quadColor2[2]); /* B */	 
      break;
   case PIPE_BLENDFACTOR_SRC1_ALPHA:
      {
         const float *alpha = quadColor2[3];
         VEC4_MUL(source[0], quadColor[0], alpha); /* R */
         VEC4_MUL(source[1], quadColor[1], alpha); /* G */
         VEC4_MUL(source[2], quadColor[2], alpha); /* B */
      }
      break;
   case PIPE_BLENDFACTOR_ZERO:
      VEC4_COPY(source[0], zero); /* R */
      VEC4_COPY(source[1], zero); /* G */
      VEC4_COPY(source[2], zero); /* B */
      break;
   case PIPE_BLENDFACTOR_INV_SRC_COLOR:
      {
         float inv_comp[4];
         VEC4_SUB(inv_comp, one, quadColor[0]); /* R */
         VEC4_MUL(source[0], quadColor[0], inv_comp); /* R */
         VEC4_SUB(inv_comp, one, quadColor[1]); /* G */
         VEC4_MUL(source[1], quadColor[1], inv_comp); /* G */
         VEC4_SUB(inv_comp, one, quadColor[2]); /* B */
         VEC4_MUL(source[2], quadColor[2], inv_comp); /* B */
      }
      break;
   case PIPE_BLENDFACTOR_INV_SRC_ALPHA:
      {
         float inv_alpha[4];
         VEC4_SUB(inv_alpha, one, quadColor[3]);
         VEC4_MUL(source[0], quadColor[0], inv_alpha); /* R */
         VEC4_MUL(source[1], quadColor[1], inv_alpha); /* G */
         VEC4_MUL(source[2], quadColor[2], inv_alpha); /* B */
      }
      break;
   case PIPE_BLENDFACTOR_INV_DST_ALPHA:
      {
         float inv_alpha[4];
         VEC4_SUB(inv_alpha, one, dest[3]);
         VEC4_MUL(source[0], quadColor[0], inv_alpha); /* R */
         VEC4_MUL(source[1], quadColor[1], inv_alpha); /* G */
         VEC4_MUL(source[2], quadColor[2], inv_alpha); /* B */
      }
      break;
   case PIPE_BLENDFACTOR_INV_DST_COLOR:
      {
         float inv_comp[4];
         VEC4_SUB(inv_comp, one, dest[0]); /* R */
         VEC4_MUL(source[0], quadColor[0], inv_comp); /* R */
         VEC4_SUB(inv_comp, one, dest[1]); /* G */
         VEC4_MUL(source[1], quadColor[1], inv_comp); /* G */
         VEC4_SUB(inv_comp, one, dest[2]); /* B */
         VEC4_MUL(source[2], quadColor[2], inv_comp); /* B */
      }
      break;
   case PIPE_BLENDFACTOR_INV_CONST_COLOR:
      {
         float inv_comp[4];
         /* R */
         VEC4_SCALAR(inv_comp, 1.0f - const_blend_color[0]);
         VEC4_MUL(source[0], quadColor[0], inv_comp);
         /* G */
         VEC4_SCALAR(inv_comp, 1.0f - const_blend_color[1]);
         VEC4_MUL(source[1], quadColor[1], inv_comp);
         /* B */
         VEC4_SCALAR(inv_comp, 1.0f - const_blend_color[2]);
         VEC4_MUL(source[2], quadColor[2], inv_comp);
      }
      break;
   case PIPE_BLENDFACTOR_INV_CONST_ALPHA:
      {
         float inv_alpha[4];
         VEC4_SCALAR(inv_alpha, 1.0f - const_blend_color[3]);
         VEC4_MUL(source[0], quadColor[0], inv_alpha); /* R */
         VEC4_MUL(source[1], quadColor[1], inv_alpha); /* G */
         VEC4_MUL(source[2], quadColor[2], inv_alpha); /* B */
      }
      break;
   case PIPE_BLENDFACTOR_INV_SRC1_COLOR:
      {
         float inv_comp[4];
         VEC4_SUB(inv_comp, one, quadColor2[0]); /* R */
         VEC4_MUL(source[0], quadColor[0], inv_comp); /* R */
         VEC4_SUB(inv_comp, one, quadColor2[1]); /* G */
         VEC4_MUL(source[1], quadColor[1], inv_comp); /* G */
         VEC4_SUB(inv_comp, one, quadColor2[2]); /* B */
         VEC4_MUL(source[2], quadColor[2], inv_comp); /* B */
      }
      break;
   case PIPE_BLENDFACTOR_INV_SRC1_ALPHA:
      {
         float inv_alpha[4];
         VEC4_SUB(inv_alpha, one, quadColor2[3]);
         VEC4_MUL(source[0], quadColor[0], inv_alpha); /* R */
         VEC4_MUL(source[1], quadColor[1], inv_alpha); /* G */
         VEC4_MUL(source[2], quadColor[2], inv_alpha); /* B */
      }
      break;
   default:
      assert(0 && "invalid rgb src factor");
   }

   /*
    * Compute src/first term A
    */
   switch (softpipe->blend->rt[blend_index].alpha_src_factor) {
   case PIPE_BLENDFACTOR_ONE:
      VEC4_COPY(source[3], quadColor[3]); /* A */
      break;
   case PIPE_BLENDFACTOR_SRC_COLOR:
      /* fall-through */
   case PIPE_BLENDFACTOR_SRC_ALPHA:
      {
         const float *alpha = quadColor[3];
         VEC4_MUL(source[3], quadColor[3], alpha); /* A */
      }
      break;
   case PIPE_BLENDFACTOR_DST_COLOR:
      /* fall-through */
   case PIPE_BLENDFACTOR_DST_ALPHA:
      VEC4_MUL(source[3], quadColor[3], dest[3]); /* A */
      break;
   case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE:
      /* multiply alpha by 1.0 */
      VEC4_COPY(source[3], quadColor[3]); /* A */
      break;
   case PIPE_BLENDFACTOR_CONST_COLOR:
      /* fall-through */
   case PIPE_BLENDFACTOR_CONST_ALPHA:
      {
         float comp[4];
         VEC4_SCALAR(comp, const_blend_color[3]); /* A */
         VEC4_MUL(source[3], quadColor[3], comp); /* A */
      }
      break;
   case PIPE_BLENDFACTOR_ZERO:
      VEC4_COPY(source[3], zero); /* A */
      break;
   case PIPE_BLENDFACTOR_INV_SRC_COLOR:
      /* fall-through */
   case PIPE_BLENDFACTOR_INV_SRC_ALPHA:
      {
         float inv_alpha[4];
         VEC4_SUB(inv_alpha, one, quadColor[3]);
         VEC4_MUL(source[3], quadColor[3], inv_alpha); /* A */
      }
      break;
   case PIPE_BLENDFACTOR_INV_DST_COLOR:
      /* fall-through */
   case PIPE_BLENDFACTOR_INV_DST_ALPHA:
      {
         float inv_alpha[4];
         VEC4_SUB(inv_alpha, one, dest[3]);
         VEC4_MUL(source[3], quadColor[3], inv_alpha); /* A */
      }
      break;
   case PIPE_BLENDFACTOR_INV_CONST_COLOR:
      /* fall-through */
   case PIPE_BLENDFACTOR_INV_CONST_ALPHA:
      {
         float inv_comp[4];
         /* A */
         VEC4_SCALAR(inv_comp, 1.0f - const_blend_color[3]);
         VEC4_MUL(source[3], quadColor[3], inv_comp);
      }
      break;
   case PIPE_BLENDFACTOR_SRC1_COLOR:
      /* fall-through */
   case PIPE_BLENDFACTOR_SRC1_ALPHA:
      {
         const float *alpha = quadColor2[3];
         VEC4_MUL(source[3], quadColor[3], alpha); /* A */
      }
      break;
   case PIPE_BLENDFACTOR_INV_SRC1_COLOR:
      /* fall-through */
   case PIPE_BLENDFACTOR_INV_SRC1_ALPHA:
      {
         float inv_alpha[4];
         VEC4_SUB(inv_alpha, one, quadColor2[3]);
         VEC4_MUL(source[3], quadColor[3], inv_alpha); /* A */
      }
      break;
   default:
      assert(0 && "invalid alpha src factor");
   }

   /* Save the original dest for use in masking */
   VEC4_COPY(blend_dest[0], dest[0]);
   VEC4_COPY(blend_dest[1], dest[1]);
   VEC4_COPY(blend_dest[2], dest[2]);
   VEC4_COPY(blend_dest[3], dest[3]);


   /*
    * Compute blend_dest/second term RGB
    */
   switch (softpipe->blend->rt[blend_index].rgb_dst_factor) {
   case PIPE_BLENDFACTOR_ONE:
      /* blend_dest = blend_dest * 1   NO-OP, leave blend_dest as-is */
      break;
   case PIPE_BLENDFACTOR_SRC_COLOR:
      VEC4_MUL(blend_dest[0], blend_dest[0], quadColor[0]); /* R */
      VEC4_MUL(blend_dest[1], blend_dest[1], quadColor[1]); /* G */
      VEC4_MUL(blend_dest[2], blend_dest[2], quadColor[2]); /* B */
      break;
   case PIPE_BLENDFACTOR_SRC_ALPHA:
      VEC4_MUL(blend_dest[0], blend_dest[0], quadColor[3]); /* R * A */
      VEC4_MUL(blend_dest[1], blend_dest[1], quadColor[3]); /* G * A */
      VEC4_MUL(blend_dest[2], blend_dest[2], quadColor[3]); /* B * A */
      break;
   case PIPE_BLENDFACTOR_DST_ALPHA:
      VEC4_MUL(blend_dest[0], blend_dest[0], blend_dest[3]); /* R * A */
      VEC4_MUL(blend_dest[1], blend_dest[1], blend_dest[3]); /* G * A */
      VEC4_MUL(blend_dest[2], blend_dest[2], blend_dest[3]); /* B * A */
      break;
   case PIPE_BLENDFACTOR_DST_COLOR:
      VEC4_MUL(blend_dest[0], blend_dest[0], blend_dest[0]); /* R */
      VEC4_MUL(blend_dest[1], blend_dest[1], blend_dest[1]); /* G */
      VEC4_MUL(blend_dest[2], blend_dest[2], blend_dest[2]); /* B */
      break;
   case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE:
      {
         const float *alpha = quadColor[3];
         float diff[4], temp[4];
         VEC4_SUB(diff, one, blend_dest[3]);
         VEC4_MIN(temp, alpha, diff);
         VEC4_MUL(blend_dest[0], blend_dest[0], temp); /* R */
         VEC4_MUL(blend_dest[1], blend_dest[1], temp); /* G */
         VEC4_MUL(blend_dest[2], blend_dest[2], temp); /* B */
      }
      break;
   case PIPE_BLENDFACTOR_CONST_COLOR:
      {
         float comp[4];
         VEC4_SCALAR(comp, const_blend_color[0]); /* R */
         VEC4_MUL(blend_dest[0], blend_dest[0], comp); /* R */
         VEC4_SCALAR(comp, const_blend_color[1]); /* G */
         VEC4_MUL(blend_dest[1], blend_dest[1], comp); /* G */
         VEC4_SCALAR(comp, const_blend_color[2]); /* B */
         VEC4_MUL(blend_dest[2], blend_dest[2], comp); /* B */
      }
      break;
   case PIPE_BLENDFACTOR_CONST_ALPHA:
      {
         float comp[4];
         VEC4_SCALAR(comp, const_blend_color[3]); /* A */
         VEC4_MUL(blend_dest[0], blend_dest[0], comp); /* R */
         VEC4_MUL(blend_dest[1], blend_dest[1], comp); /* G */
         VEC4_MUL(blend_dest[2], blend_dest[2], comp); /* B */
      }
      break;
   case PIPE_BLENDFACTOR_ZERO:
      VEC4_COPY(blend_dest[0], zero); /* R */
      VEC4_COPY(blend_dest[1], zero); /* G */
      VEC4_COPY(blend_dest[2], zero); /* B */
      break;
   case PIPE_BLENDFACTOR_SRC1_COLOR:
      VEC4_MUL(blend_dest[0], blend_dest[0], quadColor2[0]); /* R */
      VEC4_MUL(blend_dest[1], blend_dest[1], quadColor2[1]); /* G */
      VEC4_MUL(blend_dest[2], blend_dest[2], quadColor2[2]); /* B */
      break;
   case PIPE_BLENDFACTOR_SRC1_ALPHA:
      VEC4_MUL(blend_dest[0], blend_dest[0], quadColor2[3]); /* R * A */
      VEC4_MUL(blend_dest[1], blend_dest[1], quadColor2[3]); /* G * A */
      VEC4_MUL(blend_dest[2], blend_dest[2], quadColor2[3]); /* B * A */
      break;
   case PIPE_BLENDFACTOR_INV_SRC_COLOR:
      {
         float inv_comp[4];
         VEC4_SUB(inv_comp, one, quadColor[0]); /* R */
         VEC4_MUL(blend_dest[0], inv_comp, blend_dest[0]); /* R */
         VEC4_SUB(inv_comp, one, quadColor[1]); /* G */
         VEC4_MUL(blend_dest[1], inv_comp, blend_dest[1]); /* G */
         VEC4_SUB(inv_comp, one, quadColor[2]); /* B */
         VEC4_MUL(blend_dest[2], inv_comp, blend_dest[2]); /* B */
      }
      break;
   case PIPE_BLENDFACTOR_INV_SRC_ALPHA:
      {
         float one_minus_alpha[TGSI_QUAD_SIZE];
         VEC4_SUB(one_minus_alpha, one, quadColor[3]);
         VEC4_MUL(blend_dest[0], blend_dest[0], one_minus_alpha); /* R */
         VEC4_MUL(blend_dest[1], blend_dest[1], one_minus_alpha); /* G */
         VEC4_MUL(blend_dest[2], blend_dest[2], one_minus_alpha); /* B */
      }
      break;
   case PIPE_BLENDFACTOR_INV_DST_ALPHA:
      {
         float inv_comp[4];
         VEC4_SUB(inv_comp, one, blend_dest[3]); /* A */
         VEC4_MUL(blend_dest[0], inv_comp, blend_dest[0]); /* R */
         VEC4_MUL(blend_dest[1], inv_comp, blend_dest[1]); /* G */
         VEC4_MUL(blend_dest[2], inv_comp, blend_dest[2]); /* B */
      }
      break;
   case PIPE_BLENDFACTOR_INV_DST_COLOR:
      {
         float inv_comp[4];
         VEC4_SUB(inv_comp, one, blend_dest[0]); /* R */
         VEC4_MUL(blend_dest[0], blend_dest[0], inv_comp); /* R */
         VEC4_SUB(inv_comp, one, blend_dest[1]); /* G */
         VEC4_MUL(blend_dest[1], blend_dest[1], inv_comp); /* G */
         VEC4_SUB(inv_comp, one, blend_dest[2]); /* B */
         VEC4_MUL(blend_dest[2], blend_dest[2], inv_comp); /* B */
      }
      break;
   case PIPE_BLENDFACTOR_INV_CONST_COLOR:
      {
         float inv_comp[4];
         /* R */
         VEC4_SCALAR(inv_comp, 1.0f - const_blend_color[0]);
         VEC4_MUL(blend_dest[0], blend_dest[0], inv_comp);
         /* G */
         VEC4_SCALAR(inv_comp, 1.0f - const_blend_color[1]);
         VEC4_MUL(blend_dest[1], blend_dest[1], inv_comp);
         /* B */
         VEC4_SCALAR(inv_comp, 1.0f - const_blend_color[2]);
         VEC4_MUL(blend_dest[2], blend_dest[2], inv_comp);
      }
      break;
   case PIPE_BLENDFACTOR_INV_CONST_ALPHA:
      {
         float inv_comp[4];
         VEC4_SCALAR(inv_comp, 1.0f - const_blend_color[3]);
         VEC4_MUL(blend_dest[0], blend_dest[0], inv_comp);
         VEC4_MUL(blend_dest[1], blend_dest[1], inv_comp);
         VEC4_MUL(blend_dest[2], blend_dest[2], inv_comp);
      }
      break;
   case PIPE_BLENDFACTOR_INV_SRC1_COLOR:
      {
         float inv_comp[4];
         VEC4_SUB(inv_comp, one, quadColor2[0]); /* R */
         VEC4_MUL(blend_dest[0], inv_comp, blend_dest[0]); /* R */
         VEC4_SUB(inv_comp, one, quadColor2[1]); /* G */
         VEC4_MUL(blend_dest[1], inv_comp, blend_dest[1]); /* G */
         VEC4_SUB(inv_comp, one, quadColor2[2]); /* B */
         VEC4_MUL(blend_dest[2], inv_comp, blend_dest[2]); /* B */
      }
      break;
   case PIPE_BLENDFACTOR_INV_SRC1_ALPHA:
      {
         float one_minus_alpha[TGSI_QUAD_SIZE];
         VEC4_SUB(one_minus_alpha, one, quadColor2[3]);
         VEC4_MUL(blend_dest[0], blend_dest[0], one_minus_alpha); /* R */
         VEC4_MUL(blend_dest[1], blend_dest[1], one_minus_alpha); /* G */
         VEC4_MUL(blend_dest[2], blend_dest[2], one_minus_alpha); /* B */
      }
      break;
   default:
      assert(0 && "invalid rgb dst factor");
   }

   /*
    * Compute blend_dest/second term A
    */
   switch (softpipe->blend->rt[blend_index].alpha_dst_factor) {
   case PIPE_BLENDFACTOR_ONE:
      /* blend_dest = blend_dest * 1   NO-OP, leave blend_dest as-is */
      break;
   case PIPE_BLENDFACTOR_SRC_COLOR:
      /* fall-through */
   case PIPE_BLENDFACTOR_SRC_ALPHA:
      VEC4_MUL(blend_dest[3], blend_dest[3], quadColor[3]); /* A * A */
      break;
   case PIPE_BLENDFACTOR_DST_COLOR:
      /* fall-through */
   case PIPE_BLENDFACTOR_DST_ALPHA:
      VEC4_MUL(blend_dest[3], blend_dest[3], blend_dest[3]); /* A */
      break;
   case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE:
      /* blend_dest = blend_dest * 1   NO-OP, leave blend_dest as-is */
      break;
   case PIPE_BLENDFACTOR_CONST_COLOR:
      /* fall-through */
   case PIPE_BLENDFACTOR_CONST_ALPHA:
      {
         float comp[4];
         VEC4_SCALAR(comp, const_blend_color[3]); /* A */
         VEC4_MUL(blend_dest[3], blend_dest[3], comp); /* A */
      }
      break;
   case PIPE_BLENDFACTOR_ZERO:
      VEC4_COPY(blend_dest[3], zero); /* A */
      break;
   case PIPE_BLENDFACTOR_INV_SRC_COLOR:
      /* fall-through */
   case PIPE_BLENDFACTOR_INV_SRC_ALPHA:
      {
         float one_minus_alpha[TGSI_QUAD_SIZE];
         VEC4_SUB(one_minus_alpha, one, quadColor[3]);
         VEC4_MUL(blend_dest[3], blend_dest[3], one_minus_alpha); /* A */
      }
      break;
   case PIPE_BLENDFACTOR_INV_DST_COLOR:
      /* fall-through */
   case PIPE_BLENDFACTOR_INV_DST_ALPHA:
      {
         float inv_comp[4];
         VEC4_SUB(inv_comp, one, blend_dest[3]); /* A */
         VEC4_MUL(blend_dest[3], inv_comp, blend_dest[3]); /* A */
      }
      break;
   case PIPE_BLENDFACTOR_INV_CONST_COLOR:
      /* fall-through */
   case PIPE_BLENDFACTOR_INV_CONST_ALPHA:
      {
         float inv_comp[4];
         VEC4_SCALAR(inv_comp, 1.0f - const_blend_color[3]);
         VEC4_MUL(blend_dest[3], blend_dest[3], inv_comp);
      }
      break;
   case PIPE_BLENDFACTOR_SRC1_COLOR:
      /* fall-through */
   case PIPE_BLENDFACTOR_SRC1_ALPHA:
      VEC4_MUL(blend_dest[3], blend_dest[3], quadColor2[3]); /* A * A */
      break;
   case PIPE_BLENDFACTOR_INV_SRC1_COLOR:
      /* fall-through */
   case PIPE_BLENDFACTOR_INV_SRC1_ALPHA:
      {
         float one_minus_alpha[TGSI_QUAD_SIZE];
         VEC4_SUB(one_minus_alpha, one, quadColor2[3]);
         VEC4_MUL(blend_dest[3], blend_dest[3], one_minus_alpha); /* A */
      }
      break;
   default:
      assert(0 && "invalid alpha dst factor");
   }

   /*
    * Combine RGB terms
    */
   switch (softpipe->blend->rt[blend_index].rgb_func) {
   case PIPE_BLEND_ADD:
      VEC4_ADD(quadColor[0], source[0], blend_dest[0]); /* R */
      VEC4_ADD(quadColor[1], source[1], blend_dest[1]); /* G */
      VEC4_ADD(quadColor[2], source[2], blend_dest[2]); /* B */
      break;
   case PIPE_BLEND_SUBTRACT:
      VEC4_SUB(quadColor[0], source[0], blend_dest[0]); /* R */
      VEC4_SUB(quadColor[1], source[1], blend_dest[1]); /* G */
      VEC4_SUB(quadColor[2], source[2], blend_dest[2]); /* B */
      break;
   case PIPE_BLEND_REVERSE_SUBTRACT:
      VEC4_SUB(quadColor[0], blend_dest[0], source[0]); /* R */
      VEC4_SUB(quadColor[1], blend_dest[1], source[1]); /* G */
      VEC4_SUB(quadColor[2], blend_dest[2], source[2]); /* B */
      break;
   case PIPE_BLEND_MIN:
      VEC4_MIN(quadColor[0], source[0], blend_dest[0]); /* R */
      VEC4_MIN(quadColor[1], source[1], blend_dest[1]); /* G */
      VEC4_MIN(quadColor[2], source[2], blend_dest[2]); /* B */
      break;
   case PIPE_BLEND_MAX:
      VEC4_MAX(quadColor[0], source[0], blend_dest[0]); /* R */
      VEC4_MAX(quadColor[1], source[1], blend_dest[1]); /* G */
      VEC4_MAX(quadColor[2], source[2], blend_dest[2]); /* B */
      break;
   default:
      assert(0 && "invalid rgb blend func");
   }

   /*
    * Combine A terms
    */
   switch (softpipe->blend->rt[blend_index].alpha_func) {
   case PIPE_BLEND_ADD:
      VEC4_ADD(quadColor[3], source[3], blend_dest[3]); /* A */
      break;
   case PIPE_BLEND_SUBTRACT:
      VEC4_SUB(quadColor[3], source[3], blend_dest[3]); /* A */
      break;
   case PIPE_BLEND_REVERSE_SUBTRACT:
      VEC4_SUB(quadColor[3], blend_dest[3], source[3]); /* A */
      break;
   case PIPE_BLEND_MIN:
      VEC4_MIN(quadColor[3], source[3], blend_dest[3]); /* A */
      break;
   case PIPE_BLEND_MAX:
      VEC4_MAX(quadColor[3], source[3], blend_dest[3]); /* A */
      break;
   default:
      assert(0 && "invalid alpha blend func");
   }
}