gallivm: add coroutine pass manager support
[mesa.git] / src / gallium / auxiliary / util / u_index_modify.c
index f2c9db3caf1f8a830772a78f39dd5b48b87c3b1a..4e9349a7db66efb5af9f2274a94087567c9f9ade 100644 (file)
 /* Ubyte indices. */
 
 void util_shorten_ubyte_elts_to_userptr(struct pipe_context *context,
-                                       struct pipe_resource *elts,
+                                       const struct pipe_draw_info *info,
+                                        unsigned add_transfer_flags,
                                        int index_bias,
                                        unsigned start,
                                        unsigned count,
                                        void *out)
 {
-    struct pipe_transfer *src_transfer;
-    unsigned char *in_map;
+    struct pipe_transfer *src_transfer = NULL;
+    const unsigned char *in_map;
     unsigned short *out_map = out;
     unsigned i;
 
-    in_map = pipe_buffer_map(context, elts, PIPE_TRANSFER_READ, &src_transfer);
+    if (info->has_user_indices) {
+       in_map = info->index.user;
+    } else {
+       in_map = pipe_buffer_map(context, info->index.resource,
+                                PIPE_TRANSFER_READ |
+                                add_transfer_flags,
+                                &src_transfer);
+    }
     in_map += start;
 
     for (i = 0; i < count; i++) {
@@ -47,47 +55,32 @@ void util_shorten_ubyte_elts_to_userptr(struct pipe_context *context,
         out_map++;
     }
 
-    pipe_buffer_unmap(context, src_transfer);
-}
-
-void util_shorten_ubyte_elts(struct pipe_context *context,
-                            struct pipe_resource **elts,
-                            int index_bias,
-                            unsigned start,
-                            unsigned count)
-{
-    struct pipe_resource* new_elts;
-    unsigned short *out_map;
-    struct pipe_transfer *dst_transfer;
-
-    new_elts = pipe_buffer_create(context->screen,
-                                  PIPE_BIND_INDEX_BUFFER,
-                                  2 * count);
-
-    out_map = pipe_buffer_map(context, new_elts, PIPE_TRANSFER_WRITE,
-                              &dst_transfer);
-    util_shorten_ubyte_elts_to_userptr(context, *elts, index_bias,
-                                       start, count, out_map);
-    pipe_buffer_unmap(context, dst_transfer);
-
-    *elts = new_elts;
+    if (src_transfer)
+       pipe_buffer_unmap(context, src_transfer);
 }
 
-
 /* Ushort indices. */
 
 void util_rebuild_ushort_elts_to_userptr(struct pipe_context *context,
-                                        struct pipe_resource *elts,
+                                        const struct pipe_draw_info *info,
+                                         unsigned add_transfer_flags,
                                         int index_bias,
                                         unsigned start, unsigned count,
                                         void *out)
 {
     struct pipe_transfer *in_transfer = NULL;
-    unsigned short *in_map;
+    const unsigned short *in_map;
     unsigned short *out_map = out;
     unsigned i;
 
-    in_map = pipe_buffer_map(context, elts, PIPE_TRANSFER_READ, &in_transfer);
+    if (info->has_user_indices) {
+       in_map = info->index.user;
+    } else {
+       in_map = pipe_buffer_map(context, info->index.resource,
+                                PIPE_TRANSFER_READ |
+                                add_transfer_flags,
+                                &in_transfer);
+    }
     in_map += start;
 
     for (i = 0; i < count; i++) {
@@ -96,46 +89,32 @@ void util_rebuild_ushort_elts_to_userptr(struct pipe_context *context,
         out_map++;
     }
 
-    pipe_buffer_unmap(context, in_transfer);
+    if (in_transfer)
+       pipe_buffer_unmap(context, in_transfer);
 }
 
-void util_rebuild_ushort_elts(struct pipe_context *context,
-                             struct pipe_resource **elts,
-                             int index_bias,
-                             unsigned start, unsigned count)
-{
-    struct pipe_transfer *out_transfer = NULL;
-    struct pipe_resource *new_elts;
-    unsigned short *out_map;
-
-    new_elts = pipe_buffer_create(context->screen,
-                                  PIPE_BIND_INDEX_BUFFER,
-                                  2 * count);
-
-    out_map = pipe_buffer_map(context, new_elts,
-                              PIPE_TRANSFER_WRITE, &out_transfer);
-    util_rebuild_ushort_elts_to_userptr(context, *elts, index_bias,
-                                        start, count, out_map);
-    pipe_buffer_unmap(context, out_transfer);
-
-    *elts = new_elts;
-}
-
-
 /* Uint indices. */
 
 void util_rebuild_uint_elts_to_userptr(struct pipe_context *context,
-                                      struct pipe_resource *elts,
+                                      const struct pipe_draw_info *info,
+                                       unsigned add_transfer_flags,
                                       int index_bias,
                                       unsigned start, unsigned count,
                                       void *out)
 {
     struct pipe_transfer *in_transfer = NULL;
-    unsigned int *in_map;
+    const unsigned int *in_map;
     unsigned int *out_map = out;
     unsigned i;
 
-    in_map = pipe_buffer_map(context, elts, PIPE_TRANSFER_READ, &in_transfer);
+    if (info->has_user_indices) {
+       in_map = info->index.user;
+    } else {
+       in_map = pipe_buffer_map(context, info->index.resource,
+                                PIPE_TRANSFER_READ |
+                                add_transfer_flags,
+                                &in_transfer);
+    }
     in_map += start;
 
     for (i = 0; i < count; i++) {
@@ -144,27 +123,6 @@ void util_rebuild_uint_elts_to_userptr(struct pipe_context *context,
         out_map++;
     }
 
-    pipe_buffer_unmap(context, in_transfer);
-}
-
-void util_rebuild_uint_elts(struct pipe_context *context,
-                           struct pipe_resource **elts,
-                           int index_bias,
-                           unsigned start, unsigned count)
-{
-    struct pipe_transfer *out_transfer = NULL;
-    struct pipe_resource *new_elts;
-    unsigned int *out_map;
-
-    new_elts = pipe_buffer_create(context->screen,
-                                  PIPE_BIND_INDEX_BUFFER,
-                                  2 * count);
-
-    out_map = pipe_buffer_map(context, new_elts,
-                              PIPE_TRANSFER_WRITE, &out_transfer);
-    util_rebuild_uint_elts_to_userptr(context, *elts, index_bias,
-                                      start, count, out_map);
-    pipe_buffer_unmap(context, out_transfer);
-
-    *elts = new_elts;
+    if (in_transfer)
+       pipe_buffer_unmap(context, in_transfer);
 }