summaryrefslogtreecommitdiff
path: root/src/vk/swapchain.cpp
diff options
context:
space:
mode:
authorFrederico Linhares <fred@linhares.blue>2022-09-16 12:03:04 -0300
committerFrederico Linhares <fred@linhares.blue>2022-09-16 12:03:04 -0300
commit3d6ca447a7104c499e92fc954affdaf4bf011388 (patch)
treed759fbd39d3d66a2457ea92fc4eeb2c31b2cbe4f /src/vk/swapchain.cpp
parent0d0868611389b8dded0c1dfef7a530a4b6e1f148 (diff)
feat Create View
Diffstat (limited to 'src/vk/swapchain.cpp')
-rw-r--r--src/vk/swapchain.cpp58
1 files changed, 56 insertions, 2 deletions
diff --git a/src/vk/swapchain.cpp b/src/vk/swapchain.cpp
index 678279e..1dd19d9 100644
--- a/src/vk/swapchain.cpp
+++ b/src/vk/swapchain.cpp
@@ -127,9 +127,62 @@ unload_image_view(void *obj)
cg_core.vk_device_with_swapchain->device, self->image_views[i], nullptr);
}
+void
+load_frame_sync(void *obj)
+{
+ auto self = static_cast<VK::Swapchain*>(obj);
+
+ self->image_available_semaphores.resize(self->max_frames_in_flight);
+ self->render_finished_semaphores.resize(self->max_frames_in_flight);
+ self->in_flight_fences.resize(self->max_frames_in_flight);
+
+ VkSemaphoreCreateInfo semaphore_info = {};
+ semaphore_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
+ semaphore_info.pNext = nullptr;
+ semaphore_info.flags = 0;
+
+ VkFenceCreateInfo fence_info = {};
+ fence_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
+ fence_info.pNext = nullptr;
+ fence_info.flags = VK_FENCE_CREATE_SIGNALED_BIT;
+
+ // FIXME: if this loop fails, it will not destroy the semaphores.
+ for(auto i{0}; i < self->max_frames_in_flight; i++)
+ {
+ if(vkCreateSemaphore(
+ cg_core.vk_device_with_swapchain->device, &semaphore_info,
+ nullptr, &self->image_available_semaphores[i]) != VK_SUCCESS ||
+ vkCreateSemaphore(
+ cg_core.vk_device_with_swapchain->device, &semaphore_info,
+ nullptr, &self->render_finished_semaphores[i]) != VK_SUCCESS ||
+ vkCreateFence(cg_core.vk_device_with_swapchain->device, &fence_info,
+ nullptr, &self->in_flight_fences[i]) != VK_SUCCESS)
+ throw CommandError{"Failed to create semaphores."};
+ }
+}
+
+void
+unload_frame_sync(void *obj)
+{
+ auto self = static_cast<VK::Swapchain*>(obj);
+
+ vkDeviceWaitIdle(cg_core.vk_device_with_swapchain->device);
+
+ for(auto i{0}; i < self->max_frames_in_flight; i++)
+ {
+ vkDestroySemaphore(cg_core.vk_device_with_swapchain->device,
+ self->render_finished_semaphores[i], nullptr);
+ vkDestroySemaphore(cg_core.vk_device_with_swapchain->device,
+ self->image_available_semaphores[i], nullptr);
+ vkDestroyFence(cg_core.vk_device_with_swapchain->device,
+ self->in_flight_fences[i], nullptr);
+ }
+}
+
const CommandChain loader{
{&load_swapchain, &unload_swapchain},
- {&load_image_view, &unload_image_view}
+ {&load_image_view, &unload_image_view},
+ {&load_frame_sync, &unload_frame_sync}
};
}
@@ -137,7 +190,8 @@ const CommandChain loader{
namespace VK
{
-Swapchain::Swapchain()
+Swapchain::Swapchain():
+ current_frame{0}
{
loader.execute(this);
}