1
0
mirror of https://github.com/wolfpld/tracy synced 2025-04-29 20:33:52 +00:00

Allow setting custom FPS targets on frames overview.

This commit is contained in:
Bartosz Taudul 2022-08-04 18:58:13 +02:00
parent 9b5d0747eb
commit 49dc3431ab
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3

View File

@ -7,15 +7,11 @@
namespace tracy namespace tracy
{ {
enum { BestTime = 1000 * 1000 * 1000 / 143 }; static uint32_t GetFrameColor( uint64_t time, uint64_t target )
enum { GoodTime = 1000 * 1000 * 1000 / 59 };
enum { BadTime = 1000 * 1000 * 1000 / 29 };
static ImU32 GetFrameColor( uint64_t frameTime )
{ {
return frameTime > BadTime ? 0xFF2222DD : return time > target * 2 ? 0xFF2222DD :
frameTime > GoodTime ? 0xFF22DDDD : time > target ? 0xFF22DDDD :
frameTime > BestTime ? 0xFF22DD22 : 0xFFDD9900; time > target / 2 ? 0xFF22DD22 : 0xFFDD9900;
} }
static int GetFrameWidth( int frameScale ) static int GetFrameWidth( int frameScale )
@ -41,11 +37,13 @@ void View::DrawFrames()
const auto scale = GetScale(); const auto scale = GetScale();
const auto Height = 50 * scale; const auto Height = 50 * scale;
enum { MaxFrameTime = 50 * 1000 * 1000 }; // 50ms constexpr uint64_t MaxFrameTime = 50 * 1000 * 1000; // 50ms
ImGuiWindow* window = ImGui::GetCurrentWindowRead(); ImGuiWindow* window = ImGui::GetCurrentWindowRead();
if( window->SkipItems ) return; if( window->SkipItems ) return;
const uint64_t frameTarget = 1000 * 1000 * 1000 / m_vd.frameTarget;
auto& io = ImGui::GetIO(); auto& io = ImGui::GetIO();
const auto wpos = ImGui::GetCursorScreenPos(); const auto wpos = ImGui::GetCursorScreenPos();
@ -416,11 +414,11 @@ void View::DrawFrames()
const auto h = std::max( 1.f, float( std::min<uint64_t>( MaxFrameTime, f ) ) / MaxFrameTime * ( Height - 2 ) ); const auto h = std::max( 1.f, float( std::min<uint64_t>( MaxFrameTime, f ) ) / MaxFrameTime * ( Height - 2 ) );
if( fwidth != 1 ) if( fwidth != 1 )
{ {
draw->AddRectFilled( wpos + ImVec2( 1 + i*fwidth, Height-1-h ), wpos + ImVec2( fwidth + i*fwidth, Height-1 ), GetFrameColor( f ) ); draw->AddRectFilled( wpos + ImVec2( 1 + i*fwidth, Height-1-h ), wpos + ImVec2( fwidth + i*fwidth, Height-1 ), GetFrameColor( f, frameTarget ) );
} }
else else
{ {
DrawLine( draw, dpos + ImVec2( 1+i, Height-2-h ), dpos + ImVec2( 1+i, Height-2 ), GetFrameColor( f ) ); DrawLine( draw, dpos + ImVec2( 1+i, Height-2-h ), dpos + ImVec2( 1+i, Height-2 ), GetFrameColor( f, frameTarget ) );
} }
i++; i++;
@ -447,9 +445,9 @@ void View::DrawFrames()
} }
} }
DrawLine( draw, dpos + ImVec2( 0, round( Height - Height * BadTime / MaxFrameTime ) ), dpos + ImVec2( w, round( Height - Height * BadTime / MaxFrameTime ) ), 0x4422DDDD ); if( frameTarget * 2 <= MaxFrameTime ) DrawLine( draw, dpos + ImVec2( 0, round( Height - Height * frameTarget * 2 / MaxFrameTime ) ), dpos + ImVec2( w, round( Height - Height * frameTarget * 2 / MaxFrameTime ) ), 0x442222DD );
DrawLine( draw, dpos + ImVec2( 0, round( Height - Height * GoodTime / MaxFrameTime ) ), dpos + ImVec2( w, round( Height - Height * GoodTime / MaxFrameTime ) ), 0x4422DD22 ); if( frameTarget <= MaxFrameTime ) DrawLine( draw, dpos + ImVec2( 0, round( Height - Height * frameTarget / MaxFrameTime ) ), dpos + ImVec2( w, round( Height - Height * frameTarget / MaxFrameTime ) ), 0x4422DDDD );
DrawLine( draw, dpos + ImVec2( 0, round( Height - Height * BestTime / MaxFrameTime ) ), dpos + ImVec2( w, round( Height - Height * BestTime / MaxFrameTime ) ), 0x44DD9900 ); if( frameTarget / 2 <= MaxFrameTime ) DrawLine( draw, dpos + ImVec2( 0, round( Height - Height * frameTarget / 2 / MaxFrameTime ) ), dpos + ImVec2( w, round( Height - Height * frameTarget / 2 / MaxFrameTime ) ), 0x4422DD22 );
} }
} }