BsVulkanDescriptorManager.h 1.8 KB

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