Skip to content

Commit

Permalink
CompositorBase: Use an event instead of a mutex.
Browse files Browse the repository at this point in the history
Less strict, closer to what's intended.
  • Loading branch information
CrossVR committed Oct 19, 2019
1 parent 2f4774a commit 0e21320
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
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;
};

0 comments on commit 0e21320

Please sign in to comment.