diff --git a/server/TracyTimelineController.cpp b/server/TracyTimelineController.cpp index 569f1b50..50ac01ea 100644 --- a/server/TracyTimelineController.cpp +++ b/server/TracyTimelineController.cpp @@ -1,4 +1,5 @@ #include +#include #include "TracyTimelineItem.hpp" #include "TracyTimelineContext.hpp" @@ -16,6 +17,11 @@ TimelineController::TimelineController( View& view, Worker& worker ) , m_firstFrame( true ) , m_view( view ) , m_worker( worker ) +#ifdef __EMSCRIPTEN__ + , m_td( 1 ) +#else + , m_td( std::max( 1u, std::thread::hardware_concurrency() - 2 ) ) +#endif { } @@ -131,9 +137,10 @@ void TimelineController::End( double pxns, const ImVec2& wpos, bool hover, bool { if( item->WantPreprocess() && item->IsVisible() ) { - item->Preprocess( ctx ); + item->Preprocess( ctx, m_td ); } } + m_td.Sync(); int yOffset = 0; diff --git a/server/TracyTimelineController.hpp b/server/TracyTimelineController.hpp index 8d9ac007..d63abc60 100644 --- a/server/TracyTimelineController.hpp +++ b/server/TracyTimelineController.hpp @@ -6,6 +6,7 @@ #include #include "TracyImGui.hpp" +#include "TracyTaskDispatch.hpp" #include "../public/common/TracyForceInline.hpp" #include "tracy_robin_hood.h" @@ -61,6 +62,8 @@ private: View& m_view; Worker& m_worker; + + TaskDispatch m_td; }; } diff --git a/server/TracyTimelineItem.hpp b/server/TracyTimelineItem.hpp index d7182eea..155bbcf1 100644 --- a/server/TracyTimelineItem.hpp +++ b/server/TracyTimelineItem.hpp @@ -10,6 +10,7 @@ namespace tracy { struct TimelineContext; +class TaskDispatch; class View; class Worker; @@ -23,7 +24,7 @@ public: void Draw( bool firstFrame, const TimelineContext& ctx, int yOffset ); bool WantPreprocess() const { return m_wantPreprocess; } - virtual void Preprocess( const TimelineContext& ctx ) { assert( false ); } + virtual void Preprocess( const TimelineContext& ctx, TaskDispatch& td ) { assert( false ); } void VisibilityCheckbox(); virtual void SetVisible( bool visible ) { m_visible = visible; } diff --git a/server/TracyTimelineItemThread.cpp b/server/TracyTimelineItemThread.cpp index 17508cdc..9c2b9390 100644 --- a/server/TracyTimelineItemThread.cpp +++ b/server/TracyTimelineItemThread.cpp @@ -277,20 +277,22 @@ void TimelineItemThread::DrawFinished() m_draw.clear(); } -void TimelineItemThread::Preprocess( const TimelineContext& ctx ) +void TimelineItemThread::Preprocess( const TimelineContext& ctx, TaskDispatch& td ) { assert( m_draw.empty() ); + td.Queue( [this, &ctx] { #ifndef TRACY_NO_STATISTICS - if( m_worker.AreGhostZonesReady() && ( m_ghost || ( m_view.GetViewData().ghostZones && m_thread->timeline.empty() ) ) ) - { - m_depth = PreprocessGhostLevel( ctx, m_thread->ghostZones, 0 ); - } - else + if( m_worker.AreGhostZonesReady() && ( m_ghost || ( m_view.GetViewData().ghostZones && m_thread->timeline.empty() ) ) ) + { + m_depth = PreprocessGhostLevel( ctx, m_thread->ghostZones, 0 ); + } + else #endif - { - m_depth = PreprocessZoneLevel( ctx, m_thread->timeline, 0 ); - } + { + m_depth = PreprocessZoneLevel( ctx, m_thread->timeline, 0 ); + } + } ); } #ifndef TRACY_NO_STATISTICS diff --git a/server/TracyTimelineItemThread.hpp b/server/TracyTimelineItemThread.hpp index 50e07db3..1d38e632 100644 --- a/server/TracyTimelineItemThread.hpp +++ b/server/TracyTimelineItemThread.hpp @@ -31,7 +31,7 @@ protected: bool IsEmpty() const override; - void Preprocess( const TimelineContext& ctx ) override; + void Preprocess( const TimelineContext& ctx, TaskDispatch& td ) override; private: #ifndef TRACY_NO_STATISTICS