BsVulkanDescriptorManager.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 "BsVulkanDescriptorLayout.h"
  6. namespace BansheeEngine
  7. {
  8. /** Used as a key in a hash map containing VulkanDescriptorLayout%s. */
  9. struct VulkanLayoutKey
  10. {
  11. VulkanLayoutKey(VkDescriptorSetLayoutBinding* bindings, UINT32 numBindings);
  12. /** Compares two descriptor layouts. */
  13. bool operator==(const VulkanLayoutKey& rhs) const;
  14. UINT32 numBindings;
  15. VkDescriptorSetLayoutBinding* bindings;
  16. VulkanDescriptorLayout* layout;
  17. };
  18. }
  19. /** @cond STDLIB */
  20. /** @addtogroup Vulkan
  21. * @{
  22. */
  23. namespace std
  24. {
  25. /** Hash value generator for VulkanDescriptorLayout. */
  26. template<>
  27. struct hash<BansheeEngine::VulkanLayoutKey>
  28. {
  29. size_t operator()(const BansheeEngine::VulkanLayoutKey& value) const
  30. {
  31. if (value.layout != nullptr)
  32. return value.layout->getHash();
  33. return BansheeEngine::VulkanDescriptorLayout::calculateHash(value.bindings, value.numBindings);
  34. }
  35. };
  36. }
  37. /** @} */
  38. /** @endcond */
  39. namespace BansheeEngine
  40. {
  41. /** @addtogroup Vulkan
  42. * @{
  43. */
  44. /** Manages allocation of descriptor layouts and sets for a single Vulkan device. */
  45. class VulkanDescriptorManager
  46. {
  47. public:
  48. VulkanDescriptorManager(VulkanDevice& device);
  49. ~VulkanDescriptorManager();
  50. /** Attempts to find an existing one, or allocates a new descriptor set layout from the provided set of bindings. */
  51. VulkanDescriptorLayout* getLayout(VkDescriptorSetLayoutBinding* bindings, UINT32 numBindings);
  52. /** Allocates a new empty descriptor set matching the provided layout. */
  53. VulkanDescriptorSet* createSet(VulkanDescriptorLayout* layout);
  54. protected:
  55. VulkanDevice& mDevice;
  56. UnorderedSet<VulkanLayoutKey> mLayouts;
  57. Vector<VulkanDescriptorPool*> mPools;
  58. };
  59. /** @} */
  60. }