venus: require exportable/importable bit for ext semaphores sync fd
authorJuston Li <justonli@google.com>
Tue, 20 Dec 2022 22:19:13 +0000 (14:19 -0800)
committerMarge Bot <emma+marge@anholt.net>
Sat, 14 Jan 2023 00:51:56 +0000 (00:51 +0000)
Signed-off-by: Juston Li <justonli@google.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20088>

src/virtio/vulkan/vn_physical_device.c
src/virtio/vulkan/vn_queue.c

index d00357b..5ee4428 100644 (file)
@@ -965,7 +965,11 @@ vn_physical_device_get_native_extensions(
            VK_EXTERNAL_FENCE_FEATURE_EXPORTABLE_BIT))
          exts->KHR_external_fence_fd = true;
 
-      exts->KHR_external_semaphore_fd = true;
+      if ((physical_dev->renderer_sync_fd_semaphore_features &
+           VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT) &&
+          (physical_dev->renderer_sync_fd_semaphore_features &
+           VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT))
+         exts->KHR_external_semaphore_fd = true;
    }
 #endif
 
index 28e4052..1b9309f 100644 (file)
@@ -1551,6 +1551,11 @@ vn_GetSemaphoreFdKHR(VkDevice device,
 
    assert(dev->instance->experimental.globalFencing);
    assert(sync_file);
+   assert((dev->physical_device->renderer_sync_fd_semaphore_features &
+           VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT));
+   assert((dev->physical_device->renderer_sync_fd_semaphore_features &
+           VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT));
+
    int fd = -1;
    if (payload->type == VN_SYNC_TYPE_DEVICE_ONLY) {
       VkResult result = vn_create_sync_file(dev, sem->ring_idx, &fd);
@@ -1565,36 +1570,28 @@ vn_GetSemaphoreFdKHR(VkDevice device,
       payload->fd = -1;
    }
 
-   /* required sync_fd features for fixing the host semaphore payload */
-   static const VkExternalSemaphoreFeatureFlags req_sync_fd_feats =
-      VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT |
-      VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT;
-   if ((dev->physical_device->renderer_sync_fd_semaphore_features &
-        req_sync_fd_feats) == req_sync_fd_feats) {
-
-      /* When payload->type is VN_SYNC_TYPE_IMPORTED_SYNC_FD, the current
-       * payload is from a prior temporary sync_fd import. The permanent
-       * payload of the sempahore might be in signaled state. So we do an
-       * import here to ensure later wait operation is legit. With resourceId
-       * 0, renderer does a signaled sync_fd -1 payload import on the host
-       * semaphore.
-       */
-      if (payload->type == VN_SYNC_TYPE_IMPORTED_SYNC_FD) {
-         const VkImportSemaphoreResourceInfo100000MESA res_info = {
-            .sType =
-               VK_STRUCTURE_TYPE_IMPORT_SEMAPHORE_RESOURCE_INFO_100000_MESA,
-            .semaphore = pGetFdInfo->semaphore,
-            .resourceId = 0,
-         };
-         vn_async_vkImportSemaphoreResource100000MESA(dev->instance, device,
-                                                      &res_info);
-      }
-
-      /* perform wait operation on the host semaphore */
-      vn_async_vkWaitSemaphoreResource100000MESA(dev->instance, device,
-                                                 pGetFdInfo->semaphore);
+   /* When payload->type is VN_SYNC_TYPE_IMPORTED_SYNC_FD, the current
+    * payload is from a prior temporary sync_fd import. The permanent
+    * payload of the sempahore might be in signaled state. So we do an
+    * import here to ensure later wait operation is legit. With resourceId
+    * 0, renderer does a signaled sync_fd -1 payload import on the host
+    * semaphore.
+    */
+   if (payload->type == VN_SYNC_TYPE_IMPORTED_SYNC_FD) {
+      const VkImportSemaphoreResourceInfo100000MESA res_info = {
+         .sType =
+            VK_STRUCTURE_TYPE_IMPORT_SEMAPHORE_RESOURCE_INFO_100000_MESA,
+         .semaphore = pGetFdInfo->semaphore,
+         .resourceId = 0,
+      };
+      vn_async_vkImportSemaphoreResource100000MESA(dev->instance, device,
+                                                   &res_info);
    }
 
+   /* perform wait operation on the host semaphore */
+   vn_async_vkWaitSemaphoreResource100000MESA(dev->instance, device,
+                                              pGetFdInfo->semaphore);
+
    vn_sync_payload_release(dev, &sem->temporary);
    sem->payload = &sem->permanent;