#include "Frame.h" #include #include "MacroUtils.h" #include "RenderDevice.h" bool Frame::isInit() const { return static_cast(commandPool); } Frame::Frame( VkDevice const device, uint32_t const directQueueFamilyIndex ) { VkCommandPoolCreateInfo const commandPoolCreateInfo = { .sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, .pNext = nullptr, .flags = VK_COMMAND_POOL_CREATE_TRANSIENT_BIT, .queueFamilyIndex = directQueueFamilyIndex, }; VK_CHECK( vkCreateCommandPool(device, &commandPoolCreateInfo, nullptr, &commandPool) ); VkCommandBufferAllocateInfo const commandBufferAllocateInfo = { .sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, .pNext = nullptr, .commandPool = commandPool, .level = VK_COMMAND_BUFFER_LEVEL_PRIMARY, .commandBufferCount = 1, }; VK_CHECK( vkAllocateCommandBuffers(device, &commandBufferAllocateInfo, &commandBuffer) ); VkSemaphoreCreateInfo constexpr semaphoreCreateInfo = { .sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, .pNext = nullptr, .flags = 0 }; VK_CHECK( vkCreateSemaphore(device, &semaphoreCreateInfo, nullptr, &imageAcquiredSemaphore) ); VK_CHECK( vkCreateSemaphore(device, &semaphoreCreateInfo, nullptr, &renderFinishedSemaphore) ); VkFenceCreateInfo constexpr fenceCreateInfo = { .sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, .pNext = nullptr, .flags = VK_FENCE_CREATE_SIGNALED_BIT, }; VK_CHECK( vkCreateFence(device, &fenceCreateInfo, nullptr, &frameReadyToReuse) ); } void Frame::destroy( RenderDevice const& renderDevice ) { if ( !isInit() ) return; VkDevice const device = renderDevice.device; vkDestroyCommandPool( device, Take( commandPool ), nullptr ); vkDestroyFence( device, Take( frameReadyToReuse ), nullptr ); vkDestroySemaphore( device, Take( imageAcquiredSemaphore ), nullptr ); vkDestroySemaphore( device, Take( renderFinishedSemaphore ), nullptr ); } Frame::~Frame() { // Manual Cleanup Required. ASSERT( not isInit() ); }