tnl: Merge _tnl_vbo_draw_prims() into _tnl_draw_prims().
authorIago Toral Quiroga <itoral@igalia.com>
Tue, 8 Apr 2014 11:01:20 +0000 (13:01 +0200)
committerEric Anholt <eric@anholt.net>
Tue, 8 Apr 2014 22:10:10 +0000 (15:10 -0700)
This should help prevent situations where we render without proper index
bounds. For example: https://bugs.freedesktop.org/show_bug.cgi?id=59455

Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
src/mesa/drivers/dri/i965/brw_draw.c
src/mesa/drivers/dri/nouveau/nouveau_vbo_t.c
src/mesa/tnl/t_context.c
src/mesa/tnl/t_draw.c
src/mesa/tnl/tnl.h

index ef0f2737ca11aba0da07aa794168d199c87b7dad..0c131be806affa10662d07c2b484f2f11ded13e9 100644 (file)
@@ -550,17 +550,6 @@ void brw_draw_prims( struct gl_context *ctx,
       return;
    }
 
-   /* If we're going to have to upload any of the user's vertex arrays, then
-    * get the minimum and maximum of their index buffer so we know what range
-    * to upload.
-    */
-   if (!index_bounds_valid &&
-       (ctx->RenderMode != GL_RENDER || !vbo_all_varyings_in_vbos(arrays))) {
-      perf_debug("Scanning index buffer to compute index buffer bounds.  "
-                 "Use glDrawRangeElements() to avoid this.\n");
-      vbo_get_minmax_indices(ctx, prims, ib, &min_index, &max_index, nr_prims);
-   }
-
    /* Do GL_SELECT and GL_FEEDBACK rendering using swrast, even though it
     * won't support all the extensions we support.
     */
@@ -569,10 +558,21 @@ void brw_draw_prims( struct gl_context *ctx,
                  _mesa_lookup_enum_by_nr(ctx->RenderMode));
       _swsetup_Wakeup(ctx);
       _tnl_wakeup(ctx);
-      _tnl_draw_prims(ctx, arrays, prims, nr_prims, ib, min_index, max_index);
+      _tnl_draw_prims(ctx, prims, nr_prims, ib,
+                      index_bounds_valid, min_index, max_index, NULL, NULL);
       return;
    }
 
+   /* If we're going to have to upload any of the user's vertex arrays, then
+    * get the minimum and maximum of their index buffer so we know what range
+    * to upload.
+    */
+   if (!index_bounds_valid && !vbo_all_varyings_in_vbos(arrays)) {
+      perf_debug("Scanning index buffer to compute index buffer bounds.  "
+                 "Use glDrawRangeElements() to avoid this.\n");
+      vbo_get_minmax_indices(ctx, prims, ib, &min_index, &max_index, nr_prims);
+   }
+
    /* 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.
index dff947aa02828c2649a9e134bbaac693ddad74a0..c85acec12680a2f2889185c4896170d76f9083c3 100644 (file)
@@ -504,9 +504,9 @@ TAG(vbo_check_render_prims)(struct gl_context *ctx,
                                      tfb_vertcount, indirect);
 
        if (nctx->fallback == SWTNL)
-               _tnl_vbo_draw_prims(ctx, prims, nr_prims, ib,
-                                   index_bounds_valid, min_index, max_index,
-                                   tfb_vertcount, indirect);
+               _tnl_draw_prims(ctx, prims, nr_prims, ib,
+                               index_bounds_valid, min_index, max_index,
+                               tfb_vertcount, indirect);
 }
 
 void
index 134f699be5f55af93dbf4f5c850840366f31e093..eb5bae41da275725df16352e238551631e71d8a1 100644 (file)
@@ -93,7 +93,7 @@ _tnl_CreateContext( struct gl_context *ctx )
    }
 
    /* plug in the VBO drawing function */
-   vbo_set_draw_func(ctx, _tnl_vbo_draw_prims);
+   vbo_set_draw_func(ctx, _tnl_draw_prims);
 
    _math_init_transformation();
    _math_init_translate();
index 2755ae62d4928f222b24ba3bd9eea2236bb08baf..be3f059bb567cb80d93200af9bf8bda1326a1e8f 100644 (file)
@@ -411,7 +411,11 @@ static void unmap_vbos( struct gl_context *ctx,
 }
 
 
-void _tnl_vbo_draw_prims(struct gl_context *ctx,
+/* This is the main entrypoint into the slimmed-down software tnl
+ * module.  In a regular swtnl driver, this can be plugged straight
+ * into the vbo->Driver.DrawPrims() callback.
+ */
+void _tnl_draw_prims(struct gl_context *ctx,
                         const struct _mesa_prim *prim,
                         GLuint nr_prims,
                         const struct _mesa_index_buffer *ib,
@@ -420,33 +424,17 @@ void _tnl_vbo_draw_prims(struct gl_context *ctx,
                         GLuint max_index,
                         struct gl_transform_feedback_object *tfb_vertcount,
                         struct gl_buffer_object *indirect)
-{
-   const struct gl_client_array **arrays = ctx->Array._DrawArrays;
-
-   if (!index_bounds_valid)
-      vbo_get_minmax_indices(ctx, prim, ib, &min_index, &max_index, nr_prims);
-
-   _tnl_draw_prims(ctx, arrays, prim, nr_prims, ib, min_index, max_index);
-}
-
-/* This is the main entrypoint into the slimmed-down software tnl
- * module.  In a regular swtnl driver, this can be plugged straight
- * into the vbo->Driver.DrawPrims() callback.
- */
-void _tnl_draw_prims( struct gl_context *ctx,
-                     const struct gl_client_array *arrays[],
-                     const struct _mesa_prim *prim,
-                     GLuint nr_prims,
-                     const struct _mesa_index_buffer *ib,
-                     GLuint min_index,
-                     GLuint max_index)
 {
    TNLcontext *tnl = TNL_CONTEXT(ctx);
+   const struct gl_client_array **arrays = ctx->Array._DrawArrays;
    const GLuint TEST_SPLIT = 0;
    const GLint max = TEST_SPLIT ? 8 : tnl->vb.Size - MAX_CLIPPED_VERTICES;
    GLint max_basevertex = prim->basevertex;
    GLuint i;
 
+   if (!index_bounds_valid)
+      vbo_get_minmax_indices(ctx, prim, ib, &min_index, &max_index, nr_prims);
+
    /* Mesa core state should have been validated already */
    assert(ctx->NewState == 0x0);
 
@@ -471,7 +459,7 @@ void _tnl_draw_prims( struct gl_context *ctx,
        */
       vbo_rebase_prims( ctx, arrays, prim, nr_prims, ib, 
                        min_index, max_index,
-                       _tnl_vbo_draw_prims );
+                       _tnl_draw_prims );
       return;
    }
    else if ((GLint)max_index + max_basevertex > max) {
@@ -489,7 +477,7 @@ void _tnl_draw_prims( struct gl_context *ctx,
        */
       vbo_split_prims( ctx, arrays, prim, nr_prims, ib, 
                       0, max_index + prim->basevertex,
-                      _tnl_vbo_draw_prims,
+                      _tnl_draw_prims,
                       &limits );
    }
    else {
index 59a0ac38084ac0411484edf9ae3915bf25e45ed1..8c59ff9e58f9dba759e3ba61591a3126c163b70a 100644 (file)
@@ -77,15 +77,6 @@ struct _mesa_index_buffer;
 
 void
 _tnl_draw_prims( struct gl_context *ctx,
-                const struct gl_client_array *arrays[],
-                const struct _mesa_prim *prim,
-                GLuint nr_prims,
-                const struct _mesa_index_buffer *ib,
-                GLuint min_index,
-                GLuint max_index);
-
-void
-_tnl_vbo_draw_prims( struct gl_context *ctx,
                     const struct _mesa_prim *prim,
                     GLuint nr_prims,
                     const struct _mesa_index_buffer *ib,