experiments with fresnel and shadergraph
[WindSway-HDRP.git] / Library / PackageCache / com.unity.render-pipelines.high-definition@4.10.0-preview / Runtime / Core / Script / Profiler / MiniProfiler.cs
blobd90e3949ab0fdb5ae2aabf71ad590de0498a6b65
1 using System.Collections;
2 using System.Collections.Generic;
3 using UnityEngine;
5 using UnityEngine.Profiling;
6 using UnityEngine.Rendering;
8 namespace UnityEngine.Experimental.Rendering
10 public class MiniProfiler : MonoBehaviour
12 private bool m_Enable = false;
14 private const int k_AverageFrameCount = 64;
16 private int m_frameCount = 0;
17 private float m_AccDeltaTime;
18 private float m_AvgDeltaTime;
20 internal class RecorderEntry
22 public string name;
23 public float time;
24 public int count;
25 public float avgTime;
26 public float avgCount;
27 public float accTime;
28 public int accCount;
29 public Recorder recorder;
32 RecorderEntry[] recordersList =
34 new RecorderEntry() { name="RenderLoop.Draw" },
35 new RecorderEntry() { name="Shadows.Draw" },
36 new RecorderEntry() { name="RenderLoopNewBatcher.Draw" },
37 new RecorderEntry() { name="ShadowLoopNewBatcher.Draw" },
38 new RecorderEntry() { name="RenderLoopDevice.Idle" },
41 void OnEnable()
43 RegisterDebug("Frame Statistics");
46 void Ondisable()
48 UnRegisterDebug("Frame Statistics");
51 void Awake()
53 for (int i = 0; i < recordersList.Length; i++)
55 var sampler = Sampler.Get(recordersList[i].name);
56 if (sampler != null)
58 recordersList[i].recorder = sampler.GetRecorder();
63 void Update()
65 if (Input.GetKeyDown(KeyCode.F9))
67 GraphicsSettings.useScriptableRenderPipelineBatching = !GraphicsSettings.useScriptableRenderPipelineBatching;
70 if (m_Enable)
73 // get timing & update average accumulators
74 for (int i = 0; i < recordersList.Length; i++)
76 recordersList[i].time = recordersList[i].recorder.elapsedNanoseconds / 1000000.0f;
77 recordersList[i].count = recordersList[i].recorder.sampleBlockCount;
78 recordersList[i].accTime += recordersList[i].time;
79 recordersList[i].accCount += recordersList[i].count;
82 m_AccDeltaTime += Time.deltaTime;
84 m_frameCount++;
85 // time to time, update average values & reset accumulators
86 if (m_frameCount >= k_AverageFrameCount)
88 for (int i = 0; i < recordersList.Length; i++)
90 recordersList[i].avgTime = recordersList[i].accTime * (1.0f / k_AverageFrameCount);
91 recordersList[i].avgCount = recordersList[i].accCount * (1.0f / k_AverageFrameCount);
92 recordersList[i].accTime = 0.0f;
93 recordersList[i].accCount = 0;
97 m_AvgDeltaTime = m_AccDeltaTime / k_AverageFrameCount;
98 m_AccDeltaTime = 0.0f;
99 m_frameCount = 0;
105 void OnGUI()
107 if (m_Enable)
109 GraphicsSettings.useScriptableRenderPipelineBatching = GUI.Toggle(new Rect(10, 28, 200, 20), GraphicsSettings.useScriptableRenderPipelineBatching, "SRP Batcher (F9)");
110 GUI.skin.label.fontSize = 17;
111 GUI.color = new Color(1, 1, 1, 1);
112 float w = 800, h = 24 + (recordersList.Length + 10) * 18 + 8;
114 GUILayout.BeginArea(new Rect(32, 50, w, h), "Mini Profiler", GUI.skin.window);
115 string sLabel = System.String.Format("<b>{0:F2} FPS ({1:F2}ms)</b>\n", 1.0f / m_AvgDeltaTime, Time.deltaTime * 1000.0f);
116 for (int i = 0; i < recordersList.Length; i++)
118 sLabel += string.Format("{0:F2}ms (*{1:F2})\t({2:F2}ms *{3:F2})\t<b>{4}</b>\n", recordersList[i].avgTime, recordersList[i].avgCount, recordersList[i].time, recordersList[i].count, recordersList[i].name);
120 GUILayout.Label(sLabel);
122 //Memory =========================================================/* Added by Ming Wai */
123 long num1 = UnityEngine.Profiling.Profiler.GetAllocatedMemoryForGraphicsDriver() / 1024 / 1024;
124 long num2 = UnityEngine.Profiling.Profiler.GetTotalAllocatedMemoryLong() / 1024 / 1024;
125 long num3 = UnityEngine.Profiling.Profiler.GetTotalReservedMemoryLong() / 1024 / 1024;
126 long num4 = UnityEngine.Profiling.Profiler.GetTotalUnusedReservedMemoryLong() / 1024 / 1024;
127 //long num5 = UnityEngine.Profiling.Profiler.GetTempAllocatorSize() / 1024 / 1024;
129 GUILayout.BeginHorizontal();
130 GUILayout.Label(
131 "Allocated Mem For GfxDriver\n" +
132 "Total Allocated Mem\n" +
133 "Total Reserved Mem\n" +
134 "Total Unused Reserved Mem\n"//+
135 //"Temp Allocator Size\n"
138 GUILayout.Label(
139 num1 + " mb\n" +
140 num2 + " mb\n" +
141 num3 + " mb\n" +
142 num4 + " mb\n"//+
143 //num5+" mb\n"
145 GUILayout.EndHorizontal();
147 GUILayout.EndArea();
151 public void RegisterDebug(string menuName)
153 List<DebugUI.Widget> widgets = new List<DebugUI.Widget>();
154 widgets.AddRange(
155 new DebugUI.Widget[]
157 new DebugUI.Container
159 displayName = "Mini Profiler",
160 children =
162 new DebugUI.BoolField { displayName = "Enable Mini Profiler", getter = () => m_Enable, setter = value => m_Enable = value },
163 new DebugUI.BoolField { displayName = "Enable New Batcher", getter = () => GraphicsSettings.useScriptableRenderPipelineBatching , setter = value => GraphicsSettings.useScriptableRenderPipelineBatching = value },
168 var panel = DebugManager.instance.GetPanel(menuName, true);
169 panel.children.Add(widgets.ToArray());
172 public static void UnRegisterDebug(string menuName)
174 DebugManager.instance.RemovePanel(menuName);