r600g: add a faster implementation of transfer_inline_write
authorMarek Olšák <maraeo@gmail.com>
Tue, 8 Feb 2011 16:36:48 +0000 (17:36 +0100)
committerMarek Olšák <maraeo@gmail.com>
Tue, 8 Feb 2011 16:47:00 +0000 (17:47 +0100)
u_default_transfer_inline_write uses util_copy_rect, which is kinda slow.

src/gallium/drivers/r600/r600_buffer.c

index 2a42783..183e347 100644 (file)
@@ -131,6 +131,30 @@ static void r600_transfer_destroy(struct pipe_context *ctx,
        util_slab_free(&rctx->pool_transfers, transfer);
 }
 
+static void r600_buffer_transfer_inline_write(struct pipe_context *pipe,
+                                              struct pipe_resource *resource,
+                                              unsigned level,
+                                              unsigned usage,
+                                              const struct pipe_box *box,
+                                              const void *data,
+                                              unsigned stride,
+                                              unsigned layer_stride)
+{
+       struct radeon *ws = (struct radeon*)pipe->winsys;
+       struct r600_resource_buffer *rbuffer = r600_buffer(resource);
+       uint8_t *map = NULL;
+
+       assert(rbuffer->b.user_ptr == NULL);
+
+       map = r600_bo_map(ws, rbuffer->r.bo,
+                         PIPE_TRANSFER_WRITE | PIPE_TRANSFER_DISCARD | usage,
+                         pipe);
+
+       memcpy(map + box->x, data, box->width);
+
+       if (rbuffer->r.bo)
+               r600_bo_unmap(ws, rbuffer->r.bo);
+}
 
 static const struct u_resource_vtbl r600_buffer_vtbl =
 {
@@ -142,7 +166,7 @@ static const struct u_resource_vtbl r600_buffer_vtbl =
        r600_buffer_transfer_map,               /* transfer_map */
        r600_buffer_transfer_flush_region,      /* transfer_flush_region */
        r600_buffer_transfer_unmap,             /* transfer_unmap */
-       u_default_transfer_inline_write         /* transfer_inline_write */
+       r600_buffer_transfer_inline_write       /* transfer_inline_write */
 };
 
 struct pipe_resource *r600_buffer_create(struct pipe_screen *screen,