From aaee0ad6bb12e04fa5ea7643b23ae8998c39b2d3 Mon Sep 17 00:00:00 2001 From: Juston Li Date: Tue, 7 Feb 2023 09:59:23 -0800 Subject: [PATCH] venus: refactor semaphore helper functions Change to inline functions using conditional operators Signed-off-by: Juston Li Part-of: --- 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 8d51a6e..7fc1cc0 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 -- 2.7.4