Skip to content

Commit ff4b18f

Browse files
author
Eric Eaton
committed
Merge the GetZoneColor functions
This change has CPU and GPU use the same code to calculate zone colors. This changes the UI because the GPU zones will have a different color. The color of GPU zones will be set to match the CPU thread making the GPU calls.
1 parent eaa7f80 commit ff4b18f

File tree

7 files changed

+22
-48
lines changed

7 files changed

+22
-48
lines changed

profiler/src/profiler/TracyView.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,8 @@ class View
332332
uint32_t GetThreadColor( uint64_t thread, int depth );
333333
uint32_t GetSrcLocColor( const SourceLocation& srcloc, int depth );
334334
uint32_t GetRawSrcLocColor( const SourceLocation& srcloc, int depth );
335-
uint32_t GetZoneColor( const ZoneEvent& ev, uint64_t thread, int depth );
336-
uint32_t GetZoneColor( const ZoneEvent& ev );
337-
ZoneColorData GetZoneColorData( const ZoneEvent& ev, uint64_t thread, int depth, uint32_t inheritedColor );
338-
ZoneColorData GetZoneColorData( const ZoneEvent& ev );
335+
uint32_t GetZoneColor( const ZoneEventC ev, uint64_t thread, int depth );
336+
ZoneColorData GetZoneColorData( const ZoneEventC ev, uint64_t thread, int depth, uint32_t inheritedColor );
339337

340338
void ZoomToZone( const ZoneEvent& ev );
341339
void ZoomToZoneGPU( const ZoneEventC ev );

profiler/src/profiler/TracyView_GpuTimeline.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ int View::DrawGpuZoneLevel( const V& vec, bool hover, double pxns, int64_t nspx,
162162
const auto zoneThread = ctx->thread != 0 ? ctx->thread : m_worker.DecompressThread( ev.Thread() );
163163
if( zsz < MinVisSize )
164164
{
165-
const auto color = GetZoneColor( ev );
165+
const auto color = GetZoneColor( { &ev.event, ctx }, zoneThread, depth );
166166
const auto MinVisNs = MinVisSize * nspx;
167167
int num = 0;
168168
const auto px0 = ( start - m_vd.zvStart ) * pxns;
@@ -242,7 +242,7 @@ int View::DrawGpuZoneLevel( const V& vec, bool hover, double pxns, int64_t nspx,
242242
const auto pr1 = ( end - m_vd.zvStart ) * pxns;
243243
const auto px0 = std::max( pr0, -10.0 );
244244
const auto px1 = std::max( { std::min( pr1, double( w + 10 ) ), px0 + pxns * 0.5, px0 + MinVisSize } );
245-
const auto zoneColor = GetZoneColorData( ev );
245+
const auto zoneColor = GetZoneColorData( { &ev.event, ctx }, zoneThread, depth, 0 );
246246
draw->AddRectFilled( wpos + ImVec2( px0, offset ), wpos + ImVec2( px1, offset + tsz.y ), zoneColor.color );
247247
if( zoneColor.highlight )
248248
{

profiler/src/profiler/TracyView_Utility.cpp

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ uint32_t View::GetSrcLocColor( const SourceLocation& srcloc, int depth )
4949
return GetRawSrcLocColor( srcloc, depth );
5050
}
5151

52-
uint32_t View::GetZoneColor( const ZoneEvent& ev, uint64_t thread, int depth )
52+
uint32_t View::GetZoneColor( const ZoneEventC ev, uint64_t thread, int depth )
5353
{
5454
const auto sl = ev.SrcLoc();
5555
const auto& srcloc = m_worker.GetSourceLocation( sl );
5656
if( !m_vd.forceColors )
5757
{
58-
if( m_worker.HasZoneExtra( ev ) )
58+
if( m_worker.HasZoneExtra( *ev.event ) )
5959
{
6060
const auto custom_color = m_worker.GetZoneExtra( ev ).color.Val();
6161
if( custom_color != 0 ) return custom_color | 0xFF000000;
@@ -77,25 +77,18 @@ uint32_t View::GetZoneColor( const ZoneEvent& ev, uint64_t thread, int depth )
7777
}
7878
}
7979

80-
uint32_t View::GetZoneColor( const ZoneEvent& ev )
81-
{
82-
const auto& srcloc = m_worker.GetSourceLocation( ev.SrcLoc() );
83-
const auto color = srcloc.color;
84-
return color != 0 ? ( color | 0xFF000000 ) : 0xFF222288;
85-
}
86-
87-
View::ZoneColorData View::GetZoneColorData( const ZoneEvent& ev, uint64_t thread, int depth, uint32_t inheritedColor )
80+
View::ZoneColorData View::GetZoneColorData( const ZoneEventC ev, uint64_t thread, int depth, uint32_t inheritedColor )
8881
{
8982
ZoneColorData ret;
9083
const auto& srcloc = ev.SrcLoc();
91-
if( m_zoneInfoWindow == &ev )
84+
if( m_zoneInfoWindow == ev.event )
9285
{
9386
ret.color = inheritedColor ? inheritedColor : GetZoneColor( ev, thread, depth );
9487
ret.accentColor = 0xFF44DD44;
9588
ret.thickness = 3.f;
9689
ret.highlight = true;
9790
}
98-
else if( m_zoneHighlight == &ev )
91+
else if( m_zoneHighlight == ev.event )
9992
{
10093
ret.color = inheritedColor ? inheritedColor : GetZoneColor( ev, thread, depth );
10194
ret.accentColor = 0xFF4444FF;
@@ -136,33 +129,6 @@ View::ZoneColorData View::GetZoneColorData( const ZoneEvent& ev, uint64_t thread
136129
return ret;
137130
}
138131

139-
View::ZoneColorData View::GetZoneColorData( const ZoneEvent& ev )
140-
{
141-
ZoneColorData ret;
142-
const auto color = GetZoneColor( ev );
143-
ret.color = color;
144-
if( m_gpuInfoWindow == &ev )
145-
{
146-
ret.accentColor = 0xFF44DD44;
147-
ret.thickness = 3.f;
148-
ret.highlight = true;
149-
}
150-
else if( m_gpuHighlight == &ev )
151-
{
152-
ret.accentColor = 0xFF4444FF;
153-
ret.thickness = 3.f;
154-
ret.highlight = true;
155-
}
156-
else
157-
{
158-
ret.accentColor = HighlightColor( color );
159-
ret.thickness = 1.f;
160-
ret.highlight = false;
161-
}
162-
return ret;
163-
}
164-
165-
166132
const ZoneEvent* View::FindZoneAtTime( uint64_t thread, int64_t time ) const
167133
{
168134
// TODO add thread rev-map

profiler/src/profiler/TracyView_ZoneTimeline.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ void View::DrawZoneList( const TimelineContext& ctx, const std::vector<TimelineD
351351
const auto pr1 = ( end - vStart ) * pxns;
352352
const auto zsz = std::max( pr1 - pr0, pxns * 0.5 );
353353

354-
const auto zoneColor = GetZoneColorData( ev, tid, v.depth, v.inheritedColor );
354+
const auto zoneColor = GetZoneColorData( { &ev, nullptr }, tid, v.depth, v.inheritedColor );
355355
const char* zoneName = m_worker.GetZoneName( ev );
356356

357357
auto tsz = ImGui::CalcTextSize( zoneName );

server/TracyEvent.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,14 @@ struct ZoneEventC
801801
{
802802
tracy_force_inline ZoneEventC(const ZoneEvent* event, const GpuCtxData* ctx): event(event), ctx(ctx) {}
803803

804+
tracy_force_inline int64_t Start() const { return event->Start(); }
805+
tracy_force_inline int64_t End() const { return event->End(); }
806+
tracy_force_inline bool IsEndValid() const { return event->IsEndValid(); }
807+
tracy_force_inline int16_t SrcLoc() const { return event->SrcLoc(); }
808+
tracy_force_inline int32_t Child() const { return event->Child(); }
809+
tracy_force_inline bool HasChildren() const { return event->HasChildren(); }
810+
tracy_force_inline bool IsGpu() const { return ctx != nullptr; }
811+
804812
tracy_force_inline operator bool() const { return event != nullptr; }
805813
tracy_force_inline bool operator==( const ZoneEventC& other ) const { return other.event == event; }
806814
tracy_force_inline bool operator==( const ZoneEvent* other ) const { return other == event; }

server/TracyWorker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2359,7 +2359,7 @@ const uint64_t* Worker::GetInlineSymbolList( uint64_t sym, uint32_t len )
23592359
return it;
23602360
}
23612361

2362-
int64_t Worker::GetZoneEndImpl( const ZoneEvent& ev, const Vector<Vector<short_ptr<ZoneEvent>>>& childArray )
2362+
int64_t Worker::GetZoneEndImpl( const ZoneEvent& ev, const Vector<Vector<short_ptr<ZoneEvent>>>& childArray ) const
23632363
{
23642364
assert( !ev.IsEndValid() );
23652365
auto ptr = &ev;

server/TracyWorker.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,7 @@ class Worker
579579
// before its children have ended).
580580
// GetZoneEndDirect() will only return zone's direct timing data, without looking at children.
581581
tracy_force_inline int64_t GetZoneEnd( const ZoneEvent& ev ) { return ev.IsEndValid() ? ev.End() : GetZoneEndImpl( ev, m_data.zoneChildren ); }
582+
tracy_force_inline int64_t GetZoneEnd( const ZoneEventC ev ) const { return ev.IsEndValid() ? ev.End() : GetZoneEndImpl( *ev.event, ev.IsGpu() ? m_data.gpuChildren : m_data.zoneChildren ); }
582583
tracy_force_inline int64_t GetZoneEndGPU( const ZoneEvent& ev ) { return ev.IsEndValid() ? ev.End() : GetZoneEndImpl( ev, m_data.gpuChildren ); }
583584
static tracy_force_inline int64_t GetZoneEndDirect( const ZoneEvent& ev ) { return ev.IsEndValid() ? ev.End() : ev.Start(); }
584585

@@ -606,6 +607,7 @@ class Worker
606607
tracy_force_inline const bool HasZoneExtra( const ZoneEvent& ev ) const { return ev.extra != 0; }
607608
tracy_force_inline const ZoneExtra& GetZoneExtra( const ZoneEvent& ev ) const { return m_data.zoneExtra[ev.extra]; }
608609
tracy_force_inline const EventAdapter<true> GetGpuExtra( const ZoneEvent& ev ) const { return { ev, m_data.gpuExtra[ev.extra] }; }
610+
tracy_force_inline const ZoneExtra& GetZoneExtra( const ZoneEventC ev ) const { return ev.IsGpu() ? m_data.gpuExtra[ev.event->extra] : m_data.zoneExtra[ev.event->extra]; }
609611

610612
std::vector<int16_t> GetMatchingSourceLocation( const char* query, bool ignoreCase ) const;
611613

@@ -959,7 +961,7 @@ class Worker
959961
tracy_force_inline ZoneExtra& AllocZoneExtra( ZoneEvent& ev );
960962
tracy_force_inline ZoneExtra& RequestZoneExtra( ZoneEvent& ev );
961963

962-
int64_t GetZoneEndImpl( const ZoneEvent& ev, const Vector<Vector<short_ptr<ZoneEvent>>>& childArray );
964+
int64_t GetZoneEndImpl( const ZoneEvent& ev, const Vector<Vector<short_ptr<ZoneEvent>>>& childArray ) const;
963965

964966
void UpdateMbps( int64_t td );
965967

0 commit comments

Comments
 (0)