Mesa (master): tnl: Respect `start` when converting indices to GLuint

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Jan 20 00:47:10 UTC 2021


Module: Mesa
Branch: master
Commit: 376c8f750b9766d9704ced167dfaf00f521a92f4
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=376c8f750b9766d9704ced167dfaf00f521a92f4

Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Fri Jan 15 00:40:18 2021 -0800

tnl: Respect `start` when converting indices to GLuint

Prior to commit e99e7aa4c1ddd7b8c2c4388f4f8e4fa1955ca771 (mesa: switch
Draw(Range)Elements(BaseVertex) calls to DrawGallium), the indices
parameter of glDrawElements (an offset into the VBO) was handled by
setting ib->ptr.  With that commit, it instead began binding the
index buffer with offset 0, and adding the offset to draw->start,
which eventually becomes prim->start.

t_draw.c's bind_indices() was trying to convert the relevant section of
the index buffer to GLuints, but was failing to account for start, so
it nabbed the wrong portion of the index buffer.

Fixes: e99e7aa4c1d ("mesa: switch Draw(Range)Elements(BaseVertex) calls to DrawGallium")
Acked-by: Marek Olšák <marek.olsak at amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8522>

---

 src/mesa/tnl/t_draw.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/src/mesa/tnl/t_draw.c b/src/mesa/tnl/t_draw.c
index c28378cb148..bffab548a0f 100644
--- a/src/mesa/tnl/t_draw.c
+++ b/src/mesa/tnl/t_draw.c
@@ -341,6 +341,7 @@ static void bind_inputs(struct gl_context *ctx,
 /* Translate indices to GLuints and store in VB->Elts.
  */
 static void bind_indices(struct gl_context *ctx,
+                         unsigned start,
                          const struct _mesa_index_buffer *ib,
                          struct gl_buffer_object **bo,
                          GLuint *nr_bo)
@@ -376,21 +377,23 @@ static void bind_indices(struct gl_context *ctx,
       VB->Elts = (GLuint *) ptr;
    }
    else {
-      GLuint *elts = (GLuint *)get_space(ctx, ib->count * sizeof(GLuint));
+      GLuint *elts = (GLuint *)get_space(ctx, (start + ib->count) * sizeof(GLuint));
       VB->Elts = elts;
 
+      elts += start;
+
       if (ib->index_size_shift == 2) {
-         const GLuint *in = (GLuint *)ptr;
+         const GLuint *in = (GLuint *)ptr + start;
          for (i = 0; i < ib->count; i++)
             *elts++ = (GLuint)(*in++) + VB->Primitive[0].basevertex;
       }
       else if (ib->index_size_shift == 1) {
-         const GLushort *in = (GLushort *)ptr;
+         const GLushort *in = (GLushort *)ptr + start;
          for (i = 0; i < ib->count; i++)
             *elts++ = (GLuint)(*in++) + VB->Primitive[0].basevertex;
       }
       else {
-         const GLubyte *in = (GLubyte *)ptr;
+         const GLubyte *in = (GLubyte *)ptr + start;
          for (i = 0; i < ib->count; i++)
             *elts++ = (GLuint)(*in++) + VB->Primitive[0].basevertex;
       }
@@ -505,7 +508,8 @@ void _tnl_draw_prims(struct gl_context *ctx,
           */
          for (this_nr_prims = 1; i + this_nr_prims < nr_prims;
               this_nr_prims++) {
-            if (prim[i].basevertex != prim[i + this_nr_prims].basevertex)
+            if (prim[i].basevertex != prim[i + this_nr_prims].basevertex ||
+                prim[i].start != prim[i + this_nr_prims].start)
                break;
          }
 
@@ -517,7 +521,7 @@ void _tnl_draw_prims(struct gl_context *ctx,
             bind_prims(ctx, &prim[i], this_nr_prims);
             bind_inputs(ctx, arrays, max_index + prim[i].basevertex + 1,
                         bo, &nr_bo);
-            bind_indices(ctx, ib, bo, &nr_bo);
+            bind_indices(ctx, prim[i].start, ib, bo, &nr_bo);
 
             tnl->CurInstance = inst;
             TNL_CONTEXT(ctx)->Driver.RunPipeline(ctx);



More information about the mesa-commit mailing list