sna: Allow more inplace promotions of CPU to GPU bo
authorChris Wilson <chris@chris-wilson.co.uk>
Sat, 1 Feb 2014 21:37:41 +0000 (21:37 +0000)
committerChris Wilson <chris@chris-wilson.co.uk>
Sat, 1 Feb 2014 21:40:54 +0000 (21:40 +0000)
If the CPU bo is wholly damaged, then it makes an ideal candidate for
simply converting into the GPU bo.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
src/sna/kgem.c
src/sna/kgem.h
src/sna/sna_accel.c

index f7404df..788b710 100644 (file)
@@ -6743,14 +6743,19 @@ kgem_replace_bo(struct kgem *kgem,
        return dst;
 }
 
-bool kgem_bo_convert_to_gpu(struct kgem *kgem, struct kgem_bo *bo)
+bool kgem_bo_convert_to_gpu(struct kgem *kgem,
+                           struct kgem_bo *bo,
+                           unsigned flags)
 {
-       DBG(("%s: converting handle=%d from CPU to GPU\n", __FUNCTION__, bo->handle));
+       DBG(("%s: converting handle=%d from CPU to GPU, flags=%x\n", __FUNCTION__, bo->handle));
        assert(bo->tiling == I915_TILING_NONE);
 
        if (kgem->has_llc)
                return true;
 
+       if (flags & MOVE_ASYNC_HINT && __kgem_bo_is_busy(kgem, bo))
+               return false;
+
        assert(bo->snoop);
 
        kgem_bo_submit(kgem, bo);
index f670b60..4c4996f 100644 (file)
@@ -301,7 +301,9 @@ struct kgem_bo *kgem_create_cpu_2d(struct kgem *kgem,
                                   int bpp,
                                   uint32_t flags);
 
-bool kgem_bo_convert_to_gpu(struct kgem *kgem, struct kgem_bo *bo);
+bool kgem_bo_convert_to_gpu(struct kgem *kgem,
+                           struct kgem_bo *bo,
+                           unsigned flags);
 
 uint32_t kgem_bo_get_binding(struct kgem_bo *bo, uint32_t format);
 void kgem_bo_set_binding(struct kgem_bo *bo, uint32_t format, uint16_t offset);
index d654660..9d7dec4 100644 (file)
@@ -3868,7 +3868,7 @@ sna_pixmap_move_to_gpu(PixmapPtr pixmap, unsigned flags)
 
                        if (tiling == I915_TILING_NONE &&
                            priv->cpu_bo && !priv->shm &&
-                           kgem_bo_convert_to_gpu(&sna->kgem, priv->cpu_bo)) {
+                           kgem_bo_convert_to_gpu(&sna->kgem, priv->cpu_bo, flags)) {
                                assert(!priv->mapped);
                                assert(!IS_STATIC_PTR(priv->ptr));
 #ifdef DEBUG_MEMORY
@@ -3933,6 +3933,28 @@ sna_pixmap_move_to_gpu(PixmapPtr pixmap, unsigned flags)
        if (priv->cpu_damage == NULL)
                goto done;
 
+       if (DAMAGE_IS_ALL(priv->cpu_damage) &&
+           priv->gpu_bo->tiling == I915_TILING_NONE &&
+           priv->cpu_bo && !priv->shm &&
+           kgem_bo_convert_to_gpu(&sna->kgem, priv->cpu_bo, flags)) {
+               assert(!priv->mapped);
+               assert(!IS_STATIC_PTR(priv->ptr));
+#ifdef DEBUG_MEMORY
+               sna->debug_memory.cpu_bo_allocs--;
+               sna->debug_memory.cpu_bo_bytes -= kgem_bo_size(priv->cpu_bo);
+#endif
+               sna_pixmap_free_gpu(sna, priv);
+               priv->gpu_bo = priv->cpu_bo;
+               priv->cpu_bo = NULL;
+               priv->ptr = NULL;
+               pixmap->devPrivate.ptr = NULL;
+               sna_damage_all(&priv->gpu_damage,
+                              pixmap->drawable.width,
+                              pixmap->drawable.height);
+               sna_damage_destroy(&priv->cpu_damage);
+               goto done;
+       }
+
        if (priv->shm) {
                assert(!priv->flush);
                sna_add_flush_pixmap(sna, priv, priv->cpu_bo);