Parallelize timeline item preprocessing.

This commit is contained in:
Bartosz Taudul 2023-03-19 18:54:32 +01:00
parent 66d3c2a472
commit 1e1833edc2
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3
5 changed files with 25 additions and 12 deletions

View File

@ -1,4 +1,5 @@
#include <algorithm> #include <algorithm>
#include <thread>
#include "TracyTimelineItem.hpp" #include "TracyTimelineItem.hpp"
#include "TracyTimelineContext.hpp" #include "TracyTimelineContext.hpp"
@ -16,6 +17,11 @@ TimelineController::TimelineController( View& view, Worker& worker )
, m_firstFrame( true ) , m_firstFrame( true )
, m_view( view ) , m_view( view )
, m_worker( worker ) , 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() ) if( item->WantPreprocess() && item->IsVisible() )
{ {
item->Preprocess( ctx ); item->Preprocess( ctx, m_td );
} }
} }
m_td.Sync();
int yOffset = 0; int yOffset = 0;

View File

@ -6,6 +6,7 @@
#include <vector> #include <vector>
#include "TracyImGui.hpp" #include "TracyImGui.hpp"
#include "TracyTaskDispatch.hpp"
#include "../public/common/TracyForceInline.hpp" #include "../public/common/TracyForceInline.hpp"
#include "tracy_robin_hood.h" #include "tracy_robin_hood.h"
@ -61,6 +62,8 @@ private:
View& m_view; View& m_view;
Worker& m_worker; Worker& m_worker;
TaskDispatch m_td;
}; };
} }

View File

@ -10,6 +10,7 @@ namespace tracy
{ {
struct TimelineContext; struct TimelineContext;
class TaskDispatch;
class View; class View;
class Worker; class Worker;
@ -23,7 +24,7 @@ public:
void Draw( bool firstFrame, const TimelineContext& ctx, int yOffset ); void Draw( bool firstFrame, const TimelineContext& ctx, int yOffset );
bool WantPreprocess() const { return m_wantPreprocess; } 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(); void VisibilityCheckbox();
virtual void SetVisible( bool visible ) { m_visible = visible; } virtual void SetVisible( bool visible ) { m_visible = visible; }

View File

@ -277,20 +277,22 @@ void TimelineItemThread::DrawFinished()
m_draw.clear(); m_draw.clear();
} }
void TimelineItemThread::Preprocess( const TimelineContext& ctx ) void TimelineItemThread::Preprocess( const TimelineContext& ctx, TaskDispatch& td )
{ {
assert( m_draw.empty() ); assert( m_draw.empty() );
td.Queue( [this, &ctx] {
#ifndef TRACY_NO_STATISTICS #ifndef TRACY_NO_STATISTICS
if( m_worker.AreGhostZonesReady() && ( m_ghost || ( m_view.GetViewData().ghostZones && m_thread->timeline.empty() ) ) ) if( m_worker.AreGhostZonesReady() && ( m_ghost || ( m_view.GetViewData().ghostZones && m_thread->timeline.empty() ) ) )
{ {
m_depth = PreprocessGhostLevel( ctx, m_thread->ghostZones, 0 ); m_depth = PreprocessGhostLevel( ctx, m_thread->ghostZones, 0 );
} }
else else
#endif #endif
{ {
m_depth = PreprocessZoneLevel( ctx, m_thread->timeline, 0 ); m_depth = PreprocessZoneLevel( ctx, m_thread->timeline, 0 );
} }
} );
} }
#ifndef TRACY_NO_STATISTICS #ifndef TRACY_NO_STATISTICS

View File

@ -31,7 +31,7 @@ protected:
bool IsEmpty() const override; bool IsEmpty() const override;
void Preprocess( const TimelineContext& ctx ) override; void Preprocess( const TimelineContext& ctx, TaskDispatch& td ) override;
private: private:
#ifndef TRACY_NO_STATISTICS #ifndef TRACY_NO_STATISTICS