From 304a29a221178d10b44e92aeba3e1bc394f106ca Mon Sep 17 00:00:00 2001 From: Imanol Fernandez Date: Thu, 21 Nov 2019 16:13:56 +0100 Subject: [PATCH] Reuse the last frame and tracking when a VR frame is discarded in Oculus --- app/src/oculusvr/cpp/DeviceDelegateOculusVR.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app/src/oculusvr/cpp/DeviceDelegateOculusVR.cpp b/app/src/oculusvr/cpp/DeviceDelegateOculusVR.cpp index cab14b47d..7109f9166 100644 --- a/app/src/oculusvr/cpp/DeviceDelegateOculusVR.cpp +++ b/app/src/oculusvr/cpp/DeviceDelegateOculusVR.cpp @@ -674,6 +674,9 @@ struct DeviceDelegateOculusVR::State { uint32_t frameIndex = 0; double predictedDisplayTime = 0; ovrTracking2 predictedTracking = {}; + ovrTracking2 discardPredictedTracking = {}; + uint32_t discardedFrameIndex = 0; + int discardCount = 0; uint32_t renderWidth = 0; uint32_t renderHeight = 0; int32_t standaloneFoveatedLevel = 0; @@ -1463,7 +1466,17 @@ DeviceDelegateOculusVR::EndFrame(const bool aDiscard) { } if (aDiscard) { - return; + // Reuse the last frame when a frame is discarded. + // The last frame is timewarped by the VR compositor. + if (m.discardCount == 0) { + m.discardPredictedTracking = m.predictedTracking; + m.discardedFrameIndex = m.frameIndex; + } + m.discardCount++; + m.frameIndex = m.discardedFrameIndex; + m.predictedTracking = m.discardPredictedTracking; + } else { + m.discardCount = 0; } uint32_t layerCount = 0;