mesa: Move vbo draw functions into dd_function_table.
authorMathias Fröhlich <mathias.froehlich@web.de>
Fri, 16 Mar 2018 05:34:35 +0000 (06:34 +0100)
committerMathias Fröhlich <Mathias.Froehlich@gmx.net>
Thu, 22 Mar 2018 03:58:52 +0000 (04:58 +0100)
Move vbo draw functions into struct dd_function_table.
For now just wrap the underlying vbo functions.

Reviewed-by: Brian Paul <brianp@vmware.com>
Signed-off-by: Mathias Fröhlich <Mathias.Froehlich@web.de>
src/mesa/drivers/common/driverfuncs.c
src/mesa/main/dd.h
src/mesa/state_tracker/st_context.c
src/mesa/vbo/vbo.h
src/mesa/vbo/vbo_context.c
src/mesa/vbo/vbo_exec_array.c
src/mesa/vbo/vbo_exec_draw.c
src/mesa/vbo/vbo_primitive_restart.c
src/mesa/vbo/vbo_save_draw.c

index 8f2e3e075c82070efe1a8f9a04d72f6670e03d08..2ddfdb5efa8fbd8c2d57d303d11501a4447f9778 100644 (file)
@@ -55,6 +55,7 @@
 #include "tnl/tnl.h"
 #include "swrast/swrast.h"
 #include "swrast/s_renderbuffer.h"
+#include "vbo/vbo.h"
 
 #include "driverfuncs.h"
 #include "meta.h"
@@ -119,6 +120,10 @@ _mesa_init_driver_functions(struct dd_function_table *driver)
    /* ATI_fragment_shader */
    driver->NewATIfs = NULL;
 
+   /* Draw functions */
+   driver->Draw = _vbo_draw;
+   driver->DrawIndirect = _vbo_draw_indirect;
+
    /* simple state commands */
    driver->AlphaFunc = NULL;
    driver->BlendColor = NULL;
index 3e6a0418a2e65c1692e42b358b8fb326928d3ad7..09e9c41244ef7e150c2dc622b644f9c68bfc5e1d 100644 (file)
@@ -51,6 +51,8 @@ struct gl_texture_image;
 struct gl_texture_object;
 struct gl_memory_info;
 struct util_queue_monitoring;
+struct _mesa_prim;
+struct _mesa_index_buffer;
 
 /* GL_ARB_vertex_buffer_object */
 /* Modifies GL_MAP_UNSYNCHRONIZED_BIT to allow driver to fail (return
@@ -489,6 +491,85 @@ struct dd_function_table {
                            struct gl_shader_program *shader);
    /*@}*/
 
+
+   /**
+    * \name Draw functions.
+    */
+   /*@{*/
+   /**
+    * For indirect array drawing:
+    *
+    *    typedef struct {
+    *       GLuint count;
+    *       GLuint primCount;
+    *       GLuint first;
+    *       GLuint baseInstance; // in GL 4.2 and later, must be zero otherwise
+    *    } DrawArraysIndirectCommand;
+    *
+    * For indirect indexed drawing:
+    *
+    *    typedef struct {
+    *       GLuint count;
+    *       GLuint primCount;
+    *       GLuint firstIndex;
+    *       GLint  baseVertex;
+    *       GLuint baseInstance; // in GL 4.2 and later, must be zero otherwise
+    *    } DrawElementsIndirectCommand;
+    */
+
+   /**
+    * Draw a number of primitives.
+    * \param prims  array [nr_prims] describing what to draw (prim type,
+    *               vertex count, first index, instance count, etc).
+    * \param ib  index buffer for indexed drawing, NULL for array drawing
+    * \param index_bounds_valid  are min_index and max_index valid?
+    * \param min_index  lowest vertex index used
+    * \param max_index  highest vertex index used
+    * \param tfb_vertcount  if non-null, indicates which transform feedback
+    *                       object has the vertex count.
+    * \param tfb_stream  If called via DrawTransformFeedbackStream, specifies
+    *                    the vertex stream buffer from which to get the vertex
+    *                    count.
+    * \param indirect  If any prims are indirect, this specifies the buffer
+    *                  to find the "DrawArrays/ElementsIndirectCommand" data.
+    *                  This may be deprecated in the future
+    */
+   void (*Draw)(struct gl_context *ctx,
+                const struct _mesa_prim *prims, GLuint nr_prims,
+                const struct _mesa_index_buffer *ib,
+                GLboolean index_bounds_valid,
+                GLuint min_index, GLuint max_index,
+                struct gl_transform_feedback_object *tfb_vertcount,
+                unsigned tfb_stream, struct gl_buffer_object *indirect);
+
+
+   /**
+    * Draw a primitive, getting the vertex count, instance count, start
+    * vertex, etc. from a buffer object.
+    * \param mode  GL_POINTS, GL_LINES, GL_TRIANGLE_STRIP, etc.
+    * \param indirect_data  buffer to get "DrawArrays/ElementsIndirectCommand"
+    *                       data
+    * \param indirect_offset  offset of first primitive in indrect_data buffer
+    * \param draw_count  number of primitives to draw
+    * \param stride  stride, in bytes, between
+    *                "DrawArrays/ElementsIndirectCommand" objects
+    * \param indirect_draw_count_buffer  if non-NULL specifies a buffer to get
+    *                                    the real draw_count value.  Used for
+    *                                    GL_ARB_indirect_parameters.
+    * \param indirect_draw_count_offset  offset to the draw_count value in
+    *                                    indirect_draw_count_buffer
+    * \param ib  index buffer for indexed drawing, NULL otherwise.
+    */
+   void (*DrawIndirect)(struct gl_context *ctx, GLuint mode,
+                        struct gl_buffer_object *indirect_data,
+                        GLsizeiptr indirect_offset, unsigned draw_count,
+                        unsigned stride,
+                        struct gl_buffer_object *indirect_draw_count_buffer,
+                        GLsizeiptr indirect_draw_count_offset,
+                        const struct _mesa_index_buffer *ib);
+   /*@}*/
+
+
    /**
     * \name State-changing functions.
     *
index de30905dd2248dc23781e6f4e3d17bb1a875b337..90b7f9359a1d52d8b02d132bb70d18ff6f480aa5 100644 (file)
@@ -752,6 +752,10 @@ st_init_driver_functions(struct pipe_screen *screen,
    if (screen->get_param(screen, PIPE_CAP_STRING_MARKER))
       functions->EmitStringMarker = st_emit_string_marker;
 
+   /* For now call through these into the vbo_set_draw_func... */
+   functions->Draw = _vbo_draw;
+   functions->DrawIndirect = _vbo_draw_indirect;
+
    functions->Enable = st_Enable;
    functions->UpdateState = st_invalidate_state;
    functions->QueryMemoryInfo = st_query_memory_info;
index d6cf8e2afe5a839de053f2b4c6c29b184eea1ce6..42436e0fac91f32ba4097ff90d87a1d068863fe2 100644 (file)
@@ -214,6 +214,24 @@ struct split_limits
 };
 
 
+void
+_vbo_draw(struct gl_context *ctx, const struct _mesa_prim *prims,
+               GLuint nr_prims, const struct _mesa_index_buffer *ib,
+               GLboolean index_bounds_valid, GLuint min_index, GLuint max_index,
+               struct gl_transform_feedback_object *tfb_vertcount,
+               unsigned tfb_stream, struct gl_buffer_object *indirect);
+
+
+void
+_vbo_draw_indirect(struct gl_context *ctx, GLuint mode,
+                        struct gl_buffer_object *indirect_data,
+                        GLsizeiptr indirect_offset, unsigned draw_count,
+                        unsigned stride,
+                        struct gl_buffer_object *indirect_draw_count_buffer,
+                        GLsizeiptr indirect_draw_count_offset,
+                        const struct _mesa_index_buffer *ib);
+
+
 void
 vbo_split_prims(struct gl_context *ctx,
                 const struct gl_vertex_array *arrays,
index acb28d0293874275e0c621b0c8937395d94be5c9..bef2b47fdffa63b8b6591489d48dec544d7e3846 100644 (file)
@@ -307,3 +307,32 @@ vbo_set_indirect_draw_func(struct gl_context *ctx,
    struct vbo_context *vbo = vbo_context(ctx);
    vbo->draw_indirect_prims = func;
 }
+
+
+void
+_vbo_draw(struct gl_context *ctx, const struct _mesa_prim *prims,
+               GLuint nr_prims, const struct _mesa_index_buffer *ib,
+               GLboolean index_bounds_valid, GLuint min_index, GLuint max_index,
+               struct gl_transform_feedback_object *tfb_vertcount,
+               unsigned tfb_stream, struct gl_buffer_object *indirect)
+{
+   struct vbo_context *vbo = vbo_context(ctx);
+   vbo->draw_prims(ctx, prims, nr_prims, ib, index_bounds_valid,
+                   min_index, max_index, tfb_vertcount, tfb_stream, indirect);
+}
+
+
+void
+_vbo_draw_indirect(struct gl_context *ctx, GLuint mode,
+                        struct gl_buffer_object *indirect_data,
+                        GLsizeiptr indirect_offset, unsigned draw_count,
+                        unsigned stride,
+                        struct gl_buffer_object *indirect_draw_count_buffer,
+                        GLsizeiptr indirect_draw_count_offset,
+                        const struct _mesa_index_buffer *ib)
+{
+   struct vbo_context *vbo = vbo_context(ctx);
+   vbo->draw_indirect_prims(ctx, mode, indirect_data, indirect_offset,
+                            draw_count, stride, indirect_draw_count_buffer,
+                            indirect_draw_count_offset, ib);
+}
index 502993733657fca7d0d164e66940cc9bb45aa5e4..18b0032ae84af2983500b7f67d90fa35bff089b0 100644 (file)
@@ -395,7 +395,6 @@ vbo_draw_arrays(struct gl_context *ctx, GLenum mode, GLint start,
                 GLsizei count, GLuint numInstances, GLuint baseInstance,
                 GLuint drawID)
 {
-   struct vbo_context *vbo = vbo_context(ctx);
    struct _mesa_prim prim;
 
    if (skip_validated_draw(ctx))
@@ -417,8 +416,8 @@ vbo_draw_arrays(struct gl_context *ctx, GLenum mode, GLint start,
    prim.start = start;
    prim.count = count;
 
-   vbo->draw_prims(ctx, &prim, 1, NULL,
-                   GL_TRUE, start, start + count - 1, NULL, 0, NULL);
+   ctx->Driver.Draw(ctx, &prim, 1, NULL,
+                    GL_TRUE, start, start + count - 1, NULL, 0, NULL);
 
    if (MESA_DEBUG_FLAGS & DEBUG_ALWAYS_FLUSH) {
       _mesa_flush(ctx);
@@ -808,7 +807,6 @@ vbo_validated_drawrangeelements(struct gl_context *ctx, GLenum mode,
                                 GLint basevertex, GLuint numInstances,
                                 GLuint baseInstance)
 {
-   struct vbo_context *vbo = vbo_context(ctx);
    struct _mesa_index_buffer ib;
    struct _mesa_prim prim;
 
@@ -872,8 +870,8 @@ vbo_validated_drawrangeelements(struct gl_context *ctx, GLenum mode,
     * for the latter case elsewhere.
     */
 
-   vbo->draw_prims(ctx, &prim, 1, &ib,
-                   index_bounds_valid, start, end, NULL, 0, NULL);
+   ctx->Driver.Draw(ctx, &prim, 1, &ib,
+                    index_bounds_valid, start, end, NULL, 0, NULL);
 
    if (MESA_DEBUG_FLAGS & DEBUG_ALWAYS_FLUSH) {
       _mesa_flush(ctx);
@@ -1237,7 +1235,6 @@ vbo_validated_multidrawelements(struct gl_context *ctx, GLenum mode,
                                 const GLvoid * const *indices,
                                 GLsizei primcount, const GLint *basevertex)
 {
-   struct vbo_context *vbo = vbo_context(ctx);
    struct _mesa_index_buffer ib;
    struct _mesa_prim *prim;
    unsigned int index_type_size = sizeof_ib_type(type);
@@ -1323,8 +1320,8 @@ vbo_validated_multidrawelements(struct gl_context *ctx, GLenum mode,
             prim[i].basevertex = 0;
       }
 
-      vbo->draw_prims(ctx, prim, primcount, &ib,
-                      false, 0, ~0, NULL, 0, NULL);
+      ctx->Driver.Draw(ctx, prim, primcount, &ib,
+                       false, 0, ~0, NULL, 0, NULL);
    }
    else {
       /* render one prim at a time */
@@ -1353,7 +1350,7 @@ vbo_validated_multidrawelements(struct gl_context *ctx, GLenum mode,
          else
             prim[0].basevertex = 0;
 
-         vbo->draw_prims(ctx, prim, 1, &ib, false, 0, ~0, NULL, 0, NULL);
+         ctx->Driver.Draw(ctx, prim, 1, &ib, false, 0, ~0, NULL, 0, NULL);
       }
    }
 
@@ -1431,7 +1428,6 @@ vbo_draw_transform_feedback(struct gl_context *ctx, GLenum mode,
                             struct gl_transform_feedback_object *obj,
                             GLuint stream, GLuint numInstances)
 {
-   struct vbo_context *vbo = vbo_context(ctx);
    struct _mesa_prim prim;
 
    if (_mesa_is_no_error_enabled(ctx)) {
@@ -1477,7 +1473,7 @@ vbo_draw_transform_feedback(struct gl_context *ctx, GLenum mode,
     * (like in DrawArrays), but we have no way to know how many vertices
     * will be rendered. */
 
-   vbo->draw_prims(ctx, &prim, 1, NULL, GL_FALSE, 0, ~0, obj, stream, NULL);
+   ctx->Driver.Draw(ctx, &prim, 1, NULL, GL_FALSE, 0, ~0, obj, stream, NULL);
 
    if (MESA_DEBUG_FLAGS & DEBUG_ALWAYS_FLUSH) {
       _mesa_flush(ctx);
@@ -1561,11 +1557,9 @@ static void
 vbo_validated_drawarraysindirect(struct gl_context *ctx,
                                  GLenum mode, const GLvoid *indirect)
 {
-   struct vbo_context *vbo = vbo_context(ctx);
-
    vbo_bind_arrays(ctx);
 
-   vbo->draw_indirect_prims(ctx, mode,
+   ctx->Driver.DrawIndirect(ctx, mode,
                             ctx->DrawIndirectBuffer, (GLsizeiptr) indirect,
                             1 /* draw_count */ , 16 /* stride */ ,
                             NULL, 0, NULL);
@@ -1581,7 +1575,6 @@ vbo_validated_multidrawarraysindirect(struct gl_context *ctx,
                                       const GLvoid *indirect,
                                       GLsizei primcount, GLsizei stride)
 {
-   struct vbo_context *vbo = vbo_context(ctx);
    GLsizeiptr offset = (GLsizeiptr) indirect;
 
    if (primcount == 0)
@@ -1589,7 +1582,7 @@ vbo_validated_multidrawarraysindirect(struct gl_context *ctx,
 
    vbo_bind_arrays(ctx);
 
-   vbo->draw_indirect_prims(ctx, mode, ctx->DrawIndirectBuffer, offset,
+   ctx->Driver.DrawIndirect(ctx, mode, ctx->DrawIndirectBuffer, offset,
                             primcount, stride, NULL, 0, NULL);
 
    if (MESA_DEBUG_FLAGS & DEBUG_ALWAYS_FLUSH)
@@ -1602,7 +1595,6 @@ vbo_validated_drawelementsindirect(struct gl_context *ctx,
                                    GLenum mode, GLenum type,
                                    const GLvoid *indirect)
 {
-   struct vbo_context *vbo = vbo_context(ctx);
    struct _mesa_index_buffer ib;
 
    vbo_bind_arrays(ctx);
@@ -1612,7 +1604,7 @@ vbo_validated_drawelementsindirect(struct gl_context *ctx,
    ib.obj = ctx->Array.VAO->IndexBufferObj;
    ib.ptr = NULL;
 
-   vbo->draw_indirect_prims(ctx, mode,
+   ctx->Driver.DrawIndirect(ctx, mode,
                             ctx->DrawIndirectBuffer, (GLsizeiptr) indirect,
                             1 /* draw_count */ , 20 /* stride */ ,
                             NULL, 0, &ib);
@@ -1628,7 +1620,6 @@ vbo_validated_multidrawelementsindirect(struct gl_context *ctx,
                                         const GLvoid *indirect,
                                         GLsizei primcount, GLsizei stride)
 {
-   struct vbo_context *vbo = vbo_context(ctx);
    struct _mesa_index_buffer ib;
    GLsizeiptr offset = (GLsizeiptr) indirect;
 
@@ -1644,7 +1635,7 @@ vbo_validated_multidrawelementsindirect(struct gl_context *ctx,
    ib.obj = ctx->Array.VAO->IndexBufferObj;
    ib.ptr = NULL;
 
-   vbo->draw_indirect_prims(ctx, mode,
+   ctx->Driver.DrawIndirect(ctx, mode,
                             ctx->DrawIndirectBuffer, offset,
                             primcount, stride, NULL, 0, &ib);
 
@@ -1802,7 +1793,6 @@ vbo_validated_multidrawarraysindirectcount(struct gl_context *ctx,
                                            GLsizei maxdrawcount,
                                            GLsizei stride)
 {
-   struct vbo_context *vbo = vbo_context(ctx);
    GLsizeiptr offset = indirect;
 
    if (maxdrawcount == 0)
@@ -1810,7 +1800,7 @@ vbo_validated_multidrawarraysindirectcount(struct gl_context *ctx,
 
    vbo_bind_arrays(ctx);
 
-   vbo->draw_indirect_prims(ctx, mode,
+   ctx->Driver.DrawIndirect(ctx, mode,
                             ctx->DrawIndirectBuffer, offset,
                             maxdrawcount, stride,
                             ctx->ParameterBuffer, drawcount_offset, NULL);
@@ -1828,7 +1818,6 @@ vbo_validated_multidrawelementsindirectcount(struct gl_context *ctx,
                                              GLsizei maxdrawcount,
                                              GLsizei stride)
 {
-   struct vbo_context *vbo = vbo_context(ctx);
    struct _mesa_index_buffer ib;
    GLsizeiptr offset = (GLsizeiptr) indirect;
 
@@ -1844,7 +1833,7 @@ vbo_validated_multidrawelementsindirectcount(struct gl_context *ctx,
    ib.obj = ctx->Array.VAO->IndexBufferObj;
    ib.ptr = NULL;
 
-   vbo->draw_indirect_prims(ctx, mode,
+   ctx->Driver.DrawIndirect(ctx, mode,
                             ctx->DrawIndirectBuffer, offset,
                             maxdrawcount, stride,
                             ctx->ParameterBuffer, drawcount_offset, &ib);
index d02b33c8ee2bf70a47fd4a586e60136a57196b4c..628720b1d043aae6cb4f1f156241d45a562c4a5c 100644 (file)
@@ -398,14 +398,9 @@ vbo_exec_vtx_flush(struct vbo_exec_context *exec, GLboolean keepUnmapped)
             printf("%s %d %d\n", __func__, exec->vtx.prim_count,
                    exec->vtx.vert_count);
 
-         vbo_context(ctx)->draw_prims(ctx,
-                                      exec->vtx.prim,
-                                      exec->vtx.prim_count,
-                                      NULL,
-                                      GL_TRUE,
-                                      0,
-                                      exec->vtx.vert_count - 1,
-                                      NULL, 0, NULL);
+         ctx->Driver.Draw(ctx, exec->vtx.prim, exec->vtx.prim_count,
+                          NULL, GL_TRUE, 0, exec->vtx.vert_count - 1,
+                          NULL, 0, NULL);
 
          /* Get new storage -- unless asked not to. */
          if (!keepUnmapped)
index 33ad37c57338d5a57e3d2ee255ab7be3ea26e624..699b566dca20d97333f3cc6acecdbaa274b80fdb 100644 (file)
@@ -177,8 +177,6 @@ vbo_sw_primitive_restart(struct gl_context *ctx,
    GLuint sub_end_index;
    GLuint restart_index = _mesa_primitive_restart_index(ctx, ib->index_size);
    struct _mesa_prim temp_prim;
-   struct vbo_context *vbo = vbo_context(ctx);
-   vbo_draw_func draw_prims_func = vbo->draw_prims;
    GLboolean map_ib = ib->obj->Name && !ib->obj->Mappings[MAP_INTERNAL].Pointer;
    void *ptr;
 
@@ -249,13 +247,13 @@ vbo_sw_primitive_restart(struct gl_context *ctx,
             temp_prim.count = MIN2(sub_end_index, end_index) - temp_prim.start;
             if ((temp_prim.start == sub_prim->start) &&
                 (temp_prim.count == sub_prim->count)) {
-               draw_prims_func(ctx, &temp_prim, 1, ib,
-                               GL_TRUE, sub_prim->min_index, sub_prim->max_index,
-                               NULL, 0, NULL);
+               ctx->Driver.Draw(ctx, &temp_prim, 1, ib, GL_TRUE,
+                                sub_prim->min_index, sub_prim->max_index,
+                                NULL, 0, NULL);
             } else {
-               draw_prims_func(ctx, &temp_prim, 1, ib,
-                               GL_FALSE, -1, -1,
-                               NULL, 0, NULL);
+               ctx->Driver.Draw(ctx, &temp_prim, 1, ib,
+                                GL_FALSE, -1, -1,
+                                NULL, 0, NULL);
             }
          }
          if (sub_end_index >= end_index) {
index 69d28312d3f05a53cd03839231fb3e14789e8d72..280e16cb8115bc2e11a921c93026e4f99718b6f3 100644 (file)
@@ -215,13 +215,8 @@ vbo_save_playback_vertex_list(struct gl_context *ctx, void *data)
       if (node->vertex_count > 0) {
          GLuint min_index = _vbo_save_get_min_index(node);
          GLuint max_index = _vbo_save_get_max_index(node);
-         vbo->draw_prims(ctx,
-                         node->prims,
-                         node->prim_count,
-                         NULL,
-                         GL_TRUE,
-                         min_index, max_index,
-                         NULL, 0, NULL);
+         ctx->Driver.Draw(ctx, node->prims, node->prim_count, NULL, GL_TRUE,
+                          min_index, max_index, NULL, 0, NULL);
       }
    }