diff --git a/apps/OpenSpace/main.cpp b/apps/OpenSpace/main.cpp index a699d7c3e3..49b47645a9 100644 --- a/apps/OpenSpace/main.cpp +++ b/apps/OpenSpace/main.cpp @@ -228,26 +228,23 @@ std::stringstream& operator<<(std::stringstream& o, const FunctionLogKey& l) { -const FunctionLogKey PRE_SYNC = {'1', '2'}; -const FunctionLogKey ENCODE = {'E', 'e'}; -const FunctionLogKey DECODE = {'D', 'd'}; +const FunctionLogKey PRE_SYNC = { '1', '2' }; +const FunctionLogKey ENCODE = { 'E', 'e' }; +const FunctionLogKey DECODE = { 'D', 'd' }; const FunctionLogKey POST_SYNC = { '3', '4' }; -const FunctionLogKey RENDER = {'R', 'r'}; -const FunctionLogKey POST_DRAW = {'P', 'p'}; +const FunctionLogKey RENDER = { 'R', 'r' }; +const FunctionLogKey POST_DRAW = { 'P', 'p' }; std::stringstream minilog; std::stringstream masterlog; std::stringstream slavelog; const std::string EXPECTED_MASTER_LOG = (masterlog << PRE_SYNC << ENCODE << POST_SYNC << RENDER << POST_DRAW).str(); -const std::string EXPECTED_SLAVE_LOG = (slavelog << PRE_SYNC << DECODE << POST_SYNC << RENDER << POST_DRAW).str(); +const std::string EXPECTED_SLAVE_LOG = (slavelog << PRE_SYNC << DECODE << POST_SYNC << RENDER << POST_DRAW).str(); #define LOG_BEGIN(x) minilog << (x).begin #define LOG_END(x) minilog << (x).end -#define BUSY_WAIT_FOR(x) \ - while (minilog.str().size() && minilog.str().back() != (x)) { \ - std::this_thread::sleep_for(std::chrono::microseconds(10)); \ - }\ + void mainPreSyncFunc() { LOG_BEGIN(PRE_SYNC); @@ -256,9 +253,12 @@ void mainPreSyncFunc() { LOG_END(PRE_SYNC); } +volatile bool busyWaitDecode = false; void mainPostSyncPreDrawFunc() { - if (!sgct::Engine::instance()->isMaster()) { - BUSY_WAIT_FOR(DECODE.end); + if (OsEng.useBusyWaitForDecode() && !sgct::Engine::instance()->isMaster()) { + while (minilog.str().size() && minilog.str().back() != DECODE.end) { + std::this_thread::sleep_for(std::chrono::microseconds(10)); + } } LOG_BEGIN(POST_SYNC); OsEng.postSynchronizationPreDraw(); @@ -270,11 +270,11 @@ void mainRenderFunc() { using glm::mat4; using glm::translate; //not the most efficient, but for clarity @JK - + mat4 userMatrix = translate(mat4(1.f), _sgctEngine->getDefaultUserPtr()->getPos()); mat4 sceneMatrix = _sgctEngine->getModelMatrix(); mat4 viewMatrix = _sgctEngine->getCurrentViewMatrix() * userMatrix; - + //dont shift nav-direction on master, makes it very tricky to navigate @JK if (!OsEng.ref().isMaster()) viewMatrix = viewMatrix * sceneMatrix; @@ -289,17 +289,20 @@ void mainPostDrawFunc() { OsEng.postDraw(); LOG_END(POST_DRAW); - if (sgct::Engine::instance()->isMaster()) { - if (minilog.str() != EXPECTED_MASTER_LOG) { - LERRORC("Minilog", "Bad combination: " << minilog.str()); + if (OsEng.logSGCTOutOfOrderErrors()) { + if (sgct::Engine::instance()->isMaster()) { + if (minilog.str() != EXPECTED_MASTER_LOG) { + LERRORC("Minilog", "Bad combination: " << minilog.str()); + } } - } - else { - if (minilog.str() != EXPECTED_SLAVE_LOG) { - LERRORC("Minilog", "Bad combination: " << minilog.str()); + else { + if (minilog.str() != EXPECTED_SLAVE_LOG) { + LERRORC("Minilog", "Bad combination: " << minilog.str()); + } } } + // clear minilog.str(std::string()); } @@ -315,7 +318,7 @@ void mainKeyboardCallback(int key, int, int action, int mods) { openspace::Key(key), openspace::KeyModifier(mods), openspace::KeyAction(action) - ); + ); } } @@ -324,7 +327,7 @@ void mainMouseButtonCallback(int key, int action) { OsEng.mouseButtonCallback( openspace::MouseButton(key), openspace::MouseAction(action) - ); + ); } } diff --git a/include/openspace/engine/openspaceengine.h b/include/openspace/engine/openspaceengine.h index 3af650bcf7..a82322f8b1 100644 --- a/include/openspace/engine/openspaceengine.h +++ b/include/openspace/engine/openspaceengine.h @@ -115,6 +115,9 @@ public: void disableBarrier(); void toggleShutdownMode(); + + bool useBusyWaitForDecode(); + bool logSGCTOutOfOrderErrors(); void runPostInitializationScripts(const std::string& sceneDescription); diff --git a/include/openspace/engine/settingsengine.h b/include/openspace/engine/settingsengine.h index c305e13148..36f9a1d0c0 100644 --- a/include/openspace/engine/settingsengine.h +++ b/include/openspace/engine/settingsengine.h @@ -43,14 +43,22 @@ public: void setModules(std::vector modules); + bool busyWaitForDecode(); + bool logSGCTOutOfOrderErrors(); + private: void initEyeSeparation(); void initSceneFiles(); void initShowFrameNumber(); + void initBusyWaitForDecode(); + void initLogSGCTOutOfOrderErrors(); properties::FloatProperty _eyeSeparation; properties::OptionProperty _scenes; properties::BoolProperty _showFrameNumber; + properties::BoolProperty _busyWaitForDecode; + properties::BoolProperty _logSGCTOutOfOrderErrors; + }; } // namespace openspace diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 392bc943c0..79a7b5d248 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -770,8 +770,8 @@ void OpenSpaceEngine::preSynchronization() { _interactionHandler->updateInputStates(dt); _renderEngine->updateSceneGraph(); - _renderEngine->camera()->invalidateCache(); _interactionHandler->updateCamera(); + _renderEngine->camera()->invalidateCache(); _parallelConnection->preSynchronization(); } @@ -1001,6 +1001,14 @@ scripting::LuaLibrary OpenSpaceEngine::luaLibrary() { }; } +bool OpenSpaceEngine::useBusyWaitForDecode() { + return _settingsEngine->busyWaitForDecode(); +} + +bool OpenSpaceEngine::logSGCTOutOfOrderErrors() { + return _settingsEngine->logSGCTOutOfOrderErrors(); +} + void OpenSpaceEngine::enableBarrier() { _windowWrapper->setBarrier(true); } diff --git a/src/engine/settingsengine.cpp b/src/engine/settingsengine.cpp index cc2f36be0c..844da6cf48 100644 --- a/src/engine/settingsengine.cpp +++ b/src/engine/settingsengine.cpp @@ -32,13 +32,26 @@ #include #include +#include + +#include + + +namespace { + const std::string _loggerCat = "SettingsEngine"; +} + namespace openspace { + + SettingsEngine::SettingsEngine() : _eyeSeparation("eyeSeparation", "Eye Separation" , 0.f, 0.f, 10.f) , _scenes("scenes", "Scene", properties::OptionProperty::DisplayType::DROPDOWN) , _showFrameNumber("showFrameNumber", "Show frame number", false) + , _busyWaitForDecode("busyWaitForDecode", "Busy Wait for decode", false) + , _logSGCTOutOfOrderErrors("logSGCTOutOfOrderErrors", "Log SGCT out-of-order", false) { setName("Global Properties"); } @@ -47,6 +60,8 @@ void SettingsEngine::initialize() { initEyeSeparation(); initSceneFiles(); initShowFrameNumber(); + initBusyWaitForDecode(); + initLogSGCTOutOfOrderErrors(); } void SettingsEngine::setModules(std::vector modules) { @@ -70,6 +85,30 @@ void SettingsEngine::initShowFrameNumber() { [this]() { OsEng.renderEngine().setShowFrameNumber(_showFrameNumber.value()); } ); } +void SettingsEngine::initBusyWaitForDecode() { + addProperty(_busyWaitForDecode); + _busyWaitForDecode.onChange( + [this]() { + LINFO((_busyWaitForDecode.value() ? "Busy wait for decode" : "Async decode")); + }); +} + +bool SettingsEngine::busyWaitForDecode() { + return _busyWaitForDecode.value(); +} + +void SettingsEngine::initLogSGCTOutOfOrderErrors() { + addProperty(_logSGCTOutOfOrderErrors); + _logSGCTOutOfOrderErrors.onChange( + [this]() { + LINFO("Turn " << (_logSGCTOutOfOrderErrors.value() ? "on" : "off") << " SGCT out of order logging"); + }); +} + +bool SettingsEngine::logSGCTOutOfOrderErrors() { + return _logSGCTOutOfOrderErrors.value(); +} + void SettingsEngine::initSceneFiles() { addProperty(_scenes);