BsVulkanDevice.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. #include "Renderapi/BsRenderAPI.h"
  6. #include "Managers/BsVulkanDescriptorManager.h"
  7. namespace bs { namespace ct
  8. {
  9. /** @addtogroup Vulkan
  10. * @{
  11. */
  12. /** Represents a single GPU device usable by Vulkan. */
  13. class VulkanDevice
  14. {
  15. public:
  16. VulkanDevice(VkPhysicalDevice device, UINT32 deviceIdx);
  17. ~VulkanDevice();
  18. /** Returns an object describing the physical properties of the device. */
  19. VkPhysicalDevice getPhysical() const { return mPhysicalDevice; }
  20. /** Returns an object describing the logical properties of the device. */
  21. VkDevice getLogical() const { return mLogicalDevice; }
  22. /** Returns true if the device is one of the primary GPU's. */
  23. bool isPrimary() const { return mIsPrimary; }
  24. /** Returns the unique index of the device. */
  25. UINT32 getIndex() const { return mDeviceIdx; }
  26. /** Blocks the calling thread until all operations on the device finish. */
  27. void waitIdle() const;
  28. /** Returns a set of properties describing the physical device. */
  29. const VkPhysicalDeviceProperties& getDeviceProperties() const { return mDeviceProperties; }
  30. /** Returns a set of features that the application can use to check if a specific feature is supported. */
  31. const VkPhysicalDeviceFeatures& getDeviceFeatures() const { return mDeviceFeatures; }
  32. /** Returns a set of properties describing the memory of the physical device. */
  33. const VkPhysicalDeviceMemoryProperties& getMemoryProperties() const { return mMemoryProperties; }
  34. /** Returns the number of queue supported on the device, per type. */
  35. UINT32 getNumQueues(GpuQueueType type) const { return (UINT32)mQueueInfos[(int)type].queues.size(); }
  36. /** Returns queue of the specified type at the specified index. Index must be in range [0, getNumQueues()). */
  37. VulkanQueue* getQueue(GpuQueueType type, UINT32 idx) const { return mQueueInfos[(int)type].queues[idx]; }
  38. /**
  39. * Returns index of the queue family for the specified queue type. Returns -1 if no queues for the specified type
  40. * exist. There will always be a queue family for the graphics type.
  41. */
  42. UINT32 getQueueFamily(GpuQueueType type) const { return mQueueInfos[(int)type].familyIdx; }
  43. /**
  44. * Fills out a mask that has bits set for every queue index that maps to the same physical queue as the provided
  45. * index. This is useful as different queue indices will sometimes map to the same physical queue.
  46. */
  47. UINT32 getQueueMask(GpuQueueType type, UINT32 queueIdx) const;
  48. /** Returns a pool that can be used for allocating command buffers for all queues on this device. */
  49. VulkanCmdBufferPool& getCmdBufferPool() const { return *mCommandBufferPool; }
  50. /** Returns a pool that can be used for allocating queries on this device. */
  51. VulkanQueryPool& getQueryPool() const { return *mQueryPool; }
  52. /** Returns a manager that can be used for allocating descriptor layouts and sets. */
  53. VulkanDescriptorManager& getDescriptorManager() const { return *mDescriptorManager; }
  54. /** Returns a manager that can be used for allocating Vulkan objects wrapped as managed resources. */
  55. VulkanResourceManager& getResourceManager() const { return *mResourceManager; }
  56. /**
  57. * Allocates memory for the provided image, and binds it to the image. Returns null if it cannot find memory
  58. * with the specified flags.
  59. */
  60. VkDeviceMemory allocateMemory(VkImage image, VkMemoryPropertyFlags flags);
  61. /**
  62. * Allocates memory for the provided buffer, and binds it to the buffer. Returns null if it cannot find memory
  63. * with the specified flags.
  64. */
  65. VkDeviceMemory allocateMemory(VkBuffer buffer, VkMemoryPropertyFlags flags);
  66. /**
  67. * Allocates a block of memory according to the provided memory requirements. Returns null if it cannot find memory
  68. * with the specified flags.
  69. */
  70. VkDeviceMemory allocateMemory(const VkMemoryRequirements& reqs, VkMemoryPropertyFlags flags);
  71. /** Frees a previously allocated block of memory. */
  72. void freeMemory(VkDeviceMemory memory);
  73. private:
  74. friend class VulkanRenderAPI;
  75. /** Attempts to find a memory type that matches the requirements bits and the requested flags. */
  76. uint32_t findMemoryType(uint32_t requirementBits, VkMemoryPropertyFlags wantedFlags);
  77. /** Marks the device as a primary device. */
  78. void setIsPrimary() { mIsPrimary = true; }
  79. VkPhysicalDevice mPhysicalDevice;
  80. VkDevice mLogicalDevice;
  81. bool mIsPrimary;
  82. UINT32 mDeviceIdx;
  83. VulkanCmdBufferPool* mCommandBufferPool;
  84. VulkanQueryPool* mQueryPool;
  85. VulkanDescriptorManager* mDescriptorManager;
  86. VulkanResourceManager* mResourceManager;
  87. VkPhysicalDeviceProperties mDeviceProperties;
  88. VkPhysicalDeviceFeatures mDeviceFeatures;
  89. VkPhysicalDeviceMemoryProperties mMemoryProperties;
  90. /** Contains data about a set of queues of a specific type. */
  91. struct QueueInfo
  92. {
  93. UINT32 familyIdx;
  94. Vector<VulkanQueue*> queues;
  95. };
  96. QueueInfo mQueueInfos[GQT_COUNT];
  97. };
  98. /** @} */
  99. }}