BsVulkanDevice.h 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. /** Represents a single GPU device usable by Vulkan. */
  12. class VulkanDevice
  13. {
  14. public:
  15. VulkanDevice(VkPhysicalDevice device);
  16. ~VulkanDevice();
  17. /** Returns an object describing the physical properties of the device. */
  18. VkPhysicalDevice getPhysical() const { return mPhysicalDevice; }
  19. /** Returns an object describing the logical properties of the device. */
  20. VkDevice getLogical() const { return mLogicalDevice; }
  21. /** Returns a set of properties describing the physical device. */
  22. const VkPhysicalDeviceProperties& getDeviceProperties() const { return mDeviceProperties; }
  23. /** Returns a set of features that the application can use to check if a specific feature is supported. */
  24. const VkPhysicalDeviceFeatures& getDeviceFeatures() const { return mDeviceFeatures; }
  25. /** Returns a set of properties describing the memory of the physical device. */
  26. const VkPhysicalDeviceMemoryProperties& getMemoryProperties() const { return mMemoryProperties; }
  27. /** Returns the number of queue supported on the device, per type. */
  28. UINT32 getNumQueues(VulkanQueueType type) const { return (UINT32)mQueueInfos[(int)type].queues.size(); }
  29. /** Returns queue of the specified type at the specified index. Index must be in range [0, getNumQueues()). */
  30. VkQueue getQueue(VulkanQueueType type, UINT32 idx) const { return mQueueInfos[(int)type].queues[idx]; }
  31. /**
  32. * Returns index of the queue family for the specified queue type. Returns -1 if no queues for the specified type
  33. * exist. There will always be a queue family for the graphics type.
  34. */
  35. UINT32 getQueueFamily(VulkanQueueType type) const { return mQueueInfos[(int)type].familyIdx; }
  36. /** Returns a pool that can be used for allocating command buffers for all queues on this device. */
  37. CommandBufferPool& getCmdBufferPool() const { return *mCommandBufferPool; }
  38. /**
  39. * Allocates memory for the provided image, and binds it to the image. Returns null if it cannot find memory
  40. * with the specified flags.
  41. */
  42. VkDeviceMemory allocateMemory(VkImage image, VkMemoryPropertyFlags flags);
  43. /**
  44. * Allocates memory for the provided buffer, and binds it to the buffer. Returns null if it cannot find memory
  45. * with the specified flags.
  46. */
  47. VkDeviceMemory allocateMemory(VkBuffer buffer, VkMemoryPropertyFlags flags);
  48. /**
  49. * Allocates a block of memory according to the provided memory requirements. Returns null if it cannot find memory
  50. * with the specified flags.
  51. */
  52. VkDeviceMemory allocateMemory(const VkMemoryRequirements& reqs, VkMemoryPropertyFlags flags);
  53. /** Frees a previously allocated block of memory. */
  54. void freeMemory(VkDeviceMemory memory);
  55. private:
  56. /** Attempts to find a memory type that matches the requirements bits and the requested flags. */
  57. uint32_t findMemoryType(uint32_t requirementBits, VkMemoryPropertyFlags wantedFlags);
  58. VkPhysicalDevice mPhysicalDevice;
  59. VkDevice mLogicalDevice;
  60. CommandBufferPool* mCommandBufferPool;
  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. }