Welcome to mirror list, hosted at ThFree Co, Russian Federation.

TracyTimelineItemGpu.cpp « server - github.com/wolfpld/tracy.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 11506e9b3f29dbf69ac6f60884242b844e00f58b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#include "TracyImGui.hpp"
#include "TracyPopcnt.hpp"
#include "TracyPrint.hpp"
#include "TracyTimelineItemGpu.hpp"
#include "TracyUtility.hpp"
#include "TracyView.hpp"
#include "TracyWorker.hpp"

namespace tracy
{

TimelineItemGpu::TimelineItemGpu( View& view, Worker& worker, GpuCtxData* gpu )
    : TimelineItem( view, worker )
    , m_gpu( gpu )
    , m_idx( view.GetNextGpuIdx() )
{
}

bool TimelineItemGpu::IsEmpty() const
{
    return m_gpu->threadData.empty();
}

const char* TimelineItemGpu::HeaderLabel() const
{
    static char buf[4096];
    if( m_gpu->name.Active() )
    {
        sprintf( buf, "%s", m_worker.GetString( m_gpu->name ) );
    }
    else
    {
        sprintf( buf, "%s context %i", GpuContextNames[(int)m_gpu->type], m_idx );
    }
    return buf;
}

void TimelineItemGpu::HeaderTooltip( const char* label ) const
{
    const bool dynamicColors = m_view.GetViewData().dynamicColors;
    const bool isMultithreaded =
        ( m_gpu->type == GpuContextType::Vulkan ) ||
        ( m_gpu->type == GpuContextType::OpenCL ) ||
        ( m_gpu->type == GpuContextType::Direct3D12 );

    char buf[64];
    sprintf( buf, "%s context %i", GpuContextNames[(int)m_gpu->type], m_idx );

    ImGui::BeginTooltip();
    if( m_gpu->name.Active() ) TextFocused( "Name:", m_worker.GetString( m_gpu->name ) );
    ImGui::TextUnformatted( buf );
    ImGui::Separator();
    if( !isMultithreaded )
    {
        SmallColorBox( GetThreadColor( m_gpu->thread, 0, dynamicColors ) );
        ImGui::SameLine();
        TextFocused( "Thread:", m_worker.GetThreadName( m_gpu->thread ) );
    }
    else
    {
        if( m_gpu->threadData.size() == 1 )
        {
            auto it = m_gpu->threadData.begin();
            auto tid = it->first;
            if( tid == 0 )
            {
                if( !it->second.timeline.empty() )
                {
                    if( it->second.timeline.is_magic() )
                    {
                        auto& tl = *(Vector<GpuEvent>*)&it->second.timeline;
                        tid = m_worker.DecompressThread( tl.begin()->Thread() );
                    }
                    else
                    {
                        tid = m_worker.DecompressThread( (*it->second.timeline.begin())->Thread() );
                    }
                }
            }
            SmallColorBox( GetThreadColor( tid, 0, dynamicColors ) );
            ImGui::SameLine();
            TextFocused( "Thread:", m_worker.GetThreadName( tid ) );
            ImGui::SameLine();
            ImGui::TextDisabled( "(%s)", RealToString( tid ) );
            if( m_worker.IsThreadFiber( tid ) )
            {
                ImGui::SameLine();
                TextColoredUnformatted( ImVec4( 0.2f, 0.6f, 0.2f, 1.f ), "Fiber" );
            }
        }
        else
        {
            ImGui::TextDisabled( "Threads:" );
            ImGui::Indent();
            for( auto& td : m_gpu->threadData )
            {
                SmallColorBox( GetThreadColor( td.first, 0, dynamicColors ) );
                ImGui::SameLine();
                ImGui::TextUnformatted( m_worker.GetThreadName( td.first ) );
                ImGui::SameLine();
                ImGui::TextDisabled( "(%s)", RealToString( td.first ) );
            }
            ImGui::Unindent();
        }
    }
    const auto t0 = RangeBegin();
    if( t0 != std::numeric_limits<int64_t>::max() )
    {
        TextFocused( "Appeared at", TimeToString( t0 ) );
    }
    TextFocused( "Zone count:", RealToString( m_gpu->count ) );
    if( m_gpu->period != 1.f )
    {
        TextFocused( "Timestamp accuracy:", TimeToString( m_gpu->period ) );
    }
    if( m_gpu->overflow != 0 )
    {
        ImGui::Separator();
        ImGui::TextUnformatted( "GPU timer overflow has been detected." );
        TextFocused( "Timer resolution:", RealToString( 63 - TracyLzcnt( m_gpu->overflow ) ) );
        ImGui::SameLine();
        TextDisabledUnformatted( "bits" );
    }
    ImGui::EndTooltip();
}

void TimelineItemGpu::HeaderExtraContents( int offset, const ImVec2& wpos, float labelWidth, double pxns, bool hover )
{
    if( m_gpu->name.Active() )
    {
        auto draw = ImGui::GetWindowDrawList();
        const auto ty = ImGui::GetTextLineHeight();

        char buf[64];
        sprintf( buf, "%s context %i", GpuContextNames[(int)m_gpu->type], m_idx );
        draw->AddText( wpos + ImVec2( ty * 1.5f + labelWidth, offset ), HeaderColorInactive(), buf );
    }
}

int64_t TimelineItemGpu::RangeBegin() const
{
    int64_t t = std::numeric_limits<int64_t>::max();
    for( auto& td : m_gpu->threadData )
    {
        int64_t t0;
        if( td.second.timeline.is_magic() )
        {
            t0 = ((Vector<GpuEvent>*)&td.second.timeline)->front().GpuStart();
        }
        else
        {
            t0 = td.second.timeline.front()->GpuStart();
        }
        if( t0 >= 0 )
        {
            t = std::min( t, t0 );
        }
    }
    return t;
}

int64_t TimelineItemGpu::RangeEnd() const
{
    int64_t t = std::numeric_limits<int64_t>::min();
    for( auto& td : m_gpu->threadData )
    {
        int64_t t0;
        if( td.second.timeline.is_magic() )
        {
            t0 = ((Vector<GpuEvent>*)&td.second.timeline)->front().GpuStart();
        }
        else
        {
            t0 = td.second.timeline.front()->GpuStart();
        }
        if( t0 >= 0 )
        {
            if( td.second.timeline.is_magic() )
            {
                t = std::max( t, std::min( m_worker.GetLastTime(), m_worker.GetZoneEnd( ((Vector<GpuEvent>*)&td.second.timeline)->back() ) ) );
            }
            else
            {
                t = std::max( t, std::min( m_worker.GetLastTime(), m_worker.GetZoneEnd( *td.second.timeline.back() ) ) );
            }
        }
    }
    return t;
}

bool TimelineItemGpu::DrawContents( double pxns, int& offset, const ImVec2& wpos, bool hover, float yMin, float yMax )
{
    return m_view.DrawGpu( *m_gpu, pxns, offset, wpos, hover, yMin, yMax );
}

}