[Mesa-dev] [PATCH 8/8] mesa: rework _ae_invalidate_state() so that it just sets a dirty flag

Timothy Arceri tarceri at itsqueeze.com
Wed Jun 7 06:02:05 UTC 2017


---
 src/mesa/main/api_arrayelt.c | 26 +++++++++++++-------------
 src/mesa/main/api_arrayelt.h |  2 +-
 src/mesa/vbo/vbo_context.h   |  9 +++++----
 3 files changed, 19 insertions(+), 18 deletions(-)

diff --git a/src/mesa/main/api_arrayelt.c b/src/mesa/main/api_arrayelt.c
index c973c5e..4611e24 100644
--- a/src/mesa/main/api_arrayelt.c
+++ b/src/mesa/main/api_arrayelt.c
@@ -58,26 +58,27 @@ typedef void (GLAPIENTRY *attrib_func)( GLuint indx, const void *data );
 typedef struct {
    const struct gl_array_attributes *array;
    const struct gl_vertex_buffer_binding *binding;
    attrib_func func;
    GLuint index;
 } AEattrib;
 
 typedef struct {
    AEarray arrays[32];
    AEattrib attribs[VERT_ATTRIB_MAX + 1];
-   GLbitfield NewState;
 
    /* List of VBOs we need to map before executing ArrayElements */
    struct gl_buffer_object *vbo[VERT_ATTRIB_MAX];
    GLuint nr_vbos;
    GLboolean mapped_vbos;  /**< Any currently mapped VBOs? */
+
+   bool dirty_state;
 } AEcontext;
 
 
 /** Cast wrapper */
 static inline AEcontext *
 AE_CONTEXT(struct gl_context *ctx)
 {
    return (AEcontext *) ctx->aelt_context;
 }
 
@@ -89,21 +90,21 @@ AE_CONTEXT(struct gl_context *ctx)
  */
 static inline int
 TYPE_IDX(GLenum t)
 {
    return t == GL_DOUBLE ? 7 : t & 7;
 }
 
 
 bool
 _ae_is_state_dirty(struct gl_context *ctx) {
-   return AE_CONTEXT(ctx)->NewState;
+   return AE_CONTEXT(ctx)->dirty_state;
 }
 
 
 #define NUM_TYPES 8
 
 
 static const int ColorFuncs[2][NUM_TYPES] = {
    {
       _gloffset_Color3bv,
       _gloffset_Color3ubv,
@@ -1510,21 +1511,21 @@ _ae_create_context(struct gl_context *ctx)
    FogCoordFuncs[3] = -1;
    FogCoordFuncs[4] = -1;
    FogCoordFuncs[5] = -1;
    FogCoordFuncs[6] = _gloffset_FogCoordfvEXT;
    FogCoordFuncs[7] = _gloffset_FogCoorddv;
 
    ctx->aelt_context = calloc(1, sizeof(AEcontext));
    if (!ctx->aelt_context)
       return GL_FALSE;
 
-   AE_CONTEXT(ctx)->NewState = ~0;
+   AE_CONTEXT(ctx)->dirty_state = true;
    return GL_TRUE;
 }
 
 
 void
 _ae_destroy_context(struct gl_context *ctx)
 {
    if (AE_CONTEXT(ctx)) {
       free(ctx->aelt_context);
       ctx->aelt_context = NULL;
@@ -1689,38 +1690,38 @@ _ae_update_state(struct gl_context *ctx)
       aa++;
    }
 
    check_vbo(actx, vao->IndexBufferObj);
 
    assert(at - actx->attribs <= VERT_ATTRIB_MAX);
    assert(aa - actx->arrays < 32);
    at->func = NULL;  /* terminate the list */
    aa->offset = -1;  /* terminate the list */
 
-   actx->NewState = 0;
+   actx->dirty_state = false;
 }
 
 
 /**
  * Before replaying glArrayElements calls we need to map (for reading) any
  * VBOs referenced by the enabled vertex arrays.
  */
 void
 _ae_map_vbos(struct gl_context *ctx)
 {
    AEcontext *actx = AE_CONTEXT(ctx);
    GLuint i;
 
    if (actx->mapped_vbos)
       return;
 
-   if (actx->NewState)
+   if (actx->dirty_state)
       _ae_update_state(ctx);
 
    for (i = 0; i < actx->nr_vbos; i++)
       ctx->Driver.MapBufferRange(ctx, 0,
 				 actx->vbo[i]->Size,
 				 GL_MAP_READ_BIT,
 				 actx->vbo[i],
                                  MAP_INTERNAL);
 
    if (actx->nr_vbos)
@@ -1733,21 +1734,21 @@ _ae_map_vbos(struct gl_context *ctx)
  */
 void
 _ae_unmap_vbos(struct gl_context *ctx)
 {
    AEcontext *actx = AE_CONTEXT(ctx);
    GLuint i;
 
    if (!actx->mapped_vbos)
       return;
 
-   assert (!actx->NewState);
+   assert (!actx->dirty_state);
 
    for (i = 0; i < actx->nr_vbos; i++)
       ctx->Driver.UnmapBuffer(ctx, actx->vbo[i], MAP_INTERNAL);
 
    actx->mapped_vbos = GL_FALSE;
 }
 
 
 /**
  * Called via glArrayElement() and glDrawArrays().
@@ -1766,21 +1767,21 @@ _ae_ArrayElement(GLint elt)
    GLboolean do_map;
 
    /* If PrimitiveRestart is enabled and the index is the RestartIndex
     * then we call PrimitiveRestartNV and return.
     */
    if (ctx->Array.PrimitiveRestart && (elt == ctx->Array.RestartIndex)) {
       CALL_PrimitiveRestartNV((struct _glapi_table *)disp, ());
       return;
    }
 
-   if (actx->NewState) {
+   if (actx->dirty_state) {
       assert(!actx->mapped_vbos);
       _ae_update_state(ctx);
    }
 
    /* Determine if we need to map/unmap VBOs */
    do_map = actx->nr_vbos && !actx->mapped_vbos;
 
    if (do_map)
       _ae_map_vbos(ctx);
 
@@ -1801,37 +1802,36 @@ _ae_ArrayElement(GLint elt)
          + elt * aa->binding->Stride;
       CALL_by_offset(disp, (array_func), aa->offset, ((const void *) src));
    }
 
    if (do_map)
       _ae_unmap_vbos(ctx);
 }
 
 
 void
-_ae_invalidate_state(struct gl_context *ctx, GLbitfield new_state)
+_ae_invalidate_state(struct gl_context *ctx)
 {
    AEcontext *actx = AE_CONTEXT(ctx);
 
    /* Only interested in this subset of mesa state.  Need to prune
     * this down as both tnl/ and the drivers can raise statechanges
     * for arcane reasons in the middle of seemingly atomic operations
     * like DrawElements, over which we'd like to keep a known set of
     * arrays and vbo's mapped.
     *
     * Luckily, neither the drivers nor tnl muck with the state that
     * concerns us here:
     */
-   new_state &= _NEW_ARRAY | _NEW_PROGRAM;
-   if (new_state) {
-      assert(!actx->mapped_vbos);
-      actx->NewState |= new_state;
-   }
+   assert(ctx->NewState & (_NEW_ARRAY | _NEW_PROGRAM));
+
+   assert(!actx->mapped_vbos);
+   actx->dirty_state = true;
 }
 
 
 void
 _mesa_install_arrayelt_vtxfmt(struct _glapi_table *disp,
                               const GLvertexformat *vfmt)
 {
    SET_ArrayElement(disp, vfmt->ArrayElement);
 }
diff --git a/src/mesa/main/api_arrayelt.h b/src/mesa/main/api_arrayelt.h
index 9ae79a9..965e0ad 100644
--- a/src/mesa/main/api_arrayelt.h
+++ b/src/mesa/main/api_arrayelt.h
@@ -26,21 +26,21 @@
 
 #ifndef API_ARRAYELT_H
 #define API_ARRAYELT_H
 
 
 #include "main/mtypes.h"
 
 
 extern GLboolean _ae_create_context( struct gl_context *ctx );
 extern void _ae_destroy_context( struct gl_context *ctx );
-extern void _ae_invalidate_state( struct gl_context *ctx, GLbitfield new_state );
+extern void _ae_invalidate_state(struct gl_context *ctx);
 extern bool _ae_is_state_dirty(struct gl_context *ctx);
 extern void GLAPIENTRY _ae_ArrayElement( GLint elt );
 
 /* May optionally be called before a batch of element calls:
  */
 extern void _ae_map_vbos( struct gl_context *ctx );
 extern void _ae_unmap_vbos( struct gl_context *ctx );
 
 extern void
 _mesa_install_arrayelt_vtxfmt(struct _glapi_table *disp,
diff --git a/src/mesa/vbo/vbo_context.h b/src/mesa/vbo/vbo_context.h
index 0418643..2a762c8 100644
--- a/src/mesa/vbo/vbo_context.h
+++ b/src/mesa/vbo/vbo_context.h
@@ -91,28 +91,29 @@ static inline struct vbo_context *vbo_context(struct gl_context *ctx)
    return ctx->vbo_context;
 }
 
 
 static inline void
 vbo_exec_invalidate_state(struct gl_context *ctx)
 {
    struct vbo_context *vbo = vbo_context(ctx);
    struct vbo_exec_context *exec = &vbo->exec;
 
-   if (!exec->validating && ctx->NewState & (_NEW_PROGRAM | _NEW_ARRAY)) {
-      exec->array.recalculate_inputs = GL_TRUE;
+   if (ctx->NewState & (_NEW_PROGRAM | _NEW_ARRAY)) {
+      if (!exec->validating)
+         exec->array.recalculate_inputs = GL_TRUE;
+
+      _ae_invalidate_state(ctx);
    }
 
    if (ctx->NewState & _NEW_EVAL)
       exec->eval.recalculate_maps = GL_TRUE;
-
-   _ae_invalidate_state(ctx, ctx->NewState);
 }
 
 
 /**
  * Return VP_x token to indicate whether we're running fixed-function
  * vertex transformation, an NV vertex program or ARB vertex program/shader.
  */
 static inline enum vp_mode
 get_program_mode( struct gl_context *ctx )
 {
-- 
2.9.4



More information about the mesa-dev mailing list