tracy/server/TracyTextureCompression.hpp
Bartosz Taudul c91c7a7fd5
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
2021-05-15 18:06:44 +02:00

64 lines
1.6 KiB
C++

#ifndef __TRACY__TEXTURECOMPRESSION_HPP__
#define __TRACY__TEXTURECOMPRESSION_HPP__
#include <atomic>
#include <stdint.h>
#include <stdlib.h>
#include "TracySlab.hpp"
struct ZSTD_CCtx_s;
struct ZSTD_DCtx_s;
struct ZSTD_CDict_s;
struct ZSTD_DDict_s;
namespace tracy
{
struct FrameImage;
class TextureCompression
{
public:
TextureCompression();
~TextureCompression();
void SetDict( struct ZSTD_DDict_s* dict ) { m_dict = dict; }
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>
const char* Pack( const char* image, uint32_t inBytes, uint32_t& csz, Slab<Size>& slab )
{
const auto outsz = Pack( m_cctx, m_buf, m_bufSize, image, inBytes );
auto ptr = (char*)slab.AllocBig( outsz );
memcpy( ptr, m_buf, outsz );
csz = outsz;
return ptr;
}
const char* Unpack( const FrameImage& image );
void Rdo( char* data, size_t blocks );
void FixOrder( char* data, size_t blocks );
uint64_t GetInputBytesCount() const { return m_inputBytes.load( std::memory_order_relaxed ); }
uint64_t GetOutputBytesCount() const { return m_outputBytes.load( std::memory_order_relaxed ); }
private:
char* m_buf;
size_t m_bufSize;
struct ZSTD_CCtx_s* m_cctx;
struct ZSTD_DCtx_s* m_dctx;
struct ZSTD_DDict_s* m_dict;
std::atomic<uint64_t> m_inputBytes { 0 };
std::atomic<uint64_t> m_outputBytes { 0 };
};
}
#endif