1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-02-16 08:39:40 +00:00

Wait on a separate thread

This commit is contained in:
Mads Buvik Sandvei 2020-07-26 12:34:24 +02:00
parent 9e16e592e8
commit a15188d3bc
3 changed files with 13 additions and 1 deletions

View file

@ -654,6 +654,8 @@ namespace MWVR
void OpenXRManagerImpl::xrResourceReleased()
{
if (mAcquiredResources == 0)
throw std::logic_error("Releasing a nonexistent resource");
mAcquiredResources--;
}

View file

@ -209,6 +209,8 @@ namespace MWVR
// But may be "Draw" without shadows.
if (phase == mXrSyncPhase && getFrame(phase)->mShouldRender)
{
if (getFrame(phase)->mXrWaitThread.joinable())
getFrame(phase)->mXrWaitThread.join();
getFrame(phase)->mXrPredictedDisplayTime = doFrameSync();
}
}
@ -226,7 +228,7 @@ namespace MWVR
auto condEnd = std::chrono::steady_clock::now();
auto* xr = Environment::get().getManager();
Log(Debug::Debug) << mFrames << ": WaitFrame " << std::this_thread::get_id();
auto predictedDisplayTime = xr->waitFrame();
auto predictedDisplayTime = xr->getLastPredictedDisplayTime();
Log(Debug::Debug) << mFrames << ": BeginFrame " << std::this_thread::get_id();
xr->beginFrame();
auto xrSyncEnd = std::chrono::steady_clock::now();
@ -303,7 +305,13 @@ namespace MWVR
frame->mPredictedPoses = predictedPoses;
frame->mShouldRender = xr->frameShouldRender();
if (frame->mShouldRender)
{
// XrWaitThread is best invoked immediately to help the runtime make more accurate predictions
// but it forces a wait which is cancer for performance so delegate it to another thread
// and join before rendering.
frame->mXrWaitThread = std::thread{ [=] {xr->waitFrame(); } };
xr->xrResourceAcquired();
}
}
const PoseSet& VRSession::predictedPoses(FramePhase phase)

View file

@ -6,6 +6,7 @@
#include <array>
#include <chrono>
#include <queue>
#include <thread>
#include <components/debug/debuglog.hpp>
#include <components/sdlutil/sdlgraphicswindow.hpp>
#include <components/settings/settings.hpp>
@ -47,6 +48,7 @@ namespace MWVR
long long mXrPredictedDisplayTime{ 0 };
PoseSet mPredictedPoses{};
bool mShouldRender{ false };
std::thread mXrWaitThread{};
};
public: