Material Clustering Benchmark
ClusteringTestGui.cs
Go to the documentation of this file.
1using UnityEngine;
3using System.Collections.Generic;
4using static Diagnostics;
5
6public class ClusteringTestGui : MonoBehaviour
7{
8 private List<WorkOption> workOptions;
9 private WorkOption frameTimeWorkOption;
10
11 public UnityEngine.Video.VideoClip[] videos;
12 public ComputeShader csHighlightRemoval;
13
15
16 private class WorkOption
17 {
18 public bool enabled;
19 public BenchmarkDescription workList;
20
21 public WorkOption(BenchmarkDescription workList)
22 {
23 this.enabled = false;
24 this.workList = workList;
25 }
26 }
27
28 private GUIStyle guiStyle;
29
30 private void InitGuiStyle()
31 {
32 const int size = 16;
33 Texture2D guiBackgroundTex = new Texture2D(size, size);
34 Color[] colors = new Color[size * size];
35 for (int i = 0; i < size * size; i++)
36 {
37 colors[i] = Color.black;
38 }
39 guiBackgroundTex.SetPixels(colors);
40 guiBackgroundTex.Apply();
41
42 this.guiStyle = new GUIStyle();
43 guiStyle.normal.background = guiBackgroundTex;
44 }
45
46 private void Awake()
47 {
48 Assert(this.videos.Length != 0, "No video files provided.");
49 foreach (UnityEngine.Video.VideoClip video in this.videos)
50 {
51 Assert(
52 video.width == video.height,
53 $"Video file {video.name} does not have height equal to width. This is unsuppoted to simplify implementation."
54 );
55 Assert(
56 video.width >= ClusteringTest.fullTextureSize,
57 $"Video file {video.name} has smaller resolution than required. File resolution: {video.width}; required: {ClusteringTest.fullTextureSize}."
58 );
59 }
60 Assert(
61 System.Diagnostics.Stopwatch.IsHighResolution,
62 "High resolution timer not available."
63 );
64
65 InitGuiStyle();
66
67 this.workOptions = new List<WorkOption>();
68
69 this.frameTimeWorkOption = new WorkOption(
70 new FrameTime(
71 kernelSize: ClusteringTest.kernelSize,
72 videos: this.videos,
73 csHighlightRemoval: this.csHighlightRemoval
75 );
76
77 this.workOptions.Add(this.frameTimeWorkOption);
78
79 this.workOptions.Add(
80 new WorkOption(
82 kernelSize: ClusteringTest.kernelSize,
83 videos: this.videos,
84 csHighlightRemoval: this.csHighlightRemoval
86 )
87 );
88
89 this.workOptions.Add(
90 new WorkOption(
92 kernelSize: ClusteringTest.kernelSize,
93 videos: this.videos,
94 csHighlightRemoval: this.csHighlightRemoval
96 )
97 );
98
99 this.workOptions.Add(
100 new WorkOption(
101 new RSnumKM(
102 kernelSize: ClusteringTest.kernelSize,
103 videos: this.videos,
104 csHighlightRemoval: this.csHighlightRemoval
106 )
107 );
108
109 this.workOptions.Add(
110 new WorkOption(
111 new KHMp(
112 kernelSize: ClusteringTest.kernelSize,
113 videos: this.videos,
114 csHighlightRemoval: this.csHighlightRemoval
116 )
117 );
118
119 this.workOptions.Add(
120 new WorkOption(
122 kernelSize: ClusteringTest.kernelSize,
123 videos: this.videos,
124 csHighlightRemoval: this.csHighlightRemoval
126 )
127 );
128
129 this.workOptions.Add(
130 new WorkOption(
131 new ScanlineJitter(
132 kernelSize: ClusteringTest.kernelSize,
133 videos: this.videos,
134 csHighlightRemoval: this.csHighlightRemoval
136 )
137 );
138
139 this.workOptions.Add(
140 new WorkOption(
141 new StaggeredJitter(
142 kernelSize: ClusteringTest.kernelSize,
143 videos: this.videos,
144 csHighlightRemoval: this.csHighlightRemoval
146 )
147 );
148
149 this.workOptions.Add(
150 new WorkOption(
151 new Subsampling(
152 kernelSize: ClusteringTest.kernelSize,
153 videos: this.videos,
154 csHighlightRemoval: this.csHighlightRemoval
156 )
157 );
158 }
159
160 private static void GuiLine()
161 {
162 GUILayout.Label("-----------------------------------------");
163 }
164
165 /// <summary>
166 /// Warning: even empty <see cref="OnGUI" /> function creates GC allocations! For frame time measurements to be accurate there should be no GC allocations.
167 /// </summary>
168 private void OnGUI()
169 {
170 GUILayout.BeginVertical(guiStyle);
171 {
172 if (this.clusteringTest.enabled)
173 {
174 foreach (WorkOption option in this.workOptions)
175 {
176 if (option.enabled)
177 {
178 GUILayout.Label("- " + option.workList.name);
179 }
180 }
181
182 GuiLine();
183
184 GUILayout.Label(
185 $"Total: {this.clusteringTest.numTotalFinishedDispatches} / {this.clusteringTest.numTotalDispatches}"
186 );
187 GUILayout.Label(
188 $"{this.clusteringTest.currentBenchmark.name}: {this.clusteringTest.numCurBenchmarkFinishedDispatches} / {this.clusteringTest.numCurBenchmarkDispatches}"
189 );
190 GUILayout.Label($"warnings: {this.clusteringTest.warningCounter}");
191 ;
192 }
193 else
194 {
195 foreach (WorkOption option in this.workOptions)
196 {
197 option.enabled = GUILayout.Toggle(option.enabled, option.workList.name);
198 }
199
200 if (GUILayout.Button("Start"))
201 {
202 if (System.IO.Directory.Exists("Reports") == false)
203 {
204 System.IO.Directory.CreateDirectory("Reports");
205 }
206
207 foreach (WorkOption option in this.workOptions)
208 {
209 if (option.enabled)
210 {
211 this.clusteringTest.benchmarkStack.Push(option.workList);
212 }
213 }
214 this.clusteringTest.enabled = true;
215 }
216 }
217 }
218 GUILayout.EndVertical();
219 }
220}
override BenchmarkDescription GenerateBenchmark()
override BenchmarkDescription GenerateBenchmark()
Definition: FrameTime.cs:17
override BenchmarkDescription GenerateBenchmark()
Definition: KHMp.cs:18
override BenchmarkDescription GenerateBenchmark()
Definition: RSnumKM.cs:16
override BenchmarkDescription GenerateBenchmark()
override BenchmarkDescription GenerateBenchmark()
override BenchmarkDescription GenerateBenchmark()
override BenchmarkDescription GenerateBenchmark()
Definition: Subsampling.cs:14
UnityEngine.Video.VideoClip[] videos
ClusteringTest clusteringTest
ComputeShader csHighlightRemoval
const int fullTextureSize
const int kernelSize
Must match the shader.
Stack< BenchmarkDescription > benchmarkStack