13192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz/**********************************************************
23192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz * Copyright 2008-2009 VMware, Inc.  All rights reserved.
33192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz *
43192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz * Permission is hereby granted, free of charge, to any person
53192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz * obtaining a copy of this software and associated documentation
63192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz * files (the "Software"), to deal in the Software without
73192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz * restriction, including without limitation the rights to use, copy,
83192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz * modify, merge, publish, distribute, sublicense, and/or sell copies
93192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz * of the Software, and to permit persons to whom the Software is
103192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz * furnished to do so, subject to the following conditions:
113192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz *
123192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz * The above copyright notice and this permission notice shall be
133192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz * included in all copies or substantial portions of the Software.
143192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz *
153192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
163192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
173192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
183192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
193192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
203192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
213192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
223192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz * SOFTWARE.
233192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz *
243192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz **********************************************************/
253192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz
2628486880ca3ec39419ccee0cb1a3bedc9ef7117cJosé Fonseca#include "util/u_inlines.h"
273192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz#include "pipe/p_defines.h"
283192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz#include "util/u_math.h"
293192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz#include "util/u_memory.h"
303192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz
313192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz#include "svga_context.h"
323192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz
333192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz#include "svga_hw_reg.h"
343192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz
353192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz
363192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantzstatic INLINE unsigned
373192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantzsvga_translate_blend_factor(unsigned factor)
383192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz{
393192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz   switch (factor) {
403192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz   case PIPE_BLENDFACTOR_ZERO:            return SVGA3D_BLENDOP_ZERO;
413192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz   case PIPE_BLENDFACTOR_SRC_ALPHA:       return SVGA3D_BLENDOP_SRCALPHA;
423192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz   case PIPE_BLENDFACTOR_ONE:             return SVGA3D_BLENDOP_ONE;
433192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz   case PIPE_BLENDFACTOR_SRC_COLOR:       return SVGA3D_BLENDOP_SRCCOLOR;
443192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz   case PIPE_BLENDFACTOR_INV_SRC_COLOR:   return SVGA3D_BLENDOP_INVSRCCOLOR;
453192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz   case PIPE_BLENDFACTOR_DST_COLOR:       return SVGA3D_BLENDOP_DESTCOLOR;
463192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz   case PIPE_BLENDFACTOR_INV_DST_COLOR:   return SVGA3D_BLENDOP_INVDESTCOLOR;
473192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz   case PIPE_BLENDFACTOR_INV_SRC_ALPHA:   return SVGA3D_BLENDOP_INVSRCALPHA;
483192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz   case PIPE_BLENDFACTOR_DST_ALPHA:       return SVGA3D_BLENDOP_DESTALPHA;
493192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz   case PIPE_BLENDFACTOR_INV_DST_ALPHA:   return SVGA3D_BLENDOP_INVDESTALPHA;
503192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz   case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE: return SVGA3D_BLENDOP_SRCALPHASAT;
513192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz   case PIPE_BLENDFACTOR_CONST_COLOR:     return SVGA3D_BLENDOP_BLENDFACTOR;
523192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz   case PIPE_BLENDFACTOR_INV_CONST_COLOR: return SVGA3D_BLENDOP_INVBLENDFACTOR;
533192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz   case PIPE_BLENDFACTOR_CONST_ALPHA:     return SVGA3D_BLENDOP_BLENDFACTOR; /* ? */
543192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz   case PIPE_BLENDFACTOR_INV_CONST_ALPHA: return SVGA3D_BLENDOP_INVBLENDFACTOR; /* ? */
553192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz   default:
563192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz      assert(0);
573192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz      return SVGA3D_BLENDOP_ZERO;
583192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz   }
593192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz}
603192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz
613192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantzstatic INLINE unsigned
623192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantzsvga_translate_blend_func(unsigned mode)
633192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz{
643192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz   switch (mode) {
653192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz   case PIPE_BLEND_ADD:              return SVGA3D_BLENDEQ_ADD;
663192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz   case PIPE_BLEND_SUBTRACT:         return SVGA3D_BLENDEQ_SUBTRACT;
673192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz   case PIPE_BLEND_REVERSE_SUBTRACT: return SVGA3D_BLENDEQ_REVSUBTRACT;
683192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz   case PIPE_BLEND_MIN:              return SVGA3D_BLENDEQ_MINIMUM;
693192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz   case PIPE_BLEND_MAX:              return SVGA3D_BLENDEQ_MAXIMUM;
703192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz   default:
713192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz      assert(0);
723192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz      return SVGA3D_BLENDEQ_ADD;
733192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz   }
743192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz}
753192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz
763192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz
773192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantzstatic void *
783192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantzsvga_create_blend_state(struct pipe_context *pipe,
793192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz                        const struct pipe_blend_state *templ)
803192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz{
813192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz   struct svga_blend_state *blend = CALLOC_STRUCT( svga_blend_state );
823192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz   unsigned i;
833192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz
843192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz
853192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz   /* Fill in the per-rendertarget blend state.  We currently only
863192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz    * have one rendertarget.
873192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz    */
883192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz   for (i = 0; i < 1; i++) {
893192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz      /* No way to set this in SVGA3D, and no way to correctly implement it on
903192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz       * top of D3D9 API.  Instead we try to simulate with various blend modes.
913192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz       */
923192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz      if (templ->logicop_enable) {
933192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz         switch (templ->logicop_func) {
943192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz         case PIPE_LOGICOP_XOR:
9512d5203bb39a6146c5fd08b66f49b4fc1feb1162José Fonseca         case PIPE_LOGICOP_INVERT:
963192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            blend->need_white_fragments = TRUE;
973192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            blend->rt[i].blend_enable = TRUE;
983192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            blend->rt[i].srcblend       = SVGA3D_BLENDOP_ONE;
993192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            blend->rt[i].dstblend       = SVGA3D_BLENDOP_ONE;
1003192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            blend->rt[i].blendeq        = SVGA3D_BLENDEQ_SUBTRACT;
1013192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            break;
1023192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz         case PIPE_LOGICOP_CLEAR:
1033192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            blend->rt[i].blend_enable = TRUE;
1043192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            blend->rt[i].srcblend       = SVGA3D_BLENDOP_ZERO;
1053192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            blend->rt[i].dstblend       = SVGA3D_BLENDOP_ZERO;
1063192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            blend->rt[i].blendeq        = SVGA3D_BLENDEQ_MINIMUM;
1073192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            break;
1083192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz         case PIPE_LOGICOP_COPY:
1093192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            blend->rt[i].blend_enable = FALSE;
1103192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            break;
1113192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz         case PIPE_LOGICOP_COPY_INVERTED:
1123192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            blend->rt[i].blend_enable   = TRUE;
1133192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            blend->rt[i].srcblend       = SVGA3D_BLENDOP_INVSRCCOLOR;
1143192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            blend->rt[i].dstblend       = SVGA3D_BLENDOP_ZERO;
1153192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            blend->rt[i].blendeq        = SVGA3D_BLENDEQ_ADD;
1163192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            break;
1173192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz         case PIPE_LOGICOP_NOOP:
1183192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            blend->rt[i].blend_enable   = TRUE;
1193192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            blend->rt[i].srcblend       = SVGA3D_BLENDOP_ZERO;
1203192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            blend->rt[i].dstblend       = SVGA3D_BLENDOP_DESTCOLOR;
1213192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            blend->rt[i].blendeq        = SVGA3D_BLENDEQ_ADD;
1223192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            break;
1233192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz         case PIPE_LOGICOP_SET:
1243192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            blend->rt[i].blend_enable = TRUE;
1253192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            blend->rt[i].srcblend       = SVGA3D_BLENDOP_ONE;
1263192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            blend->rt[i].dstblend       = SVGA3D_BLENDOP_ONE;
1273192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            blend->rt[i].blendeq        = SVGA3D_BLENDEQ_MAXIMUM;
1283192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            break;
1293192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz         case PIPE_LOGICOP_AND:
1303192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            /* Approximate with minimum - works for the 0 & anything case: */
1313192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            blend->rt[i].blend_enable = TRUE;
1323192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            blend->rt[i].srcblend       = SVGA3D_BLENDOP_SRCCOLOR;
1333192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            blend->rt[i].dstblend       = SVGA3D_BLENDOP_DESTCOLOR;
1343192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            blend->rt[i].blendeq        = SVGA3D_BLENDEQ_MINIMUM;
1353192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            break;
1363192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz         case PIPE_LOGICOP_AND_REVERSE:
1373192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            blend->rt[i].blend_enable = TRUE;
1383192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            blend->rt[i].srcblend       = SVGA3D_BLENDOP_SRCCOLOR;
1393192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            blend->rt[i].dstblend       = SVGA3D_BLENDOP_INVDESTCOLOR;
1403192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            blend->rt[i].blendeq        = SVGA3D_BLENDEQ_MINIMUM;
1413192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            break;
1423192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz         case PIPE_LOGICOP_AND_INVERTED:
1433192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            blend->rt[i].blend_enable = TRUE;
1443192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            blend->rt[i].srcblend       = SVGA3D_BLENDOP_INVSRCCOLOR;
1453192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            blend->rt[i].dstblend       = SVGA3D_BLENDOP_DESTCOLOR;
1463192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            blend->rt[i].blendeq        = SVGA3D_BLENDEQ_MINIMUM;
1473192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            break;
1483192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz         case PIPE_LOGICOP_OR:
1493192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            /* Approximate with maximum - works for the 1 | anything case: */
1503192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            blend->rt[i].blend_enable = TRUE;
1513192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            blend->rt[i].srcblend       = SVGA3D_BLENDOP_SRCCOLOR;
1523192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            blend->rt[i].dstblend       = SVGA3D_BLENDOP_DESTCOLOR;
1533192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            blend->rt[i].blendeq        = SVGA3D_BLENDEQ_MAXIMUM;
1543192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            break;
1553192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz         case PIPE_LOGICOP_OR_REVERSE:
1563192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            blend->rt[i].blend_enable = TRUE;
1573192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            blend->rt[i].srcblend       = SVGA3D_BLENDOP_SRCCOLOR;
1583192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            blend->rt[i].dstblend       = SVGA3D_BLENDOP_INVDESTCOLOR;
1593192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            blend->rt[i].blendeq        = SVGA3D_BLENDEQ_MAXIMUM;
1603192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            break;
1613192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz         case PIPE_LOGICOP_OR_INVERTED:
1623192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            blend->rt[i].blend_enable = TRUE;
1633192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            blend->rt[i].srcblend       = SVGA3D_BLENDOP_INVSRCCOLOR;
1643192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            blend->rt[i].dstblend       = SVGA3D_BLENDOP_DESTCOLOR;
1653192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            blend->rt[i].blendeq        = SVGA3D_BLENDEQ_MAXIMUM;
1663192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            break;
1673192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz         case PIPE_LOGICOP_NAND:
1683192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz         case PIPE_LOGICOP_NOR:
1693192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz         case PIPE_LOGICOP_EQUIV:
1703192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            /* Fill these in with plausible values */
1713192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            blend->rt[i].blend_enable = FALSE;
1723192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            break;
1733192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz         default:
1743192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            assert(0);
1753192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            break;
1763192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz         }
1773192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz      }
1783192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz      else {
1796893948d482ab69a41290d1b0172834197ee48f2Roland Scheidegger         blend->rt[i].blend_enable   = templ->rt[0].blend_enable;
1803192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz
1816893948d482ab69a41290d1b0172834197ee48f2Roland Scheidegger         if (templ->rt[0].blend_enable) {
1826893948d482ab69a41290d1b0172834197ee48f2Roland Scheidegger            blend->rt[i].srcblend       = svga_translate_blend_factor(templ->rt[0].rgb_src_factor);
1836893948d482ab69a41290d1b0172834197ee48f2Roland Scheidegger            blend->rt[i].dstblend       = svga_translate_blend_factor(templ->rt[0].rgb_dst_factor);
1846893948d482ab69a41290d1b0172834197ee48f2Roland Scheidegger            blend->rt[i].blendeq        = svga_translate_blend_func(templ->rt[0].rgb_func);
1856893948d482ab69a41290d1b0172834197ee48f2Roland Scheidegger            blend->rt[i].srcblend_alpha = svga_translate_blend_factor(templ->rt[0].alpha_src_factor);
1866893948d482ab69a41290d1b0172834197ee48f2Roland Scheidegger            blend->rt[i].dstblend_alpha = svga_translate_blend_factor(templ->rt[0].alpha_dst_factor);
1876893948d482ab69a41290d1b0172834197ee48f2Roland Scheidegger            blend->rt[i].blendeq_alpha  = svga_translate_blend_func(templ->rt[0].alpha_func);
1883192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz
1893192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            if (blend->rt[i].srcblend_alpha != blend->rt[i].srcblend ||
1903192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz                blend->rt[i].dstblend_alpha != blend->rt[i].dstblend ||
1913192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz                blend->rt[i].blendeq_alpha  != blend->rt[i].blendeq)
1923192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            {
1933192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz               blend->rt[i].separate_alpha_blend_enable = TRUE;
1943192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz            }
1953192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz         }
1963192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz      }
1973192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz
1986893948d482ab69a41290d1b0172834197ee48f2Roland Scheidegger      blend->rt[i].writemask = templ->rt[0].colormask;
1993192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz   }
2003192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz
2013192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz   return blend;
2023192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz}
2033192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz
2043192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantzstatic void svga_bind_blend_state(struct pipe_context *pipe,
2053192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz                                  void *blend)
2063192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz{
2073192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz   struct svga_context *svga = svga_context(pipe);
2083192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz
2093192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz   svga->curr.blend = (struct svga_blend_state*)blend;
2103192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz   svga->dirty |= SVGA_NEW_BLEND;
2113192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz}
2123192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz
2133192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz
2143192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantzstatic void svga_delete_blend_state(struct pipe_context *pipe, void *blend)
2153192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz{
2163192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz   FREE(blend);
2173192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz}
2183192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz
2193192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantzstatic void svga_set_blend_color( struct pipe_context *pipe,
2203192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz                                  const struct pipe_blend_color *blend_color )
2213192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz{
2223192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz   struct svga_context *svga = svga_context(pipe);
2233192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz
2243192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz   svga->curr.blend_color = *blend_color;
2253192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz
226cd5d7608897a435623b26e3d5d6391734b9197e8José Fonseca   svga->dirty |= SVGA_NEW_BLEND_COLOR;
2273192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz}
2283192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz
2293192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz
2303192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantzvoid svga_init_blend_functions( struct svga_context *svga )
2313192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz{
2323192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz   svga->pipe.create_blend_state = svga_create_blend_state;
2333192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz   svga->pipe.bind_blend_state = svga_bind_blend_state;
2343192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz   svga->pipe.delete_blend_state = svga_delete_blend_state;
2353192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz
2363192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz   svga->pipe.set_blend_color = svga_set_blend_color;
2373192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz}
2383192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz
2393192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz
2403192633d4abe262d413e41feb871fe8deed409d8Jakob Bornecrantz
241