BsProfilerOverlay.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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 Determines type of data to display on the 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 CameraPtr& target);
  30. ~ProfilerOverlay();
  31. /**
  32. * @brief Changes the camera to display the overlay on.
  33. */
  34. void setTarget(const CameraPtr& 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. GUILabel* guiName;
  73. GUILabel* guiPctOfParent;
  74. GUILabel* guiNumCalls;
  75. GUILabel* guiNumAllocs;
  76. GUILabel* guiNumFrees;
  77. GUILabel* guiAvgTime;
  78. GUILabel* guiTotalTime;
  79. GUILabel* guiAvgTimeSelf;
  80. GUILabel* guiTotalTimeSelf;
  81. HString name;
  82. HString pctOfParent;
  83. HString numCalls;
  84. HString numAllocs;
  85. HString numFrees;
  86. HString avgTime;
  87. HString totalTime;
  88. HString avgTimeSelf;
  89. HString totalTimeSelf;
  90. bool disabled;
  91. };
  92. /**
  93. * @brief Holds data about GUI elements in a single row of a "CPU precise" sample.
  94. */
  95. struct PreciseRow
  96. {
  97. GUILayout* labelLayout;
  98. GUILayout* contentLayout;
  99. GUIFixedSpace* labelSpace;
  100. GUILabel* guiName;
  101. GUILabel* guiPctOfParent;
  102. GUILabel* guiNumCalls;
  103. GUILabel* guiNumAllocs;
  104. GUILabel* guiNumFrees;
  105. GUILabel* guiAvgCycles;
  106. GUILabel* guiTotalCycles;
  107. GUILabel* guiAvgCyclesSelf;
  108. GUILabel* guiTotalCyclesSelf;
  109. HString name;
  110. HString pctOfParent;
  111. HString numCalls;
  112. HString numAllocs;
  113. HString numFrees;
  114. HString avgCycles;
  115. HString totalCycles;
  116. HString avgCyclesSelf;
  117. HString totalCyclesSelf;
  118. bool disabled;
  119. };
  120. /**
  121. * @brief Holds data about GUI elements in a single row of a GPU sample.
  122. */
  123. struct GPUSampleRow
  124. {
  125. GUILayout* layout;
  126. GUILabel* guiName;
  127. GUILabel* guiTime;
  128. HString name;
  129. HString time;
  130. bool disabled;
  131. };
  132. public:
  133. /**
  134. * @brief Constructs a new overlay attached to the specified parent and displayed on the provided camera.
  135. */
  136. ProfilerOverlayInternal(const CameraPtr& target);
  137. ~ProfilerOverlayInternal();
  138. /**
  139. * @brief Changes the camera to display the overlay on.
  140. */
  141. void setTarget(const CameraPtr& target);
  142. /**
  143. * @brief Shows the overlay of the specified type.
  144. */
  145. void show(ProfilerOverlayType type);
  146. /**
  147. * @brief Hides the overlay.
  148. */
  149. void hide();
  150. /**
  151. * @brief Updates overlay contents. Should be called once per frame.
  152. */
  153. void update();
  154. private:
  155. /**
  156. * @brief Called whenever the viewport resizes in order to rearrange the GUI elements.
  157. */
  158. void targetResized();
  159. /**
  160. * @brief Updates sizes of GUI areas used for displaying CPU sample data. To be called
  161. * after viewport change or resize.
  162. */
  163. void updateCPUSampleAreaSizes();
  164. /**
  165. * @brief Updates sizes of GUI areas used for displaying GPU sample data. To be called
  166. * after viewport change or resize.
  167. */
  168. void updateGPUSampleAreaSizes();
  169. /**
  170. * @brief Updates CPU GUI elements from the data in the provided profiler reports. To be called
  171. * whenever a new report is received.
  172. */
  173. void updateCPUSampleContents(const ProfilerReport& simReport, const ProfilerReport& coreReport);
  174. /**
  175. * @brief Updates GPU GUI elemnts from the data in the provided profiler report. To be called whenever
  176. * a new report is received.
  177. */
  178. void updateGPUSampleContents(const GPUProfilerReport& gpuReport);
  179. static const UINT32 MAX_DEPTH;
  180. ProfilerOverlayType mType;
  181. ViewportPtr mTarget;
  182. HSceneObject mWidgetSO;
  183. GameObjectHandle<CGUIWidget> mWidget;
  184. GUILayout* mBasicLayoutLabels = nullptr;
  185. GUILayout* mPreciseLayoutLabels = nullptr;
  186. GUILayout* mBasicLayoutContents = nullptr;
  187. GUILayout* mPreciseLayoutContents = nullptr;
  188. GUIElement* mTitleBasicName = nullptr;
  189. GUIElement* mTitleBasicPctOfParent = nullptr;
  190. GUIElement* mTitleBasicNumCalls = nullptr;
  191. GUIElement* mTitleBasicNumAllocs = nullptr;
  192. GUIElement* mTitleBasicNumFrees = nullptr;
  193. GUIElement* mTitleBasicAvgTime = nullptr;
  194. GUIElement* mTitleBasicTotalTime = nullptr;
  195. GUIElement* mTitleBasicAvgTitleSelf = nullptr;
  196. GUIElement* mTitleBasicTotalTimeSelf = nullptr;
  197. GUIElement* mTitlePreciseName = nullptr;
  198. GUIElement* mTitlePrecisePctOfParent = nullptr;
  199. GUIElement* mTitlePreciseNumCalls = nullptr;
  200. GUIElement* mTitlePreciseNumAllocs = nullptr;
  201. GUIElement* mTitlePreciseNumFrees = nullptr;
  202. GUIElement* mTitlePreciseAvgCycles = nullptr;
  203. GUIElement* mTitlePreciseTotalCycles = nullptr;
  204. GUIElement* mTitlePreciseAvgCyclesSelf = nullptr;
  205. GUIElement* mTitlePreciseTotalCyclesSelf = nullptr;
  206. GUILayout* mGPULayoutFrameContents = nullptr;
  207. GUILayout* mGPULayoutFrameContentsLeft = nullptr;
  208. GUILayout* mGPULayoutFrameContentsRight = nullptr;
  209. GUILayout* mGPULayoutSamples = nullptr;
  210. GUILayout* mGPULayoutSampleContents = nullptr;
  211. HString mGPUFrameNumStr;
  212. HString mGPUTimeStr;
  213. HString mGPUDrawCallsStr;
  214. HString mGPURenTargetChangesStr;
  215. HString mGPUPresentsStr;
  216. HString mGPUClearsStr;
  217. HString mGPUVerticesStr;
  218. HString mGPUPrimitivesStr;
  219. HString mGPUSamplesStr;
  220. HString mGPUBlendStateChangesStr;
  221. HString mGPURasterStateChangesStr;
  222. HString mGPUDepthStencilStateChangesStr;
  223. HString mGPUObjectsCreatedStr;
  224. HString mGPUObjectsDestroyedStr;
  225. HString mGPUResourceWritesStr;
  226. HString mGPUResourceReadsStr;
  227. HString mGPUTextureBindsStr;
  228. HString mGPUSamplerBindsStr;
  229. HString mGPUVertexBufferBindsStr;
  230. HString mGPUIndexBufferBindsStr;
  231. HString mGPUGPUProgramBufferBindsStr;
  232. HString mGPUGPUProgramBindsStr;
  233. Vector<BasicRow> mBasicRows;
  234. Vector<PreciseRow> mPreciseRows;
  235. Vector<GPUSampleRow> mGPUSampleRows;
  236. HEvent mTargetResizedConn;
  237. bool mIsShown;
  238. };
  239. }