Skip to content

Commit c57e29c

Browse files
committed
Carry changes to all other chapters.
1 parent 5d60291 commit c57e29c

21 files changed

Lines changed: 394 additions & 520 deletions

attachments/18_vertex_input.cpp

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -532,13 +532,18 @@ class HelloTriangleApplication
532532

533533
auto [result, imageIndex] = swapChain.acquireNextImage(UINT64_MAX, *presentCompleteSemaphores[frameIndex], nullptr);
534534

535+
// Due to VULKAN_HPP_HANDLE_ERROR_OUT_OF_DATE_AS_SUCCESS being defined, eErrorOutOfDateKHR can be checked as a result
536+
// here and does not need to be caught by an exception.
535537
if (result == vk::Result::eErrorOutOfDateKHR)
536538
{
537539
recreateSwapChain();
538540
return;
539541
}
542+
// On other success codes than eSuccess and eSuboptimalKHR we just throw an exception.
543+
// On any error code, aquireNextImage already threw an exception.
540544
if (result != vk::Result::eSuccess && result != vk::Result::eSuboptimalKHR)
541545
{
546+
assert(result == vk::Result::eTimeout || result == vk::Result::eNotReady);
542547
throw std::runtime_error("failed to acquire swap chain image!");
543548
}
544549

@@ -556,37 +561,25 @@ class HelloTriangleApplication
556561
.pSignalSemaphores = &*renderFinishedSemaphores[imageIndex]};
557562
queue.submit(submitInfo, *inFlightFences[frameIndex]);
558563

559-
try
564+
const vk::PresentInfoKHR presentInfoKHR{.waitSemaphoreCount = 1,
565+
.pWaitSemaphores = &*renderFinishedSemaphores[imageIndex],
566+
.swapchainCount = 1,
567+
.pSwapchains = &*swapChain,
568+
.pImageIndices = &imageIndex};
569+
result = queue.presentKHR(presentInfoKHR);
570+
// Due to VULKAN_HPP_HANDLE_ERROR_OUT_OF_DATE_AS_SUCCESS being defined, eErrorOutOfDateKHR can be checked as a result
571+
// here and does not need to be caught by an exception.
572+
if ((result == vk::Result::eSuboptimalKHR) || (result == vk::Result::eErrorOutOfDateKHR) || framebufferResized)
560573
{
561-
const vk::PresentInfoKHR presentInfoKHR{.waitSemaphoreCount = 1,
562-
.pWaitSemaphores = &*renderFinishedSemaphores[imageIndex],
563-
.swapchainCount = 1,
564-
.pSwapchains = &*swapChain,
565-
.pImageIndices = &imageIndex};
566-
result = queue.presentKHR(presentInfoKHR);
567-
if (result == vk::Result::eErrorOutOfDateKHR || result == vk::Result::eSuboptimalKHR || framebufferResized)
568-
{
569-
framebufferResized = false;
570-
recreateSwapChain();
571-
}
572-
else if (result != vk::Result::eSuccess)
573-
{
574-
throw std::runtime_error("failed to present swap chain image!");
575-
}
574+
framebufferResized = false;
575+
recreateSwapChain();
576576
}
577-
catch (const vk::SystemError &e)
577+
else
578578
{
579-
if (e.code().value() == static_cast<int>(vk::Result::eErrorOutOfDateKHR))
580-
{
581-
recreateSwapChain();
582-
return;
583-
}
584-
else
585-
{
586-
throw;
587-
}
579+
// There are no other success codes than eSuccess; on any error code, presentKHR already threw an exception.
580+
assert(result == vk::Result::eSuccess);
588581
}
589-
frameIndex = (frameIndex + 1) % MAX_FRAMES_IN_FLIGHT;
582+
frameIndex = (frameIndex + 1) % MAX_FRAMES_IN_FLIGHT;
590583
}
591584

592585
[[nodiscard]] vk::raii::ShaderModule createShaderModule(const std::vector<char> &code) const

attachments/19_vertex_buffer.cpp

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -568,13 +568,18 @@ class HelloTriangleApplication
568568

569569
auto [result, imageIndex] = swapChain.acquireNextImage(UINT64_MAX, *presentCompleteSemaphores[frameIndex], nullptr);
570570

571+
// Due to VULKAN_HPP_HANDLE_ERROR_OUT_OF_DATE_AS_SUCCESS being defined, eErrorOutOfDateKHR can be checked as a result
572+
// here and does not need to be caught by an exception.
571573
if (result == vk::Result::eErrorOutOfDateKHR)
572574
{
573575
recreateSwapChain();
574576
return;
575577
}
578+
// On other success codes than eSuccess and eSuboptimalKHR we just throw an exception.
579+
// On any error code, aquireNextImage already threw an exception.
576580
if (result != vk::Result::eSuccess && result != vk::Result::eSuboptimalKHR)
577581
{
582+
assert(result == vk::Result::eTimeout || result == vk::Result::eNotReady);
578583
throw std::runtime_error("failed to acquire swap chain image!");
579584
}
580585

@@ -592,35 +597,23 @@ class HelloTriangleApplication
592597
.pSignalSemaphores = &*renderFinishedSemaphores[imageIndex]};
593598
queue.submit(submitInfo, *inFlightFences[frameIndex]);
594599

595-
try
600+
const vk::PresentInfoKHR presentInfoKHR{.waitSemaphoreCount = 1,
601+
.pWaitSemaphores = &*renderFinishedSemaphores[imageIndex],
602+
.swapchainCount = 1,
603+
.pSwapchains = &*swapChain,
604+
.pImageIndices = &imageIndex};
605+
result = queue.presentKHR(presentInfoKHR);
606+
// Due to VULKAN_HPP_HANDLE_ERROR_OUT_OF_DATE_AS_SUCCESS being defined, eErrorOutOfDateKHR can be checked as a result
607+
// here and does not need to be caught by an exception.
608+
if ((result == vk::Result::eSuboptimalKHR) || (result == vk::Result::eErrorOutOfDateKHR) || framebufferResized)
596609
{
597-
const vk::PresentInfoKHR presentInfoKHR{.waitSemaphoreCount = 1,
598-
.pWaitSemaphores = &*renderFinishedSemaphores[imageIndex],
599-
.swapchainCount = 1,
600-
.pSwapchains = &*swapChain,
601-
.pImageIndices = &imageIndex};
602-
result = queue.presentKHR(presentInfoKHR);
603-
if (result == vk::Result::eErrorOutOfDateKHR || result == vk::Result::eSuboptimalKHR || framebufferResized)
604-
{
605-
framebufferResized = false;
606-
recreateSwapChain();
607-
}
608-
else if (result != vk::Result::eSuccess)
609-
{
610-
throw std::runtime_error("failed to present swap chain image!");
611-
}
610+
framebufferResized = false;
611+
recreateSwapChain();
612612
}
613-
catch (const vk::SystemError &e)
613+
else
614614
{
615-
if (e.code().value() == static_cast<int>(vk::Result::eErrorOutOfDateKHR))
616-
{
617-
recreateSwapChain();
618-
return;
619-
}
620-
else
621-
{
622-
throw;
623-
}
615+
// There are no other success codes than eSuccess; on any error code, presentKHR already threw an exception.
616+
assert(result == vk::Result::eSuccess);
624617
}
625618
frameIndex = (frameIndex + 1) % MAX_FRAMES_IN_FLIGHT;
626619
}

attachments/20_staging_buffer.cpp

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -588,13 +588,18 @@ class HelloTriangleApplication
588588

589589
auto [result, imageIndex] = swapChain.acquireNextImage(UINT64_MAX, *presentCompleteSemaphores[frameIndex], nullptr);
590590

591+
// Due to VULKAN_HPP_HANDLE_ERROR_OUT_OF_DATE_AS_SUCCESS being defined, eErrorOutOfDateKHR can be checked as a result
592+
// here and does not need to be caught by an exception.
591593
if (result == vk::Result::eErrorOutOfDateKHR)
592594
{
593595
recreateSwapChain();
594596
return;
595597
}
598+
// On other success codes than eSuccess and eSuboptimalKHR we just throw an exception.
599+
// On any error code, aquireNextImage already threw an exception.
596600
if (result != vk::Result::eSuccess && result != vk::Result::eSuboptimalKHR)
597601
{
602+
assert(result == vk::Result::eTimeout || result == vk::Result::eNotReady);
598603
throw std::runtime_error("failed to acquire swap chain image!");
599604
}
600605

@@ -612,35 +617,23 @@ class HelloTriangleApplication
612617
.pSignalSemaphores = &*renderFinishedSemaphores[imageIndex]};
613618
queue.submit(submitInfo, *inFlightFences[frameIndex]);
614619

615-
try
620+
const vk::PresentInfoKHR presentInfoKHR{.waitSemaphoreCount = 1,
621+
.pWaitSemaphores = &*renderFinishedSemaphores[imageIndex],
622+
.swapchainCount = 1,
623+
.pSwapchains = &*swapChain,
624+
.pImageIndices = &imageIndex};
625+
result = queue.presentKHR(presentInfoKHR);
626+
// Due to VULKAN_HPP_HANDLE_ERROR_OUT_OF_DATE_AS_SUCCESS being defined, eErrorOutOfDateKHR can be checked as a result
627+
// here and does not need to be caught by an exception.
628+
if ((result == vk::Result::eSuboptimalKHR) || (result == vk::Result::eErrorOutOfDateKHR) || framebufferResized)
616629
{
617-
const vk::PresentInfoKHR presentInfoKHR{.waitSemaphoreCount = 1,
618-
.pWaitSemaphores = &*renderFinishedSemaphores[imageIndex],
619-
.swapchainCount = 1,
620-
.pSwapchains = &*swapChain,
621-
.pImageIndices = &imageIndex};
622-
result = queue.presentKHR(presentInfoKHR);
623-
if (result == vk::Result::eErrorOutOfDateKHR || result == vk::Result::eSuboptimalKHR || framebufferResized)
624-
{
625-
framebufferResized = false;
626-
recreateSwapChain();
627-
}
628-
else if (result != vk::Result::eSuccess)
629-
{
630-
throw std::runtime_error("failed to present swap chain image!");
631-
}
630+
framebufferResized = false;
631+
recreateSwapChain();
632632
}
633-
catch (const vk::SystemError &e)
633+
else
634634
{
635-
if (e.code().value() == static_cast<int>(vk::Result::eErrorOutOfDateKHR))
636-
{
637-
recreateSwapChain();
638-
return;
639-
}
640-
else
641-
{
642-
throw;
643-
}
635+
// There are no other success codes than eSuccess; on any error code, presentKHR already threw an exception.
636+
assert(result == vk::Result::eSuccess);
644637
}
645638
frameIndex = (frameIndex + 1) % MAX_FRAMES_IN_FLIGHT;
646639
}

attachments/21_index_buffer.cpp

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -614,13 +614,18 @@ class HelloTriangleApplication
614614

615615
auto [result, imageIndex] = swapChain.acquireNextImage(UINT64_MAX, *presentCompleteSemaphores[frameIndex], nullptr);
616616

617+
// Due to VULKAN_HPP_HANDLE_ERROR_OUT_OF_DATE_AS_SUCCESS being defined, eErrorOutOfDateKHR can be checked as a result
618+
// here and does not need to be caught by an exception.
617619
if (result == vk::Result::eErrorOutOfDateKHR)
618620
{
619621
recreateSwapChain();
620622
return;
621623
}
624+
// On other success codes than eSuccess and eSuboptimalKHR we just throw an exception.
625+
// On any error code, aquireNextImage already threw an exception.
622626
if (result != vk::Result::eSuccess && result != vk::Result::eSuboptimalKHR)
623627
{
628+
assert(result == vk::Result::eTimeout || result == vk::Result::eNotReady);
624629
throw std::runtime_error("failed to acquire swap chain image!");
625630
}
626631

@@ -638,35 +643,23 @@ class HelloTriangleApplication
638643
.pSignalSemaphores = &*renderFinishedSemaphores[imageIndex]};
639644
queue.submit(submitInfo, *inFlightFences[frameIndex]);
640645

641-
try
646+
const vk::PresentInfoKHR presentInfoKHR{.waitSemaphoreCount = 1,
647+
.pWaitSemaphores = &*renderFinishedSemaphores[imageIndex],
648+
.swapchainCount = 1,
649+
.pSwapchains = &*swapChain,
650+
.pImageIndices = &imageIndex};
651+
result = queue.presentKHR(presentInfoKHR);
652+
// Due to VULKAN_HPP_HANDLE_ERROR_OUT_OF_DATE_AS_SUCCESS being defined, eErrorOutOfDateKHR can be checked as a result
653+
// here and does not need to be caught by an exception.
654+
if ((result == vk::Result::eSuboptimalKHR) || (result == vk::Result::eErrorOutOfDateKHR) || framebufferResized)
642655
{
643-
const vk::PresentInfoKHR presentInfoKHR{.waitSemaphoreCount = 1,
644-
.pWaitSemaphores = &*renderFinishedSemaphores[imageIndex],
645-
.swapchainCount = 1,
646-
.pSwapchains = &*swapChain,
647-
.pImageIndices = &imageIndex};
648-
result = queue.presentKHR(presentInfoKHR);
649-
if (result == vk::Result::eErrorOutOfDateKHR || result == vk::Result::eSuboptimalKHR || framebufferResized)
650-
{
651-
framebufferResized = false;
652-
recreateSwapChain();
653-
}
654-
else if (result != vk::Result::eSuccess)
655-
{
656-
throw std::runtime_error("failed to present swap chain image!");
657-
}
656+
framebufferResized = false;
657+
recreateSwapChain();
658658
}
659-
catch (const vk::SystemError &e)
659+
else
660660
{
661-
if (e.code().value() == static_cast<int>(vk::Result::eErrorOutOfDateKHR))
662-
{
663-
recreateSwapChain();
664-
return;
665-
}
666-
else
667-
{
668-
throw;
669-
}
661+
// There are no other success codes than eSuccess; on any error code, presentKHR already threw an exception.
662+
assert(result == vk::Result::eSuccess);
670663
}
671664
frameIndex = (frameIndex + 1) % MAX_FRAMES_IN_FLIGHT;
672665
}

attachments/22_descriptor_layout.cpp

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -673,13 +673,18 @@ class HelloTriangleApplication
673673

674674
auto [result, imageIndex] = swapChain.acquireNextImage(UINT64_MAX, *presentCompleteSemaphores[frameIndex], nullptr);
675675

676+
// Due to VULKAN_HPP_HANDLE_ERROR_OUT_OF_DATE_AS_SUCCESS being defined, eErrorOutOfDateKHR can be checked as a result
677+
// here and does not need to be caught by an exception.
676678
if (result == vk::Result::eErrorOutOfDateKHR)
677679
{
678680
recreateSwapChain();
679681
return;
680682
}
683+
// On other success codes than eSuccess and eSuboptimalKHR we just throw an exception.
684+
// On any error code, aquireNextImage already threw an exception.
681685
if (result != vk::Result::eSuccess && result != vk::Result::eSuboptimalKHR)
682686
{
687+
assert(result == vk::Result::eTimeout || result == vk::Result::eNotReady);
683688
throw std::runtime_error("failed to acquire swap chain image!");
684689
}
685690
updateUniformBuffer(frameIndex);
@@ -698,35 +703,23 @@ class HelloTriangleApplication
698703
.pSignalSemaphores = &*renderFinishedSemaphores[imageIndex]};
699704
queue.submit(submitInfo, *inFlightFences[frameIndex]);
700705

701-
try
706+
const vk::PresentInfoKHR presentInfoKHR{.waitSemaphoreCount = 1,
707+
.pWaitSemaphores = &*renderFinishedSemaphores[imageIndex],
708+
.swapchainCount = 1,
709+
.pSwapchains = &*swapChain,
710+
.pImageIndices = &imageIndex};
711+
result = queue.presentKHR(presentInfoKHR);
712+
// Due to VULKAN_HPP_HANDLE_ERROR_OUT_OF_DATE_AS_SUCCESS being defined, eErrorOutOfDateKHR can be checked as a result
713+
// here and does not need to be caught by an exception.
714+
if ((result == vk::Result::eSuboptimalKHR) || (result == vk::Result::eErrorOutOfDateKHR) || framebufferResized)
702715
{
703-
const vk::PresentInfoKHR presentInfoKHR{.waitSemaphoreCount = 1,
704-
.pWaitSemaphores = &*renderFinishedSemaphores[imageIndex],
705-
.swapchainCount = 1,
706-
.pSwapchains = &*swapChain,
707-
.pImageIndices = &imageIndex};
708-
result = queue.presentKHR(presentInfoKHR);
709-
if (result == vk::Result::eErrorOutOfDateKHR || result == vk::Result::eSuboptimalKHR || framebufferResized)
710-
{
711-
framebufferResized = false;
712-
recreateSwapChain();
713-
}
714-
else if (result != vk::Result::eSuccess)
715-
{
716-
throw std::runtime_error("failed to present swap chain image!");
717-
}
716+
framebufferResized = false;
717+
recreateSwapChain();
718718
}
719-
catch (const vk::SystemError &e)
719+
else
720720
{
721-
if (e.code().value() == static_cast<int>(vk::Result::eErrorOutOfDateKHR))
722-
{
723-
recreateSwapChain();
724-
return;
725-
}
726-
else
727-
{
728-
throw;
729-
}
721+
// There are no other success codes than eSuccess; on any error code, presentKHR already threw an exception.
722+
assert(result == vk::Result::eSuccess);
730723
}
731724
frameIndex = (frameIndex + 1) % MAX_FRAMES_IN_FLIGHT;
732725
}

0 commit comments

Comments
 (0)