BsVulkanVertexInputManager.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 "BsModule.h"
  6. namespace BansheeEngine
  7. {
  8. /** @addtogroup Vulkan
  9. * @{
  10. */
  11. /**
  12. * Maps vertex buffer structure and vertex shader inputs in order to create vertex input description usable by Vulkan.
  13. */
  14. class VulkanVertexInputManager : public Module<VulkanVertexInputManager>
  15. {
  16. private:
  17. /** Key uniquely identifying buffer and shader vertex declarations. */
  18. struct VertexDeclarationKey
  19. {
  20. UINT32 bufferDeclId;
  21. UINT32 shaderDeclId;
  22. };
  23. /** Creates a hash from vertex declaration key. */
  24. class HashFunc
  25. {
  26. public:
  27. ::std::size_t operator()(const VertexDeclarationKey& key) const;
  28. };
  29. /** Compares two vertex declaration keys. */
  30. class EqualFunc
  31. {
  32. public:
  33. bool operator()(const VertexDeclarationKey& a, const VertexDeclarationKey& b) const;
  34. };
  35. /** Contains data about a single instance of vertex input object. */
  36. struct VertexInputEntry
  37. {
  38. VertexInputEntry() {}
  39. VkVertexInputAttributeDescription* attributes;
  40. VkVertexInputBindingDescription* bindings;
  41. VkPipelineVertexInputStateCreateInfo vertexInputCI;
  42. UINT32 lastUsedIdx;
  43. };
  44. public:
  45. VulkanVertexInputManager();
  46. ~VulkanVertexInputManager();
  47. /**
  48. * Returns an object that describes how vertex buffer elements map to vertex shader inputs.
  49. *
  50. * @param[in] vbDecl Describes the structure of a single vertex in a vertex buffer.
  51. * @param[in] shaderDecl Describes the vertex element inputs expected by a vertex shader.
  52. * @return Vertex input state description, usable by Vulkan.
  53. */
  54. const VkPipelineVertexInputStateCreateInfo& getVertexInfo(const SPtr<VertexDeclarationCore>& vbDecl,
  55. const SPtr<VertexDeclarationCore>& shaderDecl);
  56. private:
  57. /** Creates a vertex input using the specified parameters and stores it in the input layout map. */
  58. void addNew(const SPtr<VertexDeclarationCore>& vbDecl, const SPtr<VertexDeclarationCore>& shaderDecl);
  59. /** Removes the least used vertex input. */
  60. void removeLeastUsed();
  61. private:
  62. static const int DECLARATION_BUFFER_SIZE = 1024;
  63. static const int NUM_ELEMENTS_TO_PRUNE = 64;
  64. UnorderedMap<VertexDeclarationKey, VertexInputEntry*, HashFunc, EqualFunc> mVertexInputMap;
  65. bool mWarningShown;
  66. UINT32 mLastUsedCounter;
  67. };
  68. /** @} */
  69. }