mirror of
https://github.com/yuzu-emu/FasTC.git
synced 2024-11-30 20:04:18 +01:00
Repurpose the rest of our scaffolding to use Compression Jobs
This commit is contained in:
parent
435f935de3
commit
ae2324153d
@ -103,20 +103,12 @@ namespace BC7C
|
||||
|
||||
// Compress the image given as RGBA data to BC7 format. Width and Height are the dimensions of
|
||||
// the image in pixels.
|
||||
void CompressImageBC7(
|
||||
const unsigned char *inBuf,
|
||||
unsigned char *outBuf,
|
||||
unsigned int width,
|
||||
unsigned int height
|
||||
);
|
||||
void Compress(const CompressionJob &);
|
||||
|
||||
void CompressImageBC7Stats(
|
||||
const unsigned char *inBuf,
|
||||
unsigned char *outBuf,
|
||||
unsigned int width,
|
||||
unsigned int height,
|
||||
BlockStatManager &statManager
|
||||
);
|
||||
// Perform a compression while recording all of the choices the compressor made into a
|
||||
// list of statistics. We can use this to see whether or not certain heuristics are working, such as
|
||||
// whether or not certain modes are being chosen more often than others, etc.
|
||||
void CompressWithStats(const CompressionJob &, BlockStatManager &statManager);
|
||||
|
||||
#ifdef HAS_SSE_41
|
||||
// Compress the image given as RGBA data to BC7 format using an algorithm optimized for SIMD
|
||||
@ -132,5 +124,5 @@ namespace BC7C
|
||||
#endif
|
||||
|
||||
// Decompress the image given as BC7 data to R8G8B8A8 format. Width and Height are the dimensions of the image in pixels.
|
||||
void DecompressImageBC7(const unsigned char* inBuf, unsigned char* outBuf, unsigned int width, unsigned int height);
|
||||
void Decompress(const DecompressionJob &);
|
||||
}
|
||||
|
@ -1484,14 +1484,13 @@ namespace BC7C
|
||||
// 4-byte RGBA format. The width and height parameters specify the size of the image in pixels.
|
||||
// The buffer pointed to by outBuf should be large enough to store the compressed image. This
|
||||
// implementation has an 4:1 compression ratio.
|
||||
void CompressImageBC7(const unsigned char *inBuf, unsigned char *outBuf, unsigned int width, unsigned int height)
|
||||
void Compress(const CompressionJob &cj)
|
||||
{
|
||||
const int kMaxIters = BC7CompressionMode::kMaxAnnealingIterations;
|
||||
BC7CompressionMode::MaxAnnealingIterations = std::min(kMaxIters, GetQualityLevel());
|
||||
|
||||
for(uint32 j = 0; j < height; j += 4)
|
||||
const unsigned char *inBuf = cj.inBuf;
|
||||
unsigned char *outBuf = cj.outBuf;
|
||||
for(uint32 j = 0; j < cj.height; j += 4)
|
||||
{
|
||||
for(uint32 i = 0; i < width; i += 4)
|
||||
for(uint32 i = 0; i < cj.width; i += 4)
|
||||
{
|
||||
// ExtractBlock(inBuf + i * 4, width, block);
|
||||
CompressBC7Block((const uint32 *)inBuf, outBuf);
|
||||
@ -1582,19 +1581,15 @@ namespace BC7C
|
||||
}
|
||||
#endif // HAS_ATOMICS
|
||||
|
||||
void CompressImageBC7Stats(
|
||||
const unsigned char *inBuf,
|
||||
unsigned char *outBuf,
|
||||
unsigned int width,
|
||||
unsigned int height,
|
||||
void CompressWithStats(
|
||||
const CompressionJob &cj,
|
||||
BlockStatManager &statManager
|
||||
) {
|
||||
const int kMaxIters = BC7CompressionMode::kMaxAnnealingIterations;
|
||||
BC7CompressionMode::MaxAnnealingIterations = std::min(kMaxIters, GetQualityLevel());
|
||||
|
||||
for(uint32 j = 0; j < height; j += 4)
|
||||
const unsigned char *inBuf = cj.inBuf;
|
||||
unsigned char *outBuf = cj.outBuf;
|
||||
for(uint32 j = 0; j < cj.height; j += 4)
|
||||
{
|
||||
for(uint32 i = 0; i < width; i += 4)
|
||||
for(uint32 i = 0; i < cj.width; i += 4)
|
||||
{
|
||||
// ExtractBlock(inBuf + i * 4, width, block);
|
||||
CompressBC7Block((const uint32 *)inBuf, outBuf, statManager);
|
||||
@ -2567,16 +2562,17 @@ namespace BC7C
|
||||
}
|
||||
|
||||
// Convert the image from a BC7 buffer to a RGBA8 buffer
|
||||
void DecompressImageBC7(const uint8 *inBuf, uint8* outBuf, unsigned int width, unsigned int height) {
|
||||
void Decompress(const DecompressionJob &dj) {
|
||||
|
||||
unsigned char *outBuf = dj.outBuf;
|
||||
unsigned int blockIdx = 0;
|
||||
// for(unsigned int j = 0; j < height; j += 4, outBuf += width * 3 * 4)
|
||||
for(unsigned int j = 0; j < height; j += 4)
|
||||
for(unsigned int j = 0; j < dj.height; j += 4)
|
||||
{
|
||||
for(unsigned int i = 0; i < width; i += 4)
|
||||
for(unsigned int i = 0; i < dj.width; i += 4)
|
||||
{
|
||||
uint32 pixels[16];
|
||||
DecompressBC7Block(inBuf + (16*(blockIdx++)), pixels);
|
||||
DecompressBC7Block(dj.inBuf + (16*(blockIdx++)), pixels);
|
||||
|
||||
memcpy(outBuf, pixels, 16 * sizeof(uint32));
|
||||
//memcpy(outBuf + (width * 4), pixels + 4, 4 * sizeof(uint32));
|
||||
|
@ -103,24 +103,13 @@ extern bool CompressImageData(
|
||||
// returns the compressed image data into outData. It is assumed that there is
|
||||
// enough space allocated for outData to store the compressed data. Allocation
|
||||
// is dependent on the compression format.
|
||||
typedef void (* CompressionFunc)(
|
||||
const unsigned char *inData, // Raw image data
|
||||
unsigned char *outData, // Buffer to store compressed data.
|
||||
unsigned int width, // Image width
|
||||
unsigned int height // Image height
|
||||
);
|
||||
typedef void (* CompressionFunc)(const CompressionJob &);
|
||||
|
||||
// A compression function format. It takes the raw data and image dimensions and
|
||||
// returns the compressed image data into outData. It is assumed that there is
|
||||
// enough space allocated for outData to store the compressed data. Allocation
|
||||
// is dependent on the compression format.
|
||||
typedef void (* CompressionFuncWithStats)(
|
||||
const unsigned char *inData, // Raw image data
|
||||
unsigned char *outData, // Buffer to store compressed data.
|
||||
unsigned int width, // Image width
|
||||
unsigned int height, // Image height
|
||||
BlockStatManager &statManager// Stat manager
|
||||
);
|
||||
typedef void (* CompressionFuncWithStats)(const CompressionJob &, BlockStatManager &statManager);
|
||||
|
||||
// This function computes the Peak Signal to Noise Ratio between a
|
||||
// compressed image and a raw image.
|
||||
|
@ -127,7 +127,10 @@ bool CompressedImage::DecompressImage(unsigned char *outBuf, unsigned int outBuf
|
||||
|
||||
switch(m_Format) {
|
||||
case eCompressionFormat_BPTC:
|
||||
BC7C::DecompressImageBC7(m_Data, outBuf, m_Width, m_Height);
|
||||
{
|
||||
DecompressionJob dj (m_Data, outBuf, m_Width, m_Height);
|
||||
BC7C::Decompress(dj);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -82,7 +82,7 @@ static CompressionFuncWithStats ChooseFuncFromSettingsWithStats(const SCompress
|
||||
switch(s.format) {
|
||||
case eCompressionFormat_BPTC:
|
||||
{
|
||||
return BC7C::CompressImageBC7Stats;
|
||||
return BC7C::CompressWithStats;
|
||||
}
|
||||
break;
|
||||
|
||||
@ -105,7 +105,7 @@ static CompressionFunc ChooseFuncFromSettings(const SCompressionSettings &s) {
|
||||
return BC7C::CompressImageBC7SIMD;
|
||||
}
|
||||
#endif
|
||||
return BC7C::CompressImageBC7;
|
||||
return BC7C::Compress;
|
||||
}
|
||||
break;
|
||||
|
||||
@ -140,11 +140,12 @@ static double CompressImageInSerial(
|
||||
stopWatch.Start();
|
||||
|
||||
// !FIXME! We're assuming that we have 4x4 blocks here...
|
||||
CompressionJob cj (imgData, outBuf, imgDataSz / 16, 4);
|
||||
if(fStats && settings.pStatManager) {
|
||||
(*fStats)(imgData, outBuf, imgDataSz / 16, 4, *(settings.pStatManager));
|
||||
(*fStats)(cj, *(settings.pStatManager));
|
||||
}
|
||||
else {
|
||||
(*f)(imgData, outBuf, imgDataSz / 16, 4);
|
||||
(*f)(cj);
|
||||
}
|
||||
|
||||
stopWatch.Stop();
|
||||
|
@ -86,10 +86,11 @@ void CmpThread::operator()() {
|
||||
return;
|
||||
}
|
||||
|
||||
CompressionJob cj (m_InBuf, m_OutBuf, m_Width, m_Height);
|
||||
if(m_CmpFunc)
|
||||
(*m_CmpFunc)(m_InBuf, m_OutBuf, m_Width, m_Height);
|
||||
(*m_CmpFunc)(cj);
|
||||
else
|
||||
(*m_CmpFuncWithStats)(m_InBuf, m_OutBuf, m_Width, m_Height, *m_StatManager);
|
||||
(*m_CmpFuncWithStats)(cj, *m_StatManager);
|
||||
|
||||
{
|
||||
TCLock lock(*m_ParentCounterLock);
|
||||
@ -112,7 +113,7 @@ ThreadGroup::ThreadGroup( int numThreads, const unsigned char *inBuf, unsigned i
|
||||
, m_ThreadState(eThreadState_Done)
|
||||
, m_ExitFlag(false)
|
||||
, m_CompressedBlockSize(
|
||||
(func == BC7C::CompressImageBC7
|
||||
(func == BC7C::Compress
|
||||
#ifdef HAS_SSE_41
|
||||
|| func == BC7C::CompressImageBC7SIMD
|
||||
#endif
|
||||
@ -122,7 +123,7 @@ ThreadGroup::ThreadGroup( int numThreads, const unsigned char *inBuf, unsigned i
|
||||
0
|
||||
)
|
||||
, m_UncompressedBlockSize(
|
||||
(func == BC7C::CompressImageBC7
|
||||
(func == BC7C::Compress
|
||||
#ifdef HAS_SSE_41
|
||||
|| func == BC7C::CompressImageBC7SIMD
|
||||
#endif
|
||||
@ -162,13 +163,13 @@ ThreadGroup::ThreadGroup(
|
||||
, m_ThreadState(eThreadState_Done)
|
||||
, m_ExitFlag(false)
|
||||
, m_CompressedBlockSize(
|
||||
(func == BC7C::CompressImageBC7Stats)?
|
||||
(func == BC7C::CompressWithStats)?
|
||||
16
|
||||
:
|
||||
0
|
||||
)
|
||||
, m_UncompressedBlockSize(
|
||||
(func == BC7C::CompressImageBC7Stats)?
|
||||
(func == BC7C::CompressWithStats)?
|
||||
64
|
||||
:
|
||||
0
|
||||
|
@ -100,10 +100,12 @@ void WorkerThread::operator()() {
|
||||
{
|
||||
const uint8 *src = m_Parent->GetSrcForThread(m_ThreadIdx);
|
||||
uint8 *dst = m_Parent->GetDstForThread(m_ThreadIdx);
|
||||
|
||||
CompressionJob cj (src, dst, 4 * m_Parent->GetNumBlocksForThread(m_ThreadIdx), 4);
|
||||
if(f)
|
||||
(*f)(src, dst, 4 * m_Parent->GetNumBlocksForThread(m_ThreadIdx), 4);
|
||||
(*f)(cj);
|
||||
else
|
||||
(*fStat)(src, dst, 4 * m_Parent->GetNumBlocksForThread(m_ThreadIdx), 4, *statManager);
|
||||
(*fStat)(cj, *statManager);
|
||||
|
||||
break;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user