Calculate frame images dictionary.

This commit is contained in:
Bartosz Taudul 2021-05-15 16:47:47 +02:00
parent 56958a018c
commit a53f5702b1
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3
2 changed files with 56 additions and 1 deletions

View File

@ -7,7 +7,7 @@ namespace Version
{
enum { Major = 0 };
enum { Minor = 7 };
enum { Patch = 7 };
enum { Patch = 8 };
}
}

View File

@ -21,6 +21,9 @@
#include <capstone.h>
#define ZDICT_STATIC_LINKING_ONLY
#include "../zstd/zdict.h"
#include "../common/TracyProtocol.hpp"
#include "../common/TracySystem.hpp"
#include "TracyFileRead.hpp"
@ -7268,6 +7271,58 @@ void Worker::Write( FileWrite& f, bool fiDict )
{
TextureCompression texcomp;
sz = m_data.frameImage.size();
if( fiDict )
{
enum : uint32_t { DictSize = 4*1024*1024 };
enum : uint32_t { SamplesLimit = 1 << 31 };
uint32_t sNum = 0;
uint32_t sSize = 0;
for( auto& fi : m_data.frameImage )
{
const auto fisz = fi->w * fi->h / 2;
if( sSize + fisz > SamplesLimit ) break;
sSize += fisz;
sNum++;
}
uint32_t offset = 0;
auto sdata = new char[sSize];
auto ssize = new size_t[sSize];
for( uint32_t i=0; i<sNum; i++ )
{
const auto& fi = m_data.frameImage[i];
const auto fisz = fi->w * fi->h / 2;
const auto image = texcomp.Unpack( *fi );
memcpy( sdata+offset, image, fisz );
ssize[i] = fisz;
offset += fisz;
}
assert( offset == sSize );
ZDICT_fastCover_params_t params = {};
params.d = 6;
params.k = 50;
params.f = 30;
params.nbThreads = std::thread::hardware_concurrency();
params.zParams.compressionLevel = 3;
auto dict = new char[DictSize];
const auto finalDictSize = (uint32_t)ZDICT_optimizeTrainFromBuffer_fastCover( dict, DictSize, sdata, ssize, sNum, &params );
auto zdict = ZSTD_createCDict( dict, finalDictSize, 3 );
f.Write( &finalDictSize, sizeof( finalDictSize ) );
f.Write( dict, finalDictSize );
ZSTD_freeCDict( zdict );
delete[] dict;
delete[] ssize;
delete[] sdata;
}
else
{
uint32_t zero = 0;
f.Write( &zero, sizeof( zero ) );
}
f.Write( &sz, sizeof( sz ) );
for( auto& fi : m_data.frameImage )
{