/* SPDX-License-Identifier:BSD-3-Clause */ #include "sync.h" #include "../../core/log.h" #include void vk_sync_init(struct renderer_context *context) { u32 count = context->swapchain.image_count; context->image_available = malloc(sizeof(VkSemaphore) * count); context->render_finished = malloc(sizeof(VkSemaphore) * count); context->in_flight = malloc(sizeof(VkFence) * count); VkSemaphoreCreateInfo semaphore_info = { .sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO }; VkFenceCreateInfo fence_info = { .sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, .flags = VK_FENCE_CREATE_SIGNALED_BIT }; for (u32 i = 0; i < count; i++) { if (vkCreateSemaphore(context->device, &semaphore_info, NULL, &context->image_available[i]) != VK_SUCCESS || vkCreateSemaphore(context->device, &semaphore_info, NULL, &context->render_finished[i]) != VK_SUCCESS || vkCreateFence(context->device, &fence_info, NULL, &context->in_flight[i]) != VK_SUCCESS) { fatal("Can't create sync objects.\n"); } } context->current_frame = 0; log_info("Sync objects created.\n"); } void vk_sync_deinit(struct renderer_context *context) { u32 count = context->swapchain.image_count; for (u32 i = 0; i < count; i++) { vkDestroySemaphore(context->device, context->image_available[i], NULL); vkDestroySemaphore(context->device, context->render_finished[i], NULL); vkDestroyFence(context->device, context->in_flight[i], NULL); } free(context->image_available); free(context->render_finished); free(context->in_flight); }