BsProfilerOverlay.h 7.4 KB

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