svga: add support for independent blend function per render target
authorCharmaine Lee <charmainel@vmware.com>
Wed, 4 Oct 2017 17:05:58 +0000 (11:05 -0600)
committerBrian Paul <brianp@vmware.com>
Mon, 10 Sep 2018 19:07:30 +0000 (13:07 -0600)
This patch adds support for GL_ARB_draw_buffers_blend extension
for SM4_1 device.

Fixes piglit test fbo-draw-buffers-blend.

This patch is squashed with a subsequent patch which fixed a
regression.

Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Neha Bhende <bhenden@vmware.com>
Reviewed-by: Charmaine Lee <charmainel@vmware.com>
src/gallium/drivers/svga/svga_pipe_blend.c
src/gallium/drivers/svga/svga_screen.c

index 6bb9d94369b57bdf909d05f79a5a698ca3ebd474..b5557d31f4401b815be1651d4193cd6292503bfe 100644 (file)
@@ -118,7 +118,6 @@ define_blend_state_object(struct svga_context *svga,
       perRT[i].renderTargetWriteMask = bs->rt[i].writemask;
       perRT[i].logicOpEnable = 0;
       perRT[i].logicOp = SVGA3D_LOGICOP_COPY;
-      assert(perRT[i].srcBlend == perRT[0].srcBlend);
    }
 
    /* Loop in case command buffer is full and we need to flush and retry */
@@ -148,10 +147,10 @@ svga_create_blend_state(struct pipe_context *pipe,
    if (!blend)
       return NULL;
 
-   /* Find index of first target with blending enabled.  -1 means blending
-    * is not enabled at all.
+   /* Find index of first target with blending enabled.  If no blending is
+    * enabled at all, first_enabled will be zero.
     */
-   int first_enabled = -1;
+   unsigned first_enabled = 0;
    for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) {
       if (templ->rt[i].blend_enable) {
          first_enabled = i;
@@ -271,26 +270,26 @@ svga_create_blend_state(struct pipe_context *pipe,
          }
       }
       else {
-         /* Note: the vgpu10 device does not yet support independent blend
-          * terms per render target.  When blending is enabled, the blend
-          * terms must match for all targets.
+         /* Note: per-target blend terms are only supported for sm4_1
+          * device. For vgpu10 device, the blending terms must be identical
+          * for all targets (this is why we need the first_enabled index).
           */
-         if (first_enabled >= 0) {
-            /* use first enabled target's blending terms */
-            const struct pipe_rt_blend_state *rt = &templ->rt[first_enabled];
-
+         const unsigned j =
+            svga_have_sm4_1(svga) && templ->independent_blend_enable
+            ? i : first_enabled;
+         if (templ->independent_blend_enable || templ->rt[j].blend_enable) {
             blend->rt[i].srcblend =
-               svga_translate_blend_factor(svga, rt->rgb_src_factor);
+               svga_translate_blend_factor(svga, templ->rt[j].rgb_src_factor);
             blend->rt[i].dstblend =
-               svga_translate_blend_factor(svga, rt->rgb_dst_factor);
+               svga_translate_blend_factor(svga, templ->rt[j].rgb_dst_factor);
             blend->rt[i].blendeq =
-               svga_translate_blend_func(rt->rgb_func);
+               svga_translate_blend_func(templ->rt[j].rgb_func);
             blend->rt[i].srcblend_alpha =
-               svga_translate_blend_factor(svga, rt->alpha_src_factor);
+               svga_translate_blend_factor(svga, templ->rt[j].alpha_src_factor);
             blend->rt[i].dstblend_alpha =
-               svga_translate_blend_factor(svga, rt->alpha_dst_factor);
+               svga_translate_blend_factor(svga, templ->rt[j].alpha_dst_factor);
             blend->rt[i].blendeq_alpha =
-               svga_translate_blend_func(rt->alpha_func);
+               svga_translate_blend_func(templ->rt[j].alpha_func);
 
             if (blend->rt[i].srcblend_alpha != blend->rt[i].srcblend ||
                 blend->rt[i].dstblend_alpha != blend->rt[i].dstblend ||
index 23b165c37e9a29b0ad3383cf5502884d0cc26a34..1febe8733765af1f3d5f3bdbd9dae09ec6989b85 100644 (file)
@@ -344,6 +344,7 @@ svga_get_param(struct pipe_screen *screen, enum pipe_cap param)
       return 1;
 
    case PIPE_CAP_CUBE_MAP_ARRAY:
+   case PIPE_CAP_INDEP_BLEND_FUNC:
       return sws->have_sm4_1;
 
    /* Unsupported features */
@@ -351,7 +352,6 @@ svga_get_param(struct pipe_screen *screen, enum pipe_cap param)
    case PIPE_CAP_TEXTURE_MIRROR_CLAMP_TO_EDGE:
    case PIPE_CAP_SHADER_STENCIL_EXPORT:
    case PIPE_CAP_SEAMLESS_CUBE_MAP_PER_TEXTURE:
-   case PIPE_CAP_INDEP_BLEND_FUNC:
    case PIPE_CAP_TEXTURE_BARRIER:
    case PIPE_CAP_MAX_VERTEX_STREAMS:
    case PIPE_CAP_TGSI_CAN_COMPACT_CONSTANTS: