[Mesa-dev] [PATCH 2/3] gallium/u_vbuf: split u_vbuf_get_minmax_index function

Marek Olšák maraeo at gmail.com
Tue Jul 17 06:00:38 UTC 2018


From: Marek Olšák <marek.olsak at amd.com>

This will be used by indirect multidraws.
---
 src/gallium/auxiliary/util/u_vbuf.c | 54 +++++++++++++++++------------
 1 file changed, 31 insertions(+), 23 deletions(-)

diff --git a/src/gallium/auxiliary/util/u_vbuf.c b/src/gallium/auxiliary/util/u_vbuf.c
index 76a1d143d91..87b159ec1bf 100644
--- a/src/gallium/auxiliary/util/u_vbuf.c
+++ b/src/gallium/auxiliary/util/u_vbuf.c
@@ -1015,110 +1015,118 @@ static boolean u_vbuf_mapping_vertex_buffer_blocks(const struct u_vbuf *mgr)
     * We could query whether each buffer is busy, but that would
     * be way more costly than this. */
    return (mgr->ve->used_vb_mask &
            (~mgr->user_vb_mask &
             ~mgr->incompatible_vb_mask &
             mgr->ve->compatible_vb_mask_all &
             mgr->ve->noninstance_vb_mask_any &
             mgr->nonzero_stride_vb_mask)) != 0;
 }
 
-static void u_vbuf_get_minmax_index(struct pipe_context *pipe,
-                                    const struct pipe_draw_info *info,
-                                    int *out_min_index, int *out_max_index)
+static void
+u_vbuf_get_minmax_index_mapped(const struct pipe_draw_info *info,
+                               const void *indices, int *out_min_index,
+                               int *out_max_index)
 {
-   struct pipe_transfer *transfer = NULL;
-   const void *indices;
-   unsigned i;
-
-   if (info->has_user_indices) {
-      indices = (uint8_t*)info->index.user +
-                info->start * info->index_size;
-   } else {
-      indices = pipe_buffer_map_range(pipe, info->index.resource,
-                                      info->start * info->index_size,
-                                      info->count * info->index_size,
-                                      PIPE_TRANSFER_READ, &transfer);
-   }
-
    switch (info->index_size) {
    case 4: {
       const unsigned *ui_indices = (const unsigned*)indices;
       unsigned max_ui = 0;
       unsigned min_ui = ~0U;
       if (info->primitive_restart) {
-         for (i = 0; i < info->count; i++) {
+         for (unsigned i = 0; i < info->count; i++) {
             if (ui_indices[i] != info->restart_index) {
                if (ui_indices[i] > max_ui) max_ui = ui_indices[i];
                if (ui_indices[i] < min_ui) min_ui = ui_indices[i];
             }
          }
       }
       else {
-         for (i = 0; i < info->count; i++) {
+         for (unsigned i = 0; i < info->count; i++) {
             if (ui_indices[i] > max_ui) max_ui = ui_indices[i];
             if (ui_indices[i] < min_ui) min_ui = ui_indices[i];
          }
       }
       *out_min_index = min_ui;
       *out_max_index = max_ui;
       break;
    }
    case 2: {
       const unsigned short *us_indices = (const unsigned short*)indices;
       unsigned max_us = 0;
       unsigned min_us = ~0U;
       if (info->primitive_restart) {
-         for (i = 0; i < info->count; i++) {
+         for (unsigned i = 0; i < info->count; i++) {
             if (us_indices[i] != info->restart_index) {
                if (us_indices[i] > max_us) max_us = us_indices[i];
                if (us_indices[i] < min_us) min_us = us_indices[i];
             }
          }
       }
       else {
-         for (i = 0; i < info->count; i++) {
+         for (unsigned i = 0; i < info->count; i++) {
             if (us_indices[i] > max_us) max_us = us_indices[i];
             if (us_indices[i] < min_us) min_us = us_indices[i];
          }
       }
       *out_min_index = min_us;
       *out_max_index = max_us;
       break;
    }
    case 1: {
       const unsigned char *ub_indices = (const unsigned char*)indices;
       unsigned max_ub = 0;
       unsigned min_ub = ~0U;
       if (info->primitive_restart) {
-         for (i = 0; i < info->count; i++) {
+         for (unsigned i = 0; i < info->count; i++) {
             if (ub_indices[i] != info->restart_index) {
                if (ub_indices[i] > max_ub) max_ub = ub_indices[i];
                if (ub_indices[i] < min_ub) min_ub = ub_indices[i];
             }
          }
       }
       else {
-         for (i = 0; i < info->count; i++) {
+         for (unsigned i = 0; i < info->count; i++) {
             if (ub_indices[i] > max_ub) max_ub = ub_indices[i];
             if (ub_indices[i] < min_ub) min_ub = ub_indices[i];
          }
       }
       *out_min_index = min_ub;
       *out_max_index = max_ub;
       break;
    }
    default:
       assert(0);
       *out_min_index = 0;
       *out_max_index = 0;
    }
+}
+
+static void
+u_vbuf_get_minmax_index(struct pipe_context *pipe,
+                        const struct pipe_draw_info *info,
+                        int *out_min_index, int *out_max_index)
+{
+   struct pipe_transfer *transfer = NULL;
+   const void *indices;
+
+   if (info->has_user_indices) {
+      indices = (uint8_t*)info->index.user +
+                info->start * info->index_size;
+   } else {
+      indices = pipe_buffer_map_range(pipe, info->index.resource,
+                                      info->start * info->index_size,
+                                      info->count * info->index_size,
+                                      PIPE_TRANSFER_READ, &transfer);
+   }
+
+   u_vbuf_get_minmax_index_mapped(info, indices, out_min_index, out_max_index);
 
    if (transfer) {
       pipe_buffer_unmap(pipe, transfer);
    }
 }
 
 static void u_vbuf_set_driver_vertex_buffers(struct u_vbuf *mgr)
 {
    struct pipe_context *pipe = mgr->pipe;
    unsigned start_slot, count;
-- 
2.17.1



More information about the mesa-dev mailing list