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

55 lines
1.7 KiB
C++
Raw Normal View History

2023-10-26 18:37:29 +02:00
#include "Queue.h"
#include "Allocator.h"
2023-11-15 17:42:57 +01:00
#include "Command.h"
2024-06-09 10:44:24 +02:00
#include "Enums.h"
2024-06-09 12:20:04 +02:00
#include "Graphics.h"
2020-03-24 21:05:32 +01:00
using namespace Seele;
using namespace Seele::Vulkan;
static constexpr bool waitIdleOnSubmit = false;
2024-06-09 12:20:04 +02:00
Queue::Queue(PGraphics graphics, uint32 familyIndex, uint32 queueIndex) : graphics(graphics), familyIndex(familyIndex) {
2020-03-24 21:05:32 +01:00
vkGetDeviceQueue(graphics->getDevice(), familyIndex, queueIndex, &queue);
}
2024-06-09 12:20:04 +02:00
Queue::~Queue() {}
2020-04-12 15:47:19 +02:00
2024-06-09 12:20:04 +02:00
void Queue::submitCommandBuffer(PCommand command, const Array<VkSemaphore>& signalSemaphores) {
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;
2024-06-09 12:20:04 +02:00
for (PSemaphore semaphore : command->waitSemaphores) {
waitSemaphores.add(semaphore->getHandle());
2020-04-12 15:47:19 +02:00
}
2024-06-09 12:20:04 +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
};
2024-06-09 12:20:04 +02:00
2023-11-16 22:58:47 +01:00
VK_CHECK(vkQueueSubmit(queue, 1, &submitInfo, command->fence->getHandle()));
command->fence->submit();
2023-11-15 17:42:57 +01:00
command->state = Command::State::Submit;
command->waitFlags.clear();
command->waitSemaphores.clear();
2024-06-09 12:20:04 +02:00
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
}