From 4f9b23db9a94c0546ce1aaed3e5d96e5e8604146 Mon Sep 17 00:00:00 2001 From: Guido Reina Date: Thu, 23 Sep 2021 14:39:58 +0200 Subject: [PATCH] move GPU performance collection to its own service. --- frontend/main/src/main.cpp | 7 ++++ frontend/services/CMakeLists.txt | 2 + .../opengl_glfw/OpenGL_GLFW_Service.cpp | 3 -- .../profiling_service/Profiling_Service.hpp | 39 +++++++++++++++++++ 4 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 frontend/services/profiling_service/Profiling_Service.hpp diff --git a/frontend/main/src/main.cpp b/frontend/main/src/main.cpp index 7ac969f086..e3832bee7b 100644 --- a/frontend/main/src/main.cpp +++ b/frontend/main/src/main.cpp @@ -21,6 +21,7 @@ #include "ProjectLoader_Service.hpp" #include "ImagePresentation_Service.hpp" #include "Remote_Service.hpp" +#include "Profiling_Service.hpp" #include /// XXX see temporary fix below @@ -129,6 +130,9 @@ int main(const int argc, const char** argv) { megamol::frontend::ImagePresentation_Service imagepresentation_service; megamol::frontend::ImagePresentation_Service::Config imagepresentationConfig; +#ifdef PROFILING + megamol::frontend::Profiling_Service profiling_service; +#endif imagepresentation_service.setPriority(3); // before render: do things after GL; post render: do things before GL megamol::frontend::Command_Service command_service; #ifdef MM_CUDA_ENABLED @@ -159,6 +163,9 @@ int main(const int argc, const char** argv) { services.add(projectloader_service, &projectloaderConfig); services.add(imagepresentation_service, &imagepresentationConfig); services.add(command_service, nullptr); +#ifdef PROFILING + services.add(profiling_service, nullptr); +#endif #ifdef MM_CUDA_ENABLED services.add(cuda_service, nullptr); #endif diff --git a/frontend/services/CMakeLists.txt b/frontend/services/CMakeLists.txt index ab13fea32b..7fa97b8fb8 100644 --- a/frontend/services/CMakeLists.txt +++ b/frontend/services/CMakeLists.txt @@ -31,6 +31,7 @@ if(BUILD_FRONTEND_SERVICES) "project_loader/*.hpp" "image_presentation/*.hpp" "remote_service/*.hpp" + "profiling_service/*.hpp" # "service_template/*.hpp" ) file(GLOB_RECURSE gui_header_files RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "gui/*.h" "gui/*.hpp") @@ -65,6 +66,7 @@ if(BUILD_FRONTEND_SERVICES) "project_loader" "image_presentation" "remote_service" + "profiling_service" "gui/src" # "service_template" ) diff --git a/frontend/services/opengl_glfw/OpenGL_GLFW_Service.cpp b/frontend/services/opengl_glfw/OpenGL_GLFW_Service.cpp index 397809f9ec..7869150c72 100644 --- a/frontend/services/opengl_glfw/OpenGL_GLFW_Service.cpp +++ b/frontend/services/opengl_glfw/OpenGL_GLFW_Service.cpp @@ -341,9 +341,6 @@ void megamol::frontend_resources::WindowManipulation::set_swap_interval(const un void megamol::frontend_resources::WindowManipulation::swap_buffers() const { glfwSwapBuffers(reinterpret_cast(window_ptr)); -#ifdef PROFILING - core::CallProfiling::CollectGPUPerformance(); -#endif PROFILING glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_ACCUM_BUFFER_BIT); } diff --git a/frontend/services/profiling_service/Profiling_Service.hpp b/frontend/services/profiling_service/Profiling_Service.hpp new file mode 100644 index 0000000000..ccb5f04eec --- /dev/null +++ b/frontend/services/profiling_service/Profiling_Service.hpp @@ -0,0 +1,39 @@ +/* + * Screenshot_Service.hpp + * + * Copyright (C) 2020 by MegaMol Team + * Alle Rechte vorbehalten. + */ + +#pragma once + +#include "AbstractFrontendService.hpp" +#include "mmcore/CallProfiling.h" + +namespace megamol { +namespace frontend { + +class Profiling_Service final : public AbstractFrontendService { +public: + std::string serviceName() const override { return "Profiling_Service"; } + bool init(void* configPtr) override { return true;} + void close() override {} + void updateProvidedResources() override {} + void digestChangedRequestedResources() override {} + + void resetProvidedResources() override { + core::CallProfiling::CollectGPUPerformance(); + } + + void preGraphRender() override {} + void postGraphRender() override {} + std::vector& getProvidedResources() override { return m_providedResourceReferences; } + const std::vector getRequestedResourceNames() const override { return m_requestedResourcesNames; } + void setRequestedResources(std::vector resources) override {} + + std::vector m_providedResourceReferences; + std::vector m_requestedResourcesNames; +}; + +} // namespace frontend +} // namespace megamol