diff --git a/src/gl/utility/gl_clock.cpp b/src/gl/utility/gl_clock.cpp index 68a2b06e5..2377029c2 100644 --- a/src/gl/utility/gl_clock.cpp +++ b/src/gl/utility/gl_clock.cpp @@ -40,6 +40,8 @@ #include #define USE_WINDOWS_DWORD +#elif defined __APPLE__ +#include #endif #include "i_system.h" @@ -114,6 +116,15 @@ void gl_CalculateCPUSpeed () gl_SecondsPerCycle = 1.0 / CyclesPerSecond; gl_MillisecPerCycle = 1000.0 / CyclesPerSecond; } + #elif defined __APPLE__ + long long frequency; + size_t size = sizeof frequency; + + if (0 == sysctlbyname("machdep.tsc.frequency", &frequency, &size, nullptr, 0) && 0 != frequency) + { + gl_SecondsPerCycle = 1.0 / frequency; + gl_MillisecPerCycle = 1000.0 / frequency; + } #endif } diff --git a/src/gl/utility/gl_clock.h b/src/gl/utility/gl_clock.h index 4d5163d86..2ccda639a 100644 --- a/src/gl/utility/gl_clock.h +++ b/src/gl/utility/gl_clock.h @@ -7,11 +7,11 @@ extern bool gl_benching; -#ifdef _MSC_VER - extern double gl_SecondsPerCycle; extern double gl_MillisecPerCycle; +#ifdef _MSC_VER + __forceinline long long GetClockCycle () { #if _M_X64 @@ -21,10 +21,14 @@ __forceinline long long GetClockCycle () #endif } -#elif defined(__GNUG__) && defined(__i386__) +#elif defined __APPLE__ && (defined __i386__ || defined __x86_64__) -extern double gl_SecondsPerCycle; -extern double gl_MillisecPerCycle; +inline long long GetClockCycle() +{ + return __builtin_ia32_rdtsc(); +} + +#elif defined(__GNUG__) && defined(__i386__) inline long long GetClockCycle() { @@ -42,21 +46,12 @@ inline long long GetClockCycle() #else -extern double gl_SecondsPerCycle; -extern double gl_MillisecPerCycle; - inline long long GetClockCycle () { return 0; } #endif -#if defined (__APPLE__) - -typedef cycle_t glcycle_t; - -#else // !__APPLE__ - class glcycle_t { public: @@ -100,8 +95,6 @@ private: long long Counter; }; -#endif // __APPLE__ - extern glcycle_t RenderWall,SetupWall,ClipWall; extern glcycle_t RenderFlat,SetupFlat; extern glcycle_t RenderSprite,SetupSprite; @@ -122,4 +115,4 @@ void CheckBench(); void checkBenchActive(); -#endif \ No newline at end of file +#endif diff --git a/src/posix/cocoa/i_video.mm b/src/posix/cocoa/i_video.mm index 2ee7458a8..637ca0d7f 100644 --- a/src/posix/cocoa/i_video.mm +++ b/src/posix/cocoa/i_video.mm @@ -534,6 +534,9 @@ CocoaVideo::CocoaVideo() { memset(&m_modeIterator, 0, sizeof m_modeIterator); + extern void gl_CalculateCPUSpeed(); + gl_CalculateCPUSpeed(); + // Create OpenGL pixel format NSOpenGLPixelFormat* pixelFormat = CreatePixelFormat(OpenGLProfile::Core);