Module: Mesa
Branch: main
Commit: ce0e13155d9d1c4c80c73b6866379b99e822facb
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=ce0e13155d9d1c4c80c73b6866379b99e822facb

Author: Yiwei Zhang <[email protected]>
Date:   Fri Aug 19 19:45:05 2022 +0000

venus: avoid scrubing wsi/external sempahores

When the renderer supports sync_fd import for the binary semaphore,
venus can import the special signaled payload to the semaphore instead
of scrubing it. This avoids the bugs w.r.t timeline semaphore and device
group submission in the legacy scrub path.

Signed-off-by: Yiwei Zhang <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17975>

---

 src/virtio/vulkan/vn_device.c |  7 +++++++
 src/virtio/vulkan/vn_queue.c  | 48 +++++++++++++++++++++++++++++++++++--------
 2 files changed, 46 insertions(+), 9 deletions(-)

diff --git a/src/virtio/vulkan/vn_device.c b/src/virtio/vulkan/vn_device.c
index ffa27e027b3..b7335e0a8e8 100644
--- a/src/virtio/vulkan/vn_device.c
+++ b/src/virtio/vulkan/vn_device.c
@@ -278,6 +278,13 @@ vn_device_fix_create_info(const struct vn_device *dev,
       }
    }
 
+   /* see vn_queue_submission_count_batch_semaphores */
+   if (!app_exts->KHR_external_semaphore_fd &&
+       (physical_dev->renderer_sync_fd_semaphore_features &
+        VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT)) {
+      extra_exts[extra_count++] = VK_KHR_EXTERNAL_SEMAPHORE_FD_EXTENSION_NAME;
+   }
+
    if (app_exts->EXT_physical_device_drm) {
       /* see vn_physical_device_get_native_extensions */
       block_exts[block_count++] = VK_EXT_PHYSICAL_DEVICE_DRM_EXTENSION_NAME;
diff --git a/src/virtio/vulkan/vn_queue.c b/src/virtio/vulkan/vn_queue.c
index 37dce5f0aaf..5653349fcb4 100644
--- a/src/virtio/vulkan/vn_queue.c
+++ b/src/virtio/vulkan/vn_queue.c
@@ -72,7 +72,7 @@ struct vn_queue_submission {
    } temp;
 };
 
-static void
+static VkResult
 vn_queue_submission_count_batch_semaphores(struct vn_queue_submission *submit,
                                            uint32_t batch_index)
 {
@@ -103,19 +103,45 @@ vn_queue_submission_count_batch_semaphores(struct 
vn_queue_submission *submit,
       struct vn_semaphore *sem = vn_semaphore_from_handle(wait_sems[i]);
       const struct vn_sync_payload *payload = sem->payload;
 
-      if (payload->type == VN_SYNC_TYPE_IMPORTED_SYNC_FD)
+      if (payload->type != VN_SYNC_TYPE_IMPORTED_SYNC_FD)
+         continue;
+
+      struct vn_queue *queue = vn_queue_from_handle(submit->queue);
+      struct vn_device *dev = queue->device;
+      if (dev->physical_device->renderer_sync_fd_semaphore_features &
+          VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT) {
+         if (!vn_semaphore_wait_external(dev, sem))
+            return VK_ERROR_DEVICE_LOST;
+
+         const VkImportSemaphoreResourceInfo100000MESA res_info = {
+            .sType =
+               VK_STRUCTURE_TYPE_IMPORT_SEMAPHORE_RESOURCE_INFO_100000_MESA,
+            .semaphore = wait_sems[i],
+            .resourceId = 0,
+         };
+         vn_async_vkImportSemaphoreResource100000MESA(
+            dev->instance, vn_device_to_handle(dev), &res_info);
+      } else {
          submit->wait_external_count++;
+      }
    }
+
+   return VK_SUCCESS;
 }
 
-static void
+static VkResult
 vn_queue_submission_count_semaphores(struct vn_queue_submission *submit)
 {
    submit->wait_semaphore_count = 0;
    submit->wait_external_count = 0;
 
-   for (uint32_t i = 0; i < submit->batch_count; i++)
-      vn_queue_submission_count_batch_semaphores(submit, i);
+   for (uint32_t i = 0; i < submit->batch_count; i++) {
+      VkResult result = vn_queue_submission_count_batch_semaphores(submit, i);
+      if (result != VK_SUCCESS)
+         return result;
+   }
+
+   return VK_SUCCESS;
 }
 
 static VkResult
@@ -290,9 +316,11 @@ vn_queue_submission_prepare_submit(struct 
vn_queue_submission *submit,
    submit->submit_batches = submit_batches;
    submit->fence = fence;
 
-   vn_queue_submission_count_semaphores(submit);
+   VkResult result = vn_queue_submission_count_semaphores(submit);
+   if (result != VK_SUCCESS)
+      return result;
 
-   VkResult result = vn_queue_submission_alloc_storage(submit);
+   result = vn_queue_submission_alloc_storage(submit);
    if (result != VK_SUCCESS)
       return result;
 
@@ -317,9 +345,11 @@ vn_queue_submission_prepare_bind_sparse(
    submit->bind_sparse_batches = bind_sparse_batches;
    submit->fence = fence;
 
-   vn_queue_submission_count_semaphores(submit);
+   VkResult result = vn_queue_submission_count_semaphores(submit);
+   if (result != VK_SUCCESS)
+      return result;
 
-   VkResult result = vn_queue_submission_alloc_storage(submit);
+   result = vn_queue_submission_alloc_storage(submit);
    if (result != VK_SUCCESS)
       return result;
 

Reply via email to