Start cleaning TRACY_HW_TIMER checks.

Ideally I think we might want to have TRACY_HW_TIMER mean only TSC/CNTVCT, and define TRACY_TIMER_FALLBACK for platforms that don't have them or have a special case such as iOS.
But for now, keep the same behaviour.
This commit is contained in:
Clément Grégoire
2026-02-09 11:30:24 +01:00
parent b27561c21e
commit 2b2fafbcfc
2 changed files with 17 additions and 7 deletions

View File

@@ -28,8 +28,18 @@
# include <mach/mach_time.h>
#endif
#if !defined TRACY_DISALLOW_HW_TIMER && ( (defined _WIN32 && !(defined _M_ARM64 || defined _M_ARM)) || ( defined __i386 || defined _M_IX86 || defined __x86_64__ || defined _M_X64 ) || ( defined TARGET_OS_IOS && TARGET_OS_IOS == 1 ) || ( defined __APPLE__ && defined __MACH__ && TARGET_CPU_ARM64 ) )
# define TRACY_HW_TIMER
#if ( defined __i386 || defined _M_IX86 || defined __x86_64__ || defined _M_X64 )
# define TRACY_HAS_RDTSC
#elif defined __APPLE__ && defined __MACH__ && TARGET_CPU_ARM64 // For now only supported on Apple devices
# define TRACY_HAS_CNTVCT
#endif
#if !defined TRACY_DISALLOW_HW_TIMER
# if ( defined TRACY_HAS_RDTSC || defined TRACY_HAS_CNTVCT )
# define TRACY_HW_TIMER
# elif defined TARGET_OS_IOS && TARGET_OS_IOS == 1 // For now, !defined(TRACY_HW_TIMER) implies TRACY_TIMER_FALLBACK, so define TRACY_HW_TIMER to use mach_absolute_time() on iOS
# define TRACY_HW_TIMER
# endif
#endif
#ifdef __linux__
@@ -81,7 +91,7 @@ TRACY_API bool ProfilerAvailable();
TRACY_API bool ProfilerAllocatorAvailable();
TRACY_API int64_t GetFrequencyQpc();
#if defined TRACY_TIMER_FALLBACK && defined TRACY_HW_TIMER && ( defined __i386 || defined _M_IX86 || defined __x86_64__ || defined _M_X64 )
#if defined TRACY_TIMER_FALLBACK && defined TRACY_HW_TIMER && defined TRACY_HAS_RDTSC
TRACY_API bool HardwareSupportsInvariantTSC(); // check, if we need fallback scenario
#else
# if defined TRACY_HW_TIMER

View File

@@ -597,7 +597,7 @@ bool SysTraceStart( int64_t& samplingPeriod )
TracyDebug( "drm_vblank_event id: %i", vsyncId );
bool useMonotonicClockRaw = !HardwareSupportsInvariantTSC();
#if !defined TRACY_HW_TIMER || !( defined __i386 || defined _M_IX86 || defined __x86_64__ || defined _M_X64 )
#if !defined TRACY_HW_TIMER || !defined TRACY_HAS_RDTSC
useMonotonicClockRaw = true;
#endif
if( useMonotonicClockRaw )
@@ -1070,7 +1070,7 @@ void SysTraceWorker( void* ptr )
if( cnt > 0 )
{
#if defined TRACY_HW_TIMER && ( defined __i386 || defined _M_IX86 || defined __x86_64__ || defined _M_X64 )
#if defined TRACY_HW_TIMER && defined TRACY_HAS_RDTSC
t0 = ring.ConvertTimeToTsc( t0 );
#endif
auto trace = GetCallstackBlock( cnt, ring, offset );
@@ -1104,7 +1104,7 @@ void SysTraceWorker( void* ptr )
offset += sizeof( uint64_t );
ring.Read( &t0, offset, sizeof( uint64_t ) );
#if defined TRACY_HW_TIMER && ( defined __i386 || defined _M_IX86 || defined __x86_64__ || defined _M_X64 )
#if defined TRACY_HW_TIMER && defined TRACY_HAS_RDTSC
t0 = ring.ConvertTimeToTsc( t0 );
#endif
QueueType type;
@@ -1224,7 +1224,7 @@ void SysTraceWorker( void* ptr )
perf_event_header hdr;
ring.Read( &hdr, offset, sizeof( perf_event_header ) );
#if defined TRACY_HW_TIMER && ( defined __i386 || defined _M_IX86 || defined __x86_64__ || defined _M_X64 )
#if defined TRACY_HW_TIMER && defined TRACY_HAS_RDTSC
t0 = ring.ConvertTimeToTsc( t0 );
#endif