Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

OVR submit layers to TimeWarp even frames are discarded. #2322

Closed
wants to merge 1 commit into from
Closed
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
19 changes: 14 additions & 5 deletions app/src/oculusvr/cpp/DeviceDelegateOculusVR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1462,7 +1462,7 @@ DeviceDelegateOculusVR::EndFrame(const bool aDiscard) {
m.currentFBO.reset();
}

if (aDiscard) {
if (aDiscard && m.renderMode != device::RenderMode::Immersive) {
return;
}

Expand Down Expand Up @@ -1506,7 +1506,8 @@ DeviceDelegateOculusVR::EndFrame(const bool aDiscard) {
projection.Header.DstBlend = VRAPI_FRAME_LAYER_BLEND_ONE_MINUS_SRC_ALPHA;
for (int i = 0; i < VRAPI_FRAME_LAYER_EYE_MAX; ++i) {
const auto &eyeSwapChain = m.eyeSwapChains[i];
const int swapChainIndex = m.frameIndex % eyeSwapChain->swapChainLength;
const int frameIndex = aDiscard ? lastFrameIndex : m.frameIndex;
const int swapChainIndex = frameIndex % eyeSwapChain->swapChainLength;
// Set up OVR layer textures
projection.Textures[i].ColorSwapChain = eyeSwapChain->ovrSwapChain;
projection.Textures[i].SwapChainIndex = swapChainIndex;
Expand All @@ -1523,20 +1524,28 @@ DeviceDelegateOculusVR::EndFrame(const bool aDiscard) {
}
}


// Submit all layers to TimeWarp

// Even though the frame is discarded, we still need to
// submit the previous frame to TimeWarp in order to get controller
// states from the next frame.
ovrSubmitFrameDescription2 frameDesc = {};
frameDesc.Flags = 0;
if (m.renderMode == device::RenderMode::Immersive) {
frameDesc.Flags |= VRAPI_FRAME_FLAG_INHIBIT_VOLUME_LAYER;
}
frameDesc.SwapInterval = 1;
frameDesc.FrameIndex = m.frameIndex;
frameDesc.DisplayTime = m.predictedDisplayTime;
frameDesc.FrameIndex = aDiscard ? lastFrameIndex : m.frameIndex;
frameDesc.DisplayTime = aDiscard ? lastPredictedDisplayTime : m.predictedDisplayTime;

frameDesc.LayerCount = layerCount;
frameDesc.Layers = layers;

if (!aDiscard) {
lastFrameIndex = m.frameIndex;
lastPredictedDisplayTime = m.predictedDisplayTime;
}

vrapi_SubmitFrame2(m.ovr, &frameDesc);
}

Expand Down
2 changes: 2 additions & 0 deletions app/src/oculusvr/cpp/DeviceDelegateOculusVR.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ class DeviceDelegateOculusVR : public DeviceDelegate {
virtual ~DeviceDelegateOculusVR();
private:
State& m;
int lastFrameIndex = 0;
double lastPredictedDisplayTime = 0.0f;
VRB_NO_DEFAULTS(DeviceDelegateOculusVR)
};

Expand Down