mesa: Add draw time validation for advanced blending modes.
authorKenneth Graunke <kenneth@whitecape.org>
Sat, 20 Aug 2016 19:51:03 +0000 (12:51 -0700)
committerKenneth Graunke <kenneth@whitecape.org>
Fri, 26 Aug 2016 02:22:10 +0000 (19:22 -0700)
v2: Add null checks (requested by Curro).

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Francisco Jerez <currojerez@riseup.net>
src/mesa/main/context.c

index 4ff0979c00bbea0c912207cea98bf275ae1604f4..8f9bbf1b7321f1517eeaf8953152bdd273688e25 100644 (file)
@@ -1876,6 +1876,58 @@ check_blend_func_error(struct gl_context *ctx)
         return false;
       }
    }
+
+   if (ctx->Color.BlendEnabled && ctx->Color._AdvancedBlendMode) {
+      /* The KHR_blend_equation_advanced spec says:
+       *
+       *    "If any non-NONE draw buffer uses a blend equation found in table
+       *     X.1 or X.2, the error INVALID_OPERATION is generated by Begin or
+       *     any operation that implicitly calls Begin (such as DrawElements)
+       *     if:
+       *
+       *       * the draw buffer for color output zero selects multiple color
+       *         buffers (e.g., FRONT_AND_BACK in the default framebuffer); or
+       *
+       *       * the draw buffer for any other color output is not NONE."
+       */
+      if (ctx->DrawBuffer->ColorDrawBuffer[0] == GL_FRONT_AND_BACK) {
+         _mesa_error(ctx, GL_INVALID_OPERATION,
+                     "advanced blending is active and draw buffer for color "
+                     "output zero selects multiple color buffers");
+         return false;
+      }
+
+      for (unsigned i = 1; i < ctx->DrawBuffer->_NumColorDrawBuffers; i++) {
+         if (ctx->DrawBuffer->ColorDrawBuffer[i] != GL_NONE) {
+            _mesa_error(ctx, GL_INVALID_OPERATION,
+                        "advanced blending is active with multiple color "
+                        "draw buffers");
+            return false;
+         }
+      }
+
+      /* The KHR_blend_equation_advanced spec says:
+       *
+       *    "Advanced blending equations require the use of a fragment shader
+       *     with a matching "blend_support" layout qualifier.  If the current
+       *     blend equation is found in table X.1 or X.2, and the active
+       *     fragment shader does not include the layout qualifier matching
+       *     the blend equation or "blend_support_all_equations", the error
+       *     INVALID_OPERATION is generated [...]"
+       */
+      const struct gl_shader_program *sh_prog =
+         ctx->_Shader->_CurrentFragmentProgram;
+      const GLbitfield blend_support = !sh_prog ? 0 :
+         sh_prog->_LinkedShaders[MESA_SHADER_FRAGMENT]->info.BlendSupport;
+
+      if ((blend_support & ctx->Color._AdvancedBlendMode) == 0) {
+         _mesa_error(ctx, GL_INVALID_OPERATION,
+                     "fragment shader does not allow advanced blending mode "
+                     "(%s)",
+                      _mesa_enum_to_string(ctx->Color.Blend[0].EquationRGB));
+      }
+   }
+
    return true;
 }