venus: add helper function support for VkBindSparseInfo
authorJuston Li <justonli@google.com>
Wed, 19 Apr 2023 19:03:26 +0000 (12:03 -0700)
committerMarge Bot <emma+marge@anholt.net>
Tue, 9 May 2023 04:35:16 +0000 (04:35 +0000)
add getter/setters for VkBindSparseInfo so we can at least share
vn_queue_submission_prepare() to handle external semaphores and
check for fence/semaphore feedback

Signed-off-by: Juston Li <justonli@google.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22616>

src/virtio/vulkan/vn_queue.c

index dfa5dbf..57ba3cb 100644 (file)
@@ -55,6 +55,7 @@ struct vn_queue_submission {
       const void *batches;
       const VkSubmitInfo *submit_batches;
       const VkSubmitInfo2 *submit_batches2;
+      const VkBindSparseInfo *sparse_batches;
    };
    VkFence fence_handle;
 
@@ -94,24 +95,32 @@ static inline uint32_t
 vn_get_wait_semaphore_count(struct vn_queue_submission *submit,
                             uint32_t batch_index)
 {
-   assert((submit->batch_type == VK_STRUCTURE_TYPE_SUBMIT_INFO) ||
-          (submit->batch_type == VK_STRUCTURE_TYPE_SUBMIT_INFO_2));
-
-   return submit->batch_type == VK_STRUCTURE_TYPE_SUBMIT_INFO
-             ? submit->submit_batches[batch_index].waitSemaphoreCount
-             : submit->submit_batches2[batch_index].waitSemaphoreInfoCount;
+   switch (submit->batch_type) {
+   case VK_STRUCTURE_TYPE_SUBMIT_INFO:
+      return submit->submit_batches[batch_index].waitSemaphoreCount;
+   case VK_STRUCTURE_TYPE_SUBMIT_INFO_2:
+      return submit->submit_batches2[batch_index].waitSemaphoreInfoCount;
+   case VK_STRUCTURE_TYPE_BIND_SPARSE_INFO:
+      return submit->sparse_batches[batch_index].waitSemaphoreCount;
+   default:
+      unreachable("unexpected batch type");
+   }
 }
 
 static inline uint32_t
 vn_get_signal_semaphore_count(struct vn_queue_submission *submit,
                               uint32_t batch_index)
 {
-   assert((submit->batch_type == VK_STRUCTURE_TYPE_SUBMIT_INFO) ||
-          (submit->batch_type == VK_STRUCTURE_TYPE_SUBMIT_INFO_2));
-
-   return submit->batch_type == VK_STRUCTURE_TYPE_SUBMIT_INFO
-             ? submit->submit_batches[batch_index].signalSemaphoreCount
-             : submit->submit_batches2[batch_index].signalSemaphoreInfoCount;
+   switch (submit->batch_type) {
+   case VK_STRUCTURE_TYPE_SUBMIT_INFO:
+      return submit->submit_batches[batch_index].signalSemaphoreCount;
+   case VK_STRUCTURE_TYPE_SUBMIT_INFO_2:
+      return submit->submit_batches2[batch_index].signalSemaphoreInfoCount;
+   case VK_STRUCTURE_TYPE_BIND_SPARSE_INFO:
+      return submit->sparse_batches[batch_index].signalSemaphoreCount;
+   default:
+      unreachable("unexpected batch type");
+   }
 }
 
 static inline VkSemaphore
@@ -119,15 +128,20 @@ vn_get_wait_semaphore(struct vn_queue_submission *submit,
                       uint32_t batch_index,
                       uint32_t semaphore_index)
 {
-   assert((submit->batch_type == VK_STRUCTURE_TYPE_SUBMIT_INFO) ||
-          (submit->batch_type == VK_STRUCTURE_TYPE_SUBMIT_INFO_2));
-
-   return submit->batch_type == VK_STRUCTURE_TYPE_SUBMIT_INFO
-             ? submit->submit_batches[batch_index]
-                  .pWaitSemaphores[semaphore_index]
-             : submit->submit_batches2[batch_index]
-                  .pWaitSemaphoreInfos[semaphore_index]
-                  .semaphore;
+   switch (submit->batch_type) {
+   case VK_STRUCTURE_TYPE_SUBMIT_INFO:
+      return submit->submit_batches[batch_index]
+         .pWaitSemaphores[semaphore_index];
+   case VK_STRUCTURE_TYPE_SUBMIT_INFO_2:
+      return submit->submit_batches2[batch_index]
+         .pWaitSemaphoreInfos[semaphore_index]
+         .semaphore;
+   case VK_STRUCTURE_TYPE_BIND_SPARSE_INFO:
+      return submit->sparse_batches[batch_index]
+         .pWaitSemaphores[semaphore_index];
+   default:
+      unreachable("unexpected batch type");
+   }
 }
 
 static inline VkSemaphore
@@ -135,27 +149,36 @@ vn_get_signal_semaphore(struct vn_queue_submission *submit,
                         uint32_t batch_index,
                         uint32_t semaphore_index)
 {
-   assert((submit->batch_type == VK_STRUCTURE_TYPE_SUBMIT_INFO) ||
-          (submit->batch_type == VK_STRUCTURE_TYPE_SUBMIT_INFO_2));
-
-   return submit->batch_type == VK_STRUCTURE_TYPE_SUBMIT_INFO
-             ? submit->submit_batches[batch_index]
-                  .pSignalSemaphores[semaphore_index]
-             : submit->submit_batches2[batch_index]
-                  .pSignalSemaphoreInfos[semaphore_index]
-                  .semaphore;
+   switch (submit->batch_type) {
+   case VK_STRUCTURE_TYPE_SUBMIT_INFO:
+      return submit->submit_batches[batch_index]
+         .pSignalSemaphores[semaphore_index];
+   case VK_STRUCTURE_TYPE_SUBMIT_INFO_2:
+      return submit->submit_batches2[batch_index]
+         .pSignalSemaphoreInfos[semaphore_index]
+         .semaphore;
+   case VK_STRUCTURE_TYPE_BIND_SPARSE_INFO:
+      return submit->sparse_batches[batch_index]
+         .pSignalSemaphores[semaphore_index];
+   default:
+      unreachable("unexpected batch type");
+   }
 }
 
 static inline uint32_t
 vn_get_cmd_buffer_count(struct vn_queue_submission *submit,
                         uint32_t batch_index)
 {
-   assert((submit->batch_type == VK_STRUCTURE_TYPE_SUBMIT_INFO) ||
-          (submit->batch_type == VK_STRUCTURE_TYPE_SUBMIT_INFO_2));
-
-   return submit->batch_type == VK_STRUCTURE_TYPE_SUBMIT_INFO
-             ? submit->submit_batches[batch_index].commandBufferCount
-             : submit->submit_batches2[batch_index].commandBufferInfoCount;
+   switch (submit->batch_type) {
+   case VK_STRUCTURE_TYPE_SUBMIT_INFO:
+      return submit->submit_batches[batch_index].commandBufferCount;
+   case VK_STRUCTURE_TYPE_SUBMIT_INFO_2:
+      return submit->submit_batches2[batch_index].commandBufferInfoCount;
+   case VK_STRUCTURE_TYPE_BIND_SPARSE_INFO:
+      return submit->sparse_batches[batch_index].bufferBindCount;
+   default:
+      unreachable("unexpected batch type");
+   }
 }
 
 static inline const void *