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.
This commit is contained in:
Simon Ser 2022-11-04 17:32:06 +01:00
parent 7fdcb45e66
commit f4f3c15c1e
2 changed files with 15 additions and 0 deletions

View File

@ -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;

View File

@ -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);