vbo: add vbo_get_minmax_indices_gallium
authorMarek Olšák <marek.olsak@amd.com>
Tue, 3 Nov 2020 18:03:28 +0000 (13:03 -0500)
committerMarek Olšák <marek.olsak@amd.com>
Tue, 5 Jan 2021 00:22:33 +0000 (19:22 -0500)
to be used by st/mesa to get index bounds because it won't have _mesa_prim
with the new draw interface.

Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7679>

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

index 651f5af..5237e0f 100644 (file)
@@ -43,6 +43,8 @@ extern "C" {
 #endif
 
 struct gl_context;
+struct pipe_draw_info;
+struct pipe_draw_start_count;
 
 /**
  * Max number of primitives (number of glBegin/End pairs) per VBO.
@@ -230,6 +232,12 @@ vbo_get_minmax_indices(struct gl_context *ctx, const struct _mesa_prim *prim,
                        unsigned restart_index);
 
 void
+vbo_get_minmax_indices_gallium(struct gl_context *ctx,
+                               struct pipe_draw_info *info,
+                               const struct pipe_draw_start_count *draws,
+                               unsigned num_draws);
+
+void
 vbo_sw_primitive_restart(struct gl_context *ctx,
                          const struct _mesa_prim *prim,
                          GLuint nr_prims,
index 88a71b3..97412da 100644 (file)
@@ -34,6 +34,7 @@
 #include "x86/common_x86_asm.h"
 #include "util/hash_table.h"
 #include "util/u_memory.h"
+#include "pipe/p_state.h"
 
 
 struct minmax_cache_key {
@@ -393,3 +394,38 @@ vbo_get_minmax_indices(struct gl_context *ctx,
       *max_index = MAX2(*max_index, tmp_max);
    }
 }
+
+/**
+ * Same as vbo_get_minmax_index, but using gallium draw structures.
+ */
+void
+vbo_get_minmax_indices_gallium(struct gl_context *ctx,
+                               struct pipe_draw_info *info,
+                               const struct pipe_draw_start_count *draws,
+                               unsigned num_draws)
+{
+   info->min_index = ~0;
+   info->max_index = 0;
+
+   for (unsigned i = 0; i < num_draws; i++) {
+      struct pipe_draw_start_count draw = draws[i];
+
+      /* Do combination if possible to reduce map/unmap count */
+      while ((i + 1 < num_draws) &&
+             (draws[i].start + draws[i].count == draws[i+1].start)) {
+         draw.count += draws[i+1].count;
+         i++;
+      }
+
+      unsigned tmp_min, tmp_max;
+      vbo_get_minmax_index(ctx, info->has_user_indices ?
+                              NULL : info->index.gl_bo,
+                           info->index.user,
+                           (GLintptr)draw.start * info->index_size,
+                           draw.count, info->index_size,
+                           info->primitive_restart, info->restart_index,
+                           &tmp_min, &tmp_max);
+      info->min_index = MIN2(info->min_index, tmp_min);
+      info->max_index = MAX2(info->max_index, tmp_max);
+   }
+}