Skip to content

Commit

Permalink
Merge pull request #666 from reinago/mmpld_info_fix
Browse files Browse the repository at this point in the history
update GLStateChecker to support the new view/renderers (_2)
  • Loading branch information
braunms authored Nov 30, 2020
2 parents 88d430d + f3bc443 commit 23169c3
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 23 deletions.
20 changes: 8 additions & 12 deletions core/src/Call.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#ifdef RIG_RENDERCALLS_WITH_DEBUGGROUPS
# include "mmcore/view/Renderer2DModule.h"
# include "mmcore/view/Renderer3DModule.h"
# include "mmcore/view/Renderer3DModule_2.h"
# include "vislib/graphics/gl/IncludeAllGL.h"
#endif
#include "mmcore/utility/log/Log.h"
Expand Down Expand Up @@ -53,26 +54,21 @@ bool Call::operator()(unsigned int func) {
if (this->callee != nullptr) {
#ifdef RIG_RENDERCALLS_WITH_DEBUGGROUPS
auto f = this->callee->GetCallbackFuncName(func);
auto p3 = dynamic_cast<core::view::Renderer3DModule*>(callee->Parent().get());
auto p2 = dynamic_cast<core::view::Renderer2DModule*>(callee->Parent().get());
if (p3) {
std::string output = p3->ClassName();
auto parent = callee->Parent().get();
auto p3 = dynamic_cast<core::view::Renderer3DModule*>(parent);
auto p3_2 = dynamic_cast<core::view::Renderer3DModule_2*>(parent);
auto p2 = dynamic_cast<core::view::Renderer2DModule*>(parent);
if (p3 || p3_2 || p2) {
std::string output = dynamic_cast<core::Module*>(parent)->ClassName();
output += "::";
output += f;
glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 1234, -1, output.c_str());
// megamol::core::utility::log::Log::DefaultLog.WriteInfo("called %s::%s", p3->ClassName(), f);
}
if (p2) {
std::string output = p2->ClassName();
output += "::";
output += f;
glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 1234, -1, output.c_str());
// megamol::core::utility::log::Log::DefaultLog.WriteInfo("called %s::%s", p2->ClassName(), f);
}
#endif
res = this->callee->InCall(this->funcMap[func], *this);
#ifdef RIG_RENDERCALLS_WITH_DEBUGGROUPS
if (p2 || p3) glPopDebugGroup();
if (p2 || p3 || p3_2) glPopDebugGroup();
#endif
}
// megamol::core::utility::log::Log::DefaultLog.WriteInfo("calling %s, idx %i, result %s (%s)", this->ClassName(), func,
Expand Down
6 changes: 4 additions & 2 deletions core/src/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#ifdef RIG_RENDERCALLS_WITH_DEBUGGROUPS
#include "mmcore/view/Renderer2DModule.h"
#include "mmcore/view/Renderer3DModule.h"
#include "mmcore/view/Renderer3DModule_2.h"
#include "vislib/graphics/gl/IncludeAllGL.h"
#endif

Expand Down Expand Up @@ -69,16 +70,17 @@ bool Module::Create(std::vector<megamol::frontend::FrontendResource> resources)
if (!this->created) {
#ifdef RIG_RENDERCALLS_WITH_DEBUGGROUPS
auto p3 = dynamic_cast<core::view::Renderer3DModule*>(this);
auto p3_2 = dynamic_cast<core::view::Renderer3DModule_2*>(this);
auto p2 = dynamic_cast<core::view::Renderer2DModule*>(this);
if (p2 || p3) {
if (p2 || p3 || p3_2) {
std::string output = this->ClassName();
output += "::create";
glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 1234, -1, output.c_str());
}
#endif
this->created = this->create();
#ifdef RIG_RENDERCALLS_WITH_DEBUGGROUPS
if (p2 || p3) glPopDebugGroup();
if (p2 || p3 || p3_2) glPopDebugGroup();
#endif
Log::DefaultLog.WriteMsg(Log::LEVEL_INFO + 350,
"%s module \"%s\"\n", ((this->created) ? "Created"
Expand Down
51 changes: 42 additions & 9 deletions utils/GLStateChecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,34 @@
import tempfile
import os
import re
import string
# pip install jsondiff --user
import jsondiff
import json

apitrace = "T:\\Utilities\\apitrace-msvc\\x64\\bin\\apitrace.exe"
import argparse

parser = argparse.ArgumentParser(description='checks OpenGL states when entering/leaving Render() and during module creation (only Renderer[23]DModule)')
parser.add_argument('args', nargs=argparse.REMAINDER, help='The args you want to pass to MegaMol. Separate from the rest using \'--\' to allow for dashes inside those.')
parser.add_argument('--apitrace', action='store', help='the full path of apitrace.exe', default='T:\\Utilities\\apitrace-msvc\\x64\\bin\\apitrace.exe')
parser.add_argument('--exe', action='store', help='the frontend you want to use (defaults to megamol.exe)', default='megamol.exe')
parser.add_argument('--keeptrace', action='count', help='do not delete the trace file')

parseResult = parser.parse_args()
the_apitrace = parseResult.apitrace
the_exe = parseResult.exe
the_args = parseResult.args
the_keeptrace = parseResult.keeptrace
# the_apitrace = 'C:\\Utilities\\apitrace-msvc\\x64\\bin\\apitrace.exe'
# the_exe = 'mmconsole.exe'
# the_args = ['-p', '..\\examples\\testspheres.lua']
# the_keeptrace = 1

if not os.path.isfile(the_apitrace):
sys.exit("cannot find apitrace executable ({}), please use --apitrace to specify".format(the_apitrace))

if not os.path.isfile(the_exe):
sys.exit("cannot find the executable ({}), please use --exe to specify".format(the_exe))

groupstack = []

Expand All @@ -20,7 +43,7 @@ def safeString(text):
def findDebugGroups(startnum, endnum, mmtracefile):
# dump that frame
#c:\utilities\apitrace-8.0.20190414-win64\bin\apitrace.exe dump mmconsole.trace --calls=23165-23562
args = [apitrace, 'dump', '--calls=' + startnum + '-' + endnum, '--color=never', mmtracefile]
args = [the_apitrace, 'dump', '--calls=' + startnum + '-' + endnum, '--color=never', mmtracefile]
proc = subprocess.run(args, capture_output=True)
res = proc.stdout.decode("utf-8")

Expand All @@ -45,12 +68,12 @@ def findDebugGroups(startnum, endnum, mmtracefile):
else:
# dump both states
# c:\utilities\apitrace-msvc\x64\bin\apitrace.exe replay -D 167273 mmconsole.1.trace > before.json
args = [apitrace, 'replay', '-D', groupstart, mmtracefile]
args = [the_apitrace, 'replay', '-D', groupstart, mmtracefile]
proc = subprocess.run(args, capture_output=True)
text = safeString(proc.stdout.decode("ascii"))
before = json.loads(text)

args = [apitrace, 'replay', '-D', groupend, mmtracefile]
args = [the_apitrace, 'replay', '-D', groupend, mmtracefile]
proc = subprocess.run(args, capture_output=True)
text = safeString(proc.stdout.decode("ascii"))
after = json.loads(text)
Expand Down Expand Up @@ -87,17 +110,24 @@ def findDebugGroups(startnum, endnum, mmtracefile):

mmtracefile = next(tempfile._get_candidate_names()) + ".trace"
args = sys.argv
args[0] = 'mmconsole.exe'
args = [apitrace, "trace", "-o", mmtracefile] + args
args = [the_apitrace, "trace", "-o", mmtracefile, the_exe] + the_args

sep = " "
sepnewline = "\n"
print("running " + sep.join(args))

proc = subprocess.run(args, capture_output=True)
#mmtracefile = "t0zmtikm.trace"

# find frame delimiters
args = [apitrace, 'dump', '--grep=SwapBuffers', '--color=never', mmtracefile]
args = [the_apitrace, 'dump', '--grep=SwapBuffers', '--color=never', mmtracefile]
proc = subprocess.run(args, capture_output=True)
res = proc.stdout.decode("utf-8")
res = proc.stdout.decode("utf-8")
frames = res.split(os.linesep + os.linesep)
the_re = re.compile(r"^\s*//")
the_check = lambda x : not the_re.match(x)
frames = list(filter(the_check, list(filter(None, frames))))
# print("found frame delimiters at commands: " + sepnewline.join(frames))

startf = frames[0]
endf = frames[1]
Expand All @@ -116,4 +146,7 @@ def findDebugGroups(startnum, endnum, mmtracefile):
findDebugGroups(startnum, endnum, mmtracefile)

# cleanup
os.remove(mmtracefile)
if (the_keeptrace > 0):
print("keeping the trace file ({}) around".format(mmtracefile))
else:
os.remove(mmtracefile)
11 changes: 11 additions & 0 deletions utils/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## GLStateChecker.py

This utility automatically checks the GL state when a callback of a Renderer[23]DModule is entered and left. Same applies to Create(). To use it, follow these steps:
1. compile MegaMol after uncommenting `#define RIG_RENDERCALLS_WITH_DEBUGGROUPS` in core\include\mmcore\RigRendering.h
1. have Python 3.7 or newer installed
1. have jsondiff installed `pip install jsondiff --user`
1. install apitrace https://apitrace.github.io/ somewhere
1. go to the MegaMol install/bin directory (where megamol.exe is)
1. run `python <path to this directory>\GLStateChecker.py --apitrace <path to apitrace.exe> --exe <mmconsole.exe or megamol.exe> -- <your usual arguments>`
1. close MegaMol
1. Frames 0 and 1 as well as 1 and 2 will looked at. This involves a lot of apitrace replace for all rigged calls, so please be patient.

0 comments on commit 23169c3

Please sign in to comment.