mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-23 06:44:35 +00:00
Use SPSC queue for frame images.
This commit is contained in:
parent
ff3382391e
commit
02e76faff7
@ -1146,8 +1146,7 @@ Profiler::Profiler()
|
|||||||
, m_serialQueue( 1024*1024 )
|
, m_serialQueue( 1024*1024 )
|
||||||
, m_serialDequeue( 1024*1024 )
|
, m_serialDequeue( 1024*1024 )
|
||||||
#ifndef TRACY_NO_FRAME_IMAGE
|
#ifndef TRACY_NO_FRAME_IMAGE
|
||||||
, m_fiQueue( 16 )
|
, m_fiQueue( 64 )
|
||||||
, m_fiDequeue( 16 )
|
|
||||||
#endif
|
#endif
|
||||||
, m_frameCount( 0 )
|
, m_frameCount( 0 )
|
||||||
, m_isConnected( false )
|
, m_isConnected( false )
|
||||||
@ -1785,60 +1784,30 @@ void Profiler::CompressWorker()
|
|||||||
for(;;)
|
for(;;)
|
||||||
{
|
{
|
||||||
const auto shouldExit = ShouldExit();
|
const auto shouldExit = ShouldExit();
|
||||||
|
FrameImageQueueItem fi;
|
||||||
|
if( m_fiQueue.try_dequeue( fi ) )
|
||||||
{
|
{
|
||||||
bool lockHeld = true;
|
const auto w = fi.w;
|
||||||
while( !m_fiLock.try_lock() )
|
const auto h = fi.h;
|
||||||
{
|
const auto csz = size_t( w * h / 2 );
|
||||||
if( m_shutdownManual.load( std::memory_order_relaxed ) )
|
auto etc1buf = (char*)tracy_malloc( csz );
|
||||||
{
|
CompressImageDxt1( (const char*)fi.image, etc1buf, w, h );
|
||||||
lockHeld = false;
|
tracy_free( fi.image );
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if( !m_fiQueue.empty() ) m_fiQueue.swap( m_fiDequeue );
|
|
||||||
if( lockHeld )
|
|
||||||
{
|
|
||||||
m_fiLock.unlock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto sz = m_fiDequeue.size();
|
TracyLfqPrepare( QueueType::FrameImage );
|
||||||
if( sz > 0 )
|
MemWrite( &item->frameImageFat.image, (uint64_t)etc1buf );
|
||||||
{
|
MemWrite( &item->frameImageFat.frame, fi.frame );
|
||||||
auto fi = m_fiDequeue.data();
|
MemWrite( &item->frameImageFat.w, w );
|
||||||
auto end = fi + sz;
|
MemWrite( &item->frameImageFat.h, h );
|
||||||
while( fi != end )
|
uint8_t flip = fi.flip;
|
||||||
{
|
MemWrite( &item->frameImageFat.flip, flip );
|
||||||
const auto w = fi->w;
|
TracyLfqCommit;
|
||||||
const auto h = fi->h;
|
|
||||||
const auto csz = size_t( w * h / 2 );
|
|
||||||
auto etc1buf = (char*)tracy_malloc( csz );
|
|
||||||
CompressImageDxt1( (const char*)fi->image, etc1buf, w, h );
|
|
||||||
tracy_free( fi->image );
|
|
||||||
|
|
||||||
TracyLfqPrepare( QueueType::FrameImage );
|
|
||||||
MemWrite( &item->frameImageFat.image, (uint64_t)etc1buf );
|
|
||||||
MemWrite( &item->frameImageFat.frame, fi->frame );
|
|
||||||
MemWrite( &item->frameImageFat.w, w );
|
|
||||||
MemWrite( &item->frameImageFat.h, h );
|
|
||||||
uint8_t flip = fi->flip;
|
|
||||||
MemWrite( &item->frameImageFat.flip, flip );
|
|
||||||
TracyLfqCommit;
|
|
||||||
|
|
||||||
fi++;
|
|
||||||
}
|
|
||||||
m_fiDequeue.clear();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if( shouldExit ) return;
|
||||||
std::this_thread::sleep_for( std::chrono::milliseconds( 20 ) );
|
std::this_thread::sleep_for( std::chrono::milliseconds( 20 ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( shouldExit )
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#include "tracy_concurrentqueue.h"
|
#include "tracy_concurrentqueue.h"
|
||||||
|
#include "tracy_readerwriterqueue.h"
|
||||||
#include "TracyCallstack.hpp"
|
#include "TracyCallstack.hpp"
|
||||||
#include "TracySysTime.hpp"
|
#include "TracySysTime.hpp"
|
||||||
#include "TracyFastVector.hpp"
|
#include "TracyFastVector.hpp"
|
||||||
@ -243,15 +244,14 @@ public:
|
|||||||
auto ptr = (char*)tracy_malloc( sz );
|
auto ptr = (char*)tracy_malloc( sz );
|
||||||
memcpy( ptr, image, sz );
|
memcpy( ptr, image, sz );
|
||||||
|
|
||||||
profiler.m_fiLock.lock();
|
profiler.m_fiQueue.emplace( FrameImageQueueItem {
|
||||||
auto fi = profiler.m_fiQueue.prepare_next();
|
ptr,
|
||||||
fi->image = ptr;
|
uint32_t( profiler.m_frameCount.load( std::memory_order_relaxed ) - offset ),
|
||||||
fi->frame = uint32_t( profiler.m_frameCount.load( std::memory_order_relaxed ) - offset );
|
w,
|
||||||
fi->w = w;
|
h,
|
||||||
fi->h = h;
|
0,
|
||||||
fi->flip = flip;
|
flip
|
||||||
profiler.m_fiQueue.commit_next();
|
} );
|
||||||
profiler.m_fiLock.unlock();
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -810,8 +810,7 @@ private:
|
|||||||
TracyMutex m_serialLock;
|
TracyMutex m_serialLock;
|
||||||
|
|
||||||
#ifndef TRACY_NO_FRAME_IMAGE
|
#ifndef TRACY_NO_FRAME_IMAGE
|
||||||
FastVector<FrameImageQueueItem> m_fiQueue, m_fiDequeue;
|
ReaderWriterQueue<FrameImageQueueItem> m_fiQueue;
|
||||||
TracyMutex m_fiLock;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::atomic<uint64_t> m_frameCount;
|
std::atomic<uint64_t> m_frameCount;
|
||||||
|
Loading…
Reference in New Issue
Block a user