[Mesa-dev] [PATCH 05/10] mesa: Work with bitmasks when en/dis-abling VAO arrays.

Mathias.Froehlich at gmx.net Mathias.Froehlich at gmx.net
Sat Nov 17 12:14:53 UTC 2018


From: Mathias Fröhlich <mathias.froehlich at web.de>

For enabling or disabling VAO arrays it is now possible to
change a set of arrays with a single call without the need to
iterate the attributes.
Make use of this technique in the vao module.

Signed-off-by: Mathias Fröhlich <Mathias.Froehlich at web.de>
---
 src/mesa/main/varray.c       | 38 +++++++++++++++++++-----------------
 src/mesa/main/varray.h       | 22 +++++++++++++++++++--
 src/mesa/vbo/vbo_exec_draw.c | 11 +++--------
 src/mesa/vbo/vbo_save_api.c  |  3 ++-
 4 files changed, 45 insertions(+), 29 deletions(-)

diff --git a/src/mesa/main/varray.c b/src/mesa/main/varray.c
index bcaa495647..a6d00c6ef9 100644
--- a/src/mesa/main/varray.c
+++ b/src/mesa/main/varray.c
@@ -1071,24 +1071,25 @@ _mesa_VertexAttribLPointer(GLuint index, GLint size, GLenum type,
 
 
 void
-_mesa_enable_vertex_array_attrib(struct gl_context *ctx,
-                                 struct gl_vertex_array_object *vao,
-                                 gl_vert_attrib attrib)
+_mesa_enable_vertex_array_attribs(struct gl_context *ctx,
+                                  struct gl_vertex_array_object *vao,
+                                  GLbitfield attrib_bits)
 {
-   assert(attrib < ARRAY_SIZE(vao->VertexAttrib));
+   assert((attrib_bits & ~VERT_BIT_ALL) == 0);
    assert(!vao->SharedAndImmutable);
 
-   const GLbitfield array_bit = VERT_BIT(attrib);
-   if ((vao->Enabled & array_bit) == 0) {
+   /* Only work on bits that are disabled */
+   attrib_bits &= ~vao->Enabled;
+   if (attrib_bits) {
       /* was disabled, now being enabled */
-      vao->Enabled |= array_bit;
-      vao->NewArrays |= array_bit;
+      vao->Enabled |= attrib_bits;
+      vao->NewArrays |= attrib_bits;
 
       if (vao == ctx->Array.VAO)
          ctx->NewState |= _NEW_ARRAY;
 
       /* Update the map mode if needed */
-      if (array_bit & (VERT_BIT_POS|VERT_BIT_GENERIC0))
+      if (attrib_bits & (VERT_BIT_POS|VERT_BIT_GENERIC0))
          update_attribute_map_mode(ctx, vao);
    }
 }
@@ -1157,24 +1158,25 @@ _mesa_EnableVertexArrayAttrib_no_error(GLuint vaobj, GLuint index)
 
 
 void
-_mesa_disable_vertex_array_attrib(struct gl_context *ctx,
-                                  struct gl_vertex_array_object *vao,
-                                  gl_vert_attrib attrib)
+_mesa_disable_vertex_array_attribs(struct gl_context *ctx,
+                                   struct gl_vertex_array_object *vao,
+                                   GLbitfield attrib_bits)
 {
-   assert(attrib < ARRAY_SIZE(vao->VertexAttrib));
+   assert((attrib_bits & ~VERT_BIT_ALL) == 0);
    assert(!vao->SharedAndImmutable);
 
-   const GLbitfield array_bit = VERT_BIT(attrib);
-   if (vao->Enabled & array_bit) {
+   /* Only work on bits that are enabled */
+   attrib_bits &= vao->Enabled;
+   if (attrib_bits) {
       /* was enabled, now being disabled */
-      vao->Enabled &= ~array_bit;
-      vao->NewArrays |= array_bit;
+      vao->Enabled &= ~attrib_bits;
+      vao->NewArrays |= attrib_bits;
 
       if (vao == ctx->Array.VAO)
          ctx->NewState |= _NEW_ARRAY;
 
       /* Update the map mode if needed */
-      if (array_bit & (VERT_BIT_POS|VERT_BIT_GENERIC0))
+      if (attrib_bits & (VERT_BIT_POS|VERT_BIT_GENERIC0))
          update_attribute_map_mode(ctx, vao);
    }
 }
diff --git a/src/mesa/main/varray.h b/src/mesa/main/varray.h
index a2477a7c6f..823e4f408b 100644
--- a/src/mesa/main/varray.h
+++ b/src/mesa/main/varray.h
@@ -62,15 +62,33 @@ _mesa_update_array_format(struct gl_context *ctx,
                           GLuint relativeOffset);
 
 extern void
+_mesa_enable_vertex_array_attribs(struct gl_context *ctx,
+                                 struct gl_vertex_array_object *vao,
+                                 GLbitfield attrib_bits);
+
+static inline void
 _mesa_enable_vertex_array_attrib(struct gl_context *ctx,
                                  struct gl_vertex_array_object *vao,
-                                 gl_vert_attrib attrib);
+                                 gl_vert_attrib attrib)
+{
+   assert(attrib < VERT_ATTRIB_MAX);
+   _mesa_enable_vertex_array_attribs(ctx, vao, VERT_BIT(attrib));
+}
 
 
 extern void
+_mesa_disable_vertex_array_attribs(struct gl_context *ctx,
+                                   struct gl_vertex_array_object *vao,
+                                   GLbitfield attrib_bits);
+
+static inline void
 _mesa_disable_vertex_array_attrib(struct gl_context *ctx,
                                   struct gl_vertex_array_object *vao,
-                                  gl_vert_attrib attrib);
+                                  gl_vert_attrib attrib)
+{
+   assert(attrib < VERT_ATTRIB_MAX);
+   _mesa_disable_vertex_array_attribs(ctx, vao, VERT_BIT(attrib));
+}
 
 
 extern void
diff --git a/src/mesa/vbo/vbo_exec_draw.c b/src/mesa/vbo/vbo_exec_draw.c
index db95dbbc34..87652d659d 100644
--- a/src/mesa/vbo/vbo_exec_draw.c
+++ b/src/mesa/vbo/vbo_exec_draw.c
@@ -191,11 +191,7 @@ vbo_exec_bind_arrays(struct gl_context *ctx)
    GLbitfield vao_enabled = _vbo_get_vao_enabled_from_vbo(mode, exec->vtx.enabled);
 
    /* At first disable arrays no longer needed */
-   GLbitfield mask = vao->Enabled & ~vao_enabled;
-   while (mask) {
-      const int vao_attr = u_bit_scan(&mask);
-      _mesa_disable_vertex_array_attrib(ctx, vao, vao_attr);
-   }
+   _mesa_disable_vertex_array_attribs(ctx, vao, VERT_BIT_ALL & ~vao_enabled);
    assert((~vao_enabled & vao->Enabled) == 0);
 
    /* Bind the buffer object */
@@ -208,7 +204,7 @@ vbo_exec_bind_arrays(struct gl_context *ctx)
     */
    const GLubyte *const vao_to_vbo_map = _vbo_attribute_alias_map[mode];
    /* Now set the enabled arrays */
-   mask = vao_enabled;
+   GLbitfield mask = vao_enabled;
    while (mask) {
       const int vao_attr = u_bit_scan(&mask);
       const GLubyte vbo_attr = vao_to_vbo_map[vao_attr];
@@ -222,12 +218,11 @@ vbo_exec_bind_arrays(struct gl_context *ctx)
       /* Set and enable */
       _vbo_set_attrib_format(ctx, vao, vao_attr, buffer_offset,
                              size, type, offset);
-      if ((vao->Enabled & VERT_BIT(vao_attr)) == 0)
-         _mesa_enable_vertex_array_attrib(ctx, vao, vao_attr);
 
       /* The vao is initially created with all bindings set to 0. */
       assert(vao->VertexAttrib[vao_attr].BufferBindingIndex == 0);
    }
+   _mesa_enable_vertex_array_attribs(ctx, vao, vao_enabled);
    assert(vao_enabled == vao->Enabled);
    assert(!_mesa_is_bufferobj(exec->vtx.bufferobj) ||
           (vao_enabled & ~vao->VertexAttribBufferMask) == 0);
diff --git a/src/mesa/vbo/vbo_save_api.c b/src/mesa/vbo/vbo_save_api.c
index a085729389..8dc03b9f77 100644
--- a/src/mesa/vbo/vbo_save_api.c
+++ b/src/mesa/vbo/vbo_save_api.c
@@ -514,8 +514,9 @@ update_vao(struct gl_context *ctx,
       _vbo_set_attrib_format(ctx, *vao, vao_attr, buffer_offset,
                              size[vbo_attr], type[vbo_attr], offset[vbo_attr]);
       _mesa_vertex_attrib_binding(ctx, *vao, vao_attr, 0);
-      _mesa_enable_vertex_array_attrib(ctx, *vao, vao_attr);
    }
+   _mesa_enable_vertex_array_attribs(ctx, *vao, vao_enabled);
+   assert(vao_enabled == (*vao)->Enabled);
    assert((vao_enabled & ~(*vao)->VertexAttribBufferMask) == 0);
 
    /* Finalize and freeze the VAO */
-- 
2.17.2



More information about the mesa-dev mailing list