Material Clustering Benchmark
DispatcherRSstopCondition.cs
Go to the documentation of this file.
1using UnityEngine;
2
4{
6 {
8 ComputeShader computeShader,
13 )
14 : base(
21 ) { }
22
23 // stop condition impossible without readback
24 public override bool doesReadback => true;
25
26 public override bool usesStopCondition => true;
27
28 public override string name => $"{base.name} (readback)";
29
30 public override void RunClustering(ClusteringTextures clusteringTextures)
31 {
32 this.KMiteration(clusteringTextures, rejectOld: true);
33
34 int numFailedSwaps = 0;
35
36 for (int i = 1; ; i += this.parameters.numIterationsKm)
37 {
38 this.RandomSwap(clusteringTextures);
39
40 for (int k = 0; k < this.parameters.numIterationsKm; k++)
41 {
42 this.KMiteration(clusteringTextures, rejectOld: false);
43 }
44
45 using (
46 ADispatcherRS.RandomSwapResult randomSwapResult =
48 )
49 {
50 switch (randomSwapResult.stopConditionOverride)
51 {
53 return;
55 continue;
57 if (randomSwapResult.swapFailed)
58 {
59 // failed swap
60
61 numFailedSwaps++;
62 if (numFailedSwaps > StopCondition.maxFailedSwaps)
63 {
64 return;
65 }
66 }
67 else
68 {
69 // successful swap
70
71 if (
72 randomSwapResult.varianceReduction
74 )
75 {
76 return;
77 }
78 }
79
80 continue;
81 }
82 }
83 }
84 }
85 }
86}
ClusteringRTsAndBuffers clusteringRTsAndBuffers
Definition: ADispatcher.cs:11
readonly ComputeShader computeShader
Definition: ADispatcher.cs:28
RandomSwapResult ValidateCandidatesReadback()
void RandomSwap(ClusteringTextures clusteringTextures)
Call Allocate before using and Dispose after using.
void KMiteration(ClusteringTextures textures, bool rejectOld)
First attributes pixels to clusters. Then updates cluster centers. In order to use the resulting clus...
Definition: DispatcherKM.cs:46
DispatcherRSstopCondition(ComputeShader computeShader, bool doRandomizeEmptyClusters, bool useFullResTexRef, ADispatcherRS.Parameters parameters, ClusteringRTsAndBuffers clusteringRTsAndBuffers)
override void RunClustering(ClusteringTextures clusteringTextures)
const int maxFailedSwaps
Stop when the number of failed swaps exceeds this value.
Call Dispose after using.