Skip to content

Commit

Permalink
Moved the performance markers around to be clearer
Browse files Browse the repository at this point in the history
see meeting protocol of 2023/12/19
  • Loading branch information
reinago committed Dec 20, 2023
1 parent 231f39d commit 84741cb
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 11 deletions.
19 changes: 19 additions & 0 deletions frontend/main/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,19 @@ int main(const int argc, const char** argv) {
};
services.getProvidedResources().push_back({"FrontendResourcesList", resource_lister});

#ifdef MEGAMOL_USE_PROFILING
megamol::frontend_resources::performance::ProfilingCallbacks profiling_callbacks;
#endif
megamol::frontend_resources::FrameStatsCallbacks frame_stats_callbacks;

const auto render_next_frame = [&]() -> bool {
#ifdef MEGAMOL_USE_TRACY
// I guess this is redundant now
ZoneScopedNC("RenderNextFrame", 0x0000FF);
#endif
#ifdef MEGAMOL_USE_PROFILING
profiling_callbacks.mark_frame_start();
#endif

// services: receive inputs (GLFW poll events [keyboard, mouse, window], network, lua)
services.updateProvidedResources();
Expand Down Expand Up @@ -294,6 +303,10 @@ int main(const int argc, const char** argv) {

services.resetProvidedResources(); // clear buffers holding glfw keyboard+mouse input

frame_stats_callbacks.mark_frame();
#ifdef MEGAMOL_USE_PROFILING
profiling_callbacks.mark_frame_end();
#endif
return true;
};

Expand Down Expand Up @@ -326,6 +339,12 @@ int main(const int argc, const char** argv) {
ret += 2;
}

auto resources_map = megamol::frontend_resources::FrontendResourcesMap(services.getProvidedResources());
#ifdef MEGAMOL_USE_PROFILING
profiling_callbacks = resources_map.get<megamol::frontend_resources::performance::ProfilingCallbacks>();
#endif
frame_stats_callbacks = resources_map.get<megamol::frontend_resources::FrameStatsCallbacks>();

// load project files via lua
if (run_megamol && graph_resources_ok)
for (auto& file : config.project_files) {
Expand Down
7 changes: 7 additions & 0 deletions frontend/resources/include/PerformanceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ struct ProfilingLoggingStatus {
bool active = true;
};

static std::string Profiling_Callbacks_Req_Name = "ProfilingCallbacks";

struct ProfilingCallbacks {
std::function<void()> mark_frame_start;
std::function<void()> mark_frame_end;
};

static std::string PerformanceManager_Req_Name = "PerformanceManager";

// this thing must only exist ONCE.
Expand Down
2 changes: 0 additions & 2 deletions frontend/resources/include/WindowManipulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ struct WindowManipulation {
void set_fullscreen(const Fullscreen action) const GL_VSTUB();

void* window_ptr = nullptr;

FrameStatsCallbacks const* frame_stats_cb_ = nullptr;
};

} // namespace megamol::frontend_resources
1 change: 0 additions & 1 deletion frontend/services/opengl_glfw/OpenGL_GLFW_Service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include "OpenGL_Helper.h"
#include "WindowManipulation.h"
#include "Window_Events.h"
#include "FrameStatsCallbacks.h"

namespace megamol::frontend {

Expand Down
3 changes: 0 additions & 3 deletions frontend/services/opengl_glfw/gl/OpenGL_GLFW_Service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@ void megamol::frontend_resources::WindowManipulation::swap_buffers() const {
TracyGpuCollect;
FrameMark;
#endif
frame_stats_cb_->mark_frame();
}

void megamol::frontend_resources::WindowManipulation::set_fullscreen(const Fullscreen action) const {
Expand Down Expand Up @@ -795,8 +794,6 @@ void OpenGL_GLFW_Service::setRequestedResources(std::vector<FrontendResource> re
auto& megamolgraph_subscription = const_cast<frontend_resources::MegaMolGraph_SubscriptionRegistry&>(
resources[2].getResource<frontend_resources::MegaMolGraph_SubscriptionRegistry>());

m_windowManipulation.frame_stats_cb_ = &resources[3].getResource<frontend_resources::FrameStatsCallbacks>();

#ifdef MEGAMOL_USE_OPENGL_DEBUGGROUPS
frontend_resources::ModuleGraphSubscription debug_helper_subscription("OpenGL Debug Helper");

Expand Down
10 changes: 7 additions & 3 deletions frontend/services/profiling_service/Profiling_Service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ bool Profiling_Service::init(void* configPtr) {
nv::perf::InitializeNvPerf();
#endif
#ifdef MEGAMOL_USE_PROFILING
profiling_callbacks.mark_frame_start = [this] { markFrameStart(); };
profiling_callbacks.mark_frame_end = [this] { markFrameEnd(); };

_providedResourceReferences = {{frontend_resources::performance::PerformanceManager_Req_Name, _perf_man},
{frontend_resources::performance::Performance_Logging_Status_Req_Name, profiling_logging}};
{frontend_resources::performance::Performance_Logging_Status_Req_Name, profiling_logging},
{frontend_resources::performance::Profiling_Callbacks_Req_Name, profiling_callbacks}};

const auto conf = static_cast<Config*>(configPtr);
profiling_logging.active = conf->autostart_profiling;
Expand Down Expand Up @@ -195,7 +199,7 @@ void Profiling_Service::close() {

static const char* const sl_innerframe = "InnerFrame";

void Profiling_Service::updateProvidedResources() {
void Profiling_Service::markFrameStart() {
#ifdef MEGAMOL_USE_TRACY
FrameMarkStart(sl_innerframe);
#endif
Expand All @@ -211,7 +215,7 @@ void Profiling_Service::updateProvidedResources() {
#endif
}

void Profiling_Service::resetProvidedResources() {
void Profiling_Service::markFrameEnd() {
const auto rfc =
_requestedResourcesReferences[4].getResource<frontend_resources::FrameStatistics>().rendered_frames_count;
_perf_man.endFrame(rfc - 1);
Expand Down
9 changes: 7 additions & 2 deletions frontend/services/profiling_service/Profiling_Service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,17 @@ class Profiling_Service final : public AbstractFrontendService {
}
bool init(void* configPtr) override;
void close() override;
void updateProvidedResources() override;
void updateProvidedResources() override {}
void digestChangedRequestedResources() override {}

void resetProvidedResources() override;
void resetProvidedResources() override {}

void preGraphRender() override {}
void postGraphRender() override {}

void markFrameStart();
void markFrameEnd();

std::vector<FrontendResource>& getProvidedResources() override {
return _providedResourceReferences;
}
Expand All @@ -63,6 +67,7 @@ class Profiling_Service final : public AbstractFrontendService {
bool include_graph_events = false;
bool first_frame = true;
frontend_resources::performance::ProfilingLoggingStatus profiling_logging;
frontend_resources::performance::ProfilingCallbacks profiling_callbacks;
#ifdef MEGAMOL_USE_NVPERF
nv::perf::profiler::ReportGeneratorOpenGL nvperf;
#endif
Expand Down

0 comments on commit 84741cb

Please sign in to comment.