From f4f3c15c1e801760876da1fe292f24bd9f47b8ad Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Fri, 4 Nov 2022 17:32:06 +0100 Subject: [PATCH] render/vulkan: always wait for last stage to complete before rendering When we have multiple command buffers in flight, we need to make sure we don't start rendering before the previous texture uploads are complete. --- include/render/vulkan.h | 1 + render/vulkan/renderer.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/include/render/vulkan.h b/include/render/vulkan.h index 517dc451..716c5ace 100644 --- a/include/render/vulkan.h +++ b/include/render/vulkan.h @@ -195,6 +195,7 @@ struct wlr_vk_renderer { struct { struct wlr_vk_command_buffer *cb; + uint64_t last_timeline_point; struct wl_list buffers; // wlr_vk_shared_buffer.link } stage; diff --git a/render/vulkan/renderer.c b/render/vulkan/renderer.c index dd3ec94c..72f09121 100644 --- a/render/vulkan/renderer.c +++ b/render/vulkan/renderer.c @@ -860,6 +860,8 @@ static void vulkan_end(struct wlr_renderer *wlr_renderer) { // and we have a renderpass dependency for that. uint64_t stage_timeline_point; VkTimelineSemaphoreSubmitInfoKHR stage_timeline_submit_info; + uint64_t stage_wait_timeline_point; + VkPipelineStageFlags stage_wait_stage; if (stage_cb != NULL) { stage_timeline_point = end_command_buffer(stage_cb, renderer); if (stage_timeline_point == 0) { @@ -878,6 +880,18 @@ static void vulkan_end(struct wlr_renderer *wlr_renderer) { stage_sub->commandBufferCount = 1u; stage_sub->pCommandBuffers = &pre_cb; ++submit_count; + + if (renderer->stage.last_timeline_point > 0) { + stage_wait_timeline_point = renderer->stage.last_timeline_point; + stage_wait_stage = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; + stage_sub->waitSemaphoreCount = 1; + stage_sub->pWaitSemaphores = &renderer->timeline_semaphore; + stage_sub->pWaitDstStageMask = &stage_wait_stage; + stage_timeline_submit_info.waitSemaphoreValueCount = 1; + stage_timeline_submit_info.pWaitSemaphoreValues = &stage_wait_timeline_point; + } + + renderer->stage.last_timeline_point = stage_timeline_point; } uint64_t render_timeline_point = end_command_buffer(render_cb, renderer);