Material Clustering Benchmark
ClusteringTest.cs
Go to the documentation of this file.
1using UnityEngine;
2using System.Collections.Generic;
4
5public class ClusteringTest : MonoBehaviour
6{
7 /// <summary>
8 /// Must match the shader.
9 /// </summary>
10 public const int maxNumClusters = 32;
11
12 /// <summary>
13 /// Must match the shader.
14 /// </summary>
15 public const int kernelSize = 16;
16 public const int fullTextureSize = 512;
17
18 public Stack<BenchmarkDescription> benchmarkStack;
20 public ComputeShader csHighlightRemoval;
21 public const string varianceLogPath = "Variance logs";
22
25
28
29 public int warningCounter => this.measurementRunner.warningCounter;
30
31 public enum LogType
32 {
34 Variance
35 }
36
37 private MeasurementRunner measurementRunner;
38
39 // configuration
40 public long? frameStart = null;
41 public long? frameEnd = null;
42
43 private BenchmarkReportCollection reportCollection;
44
45 private void Awake()
46 {
47 this.benchmarkStack = new Stack<BenchmarkDescription>();
48 }
49
50 private void OnEnable()
51 {
52 this.reportCollection = new BenchmarkReportCollection();
53
54 this.numTotalDispatches = 0;
55 foreach (BenchmarkDescription workList in this.benchmarkStack)
56 {
57 this.numTotalDispatches += workList.dispatches.Count;
58 }
59 this.numTotalFinishedDispatches = 0;
60
61 this.currentBenchmark = this.benchmarkStack.Pop();
62 this.numCurBenchmarkFinishedDispatches = 0;
63 this.numCurBenchmarkDispatches = this.currentBenchmark.dispatches.Count;
64
65 this.measurementRunner = new MeasurementRunner(
66 launchParameters: this.currentBenchmark.dispatches.Pop(),
67 videoPlayer: this.GetComponent<UnityEngine.Video.VideoPlayer>(),
68 frameStart: this.frameStart,
69 frameEnd: this.frameEnd,
70 logType: this.currentBenchmark.logType,
71 csHighlightRemoval: this.csHighlightRemoval
72 );
73
74 Debug.Log(this.measurementRunner.paramsJSON);
75 }
76
77 private void OnFinishedRunner()
78 {
79 this.measurementRunner.Dispose();
80
81 if (this.currentBenchmark.dispatches.Count == 0)
82 {
83 System.IO.File.WriteAllText(
84 $"Reports/{this.currentBenchmark.name}.json",
85 JsonUtility.ToJson(this.reportCollection)
86 );
87
88 if (this.benchmarkStack.Count == 0)
89 {
90 this.enabled = false;
91 return;
92 }
93
94 this.currentBenchmark = this.benchmarkStack.Pop();
95 this.numCurBenchmarkFinishedDispatches = 0;
96 this.numCurBenchmarkDispatches = this.currentBenchmark.dispatches.Count;
97
98 this.reportCollection = new BenchmarkReportCollection();
99 }
100
101 this.measurementRunner = new MeasurementRunner(
102 launchParameters: this.currentBenchmark.dispatches.Pop(),
103 videoPlayer: this.GetComponent<UnityEngine.Video.VideoPlayer>(),
104 frameStart: this.frameStart,
105 frameEnd: this.frameEnd,
106 logType: this.currentBenchmark.logType,
107 csHighlightRemoval: this.csHighlightRemoval
108 );
109
110 Debug.Log(this.measurementRunner.paramsJSON);
111 }
112
113 // Update is called once per frame
114 private void Update() { }
115
116 private void OnRenderImage(RenderTexture src, RenderTexture dest)
117 {
118 //try
119 //{
120 this.measurementRunner.ProcessNextFrame(src, dest);
121 /*}
122 catch (System.Exception e)
123 {
124 string msg = $"Exception during processing a frame ({e.GetType().Name}): {e.Message}";
125
126 System.IO.File.WriteAllText($"Reports/Error.txt", msg);
127 Debug.Log(msg);
128
129 this.enabled = false;
130 Application.Quit();
131 throw e;
132 }*/
133
134 if (this.measurementRunner.finished == true)
135 {
136 this.reportCollection.reports.Add(this.measurementRunner.GetReport());
137 this.OnFinishedRunner();
138 this.numCurBenchmarkFinishedDispatches++;
139 this.numTotalFinishedDispatches++;
140 }
141 }
142}
readonly Stack< LaunchParameters > dispatches
int numCurBenchmarkDispatches
const int maxNumClusters
Must match the shader.
BenchmarkDescription currentBenchmark
int numTotalFinishedDispatches
const int fullTextureSize
int numCurBenchmarkFinishedDispatches
const int kernelSize
Must match the shader.
Stack< BenchmarkDescription > benchmarkStack
const string varianceLogPath
ComputeShader csHighlightRemoval
Call Dispose after using.
BenchmarkReport GetReport()
void ProcessNextFrame(RenderTexture src, RenderTexture dst)