CommandBuffer.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. // Copyright (C) 2009-2016, Panagiotis Christopoulos Charitos.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma once
  6. #include <anki/gr/GrObject.h>
  7. #include <anki/util/Functions.h>
  8. namespace anki
  9. {
  10. /// @addtogroup graphics
  11. /// @{
  12. /// The draw indirect structure for index drawing, also the parameters of a
  13. /// regular drawcall
  14. class DrawElementsIndirectInfo
  15. {
  16. public:
  17. DrawElementsIndirectInfo()
  18. {
  19. }
  20. DrawElementsIndirectInfo(U32 count,
  21. U32 instanceCount,
  22. U32 firstIndex,
  23. U32 baseVertex,
  24. U32 baseInstance)
  25. : m_count(count)
  26. , m_instanceCount(instanceCount)
  27. , m_firstIndex(firstIndex)
  28. , m_baseVertex(baseVertex)
  29. , m_baseInstance(baseInstance)
  30. {
  31. }
  32. U32 m_count = MAX_U32;
  33. U32 m_instanceCount = 1;
  34. U32 m_firstIndex = 0;
  35. U32 m_baseVertex = 0;
  36. U32 m_baseInstance = 0;
  37. };
  38. /// The draw indirect structure for arrays drawing, also the parameters of a
  39. /// regular drawcall
  40. class DrawArraysIndirectInfo
  41. {
  42. public:
  43. DrawArraysIndirectInfo()
  44. {
  45. }
  46. DrawArraysIndirectInfo(
  47. U32 count, U32 instanceCount, U32 first, U32 baseInstance)
  48. : m_count(count)
  49. , m_instanceCount(instanceCount)
  50. , m_first(first)
  51. , m_baseInstance(baseInstance)
  52. {
  53. }
  54. U32 m_count = MAX_U32;
  55. U32 m_instanceCount = 1;
  56. U32 m_first = 0;
  57. U32 m_baseInstance = 0;
  58. };
  59. /// Command buffer init info.
  60. class CommandBufferInitInfo
  61. {
  62. public:
  63. Bool m_secondLevel = false;
  64. FramebufferPtr m_framebuffer; ///< For second level command buffers.
  65. };
  66. /// Command buffer initialization hints. They are used to optimize the
  67. /// allocators of a command buffer.
  68. class CommandBufferInitHints
  69. {
  70. friend class CommandBufferImpl;
  71. private:
  72. PtrSize m_chunkSize = 1024 * 64;
  73. };
  74. /// Command buffer.
  75. class CommandBuffer : public GrObject
  76. {
  77. public:
  78. /// Construct.
  79. CommandBuffer(GrManager* manager);
  80. /// Destroy.
  81. ~CommandBuffer();
  82. /// Access the implementation.
  83. CommandBufferImpl& getImplementation()
  84. {
  85. return *m_impl;
  86. }
  87. /// Create command buffer.
  88. void create(CommandBufferInitHints hints = CommandBufferInitHints());
  89. /// Compute initialization hints.
  90. CommandBufferInitHints computeInitHints() const;
  91. /// Flush command buffer for deferred execution.
  92. void flush();
  93. /// Flush and wait to finish.
  94. void finish();
  95. /// @name State manipulation
  96. /// @{
  97. /// Set the viewport.
  98. void setViewport(U16 minx, U16 miny, U16 maxx, U16 maxy);
  99. /// Set depth offset and units.
  100. void setPolygonOffset(F32 offset, F32 units);
  101. /// Bind pipeline.
  102. void bindPipeline(PipelinePtr ppline);
  103. /// Bind framebuffer.
  104. void bindFramebuffer(FramebufferPtr fb);
  105. /// Bind resources.
  106. void bindResourceGroup(
  107. ResourceGroupPtr rc, U slot, const DynamicBufferInfo* dynInfo);
  108. /// @}
  109. /// @name Jobs
  110. /// @{
  111. void drawElements(U32 count,
  112. U32 instanceCount = 1,
  113. U32 firstIndex = 0,
  114. U32 baseVertex = 0,
  115. U32 baseInstance = 0);
  116. void drawArrays(
  117. U32 count, U32 instanceCount = 1, U32 first = 0, U32 baseInstance = 0);
  118. void drawElementsConditional(OcclusionQueryPtr query,
  119. U32 count,
  120. U32 instanceCount = 1,
  121. U32 firstIndex = 0,
  122. U32 baseVertex = 0,
  123. U32 baseInstance = 0);
  124. void drawArraysConditional(OcclusionQueryPtr query,
  125. U32 count,
  126. U32 instanceCount = 1,
  127. U32 first = 0,
  128. U32 baseInstance = 0);
  129. void dispatchCompute(U32 groupCountX, U32 groupCountY, U32 groupCountZ);
  130. void generateMipmaps(TexturePtr tex);
  131. void generateMipmaps(TexturePtr tex, U surface);
  132. void copyTextureToTexture(TexturePtr src,
  133. U srcSlice,
  134. U srcLevel,
  135. TexturePtr dest,
  136. U destSlice,
  137. U destLevel);
  138. /// @}
  139. /// @name Resource upload
  140. /// @{
  141. /// Upload data to a texture.
  142. void textureUpload(
  143. TexturePtr tex, U32 mipmap, U32 slice, const DynamicBufferToken& token);
  144. /// Write data to a buffer. It will copy the dynamic memory to the buffer
  145. /// starting from offset to the range indicated by the allocation of the
  146. /// token.
  147. void writeBuffer(
  148. BufferPtr buff, PtrSize offset, const DynamicBufferToken& token);
  149. /// @}
  150. /// @name Sync
  151. /// @{
  152. void setPipelineBarrier(PipelineStageBit src, PipelineStageBit dst);
  153. void setBufferMemoryBarrier(
  154. BufferPtr buff, ResourceAccessBit src, ResourceAccessBit dst);
  155. /// @}
  156. /// @name Other
  157. /// @{
  158. /// Begin query.
  159. void beginOcclusionQuery(OcclusionQueryPtr query);
  160. /// End query.
  161. void endOcclusionQuery(OcclusionQueryPtr query);
  162. /// Append a second level command buffer.
  163. void pushSecondLevelCommandBuffer(CommandBufferPtr cmdb);
  164. Bool isEmpty() const;
  165. /// @}
  166. private:
  167. UniquePtr<CommandBufferImpl> m_impl;
  168. };
  169. /// @}
  170. } // end namespace anki