Actually pass block coordinates to shape selection function

This commit is contained in:
Pavel Krajcevski 2014-03-22 19:25:21 -04:00
parent 891e2cfee8
commit 9144db4de6
2 changed files with 20 additions and 10 deletions

View File

@ -120,8 +120,8 @@ namespace BPTCC {
// A shape selection function is one that selects a BPTC shape from a given // A shape selection function is one that selects a BPTC shape from a given
// block position and pixel array. // block position and pixel array.
typedef ShapeSelection typedef ShapeSelection (*ShapeSelectionFn)
(*ShapeSelectionFn)(uint32 x, uint32 y, const uint32 pixels[16]); (uint32 x, uint32 y, const uint32 pixels[16], const void *userData);
// Compression parameters used to control the BPTC compressor. Each of the // Compression parameters used to control the BPTC compressor. Each of the
// values has a default, so this is not strictly required to perform // values has a default, so this is not strictly required to perform
@ -136,6 +136,9 @@ namespace BPTCC {
// every block mode is still available. // every block mode is still available.
ShapeSelectionFn m_ShapeSelectionFn; ShapeSelectionFn m_ShapeSelectionFn;
// The user data passed to the shape selection function.
void *m_ShapeSelectionUserData;
// The block modes that the compressor will consider during compression. // The block modes that the compressor will consider during compression.
// This variable is a bit mask of EBlockMode values and by default contains // This variable is a bit mask of EBlockMode values and by default contains
// every mode. This setting can be used to further restrict the search space // every mode. This setting can be used to further restrict the search space
@ -144,6 +147,7 @@ namespace BPTCC {
CompressionSettings() CompressionSettings()
: m_ShapeSelectionFn(NULL) : m_ShapeSelectionFn(NULL)
, m_ShapeSelectionUserData(NULL)
, m_BlockModes(static_cast<EBlockMode>(0xFF)) , m_BlockModes(static_cast<EBlockMode>(0xFF))
{ } { }
}; };

View File

@ -1493,10 +1493,12 @@ std::ostream &operator<<(const BlockLogger &bl, const T &v) {
// Function prototypes // Function prototypes
static void CompressBC7Block( static void CompressBC7Block(
const uint32 x, const uint32 y,
const uint32 block[16], uint8 *outBuf, const uint32 block[16], uint8 *outBuf,
const CompressionSettings = CompressionSettings() const CompressionSettings = CompressionSettings()
); );
static void CompressBC7Block( static void CompressBC7Block(
const uint32 x, const uint32 y,
const uint32 block[16], uint8 *outBuf, const BlockLogger &logStream, const uint32 block[16], uint8 *outBuf, const BlockLogger &logStream,
const CompressionSettings = CompressionSettings() const CompressionSettings = CompressionSettings()
); );
@ -1594,7 +1596,7 @@ void Compress(const FasTC::CompressionJob &cj, CompressionSettings settings) {
uint32 block[16]; uint32 block[16];
GetBlock(i, j, cj.Width(), inPixels, block); GetBlock(i, j, cj.Width(), inPixels, block);
CompressBC7Block(block, outBuf, settings); CompressBC7Block(i, j, block, outBuf, settings);
#ifndef NDEBUG #ifndef NDEBUG
const uint8 *inBlock = reinterpret_cast<const uint8 *>(block); const uint8 *inBlock = reinterpret_cast<const uint8 *>(block);
@ -1669,7 +1671,7 @@ void CompressAtomic(FasTC::CompressionJobList &cjl) {
uint32 y = cj->YStart() + 4 * (blockIdx / (cj->Width() / 4)); uint32 y = cj->YStart() + 4 * (blockIdx / (cj->Width() / 4));
const uint32 *inPixels = reinterpret_cast<const uint32 *>(cj->InBuf()); const uint32 *inPixels = reinterpret_cast<const uint32 *>(cj->InBuf());
GetBlock(x, y, cj->Width(), inPixels, block); GetBlock(x, y, cj->Width(), inPixels, block);
CompressBC7Block(block, out); CompressBC7Block(x, y, block, out);
} }
if(TestAndSet(cjl.GetFinishedFlag(jobIdx)) == 0) { if(TestAndSet(cjl.GetFinishedFlag(jobIdx)) == 0) {
@ -1699,9 +1701,9 @@ void CompressAtomic(FasTC::CompressionJobList &cjl) {
if(logStream) { if(logStream) {
uint64 blockIdx = cj.CoordsToBlockIdx(i, j); uint64 blockIdx = cj.CoordsToBlockIdx(i, j);
CompressBC7Block(block, outBuf, BlockLogger(blockIdx, *logStream), settings); CompressBC7Block(i, j, block, outBuf, BlockLogger(blockIdx, *logStream), settings);
} else { } else {
CompressBC7Block(block, outBuf, settings); CompressBC7Block(i, j, block, outBuf, settings);
} }
#ifndef NDEBUG #ifndef NDEBUG
@ -1775,8 +1777,9 @@ static uint32 kAlphaModes =
static_cast<uint32>(eBlockMode_Six) | static_cast<uint32>(eBlockMode_Six) |
static_cast<uint32>(eBlockMode_Seven); static_cast<uint32>(eBlockMode_Seven);
static ShapeSelection BoxSelection(uint32 x, uint32 y, static ShapeSelection BoxSelection(
const uint32 pixels[16]) { uint32, uint32, const uint32 pixels[16], const void *
) {
ShapeSelection result; ShapeSelection result;
@ -1897,7 +1900,8 @@ static void CompressClusters(ShapeSelection selection, const uint32 pixels[16],
} }
} }
static void CompressBC7Block(const uint32 block[16], uint8 *outBuf, static void CompressBC7Block(const uint32 x, const uint32 y,
const uint32 block[16], uint8 *outBuf,
const CompressionSettings settings) { const CompressionSettings settings) {
// All a single color? // All a single color?
if(AllOneColor(block)) { if(AllOneColor(block)) {
@ -1930,7 +1934,8 @@ static void CompressBC7Block(const uint32 block[16], uint8 *outBuf,
} }
assert(selectionFn); assert(selectionFn);
ShapeSelection selection = selectionFn(0, 0, block); ShapeSelection selection =
selectionFn(x, y, block, settings.m_ShapeSelectionUserData);
selection.m_SelectedModes &= settings.m_BlockModes; selection.m_SelectedModes &= settings.m_BlockModes;
assert(selection.m_SelectedModes); assert(selection.m_SelectedModes);
CompressClusters(selection, block, outBuf, NULL, NULL); CompressClusters(selection, block, outBuf, NULL, NULL);
@ -2029,6 +2034,7 @@ static void PrintStat(const BlockLogger &lgr, const char *stat, const T &v) {
// Compress a single block but collect statistics as well... // Compress a single block but collect statistics as well...
static void CompressBC7Block( static void CompressBC7Block(
const uint32 x, const uint32 y,
const uint32 block[16], uint8 *outBuf, const BlockLogger &logStream, const uint32 block[16], uint8 *outBuf, const BlockLogger &logStream,
const CompressionSettings settings const CompressionSettings settings
) { ) {