BsVulkanQueue.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. void refreshStates();
  46. /** Returns the last command buffer that was submitted on this queue. */
  47. VulkanCmdBuffer* getLastCommandBuffer() const { return mLastCommandBuffer; }
  48. protected:
  49. /** Information about a single submitted command buffer. */
  50. struct SubmitInfo
  51. {
  52. SubmitInfo(VulkanCmdBuffer* cmdBuffer, UINT32 submitIdx, VulkanSemaphore** semaphores, UINT32 numSemaphores)
  53. :cmdBuffer(cmdBuffer), submitIdx(submitIdx), semaphores(semaphores), numSemaphores(numSemaphores)
  54. { }
  55. VulkanCmdBuffer* cmdBuffer;
  56. UINT32 submitIdx;
  57. VulkanSemaphore** semaphores;
  58. UINT32 numSemaphores;
  59. };
  60. VulkanDevice& mDevice;
  61. VkQueue mQueue;
  62. GpuQueueType mType;
  63. UINT32 mIndex;
  64. VkPipelineStageFlags mSubmitDstWaitMask[BS_MAX_UNIQUE_QUEUES];
  65. List<SubmitInfo> mActiveBuffers;
  66. VulkanCmdBuffer* mLastCommandBuffer;
  67. UINT32 mNextSubmitIdx;
  68. VkSemaphore mSemaphoresTemp[BS_MAX_UNIQUE_QUEUES + 1]; // +1 for present semaphore
  69. };
  70. /** @} */
  71. }