nouveau: accelerate buffer copies in resource_copy_region
authorChristoph Bumiller <e0425955@student.tuwien.ac.at>
Sat, 30 Mar 2013 14:55:20 +0000 (15:55 +0100)
committerChristoph Bumiller <e0425955@student.tuwien.ac.at>
Wed, 3 Apr 2013 10:54:43 +0000 (12:54 +0200)
src/gallium/drivers/nouveau/nouveau_buffer.c
src/gallium/drivers/nouveau/nouveau_buffer.h
src/gallium/drivers/nv30/nv30_miptree.c
src/gallium/drivers/nv50/nv50_surface.c
src/gallium/drivers/nvc0/nvc0_surface.c

index 5c9a44e368a120d1a79e9fa1b1829a52a40933d8..02bc6f0414632a8add372328d00314d707e6b34b 100644 (file)
@@ -2,6 +2,7 @@
 #include "util/u_inlines.h"
 #include "util/u_memory.h"
 #include "util/u_math.h"
+#include "util/u_surface.h"
 
 #include "nouveau_screen.h"
 #include "nouveau_context.h"
@@ -460,6 +461,39 @@ nouveau_buffer_transfer_unmap(struct pipe_context *pipe,
 }
 
 
+void
+nouveau_copy_buffer(struct nouveau_context *nv,
+                    struct nv04_resource *dst, unsigned dstx,
+                    struct nv04_resource *src, unsigned srcx, unsigned size)
+{
+   assert(dst->base.target == PIPE_BUFFER && src->base.target == PIPE_BUFFER);
+
+   if (likely(dst->domain) && likely(src->domain)) {
+      nv->copy_data(nv,
+                    dst->bo, dst->offset + dstx, dst->domain,
+                    src->bo, src->offset + srcx, src->domain, size);
+
+      dst->status |= NOUVEAU_BUFFER_STATUS_GPU_WRITING;
+      nouveau_fence_ref(nv->screen->fence.current, &dst->fence);
+      nouveau_fence_ref(nv->screen->fence.current, &dst->fence_wr);
+
+      src->status |= NOUVEAU_BUFFER_STATUS_GPU_READING;
+      nouveau_fence_ref(nv->screen->fence.current, &src->fence);
+   } else {
+      struct pipe_box src_box;
+      src_box.x = srcx;
+      src_box.y = 0;
+      src_box.z = 0;
+      src_box.width = size;
+      src_box.height = 1;
+      src_box.depth = 1;
+      util_resource_copy_region(&nv->pipe,
+                                &dst->base, 0, dstx, 0, 0,
+                                &src->base, 0, &src_box);
+   }
+}
+
+
 void *
 nouveau_resource_map_offset(struct nouveau_context *nv,
                             struct nv04_resource *res, uint32_t offset,
index aafc84293a7b10997f3a27890c5f2414d577d20b..fd7a3f1287f15e81708b8cf6ee9b67be3e978f5d 100644 (file)
@@ -49,9 +49,10 @@ struct nv04_resource {
 void
 nouveau_buffer_release_gpu_storage(struct nv04_resource *);
 
-boolean
-nouveau_buffer_download(struct nouveau_context *, struct nv04_resource *,
-                        unsigned start, unsigned size);
+void
+nouveau_copy_buffer(struct nouveau_context *,
+                    struct nv04_resource *dst, unsigned dst_pos,
+                    struct nv04_resource *src, unsigned src_pos, unsigned size);
 
 boolean
 nouveau_buffer_migrate(struct nouveau_context *,
index d4dcacb85069fe14d6d9b084d6510ea8736e830a..f536287bbbb30b088c4791bb77199112e9ff52ae 100644 (file)
@@ -130,8 +130,9 @@ nv30_resource_copy_region(struct pipe_context *pipe,
    struct nv30_rect src, dst;
 
    if (dstres->target == PIPE_BUFFER && srcres->target == PIPE_BUFFER) {
-      util_resource_copy_region(pipe, dstres, dst_level, dstx, dsty, dstz,
-                                      srcres, src_level, src_box);
+      nouveau_copy_buffer(&nv30->base,
+                          nv04_resource(dstres), dstx,
+                          nv04_resource(srcres), src_box->x, src_box->width);
       return;
    }
 
index b29a736ae3cc7587092c82eef3fda4a5a1d1a731..51e702c7a3f137ca35784184f5c8df2725547037 100644 (file)
@@ -200,10 +200,10 @@ nv50_resource_copy_region(struct pipe_context *pipe,
    boolean m2mf;
    unsigned dst_layer = dstz, src_layer = src_box->z;
 
-   /* Fallback for buffers. */
    if (dst->target == PIPE_BUFFER && src->target == PIPE_BUFFER) {
-      util_resource_copy_region(pipe, dst, dst_level, dstx, dsty, dstz,
-                                src, src_level, src_box);
+      nouveau_copy_buffer(&nv50->base,
+                          nv04_resource(dst), dstx,
+                          nv04_resource(src), src_box->x, src_box->width);
       return;
    }
 
index 95f3ff436799544c046548f86b758153df9b780b..de71127072b4b69b65407623587266a323ffa37d 100644 (file)
@@ -201,10 +201,10 @@ nvc0_resource_copy_region(struct pipe_context *pipe,
    boolean m2mf;
    unsigned dst_layer = dstz, src_layer = src_box->z;
 
-   /* Fallback for buffers. */
    if (dst->target == PIPE_BUFFER && src->target == PIPE_BUFFER) {
-      util_resource_copy_region(pipe, dst, dst_level, dstx, dsty, dstz,
-                                src, src_level, src_box);
+      nouveau_copy_buffer(&nvc0->base,
+                          nv04_resource(dst), dstx,
+                          nv04_resource(src), src_box->x, src_box->width);
       NOUVEAU_DRV_STAT(&nvc0->screen->base, buf_copy_bytes, src_box->width);
       return;
    }