Module: Mesa
Branch: main
Commit: c00db0dbc867f48e02b86bc6cb8d49c59e534aa8
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=c00db0dbc867f48e02b86bc6cb8d49c59e534aa8

Author: Marek Olšák <[email protected]>
Date:   Sun Dec 18 15:56:50 2022 -0500

glthread: do vertex uploads if an index buffer is present for glDrawElements

glthread didn't implement uploading non-VBO vertices if indices were
in a buffer. This implements that.

Reviewed-by: Pierre-Eric Pelloux-Prayer <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20824>

---

 src/mesa/main/glthread_draw.c   | 31 ++++++++++++++++---------------
 src/mesa/vbo/vbo.h              |  7 +++++++
 src/mesa/vbo/vbo_minmax_index.c |  2 +-
 3 files changed, 24 insertions(+), 16 deletions(-)

diff --git a/src/mesa/main/glthread_draw.c b/src/mesa/main/glthread_draw.c
index 8907047906d..ba9a7399a66 100644
--- a/src/mesa/main/glthread_draw.c
+++ b/src/mesa/main/glthread_draw.c
@@ -934,22 +934,23 @@ draw_elements(GLenum mode, GLsizei count, GLenum type, 
const GLvoid *indices,
    unsigned index_size = get_index_size(type);
 
    if (need_index_bounds && !index_bounds_valid) {
-      /* Sync if indices come from a buffer and vertices come from memory
-       * and index bounds are not valid.
-       *
-       * We would have to map the indices to compute the index bounds, and
-       * for that we would have to sync anyway.
-       */
-      if (!has_user_indices)
-         goto sync;
-
       /* Compute the index bounds. */
-      min_index = ~0;
-      max_index = 0;
-      vbo_get_minmax_index_mapped(count, index_size,
-                                  ctx->GLThread._RestartIndex[index_size - 1],
-                                  ctx->GLThread._PrimitiveRestart, indices,
-                                  &min_index, &max_index);
+      if (has_user_indices) {
+         min_index = ~0;
+         max_index = 0;
+         vbo_get_minmax_index_mapped(count, index_size,
+                                     ctx->GLThread._RestartIndex[index_size - 
1],
+                                     ctx->GLThread._PrimitiveRestart, indices,
+                                     &min_index, &max_index);
+      } else {
+         /* Indices in a buffer. */
+         _mesa_glthread_finish_before(ctx, "DrawElements - need index bounds");
+         vbo_get_minmax_index(ctx, ctx->Array.VAO->IndexBufferObj,
+                              NULL, (intptr_t)indices, count, index_size,
+                              ctx->GLThread._PrimitiveRestart,
+                              ctx->GLThread._RestartIndex[index_size - 1],
+                              &min_index, &max_index);
+      }
       index_bounds_valid = true;
    }
 
diff --git a/src/mesa/vbo/vbo.h b/src/mesa/vbo/vbo.h
index 6f1676a22f0..f11824cdaa4 100644
--- a/src/mesa/vbo/vbo.h
+++ b/src/mesa/vbo/vbo.h
@@ -227,6 +227,13 @@ vbo_get_minmax_index_mapped(unsigned count, unsigned 
index_size,
                             const void *indices,
                             unsigned *min_index, unsigned *max_index);
 
+void
+vbo_get_minmax_index(struct gl_context *ctx, struct gl_buffer_object *obj,
+                     const void *ptr, GLintptr offset, unsigned count,
+                     unsigned index_size, bool primitive_restart,
+                     unsigned restart_index, GLuint *min_index,
+                     GLuint *max_index);
+
 bool
 vbo_get_minmax_indices_gallium(struct gl_context *ctx,
                                struct pipe_draw_info *info,
diff --git a/src/mesa/vbo/vbo_minmax_index.c b/src/mesa/vbo/vbo_minmax_index.c
index c0851fa7c5a..19df7807a76 100644
--- a/src/mesa/vbo/vbo_minmax_index.c
+++ b/src/mesa/vbo/vbo_minmax_index.c
@@ -319,7 +319,7 @@ vbo_get_minmax_index_mapped(unsigned count, unsigned 
index_size,
  * If primitive restart is enabled, we need to ignore restart
  * indexes when computing min/max.
  */
-static void
+void
 vbo_get_minmax_index(struct gl_context *ctx, struct gl_buffer_object *obj,
                      const void *ptr, GLintptr offset, unsigned count,
                      unsigned index_size, bool primitive_restart,

Reply via email to