Hide rest of statics.

This commit is contained in:
Bartosz Taudul 2019-02-19 19:33:37 +01:00
parent 9fabafbeca
commit 3f914834b7
8 changed files with 112 additions and 132 deletions

View File

@ -32,6 +32,25 @@ namespace tracy
DLL_IMPORT void(*get_rpfree())(void* ptr); DLL_IMPORT void(*get_rpfree())(void* ptr);
DLL_IMPORT moodycamel::ConcurrentQueue<QueueItem>::ExplicitProducer*(*get_token())(); DLL_IMPORT moodycamel::ConcurrentQueue<QueueItem>::ExplicitProducer*(*get_token())();
DLL_IMPORT Profiler&(*get_profiler())(); DLL_IMPORT Profiler&(*get_profiler())();
DLL_IMPORT std::atomic<uint32_t>&(*get_getlockcounter())();
DLL_IMPORT std::atomic<uint8_t>&(*get_getgpuctxcounter())();
DLL_IMPORT GpuCtxWrapper&(*get_getgpuctx())();
static void*(*rpmalloc_fpt)(size_t size) = get_rpmalloc();
static void(*rpfree_fpt)(void* ptr) = get_rpfree();
static moodycamel::ConcurrentQueue<QueueItem>::ExplicitProducer*(*GetToken_fpt)() = get_token();
static Profiler&(*GetProfiler_fpt)() = get_profiler();
static std::atomic<uint32_t>&(*GetLockCounter_fpt)() = get_getlockcounter();
static std::atomic<uint8_t>&(*GetGpuCtxCounter_fpt)() = get_getgpuctxcounter();
static GpuCtxWrapper&(*GetGpuCtx_fpt)() = get_getgpuctx();
RPMALLOC_RESTRICT void* rpmalloc(size_t size) { return rpmalloc_fpt(size); }
void rpfree(void* ptr) { rpfree_fpt(ptr); }
moodycamel::ConcurrentQueue<QueueItem>::ExplicitProducer* GetToken() { return GetToken_fpt(); }
Profiler& GetProfiler() { return GetProfiler_fpt(); }
std::atomic<uint32_t>& GetLockCounter() { return GetLockCounter_fpt(); }
std::atomic<uint8_t>& GetGpuCtxCounter() { return GetGpuCtxCounter_fpt(); }
GpuCtxWrapper& GetGpuCtx() { return GetGpuCtx_fpt(); }
#if defined TRACY_HW_TIMER && __ARM_ARCH >= 6 #if defined TRACY_HW_TIMER && __ARM_ARCH >= 6
DLL_IMPORT int64_t(*get_GetTimeImpl())(); DLL_IMPORT int64_t(*get_GetTimeImpl())();
@ -40,43 +59,23 @@ namespace tracy
#endif #endif
#ifdef TRACY_COLLECT_THREAD_NAMES #ifdef TRACY_COLLECT_THREAD_NAMES
DLL_IMPORT std::atomic<ThreadNameData*>& get_threadNameData(); DLL_IMPORT std::atomic<ThreadNameData*>& get_threadnamedata();
DLL_IMPORT void(*get_rpmalloc_thread_initialize())(); DLL_IMPORT void(*get_rpmalloc_thread_initialize())();
std::atomic<ThreadNameData*>& s_threadNameData = get_threadNameData(); static std::atomic<ThreadNameData*>&(*GetThreadNameData_fpt)() = get_getthreadnamedata();
void(*rpmalloc_thread_initialize_fpt)() = get_rpmalloc_thread_initialize(); static void(*rpmalloc_thread_initialize_fpt)() = get_rpmalloc_thread_initialize();
void rpmalloc_thread_initialize(void) std::atomic<ThreadNameData*>& GetThreadNameData() { return GetThreadNameData_fpt(); }
{ void rpmalloc_thread_initialize(void) { rpmalloc_thread_initialize_fpt(); }
rpmalloc_thread_initialize_fpt();
}
#endif #endif
static void*(*rpmalloc_fpt)(size_t size) = get_rpmalloc(); #ifdef TRACY_ON_DEMAND
static void(*rpfree_fpt)(void* ptr) = get_rpfree(); DLL_IMPORT LuaZoneState&(*get_getluazonestate())();
static moodycamel::ConcurrentQueue<QueueItem>::ExplicitProducer*(*GetToken_fpt)() = get_token;
static Profiler&(*GetProfiler_fpt)() = get_profiler();
RPMALLOC_RESTRICT void* rpmalloc(size_t size) static LuaZoneState&(*GetLuaZoneState_fpt)() = get_getluazonestate();
{
return rpmalloc_fpt(size);
}
void rpfree(void* ptr)
{
rpfree_fpt(ptr);
}
moodycamel::ConcurrentQueue<QueueItem>::ExplicitProducer* GetToken()
{
return GetToken_fpt();
}
Profiler& GetProfiler()
{
return GetProfiler_fpt();
}
LuaZoneState& GetLuaZoneState() { return GetLuaZoneState_fpt(); }
#endif
} }
#endif #endif

View File

@ -119,7 +119,7 @@ namespace tracy
{ {
#ifdef TRACY_ON_DEMAND #ifdef TRACY_ON_DEMAND
extern thread_local LuaZoneState s_luaZoneState; LuaZoneState& GetLuaZoneState();
#endif #endif
namespace detail namespace detail
@ -128,10 +128,10 @@ namespace detail
static inline int LuaZoneBegin( lua_State* L ) static inline int LuaZoneBegin( lua_State* L )
{ {
#ifdef TRACY_ON_DEMAND #ifdef TRACY_ON_DEMAND
const auto zoneCnt = s_luaZoneState.counter++; const auto zoneCnt = GetLuaZoneState().counter++;
if( zoneCnt != 0 && !s_luaZoneState.active ) return 0; if( zoneCnt != 0 && !GetLuaZoneState().active ) return 0;
s_luaZoneState.active = GetProfiler().IsConnected(); GetLuaZoneState().active = GetProfiler().IsConnected();
if( !s_luaZoneState.active ) return 0; if( !GetLuaZoneState().active ) return 0;
#endif #endif
const uint32_t color = Color::DeepSkyBlue3; const uint32_t color = Color::DeepSkyBlue3;
@ -182,10 +182,10 @@ static inline int LuaZoneBegin( lua_State* L )
static inline int LuaZoneBeginN( lua_State* L ) static inline int LuaZoneBeginN( lua_State* L )
{ {
#ifdef TRACY_ON_DEMAND #ifdef TRACY_ON_DEMAND
const auto zoneCnt = s_luaZoneState.counter++; const auto zoneCnt = GetLuaZoneState().counter++;
if( zoneCnt != 0 && !s_luaZoneState.active ) return 0; if( zoneCnt != 0 && !GetLuaZoneState().active ) return 0;
s_luaZoneState.active = GetProfiler().IsConnected(); GetLuaZoneState().active = GetProfiler().IsConnected();
if( !s_luaZoneState.active ) return 0; if( !GetLuaZoneState().active ) return 0;
#endif #endif
const uint32_t color = Color::DeepSkyBlue3; const uint32_t color = Color::DeepSkyBlue3;
@ -240,12 +240,12 @@ static inline int LuaZoneBeginN( lua_State* L )
static inline int LuaZoneEnd( lua_State* L ) static inline int LuaZoneEnd( lua_State* L )
{ {
#ifdef TRACY_ON_DEMAND #ifdef TRACY_ON_DEMAND
assert( s_luaZoneState.counter != 0 ); assert( GetLuaZoneState().counter != 0 );
s_luaZoneState.counter--; GetLuaZoneState().counter--;
if( !s_luaZoneState.active ) return 0; if( !GetLuaZoneState().active ) return 0;
if( !GetProfiler().IsConnected() ) if( !GetProfiler().IsConnected() )
{ {
s_luaZoneState.active = false; GetLuaZoneState().active = false;
return 0; return 0;
} }
#endif #endif
@ -270,10 +270,10 @@ static inline int LuaZoneEnd( lua_State* L )
static inline int LuaZoneText( lua_State* L ) static inline int LuaZoneText( lua_State* L )
{ {
#ifdef TRACY_ON_DEMAND #ifdef TRACY_ON_DEMAND
if( !s_luaZoneState.active ) return 0; if( !GetLuaZoneState().active ) return 0;
if( !GetProfiler().IsConnected() ) if( !GetProfiler().IsConnected() )
{ {
s_luaZoneState.active = false; GetLuaZoneState().active = false;
return 0; return 0;
} }
#endif #endif
@ -298,10 +298,10 @@ static inline int LuaZoneText( lua_State* L )
static inline int LuaZoneName( lua_State* L ) static inline int LuaZoneName( lua_State* L )
{ {
#ifdef TRACY_ON_DEMAND #ifdef TRACY_ON_DEMAND
if( !s_luaZoneState.active ) return 0; if( !GetLuaZoneState().active ) return 0;
if( !GetProfiler().IsConnected() ) if( !GetProfiler().IsConnected() )
{ {
s_luaZoneState.active = false; GetLuaZoneState().active = false;
return 0; return 0;
} }
#endif #endif

View File

@ -40,7 +40,7 @@ public:
#include "common/TracyAlign.hpp" #include "common/TracyAlign.hpp"
#include "common/TracyAlloc.hpp" #include "common/TracyAlloc.hpp"
#define TracyGpuContext tracy::s_gpuCtx.ptr = (tracy::GpuCtx*)tracy::tracy_malloc( sizeof( tracy::GpuCtx ) ); new(tracy::s_gpuCtx.ptr) tracy::GpuCtx; #define TracyGpuContext tracy::GetGpuCtx().ptr = (tracy::GpuCtx*)tracy::tracy_malloc( sizeof( tracy::GpuCtx ) ); new(tracy::GetGpuCtx().ptr) tracy::GpuCtx;
#if defined TRACY_HAS_CALLSTACK && defined TRACY_CALLSTACK #if defined TRACY_HAS_CALLSTACK && defined TRACY_CALLSTACK
# define TracyGpuNamedZone( varname, name ) static const tracy::SourceLocationData TracyConcat(__tracy_gpu_source_location,__LINE__) { name, __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 }; tracy::GpuCtxScope varname( &TracyConcat(__tracy_gpu_source_location,__LINE__), TRACY_CALLSTACK ); # define TracyGpuNamedZone( varname, name ) static const tracy::SourceLocationData TracyConcat(__tracy_gpu_source_location,__LINE__) { name, __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 }; tracy::GpuCtxScope varname( &TracyConcat(__tracy_gpu_source_location,__LINE__), TRACY_CALLSTACK );
# define TracyGpuNamedZoneC( varname, name, color ) static const tracy::SourceLocationData TracyConcat(__tracy_gpu_source_location,__LINE__) { name, __FUNCTION__, __FILE__, (uint32_t)__LINE__, color }; tracy::GpuCtxScope varname( &TracyConcat(__tracy_gpu_source_location,__LINE__), TRACY_CALLSTACK ); # define TracyGpuNamedZoneC( varname, name, color ) static const tracy::SourceLocationData TracyConcat(__tracy_gpu_source_location,__LINE__) { name, __FUNCTION__, __FILE__, (uint32_t)__LINE__, color }; tracy::GpuCtxScope varname( &TracyConcat(__tracy_gpu_source_location,__LINE__), TRACY_CALLSTACK );
@ -52,7 +52,7 @@ public:
# define TracyGpuZone( name ) TracyGpuNamedZone( ___tracy_gpu_zone, name ) # define TracyGpuZone( name ) TracyGpuNamedZone( ___tracy_gpu_zone, name )
# define TracyGpuZoneC( name, color ) TracyGpuNamedZoneC( ___tracy_gpu_zone, name, color ) # define TracyGpuZoneC( name, color ) TracyGpuNamedZoneC( ___tracy_gpu_zone, name, color )
#endif #endif
#define TracyGpuCollect tracy::s_gpuCtx.ptr->Collect(); #define TracyGpuCollect tracy::GetGpuCtx().ptr->Collect();
#ifdef TRACY_HAS_CALLSTACK #ifdef TRACY_HAS_CALLSTACK
# define TracyGpuNamedZoneS( varname, name, depth ) static const tracy::SourceLocationData TracyConcat(__tracy_gpu_source_location,__LINE__) { name, __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 }; tracy::GpuCtxScope varname( &TracyConcat(__tracy_gpu_source_location,__LINE__), depth ); # define TracyGpuNamedZoneS( varname, name, depth ) static const tracy::SourceLocationData TracyConcat(__tracy_gpu_source_location,__LINE__) { name, __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 }; tracy::GpuCtxScope varname( &TracyConcat(__tracy_gpu_source_location,__LINE__), depth );
@ -69,8 +69,6 @@ public:
namespace tracy namespace tracy
{ {
extern std::atomic<uint8_t> s_gpuCtxCounter;
class GpuCtx class GpuCtx
{ {
friend class GpuCtxScope; friend class GpuCtxScope;
@ -79,7 +77,7 @@ class GpuCtx
public: public:
GpuCtx() GpuCtx()
: m_context( s_gpuCtxCounter.fetch_add( 1, std::memory_order_relaxed ) ) : m_context( GetGpuCtxCounter().fetch_add( 1, std::memory_order_relaxed ) )
, m_head( 0 ) , m_head( 0 )
, m_tail( 0 ) , m_tail( 0 )
{ {
@ -194,8 +192,6 @@ private:
unsigned int m_tail; unsigned int m_tail;
}; };
extern thread_local GpuCtxWrapper s_gpuCtx;
class GpuCtxScope class GpuCtxScope
{ {
public: public:
@ -207,8 +203,8 @@ public:
#ifdef TRACY_ON_DEMAND #ifdef TRACY_ON_DEMAND
if( !m_active ) return; if( !m_active ) return;
#endif #endif
const auto queryId = s_gpuCtx.ptr->NextQueryId(); const auto queryId = GetGpuCtx().ptr->NextQueryId();
glQueryCounter( s_gpuCtx.ptr->TranslateOpenGlQueryId( queryId ), GL_TIMESTAMP ); glQueryCounter( GetGpuCtx().ptr->TranslateOpenGlQueryId( queryId ), GL_TIMESTAMP );
Magic magic; Magic magic;
auto token = GetToken(); auto token = GetToken();
@ -219,7 +215,7 @@ public:
MemWrite( &item->gpuZoneBegin.srcloc, (uint64_t)srcloc ); MemWrite( &item->gpuZoneBegin.srcloc, (uint64_t)srcloc );
memset( &item->gpuZoneBegin.thread, 0, sizeof( item->gpuZoneBegin.thread ) ); memset( &item->gpuZoneBegin.thread, 0, sizeof( item->gpuZoneBegin.thread ) );
MemWrite( &item->gpuZoneBegin.queryId, uint16_t( queryId ) ); MemWrite( &item->gpuZoneBegin.queryId, uint16_t( queryId ) );
MemWrite( &item->gpuZoneBegin.context, s_gpuCtx.ptr->GetId() ); MemWrite( &item->gpuZoneBegin.context, GetGpuCtx().ptr->GetId() );
tail.store( magic + 1, std::memory_order_release ); tail.store( magic + 1, std::memory_order_release );
} }
@ -231,8 +227,8 @@ public:
#ifdef TRACY_ON_DEMAND #ifdef TRACY_ON_DEMAND
if( !m_active ) return; if( !m_active ) return;
#endif #endif
const auto queryId = s_gpuCtx.ptr->NextQueryId(); const auto queryId = GetGpuCtx().ptr->NextQueryId();
glQueryCounter( s_gpuCtx.ptr->TranslateOpenGlQueryId( queryId ), GL_TIMESTAMP ); glQueryCounter( GetGpuCtx().ptr->TranslateOpenGlQueryId( queryId ), GL_TIMESTAMP );
const auto thread = GetThreadHandle(); const auto thread = GetThreadHandle();
@ -245,7 +241,7 @@ public:
MemWrite( &item->gpuZoneBegin.srcloc, (uint64_t)srcloc ); MemWrite( &item->gpuZoneBegin.srcloc, (uint64_t)srcloc );
MemWrite( &item->gpuZoneBegin.thread, thread ); MemWrite( &item->gpuZoneBegin.thread, thread );
MemWrite( &item->gpuZoneBegin.queryId, uint16_t( queryId ) ); MemWrite( &item->gpuZoneBegin.queryId, uint16_t( queryId ) );
MemWrite( &item->gpuZoneBegin.context, s_gpuCtx.ptr->GetId() ); MemWrite( &item->gpuZoneBegin.context, GetGpuCtx().ptr->GetId() );
tail.store( magic + 1, std::memory_order_release ); tail.store( magic + 1, std::memory_order_release );
GetProfiler().SendCallstack( depth, thread ); GetProfiler().SendCallstack( depth, thread );
@ -256,8 +252,8 @@ public:
#ifdef TRACY_ON_DEMAND #ifdef TRACY_ON_DEMAND
if( !m_active ) return; if( !m_active ) return;
#endif #endif
const auto queryId = s_gpuCtx.ptr->NextQueryId(); const auto queryId = GetGpuCtx().ptr->NextQueryId();
glQueryCounter( s_gpuCtx.ptr->TranslateOpenGlQueryId( queryId ), GL_TIMESTAMP ); glQueryCounter( GetGpuCtx().ptr->TranslateOpenGlQueryId( queryId ), GL_TIMESTAMP );
Magic magic; Magic magic;
auto token = GetToken(); auto token = GetToken();
@ -266,7 +262,7 @@ public:
MemWrite( &item->hdr.type, QueueType::GpuZoneEnd ); MemWrite( &item->hdr.type, QueueType::GpuZoneEnd );
MemWrite( &item->gpuZoneEnd.cpuTime, Profiler::GetTime() ); MemWrite( &item->gpuZoneEnd.cpuTime, Profiler::GetTime() );
MemWrite( &item->gpuZoneEnd.queryId, uint16_t( queryId ) ); MemWrite( &item->gpuZoneEnd.queryId, uint16_t( queryId ) );
MemWrite( &item->gpuZoneEnd.context, s_gpuCtx.ptr->GetId() ); MemWrite( &item->gpuZoneEnd.context, GetGpuCtx().ptr->GetId() );
tail.store( magic + 1, std::memory_order_release ); tail.store( magic + 1, std::memory_order_release );
} }

View File

@ -35,8 +35,6 @@ using TracyVkCtx = void*;
namespace tracy namespace tracy
{ {
extern std::atomic<uint8_t> s_gpuCtxCounter;
class VkCtx class VkCtx
{ {
friend class VkCtxScope; friend class VkCtxScope;
@ -47,7 +45,7 @@ public:
VkCtx( VkPhysicalDevice physdev, VkDevice device, VkQueue queue, VkCommandBuffer cmdbuf ) VkCtx( VkPhysicalDevice physdev, VkDevice device, VkQueue queue, VkCommandBuffer cmdbuf )
: m_device( device ) : m_device( device )
, m_queue( queue ) , m_queue( queue )
, m_context( s_gpuCtxCounter.fetch_add( 1, std::memory_order_relaxed ) ) , m_context( GetGpuCtxCounter().fetch_add( 1, std::memory_order_relaxed ) )
, m_head( 0 ) , m_head( 0 )
, m_tail( 0 ) , m_tail( 0 )
, m_oldCnt( 0 ) , m_oldCnt( 0 )

View File

@ -11,14 +11,12 @@
namespace tracy namespace tracy
{ {
extern std::atomic<uint32_t> s_lockCounter;
template<class T> template<class T>
class Lockable class Lockable
{ {
public: public:
tracy_force_inline Lockable( const SourceLocationData* srcloc ) tracy_force_inline Lockable( const SourceLocationData* srcloc )
: m_id( s_lockCounter.fetch_add( 1, std::memory_order_relaxed ) ) : m_id( GetLockCounter().fetch_add( 1, std::memory_order_relaxed ) )
#ifdef TRACY_ON_DEMAND #ifdef TRACY_ON_DEMAND
, m_lockCount( 0 ) , m_lockCount( 0 )
, m_active( false ) , m_active( false )
@ -211,7 +209,7 @@ class SharedLockable
{ {
public: public:
tracy_force_inline SharedLockable( const SourceLocationData* srcloc ) tracy_force_inline SharedLockable( const SourceLocationData* srcloc )
: m_id( s_lockCounter.fetch_add( 1, std::memory_order_relaxed ) ) : m_id( GetLockCounter().fetch_add( 1, std::memory_order_relaxed ) )
#ifdef TRACY_ON_DEMAND #ifdef TRACY_ON_DEMAND
, m_lockCount( 0 ) , m_lockCount( 0 )
, m_active( false ) , m_active( false )

View File

@ -768,57 +768,43 @@ static Profiler init_order(105) s_profiler;
#endif #endif
moodycamel::ConcurrentQueue<QueueItem>::ExplicitProducer* GetToken() moodycamel::ConcurrentQueue<QueueItem>::ExplicitProducer* GetToken() { return s_token.ptr; }
{ Profiler& GetProfiler() { return s_profiler; }
return s_token.ptr; moodycamel::ConcurrentQueue<QueueItem>& GetQueue() { return s_queue; }
} InitTimeWrapper& GetInitTime() { return s_initTime; }
std::atomic<uint32_t>& GetLockCounter() { return s_lockCounter; }
std::atomic<uint8_t>& GetGpuCtxCounter() { return s_gpuCtxCounter; }
GpuCtxWrapper& GetGpuCtx() { return s_gpuCtx; }
Profiler& GetProfiler() #ifdef TRACY_COLLECT_THREAD_NAMES
{ std::atomic<ThreadNameData*>& GetThreadNameData() { return s_threadNameData; }
return s_profiler; #endif
}
#ifdef TRACY_ON_DEMAND
LuaZoneState& GetLuaZoneState() { return s_luaZoneState; }
#endif
// DLL exports to enable TracyClientDLL.cpp to retrieve the instances of Tracy objects and functions // DLL exports to enable TracyClientDLL.cpp to retrieve the instances of Tracy objects and functions
DLL_EXPORT void*(*get_rpmalloc())(size_t size) { return rpmalloc; }
DLL_EXPORT void*(*get_rpmalloc())(size_t size) DLL_EXPORT void(*get_rpfree())(void* ptr) { return rpfree; }
{ DLL_EXPORT moodycamel::ConcurrentQueue<QueueItem>::ExplicitProducer*(*get_token())() { return GetToken; }
return rpmalloc; DLL_EXPORT Profiler&(*get_profiler())() { return GetProfiler; }
} DLL_EXPORT std::atomic<uint32_t>&(*get_getlockcounter())() { return GetLockCounter; }
DLL_EXPORT std::atomic<uint8_t>&(*get_getgpuctxcounter())() { return GetGpuCtxCounter; }
DLL_EXPORT void(*get_rpfree())(void* ptr) DLL_EXPORT GpuCtxWrapper&(*get_getgpuctx())() { return GetGpuCtx; }
{
return rpfree;
}
DLL_EXPORT moodycamel::ConcurrentQueue<QueueItem>::ExplicitProducer*(*get_token())()
{
return GetToken;
}
DLL_EXPORT Profiler&(*get_profiler())()
{
return GetProfiler;
}
#if defined TRACY_HW_TIMER && __ARM_ARCH >= 6 #if defined TRACY_HW_TIMER && __ARM_ARCH >= 6
DLL_EXPORT int64_t(*get_GetTimeImpl())() DLL_EXPORT int64_t(*get_GetTimeImpl())() { return GetTimeImpl; }
{
return GetTimeImpl;
}
#endif #endif
#ifdef TRACY_COLLECT_THREAD_NAMES #ifdef TRACY_COLLECT_THREAD_NAMES
DLL_EXPORT std::atomic<ThreadNameData*>& get_threadNameData() DLL_EXPORT std::atomic<ThreadNameData*>&(*get_threadnamedata())() { return GetThreadNameData; }
{ DLL_EXPORT void(*get_rpmalloc_thread_initialize())() { return rpmalloc_thread_initialize; }
return s_threadNameData;
}
DLL_EXPORT void(*get_rpmalloc_thread_initialize())()
{
return rpmalloc_thread_initialize;
}
#endif #endif
#ifdef TRACY_ON_DEMAND
DLL_EXPORT LuaZoneState&(*get_getluazonestate())() { return GetLuaZoneState; }
#endif
enum { BulkSize = TargetFrameSize / QueueItemSize }; enum { BulkSize = TargetFrameSize / QueueItemSize };
@ -953,7 +939,7 @@ void Profiler::Worker()
WelcomeMessage welcome; WelcomeMessage welcome;
MemWrite( &welcome.timerMul, m_timerMul ); MemWrite( &welcome.timerMul, m_timerMul );
MemWrite( &welcome.initBegin, s_initTime.val ); MemWrite( &welcome.initBegin, GetInitTime().val );
MemWrite( &welcome.initEnd, m_timeBegin.load( std::memory_order_relaxed ) ); MemWrite( &welcome.initEnd, m_timeBegin.load( std::memory_order_relaxed ) );
MemWrite( &welcome.delay, m_delay ); MemWrite( &welcome.delay, m_delay );
MemWrite( &welcome.resolution, m_resolution ); MemWrite( &welcome.resolution, m_resolution );
@ -964,7 +950,7 @@ void Profiler::Worker()
memcpy( welcome.hostInfo, hostinfo, hisz ); memcpy( welcome.hostInfo, hostinfo, hisz );
memset( welcome.hostInfo + hisz, 0, WelcomeMessageHostInfoSize - hisz ); memset( welcome.hostInfo + hisz, 0, WelcomeMessageHostInfoSize - hisz );
moodycamel::ConsumerToken token( s_queue ); moodycamel::ConsumerToken token( GetQueue() );
ListenSocket listen; ListenSocket listen;
if( !listen.Listen( "8086", 8 ) ) if( !listen.Listen( "8086", 8 ) )
@ -1240,7 +1226,7 @@ void Profiler::ClearQueues( moodycamel::ConsumerToken& token )
{ {
for(;;) for(;;)
{ {
const auto sz = s_queue.try_dequeue_bulk( token, m_itemBuf, BulkSize ); const auto sz = GetQueue().try_dequeue_bulk( token, m_itemBuf, BulkSize );
if( sz == 0 ) break; if( sz == 0 ) break;
for( size_t i=0; i<sz; i++ ) FreeAssociatedMemory( m_itemBuf[i] ); for( size_t i=0; i<sz; i++ ) FreeAssociatedMemory( m_itemBuf[i] );
} }
@ -1269,7 +1255,7 @@ void Profiler::ClearQueues( moodycamel::ConsumerToken& token )
Profiler::DequeueStatus Profiler::Dequeue( moodycamel::ConsumerToken& token ) Profiler::DequeueStatus Profiler::Dequeue( moodycamel::ConsumerToken& token )
{ {
const auto sz = s_queue.try_dequeue_bulk( token, m_itemBuf, BulkSize ); const auto sz = GetQueue().try_dequeue_bulk( token, m_itemBuf, BulkSize );
if( sz > 0 ) if( sz > 0 )
{ {
auto end = m_itemBuf + sz; auto end = m_itemBuf + sz;
@ -1619,8 +1605,8 @@ void Profiler::CalibrateDelay()
enum { Events = Iterations * 2 }; // start + end enum { Events = Iterations * 2 }; // start + end
static_assert( Events * 2 < QueuePrealloc, "Delay calibration loop will allocate memory in queue" ); static_assert( Events * 2 < QueuePrealloc, "Delay calibration loop will allocate memory in queue" );
moodycamel::ProducerToken ptoken_detail( s_queue ); moodycamel::ProducerToken ptoken_detail( GetQueue() );
moodycamel::ConcurrentQueue<QueueItem>::ExplicitProducer* ptoken = s_queue.get_explicit_producer( ptoken_detail ); moodycamel::ConcurrentQueue<QueueItem>::ExplicitProducer* ptoken = GetQueue().get_explicit_producer( ptoken_detail );
for( int i=0; i<Iterations; i++ ) for( int i=0; i<Iterations; i++ )
{ {
static const tracy::SourceLocationData __tracy_source_location { nullptr, __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 }; static const tracy::SourceLocationData __tracy_source_location { nullptr, __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 };
@ -1715,12 +1701,12 @@ void Profiler::CalibrateDelay()
m_resolution = mindiff; m_resolution = mindiff;
enum { Bulk = 1000 }; enum { Bulk = 1000 };
moodycamel::ConsumerToken token( s_queue ); moodycamel::ConsumerToken token( GetQueue() );
int left = Events * 2; int left = Events * 2;
QueueItem item[Bulk]; QueueItem item[Bulk];
while( left != 0 ) while( left != 0 )
{ {
const auto sz = s_queue.try_dequeue_bulk( token, item, std::min( left, (int)Bulk ) ); const auto sz = GetQueue().try_dequeue_bulk( token, item, std::min( left, (int)Bulk ) );
assert( sz > 0 ); assert( sz > 0 );
left -= (int)sz; left -= (int)sz;
} }

View File

@ -40,9 +40,21 @@
namespace tracy namespace tracy
{ {
class GpuCtx;
class Profiler; class Profiler;
class Socket; class Socket;
struct GpuCtxWrapper
{
GpuCtx* ptr;
};
moodycamel::ConcurrentQueue<QueueItem>::ExplicitProducer* GetToken();
Profiler& GetProfiler();
std::atomic<uint32_t>& GetLockCounter();
std::atomic<uint8_t>& GetGpuCtxCounter();
GpuCtxWrapper& GetGpuCtx();
struct SourceLocationData struct SourceLocationData
{ {
const char* name; const char* name;
@ -52,15 +64,6 @@ struct SourceLocationData
uint32_t color; uint32_t color;
}; };
moodycamel::ConcurrentQueue<QueueItem>::ExplicitProducer* GetToken();
Profiler& GetProfiler();
class GpuCtx;
struct GpuCtxWrapper
{
GpuCtx* ptr;
};
#ifdef TRACY_ON_DEMAND #ifdef TRACY_ON_DEMAND
struct LuaZoneState struct LuaZoneState
{ {

View File

@ -44,7 +44,7 @@ struct ThreadNameData
const char* name; const char* name;
ThreadNameData* next; ThreadNameData* next;
}; };
extern std::atomic<ThreadNameData*>& s_threadNameData; std::atomic<ThreadNameData*>& GetThreadNameData();
#endif #endif
void SetThreadName( std::thread& thread, const char* name ) void SetThreadName( std::thread& thread, const char* name )
@ -124,8 +124,8 @@ void SetThreadName( std::thread::native_handle_type handle, const char* name )
data->id = (uint64_t)handle; data->id = (uint64_t)handle;
# endif # endif
data->name = buf; data->name = buf;
data->next = s_threadNameData.load( std::memory_order_relaxed ); data->next = GetThreadNameData().load( std::memory_order_relaxed );
while( !s_threadNameData.compare_exchange_weak( data->next, data, std::memory_order_release, std::memory_order_relaxed ) ) {} while( !GetThreadNameData().compare_exchange_weak( data->next, data, std::memory_order_release, std::memory_order_relaxed ) ) {}
} }
#endif #endif
} }
@ -134,7 +134,7 @@ const char* GetThreadName( uint64_t id )
{ {
static char buf[256]; static char buf[256];
#ifdef TRACY_COLLECT_THREAD_NAMES #ifdef TRACY_COLLECT_THREAD_NAMES
auto ptr = s_threadNameData.load( std::memory_order_relaxed ); auto ptr = GetThreadNameData().load( std::memory_order_relaxed );
while( ptr ) while( ptr )
{ {
if( ptr->id == id ) if( ptr->id == id )