Compare commits

..

1 Commits

Author SHA1 Message Date
Marcos Slomp
9402d295f9 allow OpenGL on MacOS when possible 2026-06-10 14:06:35 -07:00
4 changed files with 63 additions and 61 deletions

View File

@@ -162,15 +162,6 @@ static ImGuiKey TranslateKeyCode( const char* code )
return ImGuiKey_None;
}
static void UpdateKeyModifiers( const EmscriptenKeyboardEvent* e )
{
ImGuiIO& io = ImGui::GetIO();
io.AddKeyEvent( ImGuiMod_Ctrl, e->ctrlKey );
io.AddKeyEvent( ImGuiMod_Shift, e->shiftKey );
io.AddKeyEvent( ImGuiMod_Alt, e->altKey );
io.AddKeyEvent( ImGuiMod_Super, e->metaKey );
}
Backend::Backend( const char* title, const std::function<void()>& redraw, const std::function<void(float)>& scaleChanged, const std::function<int(void)>& isBusy, RunQueue* mainThreadTasks )
{
constexpr EGLint eglConfigAttrib[] = {
@@ -252,7 +243,6 @@ Backend::Backend( const char* title, const std::function<void()>& redraw, const
return EM_TRUE;
} );
emscripten_set_keydown_callback( EMSCRIPTEN_EVENT_TARGET_WINDOW, nullptr, EM_TRUE, [] ( int, const EmscriptenKeyboardEvent* e, void* ) -> EM_BOOL {
UpdateKeyModifiers( e );
const auto code = TranslateKeyCode( e->code );
if( code == ImGuiKey_None ) return EM_FALSE;
ImGui::GetIO().AddKeyEvent( code, true );
@@ -260,7 +250,6 @@ Backend::Backend( const char* title, const std::function<void()>& redraw, const
return EM_TRUE;
} );
emscripten_set_keyup_callback( EMSCRIPTEN_EVENT_TARGET_WINDOW, nullptr, EM_TRUE, [] ( int, const EmscriptenKeyboardEvent* e, void* ) -> EM_BOOL {
UpdateKeyModifiers( e );
const auto code = TranslateKeyCode( e->code );
if( code == ImGuiKey_None ) return EM_FALSE;
ImGui::GetIO().AddKeyEvent( code, false );

View File

@@ -295,7 +295,6 @@ bool UserData::Load()
LoadValue( v, "min", a->range.min );
LoadValue( v, "max", a->range.max );
LoadValue( v, "color", a->color );
a->range.active = true;
m_annotations.emplace_back( std::move( a ) );
}
}

View File

@@ -299,22 +299,6 @@ void View::DrawTimeline()
v->range.StartFrame();
HandleRange( v->range, timespan, ImGui::GetCursorScreenPos(), w );
}
if( IsMouseClicked( 0 ) )
{
const auto ty = ImGui::GetTextLineHeight();
for( auto& ann : m_annotations )
{
if( ann->range.min >= m_vd.zvEnd || ann->range.max <= m_vd.zvStart ) continue;
const auto aMin = ( ann->range.min - m_vd.zvStart ) * pxns;
const auto aMax = ( ann->range.max - m_vd.zvStart ) * pxns;
if( ImGui::IsMouseHoveringRect( linepos + ImVec2( aMin, lineh - ty * 1.5f ), linepos + ImVec2( aMax, lineh ) ) )
{
m_selectedAnnotation = ann.get();
ConsumeMouseEvents( 0 );
break;
}
}
}
HandleTimelineMouse( timespan, ImGui::GetCursorScreenPos(), w );
}
if( ImGui::IsWindowFocused( ImGuiHoveredFlags_ChildWindows | ImGuiHoveredFlags_AllowWhenBlockedByActiveItem ) )
@@ -376,8 +360,9 @@ void View::DrawTimeline()
bool hover = ImGui::IsWindowHovered() && ImGui::IsMouseHoveringRect( wpos, wpos + ImVec2( w, h ) );
draw = ImGui::GetWindowDrawList();
const auto scale = GetScale();
const auto ty = ImGui::GetTextLineHeight();
const auto to = 9.f;
const auto th = ( ty - to ) * sqrt( 3 ) * 0.5;
if( m_vd.drawGpuZones )
{
@@ -430,24 +415,17 @@ void View::DrawTimeline()
m_lockHighlight = m_nextLockHighlight;
const auto iconSize = ImGui::CalcTextSize( ICON_FA_NOTE_STICKY );
for( auto& ann : m_annotations )
{
if( ann->range.min < m_vd.zvEnd && ann->range.max > m_vd.zvStart )
{
uint32_t c0 = ( ann->color & 0xFFFFFF ) | ( m_selectedAnnotation == ann.get() ? 0x22000000 : 0x11000000 );
uint32_t c1 = ( ann->color & 0xFFFFFF ) | ( m_selectedAnnotation == ann.get() ? 0x88000000 : 0x66000000 );
uint32_t c2 = ( ann->color & 0xFFFFFF ) | ( m_selectedAnnotation == ann.get() ? 0xDD000000 : 0xBB000000 );
const auto aMin = ( ann->range.min - m_vd.zvStart ) * pxns;
const auto aMax = ( ann->range.max - m_vd.zvStart ) * pxns;
draw->AddRectFilled( linepos + ImVec2( aMin, 0 ), linepos + ImVec2( aMax, lineh ), c0 );
draw->AddRectFilled( linepos + ImVec2( aMin + 1, lineh - ty * 1.5f ), linepos + ImVec2( aMax - 1, lineh ), 0x88000000 );
DrawLine( draw, linepos + ImVec2( aMin + 0.5f, 0.5f ), linepos + ImVec2( aMin + 0.5f, lineh + 0.5f ), ann->range.hiMin ? c2 : c1, ann->range.hiMin ? 2 : 1 );
DrawLine( draw, linepos + ImVec2( aMax - 0.5f, 0.5f ), linepos + ImVec2( aMax - 0.5f, lineh + 0.5f ), ann->range.hiMax ? c2 : c1, ann->range.hiMax ? 2 : 1 );
if( drawMouseLine && ImGui::IsMouseHoveringRect( linepos + ImVec2( aMin, 0 ), linepos + ImVec2( aMax, lineh ) ) )
uint32_t c0 = ( ann->color & 0xFFFFFF ) | ( m_selectedAnnotation == ann.get() ? 0x44000000 : 0x22000000 );
uint32_t c1 = ( ann->color & 0xFFFFFF ) | ( m_selectedAnnotation == ann.get() ? 0x66000000 : 0x44000000 );
uint32_t c2 = ( ann->color & 0xFFFFFF ) | ( m_selectedAnnotation == ann.get() ? 0xCC000000 : 0xAA000000 );
draw->AddRectFilled( linepos + ImVec2( ( ann->range.min - m_vd.zvStart ) * pxns, 0 ), linepos + ImVec2( ( ann->range.max - m_vd.zvStart ) * pxns, lineh ), c0 );
DrawLine( draw, linepos + ImVec2( ( ann->range.min - m_vd.zvStart ) * pxns + 0.5f, 0.5f ), linepos + ImVec2( ( ann->range.min - m_vd.zvStart ) * pxns + 0.5f, lineh + 0.5f ), ann->range.hiMin ? c2 : c1, ann->range.hiMin ? 2 : 1 );
DrawLine( draw, linepos + ImVec2( ( ann->range.max - m_vd.zvStart ) * pxns + 0.5f, 0.5f ), linepos + ImVec2( ( ann->range.max - m_vd.zvStart ) * pxns + 0.5f, lineh + 0.5f ), ann->range.hiMax ? c2 : c1, ann->range.hiMax ? 2 : 1 );
if( drawMouseLine && ImGui::IsMouseHoveringRect( linepos + ImVec2( ( ann->range.min - m_vd.zvStart ) * pxns, 0 ), linepos + ImVec2( ( ann->range.max - m_vd.zvStart ) * pxns, lineh ) ) )
{
ImGui::BeginTooltip();
if( ann->text.empty() )
@@ -464,22 +442,27 @@ void View::DrawTimeline()
TextFocused( "Annotation length:", TimeToString( ann->range.max - ann->range.min ) );
ImGui::EndTooltip();
}
const auto aw = ( ann->range.max - ann->range.min ) * pxns;
if( aw > ty + iconSize.x )
if( aw > th * 4 )
{
draw->AddText( linepos + ImVec2( aMin + ty * 0.5f, lineh - ty * 1.25f ), ann->color | 0xFF000000, ICON_FA_NOTE_STICKY );
draw->AddCircleFilled( linepos + ImVec2( ( ann->range.min - m_vd.zvStart ) * pxns + th * 2, th * 2 ), th, 0x88AABB22 );
draw->AddCircle( linepos + ImVec2( ( ann->range.min - m_vd.zvStart ) * pxns + th * 2, th * 2 ), th, 0xAAAABB22 );
if( drawMouseLine && IsMouseClicked( 0 ) && ImGui::IsMouseHoveringRect( linepos + ImVec2( ( ann->range.min - m_vd.zvStart ) * pxns + th, th ), linepos + ImVec2( ( ann->range.min - m_vd.zvStart ) * pxns + th * 3, th * 3 ) ) )
{
m_selectedAnnotation = ann.get();
}
if( !ann->text.empty() )
{
const auto tw = ImGui::CalcTextSize( ann->text.c_str() ).x;
if( aw > ty + iconSize.x + tw )
if( aw - th*4 > tw )
{
draw->AddText( linepos + ImVec2( aMin + ty + iconSize.x, lineh - ty * 1.25f ), 0xFFFFFFFF, ann->text.c_str() );
draw->AddText( linepos + ImVec2( ( ann->range.min - m_vd.zvStart ) * pxns + th * 4, th * 0.5 ), 0xFFFFFFFF, ann->text.c_str() );
}
else
{
draw->PushClipRect( linepos + ImVec2( aMin + 1, lineh - ty * 1.5f ), linepos + ImVec2( aMax - 1, lineh ) );
draw->AddText( linepos + ImVec2( aMin + ty + iconSize.x, lineh - ty * 1.25f ), 0xFFFFFFFF, ann->text.c_str() );
draw->PushClipRect( linepos + ImVec2( ( ann->range.min - m_vd.zvStart ) * pxns, 0 ), linepos + ImVec2( ( ann->range.max - m_vd.zvStart ) * pxns, lineh ), true );
draw->AddText( linepos + ImVec2( ( ann->range.min - m_vd.zvStart ) * pxns + th * 4, th * 0.5 ), 0xFFFFFFFF, ann->text.c_str() );
draw->PopClipRect();
}
}
@@ -502,6 +485,7 @@ void View::DrawTimeline()
draw->AddRect( ImVec2( wpos.x + px0, linepos.y ), ImVec2( wpos.x + px1, linepos.y + lineh ), 0x4488DD88 );
}
const auto scale = GetScale();
if( m_findZone.range.active && ( m_findZone.show || m_showRanges ) )
{
const auto px0 = ( m_findZone.range.min - m_vd.zvStart ) * pxns;

View File

@@ -1,7 +1,7 @@
#ifndef __TRACYOPENGL_HPP__
#define __TRACYOPENGL_HPP__
#if !defined TRACY_ENABLE || defined __APPLE__
#if !defined TRACY_ENABLE
#define TracyGpuContext
#define TracyGpuContextName(x,y)
@@ -31,6 +31,10 @@ public:
#else
#if (defined __APPLE__ && !TARGET_OS_OSX)
#error Apple devices do not support OpenGL (except on MacOS where it's deprecated).
#endif
#include <atomic>
#include <assert.h>
#include <stdlib.h>
@@ -94,11 +98,23 @@ class GpuCtx
public:
GpuCtx()
: m_context( GetGpuCtxCounter().fetch_add( 1, std::memory_order_relaxed ) )
: m_context( 255 )
, m_head( 0 )
, m_tail( 0 )
{
assert( m_context != 255 );
ZoneScopedC( Color::Red4 );
GLint bits = 0;
glGetQueryiv( GL_TIMESTAMP, GL_QUERY_COUNTER_BITS, &bits );
assert( bits > 0 );
if( bits == 0 )
{
// all timestamp queries would resolve to 0 (and produce 0ns GPU zones).
// (this is the case for many TBDR GPUs, including Apple Silicon)
Profiler::LogString( MessageSourceType::Tracy, MessageSeverity::Error, Color::Red4, 0,
"OpenGL driver does not implement GL_TIMESTAMP precision." );
return;
}
glGenQueries( QueryCount, m_query );
@@ -106,9 +122,6 @@ public:
glGetInteger64v( GL_TIMESTAMP, &tgpu );
int64_t tcpu = Profiler::GetTime();
GLint bits;
glGetQueryiv( GL_TIMESTAMP, GL_QUERY_COUNTER_BITS, &bits );
#ifdef TRACY_OPENGL_AUTO_CALIBRATION
// The anchor above is never refreshed; advertise calibration and emit periodic
// GpuCalibration events to correct CPU/GPU drift (see Recalibrate). Opt-in,
@@ -117,6 +130,9 @@ public:
m_prevCalibration = GetHostTimeNs();
#endif
assert( m_context != 255 );
m_context = GetGpuCtxCounter().fetch_add( 1, std::memory_order_relaxed );
const float period = 1.f;
const auto thread = GetThreadHandle();
TracyLfqPrepare( QueueType::GpuNewContext );
@@ -141,6 +157,8 @@ public:
void Name( const char* name, uint16_t len )
{
if ( !Valid() ) return;
auto ptr = (char*)tracy_malloc( len );
memcpy( ptr, name, len );
@@ -156,6 +174,8 @@ public:
void Collect()
{
if ( !Valid() ) return;
ZoneScopedC( Color::Red4 );
#ifdef TRACY_ON_DEMAND
@@ -244,6 +264,11 @@ private:
return m_context;
}
tracy_force_inline bool Valid() const
{
return m_context != 255;
}
unsigned int m_query[QueryCount];
uint8_t m_context;
@@ -265,7 +290,7 @@ public:
: m_active( is_active )
#endif
{
if( !m_active ) return;
if( !m_active || !Valid() ) return;
const auto queryId = GetGpuCtx().ptr->NextQueryId();
glQueryCounter( GetGpuCtx().ptr->TranslateOpenGlQueryId( queryId ), GL_TIMESTAMP );
@@ -286,7 +311,7 @@ public:
: m_active( is_active )
#endif
{
if( !m_active ) return;
if( !m_active || !Valid() ) return;
const auto queryId = GetGpuCtx().ptr->NextQueryId();
glQueryCounter( GetGpuCtx().ptr->TranslateOpenGlQueryId( queryId ), GL_TIMESTAMP );
@@ -313,7 +338,7 @@ public:
: m_active( is_active )
#endif
{
if( !m_active ) return;
if( !m_active || !Valid() ) return;
const auto queryId = GetGpuCtx().ptr->NextQueryId();
glQueryCounter( GetGpuCtx().ptr->TranslateOpenGlQueryId( queryId ), GL_TIMESTAMP );
@@ -335,7 +360,7 @@ public:
: m_active( is_active )
#endif
{
if( !m_active ) return;
if( !m_active || !Valid() ) return;
const auto queryId = GetGpuCtx().ptr->NextQueryId();
glQueryCounter( GetGpuCtx().ptr->TranslateOpenGlQueryId( queryId ), GL_TIMESTAMP );
@@ -358,7 +383,7 @@ public:
tracy_force_inline ~GpuCtxScope()
{
if( !m_active ) return;
if( !m_active || !Valid() ) return;
const auto queryId = GetGpuCtx().ptr->NextQueryId();
glQueryCounter( GetGpuCtx().ptr->TranslateOpenGlQueryId( queryId ), GL_TIMESTAMP );
@@ -371,6 +396,11 @@ public:
TracyLfqCommit;
}
tracy_force_inline bool Valid()
{
return GetGpuCtx().ptr->Valid();
}
private:
const bool m_active;
};