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"
|
2026-10-25 19:18:57 +01:00
|
|
|
#include "Graphics/Vulkan/Resources.h"
|
2025-05-16 13:04:43 +02:00
|
|
|
#include <mutex>
|
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;
|
2026-10-25 19:18:57 +01:00
|
|
|
// Use the handles captured at record time (command->waitHandles). Re-resolving
|
|
|
|
|
// the wrapper's current handle here would let the wait target drift if the
|
|
|
|
|
// wrapper rotated between record and submit, potentially onto a semaphore that
|
|
|
|
|
// is also signalled in this same submit.
|
|
|
|
|
for (VkSemaphore waitHandle : command->waitHandles) {
|
|
|
|
|
waitSemaphores.add(waitHandle);
|
2026-10-25 22:50:20 +01:00
|
|
|
// std::cout << "Semaphore " << waitHandle << " waited on by cmd " << command->getHandle() << std::endl;
|
2026-10-25 19:18:57 +01:00
|
|
|
}
|
|
|
|
|
|
2026-10-25 22:50:20 +01:00
|
|
|
// for (VkSemaphore signalSemaphore : signalSemaphores) {
|
|
|
|
|
// std::cout << "Semaphore " << signalSemaphore << " is signalled by cmd " << command->getHandle() << std::endl;
|
|
|
|
|
// }
|
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,
|
2026-10-25 19:18:57 +01:00
|
|
|
.waitSemaphoreCount = static_cast<uint32>(command->waitHandles.size()),
|
2023-11-15 17:42:57 +01:00
|
|
|
.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();
|
2026-10-25 19:18:57 +01:00
|
|
|
command->waitHandles.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
|
|
|
}
|