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

Author: Juston Li <[email protected]>
Date:   Tue Feb  7 09:59:23 2023 -0800

venus: refactor semaphore helper functions

Change to inline functions using conditional operators

Signed-off-by: Juston Li <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20500>

---

 src/virtio/vulkan/vn_queue.c | 77 +++++++++++++++++++-------------------------
 1 file changed, 34 insertions(+), 43 deletions(-)

diff --git a/src/virtio/vulkan/vn_queue.c b/src/virtio/vulkan/vn_queue.c
index 8d51a6e6c48..7fc1cc0c34c 100644
--- a/src/virtio/vulkan/vn_queue.c
+++ b/src/virtio/vulkan/vn_queue.c
@@ -72,69 +72,60 @@ struct vn_queue_submission {
    } temp;
 };
 
-static uint32_t
+static inline uint32_t
 vn_get_wait_semaphore_count(struct vn_queue_submission *submit,
                             uint32_t batch_index)
 {
-   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;
-   default:
-      unreachable("unexpected batch type");
-   }
+   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;
 }
 
-static uint32_t
+static inline uint32_t
 vn_get_signal_semaphore_count(struct vn_queue_submission *submit,
                               uint32_t batch_index)
 {
-   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;
-   default:
-      unreachable("unexpected batch type");
-   }
+   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;
 }
 
-static VkSemaphore
+static inline VkSemaphore
 vn_get_wait_semaphore(struct vn_queue_submission *submit,
                       uint32_t batch_index,
                       uint32_t semaphore_index)
 {
-
-   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;
-   default:
-      unreachable("unexpected batch type");
-   }
+   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;
 }
 
-static VkSemaphore
+static inline VkSemaphore
 vn_get_signal_semaphore(struct vn_queue_submission *submit,
                         uint32_t batch_index,
                         uint32_t semaphore_index)
 {
-   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;
-   default:
-      unreachable("unexpected batch type");
-   }
+   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;
 }
 
 static VkResult

Reply via email to