BsHardwareBufferManager.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsCorePrerequisites.h"
  5. #include "BsModule.h"
  6. #include "BsVertexBuffer.h"
  7. #include "BsIndexBuffer.h"
  8. #include "BsVertexDeclaration.h"
  9. namespace bs
  10. {
  11. struct GPU_BUFFER_DESC;
  12. struct GPU_PARAMS_DESC;
  13. /** @addtogroup RenderAPI-Internal
  14. * @{
  15. */
  16. /**
  17. * Handles creation of various hardware buffers.
  18. *
  19. * @note Sim thread only.
  20. */
  21. class BS_CORE_EXPORT HardwareBufferManager : public Module<HardwareBufferManager>
  22. {
  23. public:
  24. HardwareBufferManager();
  25. virtual ~HardwareBufferManager();
  26. /**
  27. * Creates a new vertex buffer used for holding number of vertices and other per-vertex data. Buffer can be bound
  28. * to the pipeline and its data can be passed to the active vertex GPU program.
  29. *
  30. * @param[in] desc Description of the buffer to create.
  31. */
  32. SPtr<VertexBuffer> createVertexBuffer(const VERTEX_BUFFER_DESC& desc);
  33. /**
  34. * Creates a new index buffer that holds indices referencing vertices in a vertex buffer. Indices are interpreted
  35. * by the pipeline and vertices are drawn in the order specified in the index buffer.
  36. *
  37. * @param[in] desc Description of the buffer to create.
  38. */
  39. SPtr<IndexBuffer> createIndexBuffer(const INDEX_BUFFER_DESC& desc);
  40. /**
  41. * Creates an GPU parameter block that you can use for setting parameters for GPU programs. Parameter blocks may be
  42. * used for sharing parameter data between multiple GPU programs, requiring you to update only one buffer for all of
  43. * them, potentially improving performance.
  44. *
  45. * @param[in] size Size of the parameter buffer in bytes.
  46. * @param[in] usage Usage that tells the hardware how will be buffer be used.
  47. */
  48. SPtr<GpuParamBlockBuffer> createGpuParamBlockBuffer(UINT32 size, GpuParamBlockUsage usage = GPBU_DYNAMIC);
  49. /**
  50. * Creates a generic buffer that can be passed as a parameter to a GPU program. This type of buffer can hold various
  51. * type of data and can be used for various purposes. See GpuBufferType for explanation of different buffer types.
  52. *
  53. * @param[in] desc Description of the buffer to create.
  54. */
  55. SPtr<GpuBuffer> createGpuBuffer(const GPU_BUFFER_DESC& desc);
  56. /**
  57. * Creates a new vertex declaration from a list of vertex elements.
  58. *
  59. * @param[in] desc Description of the object to create.
  60. */
  61. SPtr<VertexDeclaration> createVertexDeclaration(const SPtr<VertexDataDesc>& desc);
  62. /** @copydoc GpuParams::create(const SPtr<GpuPipelineParamInfo>&) */
  63. SPtr<GpuParams> createGpuParams(const SPtr<GpuPipelineParamInfo>& paramInfo);
  64. };
  65. namespace ct
  66. {
  67. /**
  68. * Handles creation of various hardware buffers.
  69. *
  70. * @note Core thread only.
  71. */
  72. class BS_CORE_EXPORT HardwareBufferManager : public Module<HardwareBufferManager>
  73. {
  74. public:
  75. virtual ~HardwareBufferManager() { }
  76. /**
  77. * @copydoc bs::HardwareBufferManager::createVertexBuffer
  78. * @param[in] deviceMask Mask that determines on which GPU devices should the object be created on.
  79. */
  80. SPtr<VertexBuffer> createVertexBuffer(const VERTEX_BUFFER_DESC& desc, GpuDeviceFlags deviceMask = GDF_DEFAULT);
  81. /**
  82. * @copydoc bs::HardwareBufferManager::createIndexBuffer
  83. * @param[in] deviceMask Mask that determines on which GPU devices should the object be created on.
  84. */
  85. SPtr<IndexBuffer> createIndexBuffer(const INDEX_BUFFER_DESC& desc, GpuDeviceFlags deviceMask = GDF_DEFAULT);
  86. /**
  87. * @copydoc bs::HardwareBufferManager::createVertexDeclaration
  88. * @param[in] deviceMask Mask that determines on which GPU devices should the object be created on.
  89. */
  90. SPtr<VertexDeclaration> createVertexDeclaration(const SPtr<VertexDataDesc>& desc,
  91. GpuDeviceFlags deviceMask = GDF_DEFAULT);
  92. /**
  93. * Creates a new vertex declaration from a list of vertex elements.
  94. *
  95. * @param[in] elements List of elements to initialize the declaration with.
  96. * @param[in] deviceMask Mask that determines on which GPU devices should the object be created on.
  97. */
  98. SPtr<VertexDeclaration> createVertexDeclaration(const List<VertexElement>& elements,
  99. GpuDeviceFlags deviceMask = GDF_DEFAULT);
  100. /**
  101. * @copydoc bs::HardwareBufferManager::createGpuParamBlockBuffer
  102. * @param[in] deviceMask Mask that determines on which GPU devices should the object be created on.
  103. */
  104. SPtr<GpuParamBlockBuffer> createGpuParamBlockBuffer(UINT32 size,
  105. GpuParamBlockUsage usage = GPBU_DYNAMIC, GpuDeviceFlags deviceMask = GDF_DEFAULT);
  106. /**
  107. * @copydoc bs::HardwareBufferManager::createGpuBuffer
  108. * @param[in] deviceMask Mask that determines on which GPU devices should the object be created on.
  109. */
  110. SPtr<GpuBuffer> createGpuBuffer(const GPU_BUFFER_DESC& desc, GpuDeviceFlags deviceMask = GDF_DEFAULT);
  111. /** @copydoc GpuParams::create(const SPtr<GpuPipelineParamInfo>&, GpuDeviceFlags) */
  112. SPtr<GpuParams> createGpuParams(const SPtr<GpuPipelineParamInfo>& paramInfo,
  113. GpuDeviceFlags deviceMask = GDF_DEFAULT);
  114. protected:
  115. friend class bs::IndexBuffer;
  116. friend class IndexBuffer;
  117. friend class bs::VertexBuffer;
  118. friend class VertexBuffer;
  119. friend class bs::VertexDeclaration;
  120. friend class bs::GpuParamBlockBuffer;
  121. friend class bs::GpuBuffer;
  122. friend class GpuBuffer;
  123. /** Key for use in the vertex declaration map. */
  124. struct VertexDeclarationKey
  125. {
  126. VertexDeclarationKey(const List<VertexElement>& elements);
  127. class HashFunction
  128. {
  129. public:
  130. size_t operator()(const VertexDeclarationKey& key) const;
  131. };
  132. class EqualFunction
  133. {
  134. public:
  135. bool operator()(const VertexDeclarationKey& lhs, const VertexDeclarationKey& rhs) const;
  136. };
  137. List<VertexElement> elements;
  138. };
  139. /** @copydoc createVertexBuffer */
  140. virtual SPtr<VertexBuffer> createVertexBufferInternal(const VERTEX_BUFFER_DESC& desc,
  141. GpuDeviceFlags deviceMask = GDF_DEFAULT) = 0;
  142. /** @copydoc createIndexBuffer */
  143. virtual SPtr<IndexBuffer> createIndexBufferInternal(const INDEX_BUFFER_DESC& desc,
  144. GpuDeviceFlags deviceMask = GDF_DEFAULT) = 0;
  145. /** @copydoc createGpuParamBlockBuffer */
  146. virtual SPtr<GpuParamBlockBuffer> createGpuParamBlockBufferInternal(UINT32 size,
  147. GpuParamBlockUsage usage = GPBU_DYNAMIC, GpuDeviceFlags deviceMask = GDF_DEFAULT) = 0;
  148. /** @copydoc createGpuBuffer */
  149. virtual SPtr<GpuBuffer> createGpuBufferInternal(const GPU_BUFFER_DESC& desc,
  150. GpuDeviceFlags deviceMask = GDF_DEFAULT) = 0;
  151. /** @copydoc createVertexDeclaration(const List<VertexElement>&, GpuDeviceFlags) */
  152. virtual SPtr<VertexDeclaration> createVertexDeclarationInternal(const List<VertexElement>& elements,
  153. GpuDeviceFlags deviceMask = GDF_DEFAULT);
  154. /** @copydoc createGpuParams */
  155. virtual SPtr<GpuParams> createGpuParamsInternal(const SPtr<GpuPipelineParamInfo>& paramInfo,
  156. GpuDeviceFlags deviceMask = GDF_DEFAULT);
  157. typedef UnorderedMap<VertexDeclarationKey, SPtr<VertexDeclaration>,
  158. VertexDeclarationKey::HashFunction, VertexDeclarationKey::EqualFunction> DeclarationMap;
  159. DeclarationMap mCachedDeclarations;
  160. };
  161. }
  162. /** @} */
  163. }