BsVulkanQueue.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsVulkanPrerequisites.h"
  5. namespace bs { namespace ct
  6. {
  7. /** @addtogroup Vulkan
  8. * @{
  9. */
  10. /** Wrapper for the Vulkan device queue. */
  11. class VulkanQueue
  12. {
  13. public:
  14. VulkanQueue(VulkanDevice& device, VkQueue queue, GpuQueueType type, UINT32 index);
  15. /** Returns the internal handle to the Vulkan queue object. */
  16. VkQueue getHandle() const { return mQueue; }
  17. /** Returns the device that owns the queue. */
  18. VulkanDevice& getDevice() const { return mDevice; }
  19. /** Returns the type of the queue. */
  20. GpuQueueType getType() const { return mType; }
  21. /** Returns the unique index of the queue, for its type. */
  22. UINT32 getIndex() const { return mIndex; }
  23. /**
  24. * Checks if anything is currently executing on this queue.
  25. *
  26. * @note This status is only updated after a VulkanCommandBufferManager::refreshStates() call.
  27. */
  28. bool isExecuting() const;
  29. /** Submits the provided command buffer on the queue. */
  30. void submit(VulkanCmdBuffer* cmdBuffer, VulkanSemaphore** waitSemaphores, UINT32 semaphoresCount);
  31. /**
  32. * Stores information about a submit internally, but doesn't actually execute it. The intended use is to queue
  33. * multiple submits and execute them all at once using submitQueued(), ensuring better performance than queuing them
  34. * all individually.
  35. */
  36. void queueSubmit(VulkanCmdBuffer* cmdBuffer, VulkanSemaphore** waitSemaphores, UINT32 semaphoresCount);
  37. /** Submits all previously queued commands buffers, as recorded by queueSubmit(). */
  38. void submitQueued();
  39. /**
  40. * Presents the back buffer of the provided swap chain.
  41. *
  42. * @param[in] swapChain Swap chain whose back buffer to present.
  43. * @param[in] waitSemaphores Optional semaphores to wait on before presenting the queue.
  44. * @param[in] semaphoresCount Number of semaphores in the @p semaphores array.
  45. */
  46. void present(VulkanSwapChain* swapChain, VulkanSemaphore** waitSemaphores, UINT32 semaphoresCount);
  47. /** Blocks the calling thread until all operations on the queue finish. */
  48. void waitIdle() const;
  49. /**
  50. * Checks if any of the active command buffers finished executing on the queue and updates their states
  51. * accordingly.
  52. *
  53. * @param[in] forceWait Set to true if the system should wait until all command buffers finish executing.
  54. * @param[in] queueEmpty Set to true if the caller guarantees the queue will be empty (e.g. on shutdown). This
  55. * allows the system to free all needed resources.
  56. */
  57. void refreshStates(bool forceWait, bool queueEmpty = false);
  58. /** Returns the last command buffer that was submitted on this queue. */
  59. VulkanCmdBuffer* getLastCommandBuffer() const { return mLastCommandBuffer; }
  60. protected:
  61. /**
  62. * Generates a submit-info structure that can be used for submitting the command buffer to the queue, but doesn't
  63. * perform the actual submit.
  64. */
  65. void getSubmitInfo(VkCommandBuffer* cmdBuffer, VkSemaphore* signalSemaphores, UINT32 numSignalSemaphores,
  66. VkSemaphore* waitSemaphores, UINT32 numWaitSemaphores, VkSubmitInfo& submitInfo);
  67. /**
  68. * Prepares a list of semaphores that can be provided to submit or present calls. *
  69. *
  70. * @param[in] inSemaphores External wait semaphores that need to be waited on.
  71. * @param[out] outSemaphores All semaphores (external ones, and possibly additional ones), as Vulkan handles.
  72. * @param[in, out] semaphoresCount Number of semaphores in @p inSemaphores when calling. When method returns this
  73. * will contain number of semaphores in @p outSemaphores.
  74. */
  75. void prepareSemaphores(VulkanSemaphore** inSemaphores, VkSemaphore* outSemaphores, UINT32& semaphoresCount);
  76. /** Information about a single submitted command buffer. */
  77. struct SubmitInfo
  78. {
  79. SubmitInfo(VulkanCmdBuffer* cmdBuffer, UINT32 submitIdx, UINT32 numSemaphores, UINT32 numCommandBuffers)
  80. : cmdBuffer(cmdBuffer), submitIdx(submitIdx), numSemaphores(numSemaphores)
  81. , numCommandBuffers(numCommandBuffers)
  82. { }
  83. VulkanCmdBuffer* cmdBuffer;
  84. UINT32 submitIdx;
  85. UINT32 numSemaphores;
  86. UINT32 numCommandBuffers;
  87. };
  88. VulkanDevice& mDevice;
  89. VkQueue mQueue;
  90. GpuQueueType mType;
  91. UINT32 mIndex;
  92. VkPipelineStageFlags mSubmitDstWaitMask[BS_MAX_UNIQUE_QUEUES];
  93. Vector<SubmitInfo> mQueuedBuffers;
  94. Vector<VulkanSemaphore*> mQueuedSemaphores;
  95. List<SubmitInfo> mActiveSubmissions;
  96. Queue<VulkanCmdBuffer*> mActiveBuffers;
  97. Queue<VulkanSemaphore*> mActiveSemaphores;
  98. VulkanCmdBuffer* mLastCommandBuffer;
  99. bool mLastCBSemaphoreUsed;
  100. UINT32 mNextSubmitIdx;
  101. Vector<VkSemaphore> mSemaphoresTemp;
  102. };
  103. /** @} */
  104. }}