mirror of
https://github.com/yuzu-emu/FasTC
synced 2024-11-23 14:03:35 +00:00
Partition compression code into separate functions.
This commit is contained in:
parent
2fa4da80ed
commit
72c44f51d1
1 changed files with 67 additions and 36 deletions
|
@ -57,6 +57,71 @@ static void ReportError(const char *msg) {
|
||||||
fprintf(stderr, "TexComp -- %s\n", msg);
|
fprintf(stderr, "TexComp -- %s\n", msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static double CompressImageInSerial(
|
||||||
|
const ImageFile &img,
|
||||||
|
const SCompressionSettings &settings,
|
||||||
|
const CompressionFunc f,
|
||||||
|
unsigned char *outBuf
|
||||||
|
) {
|
||||||
|
double cmpTimeTotal = 0.0;
|
||||||
|
|
||||||
|
for(int i = 0; i < settings.iNumCompressions; i++) {
|
||||||
|
|
||||||
|
StopWatch stopWatch = StopWatch();
|
||||||
|
stopWatch.Reset();
|
||||||
|
stopWatch.Start();
|
||||||
|
|
||||||
|
(*f)(img.GetPixels(), outBuf, img.GetWidth(), img.GetHeight());
|
||||||
|
|
||||||
|
stopWatch.Stop();
|
||||||
|
|
||||||
|
cmpTimeTotal += stopWatch.TimeInMilliseconds();
|
||||||
|
}
|
||||||
|
|
||||||
|
double cmpTime = cmpTimeTotal / double(settings.iNumCompressions);
|
||||||
|
return cmpTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
static double CompressImageWithThreads(
|
||||||
|
const ImageFile &img,
|
||||||
|
const SCompressionSettings &settings,
|
||||||
|
const CompressionFunc f,
|
||||||
|
unsigned char *outBuf
|
||||||
|
) {
|
||||||
|
|
||||||
|
ThreadGroup tgrp (settings.iNumThreads, img, f, outBuf);
|
||||||
|
if(!(tgrp.PrepareThreads())) {
|
||||||
|
assert(!"Thread group failed to prepare threads?!");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
double cmpTimeTotal = 0.0;
|
||||||
|
for(int i = 0; i < settings.iNumCompressions; i++) {
|
||||||
|
if(i > 0)
|
||||||
|
tgrp.PrepareThreads();
|
||||||
|
|
||||||
|
tgrp.Start();
|
||||||
|
tgrp.Join();
|
||||||
|
|
||||||
|
StopWatch stopWatch = tgrp.GetStopWatch();
|
||||||
|
cmpTimeTotal += tgrp.GetStopWatch().TimeInMilliseconds();
|
||||||
|
}
|
||||||
|
|
||||||
|
tgrp.CleanUpThreads();
|
||||||
|
|
||||||
|
double cmpTime = cmpTimeTotal / double(settings.iNumCompressions);
|
||||||
|
return cmpTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
static double CompressImageWithWorkerQueue(
|
||||||
|
const ImageFile &img,
|
||||||
|
const SCompressionSettings &settings,
|
||||||
|
const CompressionFunc f,
|
||||||
|
unsigned char *outBuf
|
||||||
|
) {
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
CompressedImage * CompressImage(
|
CompressedImage * CompressImage(
|
||||||
const ImageFile &img,
|
const ImageFile &img,
|
||||||
const SCompressionSettings &settings
|
const SCompressionSettings &settings
|
||||||
|
@ -95,44 +160,10 @@ CompressedImage * CompressImage(
|
||||||
double cmpMSTime = 0.0;
|
double cmpMSTime = 0.0;
|
||||||
|
|
||||||
if(settings.iNumThreads > 1) {
|
if(settings.iNumThreads > 1) {
|
||||||
|
cmpMSTime = CompressImageWithThreads(img, settings, f, cmpData);
|
||||||
ThreadGroup tgrp (settings.iNumThreads, img, f, cmpData);
|
|
||||||
if(!(tgrp.PrepareThreads())) {
|
|
||||||
assert(!"Thread group failed to prepare threads?!");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
double cmpTimeTotal = 0.0;
|
|
||||||
for(int i = 0; i < settings.iNumCompressions; i++) {
|
|
||||||
if(i > 0)
|
|
||||||
tgrp.PrepareThreads();
|
|
||||||
|
|
||||||
tgrp.Start();
|
|
||||||
tgrp.Join();
|
|
||||||
|
|
||||||
StopWatch stopWatch = tgrp.GetStopWatch();
|
|
||||||
cmpTimeTotal += tgrp.GetStopWatch().TimeInMilliseconds();
|
|
||||||
}
|
|
||||||
|
|
||||||
cmpMSTime = cmpTimeTotal / double(settings.iNumCompressions);
|
|
||||||
|
|
||||||
tgrp.CleanUpThreads();
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
double cmpTimeTotal = 0.0;
|
cmpMSTime = CompressImageInSerial(img, settings, f, cmpData);
|
||||||
for(int i = 0; i < settings.iNumCompressions; i++) {
|
|
||||||
|
|
||||||
StopWatch stopWatch = StopWatch();
|
|
||||||
stopWatch.Reset();
|
|
||||||
stopWatch.Start();
|
|
||||||
|
|
||||||
(*f)(img.GetPixels(), cmpData, img.GetWidth(), img.GetHeight());
|
|
||||||
stopWatch.Stop();
|
|
||||||
|
|
||||||
cmpTimeTotal += stopWatch.TimeInMilliseconds();
|
|
||||||
}
|
|
||||||
|
|
||||||
cmpMSTime = cmpTimeTotal / double(settings.iNumCompressions);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
outImg = new CompressedImage(img.GetWidth(), img.GetHeight(), settings.format, cmpData);
|
outImg = new CompressedImage(img.GetWidth(), img.GetHeight(), settings.format, cmpData);
|
||||||
|
|
Loading…
Reference in a new issue