svga: fix blending regression
authorBrian Paul <brianp@vmware.com>
Thu, 22 Feb 2018 04:00:38 +0000 (21:00 -0700)
committerBrian Paul <brianp@vmware.com>
Fri, 2 Mar 2018 19:23:50 +0000 (12:23 -0700)
The earlier Mesa commit 3d06c8afb5 ("st/mesa: don't translate blend
state when it's disabled for a colorbuffer") subtly changed the
details of gallium's per-RT blend state.

In particular, when pipe_rt_blend_state[i].blend_enabled is true,
we have to get the src/dst blend terms from pipe_rt_blend_state[i],
not [0] as before.

We now have to scan the blend targets to find the first one that's
enabled (if any).  We have to use the index of that target for getting
the src/dst blend terms.  And note that we have to set identical blend
terms for all targets.

This fixes the Piglit fbo-drawbuffers2-blend test.  VMware bug 2063493.

Reviewed-by: Charmaine Lee <charmainel@vmware.com>
src/gallium/drivers/svga/svga_pipe_blend.c

index 04855fa7c95210ce26be5eca1cdeb9f8c01b43a7..6bb9d94369b57bdf909d05f79a5a698ca3ebd474 100644 (file)
@@ -148,6 +148,17 @@ 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.
+    */
+   int first_enabled = -1;
+   for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) {
+      if (templ->rt[i].blend_enable) {
+         first_enabled = i;
+         break;
+      }
+   }
+
    /* Fill in the per-rendertarget blend state.  We currently only
     * support independent blend enable and colormask per render target.
     */
@@ -260,24 +271,26 @@ svga_create_blend_state(struct pipe_context *pipe,
          }
       }
       else {
-         /* Note: the vgpu10 device does not yet support independent
-          * blend terms per render target.  Target[0] always specifies the
-          * blending terms.
+         /* 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.
           */
-         if (templ->independent_blend_enable || templ->rt[0].blend_enable) {
-            /* always use the 0th target's blending terms for now */
+         if (first_enabled >= 0) {
+            /* use first enabled target's blending terms */
+            const struct pipe_rt_blend_state *rt = &templ->rt[first_enabled];
+
             blend->rt[i].srcblend =
-               svga_translate_blend_factor(svga, templ->rt[0].rgb_src_factor);
+               svga_translate_blend_factor(svga, rt->rgb_src_factor);
             blend->rt[i].dstblend =
-               svga_translate_blend_factor(svga, templ->rt[0].rgb_dst_factor);
+               svga_translate_blend_factor(svga, rt->rgb_dst_factor);
             blend->rt[i].blendeq =
-               svga_translate_blend_func(templ->rt[0].rgb_func);
+               svga_translate_blend_func(rt->rgb_func);
             blend->rt[i].srcblend_alpha =
-               svga_translate_blend_factor(svga, templ->rt[0].alpha_src_factor);
+               svga_translate_blend_factor(svga, rt->alpha_src_factor);
             blend->rt[i].dstblend_alpha =
-               svga_translate_blend_factor(svga, templ->rt[0].alpha_dst_factor);
+               svga_translate_blend_factor(svga, rt->alpha_dst_factor);
             blend->rt[i].blendeq_alpha =
-               svga_translate_blend_func(templ->rt[0].alpha_func);
+               svga_translate_blend_func(rt->alpha_func);
 
             if (blend->rt[i].srcblend_alpha != blend->rt[i].srcblend ||
                 blend->rt[i].dstblend_alpha != blend->rt[i].dstblend ||