From 225c462685724c43aef558f2661d13d79949047a Mon Sep 17 00:00:00 2001 From: Anthony Thibault Date: Mon, 21 Mar 2016 21:47:59 -0700 Subject: [PATCH] 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);