The open source OpenXR runtime

st/oxr: Return correct value

When the timeout expires:
1. Don't change the swapchain image index.
2. Return XR_TIMEOUT_EXPIRED.

Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/2256>

authored by

Weijie Wang and committed by
Marge Bot
9e46337a da80ac3f

+29 -4
+11 -2
src/xrt/state_trackers/oxr/oxr_swapchain.c
··· 222 222 oxr_swapchain_common_wait(struct oxr_logger *log, struct oxr_swapchain *sc, XrDuration timeout) 223 223 { 224 224 uint32_t index = UINT32_MAX; 225 - if (u_index_fifo_pop(&sc->acquired.fifo, &index) != 0) { 226 - return oxr_error(log, XR_ERROR_RUNTIME_FAILURE, "u_index_fifo_pop: failed!"); 225 + if (u_index_fifo_peek(&sc->acquired.fifo, &index) != 0) { 226 + return oxr_error(log, XR_ERROR_RUNTIME_FAILURE, "u_index_fifo_peek: failed!"); 227 227 } 228 228 assert(index < INT32_MAX); 229 229 230 230 struct xrt_swapchain *xsc = (struct xrt_swapchain *)sc->swapchain; 231 231 232 232 xrt_result_t xret = xrt_swapchain_wait_image(xsc, timeout, index); 233 + if (xret == XRT_TIMEOUT) { 234 + oxr_warn(log, "call to xrt_swapchain_wait_image timeout"); 235 + return XR_TIMEOUT_EXPIRED; 236 + } 237 + 238 + if (u_index_fifo_pop(&sc->acquired.fifo, &index) != 0) { 239 + return oxr_error(log, XR_ERROR_RUNTIME_FAILURE, "u_index_fifo_pop: failed!"); 240 + } 241 + 233 242 OXR_CHECK_XRET(log, sc->sess, xret, xrt_swapchain_wait_image); 234 243 235 244 // The app can only wait on one image.
+18 -2
src/xrt/state_trackers/oxr/oxr_swapchain_vk.c
··· 61 61 CHECK_OXR_RET(oxr_swapchain_verify_wait_state(log, sc)); 62 62 63 63 uint32_t index = UINT32_MAX; 64 - if (u_index_fifo_pop(&sc->acquired.fifo, &index) != 0) { 65 - return oxr_error(log, XR_ERROR_RUNTIME_FAILURE, "u_index_fifo_pop: failed!"); 64 + if (!WAIT_IN_ACQUIRE) { 65 + if (u_index_fifo_peek(&sc->acquired.fifo, &index) != 0) { 66 + return oxr_error(log, XR_ERROR_RUNTIME_FAILURE, "u_index_fifo_peek: failed!"); 67 + } 68 + } else { 69 + if (u_index_fifo_pop(&sc->acquired.fifo, &index) != 0) { 70 + return oxr_error(log, XR_ERROR_RUNTIME_FAILURE, "u_index_fifo_pop: failed!"); 71 + } 66 72 } 73 + 67 74 assert(index < INT32_MAX); 68 75 69 76 struct xrt_swapchain *xsc = (struct xrt_swapchain *)sc->swapchain; ··· 73 80 74 81 // We have already waited in acquire. 75 82 xrt_result_t xret = xrt_swapchain_wait_image(xsc, timeout, index); 83 + if (xret == XRT_TIMEOUT) { 84 + oxr_warn(log, "call to xrt_swapchain_wait_image timeout"); 85 + return XR_TIMEOUT_EXPIRED; 86 + } 87 + 88 + if (u_index_fifo_pop(&sc->acquired.fifo, &index) != 0) { 89 + return oxr_error(log, XR_ERROR_RUNTIME_FAILURE, "u_index_fifo_pop: failed!"); 90 + } 91 + 76 92 OXR_CHECK_XRET(log, sc->sess, xret, xrt_swapchain_wait_image); 77 93 } 78 94