From e37c9b0b44be4c9d990be5a9dd02c703050aba8b Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Fri, 11 Jun 2021 14:08:31 -0700 Subject: [PATCH] vkr: make internal fences exportable This is desirable when we have a per-context version of virgl_renderer_export_fence. Signed-off-by: Chia-I Wu Reviewed-by: Yiwei Zhang --- src/vkr_renderer.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/vkr_renderer.c b/src/vkr_renderer.c index c6227ac..a7f4726 100644 --- a/src/vkr_renderer.c +++ b/src/vkr_renderer.c @@ -965,7 +965,8 @@ vkr_physical_device_init_memory_properties(struct vkr_physical_device *physical_ } static void -vkr_physical_device_init_extensions(struct vkr_physical_device *physical_dev) +vkr_physical_device_init_extensions(struct vkr_physical_device *physical_dev, + struct vkr_instance *instance) { VkPhysicalDevice handle = physical_dev->base.handle.physical_device; @@ -1004,6 +1005,23 @@ vkr_physical_device_init_extensions(struct vkr_physical_device *physical_dev) } } + if (physical_dev->KHR_external_fence_fd) { + const VkPhysicalDeviceExternalFenceInfo fence_info = { + .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_FENCE_INFO, + .handleType = VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT, + }; + VkExternalFenceProperties fence_props = { + .sType = VK_STRUCTURE_TYPE_EXTERNAL_FENCE_PROPERTIES, + }; + PFN_vkGetPhysicalDeviceExternalFenceProperties get_fence_props = + (PFN_vkGetPhysicalDeviceExternalFenceProperties)vkGetInstanceProcAddr( + instance->base.handle.instance, "vkGetPhysicalDeviceExternalFenceProperties"); + get_fence_props(handle, &fence_info, &fence_props); + + if (!(fence_props.externalFenceFeatures & VK_EXTERNAL_FENCE_FEATURE_EXPORTABLE_BIT)) + physical_dev->KHR_external_fence_fd = false; + } + physical_dev->extensions = exts; physical_dev->extension_count = advertised_count; } @@ -1078,7 +1096,7 @@ vkr_dispatch_vkEnumeratePhysicalDevices(struct vn_dispatch_context *dispatch, vkr_physical_device_init_properties(physical_dev); physical_dev->api_version = MIN2(physical_dev->properties.apiVersion, instance->api_version); - vkr_physical_device_init_extensions(physical_dev); + vkr_physical_device_init_extensions(physical_dev, instance); vkr_physical_device_init_memory_properties(physical_dev); instance->physical_devices[i] = physical_dev; @@ -4229,8 +4247,13 @@ vkr_context_submit_fence_locked(struct virgl_context *base, if (!sync) return -ENOMEM; + const VkExportFenceCreateInfo export_info = { + .sType = VK_STRUCTURE_TYPE_EXPORT_FENCE_CREATE_INFO, + .handleTypes = VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT, + }; const struct VkFenceCreateInfo create_info = { .sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, + .pNext = dev->physical_device->KHR_external_fence_fd ? &export_info : NULL, }; result = vkCreateFence(dev->base.handle.device, &create_info, NULL, &sync->fence); if (result != VK_SUCCESS) {