Add texture packer with zstd dict support.

This commit is contained in:
Bartosz Taudul 2021-05-15 17:27:00 +02:00
parent a53f5702b1
commit 925a23a053
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3
2 changed files with 20 additions and 0 deletions

View File

@ -39,6 +39,24 @@ uint32_t TextureCompression::Pack( struct ZSTD_CCtx_s* ctx, char*& buf, size_t&
return ret; return ret;
} }
uint32_t TextureCompression::Pack( struct ZSTD_CCtx_s* ctx, const struct ZSTD_CDict_s* dict, char*& buf, size_t& bufsz, const char* image, uint32_t inBytes )
{
const auto maxout = ZSTD_COMPRESSBOUND( inBytes );
if( bufsz < maxout )
{
bufsz = maxout;
delete[] buf;
buf = new char[maxout];
}
assert( ctx );
auto ret = (uint32_t)ZSTD_compress_usingCDict( ctx, buf, maxout, image, inBytes, dict );
#ifndef TRACY_NO_STATISTICS
m_inputBytes.fetch_add( inBytes, std::memory_order_relaxed );
m_outputBytes.fetch_add( ret, std::memory_order_relaxed );
#endif
return ret;
}
const char* TextureCompression::Unpack( const FrameImage& image ) const char* TextureCompression::Unpack( const FrameImage& image )
{ {
const auto outsz = size_t( image.w ) * size_t( image.h ) / 2; const auto outsz = size_t( image.w ) * size_t( image.h ) / 2;

View File

@ -10,6 +10,7 @@
struct ZSTD_CCtx_s; struct ZSTD_CCtx_s;
struct ZSTD_DCtx_s; struct ZSTD_DCtx_s;
struct ZSTD_CDict_s;
namespace tracy namespace tracy
{ {
@ -23,6 +24,7 @@ public:
~TextureCompression(); ~TextureCompression();
uint32_t Pack( struct ZSTD_CCtx_s* ctx, char*& buf, size_t& bufsz, const char* image, uint32_t inBytes ); uint32_t Pack( struct ZSTD_CCtx_s* ctx, char*& buf, size_t& bufsz, const char* image, uint32_t inBytes );
uint32_t Pack( struct ZSTD_CCtx_s* ctx, const struct ZSTD_CDict_s* dict, char*& buf, size_t& bufsz, const char* image, uint32_t inBytes );
template<size_t Size> template<size_t Size>
const char* Pack( const char* image, uint32_t inBytes, uint32_t& csz, Slab<Size>& slab ) const char* Pack( const char* image, uint32_t inBytes, uint32_t& csz, Slab<Size>& slab )