Skip to content

Commit f1be81e

Browse files
Merge pull request #297 from gpx1000/address-issue-282
ray tracing resize.
2 parents 4a07199 + 510efd8 commit f1be81e

1 file changed

Lines changed: 31 additions & 5 deletions

File tree

attachments/38_ray_tracing.cpp

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,7 @@ struct UniformBufferObject
106106
struct PushConstant
107107
{
108108
uint32_t materialIndex;
109-
#if LAB_TASK_LEVEL >= LAB_TASK_REFLECTIONS
110-
// TASK11
111109
uint32_t reflective;
112-
#endif // LAB_TASK_LEVEL >= LAB_TASK_REFLECTIONS
113110
};
114111

115112
class VulkanRaytracingApplication
@@ -123,6 +120,14 @@ class VulkanRaytracingApplication
123120
cleanup();
124121
}
125122

123+
~VulkanRaytracingApplication()
124+
{
125+
if (*device)
126+
{
127+
device.waitIdle();
128+
}
129+
}
130+
126131
private:
127132
GLFWwindow *window = nullptr;
128133

@@ -1645,6 +1650,8 @@ class VulkanRaytracingApplication
16451650
.materialIndex = sub.materialID < 0 ? 0u : static_cast<uint32_t>(sub.materialID),
16461651
#if LAB_TASK_LEVEL >= LAB_TASK_REFLECTIONS
16471652
.reflective = sub.reflective
1653+
#else
1654+
.reflective = 0u
16481655
#endif // LAB_TASK_LEVEL >= LAB_TASK_REFLECTIONS
16491656
};
16501657
commandBuffer.pushConstants<PushConstant>(pipelineLayout, vk::ShaderStageFlagBits::eFragment, 0, pushConstant);
@@ -1845,7 +1852,19 @@ class VulkanRaytracingApplication
18451852
throw std::runtime_error("failed to wait for fence!");
18461853
}
18471854

1848-
auto [result, imageIndex] = swapChain.acquireNextImage(UINT64_MAX, *presentCompleteSemaphores[frameIndex], nullptr);
1855+
vk::Result result;
1856+
uint32_t imageIndex;
1857+
try
1858+
{
1859+
auto res = swapChain.acquireNextImage(UINT64_MAX, *presentCompleteSemaphores[frameIndex], nullptr);
1860+
result = res.result;
1861+
imageIndex = res.value;
1862+
}
1863+
catch (const vk::OutOfDateKHRError &e)
1864+
{
1865+
recreateSwapChain();
1866+
return;
1867+
}
18491868

18501869
// Due to VULKAN_HPP_HANDLE_ERROR_OUT_OF_DATE_AS_SUCCESS being defined, eErrorOutOfDateKHR can be checked as a result
18511870
// here and does not need to be caught by an exception.
@@ -1888,7 +1907,14 @@ class VulkanRaytracingApplication
18881907
.swapchainCount = 1,
18891908
.pSwapchains = &*swapChain,
18901909
.pImageIndices = &imageIndex};
1891-
result = presentQueue.presentKHR(presentInfoKHR);
1910+
try
1911+
{
1912+
result = presentQueue.presentKHR(presentInfoKHR);
1913+
}
1914+
catch (const vk::OutOfDateKHRError &e)
1915+
{
1916+
result = vk::Result::eErrorOutOfDateKHR;
1917+
}
18921918
// Due to VULKAN_HPP_HANDLE_ERROR_OUT_OF_DATE_AS_SUCCESS being defined, eErrorOutOfDateKHR can be checked as a result
18931919
// here and does not need to be caught by an exception.
18941920
if ((result == vk::Result::eSuboptimalKHR) || (result == vk::Result::eErrorOutOfDateKHR) || framebufferResized)

0 commit comments

Comments
 (0)