Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions attachments/15_hello_triangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading