92 lines
3.1 KiB
C++
92 lines
3.1 KiB
C++
#include "Frame.h"
|
|
|
|
#include <SDL3/SDL_log.h>
|
|
|
|
#include "MacroUtils.h"
|
|
#include "RenderDevice.h"
|
|
|
|
bool Frame::isInit() const
|
|
{
|
|
return static_cast<bool>( commandPool );
|
|
}
|
|
|
|
Frame::Frame(
|
|
VkCommandPool const commandPool,
|
|
VkCommandBuffer const commandBuffer,
|
|
VkSemaphore const imageAcquiredSemaphore,
|
|
VkSemaphore const renderFinishedSemaphore,
|
|
VkFence const frameReadyToReuse )
|
|
: commandPool{ commandPool }
|
|
, commandBuffer{ commandBuffer }
|
|
, imageAcquiredSemaphore{ imageAcquiredSemaphore }
|
|
, renderFinishedSemaphore{ renderFinishedSemaphore }
|
|
, frameReadyToReuse{ 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( !isInit() );
|
|
}
|
|
|
|
void Frame_Create( Frame* frame, VkDevice const device, uint32_t const directQueueFamilyIndex )
|
|
{
|
|
VkCommandPool commandPool;
|
|
VkCommandBuffer commandBuffer;
|
|
VkSemaphore imageAcquiredSemaphore;
|
|
VkSemaphore renderFinishedSemaphore;
|
|
VkFence frameReadyToReuse;
|
|
|
|
{
|
|
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 ) );
|
|
}
|
|
|
|
frame->commandPool = commandPool;
|
|
frame->commandBuffer = commandBuffer;
|
|
frame->imageAcquiredSemaphore = imageAcquiredSemaphore;
|
|
frame->renderFinishedSemaphore = renderFinishedSemaphore;
|
|
frame->frameReadyToReuse = frameReadyToReuse;
|
|
}
|