Use zstd dict for packing/unpacking frame images.

This only affects run-time memory usage and needs an offline calculation of
the dictionary. Results vary depending on similarity of image blocks.

agora        34.96 MB ->  28.21 MB
agora2       40.75 MB ->  34.14 MB
android-vk   36.21 MB ->  18.44 MB
astar3       44.72 MB ->  43.38 MB
clipper1    134.36 MB ->  52.16 MB
fi           50.82 MB ->  40.79 MB
fi-big      537.74 MB -> 469.54 MB
test         23.26 MB ->   1.87 MB
This commit is contained in:
Bartosz Taudul
2021-05-15 17:02:25 +02:00
parent d555256546
commit c91c7a7fd5
3 changed files with 43 additions and 3 deletions

View File

@@ -11,6 +11,7 @@ TextureCompression::TextureCompression()
, m_bufSize( 0 )
, m_cctx( ZSTD_createCCtx() )
, m_dctx( ZSTD_createDCtx() )
, m_dict( nullptr )
{
}
@@ -19,6 +20,7 @@ TextureCompression::~TextureCompression()
delete[] m_buf;
ZSTD_freeCCtx( m_cctx );
ZSTD_freeDCtx( m_dctx );
ZSTD_freeDDict( m_dict );
}
uint32_t TextureCompression::Pack( struct ZSTD_CCtx_s* ctx, char*& buf, size_t& bufsz, const char* image, uint32_t inBytes )
@@ -67,7 +69,14 @@ const char* TextureCompression::Unpack( const FrameImage& image )
m_buf = new char[outsz];
}
assert( m_dctx );
ZSTD_decompressDCtx( m_dctx, m_buf, outsz, image.ptr, image.csz );
if( m_dict )
{
ZSTD_decompress_usingDDict( m_dctx, m_buf, outsz, image.ptr, image.csz, m_dict );
}
else
{
ZSTD_decompressDCtx( m_dctx, m_buf, outsz, image.ptr, image.csz );
}
return m_buf;
}