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