dzn: Hook up fd semaphore import/export
authorJesse Natalie <jenatali@microsoft.com>
Fri, 5 May 2023 15:45:53 +0000 (08:45 -0700)
committerMarge Bot <emma+marge@anholt.net>
Mon, 15 May 2023 17:14:20 +0000 (17:14 +0000)
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22879>

src/microsoft/vulkan/dzn_device.c
src/microsoft/vulkan/dzn_sync.c

index 1f5f8e9..00d455b 100644 (file)
@@ -116,10 +116,13 @@ dzn_physical_device_get_extensions(struct dzn_physical_device *pdev)
       .KHR_driver_properties                 = true,
       .KHR_dynamic_rendering                 = true,
       .KHR_external_memory                   = true,
+      .KHR_external_semaphore                = true,
 #ifdef _WIN32
       .KHR_external_memory_win32             = true,
+      .KHR_external_semaphore_win32          = true,
 #else
       .KHR_external_memory_fd                = true,
+      .KHR_external_semaphore_fd             = true,
 #endif
       .KHR_image_format_list                 = true,
       .KHR_imageless_framebuffer             = true,
index 5b19330..76e047c 100644 (file)
@@ -278,6 +278,34 @@ dzn_sync_prep_win32_export(struct vk_device *device, struct vk_sync *sync,
       return vk_error(device, VK_ERROR_OUT_OF_DEVICE_MEMORY);
    return VK_SUCCESS;
 }
+#else
+static VkResult
+dzn_sync_import_opaque_fd(struct vk_device *device, struct vk_sync *sync,
+                          int fd)
+{
+   struct dzn_sync *dsync = container_of(sync, struct dzn_sync, vk);
+   struct dzn_device *ddev = container_of(device, struct dzn_device, vk);
+
+   dzn_sync_finish(device, sync);
+
+   HANDLE handle = (HANDLE)(intptr_t)fd;
+   if (FAILED(ID3D12Device_OpenSharedHandle(ddev->dev, handle, &IID_ID3D12Fence, (void **)&dsync->fence)))
+      return vk_error(device, VK_ERROR_INVALID_EXTERNAL_HANDLE);
+   return VK_SUCCESS;
+}
+
+static VkResult
+dzn_sync_export_opaque_fd(struct vk_device *device, struct vk_sync *sync, int *fd)
+{
+   struct dzn_sync *dsync = container_of(sync, struct dzn_sync, vk);
+   struct dzn_device *ddev = container_of(device, struct dzn_device, vk);
+   HANDLE handle;
+   if (FAILED(ID3D12Device_CreateSharedHandle(ddev->dev, (ID3D12DeviceChild *)dsync->fence,
+                                              NULL, GENERIC_ALL, NULL, &handle)))
+      return vk_error(device, VK_ERROR_OUT_OF_DEVICE_MEMORY);
+   *fd = (int)(intptr_t)handle;
+   return VK_SUCCESS;
+}
 #endif
 
 const struct vk_sync_type dzn_sync_type = {
@@ -301,5 +329,8 @@ const struct vk_sync_type dzn_sync_type = {
    .import_win32_handle = dzn_sync_import_win32_handle,
    .export_win32_handle = dzn_sync_export_win32_handle,
    .set_win32_export_params = dzn_sync_prep_win32_export,
+#else
+   .import_opaque_fd = dzn_sync_import_opaque_fd,
+   .export_opaque_fd = dzn_sync_export_opaque_fd,
 #endif
 };