Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apple MacOS X uses CPU timers #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions iagp.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
MIT License

Copyright (c) 2021-2024 Stephane Cuillerdier (aka aiekick)
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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<std::chrono::nanoseconds>(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());
Expand All @@ -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<std::chrono::nanoseconds>(tstamp.time_since_epoch()).count();
#endif
++queryPtr->current_count;
--sCurrentDepth;
}
Expand Down
12 changes: 10 additions & 2 deletions iagp.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
MIT License

Copyright (c) 2021-2024 Stephane Cuillerdier (aka aiekick)
Expand Down Expand Up @@ -57,6 +57,11 @@ SOFTWARE.
#include <functional>
#include <unordered_map>

// OS X can't use GL_ARB_timer_query
#ifdef __APPLE__
#include <chrono>
#endif

#ifndef IMGUI_DEFINE_MATH_OPERATORS
#define IMGUI_DEFINE_MATH_OPERATORS
#endif // IMGUI_DEFINE_MATH_OPERATORS
Expand Down Expand Up @@ -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;
Expand Down