diff --git a/backends/vulkan/runtime/api/Context.cpp b/backends/vulkan/runtime/api/Context.cpp index 6a80b912a9a..64d940d44fb 100644 --- a/backends/vulkan/runtime/api/Context.cpp +++ b/backends/vulkan/runtime/api/Context.cpp @@ -39,6 +39,7 @@ Context::Context(vkapi::Adapter* adapter, const ContextConfig& config) // Command buffer submission cmd_mutex_{}, cmd_(VK_NULL_HANDLE, VK_NULL_HANDLE, 0u), + prev_semaphore_(VK_NULL_HANDLE), submit_count_{0u}, // Memory Management buffer_clearlist_mutex_{}, @@ -195,10 +196,21 @@ void Context::register_blit( } void Context::submit_cmd_to_gpu(VkFence fence_handle, const bool final_use) { + // Wait semaphore would be previous command buffer's signal semaphore + VkSemaphore wait_semaphore = prev_semaphore_; + // Signal semaphore for the the current command buffer + VkSemaphore signal_semaphore = cmd_.get_signal_semaphore(); + // Next command buffer would wait on this command buffer's signal semaphore + prev_semaphore_ = signal_semaphore; + if (cmd_) { cmd_.end(); adapter_p_->submit_cmd( - queue_, cmd_.get_submit_handle(final_use), fence_handle); + queue_, + cmd_.get_submit_handle(final_use), + fence_handle, + wait_semaphore, + signal_semaphore); submit_count_ = 0u; } @@ -214,6 +226,8 @@ void Context::flush() { if (cmd_) { cmd_.invalidate(); } + // Reset previous command buffer semaphore + prev_semaphore_ = VK_NULL_HANDLE; std::lock_guard bufferlist_lock(buffer_clearlist_mutex_); std::lock_guard imagelist_lock(image_clearlist_mutex_); diff --git a/backends/vulkan/runtime/api/Context.h b/backends/vulkan/runtime/api/Context.h index e55ddcca141..9d8e7c92255 100644 --- a/backends/vulkan/runtime/api/Context.h +++ b/backends/vulkan/runtime/api/Context.h @@ -68,6 +68,8 @@ class Context final { // Command buffers submission std::mutex cmd_mutex_; vkapi::CommandBuffer cmd_; + // Semaphore for the previously submitted command buffer, if any + VkSemaphore prev_semaphore_; uint32_t submit_count_; // Memory Management std::mutex buffer_clearlist_mutex_;