diff options
| author | Rémi Verschelde <rverschelde@gmail.com> | 2023-10-06 12:52:52 +0200 |
|---|---|---|
| committer | Rémi Verschelde <rverschelde@gmail.com> | 2023-10-06 12:52:52 +0200 |
| commit | 7f8c3124a84504490dd20e5cf766b60837ae8430 (patch) | |
| tree | fdecf3cac0cfda4e46306a61d97058bfb11dc993 | |
| parent | 373c4b22d3f2ea1f08ec36ca95a5115e9d967cfb (diff) | |
| parent | 771ec958af3a6ff0d0a9183b0ab7c73d98d8b953 (diff) | |
| download | redot-engine-7f8c3124a84504490dd20e5cf766b60837ae8430.tar.gz | |
Merge pull request #82752 from decacis/openxr_swapchain_error
OpenXR - Properly skip frame render when the XR runtime is not yet ready to let us acquire the next image from the swapchain
| -rw-r--r-- | modules/openxr/openxr_api.cpp | 47 | ||||
| -rw-r--r-- | modules/openxr/openxr_api.h | 1 |
2 files changed, 37 insertions, 11 deletions
diff --git a/modules/openxr/openxr_api.cpp b/modules/openxr/openxr_api.cpp index b1c7ab1615..d0e958164d 100644 --- a/modules/openxr/openxr_api.cpp +++ b/modules/openxr/openxr_api.cpp @@ -1683,14 +1683,27 @@ bool OpenXRAPI::acquire_image(OpenXRSwapChainInfo &p_swapchain) { ERR_FAIL_COND_V(p_swapchain.image_acquired, true); // This was not released when it should be, error out and reuse... XrResult result; - XrSwapchainImageAcquireInfo swapchain_image_acquire_info = { - XR_TYPE_SWAPCHAIN_IMAGE_ACQUIRE_INFO, // type - nullptr // next - }; - result = xrAcquireSwapchainImage(p_swapchain.swapchain, &swapchain_image_acquire_info, &p_swapchain.image_index); - if (XR_FAILED(result)) { - print_line("OpenXR: failed to acquire swapchain image [", get_error_string(result), "]"); - return false; + + if (!p_swapchain.skip_acquire_swapchain) { + XrSwapchainImageAcquireInfo swapchain_image_acquire_info = { + XR_TYPE_SWAPCHAIN_IMAGE_ACQUIRE_INFO, // type + nullptr // next + }; + + result = xrAcquireSwapchainImage(p_swapchain.swapchain, &swapchain_image_acquire_info, &p_swapchain.image_index); + if (!XR_UNQUALIFIED_SUCCESS(result)) { + // Make sure end_frame knows we need to submit an empty frame + frame_state.shouldRender = false; + + if (XR_FAILED(result)) { + // Unexpected failure, log this! + print_line("OpenXR: failed to acquire swapchain image [", get_error_string(result), "]"); + return false; + } else { + // In this scenario we silently fail, the XR runtime is simply not ready yet to acquire the swapchain. + return false; + } + } } XrSwapchainImageWaitInfo swapchain_image_wait_info = { @@ -1700,9 +1713,21 @@ bool OpenXRAPI::acquire_image(OpenXRSwapChainInfo &p_swapchain) { }; result = xrWaitSwapchainImage(p_swapchain.swapchain, &swapchain_image_wait_info); - if (XR_FAILED(result)) { - print_line("OpenXR: failed to wait for swapchain image [", get_error_string(result), "]"); - return false; + if (!XR_UNQUALIFIED_SUCCESS(result)) { + // Make sure end_frame knows we need to submit an empty frame + frame_state.shouldRender = false; + + if (XR_FAILED(result)) { + // Unexpected failure, log this! + print_line("OpenXR: failed to wait for swapchain image [", get_error_string(result), "]"); + return false; + } else { + // Make sure to skip trying to acquire the swapchain image in the next frame + p_swapchain.skip_acquire_swapchain = true; + return false; + } + } else { + p_swapchain.skip_acquire_swapchain = false; } return true; diff --git a/modules/openxr/openxr_api.h b/modules/openxr/openxr_api.h index 89f8f3cbec..64769b244c 100644 --- a/modules/openxr/openxr_api.h +++ b/modules/openxr/openxr_api.h @@ -139,6 +139,7 @@ private: void *swapchain_graphics_data = nullptr; uint32_t image_index = 0; bool image_acquired = false; + bool skip_acquire_swapchain = false; }; OpenXRSwapChainInfo swapchains[OPENXR_SWAPCHAIN_MAX]; |
