diff --git a/iagp.cpp b/iagp.cpp index e6af1d3..4516701 100644 --- a/iagp.cpp +++ b/iagp.cpp @@ -1,4 +1,4 @@ -/* +/* MIT License Copyright (c) 2021-2024 Stephane Cuillerdier (aka aiekick) @@ -745,11 +745,19 @@ void InAppGpuGLContext::Collect() { auto ptr = m_QueryIDToZone[id]; if (ptr != nullptr) { if (id == ptr->ids[0]) { +#ifdef __APPLE__ + ptr->SetStartTimeStamp(ptr->m_CPUStartTimeStamp); +#else ptr->SetStartTimeStamp(value64); +#endif } else if (id == ptr->ids[1]) { ptr->last_count = ptr->current_count; ptr->current_count = 0U; - ptr->SetEndTimeStamp(value64); +#ifdef __APPLE__ + ptr->SetEndTimeStamp(ptr->m_CPUEndTimeStamp); +#else + ptr->SetEndTimeStamp(value64); +#endif } else { DEBUG_BREAK; } @@ -1108,6 +1116,10 @@ InAppGpuScopedZone::InAppGpuScopedZone(const bool& vIsRoot, const void* vPtr, co queryPtr = context_ptr->GetQueryZoneForName(vPtr, label, vSection, vIsRoot); if (queryPtr != nullptr) { glQueryCounter(queryPtr->ids[0], GL_TIMESTAMP); +#ifdef __APPLE__ + auto tstamp = std::chrono::high_resolution_clock::now(); + queryPtr->m_CPUStartTimeStamp = std::chrono::duration_cast(tstamp.time_since_epoch()).count(); +#endif #ifdef IAGP_DEBUG_MODE_LOGGING IAGP_DEBUG_MODE_LOGGING("%*s begin : [%u:%u] (depth:%u) (%s)", // queryPtr->depth, "", queryPtr->ids[0], queryPtr->ids[1], queryPtr->depth, label.c_str()); @@ -1132,6 +1144,10 @@ InAppGpuScopedZone::~InAppGpuScopedZone() { } #endif glQueryCounter(queryPtr->ids[1], GL_TIMESTAMP); +#ifdef __APPLE__ + auto tstamp = std::chrono::high_resolution_clock::now(); + queryPtr->m_CPUEndTimeStamp = std::chrono::duration_cast(tstamp.time_since_epoch()).count(); +#endif ++queryPtr->current_count; --sCurrentDepth; } diff --git a/iagp.h b/iagp.h index b3417b8..cf4b71e 100644 --- a/iagp.h +++ b/iagp.h @@ -1,4 +1,4 @@ -/* +/* MIT License Copyright (c) 2021-2024 Stephane Cuillerdier (aka aiekick) @@ -57,6 +57,11 @@ SOFTWARE. #include #include +// OS X can't use GL_ARB_timer_query +#ifdef __APPLE__ +#include +#endif + #ifndef IMGUI_DEFINE_MATH_OPERATORS #define IMGUI_DEFINE_MATH_OPERATORS #endif // IMGUI_DEFINE_MATH_OPERATORS @@ -168,7 +173,10 @@ class IN_APP_GPU_PROFILER_API InAppGpuQueryZone { static IAGPQueryZonePtr create(IAGP_GPU_CONTEXT vContext, const std::string& vName, const std::string& vSectionName, const bool& vIsRoot = false); static circularSettings sCircularSettings; - +#ifdef __APPLE__ + GLuint64 m_CPUStartTimeStamp = 0; + GLuint64 m_CPUEndTimeStamp = 0; +#endif private: IAGPQueryZoneWeak m_This; IAGP_GPU_CONTEXT m_Context;