Files
Seele/src/Engine/Graphics/Vulkan/Queue.cpp
T

60 lines
1.6 KiB
C++
Raw Normal View History

2023-10-26 18:37:29 +02:00
#include "Queue.h"
#include "Graphics.h"
#include "Allocator.h"
2023-11-15 17:42:57 +01:00
#include "Command.h"
2020-03-24 21:05:32 +01:00
using namespace Seele;
using namespace Seele::Vulkan;
static constexpr bool waitIdleOnSubmit = false;
2024-01-16 19:24:49 +01:00
Queue::Queue(PGraphics graphics, uint32 familyIndex, uint32 queueIndex)
2021-04-01 16:40:14 +02:00
: graphics(graphics)
, familyIndex(familyIndex)
2020-05-05 01:51:13 +02:00
{
2020-03-24 21:05:32 +01:00
vkGetDeviceQueue(graphics->getDevice(), familyIndex, queueIndex, &queue);
}
Queue::~Queue()
{
2020-04-12 15:47:19 +02:00
}
void Queue::submitCommandBuffer(PCommand command, const Array<VkSemaphore>& signalSemaphores)
2020-04-12 15:47:19 +02:00
{
2023-11-15 17:42:57 +01:00
std::unique_lock lock(queueLock);
assert(command->state == Command::State::End);
2023-11-16 22:58:47 +01:00
assert(!(command->fence->isSignaled()));
2023-11-15 17:42:57 +01:00
VkCommandBuffer cmdHandle = command->handle;
Array<VkSemaphore> waitSemaphores;
for (PSemaphore semaphore : command->waitSemaphores)
2020-04-12 15:47:19 +02:00
{
waitSemaphores.add(semaphore->getHandle());
2020-04-12 15:47:19 +02:00
}
2023-11-15 17:42:57 +01:00
VkSubmitInfo submitInfo = {
.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO,
.pNext = nullptr,
.waitSemaphoreCount = static_cast<uint32>(command->waitSemaphores.size()),
.pWaitSemaphores = waitSemaphores.data(),
.pWaitDstStageMask = command->waitFlags.data(),
.commandBufferCount = 1,
.pCommandBuffers = &cmdHandle,
.signalSemaphoreCount = static_cast<uint32>(signalSemaphores.size()),
.pSignalSemaphores = signalSemaphores.data(),
2023-11-15 17:42:57 +01:00
};
2023-11-16 22:58:47 +01:00
VK_CHECK(vkQueueSubmit(queue, 1, &submitInfo, command->fence->getHandle()));
2023-11-15 17:42:57 +01:00
command->state = Command::State::Submit;
command->waitFlags.clear();
command->waitSemaphores.clear();
if (waitIdleOnSubmit)
{
2023-12-14 09:04:23 +01:00
command->fence->wait(1000 * 1000ull);
}
2023-11-16 22:58:47 +01:00
command->checkFence();
2020-03-24 21:05:32 +01:00
}