Skip to content

Commit

Permalink
Change GPU sync logic once again
Browse files Browse the repository at this point in the history
OpenXR must first release the swapchain frame, then call xrEndFrame!
  • Loading branch information
Detegr committed Jan 8, 2024
1 parent 9df6a02 commit cf17f68
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
4 changes: 3 additions & 1 deletion OpenVR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ void OpenVR::SubmitFramesToHMD(IDirect3DDevice9* dev)
dev->StretchRect(dxSurface[RightEye], nullptr, rightEye, nullptr, D3DTEXF_NONE);
}

gD3DVR->WaitDeviceIdle(true);
gD3DVR->BeginVRSubmit();

if (auto e = compositor->Submit(static_cast<vr::EVREye>(LeftEye), &openvrTexture[LeftEye]); e != vr::VRCompositorError_None) [[unlikely]] {
Dbg(std::format("Compositor error: {}", VRCompositorErrorStr(e)));
Expand All @@ -140,6 +140,8 @@ void OpenVR::SubmitFramesToHMD(IDirect3DDevice9* dev)
Dbg(std::format("Compositor error: {}", VRCompositorErrorStr(e)));
}

gD3DVR->EndVRSubmit();

release:
leftEye->Release();
rightEye->Release();
Expand Down
11 changes: 6 additions & 5 deletions OpenXR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,9 +430,6 @@ void OpenXR::SubmitFramesToHMD(IDirect3DDevice9* dev)
return;
}

// Wait for the GPU. Without this the game will crash at startup.
gD3DVR->WaitDeviceIdle(true);

// Essentially StretchRect but works directly with VkImage as a target
gD3DVR->CopySurfaceToVulkanImage(
dxSurface[LeftEye],
Expand Down Expand Up @@ -474,12 +471,16 @@ void OpenXR::SubmitFramesToHMD(IDirect3DDevice9* dev)
.layers = layers,
};

xrReleaseSwapchainImage(swapchains[LeftEye], &releaseInfo);
xrReleaseSwapchainImage(swapchains[RightEye], &releaseInfo);

gD3DVR->BeginVRSubmit();

if (auto res = xrEndFrame(session, &frameEndInfo); res != XR_SUCCESS) {
Dbg(std::format("xrEndFrame failed: {}", XrResultToString(instance, res)));
}

xrReleaseSwapchainImage(swapchains[LeftEye], &releaseInfo);
xrReleaseSwapchainImage(swapchains[RightEye], &releaseInfo);
gD3DVR->EndVRSubmit();

if (gCfg.debug && perfQueryFree) [[unlikely]] {
gpuEndQuery->Issue(D3DISSUE_END);
Expand Down

0 comments on commit cf17f68

Please sign in to comment.