BsVulkanDevice.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. /** Types of GPU queues. */
  13. enum VulkanQueueType
  14. {
  15. /**
  16. * Queue used for rendering. Allows the use of draw commands, but also all commands supported by compute
  17. * or upload buffers.
  18. */
  19. VQT_GRAPHICS,
  20. /** Discrete queue used for compute operations. Allows the use of dispatch and upload commands. */
  21. VQT_COMPUTE,
  22. /** Queue used for memory transfer operations only. No rendering or compute dispatch allowed. */
  23. VQT_UPLOAD,
  24. VQT_COUNT // Keep at end
  25. };
  26. /** Represents a single GPU device usable by Vulkan. */
  27. class VulkanDevice
  28. {
  29. public:
  30. VulkanDevice(VkPhysicalDevice device);
  31. ~VulkanDevice();
  32. /** Returns an object describing the physical properties of the device. */
  33. VkPhysicalDevice getPhysical() const { return mPhysicalDevice; }
  34. /** Returns an object describing the logical properties of the device. */
  35. VkDevice getLogical() const { return mLogicalDevice; }
  36. /** Returns a set of properties describing the physical device. */
  37. const VkPhysicalDeviceProperties& getDeviceProperties() const { return mDeviceProperties; }
  38. /** Returns a set of features that the application can use to check if a specific feature is supported. */
  39. const VkPhysicalDeviceFeatures& getDeviceFeatures() const { return mDeviceFeatures; }
  40. /** Returns a set of properties describing the memory of the physical device. */
  41. const VkPhysicalDeviceMemoryProperties& getMemoryProperties() const { return mMemoryProperties; }
  42. /** Returns the number of queue supported on the device, per type. */
  43. UINT32 getNumQueues(VulkanQueueType type) const { return (UINT32)mQueueInfos[(int)type].queues.size(); }
  44. /** Returns queue of the specified type at the specified index. Index must be in range [0, getNumQueues()) */
  45. VkQueue getQueue(VulkanQueueType type, UINT32 idx) const { return mQueueInfos[(int)type].queues[idx]; }
  46. /** Returns index of the queue family for the specified queue type. */
  47. UINT32 getQueueFamily(VulkanQueueType type) const { return mQueueInfos[(int)type].familyIdx; }
  48. /** Allocates memory for the provided image, and binds it to the image. */
  49. VkDeviceMemory allocateMemory(VkImage image, VkMemoryPropertyFlags flags);
  50. /** Allocates memory for the provided buffer, and binds it to the buffer. */
  51. VkDeviceMemory allocateMemory(VkBuffer buffer, VkMemoryPropertyFlags flags);
  52. /** Allocates a block of memory according to the provided memory requirements. */
  53. VkDeviceMemory allocateMemory(const VkMemoryRequirements& reqs, VkMemoryPropertyFlags flags);
  54. /** Frees a previously allocated block of memory. */
  55. void freeMemory(VkDeviceMemory memory);
  56. private:
  57. /** Attempts to find a memory type that matches the requirements bits and the requested flags. */
  58. uint32_t findMemoryType(uint32_t requirementBits, VkMemoryPropertyFlags wantedFlags);
  59. VkPhysicalDevice mPhysicalDevice;
  60. VkDevice mLogicalDevice;
  61. VkPhysicalDeviceProperties mDeviceProperties;
  62. VkPhysicalDeviceFeatures mDeviceFeatures;
  63. VkPhysicalDeviceMemoryProperties mMemoryProperties;
  64. /** Contains data about a set of queues of a specific type. */
  65. struct QueueInfo
  66. {
  67. UINT32 familyIdx;
  68. Vector<VkQueue> queues;
  69. };
  70. QueueInfo mQueueInfos[VQT_COUNT];
  71. };
  72. /** @} */
  73. }