vulkan/wsi: provide api for drivers to setup syncobj fd
authorTapani Pälli <tapani.palli@intel.com>
Thu, 14 Oct 2021 11:43:00 +0000 (14:43 +0300)
committerMarge Bot <emma+marge@anholt.net>
Thu, 4 Nov 2021 16:57:29 +0000 (16:57 +0000)
Drivers that import sync_fd to the wsi fences can use this to set file
descriptor for syncobj related calls. This fixes permission errors when
registering display/device events and importing sync_fd from driver
side.

Signed-off-by: Tapani Pälli <tapani.palli@intel.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12305>

src/vulkan/wsi/wsi_common.c
src/vulkan/wsi/wsi_common.h
src/vulkan/wsi/wsi_common_display.c
src/vulkan/wsi/wsi_common_private.h

index 8df55f5..a72f65e 100644 (file)
@@ -203,6 +203,15 @@ wsi_DestroySurfaceKHR(VkInstance _instance,
    vk_free2(&instance->alloc, pAllocator, surface);
 }
 
+void
+wsi_device_setup_syncobj_fd(struct wsi_device *wsi_device,
+                            int fd)
+{
+#ifdef VK_USE_PLATFORM_DISPLAY_KHR
+   wsi_display_setup_syncobj_fd(wsi_device, fd);
+#endif
+}
+
 VkResult
 wsi_swapchain_init(const struct wsi_device *wsi,
                    struct wsi_swapchain *chain,
index ab657b0..0e4ab77 100644 (file)
@@ -226,6 +226,11 @@ void
 wsi_device_finish(struct wsi_device *wsi,
                   const VkAllocationCallbacks *alloc);
 
+/* Setup file descriptor to be used with imported sync_fd's in wsi fences. */
+void
+wsi_device_setup_syncobj_fd(struct wsi_device *wsi_device,
+                            int fd);
+
 #define ICD_DEFINE_NONDISP_HANDLE_CASTS(__VkIcdType, __VkType)             \
                                                                            \
    static inline __VkIcdType *                                             \
index a8d0353..e20c755 100644 (file)
@@ -96,6 +96,9 @@ struct wsi_display {
 
    int                          fd;
 
+   /* Used with syncobj imported from driver side. */
+   int                          syncobj_fd;
+
    pthread_mutex_t              wait_mutex;
    pthread_cond_t               wait_cond;
    pthread_t                    wait_thread;
@@ -1542,8 +1545,8 @@ static void wsi_display_fence_event_handler(struct wsi_display_fence *fence)
       (struct wsi_display *) fence->base.wsi_device->wsi[VK_ICD_WSI_PLATFORM_DISPLAY];
 
    if (fence->syncobj) {
-      (void) drmSyncobjSignal(wsi->fd, &fence->syncobj, 1);
-      (void) drmSyncobjDestroy(wsi->fd, fence->syncobj);
+      (void) drmSyncobjSignal(wsi->syncobj_fd, &fence->syncobj, 1);
+      (void) drmSyncobjDestroy(wsi->syncobj_fd, fence->syncobj);
    }
 
    fence->event_received = true;
@@ -1577,7 +1580,8 @@ wsi_display_fence_alloc(VkDevice device,
       return NULL;
 
    if (sync_fd >= 0) {
-      int ret = drmSyncobjFDToHandle(wsi->fd, sync_fd, &fence->syncobj);
+      int ret = drmSyncobjFDToHandle(wsi->syncobj_fd, sync_fd, &fence->syncobj);
+
       if (ret) {
          vk_free2(wsi->alloc, allocator, fence);
          return NULL;
@@ -1926,6 +1930,8 @@ wsi_display_init_wsi(struct wsi_device *wsi_device,
    if (wsi->fd != -1 && !local_drmIsMaster(wsi->fd))
       wsi->fd = -1;
 
+   wsi->syncobj_fd = wsi->fd;
+
    wsi->alloc = alloc;
 
    list_inithead(&wsi->connectors);
@@ -2579,7 +2585,7 @@ wsi_register_display_event(VkDevice device,
             fence->base.destroy(&fence->base);
       } else if (fence != NULL) {
          if (fence->syncobj)
-            drmSyncobjDestroy(wsi->fd, fence->syncobj);
+            drmSyncobjDestroy(wsi->syncobj_fd, fence->syncobj);
          vk_free2(wsi->alloc, allocator, fence);
       }
 
@@ -2602,6 +2608,15 @@ wsi_RegisterDisplayEventEXT(VkDevice device,
    unreachable("Not enough common infrastructure to implement this yet");
 }
 
+void
+wsi_display_setup_syncobj_fd(struct wsi_device *wsi_device,
+                             int fd)
+{
+   struct wsi_display *wsi =
+      (struct wsi_display *) wsi_device->wsi[VK_ICD_WSI_PLATFORM_DISPLAY];
+   wsi->syncobj_fd = fd;
+}
+
 VKAPI_ATTR VkResult VKAPI_CALL
 wsi_GetSwapchainCounterEXT(VkDevice _device,
                            VkSwapchainKHR _swapchain,
index 2bed91d..3eb14d2 100644 (file)
@@ -167,6 +167,10 @@ void
 wsi_display_finish_wsi(struct wsi_device *wsi_device,
                        const VkAllocationCallbacks *alloc);
 
+void
+wsi_display_setup_syncobj_fd(struct wsi_device *wsi_device,
+                             int fd);
+
 VK_DEFINE_NONDISP_HANDLE_CASTS(wsi_swapchain, base, VkSwapchainKHR,
                                VK_OBJECT_TYPE_SWAPCHAIN_KHR)