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