From 23508d4483f6e79f04dc00757d4380084da32623 Mon Sep 17 00:00:00 2001 From: Sascha Willems Date: Sat, 24 Oct 2026 10:32:28 +0200 Subject: [PATCH] Add note on queue wait idle Fixes #525 --- attachments/15_hello_triangle.cpp | 4 ++-- .../03_Drawing/02_Rendering_and_presentation.adoc | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/attachments/15_hello_triangle.cpp b/attachments/15_hello_triangle.cpp index e7bbada4..d90a1191 100644 --- a/attachments/15_hello_triangle.cpp +++ b/attachments/15_hello_triangle.cpp @@ -490,8 +490,8 @@ class HelloTriangleApplication recordCommandBuffer(imageIndex); - queue.waitIdle(); // NOTE: for simplicity, wait for the queue to be idle before starting the frame - // In the next chapter you see how to use multiple frames in flight and fences to sync + queue.waitIdle(); // NOTE: for simplicity, wait for the queue to be idle before submitting, so renderFinishedSemaphore is no longer in use by the previous present + // In the next chapter you see how to use multiple frames in flight and a semaphore per swap chain image to sync vk::PipelineStageFlags waitDestinationStageMask(vk::PipelineStageFlagBits::eColorAttachmentOutput); const vk::SubmitInfo submitInfo{.waitSemaphoreCount = 1, diff --git a/en/03_Drawing_a_triangle/03_Drawing/02_Rendering_and_presentation.adoc b/en/03_Drawing_a_triangle/03_Drawing/02_Rendering_and_presentation.adoc index b807c4bf..58816978 100644 --- a/en/03_Drawing_a_triangle/03_Drawing/02_Rendering_and_presentation.adoc +++ b/en/03_Drawing_a_triangle/03_Drawing/02_Rendering_and_presentation.adoc @@ -267,6 +267,19 @@ Now call the function `recordCommandBuffer` to record the commands we want. recordCommandBuffer(imageIndex); ---- +Before we submit the recorded command buffer, there is one more thing to take care of. +The fence we wait on at the start of `drawFrame` is signaled when the submitted work has finished, but it says nothing about the presentation of the previous frame, which waits on `renderFinishedSemaphore`. +Since we only have a single `renderFinishedSemaphore`, submitting again while the presentation engine may still be waiting on it would signal a semaphore that is still in use. +To keep this chapter simple, we make the queue wait until all of its previous work, including the presentation, has completed: + +[,c++] +---- +queue.waitIdle(); +---- + +This is a very rudimentary form of synchronization, and it prevents the CPU and the GPU from working in parallel. This shouldn't be used in production. +In the xref:./03_Frames_in_flight.adoc[next chapter] we'll replace it by using multiple frames in flight and a `renderFinishedSemaphore` for each swap chain image. + With a fully recorded command buffer, we can now submit it. == Submitting the command buffer