[Mesa-dev] [PATCH] r600g/compute: Fix handling of global buffers in r600_resource_copy_region()

Tom Stellard tom at stellard.net
Fri Nov 15 11:47:56 PST 2013


From: Tom Stellard <thomas.stellard at amd.com>

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

CC: "10.0" <mesa-stable at lists.freedesktop.org>
---
 src/gallium/drivers/r600/r600_blit.c | 32 +++++++++++++++++++++++++++++++-
 1 file changed, 31 insertions(+), 1 deletion(-)

diff --git a/src/gallium/drivers/r600/r600_blit.c b/src/gallium/drivers/r600/r600_blit.c
index 124efa5..86ff297 100644
--- a/src/gallium/drivers/r600/r600_blit.c
+++ b/src/gallium/drivers/r600/r600_blit.c
@@ -619,6 +619,31 @@ 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.
+ */
+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 +696,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;
 	}
 
-- 
1.8.1.4



More information about the mesa-dev mailing list