zink: implement resource_from_handle
authorErik Faye-Lund <erik.faye-lund@collabora.com>
Wed, 24 Jul 2019 15:58:54 +0000 (17:58 +0200)
committerErik Faye-Lund <erik.faye-lund@collabora.com>
Mon, 28 Oct 2019 08:51:48 +0000 (08:51 +0000)
Acked-by: Jordan Justen <jordan.l.justen@intel.com>
src/gallium/drivers/zink/zink_resource.c

index 796ecae2d51e7d8167961a97125590714d839fe0..fe4097e9f0ce62c8d6518c9f6cfd10e2a2d9ab43 100644 (file)
@@ -84,8 +84,10 @@ aspect_from_format(enum pipe_format fmt)
 }
 
 static struct pipe_resource *
-zink_resource_create(struct pipe_screen *pscreen,
-                     const struct pipe_resource *templ)
+resource_create(struct pipe_screen *pscreen,
+                const struct pipe_resource *templ,
+                struct winsys_handle *whandle,
+                unsigned external_usage)
 {
    struct zink_screen *screen = zink_screen(pscreen);
    struct zink_resource *res = CALLOC_STRUCT(zink_resource);
@@ -241,6 +243,20 @@ zink_resource_create(struct pipe_screen *pscreen,
       mai.pNext = &emai;
    }
 
+   VkImportMemoryFdInfoKHR imfi = {
+      VK_STRUCTURE_TYPE_IMPORT_MEMORY_FD_INFO_KHR,
+      NULL,
+   };
+
+   if (whandle && whandle->type == WINSYS_HANDLE_TYPE_FD) {
+      imfi.sType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT;
+      imfi.pNext = NULL;
+      imfi.handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT;
+      imfi.fd = whandle->handle;
+
+      emai.pNext = &imfi;
+   }
+
    if (vkAllocateMemory(screen->dev, &mai, NULL, &res->mem) != VK_SUCCESS)
       goto fail;
 
@@ -278,6 +294,13 @@ fail:
    return NULL;
 }
 
+static struct pipe_resource *
+zink_resource_create(struct pipe_screen *pscreen,
+                     const struct pipe_resource *templ)
+{
+   return resource_create(pscreen, templ, NULL, 0);
+}
+
 static bool
 zink_resource_get_handle(struct pipe_screen *pscreen,
                          struct pipe_context *context,
@@ -320,11 +343,11 @@ zink_resource_get_handle(struct pipe_screen *pscreen,
 
 static struct pipe_resource *
 zink_resource_from_handle(struct pipe_screen *pscreen,
-                 const struct pipe_resource *templat,
+                 const struct pipe_resource *templ,
                  struct winsys_handle *whandle,
                  unsigned usage)
 {
-   return NULL;
+   return resource_create(pscreen, templ, whandle, usage);
 }
 
 void