summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Natalie <jenatali@microsoft.com>2023-05-05 08:45:53 -0700
committerMarge Bot <emma+marge@anholt.net>2023-05-15 17:14:20 +0000
commit60ed4b92a0851332b3ba581ed926e37aa3ef4b09 (patch)
treea3cc179441a094ca7558665b745b3b4279392185
parentc64f1b6650f9f81a0329390d92f8c27bcb046e7c (diff)
downloadmesa-60ed4b92a0851332b3ba581ed926e37aa3ef4b09.tar.gz
dzn: Hook up fd semaphore import/export
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22879>
-rw-r--r--src/microsoft/vulkan/dzn_device.c3
-rw-r--r--src/microsoft/vulkan/dzn_sync.c31
2 files changed, 34 insertions, 0 deletions
diff --git a/src/microsoft/vulkan/dzn_device.c b/src/microsoft/vulkan/dzn_device.c
index 1f5f8e9f343..00d455b474f 100644
--- a/src/microsoft/vulkan/dzn_device.c
+++ b/src/microsoft/vulkan/dzn_device.c
@@ -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,
diff --git a/src/microsoft/vulkan/dzn_sync.c b/src/microsoft/vulkan/dzn_sync.c
index 5b19330949b..76e047c57b7 100644
--- a/src/microsoft/vulkan/dzn_sync.c
+++ b/src/microsoft/vulkan/dzn_sync.c
@@ -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
};