Merge pull request #7431 from hyperlogic/tony/vive-rendering-work

OpenVR rendering & Nsight instrumentation improvements
This commit is contained in:
Brad Davis 2016-03-24 17:44:30 -07:00
commit 0ac70049c7
13 changed files with 96 additions and 23 deletions

View file

@ -7,8 +7,8 @@ string(TOUPPER ${EXTERNAL_NAME} EXTERNAL_NAME_UPPER)
ExternalProject_Add( ExternalProject_Add(
${EXTERNAL_NAME} ${EXTERNAL_NAME}
URL https://github.com/ValveSoftware/openvr/archive/v0.9.15.zip URL https://github.com/ValveSoftware/openvr/archive/v0.9.19.zip
URL_MD5 0ff8560b49b6da1150fcc47360e8ceca URL_MD5 843f9dde488584d8af1f3ecf2252b4e0
CONFIGURE_COMMAND "" CONFIGURE_COMMAND ""
BUILD_COMMAND "" BUILD_COMMAND ""
INSTALL_COMMAND "" INSTALL_COMMAND ""

View file

@ -1415,7 +1415,7 @@ void Application::paintGL() {
_lastFramesPerSecondUpdate = now; _lastFramesPerSecondUpdate = now;
} }
PROFILE_RANGE(__FUNCTION__); PROFILE_RANGE_EX(__FUNCTION__, 0xff0000ff, (uint64_t)_frameCount);
PerformanceTimer perfTimer("paintGL"); PerformanceTimer perfTimer("paintGL");
if (nullptr == _displayPlugin) { if (nullptr == _displayPlugin) {
@ -2554,11 +2554,12 @@ void Application::idle(uint64_t now) {
return; return;
} }
PROFILE_RANGE(__FUNCTION__);
// We're going to execute idle processing, so restart the last idle timer // We're going to execute idle processing, so restart the last idle timer
_lastTimeUpdated.start(); _lastTimeUpdated.start();
{ {
PROFILE_RANGE(__FUNCTION__);
static uint64_t lastIdleStart{ now }; static uint64_t lastIdleStart{ now };
uint64_t idleStartToStartDuration = now - lastIdleStart; uint64_t idleStartToStartDuration = now - lastIdleStart;
if (idleStartToStartDuration != 0) { if (idleStartToStartDuration != 0) {
@ -3146,6 +3147,9 @@ void Application::updateDialogs(float deltaTime) {
} }
void Application::update(float deltaTime) { void Application::update(float deltaTime) {
PROFILE_RANGE_EX(__FUNCTION__, 0xffff0000, (uint64_t)_frameCount + 1);
bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);
PerformanceWarning warn(showWarnings, "Application::update()"); PerformanceWarning warn(showWarnings, "Application::update()");
@ -3246,9 +3250,13 @@ void Application::update(float deltaTime) {
QSharedPointer<AvatarManager> avatarManager = DependencyManager::get<AvatarManager>(); QSharedPointer<AvatarManager> avatarManager = DependencyManager::get<AvatarManager>();
if (_physicsEnabled) { if (_physicsEnabled) {
PROFILE_RANGE_EX("Physics", 0xffff0000, (uint64_t)getActiveDisplayPlugin()->presentCount());
PerformanceTimer perfTimer("physics"); PerformanceTimer perfTimer("physics");
{ {
PROFILE_RANGE_EX("UpdateStats", 0xffffff00, (uint64_t)getActiveDisplayPlugin()->presentCount());
PerformanceTimer perfTimer("updateStates)"); PerformanceTimer perfTimer("updateStates)");
static VectorOfMotionStates motionStates; static VectorOfMotionStates motionStates;
_entitySimulation.getObjectsToRemoveFromPhysics(motionStates); _entitySimulation.getObjectsToRemoveFromPhysics(motionStates);
@ -3281,12 +3289,14 @@ void Application::update(float deltaTime) {
}); });
} }
{ {
PROFILE_RANGE_EX("StepSimulation", 0xffff8000, (uint64_t)getActiveDisplayPlugin()->presentCount());
PerformanceTimer perfTimer("stepSimulation"); PerformanceTimer perfTimer("stepSimulation");
getEntities()->getTree()->withWriteLock([&] { getEntities()->getTree()->withWriteLock([&] {
_physicsEngine->stepSimulation(); _physicsEngine->stepSimulation();
}); });
} }
{ {
PROFILE_RANGE_EX("HarvestChanges", 0xffffff00, (uint64_t)getActiveDisplayPlugin()->presentCount());
PerformanceTimer perfTimer("havestChanges"); PerformanceTimer perfTimer("havestChanges");
if (_physicsEngine->hasOutgoingChanges()) { if (_physicsEngine->hasOutgoingChanges()) {
getEntities()->getTree()->withWriteLock([&] { getEntities()->getTree()->withWriteLock([&] {
@ -3321,17 +3331,24 @@ void Application::update(float deltaTime) {
qApp->setAvatarSimrateSample(1.0f / deltaTime); qApp->setAvatarSimrateSample(1.0f / deltaTime);
avatarManager->updateOtherAvatars(deltaTime); {
PROFILE_RANGE_EX("OtherAvatars", 0xffff00ff, (uint64_t)getActiveDisplayPlugin()->presentCount());
avatarManager->updateOtherAvatars(deltaTime);
}
qApp->updateMyAvatarLookAtPosition(); qApp->updateMyAvatarLookAtPosition();
// update sensorToWorldMatrix for camera and hand controllers // update sensorToWorldMatrix for camera and hand controllers
myAvatar->updateSensorToWorldMatrix(); myAvatar->updateSensorToWorldMatrix();
avatarManager->updateMyAvatar(deltaTime); {
PROFILE_RANGE_EX("MyAvatar", 0xffff00ff, (uint64_t)getActiveDisplayPlugin()->presentCount());
avatarManager->updateMyAvatar(deltaTime);
}
} }
{ {
PROFILE_RANGE_EX("Overlays", 0xffff0000, (uint64_t)getActiveDisplayPlugin()->presentCount());
PerformanceTimer perfTimer("overlays"); PerformanceTimer perfTimer("overlays");
_overlays.update(deltaTime); _overlays.update(deltaTime);
} }
@ -3351,6 +3368,7 @@ void Application::update(float deltaTime) {
// Update my voxel servers with my current voxel query... // Update my voxel servers with my current voxel query...
{ {
PROFILE_RANGE_EX("QueryOctree", 0xffff0000, (uint64_t)getActiveDisplayPlugin()->presentCount());
PerformanceTimer perfTimer("queryOctree"); PerformanceTimer perfTimer("queryOctree");
quint64 sinceLastQuery = now - _lastQueriedTime; quint64 sinceLastQuery = now - _lastQueriedTime;
const quint64 TOO_LONG_SINCE_LAST_QUERY = 3 * USECS_PER_SECOND; const quint64 TOO_LONG_SINCE_LAST_QUERY = 3 * USECS_PER_SECOND;

View file

@ -20,6 +20,7 @@
#include <GeometryUtil.h> #include <GeometryUtil.h>
#include <NumericalConstants.h> #include <NumericalConstants.h>
#include <DebugDraw.h> #include <DebugDraw.h>
#include <shared/NsightHelpers.h>
#include "AnimationLogging.h" #include "AnimationLogging.h"
#include "AnimClip.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) { void Rig::updateAnimations(float deltaTime, glm::mat4 rootTransform) {
PROFILE_RANGE_EX(__FUNCTION__, 0xffff00ff, 0);
setModelOffset(rootTransform); setModelOffset(rootTransform);
if (_animNode) { if (_animNode) {

View file

@ -21,7 +21,7 @@
#include <gl/GLWidget.h> #include <gl/GLWidget.h>
#include <NumericalConstants.h> #include <NumericalConstants.h>
#include <DependencyManager.h> #include <DependencyManager.h>
#include <shared/NsightHelpers.h>
#include <plugins/PluginContainer.h> #include <plugins/PluginContainer.h>
#include <gl/Config.h> #include <gl/Config.h>
#include <gl/GLEscrow.h> #include <gl/GLEscrow.h>
@ -404,7 +404,11 @@ void OpenGLDisplayPlugin::submitOverlayTexture(const gpu::TexturePointer& overla
void OpenGLDisplayPlugin::updateTextures() { void OpenGLDisplayPlugin::updateTextures() {
// FIXME intrduce a GPU wait instead of a CPU/GPU sync point? // FIXME intrduce a GPU wait instead of a CPU/GPU sync point?
#if THREADED_PRESENT
if (_sceneTextureEscrow.fetchSignaledAndRelease(_currentSceneTexture)) { if (_sceneTextureEscrow.fetchSignaledAndRelease(_currentSceneTexture)) {
#else
if (_sceneTextureEscrow.fetchAndReleaseWithGpuWait(_currentSceneTexture)) {
#endif
updateFrameData(); updateFrameData();
} }
@ -527,6 +531,9 @@ void OpenGLDisplayPlugin::internalPresent() {
void OpenGLDisplayPlugin::present() { void OpenGLDisplayPlugin::present() {
incrementPresentCount(); incrementPresentCount();
PROFILE_RANGE_EX(__FUNCTION__, 0xff00ff00, (uint64_t)presentCount())
updateTextures(); updateTextures();
if (_currentSceneTexture) { if (_currentSceneTexture) {
// Write all layers to a local framebuffer // Write all layers to a local framebuffer

View file

@ -17,9 +17,9 @@
#include <GLMHelpers.h> #include <GLMHelpers.h>
#include <SimpleMovingAverage.h> #include <SimpleMovingAverage.h>
#include <gl/OglplusHelpers.h> #include <gl/OglplusHelpers.h>
#include <gl/GLEscrow.h>
#define THREADED_PRESENT 1 #define THREADED_PRESENT 1
#include <gl/GLEscrow.h>
class OpenGLDisplayPlugin : public DisplayPlugin { class OpenGLDisplayPlugin : public DisplayPlugin {
protected: protected:

View file

@ -19,6 +19,7 @@
#include <gpu/GLBackend.h> #include <gpu/GLBackend.h>
#include <CursorManager.h> #include <CursorManager.h>
#include <gl/GLWidget.h> #include <gl/GLWidget.h>
#include <shared/NsightHelpers.h>
#include "../Logging.h" #include "../Logging.h"
#include "../CompositorHelper.h" #include "../CompositorHelper.h"
@ -106,6 +107,9 @@ void HmdDisplayPlugin::compositePointer() {
} }
void HmdDisplayPlugin::internalPresent() { void HmdDisplayPlugin::internalPresent() {
PROFILE_RANGE_EX(__FUNCTION__, 0xff00ff00, (uint64_t)presentCount())
// Composite together the scene, overlay and mouse cursor // Composite together the scene, overlay and mouse cursor
hmdPresent(); hmdPresent();
@ -149,6 +153,8 @@ void HmdDisplayPlugin::internalPresent() {
}); });
swapBuffers(); swapBuffers();
} }
postPreview();
} }
void HmdDisplayPlugin::setEyeRenderPose(uint32_t frameIndex, Eye eye, const glm::mat4& pose) { void HmdDisplayPlugin::setEyeRenderPose(uint32_t frameIndex, Eye eye, const glm::mat4& pose) {

View file

@ -31,6 +31,7 @@ public:
protected: protected:
virtual void hmdPresent() = 0; virtual void hmdPresent() = 0;
virtual bool isHmdMounted() const = 0; virtual bool isHmdMounted() const = 0;
virtual void postPreview() {};
void internalActivate() override; void internalActivate() override;
void compositeOverlay() override; void compositeOverlay() override;

View file

@ -8,6 +8,7 @@
#include "NsightHelpers.h" #include "NsightHelpers.h"
#ifdef _WIN32
#if defined(NSIGHT_FOUND) #if defined(NSIGHT_FOUND)
#include "nvToolsExt.h" #include "nvToolsExt.h"
@ -15,8 +16,28 @@ ProfileRange::ProfileRange(const char *name) {
nvtxRangePush(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() { ProfileRange::~ProfileRange() {
nvtxRangePop(); nvtxRangePop();
} }
#else
ProfileRange::ProfileRange(const char *name) {}
ProfileRange::ProfileRange(const char *name, uint32_t argbColor, uint64_t payload) {}
ProfileRange::~ProfileRange() {}
#endif #endif
#endif // _WIN32

View file

@ -9,16 +9,21 @@
#ifndef hifi_gl_NsightHelpers_h #ifndef hifi_gl_NsightHelpers_h
#define hifi_gl_NsightHelpers_h #define hifi_gl_NsightHelpers_h
#if defined(NSIGHT_FOUND) #ifdef _WIN32
class ProfileRange { #include <stdint.h>
public:
ProfileRange(const char *name); class ProfileRange {
~ProfileRange(); public:
}; ProfileRange(const char *name);
ProfileRange(const char *name, uint32_t argbColor, uint64_t payload);
~ProfileRange();
};
#define PROFILE_RANGE(name) ProfileRange profileRangeThis(name); #define PROFILE_RANGE(name) ProfileRange profileRangeThis(name);
#define PROFILE_RANGE_EX(name, argbColor, payload) ProfileRange profileRangeThis(name, argbColor, payload);
#else #else
#define PROFILE_RANGE(name) #define PROFILE_RANGE(name)
#define PROFILE_RANGE_EX(name, argbColor, payload)
#endif #endif
#endif
#endif

View file

@ -6,6 +6,7 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
#include "OculusDisplayPlugin.h" #include "OculusDisplayPlugin.h"
#include <shared/NsightHelpers.h>
#include "OculusHelpers.h" #include "OculusHelpers.h"
const QString OculusDisplayPlugin::NAME("Oculus Rift"); const QString OculusDisplayPlugin::NAME("Oculus Rift");
@ -54,6 +55,9 @@ void OculusDisplayPlugin::updateFrameData() {
} }
void OculusDisplayPlugin::hmdPresent() { void OculusDisplayPlugin::hmdPresent() {
PROFILE_RANGE_EX(__FUNCTION__, 0xff00ff00, (uint64_t)_currentRenderFrameIndex)
if (!_currentSceneTexture) { if (!_currentSceneTexture) {
return; return;
} }

View file

@ -21,7 +21,7 @@
#include <PerfStat.h> #include <PerfStat.h>
#include <plugins/PluginContainer.h> #include <plugins/PluginContainer.h>
#include <ViewFrustum.h> #include <ViewFrustum.h>
#include <shared/NsightHelpers.h>
#include "OpenVrHelpers.h" #include "OpenVrHelpers.h"
Q_DECLARE_LOGGING_CATEGORY(displayplugins) Q_DECLARE_LOGGING_CATEGORY(displayplugins)
@ -69,6 +69,9 @@ void OpenVrDisplayPlugin::internalActivate() {
_compositor = vr::VRCompositor(); _compositor = vr::VRCompositor();
Q_ASSERT(_compositor); 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. // set up default sensor space such that the UI overlay will align with the front of the room.
auto chaperone = vr::VRChaperone(); auto chaperone = vr::VRChaperone();
if (chaperone) { if (chaperone) {
@ -119,14 +122,11 @@ void OpenVrDisplayPlugin::updateHeadPose(uint32_t frameIndex) {
float vsyncToPhotons = _system->GetFloatTrackedDeviceProperty(vr::k_unTrackedDeviceIndex_Hmd, vr::Prop_SecondsFromVsyncToPhotons_Float); float vsyncToPhotons = _system->GetFloatTrackedDeviceProperty(vr::k_unTrackedDeviceIndex_Hmd, vr::Prop_SecondsFromVsyncToPhotons_Float);
#if THREADED_PRESENT #if THREADED_PRESENT
// TODO: this seems awfuly long, 44ms total, but it produced the best results. // 3 frames of prediction + vsyncToPhotons = 44ms total
const float NUM_PREDICTION_FRAMES = 3.0f; const float NUM_PREDICTION_FRAMES = 3.0f;
float predictedSecondsFromNow = NUM_PREDICTION_FRAMES * frameDuration + vsyncToPhotons; float predictedSecondsFromNow = NUM_PREDICTION_FRAMES * frameDuration + vsyncToPhotons;
#else #else
uint64_t frameCounter; float predictedSecondsFromNow = frameDuration + vsyncToPhotons;
float timeSinceLastVsync;
_system->GetTimeSinceLastVsync(&timeSinceLastVsync, &frameCounter);
float predictedSecondsFromNow = 3.0f * frameDuration - timeSinceLastVsync + vsyncToPhotons;
#endif #endif
vr::TrackedDevicePose_t predictedTrackedDevicePose[vr::k_unMaxTrackedDeviceCount]; vr::TrackedDevicePose_t predictedTrackedDevicePose[vr::k_unMaxTrackedDeviceCount];
@ -144,6 +144,9 @@ void OpenVrDisplayPlugin::updateHeadPose(uint32_t frameIndex) {
} }
void OpenVrDisplayPlugin::hmdPresent() { void OpenVrDisplayPlugin::hmdPresent() {
PROFILE_RANGE_EX(__FUNCTION__, 0xff00ff00, (uint64_t)_currentRenderFrameIndex)
// Flip y-axis since GL UV coords are backwards. // Flip y-axis since GL UV coords are backwards.
static vr::VRTextureBounds_t leftBounds{ 0, 0, 0.5f, 1 }; static vr::VRTextureBounds_t leftBounds{ 0, 0, 0.5f, 1 };
static vr::VRTextureBounds_t rightBounds{ 0.5f, 0, 1, 1 }; static vr::VRTextureBounds_t rightBounds{ 0.5f, 0, 1, 1 };
@ -152,6 +155,10 @@ void OpenVrDisplayPlugin::hmdPresent() {
_compositor->Submit(vr::Eye_Left, &texture, &leftBounds); _compositor->Submit(vr::Eye_Left, &texture, &leftBounds);
_compositor->Submit(vr::Eye_Right, &texture, &rightBounds); _compositor->Submit(vr::Eye_Right, &texture, &rightBounds);
}
void OpenVrDisplayPlugin::postPreview() {
PROFILE_RANGE_EX(__FUNCTION__, 0xff00ff00, (uint64_t)_currentRenderFrameIndex)
vr::TrackedDevicePose_t currentTrackedDevicePose[vr::k_unMaxTrackedDeviceCount]; vr::TrackedDevicePose_t currentTrackedDevicePose[vr::k_unMaxTrackedDeviceCount];
_compositor->WaitGetPoses(currentTrackedDevicePose, vr::k_unMaxTrackedDeviceCount, nullptr, 0); _compositor->WaitGetPoses(currentTrackedDevicePose, vr::k_unMaxTrackedDeviceCount, nullptr, 0);

View file

@ -35,6 +35,7 @@ protected:
void hmdPresent() override; void hmdPresent() override;
bool isHmdMounted() const override; bool isHmdMounted() const override;
void postPreview() override;
private: private:
vr::IVRSystem* _system { nullptr }; vr::IVRSystem* _system { nullptr };

View file

@ -51,7 +51,7 @@ vr::IVRSystem* acquireOpenVrSystem() {
if (!activeHmd) { if (!activeHmd) {
qCDebug(displayplugins) << "openvr: No vr::IVRSystem instance active, building"; qCDebug(displayplugins) << "openvr: No vr::IVRSystem instance active, building";
vr::EVRInitError eError = vr::VRInitError_None; 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; qCDebug(displayplugins) << "openvr display: HMD is " << activeHmd << " error is " << eError;
} }
if (activeHmd) { if (activeHmd) {