diff --git a/server/TracyTextureCompression.cpp b/server/TracyTextureCompression.cpp index af26c8ab..34862473 100644 --- a/server/TracyTextureCompression.cpp +++ b/server/TracyTextureCompression.cpp @@ -39,6 +39,24 @@ uint32_t TextureCompression::Pack( struct ZSTD_CCtx_s* ctx, char*& buf, size_t& 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 auto outsz = size_t( image.w ) * size_t( image.h ) / 2; diff --git a/server/TracyTextureCompression.hpp b/server/TracyTextureCompression.hpp index bbd51821..ae88337f 100644 --- a/server/TracyTextureCompression.hpp +++ b/server/TracyTextureCompression.hpp @@ -10,6 +10,7 @@ struct ZSTD_CCtx_s; struct ZSTD_DCtx_s; +struct ZSTD_CDict_s; namespace tracy { @@ -23,6 +24,7 @@ public: ~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, const struct ZSTD_CDict_s* dict, char*& buf, size_t& bufsz, const char* image, uint32_t inBytes ); template const char* Pack( const char* image, uint32_t inBytes, uint32_t& csz, Slab& slab )