From 1b9511d7ce70a9f9cadd0c03bd0c916b88b6dd43 Mon Sep 17 00:00:00 2001 From: Tom Stellard Date: Thu, 14 Nov 2013 07:28:09 -0800 Subject: r600g/compute: Fix handling of global buffers in r600_resource_copy_region() Global buffers do not have an associate cs_buf handle, so we can't copy them using r600_copy_buffer() https://bugs.freedesktop.org/show_bug.cgi?id=64226 Reviewed-by: Marek Ol????k CC: "10.0" --- src/gallium/drivers/r600/r600_blit.c | 37 +++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'src/gallium/drivers/r600/r600_blit.c') diff --git a/src/gallium/drivers/r600/r600_blit.c b/src/gallium/drivers/r600/r600_blit.c index 124efa5d7df..fea33bccaa8 100644 --- a/src/gallium/drivers/r600/r600_blit.c +++ b/src/gallium/drivers/r600/r600_blit.c @@ -619,6 +619,36 @@ void r600_copy_buffer(struct pipe_context *ctx, struct pipe_resource *dst, unsig } } +/** + * Global buffers are not really resources, they are are actually offsets + * into a single global resource (r600_screen::global_pool). The means + * they don't have their own cs_buf handle, so they cannot be passed + * to r600_copy_buffer() and must be handled separately. + * + * XXX: It should be possible to implement this function using + * r600_copy_buffer() by passing the memory_pool resource as both src + * and dst and updating dstx and src_box to point to the correct offsets. + * This would likely perform better than the current implementation. + */ +static void r600_copy_global_buffer(struct pipe_context *ctx, + struct pipe_resource *dst, unsigned + dstx, struct pipe_resource *src, + const struct pipe_box *src_box) +{ + struct pipe_box dst_box; struct pipe_transfer *src_pxfer, + *dst_pxfer; + + u_box_1d(dstx, src_box->width, &dst_box); + void *src_ptr = ctx->transfer_map(ctx, src, 0, PIPE_TRANSFER_READ, + src_box, &src_pxfer); + void *dst_ptr = ctx->transfer_map(ctx, dst, 0, PIPE_TRANSFER_WRITE, + &dst_box, &dst_pxfer); + memcpy(dst_ptr, src_ptr, src_box->width); + + ctx->transfer_unmap(ctx, src_pxfer); + ctx->transfer_unmap(ctx, dst_pxfer); +} + static void r600_clear_buffer(struct pipe_context *ctx, struct pipe_resource *dst, unsigned offset, unsigned size, unsigned value) { @@ -671,7 +701,12 @@ static void r600_resource_copy_region(struct pipe_context *ctx, /* Handle buffers first. */ if (dst->target == PIPE_BUFFER && src->target == PIPE_BUFFER) { - r600_copy_buffer(ctx, dst, dstx, src, src_box); + if ((src->bind & PIPE_BIND_GLOBAL) || + (dst->bind & PIPE_BIND_GLOBAL)) { + r600_copy_global_buffer(ctx, dst, dstx, src, src_box); + } else { + r600_copy_buffer(ctx, dst, dstx, src, src_box); + } return; } -- cgit v1.2.3