BsVulkanQueue.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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
  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. * Presents the back buffer of the provided swap chain.
  33. *
  34. * @param[in] swapChain Swap chain whose back buffer to present.
  35. * @param[in] waitSemaphores Optional semaphores to wait on before presenting the queue.
  36. * @param[in] semaphoresCount Number of semaphores in the @p semaphores array.
  37. */
  38. void present(VulkanSwapChain* swapChain, VulkanSemaphore** waitSemaphores, UINT32 semaphoresCount);
  39. /** Blocks the calling thread until all operations on the queue finish. */
  40. void waitIdle() const;
  41. /**
  42. * Checks if any of the active command buffers finished executing on the queue and updates their states
  43. * accordingly.
  44. *
  45. * @param[in] queueEmpty Set to true if the caller guarantees the queue will be empty (e.g. on shutdown). This
  46. * allows the system to free all needed resources.
  47. */
  48. void refreshStates(bool queueEmpty = false);
  49. /** Returns the last command buffer that was submitted on this queue. */
  50. VulkanCmdBuffer* getLastCommandBuffer() const { return mLastCommandBuffer; }
  51. protected:
  52. /** Information about a single submitted command buffer. */
  53. struct SubmitInfo
  54. {
  55. SubmitInfo(VulkanCmdBuffer* cmdBuffer, UINT32 submitIdx, UINT32 numSemaphores)
  56. :cmdBuffer(cmdBuffer), submitIdx(submitIdx), numSemaphores(numSemaphores)
  57. { }
  58. VulkanCmdBuffer* cmdBuffer;
  59. UINT32 submitIdx;
  60. UINT32 numSemaphores;
  61. };
  62. VulkanDevice& mDevice;
  63. VkQueue mQueue;
  64. GpuQueueType mType;
  65. UINT32 mIndex;
  66. VkPipelineStageFlags mSubmitDstWaitMask[BS_MAX_UNIQUE_QUEUES];
  67. List<SubmitInfo> mActiveBuffers;
  68. Queue<VulkanSemaphore*> mActiveSemaphores;
  69. VulkanCmdBuffer* mLastCommandBuffer;
  70. UINT32 mNextSubmitIdx;
  71. VkSemaphore mSemaphoresTemp[BS_MAX_UNIQUE_QUEUES + 1]; // +1 for present semaphore
  72. };
  73. /** @} */
  74. }