From e3a9cab00e62e0cd7f436ef4135258158552696a Mon Sep 17 00:00:00 2001 From: Sergey Kosarevsky Date: Tue, 14 Jan 2025 20:58:53 -0800 Subject: [PATCH] Use `vkQueueSubmit2()` --- lvk/vulkan/VulkanClasses.cpp | 49 ++++++++++++++++++++---------------- lvk/vulkan/VulkanClasses.h | 6 +++-- 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/lvk/vulkan/VulkanClasses.cpp b/lvk/vulkan/VulkanClasses.cpp index bbf8b8f0b2b..a9fb9b53f6a 100644 --- a/lvk/vulkan/VulkanClasses.cpp +++ b/lvk/vulkan/VulkanClasses.cpp @@ -1515,36 +1515,43 @@ lvk::SubmitHandle lvk::VulkanImmediateCommands::submit(const CommandBufferWrappe LVK_ASSERT(wrapper.isEncoding_); VK_ASSERT(vkEndCommandBuffer(wrapper.cmdBuf_)); - const VkPipelineStageFlags waitStageMasks[] = {VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; - VkSemaphore waitSemaphores[] = {VK_NULL_HANDLE, VK_NULL_HANDLE}; + VkSemaphoreSubmitInfo waitSemaphores[] = {{}, {}}; uint32_t numWaitSemaphores = 0; - if (waitSemaphore_) { + if (waitSemaphore_.semaphore) { waitSemaphores[numWaitSemaphores++] = waitSemaphore_; } - if (lastSubmitSemaphore_) { + if (lastSubmitSemaphore_.semaphore) { waitSemaphores[numWaitSemaphores++] = lastSubmitSemaphore_; } + VkSemaphoreSubmitInfo signalSemaphores[] = { + VkSemaphoreSubmitInfo{.sType = VK_STRUCTURE_TYPE_SEMAPHORE_SUBMIT_INFO, + .semaphore = wrapper.semaphore_, + .stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}, + }; - LVK_PROFILER_ZONE("vkQueueSubmit()", LVK_PROFILER_COLOR_SUBMIT); + LVK_PROFILER_ZONE("vkQueueSubmit2()", LVK_PROFILER_COLOR_SUBMIT); #if LVK_VULKAN_PRINT_COMMANDS - LLOGL("%p vkQueueSubmit()\n\n", wrapper.cmdBuf_); + LLOGL("%p vkQueueSubmit2()\n\n", wrapper.cmdBuf_); #endif // LVK_VULKAN_PRINT_COMMANDS - const VkSubmitInfo si = { - .sType = VK_STRUCTURE_TYPE_SUBMIT_INFO, - .waitSemaphoreCount = numWaitSemaphores, - .pWaitSemaphores = numWaitSemaphores ? waitSemaphores : nullptr, - .pWaitDstStageMask = waitStageMasks, - .commandBufferCount = 1u, - .pCommandBuffers = &wrapper.cmdBuf_, - .signalSemaphoreCount = 1u, - .pSignalSemaphores = &wrapper.semaphore_, + const VkCommandBufferSubmitInfo bufferSI = { + .sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_SUBMIT_INFO, + .commandBuffer = wrapper.cmdBuf_, + }; + const VkSubmitInfo2 si = { + .sType = VK_STRUCTURE_TYPE_SUBMIT_INFO_2, + .waitSemaphoreInfoCount = numWaitSemaphores, + .pWaitSemaphoreInfos = waitSemaphores, + .commandBufferInfoCount = 1u, + .pCommandBufferInfos = &bufferSI, + .signalSemaphoreInfoCount = 1u, + .pSignalSemaphoreInfos = signalSemaphores, }; - VK_ASSERT(vkQueueSubmit(queue_, 1u, &si, wrapper.fence_)); + VK_ASSERT(vkQueueSubmit2(queue_, 1u, &si,wrapper.fence_)); LVK_PROFILER_ZONE_END(); - lastSubmitSemaphore_ = wrapper.semaphore_; + lastSubmitSemaphore_.semaphore = wrapper.semaphore_; lastSubmitHandle_ = wrapper.handle_; - waitSemaphore_ = VK_NULL_HANDLE; + waitSemaphore_.semaphore = VK_NULL_HANDLE; // reset const_cast(wrapper).isEncoding_ = false; @@ -1559,13 +1566,13 @@ lvk::SubmitHandle lvk::VulkanImmediateCommands::submit(const CommandBufferWrappe } void lvk::VulkanImmediateCommands::waitSemaphore(VkSemaphore semaphore) { - LVK_ASSERT(waitSemaphore_ == VK_NULL_HANDLE); + LVK_ASSERT(waitSemaphore_.semaphore == VK_NULL_HANDLE); - waitSemaphore_ = semaphore; + waitSemaphore_.semaphore = semaphore; } VkSemaphore lvk::VulkanImmediateCommands::acquireLastSubmitSemaphore() { - return std::exchange(lastSubmitSemaphore_, VK_NULL_HANDLE); + return std::exchange(lastSubmitSemaphore_.semaphore, VK_NULL_HANDLE); } VkFence lvk::VulkanImmediateCommands::getVkFence(lvk::SubmitHandle handle) const { diff --git a/lvk/vulkan/VulkanClasses.h b/lvk/vulkan/VulkanClasses.h index ade4051e3fd..ae1013d4860 100644 --- a/lvk/vulkan/VulkanClasses.h +++ b/lvk/vulkan/VulkanClasses.h @@ -193,8 +193,10 @@ class VulkanImmediateCommands final { CommandBufferWrapper buffers_[kMaxCommandBuffers]; SubmitHandle lastSubmitHandle_ = SubmitHandle(); SubmitHandle nextSubmitHandle_ = SubmitHandle(); - VkSemaphore lastSubmitSemaphore_ = VK_NULL_HANDLE; - VkSemaphore waitSemaphore_ = VK_NULL_HANDLE; + VkSemaphoreSubmitInfo lastSubmitSemaphore_ = {.sType = VK_STRUCTURE_TYPE_SEMAPHORE_SUBMIT_INFO, + .stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; + VkSemaphoreSubmitInfo waitSemaphore_ = {.sType = VK_STRUCTURE_TYPE_SEMAPHORE_SUBMIT_INFO, + .stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; // extra "wait" semaphore uint32_t numAvailableCommandBuffers_ = kMaxCommandBuffers; uint32_t submitCounter_ = 1; };