vbo: expose helper function vbo_get_minmax_index_mapped for glthread
authorMarek Olšák <marek.olsak@amd.com>
Fri, 6 Mar 2020 21:47:52 +0000 (16:47 -0500)
committerMarek Olšák <marek.olsak@amd.com>
Mon, 6 Apr 2020 14:29:52 +0000 (10:29 -0400)
Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4466>

src/mesa/vbo/vbo.h
src/mesa/vbo/vbo_minmax_index.c

index 688e8fd83eb7ccdd666bbd94471110a7486f2c1c..c402caa74f1c04385e361a2440a6a0df87300bd5 100644 (file)
@@ -87,6 +87,12 @@ vbo_save_EndCallList(struct gl_context *ctx);
 void
 vbo_delete_minmax_cache(struct gl_buffer_object *bufferObj);
 
+void
+vbo_get_minmax_index_mapped(unsigned count, unsigned index_size,
+                            unsigned restartIndex, bool restart,
+                            const void *indices,
+                            unsigned *min_index, unsigned *max_index);
+
 void
 vbo_get_minmax_indices(struct gl_context *ctx, const struct _mesa_prim *prim,
                        const struct _mesa_index_buffer *ib,
index 34766642c6a0d8e17d3db5ac74ad003002a2e90f..ed3d5c607de8d36567ca895d4a035d611ad889d3 100644 (file)
@@ -227,47 +227,19 @@ out:
 }
 
 
-/**
- * Compute min and max elements by scanning the index buffer for
- * glDraw[Range]Elements() calls.
- * If primitive restart is enabled, we need to ignore restart
- * indexes when computing min/max.
- */
-static void
-vbo_get_minmax_index(struct gl_context *ctx,
-                     const struct _mesa_prim *prim,
-                     const struct _mesa_index_buffer *ib,
-                     GLuint *min_index, GLuint *max_index,
-                     const GLuint count)
+void
+vbo_get_minmax_index_mapped(unsigned count, unsigned index_size,
+                            unsigned restartIndex, bool restart,
+                            const void *indices,
+                            unsigned *min_index, unsigned *max_index)
 {
-   const GLboolean restart = ctx->Array._PrimitiveRestart;
-   const GLuint restartIndex =
-      ctx->Array._RestartIndex[(1 << ib->index_size_shift) - 1];
-   const char *indices;
-   GLuint i;
-   GLintptr offset = 0;
-
-   indices = (char *) ib->ptr + (prim->start << ib->index_size_shift);
-   if (ib->obj) {
-      GLsizeiptr size = MIN2(count << ib->index_size_shift, ib->obj->Size);
-
-      if (vbo_get_minmax_cached(ib->obj, 1 << ib->index_size_shift, (GLintptr) indices,
-                                count, min_index, max_index))
-         return;
-
-      offset = (GLintptr) indices;
-      indices = ctx->Driver.MapBufferRange(ctx, offset, size,
-                                           GL_MAP_READ_BIT, ib->obj,
-                                           MAP_INTERNAL);
-   }
-
-   switch (ib->index_size_shift) {
-   case 2: {
+   switch (index_size) {
+   case 4: {
       const GLuint *ui_indices = (const GLuint *)indices;
       GLuint max_ui = 0;
       GLuint min_ui = ~0U;
       if (restart) {
-         for (i = 0; i < count; i++) {
+         for (unsigned i = 0; i < count; i++) {
             if (ui_indices[i] != restartIndex) {
                if (ui_indices[i] > max_ui) max_ui = ui_indices[i];
                if (ui_indices[i] < min_ui) min_ui = ui_indices[i];
@@ -281,7 +253,7 @@ vbo_get_minmax_index(struct gl_context *ctx,
          }
          else
 #endif
-            for (i = 0; i < count; i++) {
+            for (unsigned i = 0; i < count; i++) {
                if (ui_indices[i] > max_ui) max_ui = ui_indices[i];
                if (ui_indices[i] < min_ui) min_ui = ui_indices[i];
             }
@@ -290,12 +262,12 @@ vbo_get_minmax_index(struct gl_context *ctx,
       *max_index = max_ui;
       break;
    }
-   case 1: {
+   case 2: {
       const GLushort *us_indices = (const GLushort *)indices;
       GLuint max_us = 0;
       GLuint min_us = ~0U;
       if (restart) {
-         for (i = 0; i < count; i++) {
+         for (unsigned i = 0; i < count; i++) {
             if (us_indices[i] != restartIndex) {
                if (us_indices[i] > max_us) max_us = us_indices[i];
                if (us_indices[i] < min_us) min_us = us_indices[i];
@@ -303,7 +275,7 @@ vbo_get_minmax_index(struct gl_context *ctx,
          }
       }
       else {
-         for (i = 0; i < count; i++) {
+         for (unsigned i = 0; i < count; i++) {
             if (us_indices[i] > max_us) max_us = us_indices[i];
             if (us_indices[i] < min_us) min_us = us_indices[i];
          }
@@ -312,12 +284,12 @@ vbo_get_minmax_index(struct gl_context *ctx,
       *max_index = max_us;
       break;
    }
-   case 0: {
+   case 1: {
       const GLubyte *ub_indices = (const GLubyte *)indices;
       GLuint max_ub = 0;
       GLuint min_ub = ~0U;
       if (restart) {
-         for (i = 0; i < count; i++) {
+         for (unsigned i = 0; i < count; i++) {
             if (ub_indices[i] != restartIndex) {
                if (ub_indices[i] > max_ub) max_ub = ub_indices[i];
                if (ub_indices[i] < min_ub) min_ub = ub_indices[i];
@@ -325,7 +297,7 @@ vbo_get_minmax_index(struct gl_context *ctx,
          }
       }
       else {
-         for (i = 0; i < count; i++) {
+         for (unsigned i = 0; i < count; i++) {
             if (ub_indices[i] > max_ub) max_ub = ub_indices[i];
             if (ub_indices[i] < min_ub) min_ub = ub_indices[i];
          }
@@ -337,6 +309,44 @@ vbo_get_minmax_index(struct gl_context *ctx,
    default:
       unreachable("not reached");
    }
+}
+
+
+/**
+ * Compute min and max elements by scanning the index buffer for
+ * glDraw[Range]Elements() calls.
+ * If primitive restart is enabled, we need to ignore restart
+ * indexes when computing min/max.
+ */
+static void
+vbo_get_minmax_index(struct gl_context *ctx,
+                     const struct _mesa_prim *prim,
+                     const struct _mesa_index_buffer *ib,
+                     GLuint *min_index, GLuint *max_index,
+                     const GLuint count)
+{
+   const GLboolean restart = ctx->Array._PrimitiveRestart;
+   const GLuint restartIndex =
+      ctx->Array._RestartIndex[(1 << ib->index_size_shift) - 1];
+   const char *indices;
+   GLintptr offset = 0;
+
+   indices = (char *) ib->ptr + (prim->start << ib->index_size_shift);
+   if (ib->obj) {
+      GLsizeiptr size = MIN2(count << ib->index_size_shift, ib->obj->Size);
+
+      if (vbo_get_minmax_cached(ib->obj, 1 << ib->index_size_shift, (GLintptr) indices,
+                                count, min_index, max_index))
+         return;
+
+      offset = (GLintptr) indices;
+      indices = ctx->Driver.MapBufferRange(ctx, offset, size,
+                                           GL_MAP_READ_BIT, ib->obj,
+                                           MAP_INTERNAL);
+   }
+
+   vbo_get_minmax_index_mapped(count, 1 << ib->index_size_shift, restartIndex,
+                               restart, indices, min_index, max_index);
 
    if (ib->obj) {
       vbo_minmax_cache_store(ctx, ib->obj, 1 << ib->index_size_shift, offset,