mesa: don't flag _NEW_COLOR for st/mesa if possible
authorMarek Olšák <marek.olsak@amd.com>
Fri, 9 Jun 2017 23:46:34 +0000 (01:46 +0200)
committerMarek Olšák <marek.olsak@amd.com>
Wed, 21 Jun 2017 23:51:02 +0000 (01:51 +0200)
Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
src/mesa/main/blend.c
src/mesa/main/blend.h
src/mesa/main/enable.c
src/mesa/main/mtypes.h
src/mesa/state_tracker/st_context.c

index e042b5e8e6ac7d08ac96a4879609ce2a2a9b4db6..881e9c8a79fe9a8597470ad3ea7baa441e6b3145 100644 (file)
@@ -259,7 +259,8 @@ _mesa_BlendFuncSeparate( GLenum sfactorRGB, GLenum dfactorRGB,
       return;
    }
 
-   FLUSH_VERTICES(ctx, _NEW_COLOR);
+   FLUSH_VERTICES(ctx, ctx->DriverFlags.NewBlend ? 0 : _NEW_COLOR);
+   ctx->NewDriverState |= ctx->DriverFlags.NewBlend;
 
    for (buf = 0; buf < numBuffers; buf++) {
       ctx->Color.Blend[buf].SrcRGB = sfactorRGB;
@@ -331,7 +332,8 @@ blend_func_separatei(GLuint buf, GLenum sfactorRGB, GLenum dfactorRGB,
       return;
    }
 
-   FLUSH_VERTICES(ctx, _NEW_COLOR);
+   FLUSH_VERTICES(ctx, ctx->DriverFlags.NewBlend ? 0 : _NEW_COLOR);
+   ctx->NewDriverState |= ctx->DriverFlags.NewBlend;
 
    ctx->Color.Blend[buf].SrcRGB = sfactorRGB;
    ctx->Color.Blend[buf].DstRGB = dfactorRGB;
@@ -477,7 +479,7 @@ _mesa_BlendEquation( GLenum mode )
       return;
    }
 
-   FLUSH_VERTICES(ctx, _NEW_COLOR);
+   _mesa_flush_vertices_for_blend_state(ctx);
 
    for (buf = 0; buf < numBuffers; buf++) {
       ctx->Color.Blend[buf].EquationRGB = mode;
@@ -519,7 +521,7 @@ _mesa_BlendEquationiARB(GLuint buf, GLenum mode)
        ctx->Color.Blend[buf].EquationA == mode)
       return;  /* no change */
 
-   FLUSH_VERTICES(ctx, _NEW_COLOR);
+   _mesa_flush_vertices_for_blend_state(ctx);
    ctx->Color.Blend[buf].EquationRGB = mode;
    ctx->Color.Blend[buf].EquationA = mode;
    ctx->Color._BlendEquationPerBuffer = GL_TRUE;
@@ -585,7 +587,7 @@ _mesa_BlendEquationSeparate( GLenum modeRGB, GLenum modeA )
       return;
    }
 
-   FLUSH_VERTICES(ctx, _NEW_COLOR);
+   _mesa_flush_vertices_for_blend_state(ctx);
 
    for (buf = 0; buf < numBuffers; buf++) {
       ctx->Color.Blend[buf].EquationRGB = modeRGB;
@@ -607,7 +609,7 @@ blend_equation_separatei(struct gl_context *ctx, GLuint buf, GLenum modeRGB,
        ctx->Color.Blend[buf].EquationA == modeA)
       return;  /* no change */
 
-   FLUSH_VERTICES(ctx, _NEW_COLOR);
+   _mesa_flush_vertices_for_blend_state(ctx);
    ctx->Color.Blend[buf].EquationRGB = modeRGB;
    ctx->Color.Blend[buf].EquationA = modeA;
    ctx->Color._BlendEquationPerBuffer = GL_TRUE;
@@ -691,7 +693,8 @@ _mesa_BlendColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha )
    if (TEST_EQ_4V(tmp, ctx->Color.BlendColorUnclamped))
       return;
 
-   FLUSH_VERTICES(ctx, _NEW_COLOR);
+   FLUSH_VERTICES(ctx, ctx->DriverFlags.NewBlendColor ? 0 : _NEW_COLOR);
+   ctx->NewDriverState |= ctx->DriverFlags.NewBlendColor;
    COPY_4FV( ctx->Color.BlendColorUnclamped, tmp );
 
    ctx->Color.BlendColor[0] = CLAMP(tmp[0], 0.0F, 1.0F);
@@ -796,7 +799,8 @@ _mesa_LogicOp( GLenum opcode )
    if (ctx->Color.LogicOp == opcode)
       return;
 
-   FLUSH_VERTICES(ctx, _NEW_COLOR);
+   FLUSH_VERTICES(ctx, ctx->DriverFlags.NewLogicOp ? 0 : _NEW_COLOR);
+   ctx->NewDriverState |= ctx->DriverFlags.NewLogicOp;
    ctx->Color.LogicOp = opcode;
 
    if (ctx->Driver.LogicOpcode)
@@ -812,7 +816,8 @@ _mesa_IndexMask( GLuint mask )
    if (ctx->Color.IndexMask == mask)
       return;
 
-   FLUSH_VERTICES(ctx, _NEW_COLOR);
+   FLUSH_VERTICES(ctx, ctx->DriverFlags.NewColorMask ? 0 : _NEW_COLOR);
+   ctx->NewDriverState |= ctx->DriverFlags.NewColorMask;
    ctx->Color.IndexMask = mask;
 }
 
@@ -856,7 +861,8 @@ _mesa_ColorMask( GLboolean red, GLboolean green,
    for (i = 0; i < ctx->Const.MaxDrawBuffers; i++) {
       if (!TEST_EQ_4V(tmp, ctx->Color.ColorMask[i])) {
          if (!flushed) {
-            FLUSH_VERTICES(ctx, _NEW_COLOR);
+            FLUSH_VERTICES(ctx, ctx->DriverFlags.NewColorMask ? 0 : _NEW_COLOR);
+            ctx->NewDriverState |= ctx->DriverFlags.NewColorMask;
          }
          flushed = GL_TRUE;
          COPY_4UBV(ctx->Color.ColorMask[i], tmp);
@@ -898,7 +904,8 @@ _mesa_ColorMaski( GLuint buf, GLboolean red, GLboolean green,
    if (TEST_EQ_4V(tmp, ctx->Color.ColorMask[buf]))
       return;
 
-   FLUSH_VERTICES(ctx, _NEW_COLOR);
+   FLUSH_VERTICES(ctx, ctx->DriverFlags.NewColorMask ? 0 : _NEW_COLOR);
+   ctx->NewDriverState |= ctx->DriverFlags.NewColorMask;
    COPY_4UBV(ctx->Color.ColorMask[buf], tmp);
 }
 
index 54b9ce6e1b1f9098a07e8515a24179fbae189e65..675e50d3886062a8e4d56e74adcf88c7feed256c 100644 (file)
@@ -34,7 +34,9 @@
 
 
 #include "glheader.h"
+#include "context.h"
 #include "formats.h"
+#include "extensions.h"
 
 struct gl_context;
 struct gl_framebuffer;
@@ -136,4 +138,22 @@ _mesa_get_render_format(const struct gl_context *ctx, mesa_format format);
 extern void  
 _mesa_init_color( struct gl_context * ctx );
 
+
+static inline void
+_mesa_flush_vertices_for_blend_state(struct gl_context *ctx)
+{
+   /* The advanced blend mode needs _NEW_COLOR to update the state constant,
+    * so we have to set it. This is inefficient.
+    * This should only be done for states that affect the state constant.
+    * It shouldn't be done for other blend states.
+    */
+   if (_mesa_has_KHR_blend_equation_advanced(ctx) ||
+       !ctx->DriverFlags.NewBlend) {
+      FLUSH_VERTICES(ctx, _NEW_COLOR);
+   } else {
+      FLUSH_VERTICES(ctx, 0);
+   }
+   ctx->NewDriverState |= ctx->DriverFlags.NewBlend;
+}
+
 #endif
index 9dccf759ca1b26e71fff238dc96227e1f6934908..d33fc8b3dda8d192a9054887ccd1a9e2e2a7b6c8 100644 (file)
@@ -29,6 +29,7 @@
 
 
 #include "glheader.h"
+#include "blend.h"
 #include "clip.h"
 #include "context.h"
 #include "debug_output.h"
@@ -311,7 +312,7 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
             GLbitfield newEnabled =
                state * ((1 << ctx->Const.MaxDrawBuffers) - 1);
             if (newEnabled != ctx->Color.BlendEnabled) {
-               FLUSH_VERTICES(ctx, _NEW_COLOR);
+               _mesa_flush_vertices_for_blend_state(ctx);
                ctx->Color.BlendEnabled = newEnabled;
             }
          }
@@ -378,7 +379,8 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
       case GL_DITHER:
          if (ctx->Color.DitherFlag == state)
             return;
-         FLUSH_VERTICES(ctx, _NEW_COLOR);
+         FLUSH_VERTICES(ctx, ctx->DriverFlags.NewBlend ? 0 : _NEW_COLOR);
+         ctx->NewDriverState |= ctx->DriverFlags.NewBlend;
          ctx->Color.DitherFlag = state;
          break;
       case GL_FOG:
@@ -440,7 +442,8 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
             goto invalid_enum_error;
          if (ctx->Color.IndexLogicOpEnabled == state)
             return;
-         FLUSH_VERTICES(ctx, _NEW_COLOR);
+         FLUSH_VERTICES(ctx, ctx->DriverFlags.NewLogicOp ? 0 : _NEW_COLOR);
+         ctx->NewDriverState |= ctx->DriverFlags.NewLogicOp;
          ctx->Color.IndexLogicOpEnabled = state;
          break;
       case GL_CONSERVATIVE_RASTERIZATION_INTEL:
@@ -458,7 +461,8 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
             goto invalid_enum_error;
          if (ctx->Color.ColorLogicOpEnabled == state)
             return;
-         FLUSH_VERTICES(ctx, _NEW_COLOR);
+         FLUSH_VERTICES(ctx, ctx->DriverFlags.NewLogicOp ? 0 : _NEW_COLOR);
+         ctx->NewDriverState |= ctx->DriverFlags.NewLogicOp;
          ctx->Color.ColorLogicOpEnabled = state;
          break;
       case GL_MAP1_COLOR_4:
@@ -1040,7 +1044,8 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)
          CHECK_EXTENSION(KHR_blend_equation_advanced_coherent, cap);
          if (ctx->Color.BlendCoherent == state)
             return;
-         FLUSH_VERTICES(ctx, _NEW_COLOR);
+         FLUSH_VERTICES(ctx, ctx->DriverFlags.NewBlend ? 0 : _NEW_COLOR);
+         ctx->NewDriverState |= ctx->DriverFlags.NewBlend;
          ctx->Color.BlendCoherent = state;
          break;
 
@@ -1106,7 +1111,7 @@ _mesa_set_enablei(struct gl_context *ctx, GLenum cap,
          return;
       }
       if (((ctx->Color.BlendEnabled >> index) & 1) != state) {
-         FLUSH_VERTICES(ctx, _NEW_COLOR);
+         _mesa_flush_vertices_for_blend_state(ctx);
          if (state)
             ctx->Color.BlendEnabled |= (1 << index);
          else
index 4e870359dc8ee3818812307cfb206caa32e435bc..640202cbe7cb40cd9935d5d7a3490037d423addb 100644 (file)
@@ -4478,9 +4478,21 @@ struct gl_driver_flags
    /** gl_context::Color::Alpha* */
    uint64_t NewAlphaTest;
 
+   /** gl_context::Color::Blend/Dither */
+   uint64_t NewBlend;
+
+   /** gl_context::Color::BlendColor */
+   uint64_t NewBlendColor;
+
+   /** gl_context::Color::Color/Index */
+   uint64_t NewColorMask;
+
    /** gl_context::Depth */
    uint64_t NewDepth;
 
+   /** gl_context::Color::LogicOp/ColorLogicOp/IndexLogicOp */
+   uint64_t NewLogicOp;
+
    /** gl_context::Stencil */
    uint64_t NewStencil;
 };
index cdcc4ddaf48e38e6ab1dc0e169ff186ddb807c8c..2bd91530312cedd8d159a70e8116d2d063f14f4f 100644 (file)
@@ -236,9 +236,6 @@ st_invalidate_state(struct gl_context * ctx)
        st_user_clip_planes_enabled(ctx))
       st->dirty |= ST_NEW_CLIP_STATE;
 
-   if (new_state & _NEW_COLOR)
-      st->dirty |= ST_NEW_BLEND;
-
    if (new_state & _NEW_PIXEL)
       st->dirty |= ST_NEW_PIXEL_TRANSFER;
 
@@ -519,7 +516,11 @@ static void st_init_driver_flags(struct st_context *st)
    f->NewScissorRect = ST_NEW_SCISSOR;
    f->NewScissorTest = ST_NEW_SCISSOR | ST_NEW_RASTERIZER;
    f->NewAlphaTest = ST_NEW_DSA;
+   f->NewBlend = ST_NEW_BLEND;
+   f->NewBlendColor = ST_NEW_BLEND; /* TODO: add an atom for blend color */
+   f->NewColorMask = ST_NEW_BLEND;
    f->NewDepth = ST_NEW_DSA;
+   f->NewLogicOp = ST_NEW_BLEND;
    f->NewStencil = ST_NEW_DSA;
 }