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;
|
|
|
|
|
|
2024-01-31 09:49:53 +01:00
|
|
|
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);
|
2021-06-04 18:27:49 +02:00
|
|
|
|
2023-11-16 22:58:47 +01:00
|
|
|
assert(!(command->fence->isSignaled()));
|
2021-06-04 18:27:49 +02:00
|
|
|
|
2023-11-15 17:42:57 +01:00
|
|
|
VkCommandBuffer cmdHandle = command->handle;
|
2021-06-04 18:27:49 +02:00
|
|
|
|
|
|
|
|
Array<VkSemaphore> waitSemaphores;
|
2025-03-07 21:48:27 +01:00
|
|
|
// wait semaphores get bound to the cmd when they are added
|
|
|
|
|
// and unbound when the command completes
|
2024-06-09 12:20:04 +02:00
|
|
|
for (PSemaphore semaphore : command->waitSemaphores) {
|
2023-11-17 16:53:37 +01:00
|
|
|
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,
|
2023-11-17 16:53:37 +01:00
|
|
|
.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()));
|
2024-05-30 21:24:21 +02:00
|
|
|
command->fence->submit();
|
2023-11-15 17:42:57 +01:00
|
|
|
command->state = Command::State::Submit;
|
|
|
|
|
command->waitFlags.clear();
|
|
|
|
|
command->waitSemaphores.clear();
|
2021-06-04 18:27:49 +02:00
|
|
|
|
2024-06-09 12:20:04 +02:00
|
|
|
if (waitIdleOnSubmit) {
|
2023-12-14 09:04:23 +01:00
|
|
|
command->fence->wait(1000 * 1000ull);
|
2021-06-04 18:27:49 +02:00
|
|
|
}
|
|
|
|
|
|
2023-11-16 22:58:47 +01:00
|
|
|
command->checkFence();
|
2020-03-24 21:05:32 +01:00
|
|
|
}
|