BsVulkanDevice.h 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 "BsRenderAPI.h"
  6. namespace BansheeEngine
  7. {
  8. /** @addtogroup Vulkan
  9. * @{
  10. */
  11. #define BS_MAX_VULKAN_QUEUES_PER_TYPE 4
  12. /** Represents a single GPU device usable by Vulkan. */
  13. class VulkanDevice
  14. {
  15. public:
  16. VulkanDevice(VkPhysicalDevice device);
  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 a set of properties describing the physical device. */
  23. const VkPhysicalDeviceProperties& getDeviceProperties() const { return mDeviceProperties; }
  24. /** Returns a set of features that the application can use to check if a specific feature is supported. */
  25. const VkPhysicalDeviceFeatures& getDeviceFeatures() const { return mDeviceFeatures; }
  26. /** Returns a set of properties describing the memory of the physical device. */
  27. const VkPhysicalDeviceMemoryProperties& getMemoryProperties() const { return mMemoryProperties; }
  28. /** Returns the number of queue supported on the device, per type. */
  29. UINT32 getNumQueues(VulkanQueueType type) const { return (UINT32)mQueueInfos[(int)type].queues.size(); }
  30. /** Returns queue of the specified type at the specified index. Index must be in range [0, getNumQueues()). */
  31. VkQueue getQueue(VulkanQueueType type, UINT32 idx) const { return mQueueInfos[(int)type].queues[idx]; }
  32. /**
  33. * Returns index of the queue family for the specified queue type. Returns -1 if no queues for the specified type
  34. * exist. There will always be a queue family for the graphics type.
  35. */
  36. UINT32 getQueueFamily(VulkanQueueType type) const { return mQueueInfos[(int)type].familyIdx; }
  37. /**
  38. * Returns a command pool that may be used for allocating command buffers for this queue family. Only the graphics
  39. * command pool is guaranteed to exist, others may return null.
  40. */
  41. VkCommandPool getCommandPool(VulkanQueueType type) const { return mQueueInfos[(int)type].commandPool; }
  42. /** Allocates memory for the provided image, and binds it to the image. */
  43. VkDeviceMemory allocateMemory(VkImage image, VkMemoryPropertyFlags flags);
  44. /** Allocates memory for the provided buffer, and binds it to the buffer. */
  45. VkDeviceMemory allocateMemory(VkBuffer buffer, VkMemoryPropertyFlags flags);
  46. /** Allocates a block of memory according to the provided memory requirements. */
  47. VkDeviceMemory allocateMemory(const VkMemoryRequirements& reqs, VkMemoryPropertyFlags flags);
  48. /** Frees a previously allocated block of memory. */
  49. void freeMemory(VkDeviceMemory memory);
  50. private:
  51. /** Attempts to find a memory type that matches the requirements bits and the requested flags. */
  52. uint32_t findMemoryType(uint32_t requirementBits, VkMemoryPropertyFlags wantedFlags);
  53. VkPhysicalDevice mPhysicalDevice;
  54. VkDevice mLogicalDevice;
  55. VkPhysicalDeviceProperties mDeviceProperties;
  56. VkPhysicalDeviceFeatures mDeviceFeatures;
  57. VkPhysicalDeviceMemoryProperties mMemoryProperties;
  58. /** Contains data about a set of queues of a specific type. */
  59. struct QueueInfo
  60. {
  61. UINT32 familyIdx;
  62. Vector<VkQueue> queues;
  63. VkCommandPool commandPool;
  64. };
  65. QueueInfo mQueueInfos[VQT_COUNT];
  66. };
  67. /** @} */
  68. }