mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-25 23:44:35 +00:00
Extract texture compression functionality.
This commit is contained in:
parent
0df309b45c
commit
aa0bf47ec3
@ -137,6 +137,7 @@
|
||||
<ClCompile Include="..\..\..\server\TracyMmap.cpp" />
|
||||
<ClCompile Include="..\..\..\server\TracyPrint.cpp" />
|
||||
<ClCompile Include="..\..\..\server\TracyTaskDispatch.cpp" />
|
||||
<ClCompile Include="..\..\..\server\TracyTextureCompression.cpp" />
|
||||
<ClCompile Include="..\..\..\server\TracyThreadCompress.cpp" />
|
||||
<ClCompile Include="..\..\..\server\TracyWorker.cpp" />
|
||||
<ClCompile Include="..\..\..\zstd\debug.c" />
|
||||
@ -190,6 +191,7 @@
|
||||
<ClInclude Include="..\..\..\server\TracyPrint.hpp" />
|
||||
<ClInclude Include="..\..\..\server\TracySlab.hpp" />
|
||||
<ClInclude Include="..\..\..\server\TracyTaskDispatch.hpp" />
|
||||
<ClInclude Include="..\..\..\server\TracyTextureCompression.hpp" />
|
||||
<ClInclude Include="..\..\..\server\TracyThreadCompress.hpp" />
|
||||
<ClInclude Include="..\..\..\server\TracyVector.hpp" />
|
||||
<ClInclude Include="..\..\..\server\TracyWorker.hpp" />
|
||||
|
@ -126,6 +126,9 @@
|
||||
<ClCompile Include="..\..\..\server\TracyMmap.cpp">
|
||||
<Filter>server</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\server\TracyTextureCompression.cpp">
|
||||
<Filter>server</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\..\common\tracy_lz4.hpp">
|
||||
@ -293,5 +296,8 @@
|
||||
<ClInclude Include="..\..\..\server\TracyMmap.hpp">
|
||||
<Filter>server</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\server\TracyTextureCompression.hpp">
|
||||
<Filter>server</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -136,6 +136,7 @@
|
||||
<ClCompile Include="..\..\..\server\TracyMemory.cpp" />
|
||||
<ClCompile Include="..\..\..\server\TracyMmap.cpp" />
|
||||
<ClCompile Include="..\..\..\server\TracyTaskDispatch.cpp" />
|
||||
<ClCompile Include="..\..\..\server\TracyTextureCompression.cpp" />
|
||||
<ClCompile Include="..\..\..\server\TracyThreadCompress.cpp" />
|
||||
<ClCompile Include="..\..\..\server\TracyWorker.cpp" />
|
||||
<ClCompile Include="..\..\..\zstd\debug.c" />
|
||||
@ -187,6 +188,7 @@
|
||||
<ClInclude Include="..\..\..\server\TracyPopcnt.hpp" />
|
||||
<ClInclude Include="..\..\..\server\TracySlab.hpp" />
|
||||
<ClInclude Include="..\..\..\server\TracyTaskDispatch.hpp" />
|
||||
<ClInclude Include="..\..\..\server\TracyTextureCompression.hpp" />
|
||||
<ClInclude Include="..\..\..\server\TracyThreadCompress.hpp" />
|
||||
<ClInclude Include="..\..\..\server\TracyVector.hpp" />
|
||||
<ClInclude Include="..\..\..\server\TracyWorker.hpp" />
|
||||
|
@ -120,6 +120,9 @@
|
||||
<ClCompile Include="..\..\..\server\TracyMmap.cpp">
|
||||
<Filter>server</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\server\TracyTextureCompression.cpp">
|
||||
<Filter>server</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\..\common\tracy_lz4.hpp">
|
||||
@ -281,5 +284,8 @@
|
||||
<ClInclude Include="..\..\..\server\TracyMmap.hpp">
|
||||
<Filter>server</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\server\TracyTextureCompression.hpp">
|
||||
<Filter>server</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -119,6 +119,7 @@
|
||||
<ClCompile Include="..\..\..\server\TracyStorage.cpp" />
|
||||
<ClCompile Include="..\..\..\server\TracyTaskDispatch.cpp" />
|
||||
<ClCompile Include="..\..\..\server\TracyTexture.cpp" />
|
||||
<ClCompile Include="..\..\..\server\TracyTextureCompression.cpp" />
|
||||
<ClCompile Include="..\..\..\server\TracyThreadCompress.cpp" />
|
||||
<ClCompile Include="..\..\..\server\TracyUserData.cpp" />
|
||||
<ClCompile Include="..\..\..\server\TracyView.cpp" />
|
||||
@ -204,6 +205,7 @@
|
||||
<ClInclude Include="..\..\..\server\TracyStringDiscovery.hpp" />
|
||||
<ClInclude Include="..\..\..\server\TracyTaskDispatch.hpp" />
|
||||
<ClInclude Include="..\..\..\server\TracyTexture.hpp" />
|
||||
<ClInclude Include="..\..\..\server\TracyTextureCompression.hpp" />
|
||||
<ClInclude Include="..\..\..\server\TracyThreadCompress.hpp" />
|
||||
<ClInclude Include="..\..\..\server\TracyUserData.hpp" />
|
||||
<ClInclude Include="..\..\..\server\TracyVarArray.hpp" />
|
||||
|
@ -192,6 +192,9 @@
|
||||
<ClCompile Include="..\..\..\server\TracyMmap.cpp">
|
||||
<Filter>server</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\server\TracyTextureCompression.cpp">
|
||||
<Filter>server</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\..\common\tracy_lz4.hpp">
|
||||
@ -479,6 +482,9 @@
|
||||
<ClInclude Include="..\..\..\server\TracyMmap.hpp">
|
||||
<Filter>server</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\server\TracyTextureCompression.hpp">
|
||||
<Filter>server</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Natvis Include="DebugVis.natvis" />
|
||||
|
65
server/TracyTextureCompression.cpp
Normal file
65
server/TracyTextureCompression.cpp
Normal file
@ -0,0 +1,65 @@
|
||||
#include "../zstd/zstd.h"
|
||||
|
||||
#include "TracyEvent.hpp"
|
||||
#include "TracyTextureCompression.hpp"
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
TextureCompression::TextureCompression()
|
||||
: m_buf( nullptr )
|
||||
, m_bufSize( 0 )
|
||||
, m_cctx( ZSTD_createCCtx() )
|
||||
, m_dctx( ZSTD_createDCtx() )
|
||||
{
|
||||
}
|
||||
|
||||
TextureCompression::~TextureCompression()
|
||||
{
|
||||
delete[] m_buf;
|
||||
ZSTD_freeCCtx( m_cctx );
|
||||
ZSTD_freeDCtx( m_dctx );
|
||||
}
|
||||
|
||||
void TextureCompression::Pack( struct ZSTD_CCtx_s* ctx, char*& buf, size_t& bufsz, const char* image, uint32_t inBytes, uint32_t& csz ) const
|
||||
{
|
||||
const auto maxout = ZSTD_COMPRESSBOUND( inBytes );
|
||||
if( bufsz < maxout )
|
||||
{
|
||||
bufsz = maxout;
|
||||
delete[] buf;
|
||||
buf = new char[maxout];
|
||||
}
|
||||
assert( ctx );
|
||||
const auto outsz = ZSTD_compressCCtx( ctx, buf, maxout, image, inBytes, 3 );
|
||||
csz = uint32_t( outsz );
|
||||
}
|
||||
|
||||
uint32_t TextureCompression::PackImpl( const char* image, uint32_t inBytes )
|
||||
{
|
||||
const auto maxout = ZSTD_COMPRESSBOUND( inBytes );
|
||||
if( m_bufSize < maxout )
|
||||
{
|
||||
m_bufSize = maxout;
|
||||
delete[] m_buf;
|
||||
m_buf = new char[maxout];
|
||||
}
|
||||
assert( m_cctx );
|
||||
return (uint32_t)ZSTD_compressCCtx( m_cctx, m_buf, maxout, image, inBytes, 1 );
|
||||
}
|
||||
|
||||
const char* TextureCompression::Unpack( const FrameImage& image )
|
||||
{
|
||||
const auto outsz = size_t( image.w ) * size_t( image.h ) / 2;
|
||||
if( m_bufSize < outsz )
|
||||
{
|
||||
m_bufSize = outsz;
|
||||
delete[] m_buf;
|
||||
m_buf = new char[outsz];
|
||||
}
|
||||
assert( m_dctx );
|
||||
ZSTD_decompressDCtx( m_dctx, m_buf, outsz, image.ptr, image.csz );
|
||||
return m_buf;
|
||||
}
|
||||
|
||||
}
|
48
server/TracyTextureCompression.hpp
Normal file
48
server/TracyTextureCompression.hpp
Normal file
@ -0,0 +1,48 @@
|
||||
#ifndef __TRACY__TEXTURECOMPRESSION_HPP__
|
||||
#define __TRACY__TEXTURECOMPRESSION_HPP__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "TracySlab.hpp"
|
||||
|
||||
struct ZSTD_CCtx_s;
|
||||
struct ZSTD_DCtx_s;
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
struct FrameImage;
|
||||
|
||||
class TextureCompression
|
||||
{
|
||||
public:
|
||||
TextureCompression();
|
||||
~TextureCompression();
|
||||
|
||||
void Pack( struct ZSTD_CCtx_s* ctx, char*& buf, size_t& bufsz, const char* image, uint32_t inBytes, uint32_t& csz ) const;
|
||||
|
||||
template<size_t Size>
|
||||
const char* Pack( const char* image, uint32_t inBytes, uint32_t& csz, Slab<Size>& slab )
|
||||
{
|
||||
const auto outsz = PackImpl( image, inBytes );
|
||||
auto ptr = (char*)slab.AllocBig( outsz );
|
||||
memcpy( ptr, m_buf, outsz );
|
||||
csz = outsz;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
const char* Unpack( const FrameImage& image );
|
||||
|
||||
private:
|
||||
uint32_t PackImpl( const char* image, uint32_t inBytes );
|
||||
|
||||
char* m_buf;
|
||||
size_t m_bufSize;
|
||||
struct ZSTD_CCtx_s* m_cctx;
|
||||
struct ZSTD_DCtx_s* m_dctx;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -13,8 +13,6 @@
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "../zstd/zstd.h"
|
||||
|
||||
#include "../common/TracyProtocol.hpp"
|
||||
#include "../common/TracySystem.hpp"
|
||||
#include "TracyFileRead.hpp"
|
||||
@ -233,8 +231,6 @@ Worker::Worker( const char* addr, int port )
|
||||
, m_callstackFrameStaging( nullptr )
|
||||
, m_traceVersion( CurrentVersion )
|
||||
, m_loadTime( 0 )
|
||||
, m_fiCctx( ZSTD_createCCtx() )
|
||||
, m_fiDctx( ZSTD_createDCtx() )
|
||||
{
|
||||
m_data.sourceLocationExpand.push_back( 0 );
|
||||
m_data.localThreadCompress.InitZero();
|
||||
@ -381,7 +377,6 @@ Worker::Worker( FileRead& f, EventType::Type eventMask, bool bgTasks )
|
||||
: m_hasData( true )
|
||||
, m_stream( nullptr )
|
||||
, m_buffer( nullptr )
|
||||
, m_fiDctx( ZSTD_createDCtx() )
|
||||
{
|
||||
auto loadStart = std::chrono::high_resolution_clock::now();
|
||||
|
||||
@ -1478,7 +1473,7 @@ Worker::Worker( FileRead& f, EventType::Type eventMask, bool bgTasks )
|
||||
|
||||
data[idx].state.store( JobData::InProgress, std::memory_order_release );
|
||||
td->Queue( [this, &data, idx, fi] {
|
||||
PackFrameImage( data[idx].ctx, data[idx].outbuf, data[idx].outsz, data[idx].buf, fi->w * fi->h / 2, fi->csz );
|
||||
m_texcomp.Pack( data[idx].ctx, data[idx].outbuf, data[idx].outsz, data[idx].buf, fi->w * fi->h / 2, fi->csz );
|
||||
data[idx].state.store( JobData::DataReady, std::memory_order_release );
|
||||
} );
|
||||
|
||||
@ -1769,7 +1764,6 @@ Worker::~Worker()
|
||||
LZ4_freeStreamDecode( (LZ4_streamDecode_t*)m_stream );
|
||||
|
||||
delete[] m_frameImageBuffer;
|
||||
delete[] m_frameImageCompressedBuffer;
|
||||
|
||||
for( auto& v : m_data.threads )
|
||||
{
|
||||
@ -1801,9 +1795,6 @@ Worker::~Worker()
|
||||
{
|
||||
v.second->~LockMap();
|
||||
}
|
||||
|
||||
if( m_fiCctx ) ZSTD_freeCCtx( m_fiCctx );
|
||||
if( m_fiDctx ) ZSTD_freeDCtx( m_fiDctx );
|
||||
}
|
||||
|
||||
uint64_t Worker::GetLockCount() const
|
||||
@ -3150,7 +3141,7 @@ void Worker::AddFrameImageData( uint64_t ptr, const char* data, size_t sz )
|
||||
dst += 8;
|
||||
}
|
||||
uint32_t csz;
|
||||
auto image = PackFrameImage( m_frameImageBuffer, sz, csz );
|
||||
auto image = m_texcomp.Pack( m_frameImageBuffer, sz, csz, m_slab );
|
||||
m_pendingFrameImageData.emplace( ptr, FrameImagePending { image, csz } );
|
||||
}
|
||||
|
||||
@ -6203,7 +6194,7 @@ void Worker::Write( FileWrite& f )
|
||||
f.Write( &fi->w, sizeof( fi->w ) );
|
||||
f.Write( &fi->h, sizeof( fi->h ) );
|
||||
f.Write( &fi->flip, sizeof( fi->flip ) );
|
||||
const auto image = UnpackFrameImage( *fi );
|
||||
const auto image = m_texcomp.Unpack( *fi );
|
||||
f.Write( image, fi->w * fi->h / 2 );
|
||||
}
|
||||
|
||||
@ -6381,51 +6372,6 @@ const char* Worker::GetFailureString( Worker::Failure failure )
|
||||
return s_failureReasons[(int)failure];
|
||||
}
|
||||
|
||||
void Worker::PackFrameImage( struct ZSTD_CCtx_s* ctx, char*& buf, size_t& bufsz, const char* image, uint32_t inBytes, uint32_t& csz ) const
|
||||
{
|
||||
const auto maxout = ZSTD_COMPRESSBOUND( inBytes );
|
||||
if( bufsz < maxout )
|
||||
{
|
||||
bufsz = maxout;
|
||||
delete[] buf;
|
||||
buf = new char[maxout];
|
||||
}
|
||||
assert( ctx );
|
||||
const auto outsz = ZSTD_compressCCtx( ctx, buf, maxout, image, inBytes, 3 );
|
||||
csz = uint32_t( outsz );
|
||||
}
|
||||
|
||||
const char* Worker::PackFrameImage( const char* image, uint32_t inBytes, uint32_t& csz )
|
||||
{
|
||||
const auto maxout = ZSTD_COMPRESSBOUND( inBytes );
|
||||
if( m_frameImageCompressedBufferSize < maxout )
|
||||
{
|
||||
m_frameImageCompressedBufferSize = maxout;
|
||||
delete[] m_frameImageCompressedBuffer;
|
||||
m_frameImageCompressedBuffer = new char[maxout];
|
||||
}
|
||||
assert( m_fiCctx );
|
||||
const auto outsz = ZSTD_compressCCtx( m_fiCctx, m_frameImageCompressedBuffer, maxout, image, inBytes, 1 );
|
||||
csz = uint32_t( outsz );
|
||||
auto ptr = (char*)m_slab.AllocBig( outsz );
|
||||
memcpy( ptr, m_frameImageCompressedBuffer, outsz );
|
||||
return ptr;
|
||||
}
|
||||
|
||||
const char* Worker::UnpackFrameImage( const FrameImage& image )
|
||||
{
|
||||
const auto outsz = size_t( image.w ) * size_t( image.h ) / 2;
|
||||
if( m_frameImageCompressedBufferSize < outsz )
|
||||
{
|
||||
m_frameImageCompressedBufferSize = outsz;
|
||||
delete[] m_frameImageCompressedBuffer;
|
||||
m_frameImageCompressedBuffer = new char[outsz];
|
||||
}
|
||||
assert( m_fiDctx );
|
||||
ZSTD_decompressDCtx( m_fiDctx, m_frameImageCompressedBuffer, outsz, image.ptr, image.csz );
|
||||
return m_frameImageCompressedBuffer;
|
||||
}
|
||||
|
||||
void Worker::SetParameter( size_t paramIdx, int32_t val )
|
||||
{
|
||||
assert( paramIdx < m_params.size() );
|
||||
|
@ -21,13 +21,11 @@
|
||||
#include "TracyShortPtr.hpp"
|
||||
#include "TracySlab.hpp"
|
||||
#include "TracyStringDiscovery.hpp"
|
||||
#include "TracyTextureCompression.hpp"
|
||||
#include "TracyThreadCompress.hpp"
|
||||
#include "TracyVarArray.hpp"
|
||||
|
||||
|
||||
struct ZSTD_CCtx_s;
|
||||
struct ZSTD_DCtx_s;
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
@ -486,9 +484,7 @@ public:
|
||||
const FailureData& GetFailureData() const { return m_failureData; }
|
||||
static const char* GetFailureString( Failure failure );
|
||||
|
||||
void PackFrameImage( struct ZSTD_CCtx_s* ctx, char*& buf, size_t& bufsz, const char* image, uint32_t inBytes, uint32_t& csz ) const;
|
||||
const char* PackFrameImage( const char* image, uint32_t inBytes, uint32_t& csz );
|
||||
const char* UnpackFrameImage( const FrameImage& image );
|
||||
const char* UnpackFrameImage( const FrameImage& image ) { return m_texcomp.Unpack( image ); }
|
||||
|
||||
const Vector<Parameter>& GetParameters() const { return m_params; }
|
||||
void SetParameter( size_t paramIdx, int32_t val );
|
||||
@ -772,10 +768,7 @@ private:
|
||||
unordered_flat_map<uint64_t, int32_t> m_frameImageStaging;
|
||||
char* m_frameImageBuffer = nullptr;
|
||||
size_t m_frameImageBufferSize = 0;
|
||||
char* m_frameImageCompressedBuffer = nullptr;
|
||||
size_t m_frameImageCompressedBufferSize = 0;
|
||||
struct ZSTD_CCtx_s* m_fiCctx = nullptr;
|
||||
struct ZSTD_DCtx_s* m_fiDctx = nullptr;
|
||||
TextureCompression m_texcomp;
|
||||
|
||||
uint64_t m_threadCtx = 0;
|
||||
ThreadData* m_threadCtxData = nullptr;
|
||||
|
@ -137,6 +137,7 @@
|
||||
<ClCompile Include="..\..\..\server\TracyMmap.cpp" />
|
||||
<ClCompile Include="..\..\..\server\TracyPrint.cpp" />
|
||||
<ClCompile Include="..\..\..\server\TracyTaskDispatch.cpp" />
|
||||
<ClCompile Include="..\..\..\server\TracyTextureCompression.cpp" />
|
||||
<ClCompile Include="..\..\..\server\TracyThreadCompress.cpp" />
|
||||
<ClCompile Include="..\..\..\server\TracyWorker.cpp" />
|
||||
<ClCompile Include="..\..\..\zstd\debug.c" />
|
||||
@ -189,6 +190,7 @@
|
||||
<ClInclude Include="..\..\..\server\TracyPrint.hpp" />
|
||||
<ClInclude Include="..\..\..\server\TracySlab.hpp" />
|
||||
<ClInclude Include="..\..\..\server\TracyTaskDispatch.hpp" />
|
||||
<ClInclude Include="..\..\..\server\TracyTextureCompression.hpp" />
|
||||
<ClInclude Include="..\..\..\server\TracyThreadCompress.hpp" />
|
||||
<ClInclude Include="..\..\..\server\TracyVector.hpp" />
|
||||
<ClInclude Include="..\..\..\server\TracyWorker.hpp" />
|
||||
|
@ -123,6 +123,9 @@
|
||||
<ClCompile Include="..\..\..\server\TracyMmap.cpp">
|
||||
<Filter>server</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\server\TracyTextureCompression.cpp">
|
||||
<Filter>server</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\..\common\tracy_lz4.hpp">
|
||||
@ -287,5 +290,8 @@
|
||||
<ClInclude Include="..\..\..\server\TracyMmap.hpp">
|
||||
<Filter>server</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\server\TracyTextureCompression.hpp">
|
||||
<Filter>server</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
Loading…
Reference in New Issue
Block a user