[Mesa-dev] [PATCH 1/2] mesa: Keep a computed value for dual source blend func with each buffer.

Eric Anholt eric at anholt.net
Fri May 18 20:00:29 PDT 2012


The i965 driver needed this as well for hardware setup, so instead of
duplicating the logic, just save it off.
---
 src/mesa/main/blend.c   |   20 ++++++++++++++++++++
 src/mesa/main/context.c |   24 +++++++-----------------
 src/mesa/main/mtypes.h  |    5 +++++
 3 files changed, 32 insertions(+), 17 deletions(-)

diff --git a/src/mesa/main/blend.c b/src/mesa/main/blend.c
index bc446ed..5bc40a0 100644
--- a/src/mesa/main/blend.c
+++ b/src/mesa/main/blend.c
@@ -166,6 +166,24 @@ _mesa_BlendFunc( GLenum sfactor, GLenum dfactor )
    _mesa_BlendFuncSeparateEXT(sfactor, dfactor, sfactor, dfactor);
 }
 
+static GLboolean
+blend_factor_is_dual_src(GLenum factor)
+{
+   return (factor == GL_SRC1_COLOR ||
+	   factor == GL_SRC1_ALPHA ||
+	   factor == GL_ONE_MINUS_SRC1_COLOR ||
+	   factor == GL_ONE_MINUS_SRC1_ALPHA);
+}
+
+static void
+update_uses_dual_src(struct gl_context *ctx, int buf)
+{
+   ctx->Color.Blend[buf]._UsesDualSrc =
+      (blend_factor_is_dual_src(ctx->Color.Blend[buf].SrcRGB) ||
+       blend_factor_is_dual_src(ctx->Color.Blend[buf].DstRGB) ||
+       blend_factor_is_dual_src(ctx->Color.Blend[buf].SrcA) ||
+       blend_factor_is_dual_src(ctx->Color.Blend[buf].DstA));
+}
 
 /**
  * Set the separate blend source/dest factors for all draw buffers.
@@ -220,6 +238,7 @@ _mesa_BlendFuncSeparateEXT( GLenum sfactorRGB, GLenum dfactorRGB,
       ctx->Color.Blend[buf].DstRGB = dfactorRGB;
       ctx->Color.Blend[buf].SrcA = sfactorA;
       ctx->Color.Blend[buf].DstA = dfactorA;
+      update_uses_dual_src(ctx, buf);
    }
    ctx->Color._BlendFuncPerBuffer = GL_FALSE;
 
@@ -282,6 +301,7 @@ _mesa_BlendFuncSeparatei(GLuint buf, GLenum sfactorRGB, GLenum dfactorRGB,
    ctx->Color.Blend[buf].DstRGB = dfactorRGB;
    ctx->Color.Blend[buf].SrcA = sfactorA;
    ctx->Color.Blend[buf].DstA = dfactorA;
+   update_uses_dual_src(ctx, buf);
    ctx->Color._BlendFuncPerBuffer = GL_TRUE;
 
    if (ctx->Driver.BlendFuncSeparatei) {
diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c
index bafd250..2753f56 100644
--- a/src/mesa/main/context.c
+++ b/src/mesa/main/context.c
@@ -1700,13 +1700,6 @@ _mesa_set_mvp_with_dp4( struct gl_context *ctx,
    ctx->mvp_with_dp4 = flag;
 }
 
-static GLboolean
-blend_factor_is_dual_src(GLenum factor)
-{
-   return factor == GL_SRC1_COLOR || factor == GL_SRC1_ALPHA ||
-      factor == GL_ONE_MINUS_SRC1_COLOR || factor == GL_ONE_MINUS_SRC1_ALPHA;
-}
-
 /*
  * ARB_blend_func_extended - ERRORS section
  * "The error INVALID_OPERATION is generated by Begin or any procedure that
@@ -1719,16 +1712,13 @@ static GLboolean
 _mesa_check_blend_func_error(struct gl_context *ctx)
 {
    GLuint i;
-   for (i = 0; i < ctx->DrawBuffer->_NumColorDrawBuffers; i++) {
-      if (blend_factor_is_dual_src(ctx->Color.Blend[i].SrcRGB) ||
-          blend_factor_is_dual_src(ctx->Color.Blend[i].DstRGB) ||
-          blend_factor_is_dual_src(ctx->Color.Blend[i].SrcA) ||
-          blend_factor_is_dual_src(ctx->Color.Blend[i].DstA)) {
-         if (i >= ctx->Const.MaxDualSourceDrawBuffers) {
-            _mesa_error(ctx, GL_INVALID_OPERATION,
-                        "dual source blend on illegal attachment");
-            return GL_FALSE;
-         }
+   for (i = ctx->Const.MaxDualSourceDrawBuffers;
+	i < ctx->DrawBuffer->_NumColorDrawBuffers;
+	i++) {
+      if (ctx->Color.Blend[i]._UsesDualSrc) {
+	 _mesa_error(ctx, GL_INVALID_OPERATION,
+		     "dual source blend on illegal attachment");
+	 return GL_FALSE;
       }
    }
    return GL_TRUE;
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index c306ac6..b63eac6 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -755,6 +755,11 @@ struct gl_colorbuffer_attrib
       GLenum DstA;               /**< Alpha blend dest term */
       GLenum EquationRGB;        /**< GL_ADD, GL_SUBTRACT, etc. */
       GLenum EquationA;          /**< GL_ADD, GL_SUBTRACT, etc. */
+      /**
+       * Set if any blend factor uses SRC1.  Computed at the time blend factors
+       * get set.
+       */
+      GLboolean _UsesDualSrc;
    } Blend[MAX_DRAW_BUFFERS];
    /** Are the blend func terms currently different for each buffer/target? */
    GLboolean _BlendFuncPerBuffer;
-- 
1.7.10



More information about the mesa-dev mailing list