Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from LibreVR:master #87

Merged
merged 1 commit into from
Oct 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions Revive/CompositorBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "rcu_ptr.h"

#include <openvr.h>
#include <Windows.h>
#include <vector>
#include <algorithm>

Expand Down Expand Up @@ -60,11 +61,11 @@ CompositorBase::CompositorBase()
, m_MirrorTexture(nullptr)
, m_OverlayCount(0)
, m_ActiveOverlays()
, m_FrameMutex()
, m_FrameLock(m_FrameMutex, std::defer_lock)
, m_FrameEvent()
{
// We want to handle all graphics tasks explicitly instead of implicitly letting WaitGetPoses execute them
vr::VRCompositor()->SetExplicitTimingMode(vr::VRCompositorTimingMode_Explicit_ApplicationPerformsPostPresentHandoff);
CreateEvent(nullptr, true, false, nullptr);
}

CompositorBase::~CompositorBase()
Expand Down Expand Up @@ -121,8 +122,7 @@ ovrResult CompositorBase::WaitToBeginFrame(ovrSession session, long long frameIn
MICROPROFILE_SCOPE(WaitToBeginFrame);

// WaitGetPoses is equivalent to calling BeginFrame, so we need to wait for any frame still in-flight
m_FrameMutex.lock();
m_FrameMutex.unlock();
WaitForSingleObject(m_FrameEvent, int(vr::VRCompositor()->GetFrameTimeRemaining() * 1000.0));

if (!session->Details->UseHack(SessionDetails::HACK_WAIT_ON_SUBMIT))
{
Expand All @@ -136,9 +136,7 @@ ovrResult CompositorBase::BeginFrame(ovrSession session, long long frameIndex)
{
MICROPROFILE_SCOPE(BeginFrame);

// Lock the mutex only if we don't already own it
if (!m_FrameLock)
m_FrameLock.lock();
ResetEvent(m_FrameEvent);

session->FrameIndex = frameIndex;
return session->Input->UpdateInputState();
Expand Down Expand Up @@ -249,8 +247,7 @@ ovrResult CompositorBase::EndFrame(ovrSession session, ovrLayerHeader const * co
}

// Frame now completed so we can let anyone waiting on the next frame call WaitGetPoses
if (m_FrameLock)
m_FrameLock.unlock();
SetEvent(m_FrameEvent);

if (m_MirrorTexture && error == vr::VRCompositorError_None)
RenderMirrorTexture(m_MirrorTexture);
Expand Down
4 changes: 1 addition & 3 deletions Revive/CompositorBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

#include <openvr.h>
#include <vector>
#include <mutex>

class CompositorBase
{
Expand Down Expand Up @@ -50,6 +49,5 @@ class CompositorBase
std::vector<vr::VROverlayHandle_t> m_ActiveOverlays;

// Call order enforcement
std::mutex m_FrameMutex;
std::unique_lock<std::mutex> m_FrameLock;
void* m_FrameEvent;
};