Fix a few issues and make sure that when we write out to a file, only the intended values are reported. We still have to fix the accumulated stat reporting and make it thread-safe.

This commit is contained in:
Pavel Krajcevski 2012-10-08 13:16:41 -04:00
parent fdcd7c2edc
commit 71fbbca1ee
3 changed files with 72 additions and 32 deletions

View File

@ -66,23 +66,23 @@ static const char *kBlockStatString[kNumBlockStats] = {
"BlockStat_Path",
"BlockStat_Mode",
"eBlockStat_ModeZeroEstimate",
"eBlockStat_ModeOneEstimate",
"eBlockStat_ModeTwoEstimate",
"eBlockStat_ModeThreeEstimate",
"eBlockStat_ModeFourEstimate",
"eBlockStat_ModeFiveEstimate",
"eBlockStat_ModeSixEstimate",
"eBlockStat_ModeSevenEstimate",
"BlockStat_ModeZeroEstimate",
"BlockStat_ModeOneEstimate",
"BlockStat_ModeTwoEstimate",
"BlockStat_ModeThreeEstimate",
"BlockStat_ModeFourEstimate",
"BlockStat_ModeFiveEstimate",
"BlockStat_ModeSixEstimate",
"BlockStat_ModeSevenEstimate",
"eBlockStat_ModeZeroError",
"eBlockStat_ModeOneError",
"eBlockStat_ModeTwoError",
"eBlockStat_ModeThreeError",
"eBlockStat_ModeFourError",
"eBlockStat_ModeFiveError",
"eBlockStat_ModeSixError",
"eBlockStat_ModeSevenError",
"BlockStat_ModeZeroError",
"BlockStat_ModeOneError",
"BlockStat_ModeTwoError",
"BlockStat_ModeThreeError",
"BlockStat_ModeFourError",
"BlockStat_ModeFiveError",
"BlockStat_ModeSixError",
"BlockStat_ModeSevenError",
};
static const uint32 kNumShapes2 = 64;
@ -1614,8 +1614,15 @@ namespace BC7C
BC7CompressionMode compressor0(0, opaque);
BC7CompressionMode compressor2(2, opaque);
double error, bestError = (shapeIdx < 16)? compressor0.Compress(tmpStream0, shapeIdx, clusters) : DBL_MAX;
gModeError[0] = bestError;
double error, bestError;
if(shapeIdx < 16) {
bestError = compressor0.Compress(tmpStream0, shapeIdx, clusters);
gModeError[0] = bestError;
}
else {
bestError = DBL_MAX;
gModeError[0] = -1.0;
}
gModeChosen = 0;
memcpy(outBuf, tempBuf0, 16);
if(bestError == 0.0) {
@ -1680,11 +1687,18 @@ namespace BC7C
}
const float *w = BC7C::GetErrorMetric();
const double err1 = 0.0001 + c.QuantizedError(Min, Max, 8, 0xFFFCFCFC, RGBAVector(w[0], w[1], w[2], w[3]));
gModeEstimate[1] = min(gModeEstimate[1], err1);
if(err1 >= 0.0)
gModeEstimate[1] = err1;
else
gModeEstimate[1] = min(gModeEstimate[1], err1);
const double err3 = 0.0001 + c.QuantizedError(Min, Max, 8, 0xFFFEFEFE, RGBAVector(w[0], w[1], w[2], w[3]));
gModeEstimate[3] = min(gModeEstimate[3], err3);
if(err3 >= 0.0)
gModeEstimate[3] = err3;
else
gModeEstimate[3] = min(gModeEstimate[3], err3);
return min(err1, err3);
}
@ -1700,10 +1714,16 @@ namespace BC7C
const float *w = BC7C::GetErrorMetric();
const double err0 = 0.0001 + c.QuantizedError(Min, Max, 4, 0xFFF0F0F0, RGBAVector(w[0], w[1], w[2], w[3]));
gModeEstimate[0] = min(gModeEstimate[0], err0);
if(err0 >= 0.0)
gModeEstimate[0] = err0;
else
gModeEstimate[0] = min(gModeEstimate[0], err0);
const double err2 = 0.0001 + c.QuantizedError(Min, Max, 4, 0xFFF8F8F8, RGBAVector(w[0], w[1], w[2], w[3]));
gModeEstimate[2] = min(gModeEstimate[2], err2);
if(err2 >= 0.0)
gModeEstimate[2] = err2;
else
gModeEstimate[2] = min(gModeEstimate[2], err2);
return min(err0, err2);
}
@ -1740,7 +1760,7 @@ namespace BC7C
// reset global variables...
gBestMode = 0;
for(int i = 0; i < BC7CompressionMode::kNumModes; i++){
gModeError[i] = gModeEstimate[i] = DBL_MAX;
gModeError[i] = gModeEstimate[i] = -1.0;
}
blockIdx = statManager->BeginBlock();
@ -1833,9 +1853,6 @@ namespace BC7C
if(statManager) {
BlockStat s = BlockStat(kBlockStatString[eBlockStat_Path], 2);
statManager->AddStat(blockIdx, s);
s = BlockStat(kBlockStatString[eBlockStat_Mode], gBestMode);
statManager->AddStat(blockIdx, s);
}
return;
}

View File

@ -15,6 +15,13 @@ public:
BlockStat &operator=(const BlockStat &);
private:
const enum Type {
eType_Float,
eType_Int,
kNumTypes
} m_Type;
static const int kStatNameSz = 32;
CHAR m_StatName[kStatNameSz];
union {

View File

@ -18,17 +18,21 @@ static T max(const T &a, const T &b) {
//
////////////////////////////////////////////////////////////////////////////////
BlockStat::BlockStat(const CHAR *statName, int stat) : m_IntStat(stat)
BlockStat::BlockStat(const CHAR *statName, int stat)
: m_IntStat(stat)
, m_Type(eType_Int)
{
strncpy(m_StatName, statName, kStatNameSz);
}
BlockStat::BlockStat(const CHAR *statName, double stat) : m_FloatStat(stat)
BlockStat::BlockStat(const CHAR *statName, double stat)
: m_FloatStat(stat)
, m_Type(eType_Float)
{
strncpy(m_StatName, statName, kStatNameSz);
}
BlockStat::BlockStat(const BlockStat &other) {
BlockStat::BlockStat(const BlockStat &other) : m_Type(other.m_Type) {
memcpy(this, &other, sizeof(*this));
}
@ -133,12 +137,24 @@ void BlockStatManager::ToFile(const CHAR *filename) {
BlockStat s = head->GetStat();
CHAR statStr[256];
snprintf(statStr, 256, "%d: %s, %llu, %f\n", i, s.m_StatName, s.m_IntStat, s.m_FloatStat);
switch(s.m_Type) {
case BlockStat::eType_Float:
snprintf(statStr, 256, "%d,%s,%f\n", i, s.m_StatName, s.m_FloatStat);
break;
case BlockStat::eType_Int:
snprintf(statStr, 256, "%d,%s,%llu\n", i, s.m_StatName, s.m_IntStat);
break;
default:
assert(false);
break;
}
int statStrLen = strlen(statStr);
if(statStrLen > 255) {
statStr[255] = '\n';
statStrLen = 255;
statStrLen = 256;
}
fstr.Write((uint8 *)statStr, statStrLen);