radv: Implement VK_KHR_external_fence_fd.
authorBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Mon, 27 Nov 2017 23:21:12 +0000 (00:21 +0100)
committerBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Mon, 18 Dec 2017 08:31:17 +0000 (09:31 +0100)
Reviewed-by: Dave Airlie <airlied@redhat.com>
src/amd/vulkan/radv_device.c
src/amd/vulkan/radv_extensions.py

index fc9fb59..94562fd 100644 (file)
@@ -3746,3 +3746,50 @@ void radv_GetPhysicalDeviceExternalSemaphorePropertiesKHR(
                pExternalSemaphoreProperties->externalSemaphoreFeatures = 0;
        }
 }
+
+VkResult radv_ImportFenceFdKHR(VkDevice _device,
+                                  const VkImportFenceFdInfoKHR *pImportFenceFdInfo)
+{
+       RADV_FROM_HANDLE(radv_device, device, _device);
+       RADV_FROM_HANDLE(radv_fence, fence, pImportFenceFdInfo->fence);
+       uint32_t syncobj_handle = 0;
+       uint32_t *syncobj_dst = NULL;
+       assert(pImportFenceFdInfo->handleType == VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR);
+
+       int ret = device->ws->import_syncobj(device->ws, pImportFenceFdInfo->fd, &syncobj_handle);
+       if (ret != 0)
+               return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR);
+
+       if (pImportFenceFdInfo->flags & VK_FENCE_IMPORT_TEMPORARY_BIT_KHR) {
+               syncobj_dst = &fence->temp_syncobj;
+       } else {
+               syncobj_dst = &fence->syncobj;
+       }
+
+       if (*syncobj_dst)
+               device->ws->destroy_syncobj(device->ws, *syncobj_dst);
+
+       *syncobj_dst = syncobj_handle;
+       close(pImportFenceFdInfo->fd);
+       return VK_SUCCESS;
+}
+
+VkResult radv_GetFenceFdKHR(VkDevice _device,
+                               const VkFenceGetFdInfoKHR *pGetFdInfo,
+                               int *pFd)
+{
+       RADV_FROM_HANDLE(radv_device, device, _device);
+       RADV_FROM_HANDLE(radv_fence, fence, pGetFdInfo->fence);
+       int ret;
+       uint32_t syncobj_handle;
+
+       assert(pGetFdInfo->handleType == VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR);
+       if (fence->temp_syncobj)
+               syncobj_handle = fence->temp_syncobj;
+       else
+               syncobj_handle = fence->syncobj;
+       ret = device->ws->export_syncobj(device->ws, syncobj_handle, pFd);
+       if (ret)
+               return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR);
+       return VK_SUCCESS;
+}
index 2c1c71e..3188735 100644 (file)
@@ -53,6 +53,7 @@ EXTENSIONS = [
     Extension('VK_KHR_bind_memory2',                      1, True),
     Extension('VK_KHR_dedicated_allocation',              1, True),
     Extension('VK_KHR_descriptor_update_template',        1, True),
+    Extension('VK_KHR_external_fence_fd',                 1, 'device->rad_info.has_syncobj_wait'),
     Extension('VK_KHR_external_memory',                   1, True),
     Extension('VK_KHR_external_memory_capabilities',      1, True),
     Extension('VK_KHR_external_memory_fd',                1, True),