Mesa (master): mesa: Add draw time validation for advanced blending modes.

Kenneth Graunke kwg at kemper.freedesktop.org
Fri Aug 26 03:05:54 UTC 2016


Module: Mesa
Branch: master
Commit: acf57fcf7ff7e60c3550da7b6dda7ad8b69195bd
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=acf57fcf7ff7e60c3550da7b6dda7ad8b69195bd

Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Sat Aug 20 12:51:03 2016 -0700

mesa: Add draw time validation for advanced blending modes.

v2: Add null checks (requested by Curro).

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
Reviewed-by: Francisco Jerez <currojerez at riseup.net>

---

 src/mesa/main/context.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)

diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c
index 4ff0979..8f9bbf1 100644
--- a/src/mesa/main/context.c
+++ b/src/mesa/main/context.c
@@ -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;
 }
 




More information about the mesa-commit mailing list