From f565e11976a57f6d2e8f70d7007f6c12de98ca7c Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Wed, 26 Jun 2019 22:50:56 +0200 Subject: [PATCH] Store frame images in queue. --- client/TracyProfiler.cpp | 2 ++ client/TracyProfiler.hpp | 40 +++++++++++++++++++++++++++------------- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/client/TracyProfiler.cpp b/client/TracyProfiler.cpp index 733f5352..03426799 100644 --- a/client/TracyProfiler.cpp +++ b/client/TracyProfiler.cpp @@ -953,6 +953,8 @@ Profiler::Profiler() , m_lz4Buf( (char*)tracy_malloc( LZ4Size + sizeof( lz4sz_t ) ) ) , m_serialQueue( 1024*1024 ) , m_serialDequeue( 1024*1024 ) + , m_fiQueue( 16 ) + , m_fiDequeue( 16 ) , m_etc1Buf( nullptr ) , m_etc1BufSize( 0 ) #ifdef TRACY_ON_DEMAND diff --git a/client/TracyProfiler.hpp b/client/TracyProfiler.hpp index cb4ed20c..8c3a2203 100644 --- a/client/TracyProfiler.hpp +++ b/client/TracyProfiler.hpp @@ -89,6 +89,16 @@ extern int64_t (*GetTimeImpl)(); class Profiler { + struct FrameImageQueueItem + { + void* image; + int64_t time; + uint16_t w; + uint16_t h; + uint8_t offset; + bool flip; + }; + public: Profiler(); ~Profiler(); @@ -175,24 +185,25 @@ public: static tracy_force_inline void SendFrameImage( void* image, uint16_t w, uint16_t h, uint8_t offset, bool flip ) { + auto& profiler = GetProfiler(); #ifdef TRACY_ON_DEMAND - if( !GetProfiler().IsConnected() ) return; + if( !profiler.IsConnected() ) return; #endif + const auto time = GetTime(); const auto sz = size_t( w ) * size_t( h ) * 4; - Magic magic; - auto token = GetToken(); auto ptr = (char*)tracy_malloc( sz ); memcpy( ptr, image, sz ); - auto& tail = token->get_tail_index(); - auto item = token->enqueue_begin( magic ); - MemWrite( &item->hdr.type, QueueType::FrameImage ); - MemWrite( &item->frameImage.image, (uint64_t)ptr ); - MemWrite( &item->frameImage.w, w ); - MemWrite( &item->frameImage.h, h ); - MemWrite( &item->frameImage.offset, offset ); - uint8_t _flip = flip; - MemWrite( &item->frameImage.flip, _flip ); - tail.store( magic + 1, std::memory_order_release ); + + profiler.m_fiLock.lock(); + auto fi = profiler.m_fiQueue.prepare_next(); + fi->image = ptr; + fi->time = time; + fi->w = w; + fi->h = h; + fi->offset = offset; + fi->flip = flip; + profiler.m_fiQueue.commit_next(); + profiler.m_fiLock.unlock(); } static tracy_force_inline void PlotData( const char* name, int64_t val ) @@ -537,6 +548,9 @@ private: FastVector m_serialQueue, m_serialDequeue; TracyMutex m_serialLock; + FastVector m_fiQueue, m_fiDequeue; + TracyMutex m_fiLock; + char* m_etc1Buf; size_t m_etc1BufSize;