iris: fix import from dri2/3
authorChris Wilson <chris@chris-wilson.co.uk>
Sat, 2 Jun 2018 11:32:19 +0000 (12:32 +0100)
committerKenneth Graunke <kenneth@whitecape.org>
Thu, 21 Feb 2019 18:26:06 +0000 (10:26 -0800)
src/gallium/drivers/iris/iris_resource.c

index 6c90f01085b38a531f84ad0a140efe3fdcf1ba06..dde859ab795df2a6b7ceaf3efbd4d515ad7ea458 100644 (file)
@@ -289,6 +289,20 @@ iris_resource_create(struct pipe_screen *pscreen,
    return iris_resource_create_with_modifiers(pscreen, templ, NULL, 0);
 }
 
+static uint64_t
+tiling_to_modifier(uint32_t tiling)
+{
+   static const uint64_t map[] = {
+      [I915_TILING_NONE]   = DRM_FORMAT_MOD_LINEAR,
+      [I915_TILING_X]      = I915_FORMAT_MOD_X_TILED,
+      [I915_TILING_Y]      = I915_FORMAT_MOD_Y_TILED,
+   };
+
+   assert(tiling < ARRAY_SIZE(map));
+
+   return map[tiling];
+}
+
 static struct pipe_resource *
 iris_resource_from_handle(struct pipe_screen *pscreen,
                           const struct pipe_resource *templ,
@@ -308,19 +322,26 @@ iris_resource_from_handle(struct pipe_screen *pscreen,
    }
 
    switch (whandle->type) {
-   case WINSYS_HANDLE_TYPE_SHARED:
+   case WINSYS_HANDLE_TYPE_FD:
       res->bo = iris_bo_import_dmabuf(bufmgr, whandle->handle);
       break;
-   case WINSYS_HANDLE_TYPE_FD:
+   case WINSYS_HANDLE_TYPE_SHARED:
       res->bo = iris_bo_gem_create_from_name(bufmgr, "winsys image",
                                              whandle->handle);
       break;
    default:
       unreachable("invalid winsys handle type");
    }
+   if (!res->bo)
+          return NULL;
 
+   uint64_t modifier = whandle->modifier;
+   if (modifier == DRM_FORMAT_MOD_INVALID) {
+         modifier = tiling_to_modifier(res->bo->tiling_mode);
+   }
    const struct isl_drm_modifier_info *mod_info =
-      isl_drm_modifier_get_info(whandle->modifier);
+      isl_drm_modifier_get_info(modifier);
+   assert(mod_info);
 
    // XXX: usage...
    isl_surf_usage_flags_t isl_usage = ISL_SURF_USAGE_DISPLAY_BIT;