Skip to content

Commit 1532157

Browse files
committed
Carry changes to all other chapters.
1 parent 9796ad7 commit 1532157

21 files changed

+394
-520
lines changed

attachments/18_vertex_input.cpp

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

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

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

@@ -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
@@ -569,13 +569,18 @@ class HelloTriangleApplication
569569

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

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

@@ -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
@@ -589,13 +589,18 @@ class HelloTriangleApplication
589589

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

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

@@ -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
@@ -615,13 +615,18 @@ class HelloTriangleApplication
615615

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

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

@@ -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
@@ -674,13 +674,18 @@ class HelloTriangleApplication
674674

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

677+
// Due to VULKAN_HPP_HANDLE_ERROR_OUT_OF_DATE_AS_SUCCESS being defined, eErrorOutOfDateKHR can be checked as a result
678+
// here and does not need to be caught by an exception.
677679
if (result == vk::Result::eErrorOutOfDateKHR)
678680
{
679681
recreateSwapChain();
680682
return;
681683
}
684+
// On other success codes than eSuccess and eSuboptimalKHR we just throw an exception.
685+
// On any error code, aquireNextImage already threw an exception.
682686
if (result != vk::Result::eSuccess && result != vk::Result::eSuboptimalKHR)
683687
{
688+
assert(result == vk::Result::eTimeout || result == vk::Result::eNotReady);
684689
throw std::runtime_error("failed to acquire swap chain image!");
685690
}
686691
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)