freedreno: Use staging transfer if mmap fails
authorRob Clark <robdclark@chromium.org>
Wed, 20 Apr 2022 17:07:14 +0000 (10:07 -0700)
committerMarge Bot <emma+marge@anholt.net>
Wed, 27 Apr 2022 23:10:00 +0000 (23:10 +0000)
With externaly imported resources, we can have situations where we can't
mmap and directly access linear buffers.  So use the staging blit path
for this case.

Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16086>

src/gallium/drivers/freedreno/freedreno_resource.c

index 78ea440..8bbaaf8 100644 (file)
@@ -790,6 +790,16 @@ resource_transfer_map_unsync(struct pipe_context *pctx,
    char *buf;
 
    buf = fd_bo_map(rsc->bo);
+
+   /* With imported bo's allocated by something outside of mesa, when
+    * running in a VM (using virtio_gpu kernel driver) we could end up in
+    * a situation where we have a linear bo, but are unable to mmap it
+    * because it was allocated without the VIRTGPU_BLOB_FLAG_USE_MAPPABLE
+    * flag.  So we need end up needing to do a staging blit instead:
+    */
+   if (!buf)
+      return resource_transfer_map_staging(pctx, prsc, level, usage, box, trans);
+
    offset = box->y / util_format_get_blockheight(format) * trans->b.b.stride +
             box->x / util_format_get_blockwidth(format) * rsc->layout.cpp +
             fd_resource_offset(rsc, level, box->z);