From a504b98e7202ebd0aac4ad9bf7a919c00bd1f64f Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Sat, 2 Jun 2018 12:32:19 +0100 Subject: [PATCH] iris: fix import from dri2/3 --- src/gallium/drivers/iris/iris_resource.c | 27 +++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/gallium/drivers/iris/iris_resource.c b/src/gallium/drivers/iris/iris_resource.c index 6c90f01085b..dde859ab795 100644 --- a/src/gallium/drivers/iris/iris_resource.c +++ b/src/gallium/drivers/iris/iris_resource.c @@ -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; -- 2.30.2