Skip to content

Commit 4a07e27

Browse files
committed
Parallelize the BDSP sparkle detector across the filters.
1 parent 96fadf1 commit 4a07e27

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

SerialPrograms/Source/PokemonBDSP/Inference/ShinyDetection/PokemonBDSP_ShinySparkleSet.cpp

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
*/
66

77
#include "Common/Cpp/PrettyPrint.h"
8+
#include "Common/Cpp/Concurrency/SpinLock.h"
89
#include "Kernels/Waterfill/Kernels_Waterfill_Session.h"
10+
#include "CommonFramework/Tools/GlobalThreadPools.h"
911
#include "CommonTools/Images/BinaryImage_FilterRgb32.h"
1012
#include "PokemonSwSh/Inference/ShinyDetection/PokemonSwSh_SparkleDetectorRadial.h"
1113
#include "PokemonBDSP_ShinySparkleSet.h"
@@ -116,19 +118,25 @@ void ShinySparkleSetBDSP::read_from_image(size_t screen_area, const ImageViewRGB
116118
{0xff909000, 0xffffffff},
117119
}
118120
);
119-
auto session = make_WaterfillSession();
120121

122+
SpinLock lock;
121123
double best_alpha = 0;
122-
for (PackedBinaryMatrix& matrix : matrices){
123-
session->set_source(matrix);
124-
ShinySparkleSetBDSP sparkles = find_sparkles(screen_area, *session);
125-
sparkles.update_alphas();
126-
double alpha = sparkles.alpha_overall();
127-
if (best_alpha < alpha){
128-
best_alpha = alpha;
129-
*this = std::move(sparkles);
130-
}
131-
}
124+
GlobalThreadPools::realtime_inference().run_in_parallel(
125+
[&](size_t index){
126+
auto session = make_WaterfillSession();
127+
session->set_source(matrices[index]);
128+
ShinySparkleSetBDSP sparkles = find_sparkles(screen_area, *session);
129+
sparkles.update_alphas();
130+
double alpha = sparkles.alpha_overall();
131+
132+
WriteSpinLock lg(lock);
133+
if (best_alpha < alpha){
134+
best_alpha = alpha;
135+
*this = std::move(sparkles);
136+
}
137+
},
138+
0, matrices.size(), 1
139+
);
132140
}
133141

134142

0 commit comments

Comments
 (0)