#include "Queue.h" #include "Allocator.h" #include "Command.h" #include "Enums.h" #include "Graphics.h" #include "Graphics/Vulkan/Resources.h" #include using namespace Seele; using namespace Seele::Vulkan; static constexpr bool waitIdleOnSubmit = false; Queue::Queue(PGraphics graphics, uint32 familyIndex, uint32 queueIndex) : graphics(graphics), familyIndex(familyIndex) { vkGetDeviceQueue(graphics->getDevice(), familyIndex, queueIndex, &queue); } Queue::~Queue() {} void Queue::submitCommandBuffer(PCommand command, const Array& signalSemaphores) { std::unique_lock lock(queueLock); assert(command->state == Command::State::End); assert(!(command->fence->isSignaled())); VkCommandBuffer cmdHandle = command->handle; Array waitSemaphores; // 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); // std::cout << "Semaphore " << waitHandle << " waited on by cmd " << command->getHandle() << std::endl; } // for (VkSemaphore signalSemaphore : signalSemaphores) { // std::cout << "Semaphore " << signalSemaphore << " is signalled by cmd " << command->getHandle() << std::endl; // } VkSubmitInfo submitInfo = { .sType = VK_STRUCTURE_TYPE_SUBMIT_INFO, .pNext = nullptr, .waitSemaphoreCount = static_cast(command->waitHandles.size()), .pWaitSemaphores = waitSemaphores.data(), .pWaitDstStageMask = command->waitFlags.data(), .commandBufferCount = 1, .pCommandBuffers = &cmdHandle, .signalSemaphoreCount = static_cast(signalSemaphores.size()), .pSignalSemaphores = signalSemaphores.data(), }; VK_CHECK(vkQueueSubmit(queue, 1, &submitInfo, command->fence->getHandle())); command->fence->submit(); command->state = Command::State::Submit; command->waitFlags.clear(); command->waitHandles.clear(); if (waitIdleOnSubmit) { command->fence->wait(1000 * 1000ull); } command->checkFence(); }