zink: only enable KHR_external_memory_fd if supported
authorErik Faye-Lund <erik.faye-lund@collabora.com>
Wed, 23 Oct 2019 10:16:22 +0000 (12:16 +0200)
committerErik Faye-Lund <erik.faye-lund@collabora.com>
Wed, 30 Oct 2019 19:40:50 +0000 (19:40 +0000)
While we're at it, make sure we error out if it's not supported when
required.

This brings us a bit closer to being able to test on SwiftShader, which
doesn't currently support KHR_external_memory_fd.

src/gallium/drivers/zink/zink_resource.c
src/gallium/drivers/zink/zink_screen.c
src/gallium/drivers/zink/zink_screen.h

index b12d38ec7841f9e1372fa565c55920c53ea6f334..0051c891d57ccd997a8bdf4d38e95732c50f8ad3 100644 (file)
@@ -355,8 +355,11 @@ zink_screen_resource_init(struct pipe_screen *pscreen)
 {
    pscreen->resource_create = zink_resource_create;
    pscreen->resource_destroy = zink_resource_destroy;
-   pscreen->resource_get_handle = zink_resource_get_handle;
-   pscreen->resource_from_handle = zink_resource_from_handle;
+
+   if (zink_screen(pscreen)->have_KHR_external_memory_fd) {
+      pscreen->resource_get_handle = zink_resource_get_handle;
+      pscreen->resource_from_handle = zink_resource_from_handle;
+   }
 }
 
 static bool
index a75389257af7ba53bf277df3f7dc8abe5d735e0a..59c96ed946fff9781b1054e9b7638a26619fe53a 100644 (file)
@@ -299,6 +299,9 @@ zink_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
    case PIPE_CAP_TWO_SIDED_COLOR:
       return 0;
 
+   case PIPE_CAP_DMABUF:
+      return screen->have_KHR_external_memory_fd;
+
    default:
       return u_pipe_screen_get_param_defaults(pscreen, param);
    }
@@ -869,8 +872,11 @@ zink_internal_create_screen(struct sw_winsys *winsys, int fd)
 
          for (uint32_t  i = 0; i < num_extensions; ++i) {
             if (!strcmp(extensions[i].extensionName,
-                VK_KHR_MAINTENANCE1_EXTENSION_NAME))
+                        VK_KHR_MAINTENANCE1_EXTENSION_NAME))
                screen->have_KHR_maintenance1 = true;
+            if (!strcmp(extensions[i].extensionName,
+                        VK_KHR_EXTERNAL_MEMORY_FD_EXTENSION_NAME))
+               screen->have_KHR_external_memory_fd = true;
          }
          FREE(extensions);
       }
@@ -893,13 +899,24 @@ zink_internal_create_screen(struct sw_winsys *winsys, int fd)
    dci.queueCreateInfoCount = 1;
    dci.pQueueCreateInfos = &qci;
    dci.pEnabledFeatures = &screen->feats;
-   const char *extensions[] = {
+   const char *extensions[3] = {
       VK_KHR_MAINTENANCE1_EXTENSION_NAME,
-      VK_KHR_EXTERNAL_MEMORY_EXTENSION_NAME,
-      VK_KHR_EXTERNAL_MEMORY_FD_EXTENSION_NAME,
    };
+   num_extensions = 1;
+
+   if (fd >= 0 && !screen->have_KHR_external_memory_fd) {
+      debug_printf("ZINK: KHR_external_memory_fd required!\n");
+      goto fail;
+   }
+
+   if (screen->have_KHR_external_memory_fd) {
+      extensions[num_extensions++] = VK_KHR_EXTERNAL_MEMORY_EXTENSION_NAME;
+      extensions[num_extensions++] = VK_KHR_EXTERNAL_MEMORY_FD_EXTENSION_NAME;
+   }
+   assert(num_extensions <= ARRAY_SIZE(extensions));
+
    dci.ppEnabledExtensionNames = extensions;
-   dci.enabledExtensionCount = ARRAY_SIZE(extensions);
+   dci.enabledExtensionCount = num_extensions;
    if (vkCreateDevice(screen->pdev, &dci, NULL, &screen->dev) != VK_SUCCESS)
       goto fail;
 
index 0b0ee210abba9450a13354fa50c20c2448b7d919..5bf3fbdda8a9fffa9ccfe7fab23fa0d808c69fa9 100644 (file)
@@ -50,6 +50,7 @@ struct zink_screen {
    VkPhysicalDeviceMemoryProperties mem_props;
 
    bool have_KHR_maintenance1;
+   bool have_KHR_external_memory_fd;
 
    bool have_X8_D24_UNORM_PACK32;
    bool have_D24_UNORM_S8_UINT;