-
Notifications
You must be signed in to change notification settings - Fork 878
Expand file tree
/
Copy pathVFXSystemProfilerUI.cs
More file actions
333 lines (293 loc) · 11.5 KB
/
Copy pathVFXSystemProfilerUI.cs
File metadata and controls
333 lines (293 loc) · 11.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Profiling;
using UnityEngine.UIElements;
namespace UnityEditor.VFX.UI
{
class VFXSystemProfilerUI : VFXAnchoredProfilerUI
{
public VFXSystemProfilerUI(VFXContextUI initContextUI, List<VFXContextProfilerUI> systemContexts)
{
m_SystemContexts = new List<VFXContextProfilerUI>(systemContexts);
ScheduleRepositionInitializePanel();
VFXSystemNames systemNames = initContextUI.controller.viewController.graph.systemNames;
string systemName = systemNames.GetUniqueSystemName(initContextUI.controller.model.GetData());
m_InitContextUI = initContextUI;
m_SystemName = systemName;
var contextModel = initContextUI.controller.model;
var vfxData = contextModel.GetData();
bool receivesGPUEvent = false;
foreach (var inputCtx in contextModel.inputContexts)
{
if (inputCtx is VFXBasicGPUEvent)
{
receivesGPUEvent = true;
break;
}
}
m_CanReadbackAliveCount = !receivesGPUEvent || vfxData.IsAttributeStored(VFXAttribute.Alive) ;
title = "Particle System Info";
AddToClassList("VFXSystemProfiler");
AnchorTo(initContextUI);
RegisterCallback<FocusInEvent>(e => e.StopPropagation());
}
private VFXSystemBorder m_SystemBorder;
private List<VFXContextProfilerUI> m_SystemContexts;
private VFXContextUI m_InitContextUI;
private bool m_CanReadbackAliveCount;
//Status elements
private Label m_PlayPauseInfo;
private Label m_SleepStateInfo;
private Label m_CullStateInfo;
public override void Detach()
{
RemoveFromHierarchy();
}
public override void ForceExpand()
{
m_Foldout.value = true;
}
public override void ForceClose()
{
m_Foldout.value = false;
}
public string GetSystemName()
{
return m_SystemName;
}
void ScheduleRepositionInitializePanel()
{
schedule.Execute(() =>
{
m_SystemContexts[0].SetVerticalOffset(resolvedStyle.height);
m_SystemContexts[0].RepositionPanel();
});
}
protected override void OnCollapseChanged(ChangeEvent<bool> evt)
{
base.OnCollapseChanged(evt);
ScheduleRepositionInitializePanel();
}
void AddStatusSection()
{
VisualElement statusContainer = new VisualElement
{
style = { flexDirection = FlexDirection.Row, paddingTop = 2, paddingBottom = 2 }
};
m_PlayPauseInfo = CreateBadge(null, "Indicates the playing status of the game object.");
m_SleepStateInfo = CreateBadge(null, "Indicates if any of the particles are alive or if the system is sleeping");
m_CullStateInfo = CreateBadge(null, "Indicates if the system is visible by any of the cameras or if it is culled");
statusContainer.Add(m_PlayPauseInfo);
statusContainer.Add(m_SleepStateInfo);
statusContainer.Add(m_CullStateInfo);
AddContent(statusContainer);
}
void AddSystemCpuSection(string systemName)
{
var markerName = m_AttachedComponent.GetCPUSystemMarkerName(systemName);
if (string.IsNullOrEmpty(markerName))
return;
var recorder = Recorder.Get(markerName);
VisualElement labelContainer = new VisualElement
{
style = { flexDirection = FlexDirection.Row, paddingTop = 2, paddingBottom = 2 }
};
Label mainLabel = new Label
{
text = "System CPU Update:",
style = { flexGrow = 1, paddingBottom = 2, paddingTop = 2}
};
Label timingLabel = new Label
{
style = { flexGrow = 0, alignSelf = Align.FlexEnd, color = Color.white}
};
labelContainer.Add(mainLabel);
labelContainer.Add(timingLabel);
VFXProfilingBoard.ProfilingItemLeaf leaf = new VFXProfilingBoard.ProfilingItemLeaf(recorder, timingLabel);
m_ProfilingCPUItemLeaves.Add(leaf);
AddContent(labelContainer);
}
private Label m_AggregatedGPULabel;
private long m_AggregatedGPUTime;
void AddAggregatedGPUSection()
{
VisualElement labelContainer = new VisualElement
{
style = { flexDirection = FlexDirection.Row, paddingTop = 2, paddingBottom = 2 }
};
Label descLabel = new Label
{
style = { flexGrow = 1 },
text = "GPU System time:",
};
m_AggregatedGPULabel = new Label
{
style = { flexGrow = 0, alignSelf = Align.FlexEnd}
};
labelContainer.Add(descLabel);
labelContainer.Add(m_AggregatedGPULabel);
if (!m_SupportsGPURecorder)
{
labelContainer.tooltip = kGpuRecorderNotSupportedMsg;
m_AggregatedGPULabel.text = "-";
}
AddContent(labelContainer);
}
void AddGPUMemorySection()
{
long gpuMemoryInBytes = (m_InitContextUI.controller.model.GetData() as VFXDataParticle).attributeBufferSize * 4;
VisualElement labelContainer = new VisualElement
{
style = { flexDirection = FlexDirection.Row, paddingTop = 2, paddingBottom = 2 }
};
Foldout gpuMemFoldout = new Foldout()
{
style = { flexGrow = 1 },
text = "GPU Memory:",
};
Label totalGpuMemLabel = AddLabelToFoldout(gpuMemFoldout);
totalGpuMemLabel.text = "";
Label descLabel = new Label
{
style = { flexGrow = 1 },
text = "Particle Attributes Size:",
};
Label memValueLabel = new Label
{
style = { flexGrow = 0, alignSelf = Align.FlexEnd}
};
memValueLabel.text = EditorUtility.FormatBytes(gpuMemoryInBytes);
labelContainer.Add(descLabel);
labelContainer.Add(memValueLabel);
gpuMemFoldout.Add(labelContainer);
AddContent(gpuMemFoldout);
}
private Label m_AliveCountLabel;
private Label m_CapacityLabel;
void AddOccupancySection()
{
VisualElement labelContainer = new VisualElement
{
style = { flexDirection = FlexDirection.Row, paddingTop = 2, paddingBottom = 2}
};
labelContainer.tooltip = "Current count of living particles over the capacity of the system.";
Label descLabel = new Label
{
style = { flexGrow = 1 },
text = "Alive/Capacity:"
};
m_AliveCountLabel = new Label
{
style = { flexGrow = 0, alignSelf = Align.FlexEnd}
};
var particleSystemInfo = m_AttachedComponent.GetParticleSystemInfo(m_SystemName);
m_CapacityLabel = new Label
{
style = { flexGrow = 0, alignSelf = Align.FlexEnd},
text = $"/ {particleSystemInfo.capacity.ToString()}",
};
labelContainer.Add(descLabel);
labelContainer.Add(m_AliveCountLabel);
labelContainer.Add(m_CapacityLabel);
AddContent(labelContainer);
}
void ComputeAggregatedGPUFromContexts()
{
long aggregate = 0L;
foreach (var contextPanel in m_SystemContexts)
{
aggregate += contextPanel.GetGPUTimingAggregate();
}
m_AggregatedGPUTime = aggregate;
}
internal IEnumerable<VFXSlot> GetTextureSlotsFromContexts()
{
foreach (var contextPanel in m_SystemContexts)
{
foreach (var slotLabel in contextPanel.GetTextureSlotLabels())
{
yield return slotLabel.slot;
}
}
}
public long GetSystemAggregatedGPUTime()
{
return m_AggregatedGPUTime;
}
internal override void UpdateDynamicValues()
{
base.UpdateDynamicValues();
if (m_AggregatedGPULabel != null && m_SupportsGPURecorder)
{
ComputeAggregatedGPUFromContexts();
m_AggregatedGPULabel.text = $"{NanoToMilli(m_AggregatedGPUTime):F3} ms";
}
var particleSystemInfo = m_AttachedComponent.GetParticleSystemInfo(m_SystemName);
if (m_PlayPauseInfo != null)
{
if (m_AttachedComponent.pause)
{
m_PlayPauseInfo.RemoveFromClassList("play");
m_PlayPauseInfo.AddToClassList("pause");
m_PlayPauseInfo.text = "PAUSED";
}
else
{
m_PlayPauseInfo.RemoveFromClassList("pause");
m_PlayPauseInfo.AddToClassList("play");
m_PlayPauseInfo.text = "PLAYING";
}
if (particleSystemInfo.sleeping)
{
m_SleepStateInfo.RemoveFromClassList("awake");
m_SleepStateInfo.AddToClassList("sleep");
m_SleepStateInfo.text = "SLEEP";
}
else
{
m_SleepStateInfo.RemoveFromClassList("sleep");
m_SleepStateInfo.AddToClassList("awake");
m_SleepStateInfo.text = "AWAKE";
}
if (m_AttachedComponent.culled)
{
m_CullStateInfo.RemoveFromClassList("visible");
m_CullStateInfo.AddToClassList("culled");
m_CullStateInfo.text = "CULLED";
}
else
{
m_CullStateInfo.RemoveFromClassList("culled");
m_CullStateInfo.AddToClassList("visible");
m_CullStateInfo.text = "VISIBLE";
}
}
if (m_AliveCountLabel != null)
{
string aliveCountStr = m_CanReadbackAliveCount ? particleSystemInfo.aliveCount.ToString() : "-";
m_AliveCountLabel.text = $"{aliveCountStr}";
m_AliveCountLabel.ClearClassList();
m_AliveCountLabel.AddToClassList(ComputeEfficiencyColor(particleSystemInfo.aliveCount, particleSystemInfo.capacity));
}
}
protected override void SetupStatsLayout()
{
if (attachedComponent == null)
return;
if (m_ProfilingCPUItemLeaves != null)
{
ClearContent();
m_ProfilingCPUItemLeaves.Clear();
}
else
{
m_ProfilingCPUItemLeaves = new List<VFXProfilingBoard.ProfilingItemLeaf>();
}
AddStatusSection();
AddOccupancySection();
AddSystemCpuSection(m_SystemName);
AddAggregatedGPUSection();
AddGPUMemorySection();
}
}
}