u_primconvert: Use u_upload_mgr for our little IB allocations.
authorEric Anholt <eric@anholt.net>
Sat, 30 Aug 2014 01:03:36 +0000 (18:03 -0700)
committerEric Anholt <eric@anholt.net>
Tue, 2 Sep 2014 20:55:15 +0000 (13:55 -0700)
tex-miplevel-selection was hammering my memory manager with primconverts
on individual quads.  This gets all those converted IBs packed into larger
IBs.

Reviewed-by: Rob Clark <robclark@freedesktop.org>
src/gallium/auxiliary/indices/u_primconvert.c

index c8d1d66a85888519d2870c8b917176a284095c7c..0b029c97f2c607b1ff13f4d81d3cd5915ef8f0a8 100644 (file)
@@ -45,6 +45,7 @@
 #include "util/u_draw.h"
 #include "util/u_inlines.h"
 #include "util/u_memory.h"
+#include "util/u_upload_mgr.h"
 
 #include "indices/u_indices.h"
 #include "indices/u_primconvert.h"
@@ -55,7 +56,7 @@ struct primconvert_context
    struct pipe_index_buffer saved_ib;
    uint32_t primtypes_mask;
    unsigned api_pv;
-   // TODO we could cache/recycle the indexbuf created to translate prims..
+   struct u_upload_mgr *upload;
 };
 
 
@@ -112,7 +113,7 @@ util_primconvert_draw_vbo(struct primconvert_context *pc,
    struct pipe_index_buffer *ib = &pc->saved_ib;
    struct pipe_index_buffer new_ib;
    struct pipe_draw_info new_info;
-   struct pipe_transfer *src_transfer = NULL, *dst_transfer = NULL;
+   struct pipe_transfer *src_transfer = NULL;
    u_translate_func trans_func;
    u_generate_func gen_func;
    const void *src = NULL;
@@ -144,14 +145,12 @@ util_primconvert_draw_vbo(struct primconvert_context *pc,
                         &gen_func);
    }
 
+   if (!pc->upload) {
+      pc->upload = u_upload_create(pc->pipe, 4096, 4, PIPE_BIND_INDEX_BUFFER);
+   }
 
-   new_ib.buffer = pipe_buffer_create(pc->pipe->screen,
-                                      PIPE_BIND_INDEX_BUFFER,
-                                      PIPE_USAGE_IMMUTABLE,
-                                      new_ib.index_size * new_info.count);
-   dst =
-      pipe_buffer_map(pc->pipe, new_ib.buffer, PIPE_TRANSFER_WRITE,
-                      &dst_transfer);
+   u_upload_alloc(pc->upload, 0, new_ib.index_size * new_info.count,
+                  &new_ib.offset, &new_ib.buffer, &dst);
 
    if (info->indexed) {
       trans_func(src, info->start, new_info.count, dst);
@@ -163,8 +162,7 @@ util_primconvert_draw_vbo(struct primconvert_context *pc,
    if (src_transfer)
       pipe_buffer_unmap(pc->pipe, src_transfer);
 
-   if (dst_transfer)
-      pipe_buffer_unmap(pc->pipe, dst_transfer);
+   u_upload_unmap(pc->upload);
 
    /* bind new index buffer: */
    pc->pipe->set_index_buffer(pc->pipe, &new_ib);