@@ -327,7 +327,6 @@ class HelloTriangleApplication
327327 vk::PipelineShaderStageCreateInfo fragShaderStageInfo{.stage = vk::ShaderStageFlagBits::eFragment, .module = shaderModule, .pName = " fragMain" };
328328 vk::PipelineShaderStageCreateInfo shaderStages[] = {vertShaderStageInfo, fragShaderStageInfo};
329329
330-
331330 vk::PipelineVertexInputStateCreateInfo vertexInputInfo;
332331 vk::PipelineInputAssemblyStateCreateInfo inputAssembly{.topology = vk::PrimitiveTopology::eTriangleList};
333332 vk::PipelineViewportStateCreateInfo viewportState{.viewportCount = 1 , .scissorCount = 1 };
@@ -388,7 +387,8 @@ class HelloTriangleApplication
388387 void recordCommandBuffer (uint32_t imageIndex)
389388 {
390389 commandBuffer.begin ({});
391- // Before starting rendering, transition the swapchain image to COLOR_ATTACHMENT_OPTIMAL
390+
391+ // Before starting rendering, transition the swapchain image to vk::ImageLayout::eColorAttachmentOptimal
392392 transition_image_layout (
393393 imageIndex,
394394 vk::ImageLayout::eUndefined,
@@ -417,7 +417,8 @@ class HelloTriangleApplication
417417 commandBuffer.setScissor (0 , vk::Rect2D (vk::Offset2D (0 , 0 ), swapChainExtent));
418418 commandBuffer.draw (3 , 1 , 0 , 0 );
419419 commandBuffer.endRendering ();
420- // After rendering, transition the swapchain image to PRESENT_SRC
420+
421+ // After rendering, transition the swapchain image to vk::ImageLayout::ePresentSrcKHR
421422 transition_image_layout (
422423 imageIndex,
423424 vk::ImageLayout::eColorAttachmentOptimal,
@@ -471,21 +472,29 @@ class HelloTriangleApplication
471472
472473 void drawFrame ()
473474 {
474- queue.waitIdle (); // NOTE: for simplicity, wait for the queue to be idle before starting the frame
475- // In the next chapter you see how to use multiple frames in flight and fences to sync
475+ auto fenceResult = device.waitForFences (*drawFence, vk::True, UINT64_MAX);
476+ if (fenceResult != vk::Result::eSuccess)
477+ {
478+ throw std::runtime_error (" failed to wait for fence!" );
479+ }
480+ device.resetFences (*drawFence);
476481
477482 auto [result, imageIndex] = swapChain.acquireNextImage (UINT64_MAX, *presentCompleteSemaphore, nullptr );
483+
478484 recordCommandBuffer (imageIndex);
479485
480- device.resetFences (*drawFence);
486+ queue.waitIdle (); // NOTE: for simplicity, wait for the queue to be idle before starting the frame
487+ // In the next chapter you see how to use multiple frames in flight and fences to sync
488+
481489 vk::PipelineStageFlags waitDestinationStageMask (vk::PipelineStageFlagBits::eColorAttachmentOutput);
482- const vk::SubmitInfo submitInfo{.waitSemaphoreCount = 1 , .pWaitSemaphores = &*presentCompleteSemaphore, .pWaitDstStageMask = &waitDestinationStageMask, .commandBufferCount = 1 , .pCommandBuffers = &*commandBuffer, .signalSemaphoreCount = 1 , .pSignalSemaphores = &*renderFinishedSemaphore};
490+ const vk::SubmitInfo submitInfo{.waitSemaphoreCount = 1 ,
491+ .pWaitSemaphores = &*presentCompleteSemaphore,
492+ .pWaitDstStageMask = &waitDestinationStageMask,
493+ .commandBufferCount = 1 ,
494+ .pCommandBuffers = &*commandBuffer,
495+ .signalSemaphoreCount = 1 ,
496+ .pSignalSemaphores = &*renderFinishedSemaphore};
483497 queue.submit (submitInfo, *drawFence);
484- result = device.waitForFences (*drawFence, vk::True, UINT64_MAX);
485- if (result != vk::Result::eSuccess)
486- {
487- throw std::runtime_error (" failed to wait for fence!" );
488- }
489498
490499 const vk::PresentInfoKHR presentInfoKHR{.waitSemaphoreCount = 1 , .pWaitSemaphores = &*renderFinishedSemaphore, .swapchainCount = 1 , .pSwapchains = &*swapChain, .pImageIndices = &imageIndex};
491500 result = queue.presentKHR (presentInfoKHR);
0 commit comments