+/**
+ * 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 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 r600_context *rctx = (struct r600_context*)ctx;
+ struct compute_memory_pool *pool = rctx->screen->global_pool;
+ struct pipe_box new_src_box = *src_box;
+
+ if (src->bind & PIPE_BIND_GLOBAL) {
+ struct r600_resource_global *rsrc =
+ (struct r600_resource_global *)src;
+ struct compute_memory_item *item = rsrc->chunk;
+
+ if (is_item_in_pool(item)) {
+ new_src_box.x += 4 * item->start_in_dw;
+ src = (struct pipe_resource *)pool->bo;
+ } else {
+ if (item->real_buffer == NULL) {
+ item->real_buffer =
+ r600_compute_buffer_alloc_vram(pool->screen,
+ item->size_in_dw * 4);
+ }
+ src = (struct pipe_resource*)item->real_buffer;
+ }
+ }
+ if (dst->bind & PIPE_BIND_GLOBAL) {
+ struct r600_resource_global *rdst =
+ (struct r600_resource_global *)dst;
+ struct compute_memory_item *item = rdst->chunk;
+
+ if (is_item_in_pool(item)) {
+ dstx += 4 * item->start_in_dw;
+ dst = (struct pipe_resource *)pool->bo;
+ } else {
+ if (item->real_buffer == NULL) {
+ item->real_buffer =
+ r600_compute_buffer_alloc_vram(pool->screen,
+ item->size_in_dw * 4);
+ }
+ dst = (struct pipe_resource*)item->real_buffer;
+ }
+ }
+
+ r600_copy_buffer(ctx, dst, dstx, src, &new_src_box);
+}
+