BsProfilerOverlay.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. #pragma once
  2. #include "BsPrerequisites.h"
  3. #include "BsComponent.h"
  4. #include "BsProfilerGPU.h"
  5. #include "BsModule.h"
  6. #include "BsEvent.h"
  7. namespace BansheeEngine
  8. {
  9. class ProfilerOverlayInternal;
  10. /**
  11. * @brief Types of profiler overlay.
  12. */
  13. enum class ProfilerOverlayType
  14. {
  15. CPUSamples,
  16. GPUSamples
  17. };
  18. /**
  19. * @brief Handles rendering of Profiler information as an overlay in a viewport.
  20. *
  21. * @note Component wrapper of ProfilerOverlayInternal.
  22. */
  23. class BS_EXPORT ProfilerOverlay : public Component
  24. {
  25. public:
  26. /**
  27. * @brief Constructs a new overlay attached to the specified parent and displayed on the provided viewport.
  28. */
  29. ProfilerOverlay(const HSceneObject& parent, const ViewportPtr& target);
  30. ~ProfilerOverlay();
  31. /**
  32. * @brief Changes the viewport to display the overlay on.
  33. */
  34. void setTarget(const ViewportPtr& target);
  35. /**
  36. * @brief Shows the overlay of the specified type.
  37. */
  38. void show(ProfilerOverlayType type);
  39. /**
  40. * @brief Hides the overlay.
  41. */
  42. void hide();
  43. /**
  44. * @copydoc Component::update
  45. */
  46. void update() override;
  47. private:
  48. ProfilerOverlayInternal* mInternal;
  49. /************************************************************************/
  50. /* RTTI */
  51. /************************************************************************/
  52. public:
  53. friend class ProfilerOverlayRTTI;
  54. static RTTITypeBase* getRTTIStatic();
  55. virtual RTTITypeBase* getRTTI() const override;
  56. ProfilerOverlay() { } // Serialization only
  57. };
  58. /**
  59. * @brief Handles rendering of Profiler information as an overlay in a viewport.
  60. */
  61. class BS_EXPORT ProfilerOverlayInternal
  62. {
  63. public:
  64. /**
  65. * @brief Holds data about GUI elements in a single row of a "CPU basic" sample.
  66. */
  67. struct BasicRow
  68. {
  69. GUILayout* labelLayout;
  70. GUILayout* contentLayout;
  71. GUIFixedSpace* labelSpace;
  72. Vector<GUIElement*> elements;
  73. HString name;
  74. HString pctOfParent;
  75. HString numCalls;
  76. HString numAllocs;
  77. HString numFrees;
  78. HString avgTime;
  79. HString totalTime;
  80. HString avgTimeSelf;
  81. HString totalTimeSelf;
  82. };
  83. /**
  84. * @brief Holds data about GUI elements in a single row of a "CPU precise" sample.
  85. */
  86. struct PreciseRow
  87. {
  88. GUILayout* labelLayout;
  89. GUILayout* contentLayout;
  90. GUIFixedSpace* labelSpace;
  91. Vector<GUIElement*> elements;
  92. HString name;
  93. HString pctOfParent;
  94. HString numCalls;
  95. HString numAllocs;
  96. HString numFrees;
  97. HString avgCycles;
  98. HString totalCycles;
  99. HString avgCyclesSelf;
  100. HString totalCyclesSelf;
  101. };
  102. /**
  103. * @brief Holds data about GUI elements in a single row of a GPU sample.
  104. */
  105. struct GPUSampleRow
  106. {
  107. GUILayout* layout;
  108. Vector<GUIElement*> elements;
  109. HString name;
  110. HString time;
  111. };
  112. public:
  113. /**
  114. * @brief Constructs a new overlay attached to the specified parent and displayed on the provided viewport.
  115. */
  116. ProfilerOverlayInternal(const ViewportPtr& target);
  117. ~ProfilerOverlayInternal();
  118. /**
  119. * @brief Changes the viewport to display the overlay on.
  120. */
  121. void setTarget(const ViewportPtr& target);
  122. /**
  123. * @brief Shows the overlay of the specified type.
  124. */
  125. void show(ProfilerOverlayType type);
  126. /**
  127. * @brief Hides the overlay.
  128. */
  129. void hide();
  130. /**
  131. * @brief Updates overlay contents. Should be called once per frame.
  132. */
  133. void update();
  134. private:
  135. /**
  136. * @brief Called whenever the viewport resizes in order to rearrange the GUI elements.
  137. */
  138. void targetResized();
  139. /**
  140. * @brief Updates sizes of GUI areas used for displaying CPU sample data. To be called
  141. * after viewport change or resize.
  142. */
  143. void updateCPUSampleAreaSizes();
  144. /**
  145. * @brief Updates sizes of GUI areas used for displaying GPU sample data. To be called
  146. * after viewport change or resize.
  147. */
  148. void updateGPUSampleAreaSizes();
  149. /**
  150. * @brief Updates CPU GUI elements from the data in the provided profiler reports. To be called
  151. * whenever a new report is received.
  152. */
  153. void updateCPUSampleContents(const ProfilerReport& simReport, const ProfilerReport& coreReport);
  154. /**
  155. * @brief Updates GPU GUI elemnts from the data in the provided profiler report. To be called whenever
  156. * a new report is received.
  157. */
  158. void updateGPUSampleContents(const GPUProfilerReport& gpuReport);
  159. static const UINT32 MAX_DEPTH;
  160. ProfilerOverlayType mType;
  161. ViewportPtr mTarget;
  162. HSceneObject mWidgetSO;
  163. GameObjectHandle<GUIWidget> mWidget;
  164. GUILayout* mBasicLayoutLabels = nullptr;
  165. GUILayout* mPreciseLayoutLabels = nullptr;
  166. GUILayout* mBasicLayoutContents = nullptr;
  167. GUILayout* mPreciseLayoutContents = nullptr;
  168. GUIElement* mTitleBasicName = nullptr;
  169. GUIElement* mTitleBasicPctOfParent = nullptr;
  170. GUIElement* mTitleBasicNumCalls = nullptr;
  171. GUIElement* mTitleBasicNumAllocs = nullptr;
  172. GUIElement* mTitleBasicNumFrees = nullptr;
  173. GUIElement* mTitleBasicAvgTime = nullptr;
  174. GUIElement* mTitleBasicTotalTime = nullptr;
  175. GUIElement* mTitleBasicAvgTitleSelf = nullptr;
  176. GUIElement* mTitleBasicTotalTimeSelf = nullptr;
  177. GUIElement* mTitlePreciseName = nullptr;
  178. GUIElement* mTitlePrecisePctOfParent = nullptr;
  179. GUIElement* mTitlePreciseNumCalls = nullptr;
  180. GUIElement* mTitlePreciseNumAllocs = nullptr;
  181. GUIElement* mTitlePreciseNumFrees = nullptr;
  182. GUIElement* mTitlePreciseAvgCycles = nullptr;
  183. GUIElement* mTitlePreciseTotalCycles = nullptr;
  184. GUIElement* mTitlePreciseAvgCyclesSelf = nullptr;
  185. GUIElement* mTitlePreciseTotalCyclesSelf = nullptr;
  186. GUILayout* mGPULayoutFrameContents = nullptr;
  187. GUILayout* mGPULayoutFrameContentsLeft = nullptr;
  188. GUILayout* mGPULayoutFrameContentsRight = nullptr;
  189. GUILayout* mGPULayoutSamples = nullptr;
  190. GUILayout* mGPULayoutSampleContents = nullptr;
  191. HString mGPUFrameNumStr;
  192. HString mGPUTimeStr;
  193. HString mGPUDrawCallsStr;
  194. HString mGPURenTargetChangesStr;
  195. HString mGPUPresentsStr;
  196. HString mGPUClearsStr;
  197. HString mGPUVerticesStr;
  198. HString mGPUPrimitivesStr;
  199. HString mGPUSamplesStr;
  200. HString mGPUBlendStateChangesStr;
  201. HString mGPURasterStateChangesStr;
  202. HString mGPUDepthStencilStateChangesStr;
  203. HString mGPUObjectsCreatedStr;
  204. HString mGPUObjectsDestroyedStr;
  205. HString mGPUResourceWritesStr;
  206. HString mGPUResourceReadsStr;
  207. HString mGPUTextureBindsStr;
  208. HString mGPUSamplerBindsStr;
  209. HString mGPUVertexBufferBindsStr;
  210. HString mGPUIndexBufferBindsStr;
  211. HString mGPUGPUProgramBufferBindsStr;
  212. HString mGPUGPUProgramBindsStr;
  213. Vector<BasicRow> mBasicRows;
  214. Vector<PreciseRow> mPreciseRows;
  215. Vector<GPUSampleRow> mGPUSampleRows;
  216. HEvent mTargetResizedConn;
  217. bool mIsShown;
  218. };
  219. }