Lugdunum  0.1.0
Queue.cpp
Go to the documentation of this file.
2 
4 #include <lug/System/Debug.hpp>
6 
7 namespace lug {
8 namespace Graphics {
9 namespace Vulkan {
10 namespace API {
11 
12 Queue::Queue(VkQueue queue, const QueueFamily* queueFamily) : _queue(queue), _queueFamily(queueFamily) {}
13 
14 Queue::Queue(Queue&& queue) {
15  _queue = queue._queue;
16  _queueFamily = queue._queueFamily;
17 
18  queue._queue = VK_NULL_HANDLE;
19  queue._queueFamily = nullptr;
20 }
21 
23  _queue = queue._queue;
24  _queueFamily = queue._queueFamily;
25 
26  queue._queue = VK_NULL_HANDLE;
27  queue._queueFamily = nullptr;
28 
29  return *this;
30 }
31 
33  const CommandBuffer& commandBuffer,
34  const std::vector<VkSemaphore>& signalSemaphores,
35  const std::vector<VkSemaphore>& waitSemaphores,
36  const std::vector<VkPipelineStageFlags>& waitDstStageMasks,
37  VkFence fence) const {
38 
39  LUG_ASSERT(waitSemaphores.size() == waitDstStageMasks.size(), "waitDstStageMasks should be the same size as waitSemaphores");
40 
41  VkCommandBuffer vkCommandBuffer = static_cast<VkCommandBuffer>(commandBuffer);
42 
43  const VkSubmitInfo submitInfo{
44  /* submitInfo.sType */ VK_STRUCTURE_TYPE_SUBMIT_INFO,
45  /* submitInfo.pNext */ nullptr,
46  /* submitInfo.waitSemaphoreCount */ waitSemaphores.size() > 0 ? (uint32_t)waitSemaphores.size() : 0,
47  /* submitInfo.pWaitSemaphores */ waitSemaphores.size() > 0 ? waitSemaphores.data() : nullptr,
48  /* submitInfo.pWaitDstStageMask */ waitDstStageMasks.size() > 0 ? waitDstStageMasks.data() : nullptr,
49  /* submitInfo.commandBufferCount */ 1,
50  /* submitInfo.pCommandBuffers */ &vkCommandBuffer,
51  /* submitInfo.signalSemaphoreCount */ signalSemaphores.size() > 0 ? (uint32_t)signalSemaphores.size() : 0,
52  /* submitInfo.pSignalSemaphores */ signalSemaphores.size() > 0 ? signalSemaphores.data() : nullptr
53  };
54 
55  // Protect submit with mutex
56  VkResult result;
57  {
58  std::lock_guard<std::mutex> submitGuard(_mutex);
59  result = vkQueueSubmit(_queue, 1, &submitInfo, fence);
60  }
61 
62  if (result != VK_SUCCESS) {
63  LUG_LOG.error("Queue::submit: Can't submit command buffer {}", result);
64  return false;
65  }
66 
67  return true;
68 }
69 
70 bool Queue::waitIdle() const {
71  // Protect wait with mutex
72  VkResult result;
73  {
74  std::lock_guard<std::mutex> submitGuard(_mutex);
75  result = vkQueueWaitIdle(_queue);
76  }
77 
78  if (result != VK_SUCCESS) {
79  LUG_LOG.error("Queue::waitIdle: Can't wait for queue work {}", result);
80  return false;
81  }
82 
83  return true;
84 }
85 
87  return _queueFamily;
88 }
89 
90 } // API
91 } // Vulkan
92 } // Graphics
93 } // lug
#define LUG_ASSERT(assertion, message)
Definition: Debug.hpp:38
Queue & operator=(const Queue &)=delete
const QueueFamily * _queueFamily
Definition: Queue.hpp:46
bool submit(const CommandBuffer &commandBuffer, const std::vector< VkSemaphore > &signalSemaphores={}, const std::vector< VkSemaphore > &waitSemaphores={}, const std::vector< VkPipelineStageFlags > &waitDstStageMasks={}, VkFence fence=VK_NULL_HANDLE) const
Definition: Queue.cpp:32
const QueueFamily * getQueueFamily() const
Definition: Queue.cpp:86
#define LUG_LOG
Definition: Logger.hpp:73
Queue(VkQueue queue=VK_NULL_HANDLE, const QueueFamily *queueFamily=nullptr)
Definition: Queue.cpp:12