From 63d6f888e61f8cd05a70baaf3b1ec299ea410196 Mon Sep 17 00:00:00 2001 From: Anthony Thibault Date: Mon, 21 Mar 2016 17:31:13 -0700 Subject: [PATCH 01/12] Update openvr sdk to 0.9.19 --- cmake/externals/openvr/CMakeLists.txt | 4 ++-- plugins/openvr/src/OpenVrHelpers.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cmake/externals/openvr/CMakeLists.txt b/cmake/externals/openvr/CMakeLists.txt index 3fe7df44d0..930a339d12 100644 --- a/cmake/externals/openvr/CMakeLists.txt +++ b/cmake/externals/openvr/CMakeLists.txt @@ -7,8 +7,8 @@ string(TOUPPER ${EXTERNAL_NAME} EXTERNAL_NAME_UPPER) ExternalProject_Add( ${EXTERNAL_NAME} - URL https://github.com/ValveSoftware/openvr/archive/v0.9.15.zip - URL_MD5 0ff8560b49b6da1150fcc47360e8ceca + URL https://github.com/ValveSoftware/openvr/archive/v0.9.19.zip + URL_MD5 843f9dde488584d8af1f3ecf2252b4e0 CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND "" diff --git a/plugins/openvr/src/OpenVrHelpers.cpp b/plugins/openvr/src/OpenVrHelpers.cpp index d2c3649933..8ddf028dd2 100644 --- a/plugins/openvr/src/OpenVrHelpers.cpp +++ b/plugins/openvr/src/OpenVrHelpers.cpp @@ -51,7 +51,7 @@ vr::IVRSystem* acquireOpenVrSystem() { if (!activeHmd) { qCDebug(displayplugins) << "openvr: No vr::IVRSystem instance active, building"; vr::EVRInitError eError = vr::VRInitError_None; - activeHmd = vr::VR_Init(&eError); + activeHmd = vr::VR_Init(&eError, vr::VRApplication_Scene); qCDebug(displayplugins) << "openvr display: HMD is " << activeHmd << " error is " << eError; } if (activeHmd) { From 0d046b12de6ce57bc006921cfd5df6059443eca0 Mon Sep 17 00:00:00 2001 From: Anthony Thibault Date: Mon, 21 Mar 2016 17:39:10 -0700 Subject: [PATCH 02/12] OpenVR: Moved WaitGetPoses after main window preview. --- .../src/display-plugins/hmd/HmdDisplayPlugin.cpp | 2 ++ .../display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.h | 1 + plugins/openvr/src/OpenVrDisplayPlugin.cpp | 2 ++ plugins/openvr/src/OpenVrDisplayPlugin.h | 1 + 4 files changed, 6 insertions(+) diff --git a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp index c3782b907f..340804de04 100644 --- a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp @@ -149,6 +149,8 @@ void HmdDisplayPlugin::internalPresent() { }); swapBuffers(); } + + postPreview(); } void HmdDisplayPlugin::setEyeRenderPose(uint32_t frameIndex, Eye eye, const glm::mat4& pose) { diff --git a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.h b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.h index 659a3a16fa..fede16c3a5 100644 --- a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.h +++ b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.h @@ -31,6 +31,7 @@ public: protected: virtual void hmdPresent() = 0; virtual bool isHmdMounted() const = 0; + virtual void postPreview() {}; void internalActivate() override; void compositeOverlay() override; diff --git a/plugins/openvr/src/OpenVrDisplayPlugin.cpp b/plugins/openvr/src/OpenVrDisplayPlugin.cpp index 843b70807d..adad0648e8 100644 --- a/plugins/openvr/src/OpenVrDisplayPlugin.cpp +++ b/plugins/openvr/src/OpenVrDisplayPlugin.cpp @@ -152,7 +152,9 @@ void OpenVrDisplayPlugin::hmdPresent() { _compositor->Submit(vr::Eye_Left, &texture, &leftBounds); _compositor->Submit(vr::Eye_Right, &texture, &rightBounds); +} +void OpenVrDisplayPlugin::postPreview() { vr::TrackedDevicePose_t currentTrackedDevicePose[vr::k_unMaxTrackedDeviceCount]; _compositor->WaitGetPoses(currentTrackedDevicePose, vr::k_unMaxTrackedDeviceCount, nullptr, 0); _hmdActivityLevel = _system->GetTrackedDeviceActivityLevel(vr::k_unTrackedDeviceIndex_Hmd); diff --git a/plugins/openvr/src/OpenVrDisplayPlugin.h b/plugins/openvr/src/OpenVrDisplayPlugin.h index caaf75a4d0..78b76cb78d 100644 --- a/plugins/openvr/src/OpenVrDisplayPlugin.h +++ b/plugins/openvr/src/OpenVrDisplayPlugin.h @@ -35,6 +35,7 @@ protected: void hmdPresent() override; bool isHmdMounted() const override; + void postPreview() override; private: vr::IVRSystem* _system { nullptr }; From 225c462685724c43aef558f2661d13d79949047a Mon Sep 17 00:00:00 2001 From: Anthony Thibault Date: Mon, 21 Mar 2016 21:47:59 -0700 Subject: [PATCH 03/12] Improved NSIGHT instrumentation * Application::idle, physics and avatar processing are tracked * Application::paintGL frameNumber payload is tracked * OpenGLDisplayPlugin::present is profiled with corresponding frameNumber payload * Added color and payload support to Nsight ProfileRange class. --- interface/src/Application.cpp | 17 +++++++++++--- .../display-plugins/OpenGLDisplayPlugin.cpp | 5 ++++- .../display-plugins/hmd/HmdDisplayPlugin.cpp | 4 ++++ libraries/shared/src/shared/NsightHelpers.cpp | 19 ++++++++++++++++ libraries/shared/src/shared/NsightHelpers.h | 22 +++++++++---------- plugins/oculus/src/OculusDisplayPlugin.cpp | 4 ++++ plugins/openvr/src/OpenVrDisplayPlugin.cpp | 7 +++++- 7 files changed, 62 insertions(+), 16 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 5d8cbafbd2..af41da4b5d 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1401,7 +1401,7 @@ void Application::paintGL() { _lastFramesPerSecondUpdate = now; } - PROFILE_RANGE(__FUNCTION__); + PROFILE_RANGE_EX(__FUNCTION__, 0xff0000ff, (uint64_t)_frameCount); PerformanceTimer perfTimer("paintGL"); if (nullptr == _displayPlugin) { @@ -2499,6 +2499,8 @@ static uint32_t _renderedFrameIndex { INVALID_FRAME }; void Application::idle(uint64_t now) { + PROFILE_RANGE(__FUNCTION__); + if (_aboutToQuit) { return; // bail early, nothing to do here. } @@ -2556,7 +2558,6 @@ void Application::idle(uint64_t now) { _lastTimeUpdated.start(); { - PROFILE_RANGE(__FUNCTION__); static uint64_t lastIdleStart{ now }; uint64_t idleStartToStartDuration = now - lastIdleStart; if (idleStartToStartDuration != 0) { @@ -3173,6 +3174,9 @@ void Application::updateDialogs(float deltaTime) { } void Application::update(float deltaTime) { + + PROFILE_RANGE_EX(__FUNCTION__, 0xffff0000, (uint64_t)getActiveDisplayPlugin()->presentCount()); + bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); PerformanceWarning warn(showWarnings, "Application::update()"); @@ -3269,6 +3273,8 @@ void Application::update(float deltaTime) { updateDialogs(deltaTime); // update various stats dialogs if present if (_physicsEnabled) { + PROFILE_RANGE_EX("Physics", 0xffff0000, (uint64_t)getActiveDisplayPlugin()->presentCount()); + PerformanceTimer perfTimer("physics"); AvatarManager* avatarManager = DependencyManager::get().data(); @@ -3339,9 +3345,13 @@ void Application::update(float deltaTime) { } } - _avatarUpdate->synchronousProcess(); + { + PROFILE_RANGE_EX("Avatars", 0xffff0000, (uint64_t)getActiveDisplayPlugin()->presentCount()); + _avatarUpdate->synchronousProcess(); + } { + PROFILE_RANGE_EX("Overlays", 0xffff0000, (uint64_t)getActiveDisplayPlugin()->presentCount()); PerformanceTimer perfTimer("overlays"); _overlays.update(deltaTime); } @@ -3361,6 +3371,7 @@ void Application::update(float deltaTime) { // Update my voxel servers with my current voxel query... { + PROFILE_RANGE_EX("QueryOctree", 0xffff0000, (uint64_t)getActiveDisplayPlugin()->presentCount()); PerformanceTimer perfTimer("queryOctree"); quint64 sinceLastQuery = now - _lastQueriedTime; const quint64 TOO_LONG_SINCE_LAST_QUERY = 3 * USECS_PER_SECOND; diff --git a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp index ca36ab35f0..4678694d4a 100644 --- a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp @@ -21,7 +21,7 @@ #include #include #include - +#include #include #include #include @@ -527,6 +527,9 @@ void OpenGLDisplayPlugin::internalPresent() { void OpenGLDisplayPlugin::present() { incrementPresentCount(); + + PROFILE_RANGE_EX(__FUNCTION__, 0xff00ff00, (uint64_t)presentCount()) + updateTextures(); if (_currentSceneTexture) { // Write all layers to a local framebuffer diff --git a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp index 340804de04..b022b10887 100644 --- a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include "../Logging.h" #include "../CompositorHelper.h" @@ -106,6 +107,9 @@ void HmdDisplayPlugin::compositePointer() { } void HmdDisplayPlugin::internalPresent() { + + PROFILE_RANGE_EX(__FUNCTION__, 0xff00ff00, (uint64_t)presentCount()) + // Composite together the scene, overlay and mouse cursor hmdPresent(); diff --git a/libraries/shared/src/shared/NsightHelpers.cpp b/libraries/shared/src/shared/NsightHelpers.cpp index e48e228588..5b952acea8 100644 --- a/libraries/shared/src/shared/NsightHelpers.cpp +++ b/libraries/shared/src/shared/NsightHelpers.cpp @@ -15,8 +15,27 @@ ProfileRange::ProfileRange(const char *name) { nvtxRangePush(name); } +ProfileRange::ProfileRange(const char *name, uint32_t argbColor, uint64_t payload) { + + nvtxEventAttributes_t eventAttrib = {0}; + eventAttrib.version = NVTX_VERSION; + eventAttrib.size = NVTX_EVENT_ATTRIB_STRUCT_SIZE; + eventAttrib.colorType = NVTX_COLOR_ARGB; + eventAttrib.color = argbColor; + eventAttrib.messageType = NVTX_MESSAGE_TYPE_ASCII; + eventAttrib.message.ascii = name; + eventAttrib.payload.llValue = payload; + eventAttrib.payloadType = NVTX_PAYLOAD_TYPE_UNSIGNED_INT64; + + nvtxRangePushEx(&eventAttrib); +} + ProfileRange::~ProfileRange() { nvtxRangePop(); } +#else +ProfileRange::ProfileRange(const char *name) {} +ProfileRange::ProfileRange(const char *name, uint32_t argbColor, uint64_t payload) {} +ProfileRange::~ProfileRange() {} #endif diff --git a/libraries/shared/src/shared/NsightHelpers.h b/libraries/shared/src/shared/NsightHelpers.h index 3acdf14411..7a4f434ce9 100644 --- a/libraries/shared/src/shared/NsightHelpers.h +++ b/libraries/shared/src/shared/NsightHelpers.h @@ -9,16 +9,16 @@ #ifndef hifi_gl_NsightHelpers_h #define hifi_gl_NsightHelpers_h -#if defined(NSIGHT_FOUND) - class ProfileRange { - public: - ProfileRange(const char *name); - ~ProfileRange(); - }; +#include + +class ProfileRange { +public: + ProfileRange(const char *name); + ProfileRange(const char *name, uint32_t argbColor, uint64_t payload); + ~ProfileRange(); +}; + #define PROFILE_RANGE(name) ProfileRange profileRangeThis(name); -#else -#define PROFILE_RANGE(name) +#define PROFILE_RANGE_EX(name, argbColor, payload) ProfileRange profileRangeThis(name, argbColor, payload); + #endif - - -#endif \ No newline at end of file diff --git a/plugins/oculus/src/OculusDisplayPlugin.cpp b/plugins/oculus/src/OculusDisplayPlugin.cpp index 5ab56e1659..71a858e1e8 100644 --- a/plugins/oculus/src/OculusDisplayPlugin.cpp +++ b/plugins/oculus/src/OculusDisplayPlugin.cpp @@ -6,6 +6,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // #include "OculusDisplayPlugin.h" +#include #include "OculusHelpers.h" const QString OculusDisplayPlugin::NAME("Oculus Rift"); @@ -54,6 +55,9 @@ void OculusDisplayPlugin::updateFrameData() { } void OculusDisplayPlugin::hmdPresent() { + + PROFILE_RANGE_EX(__FUNCTION__, 0xff00ff00, (uint64_t)_currentRenderFrameIndex) + if (!_currentSceneTexture) { return; } diff --git a/plugins/openvr/src/OpenVrDisplayPlugin.cpp b/plugins/openvr/src/OpenVrDisplayPlugin.cpp index adad0648e8..e123512cf9 100644 --- a/plugins/openvr/src/OpenVrDisplayPlugin.cpp +++ b/plugins/openvr/src/OpenVrDisplayPlugin.cpp @@ -21,7 +21,7 @@ #include #include #include - +#include #include "OpenVrHelpers.h" Q_DECLARE_LOGGING_CATEGORY(displayplugins) @@ -144,6 +144,9 @@ void OpenVrDisplayPlugin::updateHeadPose(uint32_t frameIndex) { } void OpenVrDisplayPlugin::hmdPresent() { + + PROFILE_RANGE_EX(__FUNCTION__, 0xff00ff00, (uint64_t)_currentRenderFrameIndex) + // Flip y-axis since GL UV coords are backwards. static vr::VRTextureBounds_t leftBounds{ 0, 0, 0.5f, 1 }; static vr::VRTextureBounds_t rightBounds{ 0.5f, 0, 1, 1 }; @@ -155,6 +158,8 @@ void OpenVrDisplayPlugin::hmdPresent() { } void OpenVrDisplayPlugin::postPreview() { + PROFILE_RANGE_EX(__FUNCTION__, 0xff00ff00, (uint64_t)_currentRenderFrameIndex) + vr::TrackedDevicePose_t currentTrackedDevicePose[vr::k_unMaxTrackedDeviceCount]; _compositor->WaitGetPoses(currentTrackedDevicePose, vr::k_unMaxTrackedDeviceCount, nullptr, 0); _hmdActivityLevel = _system->GetTrackedDeviceActivityLevel(vr::k_unTrackedDeviceIndex_Hmd); From b1286517c6430072b43d654f3cdbe78a8ea65c3f Mon Sep 17 00:00:00 2001 From: Anthony Thibault Date: Mon, 21 Mar 2016 21:51:16 -0700 Subject: [PATCH 04/12] Removed frame latency in GLEscrow This could occur if the GLEscrow queue has extra frames in it. When new textures were fetched, before this fix, they were simply popped from the queue. This commit introduces a loop, that will fetch from the queue until it is empty. --- libraries/gl/src/gl/GLEscrow.h | 8 +++++--- plugins/openvr/src/OpenVrDisplayPlugin.cpp | 6 +++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/libraries/gl/src/gl/GLEscrow.h b/libraries/gl/src/gl/GLEscrow.h index 357398c79b..d4772c85e9 100644 --- a/libraries/gl/src/gl/GLEscrow.h +++ b/libraries/gl/src/gl/GLEscrow.h @@ -203,13 +203,15 @@ public: // Also releases any previous texture held by the caller bool fetchSignaledAndRelease(T& value) { T originalValue = value; - if (fetchSignaled(value)) { + bool fetched = false; + while (fetchSignaled(value)) { + fetched = true; if (originalValue != invalid()) { release(originalValue); } - return true; + originalValue = value; } - return false; + return fetched; } bool fetchAndReleaseWithFence(T& value, GLsync& sync) { diff --git a/plugins/openvr/src/OpenVrDisplayPlugin.cpp b/plugins/openvr/src/OpenVrDisplayPlugin.cpp index e123512cf9..1b87225388 100644 --- a/plugins/openvr/src/OpenVrDisplayPlugin.cpp +++ b/plugins/openvr/src/OpenVrDisplayPlugin.cpp @@ -119,14 +119,14 @@ void OpenVrDisplayPlugin::updateHeadPose(uint32_t frameIndex) { float vsyncToPhotons = _system->GetFloatTrackedDeviceProperty(vr::k_unTrackedDeviceIndex_Hmd, vr::Prop_SecondsFromVsyncToPhotons_Float); #if THREADED_PRESENT - // TODO: this seems awfuly long, 44ms total, but it produced the best results. - const float NUM_PREDICTION_FRAMES = 3.0f; + // 2 frames of prediction + vsyncToPhotons = 33ms total + const float NUM_PREDICTION_FRAMES = 2.0f; float predictedSecondsFromNow = NUM_PREDICTION_FRAMES * frameDuration + vsyncToPhotons; #else uint64_t frameCounter; float timeSinceLastVsync; _system->GetTimeSinceLastVsync(&timeSinceLastVsync, &frameCounter); - float predictedSecondsFromNow = 3.0f * frameDuration - timeSinceLastVsync + vsyncToPhotons; + float predictedSecondsFromNow = 2.0f * frameDuration - timeSinceLastVsync + vsyncToPhotons; #endif vr::TrackedDevicePose_t predictedTrackedDevicePose[vr::k_unMaxTrackedDeviceCount]; From 50ac101d568d6cfdbb635bf0c3b6860dd769c381 Mon Sep 17 00:00:00 2001 From: Anthony Thibault Date: Tue, 22 Mar 2016 10:36:00 -0700 Subject: [PATCH 05/12] Avatar and Rig NSIGHT instrumentation --- interface/src/Application.cpp | 16 ++++++++++++---- libraries/animation/src/Rig.cpp | 3 +++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index e61ef7f7e0..06755ae70a 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3245,6 +3245,8 @@ void Application::update(float deltaTime) { PerformanceTimer perfTimer("physics"); { + PROFILE_RANGE_EX("UpdateStats", 0xffffff00, (uint64_t)getActiveDisplayPlugin()->presentCount()); + PerformanceTimer perfTimer("updateStates)"); static VectorOfMotionStates motionStates; _entitySimulation.getObjectsToRemoveFromPhysics(motionStates); @@ -3277,12 +3279,14 @@ void Application::update(float deltaTime) { }); } { + PROFILE_RANGE_EX("StepSimulation", 0xffff8000, (uint64_t)getActiveDisplayPlugin()->presentCount()); PerformanceTimer perfTimer("stepSimulation"); getEntities()->getTree()->withWriteLock([&] { _physicsEngine->stepSimulation(); }); } { + PROFILE_RANGE_EX("HarvestChanges", 0xffffff00, (uint64_t)getActiveDisplayPlugin()->presentCount()); PerformanceTimer perfTimer("havestChanges"); if (_physicsEngine->hasOutgoingChanges()) { getEntities()->getTree()->withWriteLock([&] { @@ -3313,17 +3317,21 @@ void Application::update(float deltaTime) { // AvatarManager update { - PROFILE_RANGE_EX("Avatars", 0xffff0000, (uint64_t)getActiveDisplayPlugin()->presentCount()); - PerformanceTimer perfTimer("AvatarManger"); qApp->setAvatarSimrateSample(1.0f / deltaTime); - avatarManager->updateOtherAvatars(deltaTime); + { + PROFILE_RANGE_EX("OtherAvatars", 0xffff00ff, (uint64_t)getActiveDisplayPlugin()->presentCount()); + avatarManager->updateOtherAvatars(deltaTime); + } qApp->updateMyAvatarLookAtPosition(); - avatarManager->updateMyAvatar(deltaTime); + { + PROFILE_RANGE_EX("MyAvatar", 0xffff00ff, (uint64_t)getActiveDisplayPlugin()->presentCount()); + avatarManager->updateMyAvatar(deltaTime); + } } { diff --git a/libraries/animation/src/Rig.cpp b/libraries/animation/src/Rig.cpp index ae9adc71c2..a2b664d064 100644 --- a/libraries/animation/src/Rig.cpp +++ b/libraries/animation/src/Rig.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include "AnimationLogging.h" #include "AnimClip.h" @@ -852,6 +853,8 @@ void Rig::updateAnimationStateHandlers() { // called on avatar update thread (wh void Rig::updateAnimations(float deltaTime, glm::mat4 rootTransform) { + PROFILE_RANGE_EX(__FUNCTION__, 0xffff00ff, 0); + setModelOffset(rootTransform); if (_animNode) { From 209524a5c08441d9df6e10e232ca2b3f8c098548 Mon Sep 17 00:00:00 2001 From: Anthony Thibault Date: Tue, 22 Mar 2016 15:38:10 -0700 Subject: [PATCH 06/12] openvr: Non-threaded present work In the unlikely event you hit 90htz in non-threaded present mode, you will have perfect tracking and latency. This verifies that there are no other sources of tracking or rendering latency, other then the ones we already know about. --- .../src/display-plugins/OpenGLDisplayPlugin.h | 2 +- libraries/gl/src/gl/GLEscrow.h | 5 +++++ plugins/openvr/src/OpenVrDisplayPlugin.cpp | 8 ++++---- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.h b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.h index 501232f7e7..7295b07ad3 100644 --- a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.h +++ b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.h @@ -17,9 +17,9 @@ #include #include #include -#include #define THREADED_PRESENT 1 +#include class OpenGLDisplayPlugin : public DisplayPlugin { protected: diff --git a/libraries/gl/src/gl/GLEscrow.h b/libraries/gl/src/gl/GLEscrow.h index d4772c85e9..cf96e43e1f 100644 --- a/libraries/gl/src/gl/GLEscrow.h +++ b/libraries/gl/src/gl/GLEscrow.h @@ -71,11 +71,16 @@ public: } bool signaled() const { +#if THREADED_PRESENT auto result = glClientWaitSync(_sync, 0, 0); if (GL_TIMEOUT_EXPIRED != result && GL_WAIT_FAILED != result) { return true; } return false; +#else + glWaitSync(_sync, 0, GL_TIMEOUT_IGNORED); + return true; +#endif } }; diff --git a/plugins/openvr/src/OpenVrDisplayPlugin.cpp b/plugins/openvr/src/OpenVrDisplayPlugin.cpp index 1b87225388..07629a442f 100644 --- a/plugins/openvr/src/OpenVrDisplayPlugin.cpp +++ b/plugins/openvr/src/OpenVrDisplayPlugin.cpp @@ -69,6 +69,9 @@ void OpenVrDisplayPlugin::internalActivate() { _compositor = vr::VRCompositor(); Q_ASSERT(_compositor); + // enable async time warp + // _compositor->ForceInterleavedReprojectionOn(true); + // set up default sensor space such that the UI overlay will align with the front of the room. auto chaperone = vr::VRChaperone(); if (chaperone) { @@ -123,10 +126,7 @@ void OpenVrDisplayPlugin::updateHeadPose(uint32_t frameIndex) { const float NUM_PREDICTION_FRAMES = 2.0f; float predictedSecondsFromNow = NUM_PREDICTION_FRAMES * frameDuration + vsyncToPhotons; #else - uint64_t frameCounter; - float timeSinceLastVsync; - _system->GetTimeSinceLastVsync(&timeSinceLastVsync, &frameCounter); - float predictedSecondsFromNow = 2.0f * frameDuration - timeSinceLastVsync + vsyncToPhotons; + float predictedSecondsFromNow = frameDuration + vsyncToPhotons; #endif vr::TrackedDevicePose_t predictedTrackedDevicePose[vr::k_unMaxTrackedDeviceCount]; From c40b70688cbee4345ae720df7844fa7fc5694391 Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Tue, 22 Mar 2016 17:43:36 -0700 Subject: [PATCH 07/12] Made Nsight wrapper win32 only. --- libraries/shared/src/shared/NsightHelpers.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libraries/shared/src/shared/NsightHelpers.h b/libraries/shared/src/shared/NsightHelpers.h index 7a4f434ce9..9853171b34 100644 --- a/libraries/shared/src/shared/NsightHelpers.h +++ b/libraries/shared/src/shared/NsightHelpers.h @@ -9,6 +9,7 @@ #ifndef hifi_gl_NsightHelpers_h #define hifi_gl_NsightHelpers_h +#ifdef _WIN32 #include class ProfileRange { @@ -20,5 +21,9 @@ public: #define PROFILE_RANGE(name) ProfileRange profileRangeThis(name); #define PROFILE_RANGE_EX(name, argbColor, payload) ProfileRange profileRangeThis(name, argbColor, payload); +#else +#define PROFILE_RANGE(name) +#define PROFILE_RANGE_EX(name, argbColor, payload) +#endif #endif From 9dd24f81d4ea8a7f213c1b6786b92ed97470105c Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Tue, 22 Mar 2016 18:24:48 -0700 Subject: [PATCH 08/12] Fix for osx and linux --- libraries/shared/src/shared/NsightHelpers.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libraries/shared/src/shared/NsightHelpers.cpp b/libraries/shared/src/shared/NsightHelpers.cpp index 5b952acea8..2539ff8864 100644 --- a/libraries/shared/src/shared/NsightHelpers.cpp +++ b/libraries/shared/src/shared/NsightHelpers.cpp @@ -8,6 +8,7 @@ #include "NsightHelpers.h" +#ifdef _WIN32 #if defined(NSIGHT_FOUND) #include "nvToolsExt.h" @@ -39,3 +40,4 @@ ProfileRange::ProfileRange(const char *name) {} ProfileRange::ProfileRange(const char *name, uint32_t argbColor, uint64_t payload) {} ProfileRange::~ProfileRange() {} #endif +#endif // _WIN32 From 8bb387dc740734b426573f4d77dda8615d20bcf9 Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Wed, 23 Mar 2016 17:11:16 -0700 Subject: [PATCH 09/12] Revert GLEscrow changes --- libraries/gl/src/gl/GLEscrow.h | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/libraries/gl/src/gl/GLEscrow.h b/libraries/gl/src/gl/GLEscrow.h index cf96e43e1f..357398c79b 100644 --- a/libraries/gl/src/gl/GLEscrow.h +++ b/libraries/gl/src/gl/GLEscrow.h @@ -71,16 +71,11 @@ public: } bool signaled() const { -#if THREADED_PRESENT auto result = glClientWaitSync(_sync, 0, 0); if (GL_TIMEOUT_EXPIRED != result && GL_WAIT_FAILED != result) { return true; } return false; -#else - glWaitSync(_sync, 0, GL_TIMEOUT_IGNORED); - return true; -#endif } }; @@ -208,15 +203,13 @@ public: // Also releases any previous texture held by the caller bool fetchSignaledAndRelease(T& value) { T originalValue = value; - bool fetched = false; - while (fetchSignaled(value)) { - fetched = true; + if (fetchSignaled(value)) { if (originalValue != invalid()) { release(originalValue); } - originalValue = value; + return true; } - return fetched; + return false; } bool fetchAndReleaseWithFence(T& value, GLsync& sync) { From cec6e7dd8dedab70aea2f36a5bb3d13f872147ba Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Wed, 23 Mar 2016 17:12:48 -0700 Subject: [PATCH 10/12] Application: reduced idle PROFILE_RANGE spam --- interface/src/Application.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index ad25160dd7..c7e67c4d24 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2496,8 +2496,6 @@ static uint32_t _renderedFrameIndex { INVALID_FRAME }; void Application::idle(uint64_t now) { - PROFILE_RANGE(__FUNCTION__); - if (_aboutToQuit || _inPaint) { return; // bail early, nothing to do here. } @@ -2550,6 +2548,8 @@ void Application::idle(uint64_t now) { return; } + PROFILE_RANGE(__FUNCTION__); + // We're going to execute idle processing, so restart the last idle timer _lastTimeUpdated.start(); @@ -3140,7 +3140,7 @@ void Application::updateDialogs(float deltaTime) { void Application::update(float deltaTime) { - PROFILE_RANGE_EX(__FUNCTION__, 0xffff0000, (uint64_t)getActiveDisplayPlugin()->presentCount()); + PROFILE_RANGE_EX(__FUNCTION__, 0xffff0000, (uint64_t)_frameCount + 1); bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); PerformanceWarning warn(showWarnings, "Application::update()"); From 73725106f0f6824d09ea3bb29704348fc54b21c2 Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Wed, 23 Mar 2016 17:13:29 -0700 Subject: [PATCH 11/12] OpenGLDisplayPlugin: For non-threaded present use fetchAndReleasewithGpuWait --- .../src/display-plugins/OpenGLDisplayPlugin.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp index 4678694d4a..d842dc553b 100644 --- a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp @@ -404,7 +404,11 @@ void OpenGLDisplayPlugin::submitOverlayTexture(const gpu::TexturePointer& overla void OpenGLDisplayPlugin::updateTextures() { // FIXME intrduce a GPU wait instead of a CPU/GPU sync point? +#if THREADED_PRESENT if (_sceneTextureEscrow.fetchSignaledAndRelease(_currentSceneTexture)) { +#else + if (_sceneTextureEscrow.fetchAndReleaseWithGpuWait(_currentSceneTexture)) { +#endif updateFrameData(); } From 88c4e54cff936f7c4aa96bb1196f7163c1db2a12 Mon Sep 17 00:00:00 2001 From: Anthony Thibault Date: Wed, 23 Mar 2016 17:38:40 -0700 Subject: [PATCH 12/12] openvr: predict 3 frames into the future Becasue I revered the latency fix in the GLEscrow queue. *sigh* --- plugins/openvr/src/OpenVrDisplayPlugin.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/openvr/src/OpenVrDisplayPlugin.cpp b/plugins/openvr/src/OpenVrDisplayPlugin.cpp index b479c19fb4..0e7541066e 100644 --- a/plugins/openvr/src/OpenVrDisplayPlugin.cpp +++ b/plugins/openvr/src/OpenVrDisplayPlugin.cpp @@ -122,8 +122,8 @@ void OpenVrDisplayPlugin::updateHeadPose(uint32_t frameIndex) { float vsyncToPhotons = _system->GetFloatTrackedDeviceProperty(vr::k_unTrackedDeviceIndex_Hmd, vr::Prop_SecondsFromVsyncToPhotons_Float); #if THREADED_PRESENT - // 2 frames of prediction + vsyncToPhotons = 33ms total - const float NUM_PREDICTION_FRAMES = 2.0f; + // 3 frames of prediction + vsyncToPhotons = 44ms total + const float NUM_PREDICTION_FRAMES = 3.0f; float predictedSecondsFromNow = NUM_PREDICTION_FRAMES * frameDuration + vsyncToPhotons; #else float predictedSecondsFromNow = frameDuration + vsyncToPhotons;