[Mesa-dev] [PATCH 05/13] vbo: Implement method to track the inputs array.

Mathias.Froehlich at gmx.net Mathias.Froehlich at gmx.net
Thu Feb 15 19:55:17 UTC 2018


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

Provided the _DrawVAO and the derived state that is
maintained if we have the _DrawVAO set, implement a
method to incrementally update the array of
gl_vertex_array input pointers.

Signed-off-by: Mathias Fröhlich <Mathias.Froehlich at web.de>
---
 src/mesa/vbo/vbo.h         | 28 +++++++++++++++++
 src/mesa/vbo/vbo_context.c |  1 +
 src/mesa/vbo/vbo_exec.c    | 76 ++++++++++++++++++++++++++++++++++++++++++++++
 src/mesa/vbo/vbo_private.h |  2 ++
 4 files changed, 107 insertions(+)

diff --git a/src/mesa/vbo/vbo.h b/src/mesa/vbo/vbo.h
index d594ba8f6a..bb8ab7a745 100644
--- a/src/mesa/vbo/vbo.h
+++ b/src/mesa/vbo/vbo.h
@@ -254,6 +254,34 @@ vbo_sw_primitive_restart(struct gl_context *ctx,
                          const struct _mesa_index_buffer *ib,
                          struct gl_buffer_object *indirect);
 
+
+/**
+ * Utility that tracks and updates the current array entries.
+ */
+struct vbo_inputs
+{
+   const struct gl_vertex_array *inputs[VERT_ATTRIB_MAX];
+   GLbitfield current;
+   gl_vertex_processing_mode vertex_processing_mode;
+};
+
+
+/**
+ * Initialize inputs.
+ */
+void
+_vbo_array_init(struct vbo_inputs *inputs);
+
+
+/**
+ * Update the gl_vertex_array array inside the vbo_inputs structure
+ * provided the current _VPMode, the provided vao and
+ * the vao's enabled arrays filtered by the filter bitmask.
+ */
+void
+_vbo_update_inputs(struct gl_context *ctx, struct vbo_inputs *inputs);
+
+
 void GLAPIENTRY
 _es_Color4f(GLfloat r, GLfloat g, GLfloat b, GLfloat a);
 
diff --git a/src/mesa/vbo/vbo_context.c b/src/mesa/vbo/vbo_context.c
index 5bc6bf0acd..cc9cbffc51 100644
--- a/src/mesa/vbo/vbo_context.c
+++ b/src/mesa/vbo/vbo_context.c
@@ -234,6 +234,7 @@ _vbo_CreateContext(struct gl_context *ctx)
    init_legacy_currval(ctx);
    init_generic_currval(ctx);
    init_mat_currval(ctx);
+   _vbo_array_init(&vbo->array);
    vbo_set_indirect_draw_func(ctx, vbo_draw_indirect_prims);
 
    /* make sure all VBO_ATTRIB_ values can fit in an unsigned byte */
diff --git a/src/mesa/vbo/vbo_exec.c b/src/mesa/vbo/vbo_exec.c
index 372d0237aa..c5f01e3e4d 100644
--- a/src/mesa/vbo/vbo_exec.c
+++ b/src/mesa/vbo/vbo_exec.c
@@ -27,6 +27,7 @@
 
 
 #include "main/glheader.h"
+#include "main/arrayobj.h"
 #include "main/mtypes.h"
 #include "main/api_arrayelt.h"
 #include "main/vtxfmt.h"
@@ -240,3 +241,78 @@ vbo_merge_prims(struct _mesa_prim *p0, const struct _mesa_prim *p1)
    p0->count += p1->count;
    p0->end = p1->end;
 }
+
+
+void
+_vbo_array_init(struct vbo_inputs *inputs)
+{
+   inputs->current = 0;
+   inputs->vertex_processing_mode = VP_MODE_FF;
+}
+
+
+/**
+ * Update those gl_vertex_array array inside the vbo_inputs structure
+ * from the enable bits pointing into the provided vao.
+ */
+static inline void
+update_vao_inputs(struct gl_context *ctx,
+                  struct vbo_inputs *inputs, GLbitfield enable)
+{
+   const struct gl_vertex_array_object *vao = ctx->Array._DrawVAO;
+
+   /* Make sure we process only arrays enabled in the VAO */
+   assert((enable & ~_mesa_get_vao_vp_inputs(vao)) == 0);
+
+   /* Fill in the client arrays from the VAO */
+   const GLubyte *const map = _mesa_vao_attribute_map[vao->_AttributeMapMode];
+   const struct gl_vertex_array *array = vao->_VertexArray;
+   const struct gl_vertex_array **iarray = &inputs->inputs[0];
+   while (enable) {
+      const int attr = u_bit_scan(&enable);
+      iarray[attr] = &array[map[attr]];
+   }
+}
+
+
+/**
+ * Update those gl_vertex_array array inside the vbo_inputs structure
+ * from the current bits pointing into the current values.
+ */
+static inline void
+update_current_inputs(struct gl_context *ctx,
+                      struct vbo_inputs *inputs, GLbitfield current)
+{
+   gl_vertex_processing_mode mode = ctx->VertexProgram._VPMode;
+
+   /* All previously non current array pointers need update. */
+   GLbitfield mask = current & ~inputs->current;
+   /* On mode change, the slots aliasing with materials need update too */
+   if (mode != inputs->vertex_processing_mode)
+      mask |= current & VERT_BIT_MAT_ALL;
+
+   struct vbo_context *vbo = vbo_context(ctx);
+   const struct gl_vertex_array *const currval = &vbo->currval[0];
+   const struct gl_vertex_array **iarray = &inputs->inputs[0];
+   const GLubyte *const map = _vbo_attribute_alias_map[mode];
+   while (mask) {
+      const int attr = u_bit_scan(&mask);
+      iarray[attr] = &currval[map[attr]];
+   }
+
+   inputs->current = current;
+   inputs->vertex_processing_mode = mode;
+}
+
+
+void
+_vbo_update_inputs(struct gl_context *ctx, struct vbo_inputs *inputs)
+{
+   const GLbitfield enable = ctx->Array._DrawVAOEnabled;
+
+   /* Update array input pointers */
+   update_vao_inputs(ctx, inputs, enable);
+
+   /* The rest must be current inputs. */
+   update_current_inputs(ctx, inputs, ~enable & VERT_BIT_ALL);
+}
diff --git a/src/mesa/vbo/vbo_private.h b/src/mesa/vbo/vbo_private.h
index 49922892e5..545daa3b87 100644
--- a/src/mesa/vbo/vbo_private.h
+++ b/src/mesa/vbo/vbo_private.h
@@ -44,6 +44,8 @@ struct _mesa_prim;
 
 struct vbo_context {
    struct gl_vertex_array currval[VBO_ATTRIB_MAX];
+   /* The array of inputs used for _DrawVAO draws. */
+   struct vbo_inputs array;
 
    struct vbo_exec_context exec;
    struct vbo_save_context save;
-- 
2.14.3



More information about the mesa-dev mailing list