From 49c793d97691ec026ebcd0905a5a00ee4ae29af1 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Mon, 10 Feb 2020 14:50:41 +0100 Subject: [PATCH] Update Ghoul version Add initial Tracy profiling macros --- CMakeLists.txt | 32 ---- apps/OpenSpace/main.cpp | 148 +++++++++++++++++- ext/ghoul | 2 +- modules/cefwebgui/cefwebguimodule.cpp | 20 +++ modules/globebrowsing/globebrowsingmodule.cpp | 21 ++- modules/globebrowsing/src/layer.cpp | 3 + modules/globebrowsing/src/layergroup.cpp | 7 + modules/globebrowsing/src/layermanager.cpp | 20 ++- modules/globebrowsing/src/renderableglobe.cpp | 50 +++++- modules/globebrowsing/src/tileprovider.cpp | 68 ++++++++ modules/imgui/imguimodule.cpp | 17 ++ modules/server/servermodule.cpp | 15 +- modules/server/src/connection.cpp | 5 + .../spacecraftinstrumentsmodule.cpp | 3 + modules/webbrowser/src/browserinstance.cpp | 5 + modules/webbrowser/src/cefhost.cpp | 3 + modules/webbrowser/webbrowsermodule.cpp | 13 +- modules/webgui/webguimodule.cpp | 3 + src/engine/globals.cpp | 8 + src/engine/moduleengine.cpp | 11 ++ src/engine/openspaceengine.cpp | 65 +++++++- src/engine/syncengine.cpp | 5 + src/interaction/navigationhandler.cpp | 5 + src/interaction/sessionrecording.cpp | 3 + src/network/parallelpeer.cpp | 3 + src/rendering/abufferrenderer.cpp | 3 + src/rendering/framebufferrenderer.cpp | 42 +++-- src/rendering/helper.cpp | 4 + src/rendering/loadingscreen.cpp | 3 + src/rendering/luaconsole.cpp | 9 ++ src/rendering/renderable.cpp | 3 + src/rendering/renderengine.cpp | 35 +++++ src/rendering/screenspacerenderable.cpp | 3 + src/scene/assetmanager.cpp | 5 + src/scene/scene.cpp | 31 ++-- src/scene/scenegraphnode.cpp | 17 ++ src/scripting/scriptengine.cpp | 35 +++++ src/util/openspacemodule.cpp | 9 ++ src/util/syncbuffer.cpp | 6 + src/util/timemanager.cpp | 3 + 40 files changed, 671 insertions(+), 72 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3e20b7b0ff..10852f0aa9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,7 +43,6 @@ include(${OPENSPACE_CMAKE_EXT_DIR}/handle_modules.cmake) include(${GHOUL_BASE_DIR}/support/cmake/copy_shared_libraries.cmake) include(${GHOUL_BASE_DIR}/support/cmake/handle_external_library.cmake) include(${GHOUL_BASE_DIR}/support/cmake/message_macros.cmake) -include(${GHOUL_BASE_DIR}/support/cmake/include_gtest.cmake) begin_header("Configuring OpenSpace project") message(STATUS "CMake version: ${CMAKE_VERSION}") @@ -208,37 +207,6 @@ if (MSVC) endif () -########################################################################################## -# Tests # -########################################################################################## -option(OPENSPACE_HAVE_TESTS "Activate the OpenSpace unit tests" ON) -if (OPENSPACE_HAVE_TESTS) - include_gtest("${GHOUL_BASE_DIR}/ext/googletest") - - file(GLOB_RECURSE OPENSPACE_TEST_FILES ${OPENSPACE_BASE_DIR}/tests/*.inl) - add_executable(OpenSpaceTest ${OPENSPACE_BASE_DIR}/tests/main.cpp ${OPENSPACE_TEST_FILES}) - - target_include_directories(OpenSpaceTest PUBLIC - "${OPENSPACE_BASE_DIR}/include" - "${OPENSPACE_BASE_DIR}/tests" - "${OPENSPACE_EXT_DIR}/ghoul/ext/googletest/googletest/include" - ) - target_compile_definitions(OpenSpaceTest PUBLIC - "GHL_THROW_ON_ASSERT" "GTEST_HAS_TR1_TUPLE=0" - ) - target_link_libraries(OpenSpaceTest gtest openspace-core) - - set_folder_location(OpenSpaceTest "Unit Tests") - - if (MSVC) - set_target_properties(OpenSpaceTest PROPERTIES LINK_FLAGS - "/NODEFAULTLIB:LIBCMTD.lib /NODEFAULTLIB:LIBCMT.lib" - ) - endif () - set_openspace_compile_settings(OpenSpaceTest) -endif (OPENSPACE_HAVE_TESTS) - - begin_header("Configuring Modules") set(OPENSPACE_EXTERNAL_MODULES_PATHS "" CACHE STRING "List of external modules") handle_modules("${OPENSPACE_BASE_DIR}/modules" "${OPENSPACE_EXTERNAL_MODULES_PATHS}") diff --git a/apps/OpenSpace/main.cpp b/apps/OpenSpace/main.cpp index 712bfa5b8e..2ed8c68fbb 100644 --- a/apps/OpenSpace/main.cpp +++ b/apps/OpenSpace/main.cpp @@ -45,6 +45,8 @@ #include #include #include +#include +#include #ifdef WIN32 #include @@ -249,11 +251,20 @@ std::pair supportedOpenGLVersion() { return { major, minor }; } +// +// Context creation function +// +void mainContextCreationFunc(GLFWwindow* win) { + // @TODO (abock, 2020-02-10) Remove this after updating SGCT to 3.0 + TracyGpuContext +} // // Init function // void mainInitFunc() { + ZoneScoped + #ifdef OPENSPACE_HAS_VTUNE if (EnableDetailedVtune) { __itt_frame_begin_v3(_vTune.init, nullptr); @@ -410,6 +421,12 @@ void mainInitFunc() { void mainPreSyncFunc() { + // @TODO (abock, 2020-02-10) Remove this after merging SGCT version 3.0 + FrameMark + + + ZoneScoped + #ifdef OPENSPACE_HAS_VTUNE if (EnableDetailedVtune) { __itt_frame_begin_v3(_vTune.preSync, nullptr); @@ -423,6 +440,8 @@ void mainPreSyncFunc() { using namespace interaction; for (int i = GLFW_JOYSTICK_1; i <= GLFW_JOYSTICK_LAST; ++i) { + ZoneScopedN("Joystick state"); + JoystickInputState& state = global::joystickInputStates[i]; int present = glfwJoystickPresent(i); @@ -506,6 +525,8 @@ void mainPreSyncFunc() { void mainPostSyncPreDrawFunc() { + ZoneScoped + #ifdef OPENSPACE_HAS_VTUNE if (EnableDetailedVtune) { __itt_frame_begin_v3(_vTune.postSyncPreDraw, nullptr); @@ -540,6 +561,8 @@ void mainPostSyncPreDrawFunc() { void mainRenderFunc() { + ZoneScoped + #ifdef OPENSPACE_HAS_VTUNE if (EnableDetailedVtune) { __itt_frame_begin_v3(_vTune.render, nullptr); @@ -588,6 +611,8 @@ void mainRenderFunc() { void mainDraw2DFunc() { + ZoneScoped + #ifdef OPENSPACE_HAS_VTUNE if (EnableDetailedVtune) { __itt_frame_begin_v3(_vTune.draw2D, nullptr); @@ -618,6 +643,8 @@ void mainDraw2DFunc() { void mainPostDrawFunc() { + ZoneScoped + #ifdef OPENSPACE_HAS_VTUNE if (EnableDetailedVtune) { __itt_frame_begin_v3(_vTune.postDraw, nullptr); @@ -673,6 +700,8 @@ void mainPostDrawFunc() { void mainKeyboardCallback(int key, int, int action, int modifiers) { + ZoneScoped + #ifdef OPENSPACE_HAS_VTUNE if (EnableDetailedVtune) { __itt_frame_begin_v3(_vTune.keyboard, nullptr); @@ -696,6 +725,8 @@ void mainKeyboardCallback(int key, int, int action, int modifiers) { void mainMouseButtonCallback(int key, int action, int modifiers) { + ZoneScoped + #ifdef OPENSPACE_HAS_VTUNE if (EnableDetailedVtune) { __itt_frame_begin_v3(_vTune.mouseButton, nullptr); @@ -719,6 +750,8 @@ void mainMouseButtonCallback(int key, int action, int modifiers) { void mainMousePosCallback(double x, double y) { + ZoneScoped + #ifdef OPENSPACE_HAS_VTUNE if (EnableDetailedVtune) { __itt_frame_begin_v3(_vTune.mousePos, nullptr); @@ -737,6 +770,8 @@ void mainMousePosCallback(double x, double y) { void mainMouseScrollCallback(double posX, double posY) { + ZoneScoped + #ifdef OPENSPACE_HAS_VTUNE if (EnableDetailedVtune) { __itt_frame_begin_v3(_vTune.mouseScroll, nullptr); @@ -757,6 +792,8 @@ void mainMouseScrollCallback(double posX, double posY) { void mainCharCallback(unsigned int codepoint, int modifiers) { + ZoneScoped + #ifdef OPENSPACE_HAS_VTUNE if (EnableDetailedVtune) { __itt_frame_begin_v3(_vTune.character, nullptr); @@ -776,6 +813,8 @@ void mainCharCallback(unsigned int codepoint, int modifiers) { void mainEncodeFun() { + ZoneScoped + #ifdef OPENSPACE_HAS_VTUNE if (EnableDetailedVtune) { __itt_frame_begin_v3(_vTune.encode, nullptr); @@ -798,6 +837,8 @@ void mainEncodeFun() { void mainDecodeFun() { + ZoneScoped + #ifdef OPENSPACE_HAS_VTUNE if (EnableDetailedVtune) { __itt_frame_begin_v3(_vTune.decode, nullptr); @@ -820,6 +861,8 @@ void mainDecodeFun() { void mainLogCallback(const char* msg) { + ZoneScoped + std::string message = msg; if (message.empty() || message == ".") { // We don't want the empty '.' message that SGCT sends while it is waiting for @@ -837,12 +880,18 @@ void setSgctDelegateFunctions() { WindowDelegate& sgctDelegate = global::windowDelegate; sgctDelegate.terminate = []() { sgct::Engine::instance()->terminate(); }; sgctDelegate.setBarrier = [](bool enabled) { + ZoneScoped + sgct::SGCTWindow::setBarrier(enabled); }; sgctDelegate.setSynchronization = [](bool enabled) { + ZoneScoped + sgct_core::ClusterManager::instance()->setUseIgnoreSync(enabled); }; sgctDelegate.clearAllWindows = [](const glm::vec4& clearColor) { + ZoneScoped + size_t n = sgct::Engine::instance()->getNumberOfWindows(); for (size_t i = 0; i < n; ++i) { glClearColor(clearColor.r, clearColor.g, clearColor.b, clearColor.a); @@ -852,27 +901,51 @@ void setSgctDelegateFunctions() { } }; sgctDelegate.windowHasResized = []() { + ZoneScoped + return sgct::Engine::instance()->getCurrentWindowPtr()->isWindowResized(); }; - sgctDelegate.averageDeltaTime = []() { return sgct::Engine::instance()->getAvgDt(); }; + sgctDelegate.averageDeltaTime = []() { + ZoneScoped + + return sgct::Engine::instance()->getAvgDt(); + }; sgctDelegate.deltaTimeStandardDeviation = []() { + ZoneScoped + return sgct::Engine::instance()->getDtStandardDeviation(); }; sgctDelegate.minDeltaTime = []() { + ZoneScoped + return sgct::Engine::instance()->getMinDt(); }; sgctDelegate.maxDeltaTime = []() { + ZoneScoped + return sgct::Engine::instance()->getMaxDt(); }; - sgctDelegate.deltaTime = []() { return sgct::Engine::instance()->getDt(); }; - sgctDelegate.applicationTime = []() { return sgct::Engine::getTime(); }; + sgctDelegate.deltaTime = []() { + ZoneScoped + + return sgct::Engine::instance()->getDt(); + }; + sgctDelegate.applicationTime = []() { + ZoneScoped + + return sgct::Engine::getTime(); + }; sgctDelegate.mousePosition = []() { + ZoneScoped + int id = sgct::Engine::instance()->getCurrentWindowPtr()->getId(); double posX, posY; sgct::Engine::getMousePos(id, &posX, &posY); return glm::vec2(posX, posY); }; sgctDelegate.mouseButtons = [](int maxNumber) { + ZoneScoped + int id = sgct::Engine::instance()->getCurrentWindowPtr()->getId(); uint32_t result = 0; for (int i = 0; i < maxNumber; ++i) { @@ -884,11 +957,15 @@ void setSgctDelegateFunctions() { return result; }; sgctDelegate.currentWindowSize = []() { + ZoneScoped + return glm::ivec2( sgct::Engine::instance()->getCurrentWindowPtr()->getXResolution(), sgct::Engine::instance()->getCurrentWindowPtr()->getYResolution()); }; sgctDelegate.currentSubwindowSize = []() { + ZoneScoped + auto window = sgct::Engine::instance()->getCurrentWindowPtr(); if (sgct::Engine::instance()->getCurrentWindowPtr()->getNumberOfViewports() > 1) { sgct_core::Viewport* viewport = @@ -907,12 +984,16 @@ void setSgctDelegateFunctions() { } }; sgctDelegate.currentWindowResolution = []() { + ZoneScoped + int x, y; auto window = sgct::Engine::instance()->getCurrentWindowPtr(); window->getFinalFBODimensions(x, y); return glm::ivec2(x, y); }; sgctDelegate.currentDrawBufferResolution = []() { + ZoneScoped + sgct_core::Viewport* viewport = sgct::Engine::instance()->getCurrentWindowPtr()->getViewport(0); if (viewport != nullptr) { @@ -936,6 +1017,8 @@ void setSgctDelegateFunctions() { return glm::ivec2(-1, -1); }; sgctDelegate.currentViewportSize = []() { + ZoneScoped + sgct_core::Viewport* viewport = sgct::Engine::instance()->getCurrentWindowPtr()->getViewport(0); if (viewport != nullptr) { @@ -947,15 +1030,21 @@ void setSgctDelegateFunctions() { return glm::ivec2(-1, -1); }; sgctDelegate.dpiScaling = []() { + ZoneScoped + return glm::vec2( sgct::Engine::instance()->getCurrentWindowPtr()->getXScale(), sgct::Engine::instance()->getCurrentWindowPtr()->getYScale() ); }; sgctDelegate.currentNumberOfAaSamples = []() { + ZoneScoped + return sgct::Engine::instance()->getCurrentWindowPtr()->getNumberOfAASamples(); }; sgctDelegate.hasGuiWindow = []() { + ZoneScoped + auto engine = sgct::Engine::instance(); for (size_t i = 0; i < engine->getNumberOfWindows(); ++i) { if (engine->getWindowPtr(i)->checkIfTagExists("GUI")) { @@ -965,28 +1054,48 @@ void setSgctDelegateFunctions() { return false; }; sgctDelegate.isGuiWindow = []() { + ZoneScoped + return sgct::Engine::instance()->getCurrentWindowPtr()->checkIfTagExists("GUI"); }; - sgctDelegate.isMaster = []() { return sgct::Engine::instance()->isMaster(); }; + sgctDelegate.isMaster = []() { + ZoneScoped + + return sgct::Engine::instance()->isMaster(); + }; sgctDelegate.isUsingSwapGroups = []() { + ZoneScoped + return sgct::SGCTWindow::isUsingSwapGroups(); }; sgctDelegate.isSwapGroupMaster = []() { + ZoneScoped + return sgct::SGCTWindow::isSwapGroupMaster(); }; sgctDelegate.viewProjectionMatrix = []() { + ZoneScoped + return sgct::Engine::instance()->getCurrentModelViewProjectionMatrix(); }; sgctDelegate.modelMatrix = []() { + ZoneScoped + return sgct::Engine::instance()->getModelMatrix(); }; sgctDelegate.setNearFarClippingPlane = [](float nearPlane, float farPlane) { + ZoneScoped + sgct::Engine::instance()->setNearAndFarClippingPlanes(nearPlane, farPlane); }; sgctDelegate.setEyeSeparationDistance = [](float distance) { + ZoneScoped + sgct::Engine::instance()->setEyeSeparation(distance); }; sgctDelegate.viewportPixelCoordinates = []() { + ZoneScoped + sgct::SGCTWindow* window = sgct::Engine::instance()->getCurrentWindowPtr(); if (!window || !window->getCurrentViewport()) { return glm::ivec4(0); @@ -997,56 +1106,80 @@ void setSgctDelegateFunctions() { } }; sgctDelegate.isExternalControlConnected = []() { + ZoneScoped + return sgct::Engine::instance()->isExternalControlConnected(); }; sgctDelegate.sendMessageToExternalControl = [](const std::vector& message) { + ZoneScoped + sgct::Engine::instance()->sendMessageToExternalControl( message.data(), static_cast(message.size()) ); }; sgctDelegate.isSimpleRendering = []() { + ZoneScoped + return (sgct::Engine::instance()->getCurrentRenderTarget() != sgct::Engine::NonLinearBuffer); }; sgctDelegate.isFisheyeRendering = []() { + ZoneScoped + sgct::SGCTWindow* w = sgct::Engine::instance()->getCurrentWindowPtr(); return dynamic_cast( w->getViewport(0)->getNonLinearProjectionPtr() ) != nullptr; }; sgctDelegate.takeScreenshot = [](bool applyWarping) { + ZoneScoped + sgct::SGCTSettings::instance()->setCaptureFromBackBuffer(applyWarping); sgct::Engine::instance()->takeScreenshot(); return sgct::Engine::instance()->getScreenShotNumber(); }; sgctDelegate.swapBuffer = []() { + ZoneScoped + GLFWwindow* w = glfwGetCurrentContext(); glfwSwapBuffers(w); glfwPollEvents(); }; sgctDelegate.nWindows = []() { + ZoneScoped + return static_cast(sgct::Engine::instance()->getNumberOfWindows()); }; sgctDelegate.currentWindowId = []() { + ZoneScoped + return sgct::Engine::instance()->getCurrentWindowPtr()->getId(); }; sgctDelegate.openGLProcedureAddress = [](const char* func) { + ZoneScoped + return glfwGetProcAddress(func); }; sgctDelegate.getHorizFieldOfView = []() { + ZoneScoped + return static_cast( sgct::Engine::instance()->getWindowPtr(0)->getHorizFieldOfViewDegrees() ); }; sgctDelegate.setHorizFieldOfView = [](float hFovDeg) { + ZoneScoped + sgct::SGCTWindow* w = sgct::Engine::instance()->getWindowPtr(0); w->setHorizFieldOfView(hFovDeg); }; #ifdef WIN32 sgctDelegate.getNativeWindowHandle = [](size_t windowIndex) -> void* { + ZoneScoped + sgct::SGCTWindow* w = sgct::Engine::instance()->getWindowPtr(windowIndex); - if(w) { + if (w) { HWND hWnd = glfwGetWin32Window(w->getWindowHandle()); return reinterpret_cast(hWnd); } @@ -1054,6 +1187,8 @@ void setSgctDelegateFunctions() { }; #endif // WIN32 sgctDelegate.frustumMode = []() { + ZoneScoped + using FM = sgct_core::Frustum::FrustumMode; switch (sgct::Engine::instance()->getCurrentFrustumMode()) { case FM::MonoEye: return WindowDelegate::Frustum::Mono; @@ -1062,6 +1197,8 @@ void setSgctDelegateFunctions() { } }; sgctDelegate.swapGroupFrameNumber = []() { + ZoneScoped + unsigned int fn = 0; sgct::Engine::instance()->getCurrentWindowPtr()->getSwapGroupFrameNumber(fn); return static_cast(fn); @@ -1247,6 +1384,7 @@ int main(int argc, char** argv) { SgctEngine = new sgct::Engine(arguments); // Bind functions + SgctEngine->setContextCreationCallback(mainContextCreationFunc); SgctEngine->setInitOGLFunction(mainInitFunc); SgctEngine->setPreSyncFunction(mainPreSyncFunc); SgctEngine->setPostSyncPreDrawFunction(mainPostSyncPreDrawFunc); diff --git a/ext/ghoul b/ext/ghoul index 1f4dcc7863..e39e88bf13 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit 1f4dcc78638a6354a88456e87982a3e3b65d8a38 +Subproject commit e39e88bf13b8f44646d266fc15b8d74c19d31222 diff --git a/modules/cefwebgui/cefwebguimodule.cpp b/modules/cefwebgui/cefwebguimodule.cpp index 8a6951f8de..d8039aded9 100644 --- a/modules/cefwebgui/cefwebguimodule.cpp +++ b/modules/cefwebgui/cefwebguimodule.cpp @@ -35,6 +35,7 @@ #include #include #include +#include namespace { constexpr openspace::properties::Property::PropertyInfo EnabledInfo = { @@ -86,6 +87,8 @@ CefWebGuiModule::CefWebGuiModule() } void CefWebGuiModule::startOrStopGui() { + ZoneScoped + WebBrowserModule* webBrowserModule = global::moduleEngine.module(); const bool isGuiWindow = @@ -127,6 +130,8 @@ void CefWebGuiModule::startOrStopGui() { } void CefWebGuiModule::internalInitialize(const ghoul::Dictionary& configuration) { + ZoneScoped + WebBrowserModule* webBrowserModule = global::moduleEngine.module(); @@ -137,28 +142,38 @@ void CefWebGuiModule::internalInitialize(const ghoul::Dictionary& configuration) } _enabled.onChange([this]() { + ZoneScopedN("CefWebGuiModule::enabled") + startOrStopGui(); }); _url.onChange([this]() { + ZoneScopedN("CefWebGuiModule::url") + if (_instance) { _instance->loadUrl(_url); } }); _reload.onChange([this]() { + ZoneScopedN("CefWebGuiModule::reload") + if (_instance) { _instance->reloadBrowser(); } }); _guiScale.onChange([this]() { + ZoneScopedN("CefWebGuiModule::guiScale") + if (_instance) { _instance->setZoom(_guiScale); } }); _visible.onChange([this, webBrowserModule]() { + ZoneScopedN("CefWebGuiModule::visible") + if (_visible && _instance) { webBrowserModule->attachEventHandler(_instance.get()); } else { @@ -176,6 +191,7 @@ void CefWebGuiModule::internalInitialize(const ghoul::Dictionary& configuration) _endpointCallback = webGuiModule->addEndpointChangeCallback( [this](const std::string& endpoint, bool exists) { + ZoneScopedN("CefWebGuiModule::endpointCallback") if (exists && endpoint == "frontend" && _instance) { _instance->reloadBrowser(); } @@ -197,6 +213,8 @@ void CefWebGuiModule::internalInitialize(const ghoul::Dictionary& configuration) }); global::callback::draw2D.emplace_back([this](){ + ZoneScopedN("CefWebGuiModule") + const bool isGuiWindow = global::windowDelegate.hasGuiWindow() ? global::windowDelegate.isGuiWindow() : @@ -218,6 +236,8 @@ void CefWebGuiModule::internalInitialize(const ghoul::Dictionary& configuration) }); global::callback::deinitializeGL.emplace_back([this]() { + ZoneScopedN("CefWebGuiModule") + if (_endpointCallback != -1) { WebGuiModule* webGuiModule = global::moduleEngine.module(); webGuiModule->removeEndpointChangeCallback(_endpointCallback); diff --git a/modules/globebrowsing/globebrowsingmodule.cpp b/modules/globebrowsing/globebrowsingmodule.cpp index df7dd2dbc2..76242030c7 100644 --- a/modules/globebrowsing/globebrowsingmodule.cpp +++ b/modules/globebrowsing/globebrowsingmodule.cpp @@ -43,8 +43,9 @@ #include #include #include -#include #include +#include +#include #include #include @@ -236,6 +237,8 @@ void GlobeBrowsingModule::internalInitialize(const ghoul::Dictionary& dict) { // Initialize global::callback::initializeGL.emplace_back([&]() { + ZoneScopedN("GlobeBrowsingModule") + _tileCache = std::make_unique( _tileCacheSizeMB ); @@ -252,16 +255,24 @@ void GlobeBrowsingModule::internalInitialize(const ghoul::Dictionary& dict) { }); global::callback::deinitializeGL.emplace_back([]() { + ZoneScopedN("GlobeBrowsingModule") + tileprovider::deinitializeDefaultTile(); }); // Render - global::callback::render.emplace_back([&]() { _tileCache->update(); }); + global::callback::render.emplace_back([&]() { + ZoneScopedN("GlobeBrowsingModule") + + _tileCache->update(); + }); // Postdraw #ifdef OPENSPACE_MODULE_GLOBEBROWSING_INSTRUMENTATION global::callback::postDraw.emplace_back([&]() { + ZoneScopedN("GlobeBrowsingModule") + // >= as we might have multiple frames per postDraw call (stereo rendering, // fisheye, etc) const uint16_t next = _frameInfo.lastSavedFrame + _frameInfo.saveEveryNthFrame; @@ -297,7 +308,11 @@ void GlobeBrowsingModule::internalInitialize(const ghoul::Dictionary& dict) { #endif // OPENSPACE_MODULE_GLOBEBROWSING_INSTRUMENTATION // Deinitialize - global::callback::deinitialize.emplace_back([&]() { GdalWrapper::destroy(); }); + global::callback::deinitialize.emplace_back([&]() { + ZoneScopedN("GlobeBrowsingModule") + + GdalWrapper::destroy(); + }); auto fRenderable = FactoryManager::ref().factory(); ghoul_assert(fRenderable, "Renderable factory was not created"); diff --git a/modules/globebrowsing/src/layer.cpp b/modules/globebrowsing/src/layer.cpp index b176825333..24289c209b 100644 --- a/modules/globebrowsing/src/layer.cpp +++ b/modules/globebrowsing/src/layer.cpp @@ -31,6 +31,7 @@ #include #include #include +#include namespace openspace::globebrowsing { @@ -454,6 +455,8 @@ void Layer::onChange(std::function callback) { } int Layer::update() { + ZoneScoped + if (_tileProvider) { return tileprovider::update(*_tileProvider); } diff --git a/modules/globebrowsing/src/layergroup.cpp b/modules/globebrowsing/src/layergroup.cpp index 909eb3dae4..a7f2028766 100644 --- a/modules/globebrowsing/src/layergroup.cpp +++ b/modules/globebrowsing/src/layergroup.cpp @@ -27,6 +27,7 @@ #include #include #include +#include namespace { constexpr const char* _loggerCat = "LayerGroup"; @@ -81,18 +82,24 @@ void LayerGroup::setLayersFromDict(const ghoul::Dictionary& dict) { } void LayerGroup::initialize() { + ZoneScoped + for (const std::unique_ptr& l : _layers) { l->initialize(); } } void LayerGroup::deinitialize() { + ZoneScoped + for (const std::unique_ptr& l : _layers) { l->deinitialize(); } } int LayerGroup::update() { + ZoneScoped + int res = 0; _activeLayers.clear(); diff --git a/modules/globebrowsing/src/layermanager.cpp b/modules/globebrowsing/src/layermanager.cpp index 18b91da259..13bab58ed5 100644 --- a/modules/globebrowsing/src/layermanager.cpp +++ b/modules/globebrowsing/src/layermanager.cpp @@ -31,6 +31,7 @@ #include #include #include +#include namespace openspace::globebrowsing { @@ -53,6 +54,8 @@ documentation::Documentation LayerManager::Documentation() { LayerManager::LayerManager() : properties::PropertyOwner({ "Layers" }) {} void LayerManager::initialize(const ghoul::Dictionary& layerGroupsDict) { + ZoneScoped + // First create empty layer groups in case not all are specified for (size_t i = 0; i < _layerGroups.size(); ++i) { _layerGroups[i] = std::make_unique(layergroupid::GroupID(i)); @@ -91,6 +94,8 @@ void LayerManager::deinitialize() { Layer* LayerManager::addLayer(layergroupid::GroupID groupId, const ghoul::Dictionary& layerDict) { + ZoneScoped + ghoul_assert(groupId != layergroupid::Unknown, "Layer group ID must be known"); try { return _layerGroups[groupId]->addLayer(layerDict); @@ -102,6 +107,8 @@ Layer* LayerManager::addLayer(layergroupid::GroupID groupId, } void LayerManager::deleteLayer(layergroupid::GroupID id, const std::string& layerName) { + ZoneScoped + ghoul_assert(id != layergroupid::Unknown, "Layer group ID must be known"); _layerGroups[id]->deleteLayer(layerName); } @@ -115,6 +122,8 @@ const LayerGroup& LayerManager::layerGroup(layergroupid::GroupID groupId) const } bool LayerManager::hasAnyBlendingLayersEnabled() const { + ZoneScoped + return std::any_of( _layerGroups.begin(), _layerGroups.end(), @@ -124,8 +133,9 @@ bool LayerManager::hasAnyBlendingLayersEnabled() const { ); } -std::array LayerManager::layerGroups() const -{ +std::array LayerManager::layerGroups() const { + ZoneScoped + std::array res = {}; for (int i = 0; i < NumLayerGroups; ++i) { res[i] = _layerGroups[i].get(); @@ -134,6 +144,8 @@ std::array LayerManager::layerGroups( } int LayerManager::update() { + ZoneScoped + int res = 0; for (std::unique_ptr& layerGroup : _layerGroups) { res += layerGroup->update(); @@ -142,6 +154,8 @@ int LayerManager::update() { } void LayerManager::reset(bool includeDisabled) { + ZoneScoped + for (std::unique_ptr& layerGroup : _layerGroups) { for (Layer* layer : layerGroup->layers()) { if (layer->enabled() || includeDisabled) { @@ -152,6 +166,8 @@ void LayerManager::reset(bool includeDisabled) { } void LayerManager::onChange(std::function callback) { + ZoneScoped + for (std::unique_ptr& layerGroup : _layerGroups) { layerGroup->onChange(callback); } diff --git a/modules/globebrowsing/src/renderableglobe.cpp b/modules/globebrowsing/src/renderableglobe.cpp index 9fa87460e5..52f2c6050c 100644 --- a/modules/globebrowsing/src/renderableglobe.cpp +++ b/modules/globebrowsing/src/renderableglobe.cpp @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -968,6 +969,8 @@ void RenderableGlobe::renderChunks(const RenderData& data, RendererTasks&, const ShadowComponent::ShadowMapData& shadowData, bool renderGeomOnly) { + ZoneScoped + if (_shadersNeedRecompilation) { recompileShaders(); } @@ -1165,6 +1168,8 @@ void RenderableGlobe::renderChunks(const RenderData& data, RendererTasks&, auto traversal = [&global, &globalCount, &local, &localCount, cutoff = _debugProperties.modelSpaceRenderingCutoffLevel](const Chunk& node) { + ZoneScopedN("traversal") + std::vector Q; Q.reserve(256); @@ -1269,6 +1274,9 @@ void RenderableGlobe::renderChunkGlobally(const Chunk& chunk, const RenderData& const ShadowComponent::ShadowMapData& shadowData, bool renderGeomOnly) { + ZoneScoped + TracyGpuZone("renderChunkGlobally") + //PerfMeasure("globally"); const TileIndex& tileIndex = chunk.tileIndex; ghoul::opengl::ProgramObject& program = *_globalRenderer.program; @@ -1352,6 +1360,9 @@ void RenderableGlobe::renderChunkLocally(const Chunk& chunk, const RenderData& d const ShadowComponent::ShadowMapData& shadowData, bool renderGeomOnly) { + ZoneScoped + TracyGpuZone("renderChunkLocally") + //PerfMeasure("locally"); const TileIndex& tileIndex = chunk.tileIndex; ghoul::opengl::ProgramObject& program = *_localRenderer.program; @@ -1476,7 +1487,10 @@ void RenderableGlobe::renderChunkLocally(const Chunk& chunk, const RenderData& d } void RenderableGlobe::debugRenderChunk(const Chunk& chunk, const glm::dmat4& mvp, - bool renderBounds, bool renderAABB) const { + bool renderBounds, bool renderAABB) const +{ + ZoneScoped + const std::array& modelSpaceCorners = chunk.corners; std::vector clippingSpaceCorners(8); @@ -1515,8 +1529,10 @@ void RenderableGlobe::debugRenderChunk(const Chunk& chunk, const glm::dmat4& mvp ////////////////////////////////////////////////////////////////////////////////////////// void RenderableGlobe::setCommonUniforms(ghoul::opengl::ProgramObject& programObject, - const Chunk& chunk, const RenderData& data) + const Chunk& chunk, const RenderData& data) { + ZoneScoped + if (_generalProperties.useAccurateNormals && !_layerManager.layerGroup(layergroupid::HeightLayers).activeLayers().empty()) { @@ -1563,6 +1579,8 @@ void RenderableGlobe::setCommonUniforms(ghoul::opengl::ProgramObject& programObj } void RenderableGlobe::recompileShaders() { + ZoneScoped + struct LayerShaderPreprocessingData { struct LayerGroupPreprocessingData { int lastLayerIdx; @@ -1794,6 +1812,8 @@ void RenderableGlobe::recompileShaders() { SurfacePositionHandle RenderableGlobe::calculateSurfacePositionHandle( const glm::dvec3& targetModelSpace) const { + ZoneScoped + glm::dvec3 centerToEllipsoidSurface = _ellipsoid.geodeticSurfaceProjection(targetModelSpace); glm::dvec3 ellipsoidSurfaceToTarget = targetModelSpace - centerToEllipsoidSurface; @@ -1824,6 +1844,8 @@ bool RenderableGlobe::testIfCullable(const Chunk& chunk, const RenderData& renderData, const BoundingHeights& heights) const { + ZoneScoped + return (PreformHorizonCulling && isCullableByHorizon(chunk, renderData, heights)) || (PerformFrustumCulling && isCullableByFrustum(chunk, renderData)); } @@ -1831,6 +1853,8 @@ bool RenderableGlobe::testIfCullable(const Chunk& chunk, int RenderableGlobe::desiredLevel(const Chunk& chunk, const RenderData& renderData, const BoundingHeights& heights) const { + ZoneScoped + const int desiredLevel = _debugProperties.levelByProjectedAreaElseDistance ? desiredLevelByProjectedArea(chunk, renderData, heights) : desiredLevelByDistance(chunk, renderData, heights); @@ -1846,6 +1870,8 @@ int RenderableGlobe::desiredLevel(const Chunk& chunk, const RenderData& renderDa } float RenderableGlobe::getHeight(const glm::dvec3& position) const { + ZoneScoped + float height = 0; // Get the uv coordinates to sample from @@ -1997,6 +2023,8 @@ float RenderableGlobe::getHeight(const glm::dvec3& position) const { void RenderableGlobe::calculateEclipseShadows(ghoul::opengl::ProgramObject& programObject, const RenderData& data, ShadowCompType stype) { + ZoneScoped + constexpr const double KM_TO_M = 1000.0; ghoul_assert( @@ -2137,6 +2165,8 @@ int RenderableGlobe::desiredLevelByDistance(const Chunk& chunk, const RenderData& data, const BoundingHeights& heights) const { + ZoneScoped + // Calculations are done in the reference frame of the globe // (model space). Hence, the camera position needs to be transformed // with the inverse model matrix @@ -2171,6 +2201,8 @@ int RenderableGlobe::desiredLevelByProjectedArea(const Chunk& chunk, const RenderData& data, const BoundingHeights& heights) const { + ZoneScoped + // Calculations are done in the reference frame of the globe // (model space). Hence, the camera position needs to be transformed // with the inverse model matrix @@ -2251,6 +2283,8 @@ int RenderableGlobe::desiredLevelByProjectedArea(const Chunk& chunk, } int RenderableGlobe::desiredLevelByAvailableTileData(const Chunk& chunk) const { + ZoneScoped + const int currLevel = chunk.tileIndex.level; for (size_t i = 0; i < layergroupid::NUM_LAYER_GROUPS; ++i) { @@ -2274,6 +2308,8 @@ int RenderableGlobe::desiredLevelByAvailableTileData(const Chunk& chunk) const { bool RenderableGlobe::isCullableByFrustum(const Chunk& chunk, const RenderData& renderData) const { + ZoneScoped + // Calculate the MVP matrix const glm::dmat4 viewTransform = glm::dmat4(renderData.camera.combinedViewMatrix()); const glm::dmat4 modelViewProjectionTransform = glm::dmat4( @@ -2299,6 +2335,8 @@ bool RenderableGlobe::isCullableByHorizon(const Chunk& chunk, const RenderData& renderData, const BoundingHeights& heights) const { + ZoneScoped + // Calculations are done in the reference frame of the globe. Hence, the camera // position needs to be transformed with the inverse model matrix const GeodeticPatch& patch = chunk.surfacePatch; @@ -2368,6 +2406,8 @@ bool RenderableGlobe::isCullableByHorizon(const Chunk& chunk, ////////////////////////////////////////////////////////////////////////////////////////// void RenderableGlobe::splitChunkNode(Chunk& cn, int depth) { + ZoneScoped + if (depth > 0 && isLeaf(cn)) { std::vector memory = _chunkPool.allocate( static_cast(cn.children.size()) @@ -2396,6 +2436,8 @@ void RenderableGlobe::splitChunkNode(Chunk& cn, int depth) { } void RenderableGlobe::freeChunkNode(Chunk* n) { + ZoneScoped + _chunkPool.free(n); for (Chunk* c : n->children) { if (c) { @@ -2406,6 +2448,8 @@ void RenderableGlobe::freeChunkNode(Chunk* n) { } void RenderableGlobe::mergeChunkNode(Chunk& cn) { + ZoneScoped + for (Chunk* child : cn.children) { if (child) { mergeChunkNode(*child); @@ -2416,6 +2460,8 @@ void RenderableGlobe::mergeChunkNode(Chunk& cn) { } bool RenderableGlobe::updateChunkTree(Chunk& cn, const RenderData& data) { + ZoneScoped + // abock: I tried turning this into a queue and use iteration, rather than recursion // but that made the code harder to understand as the breadth-first traversal // requires parents to be passed through the pipe twice (first to add the diff --git a/modules/globebrowsing/src/tileprovider.cpp b/modules/globebrowsing/src/tileprovider.cpp index ad72426685..6ab3d8b16e 100644 --- a/modules/globebrowsing/src/tileprovider.cpp +++ b/modules/globebrowsing/src/tileprovider.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #include #include "cpl_minixml.h" @@ -152,6 +153,8 @@ namespace temporal { // void initAsyncTileDataReader(DefaultTileProvider& t, TileTextureInitData initData) { + ZoneScoped + t.asyncTextureDataProvider = std::make_unique( t.name, std::make_unique( @@ -163,6 +166,8 @@ void initAsyncTileDataReader(DefaultTileProvider& t, TileTextureInitData initDat } bool initTexturesFromLoadedData(DefaultTileProvider& t) { + ZoneScoped + if (t.asyncTextureDataProvider) { std::optional tile = t.asyncTextureDataProvider->popFinishedRawTile(); if (tile) { @@ -181,6 +186,8 @@ bool initTexturesFromLoadedData(DefaultTileProvider& t) { // void initialize(TextTileProvider& t) { + ZoneScoped + t.font = global::fontManager.font("Mono", static_cast(t.fontSize)); t.fontRenderer = ghoul::fontrendering::FontRenderer::createDefault(); t.fontRenderer->setFramebufferSize(glm::vec2(t.initData.dimensions)); @@ -192,6 +199,9 @@ void deinitialize(TextTileProvider& t) { } Tile tile(TextTileProvider& t, const TileIndex& tileIndex) { + ZoneScoped + TracyGpuZone("tile") + cache::ProviderTileKey key = { tileIndex, t.uniqueIdentifier }; Tile tile = t.tileCache->get(key); if (!tile.texture) { @@ -231,6 +241,8 @@ Tile tile(TextTileProvider& t, const TileIndex& tileIndex) { } void reset(TextTileProvider& t) { + ZoneScoped + t.tileCache->clear(); } @@ -240,6 +252,8 @@ void reset(TextTileProvider& t) { // TileProvider* levelProvider(TileProviderByLevel& t, int level) { + ZoneScoped + if (!t.levelTileProviders.empty()) { int clampedLevel = glm::clamp( level, @@ -296,6 +310,8 @@ std::string timeStringify(TemporalTileProvider::TimeFormatType type, const Time& std::unique_ptr initTileProvider(TemporalTileProvider& t, const TemporalTileProvider::TimeKey& timekey) { + ZoneScoped + static const std::vector IgnoredTokens = { // From: http://www.gdal.org/frmt_wms.html "${x}", @@ -324,6 +340,8 @@ std::unique_ptr initTileProvider(TemporalTileProvider& t, TileProvider* getTileProvider(TemporalTileProvider& t, const TemporalTileProvider::TimeKey& timekey) { + ZoneScoped + const auto it = t.tileProviderMap.find(timekey); if (it != t.tileProviderMap.end()) { return it->second.get(); @@ -339,6 +357,8 @@ TileProvider* getTileProvider(TemporalTileProvider& t, } TileProvider* getTileProvider(TemporalTileProvider& t, const Time& time) { + ZoneScoped + Time tCopy(time); if (t.timeQuantizer.quantize(tCopy, true)) { TemporalTileProvider::TimeKey timeKey = timeStringify(t.timeFormat, tCopy); @@ -354,6 +374,8 @@ TileProvider* getTileProvider(TemporalTileProvider& t, const Time& time) { } void ensureUpdated(TemporalTileProvider& t) { + ZoneScoped + if (!t.currentTileProvider) { update(t); } @@ -374,6 +396,8 @@ std::string xmlValue(TemporalTileProvider& t, CPLXMLNode* node, const std::strin } std::string consumeTemporalMetaData(TemporalTileProvider& t, const std::string& xml) { + ZoneScoped + CPLXMLNode* node = CPLParseXMLString(xml.c_str()); std::string timeStart = xmlValue(t, node, temporal::TimeStart, "2000 Jan 1"); @@ -420,6 +444,8 @@ std::string consumeTemporalMetaData(TemporalTileProvider& t, const std::string& } bool readFilePath(TemporalTileProvider& t) { + ZoneScoped + std::ifstream in(t.filePath.value().c_str()); std::string xml; if (in.is_open()) { @@ -453,6 +479,8 @@ unsigned int TileProvider::NumTileProviders = 0; // General functions // void initializeDefaultTile() { + ZoneScoped + ghoul_assert(!DefaultTile.texture, "Default tile should not have been created"); using namespace ghoul::opengl; @@ -486,6 +514,8 @@ void deinitializeDefaultTile() { std::unique_ptr createFromDictionary(layergroupid::TypeID layerTypeID, const ghoul::Dictionary& dictionary) { + ZoneScoped + const char* type = layergroupid::LAYER_TYPE_NAMES[static_cast(layerTypeID)]; auto factory = FactoryManager::ref().factory(); std::unique_ptr result = factory->create(type, dictionary); @@ -498,6 +528,8 @@ DefaultTileProvider::DefaultTileProvider(const ghoul::Dictionary& dictionary) : filePath(defaultprovider::FilePathInfo, "") , tilePixelSize(defaultprovider::TilePixelSizeInfo, 32, 32, 2048) { + ZoneScoped + type = Type::DefaultTileProvider; tileCache = global::moduleEngine.module()->tileCache(); @@ -559,6 +591,8 @@ DefaultTileProvider::DefaultTileProvider(const ghoul::Dictionary& dictionary) SingleImageProvider::SingleImageProvider(const ghoul::Dictionary& dictionary) : filePath(singleimageprovider::FilePathInfo) { + ZoneScoped + type = Type::SingleImageTileProvider; filePath = dictionary.value(KeyFilePath); @@ -575,6 +609,8 @@ TextTileProvider::TextTileProvider(TileTextureInitData initData, size_t fontSize : initData(std::move(initData)) , fontSize(fontSize) { + ZoneScoped + tileCache = global::moduleEngine.module()->tileCache(); } @@ -585,6 +621,8 @@ TextTileProvider::TextTileProvider(TileTextureInitData initData, size_t fontSize SizeReferenceTileProvider::SizeReferenceTileProvider(const ghoul::Dictionary& dictionary) : TextTileProvider(tileTextureInitData(layergroupid::GroupID::ColorLayers, false)) { + ZoneScoped + type = Type::SizeReferenceTileProvider; font = global::fontManager.font("Mono", static_cast(fontSize)); @@ -601,6 +639,8 @@ SizeReferenceTileProvider::SizeReferenceTileProvider(const ghoul::Dictionary& di TileIndexTileProvider::TileIndexTileProvider(const ghoul::Dictionary&) : TextTileProvider(tileTextureInitData(layergroupid::GroupID::ColorLayers, false)) { + ZoneScoped + type = Type::TileIndexTileProvider; } @@ -609,6 +649,8 @@ TileIndexTileProvider::TileIndexTileProvider(const ghoul::Dictionary&) TileProviderByIndex::TileProviderByIndex(const ghoul::Dictionary& dictionary) { + ZoneScoped + type = Type::ByIndexTileProvider; const ghoul::Dictionary& defaultProviderDict = dictionary.value( @@ -677,6 +719,8 @@ TileProviderByIndex::TileProviderByIndex(const ghoul::Dictionary& dictionary) { TileProviderByLevel::TileProviderByLevel(const ghoul::Dictionary& dictionary) { + ZoneScoped + type = Type::ByLevelTileProvider; layergroupid::GroupID layerGroupID = dictionary.value( @@ -753,6 +797,8 @@ TemporalTileProvider::TemporalTileProvider(const ghoul::Dictionary& dictionary) : initDict(dictionary) , filePath(temporal::FilePathInfo) { + ZoneScoped + type = Type::TemporalTileProvider; filePath = dictionary.value(KeyFilePath); @@ -771,6 +817,8 @@ TemporalTileProvider::TemporalTileProvider(const ghoul::Dictionary& dictionary) bool initialize(TileProvider& tp) { + ZoneScoped + ghoul_assert(!tp.isInitialized, "TileProvider can only be initialized once."); tp.uniqueIdentifier = TileProvider::NumTileProviders++; @@ -821,6 +869,8 @@ bool initialize(TileProvider& tp) { bool deinitialize(TileProvider& tp) { + ZoneScoped + switch (tp.type) { case Type::DefaultTileProvider: break; @@ -860,6 +910,8 @@ bool deinitialize(TileProvider& tp) { Tile tile(TileProvider& tp, const TileIndex& tileIndex) { + ZoneScoped + switch (tp.type) { case Type::DefaultTileProvider: { DefaultTileProvider& t = static_cast(tp); @@ -973,6 +1025,8 @@ Tile tile(TileProvider& tp, const TileIndex& tileIndex) { Tile::Status tileStatus(TileProvider& tp, const TileIndex& index) { + ZoneScoped + switch (tp.type) { case Type::DefaultTileProvider: { DefaultTileProvider& t = static_cast(tp); @@ -1033,6 +1087,8 @@ Tile::Status tileStatus(TileProvider& tp, const TileIndex& index) { TileDepthTransform depthTransform(TileProvider& tp) { + ZoneScoped + switch (tp.type) { case Type::DefaultTileProvider: { DefaultTileProvider& t = static_cast(tp); @@ -1076,6 +1132,8 @@ TileDepthTransform depthTransform(TileProvider& tp) { int update(TileProvider& tp) { + ZoneScoped + switch (tp.type) { case Type::DefaultTileProvider: { DefaultTileProvider& t = static_cast(tp); @@ -1146,6 +1204,8 @@ int update(TileProvider& tp) { void reset(TileProvider& tp) { + ZoneScoped + switch (tp.type) { case Type::DefaultTileProvider: { DefaultTileProvider& t = static_cast(tp); @@ -1232,6 +1292,8 @@ void reset(TileProvider& tp) { int maxLevel(TileProvider& tp) { + ZoneScoped + switch (tp.type) { case Type::DefaultTileProvider: { DefaultTileProvider& t = static_cast(tp); @@ -1277,6 +1339,8 @@ int maxLevel(TileProvider& tp) { float noDataValueAsFloat(TileProvider& tp) { + ZoneScoped + ghoul_assert(tp.isInitialized, "TileProvider was not initialized."); switch (tp.type) { case Type::DefaultTileProvider: { @@ -1307,6 +1371,8 @@ float noDataValueAsFloat(TileProvider& tp) { ChunkTile chunkTile(TileProvider& tp, TileIndex tileIndex, int parents, int maxParents) { + ZoneScoped + ghoul_assert(tp.isInitialized, "TileProvider was not initialized."); auto ascendToParent = [](TileIndex& tileIndex, TileUvTransform& uv) { @@ -1363,6 +1429,8 @@ ChunkTile chunkTile(TileProvider& tp, TileIndex tileIndex, int parents, int maxP ChunkTilePile chunkTilePile(TileProvider& tp, TileIndex tileIndex, int pileSize) { + ZoneScoped + ghoul_assert(tp.isInitialized, "TileProvider was not initialized."); ghoul_assert(pileSize >= 0, "pileSize must be positive"); diff --git a/modules/imgui/imguimodule.cpp b/modules/imgui/imguimodule.cpp index 7ee1293e2d..c6e91fe6e3 100644 --- a/modules/imgui/imguimodule.cpp +++ b/modules/imgui/imguimodule.cpp @@ -37,6 +37,7 @@ #include #include #include +#include namespace openspace { @@ -130,21 +131,29 @@ ImGUIModule::ImGUIModule() : OpenSpaceModule(Name) { }); global::callback::deinitialize.emplace_back([&]() { + ZoneScopedN("ImGUI") + LDEBUGC("ImGui", "Deinitialize GUI"); gui.deinitialize(); }); global::callback::initializeGL.emplace_back([&]() { + ZoneScopedN("ImGUI") + LDEBUGC("ImGui", "Initializing GUI OpenGL"); gui.initializeGL(); }); global::callback::deinitializeGL.emplace_back([&]() { + ZoneScopedN("ImGUI") + LDEBUGC("ImGui", "Deinitialize GUI OpenGL"); gui.deinitializeGL(); }); global::callback::draw2D.emplace_back([&]() { + ZoneScopedN("ImGUI") + // TODO emiax: Make sure this is only called for one of the eyes, in the case // of side-by-side / top-bottom stereo. @@ -182,6 +191,8 @@ ImGUIModule::ImGUIModule() : OpenSpaceModule(Name) { global::callback::keyboard.emplace_back( [&](Key key, KeyModifier mod, KeyAction action) -> bool { + ZoneScopedN("ImGUI") + // A list of all the windows that can show up by themselves if (gui.isEnabled() || gui._performance.isEnabled() || gui._sceneProperty.isEnabled()) @@ -196,6 +207,8 @@ ImGUIModule::ImGUIModule() : OpenSpaceModule(Name) { global::callback::character.emplace_back( [&](unsigned int codepoint, KeyModifier modifier) -> bool { + ZoneScopedN("ImGUI") + // A list of all the windows that can show up by themselves if (gui.isEnabled() || gui._performance.isEnabled() || gui._sceneProperty.isEnabled()) @@ -210,6 +223,8 @@ ImGUIModule::ImGUIModule() : OpenSpaceModule(Name) { global::callback::mouseButton.emplace_back( [&](MouseButton button, MouseAction action, KeyModifier) -> bool { + ZoneScopedN("ImGUI") + // A list of all the windows that can show up by themselves if (gui.isEnabled() || gui._performance.isEnabled() || gui._sceneProperty.isEnabled()) @@ -224,6 +239,8 @@ ImGUIModule::ImGUIModule() : OpenSpaceModule(Name) { global::callback::mouseScrollWheel.emplace_back( [&](double, double posY) -> bool { + ZoneScopedN("ImGUI") + // A list of all the windows that can show up by themselves if (gui.isEnabled() || gui._performance.isEnabled() || gui._sceneProperty.isEnabled()) diff --git a/modules/server/servermodule.cpp b/modules/server/servermodule.cpp index 9ae7399603..2aed0d2f0c 100644 --- a/modules/server/servermodule.cpp +++ b/modules/server/servermodule.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include namespace { @@ -72,7 +73,11 @@ ServerInterface* ServerModule::serverInterfaceByIdentifier(const std::string& id } void ServerModule::internalInitialize(const ghoul::Dictionary& configuration) { - global::callback::preSync.emplace_back([this]() { preSync(); }); + global::callback::preSync.emplace_back([this]() { + ZoneScopedN("ServerModule") + + preSync(); + }); if (!configuration.hasValue(KeyInterfaces)) { return; @@ -156,6 +161,8 @@ void ServerModule::preSync() { } void ServerModule::cleanUpFinishedThreads() { + ZoneScoped + for (ConnectionData& connectionData : _connections) { Connection& connection = *connectionData.connection; if (!connection.socket() || !connection.socket()->isConnected()) { @@ -175,6 +182,8 @@ void ServerModule::cleanUpFinishedThreads() { } void ServerModule::disconnectAll() { + ZoneScoped + for (std::unique_ptr& serverInterface : _interfaces) { if (global::windowDelegate.isMaster()) { serverInterface->deinitialize(); @@ -192,6 +201,8 @@ void ServerModule::disconnectAll() { } void ServerModule::handleConnection(std::shared_ptr connection) { + ZoneScoped + std::string messageString; while (connection->socket()->getMessage(messageString)) { std::lock_guard lock(_messageQueueMutex); @@ -200,6 +211,8 @@ void ServerModule::handleConnection(std::shared_ptr connection) { } void ServerModule::consumeMessages() { + ZoneScoped + std::lock_guard lock(_messageQueueMutex); while (!_messageQueue.empty()) { const Message& m = _messageQueue.front(); diff --git a/modules/server/src/connection.cpp b/modules/server/src/connection.cpp index b40bf007ad..0e43ca59ef 100644 --- a/modules/server/src/connection.cpp +++ b/modules/server/src/connection.cpp @@ -44,6 +44,7 @@ #include #include #include +#include #include namespace { @@ -102,6 +103,8 @@ Connection::Connection(std::unique_ptr s, } void Connection::handleMessage(const std::string& message) { + ZoneScoped + try { nlohmann::json j = nlohmann::json::parse(message.c_str()); try { @@ -138,6 +141,8 @@ void Connection::handleMessage(const std::string& message) { } void Connection::handleJson(const nlohmann::json& json) { + ZoneScoped + auto topicJson = json.find(MessageKeyTopic); auto payloadJson = json.find(MessageKeyPayload); diff --git a/modules/spacecraftinstruments/spacecraftinstrumentsmodule.cpp b/modules/spacecraftinstruments/spacecraftinstrumentsmodule.cpp index 460418b055..bb2e73d1f9 100644 --- a/modules/spacecraftinstruments/spacecraftinstrumentsmodule.cpp +++ b/modules/spacecraftinstruments/spacecraftinstrumentsmodule.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include namespace openspace { @@ -48,6 +49,8 @@ ghoul::opengl::ProgramObjectManager SpacecraftInstrumentsModule::ProgramObjectMa SpacecraftInstrumentsModule::SpacecraftInstrumentsModule() : OpenSpaceModule(Name) {} void SpacecraftInstrumentsModule::internalInitialize(const ghoul::Dictionary&) { + ZoneScoped + ImageSequencer::initialize(); FactoryManager::ref().addFactory( diff --git a/modules/webbrowser/src/browserinstance.cpp b/modules/webbrowser/src/browserinstance.cpp index f641502079..b0d5250d80 100644 --- a/modules/webbrowser/src/browserinstance.cpp +++ b/modules/webbrowser/src/browserinstance.cpp @@ -34,6 +34,7 @@ #include #include #include +#include namespace { constexpr const char* _loggerCat = "CEF BrowserInstance"; @@ -105,11 +106,15 @@ bool BrowserInstance::loadLocalPath(std::string path) { } void BrowserInstance::reshape(const glm::ivec2& windowSize) { + ZoneScoped + _renderHandler->reshape(windowSize.x, windowSize.y); _browser->GetHost()->WasResized(); } void BrowserInstance::draw() { + ZoneScoped + if (_zoomLevel != _browser->GetHost()->GetZoomLevel()) { _browser->GetHost()->SetZoomLevel(_zoomLevel); } diff --git a/modules/webbrowser/src/cefhost.cpp b/modules/webbrowser/src/cefhost.cpp index 77d8db0aae..ddbf34ecdb 100644 --- a/modules/webbrowser/src/cefhost.cpp +++ b/modules/webbrowser/src/cefhost.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -91,6 +92,8 @@ void CefHost::attachDebugSettings(CefSettings &settings) { } void CefHost::doMessageLoopWork() { + ZoneScoped + CefDoMessageLoopWork(); } diff --git a/modules/webbrowser/webbrowsermodule.cpp b/modules/webbrowser/webbrowsermodule.cpp index eb86fe070b..0a053d37bf 100644 --- a/modules/webbrowser/webbrowsermodule.cpp +++ b/modules/webbrowser/webbrowsermodule.cpp @@ -35,6 +35,7 @@ #include #include #include +#include namespace { constexpr const char* _loggerCat = "WebBrowser"; @@ -72,7 +73,11 @@ WebBrowserModule::WebBrowserModule() , _updateBrowserBetweenRenderables(UpdateBrowserBetweenRenderablesInfo, true) , _browserUpdateInterval(BrowserUpdateIntervalInfo, 1.f, 1.0f, 1000.f) { - global::callback::deinitialize.emplace_back([this]() { deinitialize(); }); + global::callback::deinitialize.emplace_back([this]() { + ZoneScopedN("WebBrowserModule") + + deinitialize(); + }); _browserUpdateInterval.onChange([this]() { webbrowser::interval = std::chrono::microseconds( @@ -94,6 +99,8 @@ WebBrowserModule::WebBrowserModule() } void WebBrowserModule::internalDeinitialize() { + ZoneScoped + if (!_enabled) { return; } @@ -118,6 +125,8 @@ std::string WebBrowserModule::findHelperExecutable() { } void WebBrowserModule::internalInitialize(const ghoul::Dictionary& dictionary) { + ZoneScoped + if (dictionary.hasKeyAndValue("WebHelperLocation")) { _webHelperLocation = absPath(dictionary.value("WebHelperLocation")); } else { @@ -162,6 +171,8 @@ void WebBrowserModule::internalInitialize(const ghoul::Dictionary& dictionary) { } void WebBrowserModule::addBrowser(BrowserInstance* browser) { + ZoneScoped + if (_enabled) { _browsers.push_back(browser); if (_updateBrowserBetweenRenderables) { diff --git a/modules/webgui/webguimodule.cpp b/modules/webgui/webguimodule.cpp index 86d86666d3..4a2340fed5 100644 --- a/modules/webgui/webguimodule.cpp +++ b/modules/webgui/webguimodule.cpp @@ -32,6 +32,7 @@ #include #include #include +#include namespace { constexpr const char* _loggerCat = "WebGuiModule"; @@ -225,6 +226,8 @@ void WebGuiModule::notifyEndpointListeners(const std::string& endpoint, bool exi } void WebGuiModule::startProcess() { + ZoneScoped + _endpoints.clear(); ServerModule* serverModule = global::moduleEngine.module(); diff --git a/src/engine/globals.cpp b/src/engine/globals.cpp index 6e0bb08628..de7e45b888 100644 --- a/src/engine/globals.cpp +++ b/src/engine/globals.cpp @@ -54,6 +54,7 @@ #include #include #include +#include #include #include @@ -215,6 +216,8 @@ scripting::ScriptScheduler& gScriptScheduler() { } // namespace detail void initialize() { + ZoneScoped + global::rootPropertyOwner.addPropertySubOwner(global::moduleEngine); global::navigationHandler.setPropertyOwner(&global::rootPropertyOwner); @@ -235,10 +238,13 @@ void initialize() { } void initializeGL() { + ZoneScoped } void deinitialize() { + ZoneScoped + for (std::unique_ptr& ssr : global::screenSpaceRenderables) { ssr->deinitialize(); } @@ -252,6 +258,8 @@ void deinitialize() { } void deinitializeGL() { + ZoneScoped + for (std::unique_ptr& ssr : global::screenSpaceRenderables) { ssr->deinitializeGL(); } diff --git a/src/engine/moduleengine.cpp b/src/engine/moduleengine.cpp index 8ab8bf14d5..4e3beceb7a 100644 --- a/src/engine/moduleengine.cpp +++ b/src/engine/moduleengine.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include "moduleengine_lua.inl" @@ -42,6 +43,8 @@ ModuleEngine::ModuleEngine() : properties::PropertyOwner({ "Modules" }) {} void ModuleEngine::initialize( const std::map& moduleConfigurations) { + ZoneScoped + for (OpenSpaceModule* m : AllModules()) { const std::string& identifier = m->identifier(); auto it = moduleConfigurations.find(identifier); @@ -54,6 +57,8 @@ void ModuleEngine::initialize( } void ModuleEngine::initializeGL() { + ZoneScoped + LDEBUG("Initializing OpenGL of modules"); for (std::unique_ptr& m : _modules) { LDEBUG(fmt::format("Initializing OpenGL of module '{}'", m->identifier())); @@ -63,6 +68,8 @@ void ModuleEngine::initializeGL() { } void ModuleEngine::deinitialize() { + ZoneScoped + LDEBUG("Deinitializing modules"); for (std::unique_ptr& m : _modules) { LDEBUG(fmt::format("Deinitializing module '{}'", m->identifier())); @@ -81,6 +88,8 @@ void ModuleEngine::deinitialize() { } void ModuleEngine::deinitializeGL() { + ZoneScoped + LDEBUG("Deinitializing OpenGL of modules"); for (std::unique_ptr& m : _modules) { LDEBUG(fmt::format("Deinitializing OpenGL of module '{}'", m->identifier())); @@ -93,6 +102,8 @@ void ModuleEngine::deinitializeGL() { void ModuleEngine::registerModule(std::unique_ptr mod, const ghoul::Dictionary& configuration) { + ZoneScoped + ghoul_assert(mod, "Module must not be nullptr"); auto it = std::find_if( diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 9716e99a3c..fc55a8afe9 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -25,7 +25,6 @@ #include #include - #include #include #include @@ -75,6 +74,7 @@ #include #include #include +#include #include #include #include @@ -183,6 +183,8 @@ void OpenSpaceEngine::registerPathTokens() { } void OpenSpaceEngine::initialize() { + ZoneScoped + LTRACE("OpenSpaceEngine::initialize(begin)"); global::initialize(); @@ -377,6 +379,8 @@ void OpenSpaceEngine::initialize() { global::renderEngine.initialize(); for (const std::function& func : global::callback::initialize) { + ZoneScopedN("[Module] initialize") + func(); } @@ -407,6 +411,8 @@ std::string OpenSpaceEngine::generateFilePath(std::string openspaceRelativePath) } void OpenSpaceEngine::initializeGL() { + ZoneScoped + LTRACE("OpenSpaceEngine::initializeGL(begin)"); glbinding::Binding::initialize(global::windowDelegate.openGLProcedureAddress); @@ -668,6 +674,8 @@ void OpenSpaceEngine::initializeGL() { global::moduleEngine.initializeGL(); for (const std::function& func : global::callback::initializeGL) { + ZoneScopedN("[Module] initializeGL") + func(); } @@ -682,6 +690,8 @@ void OpenSpaceEngine::scheduleLoadSingleAsset(std::string assetPath) { } void OpenSpaceEngine::loadSingleAsset(const std::string& assetPath) { + ZoneScoped + LTRACE("OpenSpaceEngine::loadSingleAsset(begin)"); global::windowDelegate.setBarrier(false); @@ -695,6 +705,8 @@ void OpenSpaceEngine::loadSingleAsset(const std::string& assetPath) { return; } if (_scene) { + ZoneScopedN("Reset scene") + global::syncEngine.removeSyncables(global::timeManager.getSyncables()); if (_scene && _scene->camera()) { global::syncEngine.removeSyncables(_scene->camera()->getSyncables()); @@ -754,6 +766,8 @@ void OpenSpaceEngine::loadSingleAsset(const std::string& assetPath) { a->ownSynchronizations(); for (const std::shared_ptr& s : syncs) { + ZoneScopedN("Update resource synchronization") + if (s->state() == ResourceSynchronization::State::Syncing) { LoadingScreen::ProgressInfo progressInfo; progressInfo.progress = s->progress(); @@ -854,6 +868,8 @@ void OpenSpaceEngine::loadSingleAsset(const std::string& assetPath) { } void OpenSpaceEngine::deinitialize() { + ZoneScoped + LTRACE("OpenSpaceEngine::deinitialize(begin)"); for (const std::function& func : global::callback::deinitialize) { @@ -891,6 +907,8 @@ void OpenSpaceEngine::deinitialize() { } void OpenSpaceEngine::deinitializeGL() { + ZoneScoped + LTRACE("OpenSpaceEngine::deinitializeGL(begin)"); // We want to render an image informing the user that we are shutting down @@ -938,6 +956,8 @@ void OpenSpaceEngine::writeStaticDocumentation() { } void OpenSpaceEngine::runGlobalCustomizationScripts() { + ZoneScoped + LINFO("Running Global initialization scripts"); ghoul::lua::LuaState state; global::scriptEngine.initializeLuaState(state); @@ -993,6 +1013,8 @@ void OpenSpaceEngine::loadFonts() { } void OpenSpaceEngine::writeSceneDocumentation() { + ZoneScoped + // Write documentation to json files if config file supplies path for doc files std::string path = global::configuration.documentation.path; @@ -1037,6 +1059,8 @@ void OpenSpaceEngine::writeSceneDocumentation() { } void OpenSpaceEngine::preSynchronization() { + ZoneScoped + LTRACE("OpenSpaceEngine::preSynchronization(begin)"); //std::this_thread::sleep_for(std::chrono::milliseconds(10)); @@ -1065,7 +1089,6 @@ void OpenSpaceEngine::preSynchronization() { global::syncEngine.preSynchronization(SyncEngine::IsMaster(master)); if (master) { - double dt = global::windowDelegate.deltaTime(); if (global::sessionRecording.isSavingFramesDuringPlayback()) { @@ -1100,12 +1123,16 @@ void OpenSpaceEngine::preSynchronization() { } for (const std::function& func : global::callback::preSync) { + ZoneScopedN("[Module] preSync") + func(); } LTRACE("OpenSpaceEngine::preSynchronization(end)"); } void OpenSpaceEngine::postSynchronizationPreDraw() { + ZoneScoped + LTRACE("OpenSpaceEngine::postSynchronizationPreDraw(begin)"); std::unique_ptr perf; @@ -1151,6 +1178,8 @@ void OpenSpaceEngine::postSynchronizationPreDraw() { } for (const std::function& func : global::callback::postSyncPreDraw) { + ZoneScopedN("[Module] postSyncPreDraw") + func(); } @@ -1179,6 +1208,8 @@ void OpenSpaceEngine::postSynchronizationPreDraw() { void OpenSpaceEngine::render(const glm::mat4& sceneMatrix, const glm::mat4& viewMatrix, const glm::mat4& projectionMatrix) { + ZoneScoped + LTRACE("OpenSpaceEngine::render(begin)"); std::unique_ptr perf; @@ -1200,6 +1231,8 @@ void OpenSpaceEngine::render(const glm::mat4& sceneMatrix, const glm::mat4& view global::renderEngine.render(sceneMatrix, viewMatrix, projectionMatrix); for (const std::function& func : global::callback::render) { + ZoneScopedN("[Module] render") + func(); } @@ -1207,6 +1240,8 @@ void OpenSpaceEngine::render(const glm::mat4& sceneMatrix, const glm::mat4& view } void OpenSpaceEngine::drawOverlays() { + ZoneScoped + LTRACE("OpenSpaceEngine::drawOverlays(begin)"); std::unique_ptr perf; @@ -1227,6 +1262,8 @@ void OpenSpaceEngine::drawOverlays() { } for (const std::function& func : global::callback::draw2D) { + ZoneScopedN("[Module] draw2D") + func(); } @@ -1234,6 +1271,8 @@ void OpenSpaceEngine::drawOverlays() { } void OpenSpaceEngine::postDraw() { + ZoneScoped + LTRACE("OpenSpaceEngine::postDraw(begin)"); std::unique_ptr perf; @@ -1246,6 +1285,8 @@ void OpenSpaceEngine::postDraw() { global::renderEngine.postDraw(); for (const std::function& func : global::callback::postDraw) { + ZoneScopedN("[Module] postDraw") + func(); } @@ -1258,6 +1299,8 @@ void OpenSpaceEngine::postDraw() { } void OpenSpaceEngine::keyboardCallback(Key key, KeyModifier mod, KeyAction action) { + ZoneScoped + if (_loadingScreen) { // If the loading screen object exists, we are currently loading and want key // presses to behave differently @@ -1289,6 +1332,8 @@ void OpenSpaceEngine::keyboardCallback(Key key, KeyModifier mod, KeyAction actio } void OpenSpaceEngine::charCallback(unsigned int codepoint, KeyModifier modifier) { + ZoneScoped + using F = std::function; for (const F& func : global::callback::character) { bool isConsumed = func(codepoint, modifier); @@ -1305,6 +1350,8 @@ void OpenSpaceEngine::mouseButtonCallback(MouseButton button, MouseAction action, KeyModifier mods) { + ZoneScoped + using F = std::function; for (const F& func : global::callback::mouseButton) { bool isConsumed = func(button, action, mods); @@ -1338,6 +1385,8 @@ void OpenSpaceEngine::mouseButtonCallback(MouseButton button, } void OpenSpaceEngine::mousePositionCallback(double x, double y) { + ZoneScoped + using F = std::function; for (const F& func : global::callback::mousePosition) { func(x, y); @@ -1348,6 +1397,8 @@ void OpenSpaceEngine::mousePositionCallback(double x, double y) { } void OpenSpaceEngine::mouseScrollWheelCallback(double posX, double posY) { + ZoneScoped + using F = std::function; for (const F& func : global::callback::mouseScrollWheel) { bool isConsumed = func(posX, posY); @@ -1361,6 +1412,8 @@ void OpenSpaceEngine::mouseScrollWheelCallback(double posX, double posY) { } void OpenSpaceEngine::touchDetectionCallback(TouchInput input) { + ZoneScoped + using F = std::function; for (const F& func : global::callback::touchDetected) { bool isConsumed = func(input); @@ -1371,6 +1424,8 @@ void OpenSpaceEngine::touchDetectionCallback(TouchInput input) { } void OpenSpaceEngine::touchUpdateCallback(TouchInput input) { + ZoneScoped + using F = std::function; for (const F& func : global::callback::touchUpdated) { bool isConsumed = func(input); @@ -1381,6 +1436,8 @@ void OpenSpaceEngine::touchUpdateCallback(TouchInput input) { } void OpenSpaceEngine::touchExitCallback(TouchInput input) { + ZoneScoped + using F = std::function; for (const F& func : global::callback::touchExit) { func(input); @@ -1389,11 +1446,15 @@ void OpenSpaceEngine::touchExitCallback(TouchInput input) { std::vector OpenSpaceEngine::encode() { + ZoneScoped + std::vector buffer = global::syncEngine.encodeSyncables(); return buffer; } void OpenSpaceEngine::decode(std::vector data) { + ZoneScoped + global::syncEngine.decodeSyncables(std::move(data)); } diff --git a/src/engine/syncengine.cpp b/src/engine/syncengine.cpp index 65e470ac82..6f3316f3e7 100644 --- a/src/engine/syncengine.cpp +++ b/src/engine/syncengine.cpp @@ -26,6 +26,7 @@ #include #include +#include #include namespace openspace { @@ -58,12 +59,16 @@ void SyncEngine::decodeSyncables(std::vector data) { } void SyncEngine::preSynchronization(IsMaster isMaster) { + ZoneScoped + for (Syncable* syncable : _syncables) { syncable->preSync(isMaster); } } void SyncEngine::postSynchronization(IsMaster isMaster) { + ZoneScoped + for (Syncable* syncable : _syncables) { syncable->postSync(isMaster); } diff --git a/src/interaction/navigationhandler.cpp b/src/interaction/navigationhandler.cpp index c3ac9fb6af..8d160e009a 100644 --- a/src/interaction/navigationhandler.cpp +++ b/src/interaction/navigationhandler.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include #include @@ -151,6 +152,8 @@ NavigationHandler::NavigationHandler() NavigationHandler::~NavigationHandler() {} // NOLINT void NavigationHandler::initialize() { + ZoneScoped + global::parallelPeer.connectionEvent().subscribe( "NavigationHandler", "statusChanged", @@ -162,6 +165,8 @@ void NavigationHandler::initialize() { } void NavigationHandler::deinitialize() { + ZoneScoped + global::parallelPeer.connectionEvent().unsubscribe("NavigationHandler"); } diff --git a/src/interaction/sessionrecording.cpp b/src/interaction/sessionrecording.cpp index c0c7a22674..af618e2589 100644 --- a/src/interaction/sessionrecording.cpp +++ b/src/interaction/sessionrecording.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #include namespace { @@ -587,6 +588,8 @@ void SessionRecording::saveScriptKeyframe(std::string scriptToSave) { } void SessionRecording::preSynchronization() { + ZoneScoped + if (_state == SessionState::Recording) { saveCameraKeyframe(); if (UsingTimeKeyframes) { diff --git a/src/network/parallelpeer.cpp b/src/network/parallelpeer.cpp index 793a80c29c..365d78576e 100644 --- a/src/network/parallelpeer.cpp +++ b/src/network/parallelpeer.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include "parallelpeer_lua.inl" @@ -503,6 +504,8 @@ void ParallelPeer::resetTimeOffset() { } void ParallelPeer::preSynchronization() { + ZoneScoped + std::unique_lock unqlock(_receiveBufferMutex); while (!_receiveBuffer.empty()) { ParallelConnection::Message& message = _receiveBuffer.front(); diff --git a/src/rendering/abufferrenderer.cpp b/src/rendering/abufferrenderer.cpp index e504658408..c697716a79 100644 --- a/src/rendering/abufferrenderer.cpp +++ b/src/rendering/abufferrenderer.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #include #include @@ -544,6 +545,8 @@ void ABufferRenderer::updateMSAASamplingPattern() { } void ABufferRenderer::render(Scene* scene, Camera* camera, float blackoutFactor) { + ZoneScoped + const bool doPerformanceMeasurements = global::performanceManager.isEnabled(); PerfMeasure("ABufferRenderer::render"); diff --git a/src/rendering/framebufferrenderer.cpp b/src/rendering/framebufferrenderer.cpp index 5494a1a2e9..b6cafb200a 100644 --- a/src/rendering/framebufferrenderer.cpp +++ b/src/rendering/framebufferrenderer.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -1039,16 +1040,21 @@ void FramebufferRenderer::updateDownscaledVolume() { } void FramebufferRenderer::render(Scene* scene, Camera* camera, float blackoutFactor) { - // Set OpenGL default rendering state - glGetIntegerv(GL_FRAMEBUFFER_BINDING, &_defaultFBO); - glEnablei(GL_BLEND, 0); - glDisablei(GL_BLEND, 1); - glDisablei(GL_BLEND, 2); - - glClampColor(GL_CLAMP_READ_COLOR, GL_FALSE); + ZoneScoped - glEnable(GL_DEPTH_TEST); + { + // Set OpenGL default rendering state + ZoneScopedN("Setting OpenGL state") + glGetIntegerv(GL_FRAMEBUFFER_BINDING, &_defaultFBO); + glEnablei(GL_BLEND, 0); + glDisablei(GL_BLEND, 1); + glDisablei(GL_BLEND, 2); + + glClampColor(GL_CLAMP_READ_COLOR, GL_FALSE); + + glEnable(GL_DEPTH_TEST); + } _pingPongIndex = 0; // Measurements cache variable @@ -1065,11 +1071,15 @@ void FramebufferRenderer::render(Scene* scene, Camera* camera, float blackoutFac return; } - // deferred g-buffer - glBindFramebuffer(GL_FRAMEBUFFER, _gBuffers.framebuffer); - glDrawBuffers(3, ColorAttachment012Array); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - + { + // deferred g-buffer + ZoneScopedN("Deferred G-Buffer") + TracyGpuZone("Deferred G-Buffer") + + glBindFramebuffer(GL_FRAMEBUFFER, _gBuffers.framebuffer); + glDrawBuffers(3, ColorAttachment012Array); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + } Time time = global::timeManager.time(); RenderData data = { @@ -1148,6 +1158,8 @@ void FramebufferRenderer::render(Scene* scene, Camera* camera, float blackoutFac } void FramebufferRenderer::performRaycasterTasks(const std::vector& tasks) { + ZoneScoped + for (const RaycasterTask& raycasterTask : tasks) { VolumeRaycaster* raycaster = raycasterTask.raycaster; @@ -1268,7 +1280,9 @@ void FramebufferRenderer::performRaycasterTasks(const std::vector void FramebufferRenderer::performDeferredTasks( const std::vector& tasks) -{ +{ + ZoneScoped + for (const DeferredcasterTask& deferredcasterTask : tasks) { Deferredcaster* deferredcaster = deferredcasterTask.deferredcaster; diff --git a/src/rendering/helper.cpp b/src/rendering/helper.cpp index fe4a2e5eb1..06b6f27500 100644 --- a/src/rendering/helper.cpp +++ b/src/rendering/helper.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -133,6 +134,9 @@ VertexObjects& gVertexObjectsConstructor() { } // namespace detail void initialize() { + ZoneScoped + TracyGpuZone("helper::initialize") + ghoul_assert(!isInitialized, "Rendering Helper initialized twice"); // diff --git a/src/rendering/loadingscreen.cpp b/src/rendering/loadingscreen.cpp index 179dfb9e33..dac24742ac 100644 --- a/src/rendering/loadingscreen.cpp +++ b/src/rendering/loadingscreen.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -154,6 +155,8 @@ LoadingScreen::~LoadingScreen() { } void LoadingScreen::render() { + ZoneScoped + if (_phase == Phase::PreStart) { return; } diff --git a/src/rendering/luaconsole.cpp b/src/rendering/luaconsole.cpp index 7b03d8e27d..43542e2a02 100644 --- a/src/rendering/luaconsole.cpp +++ b/src/rendering/luaconsole.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -166,6 +167,8 @@ LuaConsole::LuaConsole() LuaConsole::~LuaConsole() {} // NOLINT void LuaConsole::initialize() { + ZoneScoped + const std::string filename = FileSys.cacheManager()->cachedFilename( HistoryFile, "", @@ -229,6 +232,8 @@ void LuaConsole::initialize() { } void LuaConsole::deinitialize() { + ZoneScoped + const std::string filename = FileSys.cacheManager()->cachedFilename( HistoryFile, "", @@ -589,6 +594,8 @@ void LuaConsole::charCallback(unsigned int codepoint, } void LuaConsole::update() { + ZoneScoped + // Compute the height by simulating _historyFont number of lines and checking // what the bounding box for that text would be. using namespace ghoul::fontrendering; @@ -627,6 +634,8 @@ void LuaConsole::update() { } void LuaConsole::render() { + ZoneScoped + using namespace ghoul::fontrendering; // Don't render the console if it's collapsed. diff --git a/src/rendering/renderable.cpp b/src/rendering/renderable.cpp index 3ec1221272..97c5894be5 100644 --- a/src/rendering/renderable.cpp +++ b/src/rendering/renderable.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include namespace { @@ -117,6 +118,8 @@ Renderable::Renderable(const ghoul::Dictionary& dictionary) , _renderableType(RenderableTypeInfo, "Renderable") , _boundingSphere(BoundingSphereInfo, 0.f, 0.f, 3e10f) { + ZoneScoped + // I can't come up with a good reason not to do this for all renderables registerUpdateRenderBinFromOpacity(); diff --git a/src/rendering/renderengine.cpp b/src/rendering/renderengine.cpp index 46f1332ee8..6e6ba25f5a 100644 --- a/src/rendering/renderengine.cpp +++ b/src/rendering/renderengine.cpp @@ -54,6 +54,7 @@ #include #include #include +#include #include #include #include @@ -408,6 +409,8 @@ void RenderEngine::setRendererFromString(const std::string& renderingMethod) { } void RenderEngine::initialize() { + ZoneScoped + // We have to perform these initializations here as the OsEng has not been initialized // in our constructor _globalRotation = static_cast(global::configuration.globalRotation); @@ -446,6 +449,8 @@ void RenderEngine::initialize() { } void RenderEngine::initializeGL() { + ZoneScoped + LTRACE("RenderEngine::initializeGL(begin)"); std::string renderingMethod = global::configuration.renderingMethod; @@ -495,10 +500,14 @@ void RenderEngine::initializeGL() { } void RenderEngine::deinitializeGL() { + ZoneScoped + _renderer = nullptr; } void RenderEngine::updateScene() { + ZoneScoped + if (!_scene) { return; } @@ -519,6 +528,8 @@ void RenderEngine::updateScene() { } void RenderEngine::updateShaderPrograms() { + ZoneScoped + for (ghoul::opengl::ProgramObject* program : _programs) { try { if (program->isDirty()) { @@ -532,6 +543,8 @@ void RenderEngine::updateShaderPrograms() { } void RenderEngine::updateRenderer() { + ZoneScoped + const bool windowResized = global::windowDelegate.windowHasResized(); if (windowResized) { @@ -549,6 +562,8 @@ void RenderEngine::updateRenderer() { } void RenderEngine::updateScreenSpaceRenderables() { + ZoneScoped + for (std::unique_ptr& ssr : global::screenSpaceRenderables) { ssr->update(); } @@ -608,6 +623,8 @@ uint64_t RenderEngine::frameNumber() const { void RenderEngine::render(const glm::mat4& sceneMatrix, const glm::mat4& viewMatrix, const glm::mat4& projectionMatrix) { + ZoneScoped + LTRACE("RenderEngine::render(begin)"); const WindowDelegate& delegate = global::windowDelegate; @@ -635,6 +652,8 @@ void RenderEngine::render(const glm::mat4& sceneMatrix, const glm::mat4& viewMat } if (_showFrameInformation) { + ZoneScopedN("Show Frame Information") + glm::vec2 penPosition = glm::vec2( fontResolution().x / 2 - 50, fontResolution().y / 3 @@ -662,6 +681,8 @@ void RenderEngine::render(const glm::mat4& sceneMatrix, const glm::mat4& viewMat } if (masterEnabled && !delegate.isGuiWindow() && _globalBlackOutFactor > 0.f) { + ZoneScopedN("Render Screenspace Renderable") + std::vector ssrs; ssrs.reserve(global::screenSpaceRenderables.size()); for (const std::unique_ptr& ssr : @@ -740,6 +761,8 @@ bool RenderEngine::mouseActivationCallback(const glm::dvec2& mousePosition) cons } void RenderEngine::renderOverlays(const ShutdownInformation& shutdownInfo) { + ZoneScoped + const bool isMaster = global::windowDelegate.isMaster(); if (isMaster || _showOverlayOnSlaves) { renderScreenLog(); @@ -786,6 +809,8 @@ void RenderEngine::renderEndscreen() { } void RenderEngine::renderShutdownInformation(float timer, float fullTime) { + ZoneScoped + timer = std::max(timer, 0.f); using BBox = ghoul::fontrendering::FontRenderer::BoundingBoxInformation; @@ -817,6 +842,8 @@ void RenderEngine::renderShutdownInformation(float timer, float fullTime) { } void RenderEngine::renderDashboard() { + ZoneScoped + std::unique_ptr perf; if (global::performanceManager.isEnabled()) { perf = std::make_unique( @@ -849,6 +876,8 @@ void RenderEngine::renderDashboard() { } void RenderEngine::postDraw() { + ZoneScoped + ++_frameNumber; if (global::performanceManager.isEnabled()) { @@ -1222,6 +1251,8 @@ RenderEngine::RendererImplementation RenderEngine::rendererFromString( } void RenderEngine::renderCameraInformation() { + ZoneScoped + if (!_showCameraInfo) { return; } @@ -1296,6 +1327,8 @@ void RenderEngine::renderCameraInformation() { } void RenderEngine::renderVersionInformation() { + ZoneScoped + if (!_showVersionInfo) { return; } @@ -1359,6 +1392,8 @@ void RenderEngine::renderVersionInformation() { } void RenderEngine::renderScreenLog() { + ZoneScoped + if (!_showLog) { return; } diff --git a/src/rendering/screenspacerenderable.cpp b/src/rendering/screenspacerenderable.cpp index 844320cbe4..fdfec03d23 100644 --- a/src/rendering/screenspacerenderable.cpp +++ b/src/rendering/screenspacerenderable.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -488,6 +489,8 @@ bool ScreenSpaceRenderable::deinitializeGL() { } void ScreenSpaceRenderable::render() { + ZoneScoped + draw( globalRotationMatrix() * translationMatrix() * diff --git a/src/scene/assetmanager.cpp b/src/scene/assetmanager.cpp index 1f98f7bcb5..2cf9774691 100644 --- a/src/scene/assetmanager.cpp +++ b/src/scene/assetmanager.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include "assetmanager_lua.inl" @@ -55,6 +56,8 @@ void AssetManager::deinitialize() { } bool AssetManager::update() { + ZoneScoped + // Add assets for (const std::pair& c : _pendingStateChangeCommands) { const std::string& path = c.first; @@ -103,6 +106,8 @@ void AssetManager::remove(const std::string& path) { } void AssetManager::removeAll() { + ZoneScoped + _pendingStateChangeCommands.clear(); std::vector> allAssets = _assetLoader->rootAsset()->requestedAssets(); diff --git a/src/scene/scene.cpp b/src/scene/scene.cpp index 6b8041ccca..6831a79905 100644 --- a/src/scene/scene.cpp +++ b/src/scene/scene.cpp @@ -36,7 +36,7 @@ #include #include #include - +#include #include #include @@ -120,6 +120,8 @@ void Scene::markNodeRegistryDirty() { } void Scene::updateNodeRegistry() { + ZoneScoped + sortTopologically(); _dirtyNodeRegistry = false; } @@ -279,6 +281,8 @@ void Scene::initializeGL() { */ void Scene::update(const UpdateData& data) { + ZoneScoped + std::vector initializedNodes = _initializer->takeInitializedNodes(); for (SceneGraphNode* node : initializedNodes) { @@ -304,6 +308,8 @@ void Scene::update(const UpdateData& data) { } void Scene::render(const RenderData& data, RendererTasks& tasks) { + ZoneScoped + for (SceneGraphNode* node : _topologicallySortedNodes) { try { LTRACE("Scene::render(begin '" + node->identifier() + "')"); @@ -316,15 +322,20 @@ void Scene::render(const RenderData& data, RendererTasks& tasks) { if (global::callback::webBrowserPerformanceHotfix) { (*global::callback::webBrowserPerformanceHotfix)(); } + + { + ZoneScopedN("Get Error Hack") - // @TODO(abock 2019-08-19) This glGetError call is a hack to prevent the GPU - // thread and the CPU thread from diverging too much, particularly the uploading - // of a lot of textures for the globebrowsing planets can cause a hard stuttering - // effect. Asking for a glGetError after every rendering call will force the - // threads to implicitly synchronize and thus prevent the stuttering. The better - // solution would be to reduce the number of uploads per frame, use a staggered - // buffer, or something else like that preventing a large spike in uploads - glGetError(); + // @TODO(abock 2019-08-19) This glGetError call is a hack to prevent the GPU + // thread and the CPU thread from diverging too much, particularly the + // uploading of a lot of textures for the globebrowsing planets can cause a + // hard stuttering effect. Asking for a glGetError after every rendering call + // will force the threads to implicitly synchronize and thus prevent the + // stuttering. The better solution would be to reduce the number of uploads + // per frame, use a staggered buffer, or something else like that preventing a + // large spike in uploads + glGetError(); + } } } @@ -509,6 +520,8 @@ void Scene::removePropertyInterpolation(properties::Property* prop) { } void Scene::updateInterpolations() { + ZoneScoped + using namespace std::chrono; auto now = steady_clock::now(); diff --git a/src/scene/scenegraphnode.cpp b/src/scene/scenegraphnode.cpp index 3f949f5244..f94f5ae4bf 100644 --- a/src/scene/scenegraphnode.cpp +++ b/src/scene/scenegraphnode.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include "scenegraphnode_doc.inl" @@ -311,6 +312,8 @@ SceneGraphNode::SceneGraphNode() SceneGraphNode::~SceneGraphNode() {} // NOLINT void SceneGraphNode::initialize() { + ZoneScoped + LDEBUG(fmt::format("Initializing: {}", identifier())); if (_renderable) { @@ -332,6 +335,8 @@ void SceneGraphNode::initialize() { } void SceneGraphNode::initializeGL() { + ZoneScoped + LDEBUG(fmt::format("Initializing GL: {}", identifier())); if (_renderable) { @@ -343,6 +348,8 @@ void SceneGraphNode::initializeGL() { } void SceneGraphNode::deinitialize() { + ZoneScoped + LDEBUG(fmt::format("Deinitializing: {}", identifier())); setScene(nullptr); @@ -357,6 +364,8 @@ void SceneGraphNode::deinitialize() { } void SceneGraphNode::deinitializeGL() { + ZoneScoped + LDEBUG(fmt::format("Deinitializing GL: {}", identifier())); if (_renderable) { @@ -381,6 +390,9 @@ void SceneGraphNode::traversePostOrder(const std::function_scene) { diff --git a/src/scripting/scriptengine.cpp b/src/scripting/scriptengine.cpp index 8728f0d0a4..7615752564 100644 --- a/src/scripting/scriptengine.cpp +++ b/src/scripting/scriptengine.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include "scriptengine_lua.inl" @@ -55,6 +56,8 @@ ScriptEngine::ScriptEngine() {} void ScriptEngine::initialize() { + ZoneScoped + LDEBUG("Adding base library"); addBaseLibrary(); @@ -63,10 +66,14 @@ void ScriptEngine::initialize() { } void ScriptEngine::deinitialize() { + ZoneScoped + _registeredLibraries.clear(); } void ScriptEngine::initializeLuaState(lua_State* state) { + ZoneScoped + LDEBUG("Create openspace base library"); const int top = lua_gettop(state); @@ -86,6 +93,8 @@ ghoul::lua::LuaState* ScriptEngine::luaState() { } void ScriptEngine::addLibrary(LuaLibrary library) { + ZoneScoped + auto sortFunc = [](const LuaLibrary::Function& lhs, const LuaLibrary::Function& rhs) { return lhs.name < rhs.name; @@ -154,6 +163,8 @@ bool ScriptEngine::hasLibrary(const std::string& name) { } bool ScriptEngine::runScript(const std::string& script, ScriptCallback callback) { + ZoneScoped + if (script.empty()) { LWARNING("Script was empty"); return false; @@ -190,6 +201,8 @@ bool ScriptEngine::runScript(const std::string& script, ScriptCallback callback) } bool ScriptEngine::runScriptFile(const std::string& filename) { + ZoneScoped + if (filename.empty()) { LWARNING("Filename was empty"); return false; @@ -270,6 +283,8 @@ bool ScriptEngine::isLibraryNameAllowed(lua_State* state, const std::string& nam void ScriptEngine::addLibraryFunctions(lua_State* state, LuaLibrary& library, Replace replace) { + ZoneScoped + ghoul_assert(state, "State must not be nullptr"); for (const LuaLibrary::Function& p : library.functions) { if (!replace) { @@ -330,6 +345,8 @@ void ScriptEngine::addLibraryFunctions(lua_State* state, LuaLibrary& library, } void ScriptEngine::addBaseLibrary() { + ZoneScoped + LuaLibrary lib = { "", { @@ -489,6 +506,8 @@ void ScriptEngine::remapPrintFunction() { } bool ScriptEngine::registerLuaLibrary(lua_State* state, LuaLibrary& library) { + ZoneScoped + ghoul_assert(state, "State must not be nullptr"); const int top = lua_gettop(state); @@ -528,6 +547,8 @@ bool ScriptEngine::registerLuaLibrary(lua_State* state, LuaLibrary& library) { } std::vector ScriptEngine::allLuaFunctions() const { + ZoneScoped + std::vector result; for (const LuaLibrary& library : _registeredLibraries) { @@ -554,6 +575,8 @@ std::vector ScriptEngine::allLuaFunctions() const { } std::string ScriptEngine::generateJson() const { + ZoneScoped + // Create JSON std::stringstream json; json << "["; @@ -603,6 +626,8 @@ std::string ScriptEngine::generateJson() const { } bool ScriptEngine::writeLog(const std::string& script) { + ZoneScoped + // Check that logging is enabled and initialize if necessary if (!_logFileExists) { // If a ScriptLogFile was specified, generate it now @@ -644,6 +669,8 @@ bool ScriptEngine::writeLog(const std::string& script) { } void ScriptEngine::preSync(bool isMaster) { + ZoneScoped + if (!isMaster) { return; } @@ -669,6 +696,8 @@ void ScriptEngine::preSync(bool isMaster) { } void ScriptEngine::encode(SyncBuffer* syncBuffer) { + ZoneScoped + size_t nScripts = _scriptsToSync.size(); syncBuffer->encode(nScripts); for (const std::string& s : _scriptsToSync) { @@ -678,6 +707,8 @@ void ScriptEngine::encode(SyncBuffer* syncBuffer) { } void ScriptEngine::decode(SyncBuffer* syncBuffer) { + ZoneScoped + std::lock_guard guard(_slaveScriptsMutex); size_t nScripts; syncBuffer->decode(nScripts); @@ -690,6 +721,8 @@ void ScriptEngine::decode(SyncBuffer* syncBuffer) { } void ScriptEngine::postSync(bool isMaster) { + ZoneScoped + if (isMaster) { while (!_masterScriptQueue.empty()) { std::string script = std::move(_masterScriptQueue.front().script); @@ -721,6 +754,8 @@ void ScriptEngine::queueScript(const std::string& script, ScriptEngine::RemoteScripting remoteScripting, ScriptCallback callback) { + ZoneScoped + if (!script.empty()) { _incomingScripts.push({ script, remoteScripting, callback }); } diff --git a/src/util/openspacemodule.cpp b/src/util/openspacemodule.cpp index 9d1fba9a37..852f76a3dd 100644 --- a/src/util/openspacemodule.cpp +++ b/src/util/openspacemodule.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -49,6 +50,8 @@ OpenSpaceModule::OpenSpaceModule(std::string name) void OpenSpaceModule::initialize(const ModuleEngine* moduleEngine, const ghoul::Dictionary& configuration) { + ZoneScoped + std::string upperIdentifier = identifier(); std::transform( upperIdentifier.begin(), @@ -72,14 +75,20 @@ void OpenSpaceModule::initialize(const ModuleEngine* moduleEngine, } void OpenSpaceModule::initializeGL() { + ZoneScoped + internalInitializeGL(); } void OpenSpaceModule::deinitialize() { + ZoneScoped + internalDeinitialize(); } void OpenSpaceModule::deinitializeGL() { + ZoneScoped + internalDeinitializeGL(); } diff --git a/src/util/syncbuffer.cpp b/src/util/syncbuffer.cpp index b74446c3d0..ba57b911b7 100644 --- a/src/util/syncbuffer.cpp +++ b/src/util/syncbuffer.cpp @@ -24,6 +24,8 @@ #include +#include + namespace openspace { SyncBuffer::SyncBuffer(size_t n) @@ -35,6 +37,8 @@ SyncBuffer::SyncBuffer(size_t n) SyncBuffer::~SyncBuffer() {} // NOLINT void SyncBuffer::encode(const std::string& s) { + ZoneScoped + int32_t anticpatedBufferSize = _encodeOffset + (sizeof(char) * s.size()) + sizeof(int32_t); if (anticpatedBufferSize >= _n) { @@ -53,6 +57,8 @@ void SyncBuffer::encode(const std::string& s) { } std::string SyncBuffer::decode() { + ZoneScoped + int32_t length; memcpy( reinterpret_cast(&length), diff --git a/src/util/timemanager.cpp b/src/util/timemanager.cpp index d8e920d2a7..09e0cde509 100644 --- a/src/util/timemanager.cpp +++ b/src/util/timemanager.cpp @@ -29,6 +29,7 @@ #include #include #include +#include namespace { // Properties for time interpolation @@ -129,6 +130,8 @@ void TimeManager::interpolateTimeRelative(double delta, double durationSeconds) } void TimeManager::preSynchronization(double dt) { + ZoneScoped + removeKeyframesBefore(_latestConsumedTimestamp); progressTime(dt);