BsVulkanQueue.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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] queueEmpty Set to true if the caller guarantees the queue will be empty (e.g. on shutdown). This
  54. * allows the system to free all needed resources.
  55. */
  56. void refreshStates(bool queueEmpty = false);
  57. /** Returns the last command buffer that was submitted on this queue. */
  58. VulkanCmdBuffer* getLastCommandBuffer() const { return mLastCommandBuffer; }
  59. protected:
  60. /**
  61. * Generates a submit-info structure that can be used for submitting the command buffer to the queue, but doesn't
  62. * perform the actual submit.
  63. */
  64. void getSubmitInfo(VkCommandBuffer* cmdBuffer, VkSemaphore* signalSemaphore, VkSemaphore* waitSemaphores,
  65. UINT32 semaphoresCount, VkSubmitInfo& submitInfo);
  66. /**
  67. * Prepares a list of semaphores that can be provided to submit or present calls. *
  68. *
  69. * @param[in] inSemaphores External wait semaphores that need to be waited on.
  70. * @param[out] outSemaphores All semaphores (external ones, and possibly additional ones), as Vulkan handles.
  71. * @param[in, out] semaphoresCount Number of semaphores in @p inSemaphores when calling. When method returns this
  72. * will contain number of semaphores in @p outSemaphores.
  73. */
  74. void prepareSemaphores(VulkanSemaphore** inSemaphores, VkSemaphore* outSemaphores, UINT32& semaphoresCount);
  75. /** Information about a single submitted command buffer. */
  76. struct SubmitInfo
  77. {
  78. SubmitInfo(VulkanCmdBuffer* cmdBuffer, UINT32 submitIdx, UINT32 numSemaphores, UINT32 numCommandBuffers)
  79. : cmdBuffer(cmdBuffer), submitIdx(submitIdx), numSemaphores(numSemaphores)
  80. , numCommandBuffers(numCommandBuffers)
  81. { }
  82. VulkanCmdBuffer* cmdBuffer;
  83. UINT32 submitIdx;
  84. UINT32 numSemaphores;
  85. UINT32 numCommandBuffers;
  86. };
  87. VulkanDevice& mDevice;
  88. VkQueue mQueue;
  89. GpuQueueType mType;
  90. UINT32 mIndex;
  91. VkPipelineStageFlags mSubmitDstWaitMask[BS_MAX_UNIQUE_QUEUES];
  92. Vector<SubmitInfo> mQueuedBuffers;
  93. Vector<VulkanSemaphore*> mQueuedSemaphores;
  94. List<SubmitInfo> mActiveSubmissions;
  95. Queue<VulkanCmdBuffer*> mActiveBuffers;
  96. Queue<VulkanSemaphore*> mActiveSemaphores;
  97. VulkanCmdBuffer* mLastCommandBuffer;
  98. bool mLastCBSemaphoreUsed;
  99. UINT32 mNextSubmitIdx;
  100. VkSemaphore mSemaphoresTemp[BS_MAX_UNIQUE_QUEUES + 2]; // +1 for present semaphore, +1 for self-semaphore
  101. };
  102. /** @} */
  103. }}