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)
/*
*
* Implementation in oxr_verify.cpp

View file

@ -40,6 +40,7 @@
#include "oxr_chain.h"
#include "oxr_pretty_print.h"
#include "oxr_conversions.h"
#include "oxr_xret.h"
#include <stdio.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_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
should_render(XrSessionState state)
{
@ -144,7 +140,9 @@ oxr_session_begin(struct oxr_logger *log, struct oxr_session *sess, const XrSess
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;
@ -176,7 +174,8 @@ oxr_session_end(struct oxr_logger *log, struct oxr_session *sess)
}
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);
@ -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_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) {
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;
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;
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;
}
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.waited = -1;
}

View file

@ -30,6 +30,7 @@
#include "oxr_chain.h"
#include "oxr_api_verify.h"
#include "oxr_chain.h"
#include "oxr_xret.h"
#include <stdio.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
ns_to_ms(int64_t ns)
{
@ -936,7 +932,8 @@ submit_quad_layer(struct oxr_session *sess,
data.quad.size = *size;
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;
}
@ -1027,20 +1024,26 @@ submit_projection_layer(struct oxr_session *sess,
if (d_scs[0] != NULL && d_scs[1] != NULL) {
#ifdef XRT_FEATURE_OPENXR_LAYER_DEPTH
data.type = XRT_LAYER_STEREO_PROJECTION_DEPTH;
CALL_CHK(xrt_comp_layer_stereo_projection_depth(xc, head,
scs[0]->swapchain, // Left
scs[1]->swapchain, // Right
d_scs[0]->swapchain, // Left
d_scs[1]->swapchain, // Right
&data));
xrt_result_t xret = xrt_comp_layer_stereo_projection_depth( //
xc, // compositor
head, // xdev
scs[0]->swapchain, // left
scs[1]->swapchain, // right
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
assert(false && "Should not get here");
#endif // XRT_FEATURE_OPENXR_LAYER_DEPTH
} else {
CALL_CHK(xrt_comp_layer_stereo_projection(xc, head,
scs[0]->swapchain, // Left
scs[1]->swapchain, // Right
&data));
xrt_result_t xret = xrt_comp_layer_stereo_projection( //
xc, // compositor
head, // xdev
scs[0]->swapchain, // left
scs[1]->swapchain, // right
&data); // data
OXR_CHECK_XRET(log, sess, xret, "xrt_comp_layer_stereo_projection");
}
return XR_SUCCESS;
@ -1090,7 +1093,8 @@ submit_cube_layer(struct oxr_session *sess,
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;
}
@ -1136,7 +1140,8 @@ submit_cylinder_layer(struct oxr_session *sess,
data.cylinder.aspect_ratio = cylinder->aspectRatio;
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;
}
@ -1185,7 +1190,8 @@ submit_equirect1_layer(struct oxr_session *sess,
data.equirect1.scale = *scale;
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;
}
@ -1239,7 +1245,8 @@ submit_equirect2_layer(struct oxr_session *sess,
data.equirect2.lower_vertical_angle = equirect->lowerVerticalAngle;
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;
}
@ -1320,7 +1327,8 @@ oxr_session_frame_end(struct oxr_logger *log, struct oxr_session *sess, const Xr
sess->active_wait_frames--;
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_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};
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++) {
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));
sess->frame_id.begun = -1;
xret = xrt_comp_layer_commit(xc, sess->frame_id.begun, XRT_GRAPHICS_SYNC_HANDLE_INVALID);
OXR_CHECK_XRET(log, sess, xret, "xrt_comp_layer_commit");
sess->frame_id.begun = -1;
sess->frame_started = false;
os_mutex_lock(&sess->active_wait_frames_lock);

View file

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