2023-11-01 23:12:30 +01:00
|
|
|
#include "Resources.h"
|
|
|
|
|
#include "Enums.h"
|
|
|
|
|
#include "Graphics.h"
|
2023-11-17 22:31:26 +01:00
|
|
|
#include "Command.h"
|
|
|
|
|
#include "Window.h"
|
2020-03-24 21:05:32 +01:00
|
|
|
|
|
|
|
|
using namespace Seele;
|
|
|
|
|
using namespace Seele::Vulkan;
|
|
|
|
|
|
2020-04-01 02:17:49 +02:00
|
|
|
Semaphore::Semaphore(PGraphics graphics)
|
2020-03-24 21:05:32 +01:00
|
|
|
: graphics(graphics)
|
|
|
|
|
{
|
2023-11-15 00:06:00 +01:00
|
|
|
VkSemaphoreCreateInfo info = {
|
|
|
|
|
.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO,
|
|
|
|
|
.pNext = nullptr,
|
|
|
|
|
.flags = 0,
|
|
|
|
|
};
|
2020-03-24 21:05:32 +01:00
|
|
|
VK_CHECK(vkCreateSemaphore(graphics->getDevice(), &info, nullptr, &handle));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Semaphore::~Semaphore()
|
|
|
|
|
{
|
2024-01-24 23:10:33 +01:00
|
|
|
graphics->getDestructionManager()->queueSemaphore(graphics->getGraphicsCommands()->getCommands(), handle);
|
2020-04-12 15:47:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Fence::Fence(PGraphics graphics)
|
2021-04-01 16:40:14 +02:00
|
|
|
: graphics(graphics)
|
2022-04-15 23:45:44 +02:00
|
|
|
, signaled(false)
|
2020-04-12 15:47:19 +02:00
|
|
|
{
|
2023-11-15 00:06:00 +01:00
|
|
|
VkFenceCreateInfo info = {
|
|
|
|
|
.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
|
|
|
|
|
.pNext = nullptr,
|
|
|
|
|
.flags = 0
|
|
|
|
|
};
|
2020-04-12 15:47:19 +02:00
|
|
|
VK_CHECK(vkCreateFence(graphics->getDevice(), &info, nullptr, &fence));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Fence::~Fence()
|
|
|
|
|
{
|
|
|
|
|
vkDestroyFence(graphics->getDevice(), fence, nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Fence::isSignaled()
|
|
|
|
|
{
|
|
|
|
|
if (signaled)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2023-12-28 21:42:18 +01:00
|
|
|
VkResult r = vkGetFenceStatus(graphics->getDevice(), fence);
|
|
|
|
|
if (r == VK_SUCCESS)
|
2020-04-12 15:47:19 +02:00
|
|
|
{
|
2022-04-15 23:45:44 +02:00
|
|
|
signaled = true;
|
2023-11-15 00:06:00 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
2023-12-28 21:42:18 +01:00
|
|
|
if (r == VK_NOT_READY)
|
2023-11-15 00:06:00 +01:00
|
|
|
{
|
|
|
|
|
return false;
|
2020-04-12 15:47:19 +02:00
|
|
|
}
|
2023-12-28 21:42:18 +01:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
VK_CHECK(r);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2020-04-12 15:47:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Fence::reset()
|
|
|
|
|
{
|
|
|
|
|
if (signaled)
|
|
|
|
|
{
|
|
|
|
|
vkResetFences(graphics->getDevice(), 1, &fence);
|
2022-04-15 23:45:44 +02:00
|
|
|
signaled = false;
|
2020-04-12 15:47:19 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Fence::wait(uint32 timeout)
|
|
|
|
|
{
|
|
|
|
|
VkFence fences[] = {fence};
|
2023-11-15 17:42:57 +01:00
|
|
|
VkResult r = vkWaitForFences(graphics->getDevice(), 1, fences, true, timeout);
|
|
|
|
|
if (r == VK_SUCCESS)
|
2020-04-12 15:47:19 +02:00
|
|
|
{
|
2022-04-15 23:45:44 +02:00
|
|
|
signaled = true;
|
2023-11-15 00:06:00 +01:00
|
|
|
}
|
2023-11-15 17:42:57 +01:00
|
|
|
else if (r == VK_TIMEOUT)
|
2023-11-15 00:06:00 +01:00
|
|
|
{
|
2023-11-15 17:42:57 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else if (r != VK_NOT_READY)
|
|
|
|
|
{
|
|
|
|
|
VK_CHECK(r);
|
2020-04-12 15:47:19 +02:00
|
|
|
}
|
|
|
|
|
}
|
2020-10-03 11:00:10 +02:00
|
|
|
|
2023-11-12 16:11:27 +01:00
|
|
|
DestructionManager::DestructionManager(PGraphics graphics)
|
|
|
|
|
: graphics(graphics)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DestructionManager::~DestructionManager()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-17 19:34:38 +01:00
|
|
|
void DestructionManager::queueBuffer(PCommand cmd, VkBuffer buffer, VmaAllocation alloc)
|
2023-11-12 16:11:27 +01:00
|
|
|
{
|
2024-01-17 19:34:38 +01:00
|
|
|
buffers[cmd].add({buffer, alloc});
|
2023-11-12 16:11:27 +01:00
|
|
|
}
|
|
|
|
|
|
2024-01-17 19:34:38 +01:00
|
|
|
void DestructionManager::queueImage(PCommand cmd, VkImage image, VmaAllocation alloc)
|
2023-11-12 16:11:27 +01:00
|
|
|
{
|
2024-01-17 19:34:38 +01:00
|
|
|
images[cmd].add({image, alloc});
|
2023-11-12 16:11:27 +01:00
|
|
|
}
|
|
|
|
|
|
2023-11-15 00:06:00 +01:00
|
|
|
void DestructionManager::queueImageView(PCommand cmd, VkImageView image)
|
2023-11-12 16:11:27 +01:00
|
|
|
{
|
|
|
|
|
views[cmd].add(image);
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-15 00:06:00 +01:00
|
|
|
void DestructionManager::queueSemaphore(PCommand cmd, VkSemaphore sem)
|
|
|
|
|
{
|
|
|
|
|
sems[cmd].add(sem);
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-02 10:55:00 +01:00
|
|
|
void DestructionManager::queueRenderPass(PCommand cmd, VkRenderPass renderPass)
|
|
|
|
|
{
|
|
|
|
|
renderPasses[cmd].add(renderPass);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DestructionManager::queueDescriptorPool(PCommand cmd, VkDescriptorPool pool)
|
|
|
|
|
{
|
|
|
|
|
pools[cmd].add(pool);
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-15 17:42:57 +01:00
|
|
|
void DestructionManager::notifyCmdComplete(PCommand cmd)
|
|
|
|
|
{
|
2024-01-17 19:34:38 +01:00
|
|
|
for(auto [buf, alloc] : buffers[cmd])
|
2023-11-12 16:11:27 +01:00
|
|
|
{
|
2024-01-17 19:34:38 +01:00
|
|
|
vmaDestroyBuffer(graphics->getAllocator(), buf, alloc);
|
2023-11-12 16:11:27 +01:00
|
|
|
}
|
2023-11-15 17:42:57 +01:00
|
|
|
for(auto view : views[cmd])
|
2023-11-12 16:11:27 +01:00
|
|
|
{
|
|
|
|
|
vkDestroyImageView(graphics->getDevice(), view, nullptr);
|
|
|
|
|
}
|
2024-01-17 19:34:38 +01:00
|
|
|
for(auto [img, alloc] : images[cmd])
|
2023-11-12 16:11:27 +01:00
|
|
|
{
|
2024-01-17 19:34:38 +01:00
|
|
|
vmaDestroyImage(graphics->getAllocator(), img, alloc);
|
2023-11-12 16:11:27 +01:00
|
|
|
}
|
2023-11-15 17:42:57 +01:00
|
|
|
for (auto sem : sems[cmd])
|
2023-11-15 00:06:00 +01:00
|
|
|
{
|
|
|
|
|
vkDestroySemaphore(graphics->getDevice(), sem, nullptr);
|
|
|
|
|
}
|
2023-12-02 10:55:00 +01:00
|
|
|
for (auto pool : pools[cmd])
|
|
|
|
|
{
|
|
|
|
|
vkDestroyDescriptorPool(graphics->getDevice(), pool, nullptr);
|
|
|
|
|
}
|
|
|
|
|
for (auto renderPass : renderPasses[cmd])
|
|
|
|
|
{
|
|
|
|
|
vkDestroyRenderPass(graphics->getDevice(), renderPass, nullptr);
|
|
|
|
|
}
|
2023-11-15 17:42:57 +01:00
|
|
|
buffers[cmd].clear();
|
|
|
|
|
images[cmd].clear();
|
|
|
|
|
views[cmd].clear();
|
|
|
|
|
sems[cmd].clear();
|
2023-12-28 21:42:18 +01:00
|
|
|
pools[cmd].clear();
|
2023-12-02 10:55:00 +01:00
|
|
|
renderPasses[cmd].clear();
|
2020-10-03 11:00:10 +02:00
|
|
|
}
|