st/oxr: Convert session IPC error to XR_ERROR_SESSION_LOST

Co-authored-by: Jakob Bornecrantz <jakob@collabora.com>
This commit is contained in:
Jarvis Huang 2023-03-31 11:19:18 +08:00 committed by Jakob Bornecrantz
parent c006ac138f
commit 95512594a0
4 changed files with 60 additions and 58 deletions

View file

@ -221,6 +221,7 @@ extern "C" {
} \ } \
} while (false) } while (false)
/* /*
* *
* Implementation in oxr_verify.cpp * Implementation in oxr_verify.cpp

View file

@ -40,6 +40,7 @@
#include "oxr_chain.h" #include "oxr_chain.h"
#include "oxr_pretty_print.h" #include "oxr_pretty_print.h"
#include "oxr_conversions.h" #include "oxr_conversions.h"
#include "oxr_xret.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -51,11 +52,6 @@ DEBUG_GET_ONCE_NUM_OPTION(ipd, "OXR_DEBUG_IPD_MM", 63)
DEBUG_GET_ONCE_NUM_OPTION(wait_frame_sleep, "OXR_DEBUG_WAIT_FRAME_EXTRA_SLEEP_MS", 0) DEBUG_GET_ONCE_NUM_OPTION(wait_frame_sleep, "OXR_DEBUG_WAIT_FRAME_EXTRA_SLEEP_MS", 0)
DEBUG_GET_ONCE_BOOL_OPTION(frame_timing_spew, "OXR_FRAME_TIMING_SPEW", false) DEBUG_GET_ONCE_BOOL_OPTION(frame_timing_spew, "OXR_FRAME_TIMING_SPEW", false)
#define CALL_CHK(call) \
if ((call) == XRT_ERROR_IPC_FAILURE) { \
return oxr_error(log, XR_ERROR_INSTANCE_LOST, "Error in function call over IPC"); \
}
static bool static bool
should_render(XrSessionState state) should_render(XrSessionState state)
{ {
@ -144,7 +140,9 @@ oxr_session_begin(struct oxr_logger *log, struct oxr_session *sess, const XrSess
view_type); view_type);
} }
CALL_CHK(xrt_comp_begin_session(xc, (enum xrt_view_type)beginInfo->primaryViewConfigurationType)); enum xrt_view_type xvt = (enum xrt_view_type)beginInfo->primaryViewConfigurationType;
xrt_result_t xret = xrt_comp_begin_session(xc, xvt);
OXR_CHECK_XRET(log, sess, xret, "xrt_comp_begin_session");
} }
sess->has_begun = true; sess->has_begun = true;
@ -176,7 +174,8 @@ oxr_session_end(struct oxr_logger *log, struct oxr_session *sess)
} }
sess->frame_started = false; sess->frame_started = false;
CALL_CHK(xrt_comp_end_session(xc)); xrt_result_t xret = xrt_comp_end_session(xc);
OXR_CHECK_XRET(log, sess, xret, "xrt_comp_end_session");
} }
oxr_session_change_state(log, sess, XR_SESSION_STATE_IDLE, 0); oxr_session_change_state(log, sess, XR_SESSION_STATE_IDLE, 0);
@ -494,7 +493,12 @@ oxr_session_frame_wait(struct oxr_logger *log, struct oxr_session *sess, XrFrame
uint64_t predicted_display_time; uint64_t predicted_display_time;
uint64_t predicted_display_period; uint64_t predicted_display_period;
CALL_CHK(xrt_comp_wait_frame(xc, &sess->frame_id.waited, &predicted_display_time, &predicted_display_period)); xrt_result_t xret = xrt_comp_wait_frame( //
xc, // compositor
&sess->frame_id.waited, // out_frame_id
&predicted_display_time, // out_predicted_display_time
&predicted_display_period); // out_predicted_display_period
OXR_CHECK_XRET(log, sess, xret, "xrt_comp_wait_frame");
if ((int64_t)predicted_display_time <= 0) { if ((int64_t)predicted_display_time <= 0) {
return oxr_error(log, XR_ERROR_RUNTIME_FAILURE, "Got a negative display time '%" PRIi64 "'", return oxr_error(log, XR_ERROR_RUNTIME_FAILURE, "Got a negative display time '%" PRIi64 "'",
@ -551,7 +555,8 @@ oxr_session_frame_begin(struct oxr_logger *log, struct oxr_session *sess)
ret = XR_FRAME_DISCARDED; ret = XR_FRAME_DISCARDED;
if (xc != NULL) { if (xc != NULL) {
CALL_CHK(xrt_comp_discard_frame(xc, sess->frame_id.begun)); xrt_result_t xret = xrt_comp_discard_frame(xc, sess->frame_id.begun);
OXR_CHECK_XRET(log, sess, xret, "xrt_comp_discard_frame");
sess->frame_id.begun = -1; sess->frame_id.begun = -1;
os_mutex_lock(&sess->active_wait_frames_lock); os_mutex_lock(&sess->active_wait_frames_lock);
@ -563,7 +568,8 @@ oxr_session_frame_begin(struct oxr_logger *log, struct oxr_session *sess)
sess->frame_started = true; sess->frame_started = true;
} }
if (xc != NULL) { if (xc != NULL) {
CALL_CHK(xrt_comp_begin_frame(xc, sess->frame_id.waited)); xrt_result_t xret = xrt_comp_begin_frame(xc, sess->frame_id.waited);
OXR_CHECK_XRET(log, sess, xret, "xrt_comp_begin_frame");
sess->frame_id.begun = sess->frame_id.waited; sess->frame_id.begun = sess->frame_id.waited;
sess->frame_id.waited = -1; sess->frame_id.waited = -1;
} }

View file

@ -30,6 +30,7 @@
#include "oxr_chain.h" #include "oxr_chain.h"
#include "oxr_api_verify.h" #include "oxr_api_verify.h"
#include "oxr_chain.h" #include "oxr_chain.h"
#include "oxr_xret.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -43,11 +44,6 @@
* *
*/ */
#define CALL_CHK(call) \
if ((call) == XRT_ERROR_IPC_FAILURE) { \
return oxr_error(log, XR_ERROR_INSTANCE_LOST, "Error in function call over IPC"); \
}
static double static double
ns_to_ms(int64_t ns) ns_to_ms(int64_t ns)
{ {
@ -936,7 +932,8 @@ submit_quad_layer(struct oxr_session *sess,
data.quad.size = *size; data.quad.size = *size;
fill_in_sub_image(sc, &quad->subImage, &data.quad.sub); fill_in_sub_image(sc, &quad->subImage, &data.quad.sub);
CALL_CHK(xrt_comp_layer_quad(xc, head, sc->swapchain, &data)); xrt_result_t xret = xrt_comp_layer_quad(xc, head, sc->swapchain, &data);
OXR_CHECK_XRET(log, sess, xret, "xrt_comp_layer_quad");
return XR_SUCCESS; return XR_SUCCESS;
} }
@ -1027,20 +1024,26 @@ submit_projection_layer(struct oxr_session *sess,
if (d_scs[0] != NULL && d_scs[1] != NULL) { if (d_scs[0] != NULL && d_scs[1] != NULL) {
#ifdef XRT_FEATURE_OPENXR_LAYER_DEPTH #ifdef XRT_FEATURE_OPENXR_LAYER_DEPTH
data.type = XRT_LAYER_STEREO_PROJECTION_DEPTH; data.type = XRT_LAYER_STEREO_PROJECTION_DEPTH;
CALL_CHK(xrt_comp_layer_stereo_projection_depth(xc, head, xrt_result_t xret = xrt_comp_layer_stereo_projection_depth( //
scs[0]->swapchain, // Left xc, // compositor
scs[1]->swapchain, // Right head, // xdev
d_scs[0]->swapchain, // Left scs[0]->swapchain, // left
d_scs[1]->swapchain, // Right scs[1]->swapchain, // right
&data)); d_scs[0]->swapchain, // left
d_scs[1]->swapchain, // right
&data); // data
OXR_CHECK_XRET(log, sess, xret, "xrt_comp_layer_stereo_projection_depth");
#else #else
assert(false && "Should not get here"); assert(false && "Should not get here");
#endif // XRT_FEATURE_OPENXR_LAYER_DEPTH #endif // XRT_FEATURE_OPENXR_LAYER_DEPTH
} else { } else {
CALL_CHK(xrt_comp_layer_stereo_projection(xc, head, xrt_result_t xret = xrt_comp_layer_stereo_projection( //
scs[0]->swapchain, // Left xc, // compositor
scs[1]->swapchain, // Right head, // xdev
&data)); scs[0]->swapchain, // left
scs[1]->swapchain, // right
&data); // data
OXR_CHECK_XRET(log, sess, xret, "xrt_comp_layer_stereo_projection");
} }
return XR_SUCCESS; return XR_SUCCESS;
@ -1090,7 +1093,8 @@ submit_cube_layer(struct oxr_session *sess,
return XR_SUCCESS; return XR_SUCCESS;
} }
CALL_CHK(xrt_comp_layer_cube(xc, head, sc->swapchain, &data)); xrt_result_t xret = xrt_comp_layer_cube(xc, head, sc->swapchain, &data);
OXR_CHECK_XRET(log, sess, xret, "xrt_comp_layer_cube");
return XR_SUCCESS; return XR_SUCCESS;
} }
@ -1136,7 +1140,8 @@ submit_cylinder_layer(struct oxr_session *sess,
data.cylinder.aspect_ratio = cylinder->aspectRatio; data.cylinder.aspect_ratio = cylinder->aspectRatio;
fill_in_sub_image(sc, &cylinder->subImage, &data.cylinder.sub); fill_in_sub_image(sc, &cylinder->subImage, &data.cylinder.sub);
CALL_CHK(xrt_comp_layer_cylinder(xc, head, sc->swapchain, &data)); xrt_result_t xret = xrt_comp_layer_cylinder(xc, head, sc->swapchain, &data);
OXR_CHECK_XRET(log, sess, xret, "xrt_comp_layer_cylinder");
return XR_SUCCESS; return XR_SUCCESS;
} }
@ -1185,7 +1190,8 @@ submit_equirect1_layer(struct oxr_session *sess,
data.equirect1.scale = *scale; data.equirect1.scale = *scale;
data.equirect1.bias = *bias; data.equirect1.bias = *bias;
CALL_CHK(xrt_comp_layer_equirect1(xc, head, sc->swapchain, &data)); xrt_result_t xret = xrt_comp_layer_equirect1(xc, head, sc->swapchain, &data);
OXR_CHECK_XRET(log, sess, xret, "xrt_comp_layer_equirect1");
return XR_SUCCESS; return XR_SUCCESS;
} }
@ -1239,7 +1245,8 @@ submit_equirect2_layer(struct oxr_session *sess,
data.equirect2.lower_vertical_angle = equirect->lowerVerticalAngle; data.equirect2.lower_vertical_angle = equirect->lowerVerticalAngle;
fill_in_sub_image(sc, &equirect->subImage, &data.equirect2.sub); fill_in_sub_image(sc, &equirect->subImage, &data.equirect2.sub);
CALL_CHK(xrt_comp_layer_equirect2(xc, head, sc->swapchain, &data)); xrt_result_t xret = xrt_comp_layer_equirect2(xc, head, sc->swapchain, &data);
OXR_CHECK_XRET(log, sess, xret, "xrt_comp_layer_equirect2");
return XR_SUCCESS; return XR_SUCCESS;
} }
@ -1320,7 +1327,8 @@ oxr_session_frame_end(struct oxr_logger *log, struct oxr_session *sess, const Xr
sess->active_wait_frames--; sess->active_wait_frames--;
os_mutex_unlock(&sess->active_wait_frames_lock); os_mutex_unlock(&sess->active_wait_frames_lock);
CALL_CHK(xrt_comp_discard_frame(xc, sess->frame_id.begun)); xrt_result_t xret = xrt_comp_discard_frame(xc, sess->frame_id.begun);
OXR_CHECK_XRET(log, sess, xret, "xrt_comp_discard_frame");
sess->frame_id.begun = -1; sess->frame_id.begun = -1;
sess->frame_started = false; sess->frame_started = false;
@ -1394,7 +1402,9 @@ oxr_session_frame_end(struct oxr_logger *log, struct oxr_session *sess, const Xr
struct xrt_pose inv_offset = {0}; struct xrt_pose inv_offset = {0};
math_pose_invert(&xdev->tracking_origin->offset, &inv_offset); math_pose_invert(&xdev->tracking_origin->offset, &inv_offset);
CALL_CHK(xrt_comp_layer_begin(xc, sess->frame_id.begun, xrt_display_time_ns, blend_mode)); xrt_result_t xret;
xret = xrt_comp_layer_begin(xc, sess->frame_id.begun, xrt_display_time_ns, blend_mode);
OXR_CHECK_XRET(log, sess, xret, "xrt_comp_layer_begin");
for (uint32_t i = 0; i < frameEndInfo->layerCount; i++) { for (uint32_t i = 0; i < frameEndInfo->layerCount; i++) {
const XrCompositionLayerBaseHeader *layer = frameEndInfo->layers[i]; const XrCompositionLayerBaseHeader *layer = frameEndInfo->layers[i];
@ -1429,9 +1439,10 @@ oxr_session_frame_end(struct oxr_logger *log, struct oxr_session *sess, const Xr
} }
} }
CALL_CHK(xrt_comp_layer_commit(xc, sess->frame_id.begun, XRT_GRAPHICS_SYNC_HANDLE_INVALID)); xret = xrt_comp_layer_commit(xc, sess->frame_id.begun, XRT_GRAPHICS_SYNC_HANDLE_INVALID);
sess->frame_id.begun = -1; OXR_CHECK_XRET(log, sess, xret, "xrt_comp_layer_commit");
sess->frame_id.begun = -1;
sess->frame_started = false; sess->frame_started = false;
os_mutex_lock(&sess->active_wait_frames_lock); os_mutex_lock(&sess->active_wait_frames_lock);

View file

@ -12,6 +12,7 @@
#include "util/u_debug.h" #include "util/u_debug.h"
#include "util/u_misc.h" #include "util/u_misc.h"
#include "oxr_xret.h"
#include "oxr_objects.h" #include "oxr_objects.h"
#include "oxr_logger.h" #include "oxr_logger.h"
#include "oxr_handle.h" #include "oxr_handle.h"
@ -34,13 +35,8 @@ oxr_swapchain_acquire_image(struct oxr_logger *log,
struct xrt_swapchain *xsc = (struct xrt_swapchain *)sc->swapchain; struct xrt_swapchain *xsc = (struct xrt_swapchain *)sc->swapchain;
xrt_result_t res = xrt_swapchain_acquire_image(xsc, &index); xrt_result_t xret = xrt_swapchain_acquire_image(xsc, &index);
if (res == XRT_ERROR_IPC_FAILURE) { OXR_CHECK_XRET(log, sc->sess, xret, "xrt_swapchain_acquire_image");
return oxr_error(log, XR_ERROR_INSTANCE_LOST, "Call to xrt_swapchain_acquire_image failed");
}
if (res != XRT_SUCCESS) {
return oxr_error(log, XR_ERROR_RUNTIME_FAILURE, "Call to xrt_swapchain_acquire_image failed");
}
if (sc->images[index].state != OXR_IMAGE_STATE_READY) { if (sc->images[index].state != OXR_IMAGE_STATE_READY) {
return oxr_error(log, XR_ERROR_RUNTIME_FAILURE, return oxr_error(log, XR_ERROR_RUNTIME_FAILURE,
@ -79,13 +75,8 @@ oxr_swapchain_wait_image(struct oxr_logger *log, struct oxr_swapchain *sc, const
struct xrt_swapchain *xsc = (struct xrt_swapchain *)sc->swapchain; struct xrt_swapchain *xsc = (struct xrt_swapchain *)sc->swapchain;
xrt_result_t res = xrt_swapchain_wait_image(xsc, waitInfo->timeout, index); xrt_result_t xret = xrt_swapchain_wait_image(xsc, waitInfo->timeout, index);
if (res == XRT_ERROR_IPC_FAILURE) { OXR_CHECK_XRET(log, sc->sess, xret, "xrt_swapchain_wait_image");
return oxr_error(log, XR_ERROR_INSTANCE_LOST, "Call to xrt_swapchain_wait_image failed");
}
if (res != XRT_SUCCESS) {
return oxr_error(log, XR_ERROR_RUNTIME_FAILURE, "Call to xrt_swapchain_wait_image failed");
}
// The app can only wait on one image. // The app can only wait on one image.
sc->waited.yes = true; sc->waited.yes = true;
@ -108,13 +99,8 @@ oxr_swapchain_release_image(struct oxr_logger *log,
uint32_t index = sc->waited.index; uint32_t index = sc->waited.index;
struct xrt_swapchain *xsc = (struct xrt_swapchain *)sc->swapchain; struct xrt_swapchain *xsc = (struct xrt_swapchain *)sc->swapchain;
xrt_result_t res = xrt_swapchain_release_image(xsc, index); xrt_result_t xret = xrt_swapchain_release_image(xsc, index);
if (res == XRT_ERROR_IPC_FAILURE) { OXR_CHECK_XRET(log, sc->sess, xret, "xrt_swapchain_release_image");
return oxr_error(log, XR_ERROR_INSTANCE_LOST, "Call to xrt_swapchain_release_image failed");
}
if (res != XRT_SUCCESS) {
return oxr_error(log, XR_ERROR_RUNTIME_FAILURE, "Call to xrt_swapchain_release_image failed");
}
// Only decerement here. // Only decerement here.
sc->acquired.num--; sc->acquired.num--;
@ -216,9 +202,7 @@ oxr_create_swapchain(struct oxr_logger *log,
return oxr_error(log, XR_ERROR_SWAPCHAIN_FORMAT_UNSUPPORTED, return oxr_error(log, XR_ERROR_SWAPCHAIN_FORMAT_UNSUPPORTED,
"Specified swapchain format is not supported"); "Specified swapchain format is not supported");
} }
if (xret != XRT_SUCCESS) { OXR_CHECK_XRET(log, sess, xret, "xrt_comp_create_swapchain");
return oxr_error(log, XR_ERROR_RUNTIME_FAILURE, "Failed to create swapchain");
}
assert(xsc != NULL); assert(xsc != NULL);
struct oxr_swapchain *sc = NULL; struct oxr_swapchain *sc = NULL;