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
49 changes: 22 additions & 27 deletions attachments/17_swap_chain_recreation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,17 +513,24 @@ class HelloTriangleApplication

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

// Due to VULKAN_HPP_HANDLE_ERROR_OUT_OF_DATE_AS_SUCCESS being defined, eErrorOutOfDateKHR can be checked as a result
// here and does not need to be caught by an exception.
if (result == vk::Result::eErrorOutOfDateKHR)
{
recreateSwapChain();
return;
}
if (result != vk::Result::eSuccess && result != vk::Result::eSuboptimalKHR)
// On other success codes than eSuccess and eSuboptimalKHR we just throw an exception.
// On any error code, aquireNextImage already threw an exception.
else if (result != vk::Result::eSuccess && result != vk::Result::eSuboptimalKHR)
{
assert(result == vk::Result::eTimeout || result == vk::Result::eNotReady);
throw std::runtime_error("failed to acquire swap chain image!");
}

// Only reset the fence if we are submitting work
device.resetFences(*inFlightFences[frameIndex]);

commandBuffers[frameIndex].reset();
recordCommandBuffer(imageIndex);

Expand All @@ -537,35 +544,23 @@ class HelloTriangleApplication
.pSignalSemaphores = &*renderFinishedSemaphores[imageIndex]};
queue.submit(submitInfo, *inFlightFences[frameIndex]);

try
const vk::PresentInfoKHR presentInfoKHR{.waitSemaphoreCount = 1,
.pWaitSemaphores = &*renderFinishedSemaphores[imageIndex],
.swapchainCount = 1,
.pSwapchains = &*swapChain,
.pImageIndices = &imageIndex};
result = queue.presentKHR(presentInfoKHR);
// Due to VULKAN_HPP_HANDLE_ERROR_OUT_OF_DATE_AS_SUCCESS being defined, eErrorOutOfDateKHR can be checked as a result
// here and does not need to be caught by an exception.
if ((result == vk::Result::eSuboptimalKHR) || (result == vk::Result::eErrorOutOfDateKHR) || framebufferResized)
{
const vk::PresentInfoKHR presentInfoKHR{.waitSemaphoreCount = 1,
.pWaitSemaphores = &*renderFinishedSemaphores[imageIndex],
.swapchainCount = 1,
.pSwapchains = &*swapChain,
.pImageIndices = &imageIndex};
result = queue.presentKHR(presentInfoKHR);
if (result == vk::Result::eSuboptimalKHR || framebufferResized)
{
framebufferResized = false;
recreateSwapChain();
}
else if (result != vk::Result::eSuccess)
{
throw std::runtime_error("failed to present swap chain image!");
}
framebufferResized = false;
recreateSwapChain();
}
catch (const vk::SystemError &e)
else
{
if (e.code().value() == static_cast<int>(vk::Result::eErrorOutOfDateKHR))
{
recreateSwapChain();
return;
}
else
{
throw;
}
// There are no other success codes than eSuccess; on any error code, presentKHR already threw an exception.
assert(result == vk::Result::eSuccess);
}
frameIndex = (frameIndex + 1) % MAX_FRAMES_IN_FLIGHT;
}
Expand Down
49 changes: 22 additions & 27 deletions attachments/18_vertex_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,17 +532,24 @@ class HelloTriangleApplication

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

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

// Only reset the fence if we are submitting work
device.resetFences(*inFlightFences[frameIndex]);

commandBuffers[frameIndex].reset();
recordCommandBuffer(imageIndex);

Expand All @@ -556,37 +563,25 @@ class HelloTriangleApplication
.pSignalSemaphores = &*renderFinishedSemaphores[imageIndex]};
queue.submit(submitInfo, *inFlightFences[frameIndex]);

try
const vk::PresentInfoKHR presentInfoKHR{.waitSemaphoreCount = 1,
.pWaitSemaphores = &*renderFinishedSemaphores[imageIndex],
.swapchainCount = 1,
.pSwapchains = &*swapChain,
.pImageIndices = &imageIndex};
result = queue.presentKHR(presentInfoKHR);
// Due to VULKAN_HPP_HANDLE_ERROR_OUT_OF_DATE_AS_SUCCESS being defined, eErrorOutOfDateKHR can be checked as a result
// here and does not need to be caught by an exception.
if ((result == vk::Result::eSuboptimalKHR) || (result == vk::Result::eErrorOutOfDateKHR) || framebufferResized)
{
const vk::PresentInfoKHR presentInfoKHR{.waitSemaphoreCount = 1,
.pWaitSemaphores = &*renderFinishedSemaphores[imageIndex],
.swapchainCount = 1,
.pSwapchains = &*swapChain,
.pImageIndices = &imageIndex};
result = queue.presentKHR(presentInfoKHR);
if (result == vk::Result::eErrorOutOfDateKHR || result == vk::Result::eSuboptimalKHR || framebufferResized)
{
framebufferResized = false;
recreateSwapChain();
}
else if (result != vk::Result::eSuccess)
{
throw std::runtime_error("failed to present swap chain image!");
}
framebufferResized = false;
recreateSwapChain();
}
catch (const vk::SystemError &e)
else
{
if (e.code().value() == static_cast<int>(vk::Result::eErrorOutOfDateKHR))
{
recreateSwapChain();
return;
}
else
{
throw;
}
// There are no other success codes than eSuccess; on any error code, presentKHR already threw an exception.
assert(result == vk::Result::eSuccess);
}
frameIndex = (frameIndex + 1) % MAX_FRAMES_IN_FLIGHT;
frameIndex = (frameIndex + 1) % MAX_FRAMES_IN_FLIGHT;
}

[[nodiscard]] vk::raii::ShaderModule createShaderModule(const std::vector<char> &code) const
Expand Down
47 changes: 21 additions & 26 deletions attachments/19_vertex_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -568,17 +568,24 @@ class HelloTriangleApplication

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

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

// Only reset the fence if we are submitting work
device.resetFences(*inFlightFences[frameIndex]);

commandBuffers[frameIndex].reset();
recordCommandBuffer(imageIndex);

Expand All @@ -592,35 +599,23 @@ class HelloTriangleApplication
.pSignalSemaphores = &*renderFinishedSemaphores[imageIndex]};
queue.submit(submitInfo, *inFlightFences[frameIndex]);

try
const vk::PresentInfoKHR presentInfoKHR{.waitSemaphoreCount = 1,
.pWaitSemaphores = &*renderFinishedSemaphores[imageIndex],
.swapchainCount = 1,
.pSwapchains = &*swapChain,
.pImageIndices = &imageIndex};
result = queue.presentKHR(presentInfoKHR);
// Due to VULKAN_HPP_HANDLE_ERROR_OUT_OF_DATE_AS_SUCCESS being defined, eErrorOutOfDateKHR can be checked as a result
// here and does not need to be caught by an exception.
if ((result == vk::Result::eSuboptimalKHR) || (result == vk::Result::eErrorOutOfDateKHR) || framebufferResized)
{
const vk::PresentInfoKHR presentInfoKHR{.waitSemaphoreCount = 1,
.pWaitSemaphores = &*renderFinishedSemaphores[imageIndex],
.swapchainCount = 1,
.pSwapchains = &*swapChain,
.pImageIndices = &imageIndex};
result = queue.presentKHR(presentInfoKHR);
if (result == vk::Result::eErrorOutOfDateKHR || result == vk::Result::eSuboptimalKHR || framebufferResized)
{
framebufferResized = false;
recreateSwapChain();
}
else if (result != vk::Result::eSuccess)
{
throw std::runtime_error("failed to present swap chain image!");
}
framebufferResized = false;
recreateSwapChain();
}
catch (const vk::SystemError &e)
else
{
if (e.code().value() == static_cast<int>(vk::Result::eErrorOutOfDateKHR))
{
recreateSwapChain();
return;
}
else
{
throw;
}
// There are no other success codes than eSuccess; on any error code, presentKHR already threw an exception.
assert(result == vk::Result::eSuccess);
}
frameIndex = (frameIndex + 1) % MAX_FRAMES_IN_FLIGHT;
}
Expand Down
47 changes: 21 additions & 26 deletions attachments/20_staging_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -588,17 +588,24 @@ class HelloTriangleApplication

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

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

// Only reset the fence if we are submitting work
device.resetFences(*inFlightFences[frameIndex]);

commandBuffers[frameIndex].reset();
recordCommandBuffer(imageIndex);

Expand All @@ -612,35 +619,23 @@ class HelloTriangleApplication
.pSignalSemaphores = &*renderFinishedSemaphores[imageIndex]};
queue.submit(submitInfo, *inFlightFences[frameIndex]);

try
const vk::PresentInfoKHR presentInfoKHR{.waitSemaphoreCount = 1,
.pWaitSemaphores = &*renderFinishedSemaphores[imageIndex],
.swapchainCount = 1,
.pSwapchains = &*swapChain,
.pImageIndices = &imageIndex};
result = queue.presentKHR(presentInfoKHR);
// Due to VULKAN_HPP_HANDLE_ERROR_OUT_OF_DATE_AS_SUCCESS being defined, eErrorOutOfDateKHR can be checked as a result
// here and does not need to be caught by an exception.
if ((result == vk::Result::eSuboptimalKHR) || (result == vk::Result::eErrorOutOfDateKHR) || framebufferResized)
{
const vk::PresentInfoKHR presentInfoKHR{.waitSemaphoreCount = 1,
.pWaitSemaphores = &*renderFinishedSemaphores[imageIndex],
.swapchainCount = 1,
.pSwapchains = &*swapChain,
.pImageIndices = &imageIndex};
result = queue.presentKHR(presentInfoKHR);
if (result == vk::Result::eErrorOutOfDateKHR || result == vk::Result::eSuboptimalKHR || framebufferResized)
{
framebufferResized = false;
recreateSwapChain();
}
else if (result != vk::Result::eSuccess)
{
throw std::runtime_error("failed to present swap chain image!");
}
framebufferResized = false;
recreateSwapChain();
}
catch (const vk::SystemError &e)
else
{
if (e.code().value() == static_cast<int>(vk::Result::eErrorOutOfDateKHR))
{
recreateSwapChain();
return;
}
else
{
throw;
}
// There are no other success codes than eSuccess; on any error code, presentKHR already threw an exception.
assert(result == vk::Result::eSuccess);
}
frameIndex = (frameIndex + 1) % MAX_FRAMES_IN_FLIGHT;
}
Expand Down
47 changes: 21 additions & 26 deletions attachments/21_index_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -614,17 +614,24 @@ class HelloTriangleApplication

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

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

// Only reset the fence if we are submitting work
device.resetFences(*inFlightFences[frameIndex]);

commandBuffers[frameIndex].reset();
recordCommandBuffer(imageIndex);

Expand All @@ -638,35 +645,23 @@ class HelloTriangleApplication
.pSignalSemaphores = &*renderFinishedSemaphores[imageIndex]};
queue.submit(submitInfo, *inFlightFences[frameIndex]);

try
const vk::PresentInfoKHR presentInfoKHR{.waitSemaphoreCount = 1,
.pWaitSemaphores = &*renderFinishedSemaphores[imageIndex],
.swapchainCount = 1,
.pSwapchains = &*swapChain,
.pImageIndices = &imageIndex};
result = queue.presentKHR(presentInfoKHR);
// Due to VULKAN_HPP_HANDLE_ERROR_OUT_OF_DATE_AS_SUCCESS being defined, eErrorOutOfDateKHR can be checked as a result
// here and does not need to be caught by an exception.
if ((result == vk::Result::eSuboptimalKHR) || (result == vk::Result::eErrorOutOfDateKHR) || framebufferResized)
{
const vk::PresentInfoKHR presentInfoKHR{.waitSemaphoreCount = 1,
.pWaitSemaphores = &*renderFinishedSemaphores[imageIndex],
.swapchainCount = 1,
.pSwapchains = &*swapChain,
.pImageIndices = &imageIndex};
result = queue.presentKHR(presentInfoKHR);
if (result == vk::Result::eErrorOutOfDateKHR || result == vk::Result::eSuboptimalKHR || framebufferResized)
{
framebufferResized = false;
recreateSwapChain();
}
else if (result != vk::Result::eSuccess)
{
throw std::runtime_error("failed to present swap chain image!");
}
framebufferResized = false;
recreateSwapChain();
}
catch (const vk::SystemError &e)
else
{
if (e.code().value() == static_cast<int>(vk::Result::eErrorOutOfDateKHR))
{
recreateSwapChain();
return;
}
else
{
throw;
}
// There are no other success codes than eSuccess; on any error code, presentKHR already threw an exception.
assert(result == vk::Result::eSuccess);
}
frameIndex = (frameIndex + 1) % MAX_FRAMES_IN_FLIGHT;
}
Expand Down
Loading
Loading