[Mesa-dev] [PATCH 08/11] i965: Remove the gl_vertex_array indirection.

Mathias.Froehlich at gmx.net Mathias.Froehlich at gmx.net
Sun Apr 1 18:13:08 UTC 2018


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

For now store binding and attrib in brw_vertex_element.
The i965 driver still provides lots of opportunity to make use
of the unique binding information in the VAO which is currently not
taken from the VAO.

Signed-off-by: Mathias Fröhlich <Mathias.Froehlich at web.de>
---
 src/mesa/drivers/dri/i965/brw_context.h       |  3 ++-
 src/mesa/drivers/dri/i965/brw_draw.c          | 25 ++++++++------------
 src/mesa/drivers/dri/i965/brw_draw_upload.c   | 33 +++++++++++++--------------
 src/mesa/drivers/dri/i965/genX_state_upload.c | 12 ++++------
 4 files changed, 32 insertions(+), 41 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_context.h b/src/mesa/drivers/dri/i965/brw_context.h
index f049d08649..b82fbfa57b 100644
--- a/src/mesa/drivers/dri/i965/brw_context.h
+++ b/src/mesa/drivers/dri/i965/brw_context.h
@@ -438,7 +438,8 @@ struct brw_vertex_buffer {
    GLuint step_rate;
 };
 struct brw_vertex_element {
-   const struct gl_vertex_array *glarray;
+   const struct gl_array_attributes *glattrib;
+   const struct gl_vertex_buffer_binding *glbinding;
 
    int buffer;
    bool is_dual_slot;
diff --git a/src/mesa/drivers/dri/i965/brw_draw.c b/src/mesa/drivers/dri/i965/brw_draw.c
index 8ee2535971..1a595d88cc 100644
--- a/src/mesa/drivers/dri/i965/brw_draw.c
+++ b/src/mesa/drivers/dri/i965/brw_draw.c
@@ -278,8 +278,7 @@ brw_emit_prim(struct brw_context *brw,
 
 
 static void
-brw_merge_inputs(struct brw_context *brw,
-                 const struct gl_vertex_array *arrays)
+brw_merge_inputs(struct brw_context *brw)
 {
    const struct gen_device_info *devinfo = &brw->screen->devinfo;
    const struct gl_context *ctx = &brw->ctx;
@@ -292,8 +291,10 @@ brw_merge_inputs(struct brw_context *brw,
    brw->vb.nr_buffers = 0;
 
    for (i = 0; i < VERT_ATTRIB_MAX; i++) {
-      brw->vb.inputs[i].buffer = -1;
-      brw->vb.inputs[i].glarray = &arrays[i];
+      struct brw_vertex_element *input = &brw->vb.inputs[i];
+      input->buffer = -1;
+      _mesa_draw_attrib_and_binding(ctx, i,
+                                    &input->glattrib, &input->glbinding);
    }
 
    if (devinfo->gen < 8 && !devinfo->is_haswell) {
@@ -306,7 +307,7 @@ brw_merge_inputs(struct brw_context *brw,
          uint8_t wa_flags = 0;
 
          i = u_bit_scan64(&mask);
-         glattrib = brw->vb.inputs[i].glarray->VertexAttrib;
+         glattrib = brw->vb.inputs[i].glattrib;
 
          switch (glattrib->Type) {
 
@@ -693,7 +694,6 @@ brw_postdraw_reconcile_align_wa_slices(struct brw_context *brw)
 
 static void
 brw_prepare_drawing(struct gl_context *ctx,
-                    const struct gl_vertex_array *arrays,
                     const struct _mesa_index_buffer *ib,
                     bool index_bounds_valid,
                     GLuint min_index,
@@ -746,7 +746,7 @@ brw_prepare_drawing(struct gl_context *ctx,
 
    /* Bind all inputs, derive varying and size information:
     */
-   brw_merge_inputs(brw, arrays);
+   brw_merge_inputs(brw);
 
    brw->ib.ib = ib;
    brw->ctx.NewDriverState |= BRW_NEW_INDICES;
@@ -780,7 +780,6 @@ brw_finish_drawing(struct gl_context *ctx)
  */
 static void
 brw_draw_single_prim(struct gl_context *ctx,
-                     const struct gl_vertex_array *arrays,
                      const struct _mesa_prim *prim,
                      unsigned prim_id,
                      struct brw_transform_feedback_object *xfb_obj,
@@ -811,7 +810,7 @@ brw_draw_single_prim(struct gl_context *ctx,
       brw->baseinstance = prim->base_instance;
       if (prim_id > 0) { /* For i == 0 we just did this before the loop */
          brw->ctx.NewDriverState |= BRW_NEW_VERTICES;
-         brw_merge_inputs(brw, arrays);
+         brw_merge_inputs(brw);
       }
    }
 
@@ -929,14 +928,12 @@ brw_draw_prims(struct gl_context *ctx,
 {
    unsigned i;
    struct brw_context *brw = brw_context(ctx);
-   const struct gl_vertex_array *arrays;
    int predicate_state = brw->predicate.state;
    struct brw_transform_feedback_object *xfb_obj =
       (struct brw_transform_feedback_object *) gl_xfb_obj;
 
    /* The initial pushdown of the inputs array into the drivers */
    _mesa_set_drawing_arrays(ctx, brw->vb.draw_arrays.inputs);
-   arrays = ctx->Array._DrawArrays;
    _vbo_update_inputs(ctx, &brw->vb.draw_arrays);
 
    if (!brw_check_conditional_render(brw))
@@ -972,8 +969,7 @@ brw_draw_prims(struct gl_context *ctx,
       index_bounds_valid = true;
    }
 
-   brw_prepare_drawing(ctx, arrays, ib, index_bounds_valid, min_index,
-                       max_index);
+   brw_prepare_drawing(ctx, ib, index_bounds_valid, min_index, max_index);
    /* Try drawing with the hardware, but don't do anything else if we can't
     * manage it.  swrast doesn't support our featureset, so we can't fall back
     * to it.
@@ -1010,8 +1006,7 @@ brw_draw_prims(struct gl_context *ctx,
          brw->predicate.state = BRW_PREDICATE_STATE_USE_BIT;
       }
 
-      brw_draw_single_prim(ctx, arrays, &prims[i], i, xfb_obj, stream,
-                           indirect);
+      brw_draw_single_prim(ctx, &prims[i], i, xfb_obj, stream, indirect);
    }
 
    brw_finish_drawing(ctx);
diff --git a/src/mesa/drivers/dri/i965/brw_draw_upload.c b/src/mesa/drivers/dri/i965/brw_draw_upload.c
index 344e2f2b4e..0204257017 100644
--- a/src/mesa/drivers/dri/i965/brw_draw_upload.c
+++ b/src/mesa/drivers/dri/i965/brw_draw_upload.c
@@ -23,6 +23,7 @@
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
 
+#include "main/arrayobj.h"
 #include "main/bufferobj.h"
 #include "main/context.h"
 #include "main/enums.h"
@@ -403,9 +404,8 @@ copy_array_to_vbo_array(struct brw_context *brw,
 			struct brw_vertex_buffer *buffer,
 			GLuint dst_stride)
 {
-   const struct gl_vertex_array *glarray = element->glarray;
-   const struct gl_vertex_buffer_binding *glbinding = glarray->BufferBinding;
-   const struct gl_array_attributes *glattrib = glarray->VertexAttrib;
+   const struct gl_vertex_buffer_binding *glbinding = element->glbinding;
+   const struct gl_array_attributes *glattrib = element->glattrib;
    const int src_stride = glbinding->Stride;
 
    /* If the source stride is zero, we just want to upload the current
@@ -512,15 +512,15 @@ brw_prepare_vertices(struct brw_context *brw)
 
    for (i = j = 0; i < brw->vb.nr_enabled; i++) {
       struct brw_vertex_element *input = brw->vb.enabled[i];
-      const struct gl_vertex_array *glarray = input->glarray;
-      const struct gl_vertex_buffer_binding *glbinding = glarray->BufferBinding;
-      const struct gl_array_attributes *glattrib = glarray->VertexAttrib;
+      const struct gl_vertex_buffer_binding *glbinding = input->glbinding;
+      const struct gl_array_attributes *glattrib = input->glattrib;
 
       if (_mesa_is_bufferobj(glbinding->BufferObj)) {
 	 struct intel_buffer_object *intel_buffer =
 	    intel_buffer_object(glbinding->BufferObj);
 
-         const uint32_t offset = glbinding->Offset + glattrib->RelativeOffset;
+         const uint32_t offset = _mesa_draw_binding_offset(glbinding) +
+            _mesa_draw_attributes_relative_offset(glattrib);
 
          /* Start with the worst case */
          uint32_t start = 0;
@@ -546,10 +546,11 @@ brw_prepare_vertices(struct brw_context *brw)
 	  */
 	 unsigned k;
 	 for (k = 0; k < i; k++) {
-	    const struct gl_vertex_array *other = brw->vb.enabled[k]->glarray;
-            const struct gl_vertex_buffer_binding *obind = other->BufferBinding;
-            const struct gl_array_attributes *oattrib = other->VertexAttrib;
-            const uint32_t ooffset = obind->Offset + oattrib->RelativeOffset;
+            struct brw_vertex_element *other = brw->vb.enabled[k];
+            const struct gl_vertex_buffer_binding *obind = other->glbinding;
+            const struct gl_array_attributes *oattrib = other->glattrib;
+            const uint32_t ooffset = _mesa_draw_binding_offset(obind) +
+               _mesa_draw_attributes_relative_offset(oattrib);
 	    if (glbinding->BufferObj == obind->BufferObj &&
 		glbinding->Stride == obind->Stride &&
 		glbinding->InstanceDivisor == obind->InstanceDivisor &&
@@ -652,14 +653,13 @@ brw_prepare_vertices(struct brw_context *brw)
 	  * interleaved.  First, upload the contents and set up upload[0].
 	  */
 	 copy_array_to_vbo_array(brw, upload[0], min_index, max_index,
-				 buffer, interleaved);
+	                         buffer, interleaved);
 	 buffer->offset -= delta * interleaved;
          buffer->size += delta * interleaved;
          buffer->step_rate = 0;
 
 	 for (i = 0; i < nr_uploads; i++) {
-            const struct gl_vertex_array *glarray = upload[i]->glarray;
-            const struct gl_array_attributes *glattrib = glarray->VertexAttrib;
+            const struct gl_array_attributes *glattrib = upload[i]->glattrib;
 	    /* Then, just point upload[i] at upload[0]'s buffer. */
             upload[i]->offset = ((const unsigned char *)glattrib->Ptr - ptr);
 	    upload[i]->buffer = j;
@@ -672,9 +672,8 @@ brw_prepare_vertices(struct brw_context *brw)
    /* Upload non-interleaved arrays */
    for (i = 0; i < nr_uploads; i++) {
       struct brw_vertex_buffer *buffer = &brw->vb.buffers[j];
-      const struct gl_vertex_array *glarray = upload[i]->glarray;
-      const struct gl_vertex_buffer_binding *glbinding = glarray->BufferBinding;
-      const struct gl_array_attributes *glattrib = glarray->VertexAttrib;
+      const struct gl_vertex_buffer_binding *glbinding = upload[i]->glbinding;
+      const struct gl_array_attributes *glattrib = upload[i]->glattrib;
       if (glbinding->InstanceDivisor == 0) {
          copy_array_to_vbo_array(brw, upload[i], min_index, max_index,
                                  buffer, glattrib->_ElementSize);
diff --git a/src/mesa/drivers/dri/i965/genX_state_upload.c b/src/mesa/drivers/dri/i965/genX_state_upload.c
index a69a496f1d..f4b757fd9c 100644
--- a/src/mesa/drivers/dri/i965/genX_state_upload.c
+++ b/src/mesa/drivers/dri/i965/genX_state_upload.c
@@ -553,8 +553,7 @@ genX(emit_vertices)(struct brw_context *brw)
     */
    for (unsigned i = 0; i < brw->vb.nr_enabled; i++) {
       struct brw_vertex_element *input = brw->vb.enabled[i];
-      const struct gl_vertex_array *glarray = input->glarray;
-      const struct gl_array_attributes *glattrib = glarray->VertexAttrib;
+      const struct gl_array_attributes *glattrib = input->glattrib;
       uint32_t format = brw_get_vertex_surface_type(brw, glattrib);
 
       if (uploads_needed(format, input->is_dual_slot) > 1)
@@ -648,8 +647,7 @@ genX(emit_vertices)(struct brw_context *brw)
    unsigned i;
    for (i = 0; i < brw->vb.nr_enabled; i++) {
       const struct brw_vertex_element *input = brw->vb.enabled[i];
-      const struct gl_vertex_array *glarray = input->glarray;
-      const struct gl_array_attributes *glattrib = glarray->VertexAttrib;
+      const struct gl_array_attributes *glattrib = input->glattrib;
       uint32_t format = brw_get_vertex_surface_type(brw, glattrib);
       uint32_t comp0 = VFCOMP_STORE_SRC;
       uint32_t comp1 = VFCOMP_STORE_SRC;
@@ -691,8 +689,7 @@ genX(emit_vertices)(struct brw_context *brw)
           * entry. */
          const unsigned offset = input->offset + c * 16;
 
-         const struct gl_vertex_array *glarray = input->glarray;
-         const struct gl_array_attributes *glattrib = glarray->VertexAttrib;
+         const struct gl_array_attributes *glattrib = input->glattrib;
          const int size = (GEN_GEN < 8 && is_passthru_format(format)) ?
             upload_format_size(upload_format) : glattrib->Size;
 
@@ -816,8 +813,7 @@ genX(emit_vertices)(struct brw_context *brw)
 
 #if GEN_GEN >= 6
    if (gen6_edgeflag_input) {
-      const struct gl_vertex_array *glarray = gen6_edgeflag_input->glarray;
-      const struct gl_array_attributes *glattrib = glarray->VertexAttrib;
+      const struct gl_array_attributes *glattrib = gen6_edgeflag_input->glattrib;
       const uint32_t format = brw_get_vertex_surface_type(brw, glattrib);
 
       struct GENX(VERTEX_ELEMENT_STATE) elem_state = {
-- 
2.14.3



More information about the mesa-dev mailing list