2020-06-01 20:32:43 +00:00
|
|
|
// Copyright 2018-2020, Collabora, Ltd.
|
2019-03-18 05:52:32 +00:00
|
|
|
// SPDX-License-Identifier: BSL-1.0
|
|
|
|
/*!
|
|
|
|
* @file
|
|
|
|
* @brief Holds session related functions.
|
|
|
|
* @author Jakob Bornecrantz <jakob@collabora.com>
|
|
|
|
* @ingroup oxr_main
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2019-04-05 22:13:58 +00:00
|
|
|
#include <assert.h>
|
2020-03-02 23:35:57 +00:00
|
|
|
#include <inttypes.h>
|
2019-03-18 05:52:32 +00:00
|
|
|
|
|
|
|
#include "util/u_debug.h"
|
2019-03-23 01:11:14 +00:00
|
|
|
#include "util/u_misc.h"
|
2019-03-18 05:52:32 +00:00
|
|
|
#include "util/u_time.h"
|
2020-06-17 06:36:38 +00:00
|
|
|
#include "os/os_time.h"
|
2019-03-18 05:52:32 +00:00
|
|
|
|
2020-04-16 12:23:12 +00:00
|
|
|
#include "math/m_api.h"
|
|
|
|
|
2019-03-18 05:52:32 +00:00
|
|
|
#include "xrt/xrt_device.h"
|
2020-07-16 10:17:30 +00:00
|
|
|
#ifdef XR_USE_PLATFORM_XLIB
|
2019-03-18 05:52:32 +00:00
|
|
|
#include "xrt/xrt_gfx_xlib.h"
|
2020-07-16 10:17:30 +00:00
|
|
|
#endif // XR_USE_PLATFORM_XLIB
|
|
|
|
#ifdef XRT_HAVE_VULKAN
|
2019-03-18 05:52:32 +00:00
|
|
|
#include "xrt/xrt_gfx_vk.h"
|
2020-07-16 10:17:30 +00:00
|
|
|
#endif // XRT_HAVE_VULKAN
|
2019-03-18 05:52:32 +00:00
|
|
|
|
|
|
|
#include "oxr_objects.h"
|
|
|
|
#include "oxr_logger.h"
|
|
|
|
#include "oxr_two_call.h"
|
2019-04-05 19:18:03 +00:00
|
|
|
#include "oxr_handle.h"
|
2019-06-03 19:17:45 +00:00
|
|
|
#include "oxr_chain.h"
|
2020-05-22 11:53:23 +00:00
|
|
|
#include "oxr_api_verify.h"
|
2019-03-18 05:52:32 +00:00
|
|
|
|
|
|
|
|
2019-03-25 22:26:57 +00:00
|
|
|
DEBUG_GET_ONCE_BOOL_OPTION(dynamic_prediction, "OXR_DYNAMIC_PREDICTION", true)
|
2019-03-18 05:52:32 +00:00
|
|
|
DEBUG_GET_ONCE_NUM_OPTION(ipd, "OXR_DEBUG_IPD_MM", 63)
|
|
|
|
DEBUG_GET_ONCE_NUM_OPTION(prediction_ms, "OXR_DEBUG_PREDICTION_MS", 11)
|
|
|
|
|
2020-06-04 14:56:25 +00:00
|
|
|
#define CALL_CHK(call) \
|
|
|
|
if ((call) == XRT_ERROR_IPC_FAILURE) { \
|
|
|
|
return oxr_error(log, XR_ERROR_INSTANCE_LOST, \
|
|
|
|
"Error in function call over IPC"); \
|
|
|
|
}
|
|
|
|
|
2019-03-18 05:52:32 +00:00
|
|
|
static bool
|
2020-05-30 17:30:27 +00:00
|
|
|
is_running(struct oxr_session *sess)
|
2019-03-18 05:52:32 +00:00
|
|
|
{
|
2020-05-30 17:30:27 +00:00
|
|
|
return sess->has_begun;
|
2019-07-13 16:17:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
should_render(XrSessionState state)
|
|
|
|
{
|
|
|
|
switch (state) {
|
2019-03-18 05:52:32 +00:00
|
|
|
case XR_SESSION_STATE_VISIBLE: return true;
|
|
|
|
case XR_SESSION_STATE_FOCUSED: return true;
|
2019-10-22 12:35:09 +00:00
|
|
|
case XR_SESSION_STATE_STOPPING: return true;
|
2019-03-18 05:52:32 +00:00
|
|
|
default: return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-30 17:30:27 +00:00
|
|
|
XRT_MAYBE_UNUSED static const char *
|
|
|
|
to_string(XrSessionState state)
|
|
|
|
{
|
|
|
|
switch (state) {
|
|
|
|
case XR_SESSION_STATE_UNKNOWN: return "XR_SESSION_STATE_UNKNOWN";
|
|
|
|
case XR_SESSION_STATE_IDLE: return "XR_SESSION_STATE_IDLE";
|
|
|
|
case XR_SESSION_STATE_READY: return "XR_SESSION_STATE_READY";
|
|
|
|
case XR_SESSION_STATE_SYNCHRONIZED:
|
|
|
|
return "XR_SESSION_STATE_SYNCHRONIZED";
|
|
|
|
case XR_SESSION_STATE_VISIBLE: return "XR_SESSION_STATE_VISIBLE";
|
|
|
|
case XR_SESSION_STATE_FOCUSED: return "XR_SESSION_STATE_FOCUSED";
|
|
|
|
case XR_SESSION_STATE_STOPPING: return "XR_SESSION_STATE_STOPPING";
|
|
|
|
case XR_SESSION_STATE_LOSS_PENDING:
|
|
|
|
return "XR_SESSION_STATE_LOSS_PENDING";
|
|
|
|
case XR_SESSION_STATE_EXITING: return "XR_SESSION_STATE_EXITING";
|
|
|
|
case XR_SESSION_STATE_MAX_ENUM: return "XR_SESSION_STATE_MAX_ENUM";
|
|
|
|
default: return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-22 12:35:09 +00:00
|
|
|
static void
|
|
|
|
oxr_session_change_state(struct oxr_logger *log,
|
|
|
|
struct oxr_session *sess,
|
|
|
|
XrSessionState state)
|
|
|
|
{
|
|
|
|
oxr_event_push_XrEventDataSessionStateChanged(log, sess, state, 0);
|
|
|
|
sess->state = state;
|
|
|
|
}
|
|
|
|
|
2019-03-18 05:52:32 +00:00
|
|
|
XrResult
|
|
|
|
oxr_session_enumerate_formats(struct oxr_logger *log,
|
|
|
|
struct oxr_session *sess,
|
|
|
|
uint32_t formatCapacityInput,
|
|
|
|
uint32_t *formatCountOutput,
|
|
|
|
int64_t *formats)
|
|
|
|
{
|
|
|
|
struct xrt_compositor *xc = sess->compositor;
|
2019-06-05 19:14:18 +00:00
|
|
|
if (formatCountOutput == NULL) {
|
|
|
|
return oxr_error(log, XR_ERROR_VALIDATION_FAILURE,
|
2020-05-31 15:49:25 +00:00
|
|
|
"(formatCountOutput == NULL) can not be null");
|
2019-06-05 19:14:18 +00:00
|
|
|
}
|
2019-03-23 01:11:14 +00:00
|
|
|
if (xc == NULL) {
|
2019-06-05 19:14:18 +00:00
|
|
|
if (formatCountOutput != NULL) {
|
|
|
|
*formatCountOutput = 0;
|
|
|
|
}
|
2019-09-26 20:25:05 +00:00
|
|
|
return oxr_session_success_result(sess);
|
2019-03-23 01:11:14 +00:00
|
|
|
}
|
2019-03-18 05:52:32 +00:00
|
|
|
|
|
|
|
OXR_TWO_CALL_HELPER(log, formatCapacityInput, formatCountOutput,
|
2020-07-30 17:01:17 +00:00
|
|
|
formats, xc->info.num_formats, xc->info.formats,
|
2019-09-26 20:25:05 +00:00
|
|
|
oxr_session_success_result(sess));
|
2019-03-18 05:52:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
XrResult
|
|
|
|
oxr_session_begin(struct oxr_logger *log,
|
|
|
|
struct oxr_session *sess,
|
|
|
|
const XrSessionBeginInfo *beginInfo)
|
|
|
|
{
|
2020-05-30 17:30:27 +00:00
|
|
|
if (is_running(sess)) {
|
2019-03-18 05:52:32 +00:00
|
|
|
return oxr_error(log, XR_ERROR_SESSION_RUNNING,
|
2020-05-31 15:49:25 +00:00
|
|
|
"Session is already running");
|
2019-03-18 05:52:32 +00:00
|
|
|
}
|
2020-05-30 17:30:27 +00:00
|
|
|
|
2019-03-18 05:52:32 +00:00
|
|
|
struct xrt_compositor *xc = sess->compositor;
|
2019-03-23 01:11:14 +00:00
|
|
|
if (xc != NULL) {
|
2019-08-14 22:15:15 +00:00
|
|
|
XrViewConfigurationType view_type =
|
|
|
|
beginInfo->primaryViewConfigurationType;
|
|
|
|
|
|
|
|
if (view_type != sess->sys->view_config_type) {
|
|
|
|
/*! @todo we only support a single view config type per
|
|
|
|
* system right now */
|
|
|
|
return oxr_error(
|
|
|
|
log, XR_ERROR_VIEW_CONFIGURATION_TYPE_UNSUPPORTED,
|
2020-05-31 15:49:25 +00:00
|
|
|
"(beginInfo->primaryViewConfigurationType == "
|
|
|
|
"0x%08x) view configuration type not supported",
|
|
|
|
view_type);
|
2019-08-14 22:15:15 +00:00
|
|
|
}
|
|
|
|
|
2020-06-04 14:56:25 +00:00
|
|
|
CALL_CHK(xrt_comp_begin_session(
|
|
|
|
xc, (enum xrt_view_type)
|
|
|
|
beginInfo->primaryViewConfigurationType));
|
2019-03-23 01:11:14 +00:00
|
|
|
}
|
2019-03-18 05:52:32 +00:00
|
|
|
|
2020-05-30 17:30:27 +00:00
|
|
|
sess->has_begun = true;
|
2019-03-18 05:52:32 +00:00
|
|
|
|
2019-09-26 20:25:05 +00:00
|
|
|
return oxr_session_success_result(sess);
|
2019-03-18 05:52:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
XrResult
|
|
|
|
oxr_session_end(struct oxr_logger *log, struct oxr_session *sess)
|
|
|
|
{
|
|
|
|
struct xrt_compositor *xc = sess->compositor;
|
|
|
|
|
2020-05-30 17:30:27 +00:00
|
|
|
if (!is_running(sess)) {
|
2019-03-18 05:52:32 +00:00
|
|
|
return oxr_error(log, XR_ERROR_SESSION_NOT_RUNNING,
|
2020-05-31 15:49:25 +00:00
|
|
|
"Session is not running");
|
2019-03-18 05:52:32 +00:00
|
|
|
}
|
2019-10-22 12:35:09 +00:00
|
|
|
if (sess->state != XR_SESSION_STATE_STOPPING) {
|
|
|
|
return oxr_error(log, XR_ERROR_SESSION_NOT_STOPPING,
|
2020-05-31 15:49:25 +00:00
|
|
|
"Session is not stopping");
|
2019-10-22 12:35:09 +00:00
|
|
|
}
|
2019-03-18 05:52:32 +00:00
|
|
|
|
2019-03-23 01:11:14 +00:00
|
|
|
if (xc != NULL) {
|
2020-06-23 16:11:39 +00:00
|
|
|
if (sess->frame_id.waited > 0) {
|
|
|
|
xrt_comp_discard_frame(xc, sess->frame_id.waited);
|
|
|
|
sess->frame_id.waited = -1;
|
2019-03-23 01:11:14 +00:00
|
|
|
}
|
2020-06-23 16:11:39 +00:00
|
|
|
if (sess->frame_id.begun > 0) {
|
|
|
|
xrt_comp_discard_frame(xc, sess->frame_id.begun);
|
|
|
|
sess->frame_id.begun = -1;
|
|
|
|
}
|
|
|
|
sess->frame_started = false;
|
2019-03-18 05:52:32 +00:00
|
|
|
|
2020-06-04 14:56:25 +00:00
|
|
|
CALL_CHK(xrt_comp_end_session(xc));
|
2019-03-23 01:11:14 +00:00
|
|
|
}
|
2019-03-18 05:52:32 +00:00
|
|
|
|
2019-10-22 12:35:09 +00:00
|
|
|
oxr_session_change_state(log, sess, XR_SESSION_STATE_IDLE);
|
2019-10-22 18:51:37 +00:00
|
|
|
if (sess->exiting) {
|
|
|
|
oxr_session_change_state(log, sess, XR_SESSION_STATE_EXITING);
|
|
|
|
}
|
2020-05-30 17:30:27 +00:00
|
|
|
|
|
|
|
oxr_session_change_state(log, sess, XR_SESSION_STATE_READY);
|
|
|
|
|
|
|
|
sess->has_begun = false;
|
|
|
|
|
2019-10-22 12:35:09 +00:00
|
|
|
return oxr_session_success_result(sess);
|
|
|
|
}
|
2019-03-18 05:52:32 +00:00
|
|
|
|
2019-10-22 12:35:09 +00:00
|
|
|
XrResult
|
|
|
|
oxr_session_request_exit(struct oxr_logger *log, struct oxr_session *sess)
|
|
|
|
{
|
2020-05-30 17:30:27 +00:00
|
|
|
if (!is_running(sess)) {
|
2019-10-22 12:35:09 +00:00
|
|
|
return oxr_error(log, XR_ERROR_SESSION_NOT_RUNNING,
|
2020-05-31 15:49:25 +00:00
|
|
|
"Session is not running");
|
2019-10-22 12:35:09 +00:00
|
|
|
}
|
2020-05-30 17:30:27 +00:00
|
|
|
|
2019-10-22 12:35:09 +00:00
|
|
|
if (sess->state == XR_SESSION_STATE_FOCUSED) {
|
|
|
|
oxr_session_change_state(log, sess, XR_SESSION_STATE_VISIBLE);
|
|
|
|
}
|
|
|
|
if (sess->state == XR_SESSION_STATE_VISIBLE) {
|
|
|
|
oxr_session_change_state(log, sess,
|
|
|
|
XR_SESSION_STATE_SYNCHRONIZED);
|
|
|
|
}
|
2020-05-30 17:30:27 +00:00
|
|
|
if (!sess->has_waited_once) {
|
|
|
|
oxr_session_change_state(log, sess,
|
|
|
|
XR_SESSION_STATE_SYNCHRONIZED);
|
|
|
|
// Fake the synchronization.
|
|
|
|
sess->has_waited_once = true;
|
|
|
|
}
|
|
|
|
|
2019-10-22 12:35:09 +00:00
|
|
|
//! @todo start fading out the app.
|
|
|
|
oxr_session_change_state(log, sess, XR_SESSION_STATE_STOPPING);
|
2019-10-22 18:51:37 +00:00
|
|
|
sess->exiting = true;
|
2019-10-22 12:35:09 +00:00
|
|
|
return oxr_session_success_result(sess);
|
2019-03-18 05:52:32 +00:00
|
|
|
}
|
|
|
|
|
2019-10-08 15:24:16 +00:00
|
|
|
void
|
2020-06-17 06:36:38 +00:00
|
|
|
oxr_session_poll(struct oxr_logger *log, struct oxr_session *sess)
|
2019-10-08 15:24:16 +00:00
|
|
|
{
|
|
|
|
struct xrt_compositor *xc = sess->compositor;
|
2020-08-10 14:50:28 +00:00
|
|
|
if (xc == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-06-17 06:36:38 +00:00
|
|
|
while (true) {
|
2020-08-10 14:50:28 +00:00
|
|
|
union xrt_compositor_event xce = {0};
|
2020-06-17 06:36:38 +00:00
|
|
|
xc->poll_events(xc, &xce);
|
|
|
|
|
|
|
|
// dispatch based on event type
|
|
|
|
switch (xce.type) {
|
|
|
|
case XRT_COMPOSITOR_EVENT_NONE:
|
|
|
|
// No more events.
|
|
|
|
return;
|
|
|
|
case XRT_COMPOSITOR_EVENT_STATE_CHANGE:
|
|
|
|
if (xce.state.visible &&
|
|
|
|
sess->state == XR_SESSION_STATE_SYNCHRONIZED) {
|
|
|
|
oxr_session_change_state(
|
|
|
|
log, sess, XR_SESSION_STATE_VISIBLE);
|
|
|
|
}
|
|
|
|
if (xce.state.focused &&
|
|
|
|
sess->state == XR_SESSION_STATE_VISIBLE) {
|
|
|
|
oxr_session_change_state(
|
|
|
|
log, sess, XR_SESSION_STATE_FOCUSED);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!xce.state.focused &&
|
|
|
|
sess->state == XR_SESSION_STATE_FOCUSED) {
|
|
|
|
oxr_session_change_state(
|
|
|
|
log, sess, XR_SESSION_STATE_VISIBLE);
|
|
|
|
}
|
|
|
|
if (!xce.state.visible &&
|
|
|
|
sess->state == XR_SESSION_STATE_VISIBLE) {
|
|
|
|
oxr_session_change_state(
|
|
|
|
log, sess, XR_SESSION_STATE_SYNCHRONIZED);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case XRT_COMPOSITOR_EVENT_OVERLAY_CHANGE:
|
|
|
|
oxr_event_push_XrEventDataMainSessionVisibilityChangedEXTX(
|
|
|
|
log, sess, xce.overlay.visible);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fprintf(stderr, "unhandled event type! %d", xce.type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-10-08 15:24:16 +00:00
|
|
|
}
|
|
|
|
|
2019-03-18 05:52:32 +00:00
|
|
|
XrResult
|
|
|
|
oxr_session_get_view_pose_at(struct oxr_logger *log,
|
|
|
|
struct oxr_session *sess,
|
|
|
|
XrTime at_time,
|
|
|
|
struct xrt_pose *pose)
|
|
|
|
{
|
|
|
|
// @todo This function needs to be massively expanded to support all
|
|
|
|
// use cases this drive. The main use of this function is to get
|
|
|
|
// either the predicted position of the headset device. Right now
|
|
|
|
// it only returns the current position. But it must also deal
|
|
|
|
// with past values are allowed by the spec. See displayTime
|
|
|
|
// argument on the xrLocateViews function. It will also drive
|
|
|
|
// the function xrLocateSpace view using the view space.
|
|
|
|
// @todo If using orientation tracking only implement a neck model to
|
|
|
|
// get at least a slightly better position.
|
|
|
|
|
2020-07-07 00:14:29 +00:00
|
|
|
struct xrt_device *xdev = GET_XDEV_BY_ROLE(sess->sys, head);
|
2019-03-18 05:52:32 +00:00
|
|
|
struct xrt_space_relation relation;
|
2020-04-16 12:23:12 +00:00
|
|
|
uint64_t timestamp;
|
2019-05-07 12:47:18 +00:00
|
|
|
|
2020-04-16 12:23:12 +00:00
|
|
|
// Applies the offset in the function.
|
|
|
|
oxr_xdev_get_relation_at(log, sess->sys->inst, xdev,
|
|
|
|
XRT_INPUT_GENERIC_HEAD_POSE, at_time,
|
|
|
|
×tamp, &relation);
|
2019-05-07 12:47:18 +00:00
|
|
|
|
|
|
|
// clang-format off
|
2020-04-16 12:23:12 +00:00
|
|
|
*pose = relation.pose;
|
|
|
|
|
2019-05-07 12:47:18 +00:00
|
|
|
bool valid_vel = (relation.relation_flags & XRT_SPACE_RELATION_ANGULAR_VELOCITY_VALID_BIT) != 0;
|
|
|
|
// clang-format on
|
|
|
|
|
2019-03-18 05:52:32 +00:00
|
|
|
|
2019-05-07 12:47:18 +00:00
|
|
|
if (valid_vel) {
|
2019-03-18 05:52:32 +00:00
|
|
|
//! @todo Forcing a fixed amount of prediction for now since
|
|
|
|
//! devices don't tell us timestamps yet.
|
2019-03-22 16:07:02 +00:00
|
|
|
int64_t ns_diff = at_time - timestamp;
|
|
|
|
float interval;
|
|
|
|
if (debug_get_bool_option_dynamic_prediction()) {
|
|
|
|
interval =
|
|
|
|
time_ns_to_s(ns_diff) + sess->static_prediction_s;
|
|
|
|
} else {
|
|
|
|
interval = sess->static_prediction_s;
|
|
|
|
}
|
|
|
|
|
2019-03-18 05:52:32 +00:00
|
|
|
struct xrt_quat predicted;
|
2019-03-22 16:07:02 +00:00
|
|
|
math_quat_integrate_velocity(&pose->orientation,
|
|
|
|
&relation.angular_velocity,
|
|
|
|
interval, &predicted);
|
2019-03-18 05:52:32 +00:00
|
|
|
|
2019-10-22 10:47:25 +00:00
|
|
|
if (sess->sys->inst->debug_views) {
|
2019-03-22 16:07:02 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"\toriginal quat = {%f, %f, %f, %f} "
|
2020-03-02 23:35:57 +00:00
|
|
|
"(time requested: %" PRIi64
|
|
|
|
", Interval %" PRIi64
|
|
|
|
" nsec, with "
|
2019-03-22 16:07:02 +00:00
|
|
|
"static interval %f s)\n",
|
|
|
|
pose->orientation.x, pose->orientation.y,
|
|
|
|
pose->orientation.z, pose->orientation.w,
|
|
|
|
at_time, ns_diff, interval);
|
2019-03-18 05:52:32 +00:00
|
|
|
}
|
2019-05-07 12:47:18 +00:00
|
|
|
|
2019-03-18 05:52:32 +00:00
|
|
|
pose->orientation = predicted;
|
|
|
|
}
|
|
|
|
|
2019-09-26 20:25:05 +00:00
|
|
|
return oxr_session_success_result(sess);
|
2019-03-18 05:52:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-10-22 10:47:25 +00:00
|
|
|
print_view_fov(struct oxr_session *sess,
|
|
|
|
uint32_t index,
|
|
|
|
const struct xrt_fov *fov)
|
2019-03-18 05:52:32 +00:00
|
|
|
{
|
2019-10-22 10:47:25 +00:00
|
|
|
if (!sess->sys->inst->debug_views) {
|
2019-03-18 05:52:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(stderr, "\tviews[%i].fov = {%f, %f, %f, %f}\n", index,
|
|
|
|
fov->angle_left, fov->angle_right, fov->angle_up,
|
|
|
|
fov->angle_down);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-10-22 10:47:25 +00:00
|
|
|
print_view_pose(struct oxr_session *sess,
|
|
|
|
uint32_t index,
|
|
|
|
const struct xrt_pose *pose)
|
2019-03-18 05:52:32 +00:00
|
|
|
{
|
2019-10-22 10:47:25 +00:00
|
|
|
if (!sess->sys->inst->debug_views) {
|
2019-03-18 05:52:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(stderr, "\tviews[%i].pose = {{%f, %f, %f, %f}, {%f, %f, %f}}\n",
|
|
|
|
index, pose->orientation.x, pose->orientation.y,
|
|
|
|
pose->orientation.z, pose->orientation.w, pose->position.x,
|
|
|
|
pose->position.y, pose->position.z);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
XrResult
|
|
|
|
oxr_session_views(struct oxr_logger *log,
|
|
|
|
struct oxr_session *sess,
|
|
|
|
const XrViewLocateInfo *viewLocateInfo,
|
|
|
|
XrViewState *viewState,
|
|
|
|
uint32_t viewCapacityInput,
|
|
|
|
uint32_t *viewCountOutput,
|
|
|
|
XrView *views)
|
|
|
|
{
|
2020-07-07 00:14:29 +00:00
|
|
|
struct xrt_device *xdev = GET_XDEV_BY_ROLE(sess->sys, head);
|
2020-04-28 22:51:39 +00:00
|
|
|
struct oxr_space *baseSpc = XRT_CAST_OXR_HANDLE_TO_PTR(
|
|
|
|
struct oxr_space *, viewLocateInfo->space);
|
2019-03-18 05:52:32 +00:00
|
|
|
uint32_t num_views = 2;
|
|
|
|
|
|
|
|
// Does this apply for all calls?
|
|
|
|
if (!baseSpc->is_reference) {
|
|
|
|
viewState->viewStateFlags = 0;
|
2019-09-26 20:25:05 +00:00
|
|
|
return oxr_session_success_result(sess);
|
2019-03-18 05:52:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Start two call handling.
|
|
|
|
if (viewCountOutput != NULL) {
|
|
|
|
*viewCountOutput = num_views;
|
|
|
|
}
|
|
|
|
if (viewCapacityInput == 0) {
|
2019-09-26 20:25:05 +00:00
|
|
|
return oxr_session_success_result(sess);
|
2019-03-18 05:52:32 +00:00
|
|
|
}
|
|
|
|
if (viewCapacityInput < num_views) {
|
|
|
|
return oxr_error(log, XR_ERROR_SIZE_INSUFFICIENT,
|
|
|
|
"(viewCapacityInput == %u) need %u",
|
|
|
|
viewCapacityInput, num_views);
|
|
|
|
}
|
|
|
|
// End two call handling.
|
|
|
|
|
2019-10-22 10:47:25 +00:00
|
|
|
if (sess->sys->inst->debug_views) {
|
2019-03-18 05:52:32 +00:00
|
|
|
fprintf(stderr, "%s\n", __func__);
|
2020-03-02 23:35:57 +00:00
|
|
|
fprintf(stderr, "\tviewLocateInfo->displayTime %" PRIu64 "\n",
|
2019-03-18 05:52:32 +00:00
|
|
|
viewLocateInfo->displayTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the viewLocateInfo->space to view space relation.
|
|
|
|
struct xrt_space_relation pure_relation;
|
|
|
|
oxr_space_ref_relation(log, sess, XR_REFERENCE_SPACE_TYPE_VIEW,
|
|
|
|
baseSpc->type, viewLocateInfo->displayTime,
|
|
|
|
&pure_relation);
|
|
|
|
|
|
|
|
struct xrt_pose pure = pure_relation.pose;
|
|
|
|
|
2019-05-07 12:47:18 +00:00
|
|
|
// @todo the fov information that we get from xdev->hmd->views[i].fov is
|
|
|
|
// not properly filled out in oh_device.c, fix before wasting time
|
|
|
|
// on debugging weird rendering when adding stuff here.
|
2019-03-18 05:52:32 +00:00
|
|
|
|
|
|
|
for (uint32_t i = 0; i < num_views; i++) {
|
|
|
|
//! @todo Do not hardcode IPD.
|
|
|
|
struct xrt_vec3 eye_relation = {
|
|
|
|
sess->ipd_meters,
|
|
|
|
0.0f,
|
|
|
|
0.0f,
|
|
|
|
};
|
|
|
|
struct xrt_pose view_pose;
|
|
|
|
|
|
|
|
// Get the per view pose from the device.
|
|
|
|
xdev->get_view_pose(xdev, &eye_relation, i, &view_pose);
|
|
|
|
|
|
|
|
// Do the magical space relation dance here.
|
|
|
|
math_pose_openxr_locate(&view_pose, &pure, &baseSpc->pose,
|
|
|
|
(struct xrt_pose *)&views[i].pose);
|
|
|
|
|
|
|
|
// Copy the fov information directly from the device.
|
2019-09-06 14:35:41 +00:00
|
|
|
union {
|
|
|
|
struct xrt_fov xrt;
|
|
|
|
XrFovf oxr;
|
|
|
|
} safe_copy = {0};
|
|
|
|
safe_copy.xrt = xdev->hmd->views[i].fov;
|
|
|
|
views[i].fov = safe_copy.oxr;
|
2019-03-18 05:52:32 +00:00
|
|
|
|
2020-06-17 11:19:34 +00:00
|
|
|
struct xrt_pose *pose = (struct xrt_pose *)&views[i].pose;
|
|
|
|
if (!math_quat_ensure_normalized(&pose->orientation)) {
|
2020-06-16 13:39:16 +00:00
|
|
|
return oxr_error(
|
|
|
|
log, XR_ERROR_RUNTIME_FAILURE,
|
|
|
|
"Quaternion in xrLocateViews was invalid");
|
|
|
|
}
|
|
|
|
|
2019-10-22 10:47:25 +00:00
|
|
|
print_view_fov(sess, i, (struct xrt_fov *)&views[i].fov);
|
|
|
|
print_view_pose(sess, i, (struct xrt_pose *)&views[i].pose);
|
2019-03-18 05:52:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// @todo Add tracking bit once we have them.
|
|
|
|
viewState->viewStateFlags = 0;
|
|
|
|
viewState->viewStateFlags |= XR_VIEW_STATE_POSITION_VALID_BIT;
|
|
|
|
viewState->viewStateFlags |= XR_VIEW_STATE_ORIENTATION_VALID_BIT;
|
|
|
|
|
2019-09-26 20:25:05 +00:00
|
|
|
return oxr_session_success_result(sess);
|
2019-03-18 05:52:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
XrResult
|
|
|
|
oxr_session_frame_wait(struct oxr_logger *log,
|
|
|
|
struct oxr_session *sess,
|
|
|
|
XrFrameState *frameState)
|
|
|
|
{
|
2020-05-30 17:30:27 +00:00
|
|
|
if (!is_running(sess)) {
|
2019-03-18 05:52:32 +00:00
|
|
|
return oxr_error(log, XR_ERROR_SESSION_NOT_RUNNING,
|
2020-05-31 15:49:25 +00:00
|
|
|
"Session is not running");
|
2019-03-18 05:52:32 +00:00
|
|
|
}
|
|
|
|
|
2020-06-23 17:02:08 +00:00
|
|
|
|
2019-03-18 03:34:07 +00:00
|
|
|
//! @todo this should be carefully synchronized, because there may be
|
|
|
|
//! more than one session per instance.
|
2019-04-01 16:07:23 +00:00
|
|
|
XRT_MAYBE_UNUSED timepoint_ns now =
|
2019-03-18 05:52:32 +00:00
|
|
|
time_state_get_now_and_update(sess->sys->inst->timekeeping);
|
|
|
|
|
|
|
|
struct xrt_compositor *xc = sess->compositor;
|
2020-05-26 17:22:09 +00:00
|
|
|
if (xc == NULL) {
|
2019-10-22 15:53:07 +00:00
|
|
|
frameState->shouldRender = XR_FALSE;
|
2020-05-26 17:22:09 +00:00
|
|
|
return oxr_session_success_result(sess);
|
|
|
|
}
|
|
|
|
|
2020-06-23 17:02:08 +00:00
|
|
|
// Before calling wait frame make sure that begin frame has been called.
|
|
|
|
os_semaphore_wait(&sess->sem, 0);
|
|
|
|
|
2020-05-26 17:22:09 +00:00
|
|
|
uint64_t predicted_display_time;
|
|
|
|
uint64_t predicted_display_period;
|
2020-06-23 16:11:39 +00:00
|
|
|
CALL_CHK(xrt_comp_wait_frame(xc, &sess->frame_id.waited,
|
|
|
|
&predicted_display_time,
|
2020-06-04 14:56:25 +00:00
|
|
|
&predicted_display_period));
|
2020-05-26 17:22:09 +00:00
|
|
|
|
2020-05-27 17:02:24 +00:00
|
|
|
if ((int64_t)predicted_display_time <= 0) {
|
2020-05-26 17:22:09 +00:00
|
|
|
return oxr_error(log, XR_ERROR_RUNTIME_FAILURE,
|
2020-05-31 15:49:25 +00:00
|
|
|
"Got a negative display time '%" PRIi64 "'",
|
2020-05-26 17:22:09 +00:00
|
|
|
(int64_t)predicted_display_time);
|
|
|
|
}
|
|
|
|
|
|
|
|
frameState->shouldRender = should_render(sess->state);
|
|
|
|
frameState->predictedDisplayPeriod = predicted_display_period;
|
2020-05-26 19:09:56 +00:00
|
|
|
frameState->predictedDisplayTime = time_state_monotonic_to_ts_ns(
|
2020-05-26 17:22:09 +00:00
|
|
|
sess->sys->inst->timekeeping, predicted_display_time);
|
|
|
|
|
|
|
|
if (frameState->predictedDisplayTime <= 0) {
|
|
|
|
return oxr_error(
|
|
|
|
log, XR_ERROR_RUNTIME_FAILURE,
|
2020-05-31 15:49:25 +00:00
|
|
|
"Time_state_monotonic_to_ts_ns returned '%" PRIi64 "'",
|
2020-05-26 17:22:09 +00:00
|
|
|
frameState->predictedDisplayTime);
|
2019-10-22 15:53:07 +00:00
|
|
|
}
|
2019-07-13 16:17:57 +00:00
|
|
|
|
2020-06-17 06:36:38 +00:00
|
|
|
if (!sess->has_waited_once && sess->state < XR_SESSION_STATE_VISIBLE) {
|
2020-05-30 17:30:27 +00:00
|
|
|
oxr_session_change_state(log, sess,
|
|
|
|
XR_SESSION_STATE_SYNCHRONIZED);
|
2020-06-17 06:36:38 +00:00
|
|
|
// oxr_session_change_state(log, sess,
|
|
|
|
// XR_SESSION_STATE_VISIBLE); //these states will be handled by
|
|
|
|
// messages received from the compositor
|
|
|
|
// oxr_session_change_state(log, sess,
|
|
|
|
// XR_SESSION_STATE_FOCUSED); //these states will be handled by
|
|
|
|
// messages received from the compositor
|
2020-05-30 17:30:27 +00:00
|
|
|
sess->has_waited_once = true;
|
|
|
|
}
|
|
|
|
|
2019-09-26 20:25:05 +00:00
|
|
|
return oxr_session_success_result(sess);
|
2019-03-18 05:52:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
XrResult
|
|
|
|
oxr_session_frame_begin(struct oxr_logger *log, struct oxr_session *sess)
|
|
|
|
{
|
2020-05-30 17:30:27 +00:00
|
|
|
if (!is_running(sess)) {
|
2019-03-18 05:52:32 +00:00
|
|
|
return oxr_error(log, XR_ERROR_SESSION_NOT_RUNNING,
|
2020-05-31 15:49:25 +00:00
|
|
|
"Session is not running");
|
2019-03-18 05:52:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct xrt_compositor *xc = sess->compositor;
|
|
|
|
|
|
|
|
XrResult ret;
|
|
|
|
if (sess->frame_started) {
|
|
|
|
ret = XR_FRAME_DISCARDED;
|
2019-03-26 20:43:15 +00:00
|
|
|
if (xc != NULL) {
|
2020-06-23 16:11:39 +00:00
|
|
|
CALL_CHK(
|
|
|
|
xrt_comp_discard_frame(xc, sess->frame_id.begun));
|
|
|
|
sess->frame_id.begun = -1;
|
2019-03-26 20:43:15 +00:00
|
|
|
}
|
2019-03-18 05:52:32 +00:00
|
|
|
} else {
|
2019-09-26 20:25:05 +00:00
|
|
|
ret = oxr_session_success_result(sess);
|
2019-03-18 05:52:32 +00:00
|
|
|
sess->frame_started = true;
|
|
|
|
}
|
2019-03-26 20:43:15 +00:00
|
|
|
if (xc != NULL) {
|
2020-06-23 16:11:39 +00:00
|
|
|
CALL_CHK(xrt_comp_begin_frame(xc, sess->frame_id.waited));
|
|
|
|
sess->frame_id.begun = sess->frame_id.waited;
|
|
|
|
sess->frame_id.waited = -1;
|
2019-03-26 20:43:15 +00:00
|
|
|
}
|
2019-03-18 05:52:32 +00:00
|
|
|
|
2020-06-23 17:02:08 +00:00
|
|
|
os_semaphore_release(&sess->sem);
|
|
|
|
|
2019-03-18 05:52:32 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum xrt_blend_mode
|
|
|
|
oxr_blend_mode_to_xrt(XrEnvironmentBlendMode blend_mode)
|
|
|
|
{
|
|
|
|
// clang-format off
|
|
|
|
switch (blend_mode) {
|
|
|
|
case XR_ENVIRONMENT_BLEND_MODE_OPAQUE: return XRT_BLEND_MODE_OPAQUE;
|
|
|
|
case XR_ENVIRONMENT_BLEND_MODE_ADDITIVE: return XRT_BLEND_MODE_ADDITIVE;
|
|
|
|
case XR_ENVIRONMENT_BLEND_MODE_ALPHA_BLEND: return XRT_BLEND_MODE_ALPHA_BLEND;
|
|
|
|
default: return (enum xrt_blend_mode)0;
|
|
|
|
}
|
|
|
|
// clang-format on
|
|
|
|
}
|
|
|
|
|
2020-04-22 12:59:07 +00:00
|
|
|
static XrResult
|
|
|
|
verify_space(struct oxr_logger *log, uint32_t layer_index, XrSpace space)
|
|
|
|
{
|
|
|
|
if (space == XR_NULL_HANDLE) {
|
|
|
|
return oxr_error(
|
|
|
|
log, XR_ERROR_VALIDATION_FAILURE,
|
|
|
|
"(frameEndInfo->layers[%u]->space == "
|
|
|
|
"XR_NULL_HANDLE) XrSpace must not be XR_NULL_HANDLE",
|
|
|
|
layer_index);
|
|
|
|
}
|
|
|
|
|
|
|
|
return XR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2020-05-30 20:05:55 +00:00
|
|
|
static XrResult
|
|
|
|
is_rect_neg(const XrRect2Di *imageRect)
|
|
|
|
{
|
|
|
|
if (imageRect->offset.x < 0 || imageRect->offset.y < 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static XrResult
|
|
|
|
is_rect_out_of_bounds(const XrRect2Di *imageRect, struct oxr_swapchain *sc)
|
|
|
|
{
|
|
|
|
uint32_t total_width = imageRect->offset.x + imageRect->extent.width;
|
|
|
|
if (total_width > sc->width) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
uint32_t total_height = imageRect->offset.y + imageRect->extent.height;
|
|
|
|
if (total_height > sc->height) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-04-22 12:59:07 +00:00
|
|
|
static XrResult
|
|
|
|
verify_quad_layer(struct xrt_compositor *xc,
|
|
|
|
struct oxr_logger *log,
|
|
|
|
uint32_t layer_index,
|
|
|
|
XrCompositionLayerQuad *quad,
|
|
|
|
struct xrt_device *head,
|
|
|
|
uint64_t timestamp)
|
|
|
|
{
|
|
|
|
struct oxr_swapchain *sc = XRT_CAST_OXR_HANDLE_TO_PTR(
|
|
|
|
struct oxr_swapchain *, quad->subImage.swapchain);
|
|
|
|
|
2020-06-01 16:37:43 +00:00
|
|
|
if (sc == NULL) {
|
|
|
|
return oxr_error(log, XR_ERROR_LAYER_INVALID,
|
|
|
|
"(frameEndInfo->layers[%u]->subImage."
|
|
|
|
"swapchain) swapchain is NULL!",
|
|
|
|
layer_index);
|
|
|
|
}
|
|
|
|
|
2020-04-22 12:59:07 +00:00
|
|
|
XrResult ret = verify_space(log, layer_index, quad->space);
|
|
|
|
if (ret != XR_SUCCESS) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-05-28 12:13:31 +00:00
|
|
|
if (!math_quat_validate((struct xrt_quat *)&quad->pose.orientation)) {
|
|
|
|
XrQuaternionf *q = &quad->pose.orientation;
|
|
|
|
return oxr_error(log, XR_ERROR_POSE_INVALID,
|
|
|
|
"(frameEndInfo->layers[%u]->pose.orientation "
|
|
|
|
"== {%f %f %f %f}) is not a valid quat",
|
|
|
|
layer_index, q->x, q->y, q->z, q->w);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!math_vec3_validate((struct xrt_vec3 *)&quad->pose.position)) {
|
|
|
|
XrVector3f *p = &quad->pose.position;
|
|
|
|
return oxr_error(log, XR_ERROR_POSE_INVALID,
|
|
|
|
"(frameEndInfo->layers[%u]->pose.position "
|
|
|
|
"== {%f %f %f}) is not valid",
|
|
|
|
layer_index, p->x, p->y, p->z);
|
|
|
|
}
|
2020-05-22 11:53:23 +00:00
|
|
|
|
2020-05-30 20:05:55 +00:00
|
|
|
if (sc->num_array_layers <= quad->subImage.imageArrayIndex) {
|
|
|
|
return oxr_error(
|
|
|
|
log, XR_ERROR_VALIDATION_FAILURE,
|
|
|
|
"(frameEndInfo->layers[%u]->subImage.imageArrayIndex == "
|
|
|
|
"%u) Invalid swapchain array "
|
|
|
|
"index for quad layer (%u).",
|
|
|
|
layer_index, quad->subImage.imageArrayIndex,
|
|
|
|
sc->num_array_layers);
|
2020-05-22 12:11:20 +00:00
|
|
|
}
|
|
|
|
|
2020-05-30 16:01:00 +00:00
|
|
|
if (!sc->released.yes) {
|
2020-04-22 12:59:07 +00:00
|
|
|
return oxr_error(log, XR_ERROR_LAYER_INVALID,
|
|
|
|
"(frameEndInfo->layers[%u]->subImage."
|
|
|
|
"swapchain) swapchain has not been released!",
|
|
|
|
layer_index);
|
|
|
|
}
|
|
|
|
|
2020-05-30 16:01:00 +00:00
|
|
|
if (sc->released.index >= (int)sc->swapchain->num_images) {
|
2020-04-22 12:59:07 +00:00
|
|
|
return oxr_error(
|
|
|
|
log, XR_ERROR_RUNTIME_FAILURE,
|
|
|
|
"(frameEndInfo->layers[%u]->subImage.swapchain) internal "
|
|
|
|
"image index out of bounds",
|
|
|
|
layer_index);
|
|
|
|
}
|
|
|
|
|
2020-05-30 20:05:55 +00:00
|
|
|
if (is_rect_neg(&quad->subImage.imageRect)) {
|
|
|
|
return oxr_error(
|
|
|
|
log, XR_ERROR_SWAPCHAIN_RECT_INVALID,
|
|
|
|
"(frameEndInfo->layers[%u]->subImage.imageRect.offset == "
|
|
|
|
"{%i, %i}) has negative component(s)",
|
|
|
|
layer_index, quad->subImage.imageRect.offset.x,
|
|
|
|
quad->subImage.imageRect.offset.y);
|
2020-05-22 13:00:04 +00:00
|
|
|
}
|
|
|
|
|
2020-05-30 20:05:55 +00:00
|
|
|
if (is_rect_out_of_bounds(&quad->subImage.imageRect, sc)) {
|
|
|
|
return oxr_error(
|
|
|
|
log, XR_ERROR_SWAPCHAIN_RECT_INVALID,
|
|
|
|
"(frameEndInfo->layers[%u]->subImage.imageRect == {{%i, "
|
|
|
|
"%i}, {%u, %u}}) imageRect out of image bounds (%u, %u)",
|
|
|
|
layer_index, quad->subImage.imageRect.offset.x,
|
|
|
|
quad->subImage.imageRect.offset.y,
|
|
|
|
quad->subImage.imageRect.extent.width,
|
|
|
|
quad->subImage.imageRect.extent.height, sc->width,
|
|
|
|
sc->height);
|
2020-05-22 11:47:13 +00:00
|
|
|
}
|
|
|
|
|
2020-04-22 12:59:07 +00:00
|
|
|
return XR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static XrResult
|
|
|
|
verify_projection_layer(struct xrt_compositor *xc,
|
|
|
|
struct oxr_logger *log,
|
|
|
|
uint32_t layer_index,
|
|
|
|
XrCompositionLayerProjection *proj,
|
|
|
|
struct xrt_device *head,
|
|
|
|
uint64_t timestamp)
|
|
|
|
{
|
|
|
|
XrResult ret = verify_space(log, layer_index, proj->space);
|
|
|
|
if (ret != XR_SUCCESS) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (proj->viewCount != 2) {
|
2020-06-03 08:29:54 +00:00
|
|
|
return oxr_error(
|
|
|
|
log, XR_ERROR_VALIDATION_FAILURE,
|
|
|
|
"(frameEndInfo->layers[%u]->viewCount == %u) must be 2 for "
|
|
|
|
"projection layers and the current view configuration",
|
|
|
|
layer_index, proj->viewCount);
|
2020-04-22 12:59:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check for valid swapchain states.
|
|
|
|
for (uint32_t i = 0; i < proj->viewCount; i++) {
|
2020-05-30 20:05:55 +00:00
|
|
|
const XrCompositionLayerProjectionView *view = &proj->views[i];
|
|
|
|
|
2020-04-22 12:59:07 +00:00
|
|
|
//! @todo More validation?
|
2020-05-28 12:13:31 +00:00
|
|
|
if (!math_quat_validate(
|
2020-05-30 20:05:55 +00:00
|
|
|
(struct xrt_quat *)&view->pose.orientation)) {
|
|
|
|
const XrQuaternionf *q = &view->pose.orientation;
|
2020-05-28 12:13:31 +00:00
|
|
|
return oxr_error(
|
|
|
|
log, XR_ERROR_POSE_INVALID,
|
|
|
|
"(frameEndInfo->layers[%u]->views[%i]->pose."
|
|
|
|
"orientation == {%f %f %f %f}) is not a valid quat",
|
|
|
|
layer_index, i, q->x, q->y, q->z, q->w);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!math_vec3_validate(
|
2020-05-30 20:05:55 +00:00
|
|
|
(struct xrt_vec3 *)&view->pose.position)) {
|
|
|
|
const XrVector3f *p = &view->pose.position;
|
2020-05-28 12:13:31 +00:00
|
|
|
return oxr_error(
|
|
|
|
log, XR_ERROR_POSE_INVALID,
|
|
|
|
"(frameEndInfo->layers[%u]->views[%i]->pose."
|
|
|
|
"position == {%f %f %f}) is not valid",
|
|
|
|
layer_index, i, p->x, p->y, p->z);
|
|
|
|
}
|
|
|
|
|
2020-04-22 12:59:07 +00:00
|
|
|
struct oxr_swapchain *sc = XRT_CAST_OXR_HANDLE_TO_PTR(
|
2020-05-30 20:05:55 +00:00
|
|
|
struct oxr_swapchain *, view->subImage.swapchain);
|
2020-04-22 12:59:07 +00:00
|
|
|
|
2020-05-30 16:01:00 +00:00
|
|
|
if (!sc->released.yes) {
|
2020-04-22 12:59:07 +00:00
|
|
|
return oxr_error(
|
|
|
|
log, XR_ERROR_LAYER_INVALID,
|
|
|
|
"(frameEndInfo->layers[%u]->views[%i].subImage."
|
|
|
|
"swapchain) swapchain has not been released",
|
|
|
|
layer_index, i);
|
|
|
|
}
|
|
|
|
|
2020-05-30 16:01:00 +00:00
|
|
|
if (sc->released.index >= (int)sc->swapchain->num_images) {
|
2020-04-22 12:59:07 +00:00
|
|
|
return oxr_error(
|
|
|
|
log, XR_ERROR_RUNTIME_FAILURE,
|
|
|
|
"(frameEndInfo->layers[%u]->views[%i].subImage."
|
|
|
|
"swapchain) internal image index out of bounds",
|
|
|
|
layer_index, i);
|
|
|
|
}
|
2020-05-30 20:05:55 +00:00
|
|
|
|
|
|
|
if (sc->num_array_layers <= view->subImage.imageArrayIndex) {
|
|
|
|
return oxr_error(
|
|
|
|
log, XR_ERROR_VALIDATION_FAILURE,
|
|
|
|
"(frameEndInfo->layers[%u]->views[%i]->subImage."
|
|
|
|
"imageArrayIndex == %u) Invalid swapchain array "
|
|
|
|
"index for projection layer (%u).",
|
|
|
|
layer_index, i, view->subImage.imageArrayIndex,
|
|
|
|
sc->num_array_layers);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_rect_neg(&view->subImage.imageRect)) {
|
|
|
|
return oxr_error(log, XR_ERROR_SWAPCHAIN_RECT_INVALID,
|
|
|
|
"(frameEndInfo->layers[%u]->views[%i]-"
|
|
|
|
">subImage.imageRect.offset == {%i, "
|
|
|
|
"%i}) has negative component(s)",
|
|
|
|
layer_index, i,
|
|
|
|
view->subImage.imageRect.offset.x,
|
|
|
|
view->subImage.imageRect.offset.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_rect_out_of_bounds(&view->subImage.imageRect, sc)) {
|
|
|
|
return oxr_error(
|
|
|
|
log, XR_ERROR_SWAPCHAIN_RECT_INVALID,
|
|
|
|
"(frameEndInfo->layers[%u]->views[%i]->subImage."
|
|
|
|
"imageRect == {{%i, %i}, {%u, %u}}) imageRect out "
|
|
|
|
"of image bounds (%u, %u)",
|
|
|
|
layer_index, i, view->subImage.imageRect.offset.x,
|
|
|
|
view->subImage.imageRect.offset.y,
|
|
|
|
view->subImage.imageRect.extent.width,
|
|
|
|
view->subImage.imageRect.extent.height, sc->width,
|
|
|
|
sc->height);
|
|
|
|
}
|
2020-04-22 12:59:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return XR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2020-08-10 19:15:18 +00:00
|
|
|
static XrResult
|
|
|
|
verify_cube_layer(struct xrt_compositor *xc,
|
|
|
|
struct oxr_logger *log,
|
|
|
|
uint32_t layer_index,
|
|
|
|
const XrCompositionLayerCubeKHR *cube,
|
|
|
|
struct xrt_device *head,
|
|
|
|
uint64_t timestamp)
|
|
|
|
{
|
|
|
|
#ifndef XRT_FEATURE_OPENXR_LAYER_CUBE
|
|
|
|
return oxr_error(log, XR_ERROR_LAYER_INVALID,
|
|
|
|
"(frameEndInfo->layers[%u]->type) layer type "
|
|
|
|
"XrCompositionLayerCubeKHR not supported",
|
|
|
|
layer_index);
|
|
|
|
#else
|
|
|
|
return oxr_error(log, XR_ERROR_RUNTIME_FAILURE,
|
|
|
|
"XrCompositionLayerCubeKHR not implemented");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static XrResult
|
|
|
|
verify_cylinder_layer(struct xrt_compositor *xc,
|
|
|
|
struct oxr_logger *log,
|
|
|
|
uint32_t layer_index,
|
|
|
|
const XrCompositionLayerCylinderKHR *cylinder,
|
|
|
|
struct xrt_device *head,
|
|
|
|
uint64_t timestamp)
|
|
|
|
{
|
|
|
|
#ifndef XRT_FEATURE_OPENXR_LAYER_CYLINDER
|
|
|
|
return oxr_error(log, XR_ERROR_LAYER_INVALID,
|
|
|
|
"(frameEndInfo->layers[%u]->type) layer type "
|
|
|
|
"XrCompositionLayerCylinderKHR not supported",
|
|
|
|
layer_index);
|
|
|
|
#else
|
|
|
|
return oxr_error(log, XR_ERROR_RUNTIME_FAILURE,
|
|
|
|
"XrCompositionLayerCylinderKHR not implemented");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static XrResult
|
|
|
|
verify_equirect_layer(struct xrt_compositor *xc,
|
|
|
|
struct oxr_logger *log,
|
|
|
|
uint32_t layer_index,
|
|
|
|
const XrCompositionLayerEquirectKHR *equirect,
|
|
|
|
struct xrt_device *head,
|
|
|
|
uint64_t timestamp)
|
|
|
|
{
|
|
|
|
#ifndef XRT_FEATURE_OPENXR_LAYER_EQUIRECT
|
|
|
|
return oxr_error(log, XR_ERROR_LAYER_INVALID,
|
|
|
|
"(frameEndInfo->layers[%u]->type) layer type "
|
|
|
|
"XrCompositionLayerEquirectKHR not supported",
|
|
|
|
layer_index);
|
|
|
|
#else
|
|
|
|
return oxr_error(log, XR_ERROR_RUNTIME_FAILURE,
|
|
|
|
"XrCompositionLayerEquirectKHR not implemented");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-06-09 18:51:39 +00:00
|
|
|
static enum xrt_layer_composition_flags
|
|
|
|
convert_layer_flags(XrSwapchainUsageFlags xr_flags)
|
|
|
|
{
|
|
|
|
enum xrt_layer_composition_flags flags = 0;
|
|
|
|
|
|
|
|
// clang-format off
|
|
|
|
if ((xr_flags & XR_COMPOSITION_LAYER_CORRECT_CHROMATIC_ABERRATION_BIT) != 0) {
|
|
|
|
flags |= XRT_LAYER_COMPOSITION_CORRECT_CHROMATIC_ABERRATION_BIT;
|
|
|
|
}
|
|
|
|
if ((xr_flags & XR_COMPOSITION_LAYER_BLEND_TEXTURE_SOURCE_ALPHA_BIT) != 0) {
|
|
|
|
flags |= XRT_LAYER_COMPOSITION_BLEND_TEXTURE_SOURCE_ALPHA_BIT;
|
|
|
|
}
|
|
|
|
if ((xr_flags & XR_COMPOSITION_LAYER_UNPREMULTIPLIED_ALPHA_BIT) != 0) {
|
|
|
|
flags |= XRT_LAYER_COMPOSITION_UNPREMULTIPLIED_ALPHA_BIT;
|
|
|
|
}
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
static enum xrt_layer_eye_visibility
|
|
|
|
convert_eye_visibility(XrSwapchainUsageFlags xr_visibility)
|
|
|
|
{
|
2020-06-13 12:57:59 +00:00
|
|
|
enum xrt_layer_eye_visibility visibility = 0;
|
2020-06-09 18:51:39 +00:00
|
|
|
|
|
|
|
if (xr_visibility == XR_EYE_VISIBILITY_BOTH) {
|
|
|
|
visibility = XRT_LAYER_EYE_VISIBILITY_BOTH;
|
|
|
|
}
|
|
|
|
if (xr_visibility == XR_EYE_VISIBILITY_LEFT) {
|
|
|
|
visibility = XRT_LAYER_EYE_VISIBILITY_LEFT_BIT;
|
|
|
|
}
|
|
|
|
if (xr_visibility == XR_EYE_VISIBILITY_RIGHT) {
|
|
|
|
visibility = XRT_LAYER_EYE_VISIBILITY_RIGHT_BIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return visibility;
|
|
|
|
}
|
|
|
|
|
2020-06-04 14:56:25 +00:00
|
|
|
static XrResult
|
2020-07-16 17:34:46 +00:00
|
|
|
submit_quad_layer(struct oxr_session *sess,
|
|
|
|
struct xrt_compositor *xc,
|
2020-04-22 12:59:07 +00:00
|
|
|
struct oxr_logger *log,
|
|
|
|
XrCompositionLayerQuad *quad,
|
|
|
|
struct xrt_device *head,
|
2020-05-23 11:24:12 +00:00
|
|
|
struct xrt_pose *inv_offset,
|
2020-04-22 12:59:07 +00:00
|
|
|
uint64_t timestamp)
|
|
|
|
{
|
|
|
|
struct oxr_swapchain *sc = XRT_CAST_OXR_HANDLE_TO_PTR(
|
|
|
|
struct oxr_swapchain *, quad->subImage.swapchain);
|
2020-06-15 17:35:14 +00:00
|
|
|
struct oxr_space *spc =
|
|
|
|
XRT_CAST_OXR_HANDLE_TO_PTR(struct oxr_space *, quad->space);
|
2020-04-22 12:59:07 +00:00
|
|
|
|
2020-06-09 18:51:39 +00:00
|
|
|
enum xrt_layer_composition_flags flags =
|
|
|
|
convert_layer_flags(quad->layerFlags);
|
2020-06-09 18:02:04 +00:00
|
|
|
|
2020-06-15 17:35:14 +00:00
|
|
|
struct xrt_pose *pose_ptr = (struct xrt_pose *)&quad->pose;
|
|
|
|
struct xrt_pose pose = *pose_ptr;
|
|
|
|
|
|
|
|
if (spc->is_reference && spc->type == XR_REFERENCE_SPACE_TYPE_VIEW) {
|
|
|
|
flags |= XRT_LAYER_COMPOSITION_VIEW_SPACE_BIT;
|
|
|
|
// The space might have a pose, transform that in as well.
|
|
|
|
math_pose_transform(&spc->pose, &pose, &pose);
|
2020-07-17 11:08:07 +00:00
|
|
|
} else if (spc->is_reference) {
|
|
|
|
// The space might have a pose, transform that in as well.
|
|
|
|
math_pose_transform(&spc->pose, &pose, &pose);
|
|
|
|
|
|
|
|
// Remove the tracking system origin offset.
|
|
|
|
math_pose_transform(inv_offset, &pose, &pose);
|
2020-07-19 21:44:24 +00:00
|
|
|
|
|
|
|
if (spc->type == XR_REFERENCE_SPACE_TYPE_LOCAL) {
|
|
|
|
if (!initial_head_relation_valid(sess)) {
|
|
|
|
return XR_SUCCESS;
|
|
|
|
}
|
|
|
|
math_pose_transform(&sess->initial_head_relation.pose,
|
|
|
|
&pose, &pose);
|
|
|
|
}
|
|
|
|
|
2020-06-15 17:35:14 +00:00
|
|
|
} else {
|
2020-07-16 17:34:46 +00:00
|
|
|
//! @todo Action space handling not very complete
|
|
|
|
|
|
|
|
struct oxr_action_input *input = NULL;
|
|
|
|
|
|
|
|
oxr_action_get_pose_input(log, sess, spc->act_key,
|
|
|
|
&spc->sub_paths, &input);
|
|
|
|
|
|
|
|
// If the input isn't active.
|
|
|
|
if (input == NULL) {
|
|
|
|
//! @todo just don't render the quad here?
|
|
|
|
return XR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t xdev_timestamp = 0;
|
|
|
|
|
|
|
|
struct xrt_space_relation out_relation;
|
|
|
|
|
|
|
|
oxr_xdev_get_pose_at(log, sess->sys->inst, input->xdev,
|
|
|
|
input->input->name, timestamp,
|
|
|
|
&xdev_timestamp, &out_relation);
|
|
|
|
|
|
|
|
struct xrt_pose device_pose = out_relation.pose;
|
2020-06-15 17:35:14 +00:00
|
|
|
|
|
|
|
// The space might have a pose, transform that in as well.
|
2020-07-16 17:34:46 +00:00
|
|
|
math_pose_transform(&spc->pose, &device_pose, &device_pose);
|
|
|
|
|
|
|
|
math_pose_transform(&device_pose, &pose, &pose);
|
2020-06-15 17:35:14 +00:00
|
|
|
|
|
|
|
// Remove the tracking system origin offset.
|
|
|
|
math_pose_transform(inv_offset, &pose, &pose);
|
|
|
|
}
|
2020-05-23 11:24:12 +00:00
|
|
|
|
2020-06-09 18:02:04 +00:00
|
|
|
struct xrt_layer_data data;
|
|
|
|
U_ZERO(&data);
|
|
|
|
data.type = XRT_LAYER_QUAD;
|
|
|
|
data.name = XRT_INPUT_GENERIC_HEAD_POSE;
|
|
|
|
data.timestamp = timestamp;
|
|
|
|
data.flags = flags;
|
|
|
|
|
|
|
|
struct xrt_vec2 *size = (struct xrt_vec2 *)&quad->size;
|
|
|
|
struct xrt_rect *rect = (struct xrt_rect *)&quad->subImage.imageRect;
|
|
|
|
|
2020-06-09 18:51:39 +00:00
|
|
|
data.quad.visibility = convert_eye_visibility(quad->eyeVisibility);
|
2020-06-09 19:31:36 +00:00
|
|
|
data.quad.sub.image_index = sc->released.index;
|
|
|
|
data.quad.sub.array_index = quad->subImage.imageArrayIndex;
|
|
|
|
data.quad.sub.rect = *rect;
|
2020-06-09 18:02:04 +00:00
|
|
|
data.quad.pose = pose;
|
|
|
|
data.quad.size = *size;
|
|
|
|
|
|
|
|
CALL_CHK(xrt_comp_layer_quad(xc, head, sc->swapchain, &data));
|
2020-06-04 14:56:25 +00:00
|
|
|
|
|
|
|
return XR_SUCCESS;
|
2020-04-22 12:59:07 +00:00
|
|
|
}
|
|
|
|
|
2020-06-04 14:56:25 +00:00
|
|
|
static XrResult
|
2020-04-22 12:59:07 +00:00
|
|
|
submit_projection_layer(struct xrt_compositor *xc,
|
|
|
|
struct oxr_logger *log,
|
|
|
|
XrCompositionLayerProjection *proj,
|
|
|
|
struct xrt_device *head,
|
2020-05-23 11:24:12 +00:00
|
|
|
struct xrt_pose *inv_offset,
|
2020-04-22 12:59:07 +00:00
|
|
|
uint64_t timestamp)
|
|
|
|
{
|
2020-06-15 17:35:14 +00:00
|
|
|
struct oxr_space *spc =
|
|
|
|
XRT_CAST_OXR_HANDLE_TO_PTR(struct oxr_space *, proj->space);
|
2020-04-22 12:59:07 +00:00
|
|
|
struct oxr_swapchain *scs[2];
|
2020-06-15 17:35:14 +00:00
|
|
|
struct xrt_pose *pose_ptr[2];
|
|
|
|
struct xrt_pose pose[2];
|
2020-04-22 12:59:07 +00:00
|
|
|
|
2020-06-09 18:51:39 +00:00
|
|
|
enum xrt_layer_composition_flags flags =
|
|
|
|
convert_layer_flags(proj->layerFlags);
|
2020-04-22 12:59:07 +00:00
|
|
|
|
2020-06-09 18:51:39 +00:00
|
|
|
uint32_t num_chains = ARRAY_SIZE(scs);
|
2020-04-22 12:59:07 +00:00
|
|
|
for (uint32_t i = 0; i < num_chains; i++) {
|
|
|
|
scs[i] = XRT_CAST_OXR_HANDLE_TO_PTR(
|
|
|
|
struct oxr_swapchain *, proj->views[i].subImage.swapchain);
|
2020-06-15 17:35:14 +00:00
|
|
|
pose_ptr[i] = (struct xrt_pose *)&proj->views[i].pose;
|
|
|
|
pose[i] = *pose_ptr[i];
|
2020-04-22 12:59:07 +00:00
|
|
|
}
|
|
|
|
|
2020-06-15 17:35:14 +00:00
|
|
|
if (spc->is_reference && spc->type == XR_REFERENCE_SPACE_TYPE_VIEW) {
|
|
|
|
flags |= XRT_LAYER_COMPOSITION_VIEW_SPACE_BIT;
|
|
|
|
// The space might have a pose, transform that in as well.
|
|
|
|
math_pose_transform(&spc->pose, &pose[0], &pose[0]);
|
|
|
|
math_pose_transform(&spc->pose, &pose[1], &pose[1]);
|
|
|
|
} else {
|
|
|
|
//! @todo Handle action spaces.
|
|
|
|
|
|
|
|
// The space might have a pose, transform that in as well.
|
|
|
|
math_pose_transform(&spc->pose, &pose[0], &pose[0]);
|
|
|
|
math_pose_transform(&spc->pose, &pose[1], &pose[1]);
|
|
|
|
|
|
|
|
// Remove the tracking system origin offset.
|
|
|
|
math_pose_transform(inv_offset, &pose[0], &pose[0]);
|
|
|
|
math_pose_transform(inv_offset, &pose[1], &pose[1]);
|
|
|
|
}
|
2020-05-23 11:24:12 +00:00
|
|
|
|
2020-06-09 18:02:04 +00:00
|
|
|
struct xrt_rect *l_rect =
|
|
|
|
(struct xrt_rect *)&proj->views[0].subImage.imageRect;
|
|
|
|
struct xrt_fov *l_fov = (struct xrt_fov *)&proj->views[0].fov;
|
|
|
|
struct xrt_rect *r_rect =
|
|
|
|
(struct xrt_rect *)&proj->views[1].subImage.imageRect;
|
|
|
|
struct xrt_fov *r_fov = (struct xrt_fov *)&proj->views[1].fov;
|
|
|
|
|
|
|
|
struct xrt_layer_data data;
|
|
|
|
U_ZERO(&data);
|
|
|
|
data.type = XRT_LAYER_STEREO_PROJECTION;
|
|
|
|
data.name = XRT_INPUT_GENERIC_HEAD_POSE;
|
|
|
|
data.timestamp = timestamp;
|
|
|
|
data.flags = flags;
|
|
|
|
|
2020-06-09 19:31:36 +00:00
|
|
|
data.stereo.l.sub.image_index = scs[0]->released.index;
|
|
|
|
data.stereo.l.sub.array_index = proj->views[0].subImage.imageArrayIndex;
|
|
|
|
data.stereo.l.sub.rect = *l_rect;
|
2020-06-09 18:02:04 +00:00
|
|
|
data.stereo.l.fov = *l_fov;
|
|
|
|
data.stereo.l.pose = pose[0];
|
|
|
|
|
2020-06-09 19:31:36 +00:00
|
|
|
data.stereo.r.sub.image_index = scs[1]->released.index;
|
|
|
|
data.stereo.r.sub.array_index = proj->views[1].subImage.imageArrayIndex;
|
|
|
|
data.stereo.r.sub.rect = *r_rect;
|
2020-06-09 18:02:04 +00:00
|
|
|
data.stereo.r.fov = *r_fov;
|
|
|
|
data.stereo.r.pose = pose[1];
|
|
|
|
|
|
|
|
CALL_CHK(xrt_comp_layer_stereo_projection(xc, head,
|
|
|
|
scs[0]->swapchain, // Left
|
|
|
|
scs[1]->swapchain, // Right
|
|
|
|
&data));
|
2020-06-04 14:56:25 +00:00
|
|
|
return XR_SUCCESS;
|
2020-04-22 12:59:07 +00:00
|
|
|
}
|
|
|
|
|
2020-08-10 19:15:18 +00:00
|
|
|
static void
|
|
|
|
submit_cube_layer(struct oxr_session *sess,
|
|
|
|
struct xrt_compositor *xc,
|
|
|
|
struct oxr_logger *log,
|
|
|
|
const XrCompositionLayerCubeKHR *cube,
|
|
|
|
struct xrt_device *head,
|
|
|
|
struct xrt_pose *inv_offset,
|
|
|
|
uint64_t timestamp)
|
|
|
|
{
|
|
|
|
// Not implemented
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
submit_cylinder_layer(struct oxr_session *sess,
|
|
|
|
struct xrt_compositor *xc,
|
|
|
|
struct oxr_logger *log,
|
|
|
|
const XrCompositionLayerCylinderKHR *cylinder,
|
|
|
|
struct xrt_device *head,
|
|
|
|
struct xrt_pose *inv_offset,
|
|
|
|
uint64_t timestamp)
|
|
|
|
{
|
|
|
|
// Not implemented
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
submit_equirect_layer(struct oxr_session *sess,
|
|
|
|
struct xrt_compositor *xc,
|
|
|
|
struct oxr_logger *log,
|
|
|
|
const XrCompositionLayerEquirectKHR *equirect,
|
|
|
|
struct xrt_device *head,
|
|
|
|
struct xrt_pose *inv_offset,
|
|
|
|
uint64_t timestamp)
|
|
|
|
{
|
|
|
|
// Not implemented
|
|
|
|
}
|
|
|
|
|
2019-03-18 05:52:32 +00:00
|
|
|
XrResult
|
|
|
|
oxr_session_frame_end(struct oxr_logger *log,
|
|
|
|
struct oxr_session *sess,
|
|
|
|
const XrFrameEndInfo *frameEndInfo)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Session state and call order.
|
|
|
|
*/
|
|
|
|
|
2020-05-30 17:30:27 +00:00
|
|
|
if (!is_running(sess)) {
|
2019-03-18 05:52:32 +00:00
|
|
|
return oxr_error(log, XR_ERROR_SESSION_NOT_RUNNING,
|
2020-05-31 15:49:25 +00:00
|
|
|
"Session is not running");
|
2019-03-18 05:52:32 +00:00
|
|
|
}
|
|
|
|
if (!sess->frame_started) {
|
|
|
|
return oxr_error(log, XR_ERROR_CALL_ORDER_INVALID,
|
2020-05-31 15:49:25 +00:00
|
|
|
"Frame not begun with xrBeginFrame");
|
2019-03-18 05:52:32 +00:00
|
|
|
}
|
|
|
|
|
2020-02-25 02:15:53 +00:00
|
|
|
if (frameEndInfo->displayTime <= 0) {
|
2020-05-26 17:22:09 +00:00
|
|
|
return oxr_error(
|
|
|
|
log, XR_ERROR_TIME_INVALID,
|
|
|
|
"(frameEndInfo->displayTime == %" PRIi64
|
|
|
|
") zero or a negative value is not a valid XrTime",
|
|
|
|
frameEndInfo->displayTime);
|
2020-02-25 02:15:53 +00:00
|
|
|
}
|
|
|
|
|
2019-03-18 05:52:32 +00:00
|
|
|
struct xrt_compositor *xc = sess->compositor;
|
|
|
|
|
2019-03-26 20:43:15 +00:00
|
|
|
/*
|
|
|
|
* early out for headless sessions.
|
|
|
|
*/
|
|
|
|
if (xc == NULL) {
|
|
|
|
sess->frame_started = false;
|
|
|
|
|
2019-09-26 20:25:05 +00:00
|
|
|
return oxr_session_success_result(sess);
|
2019-03-26 20:43:15 +00:00
|
|
|
}
|
|
|
|
|
2019-03-18 05:52:32 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Blend mode.
|
2020-02-25 02:25:36 +00:00
|
|
|
* XR_ERROR_ENVIRONMENT_BLEND_MODE_UNSUPPORTED must always be reported,
|
|
|
|
* even with 0 layers.
|
2019-03-18 05:52:32 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
enum xrt_blend_mode blend_mode =
|
|
|
|
oxr_blend_mode_to_xrt(frameEndInfo->environmentBlendMode);
|
|
|
|
|
|
|
|
if (blend_mode == 0) {
|
|
|
|
return oxr_error(log, XR_ERROR_VALIDATION_FAILURE,
|
2020-05-26 16:54:13 +00:00
|
|
|
"(frameEndInfo->environmentBlendMode == "
|
|
|
|
"0x%08x) unknown environment blend mode",
|
|
|
|
frameEndInfo->environmentBlendMode);
|
2019-03-18 05:52:32 +00:00
|
|
|
}
|
|
|
|
|
2020-07-07 00:14:29 +00:00
|
|
|
struct xrt_device *xdev = GET_XDEV_BY_ROLE(sess->sys, head);
|
|
|
|
if ((blend_mode & xdev->hmd->blend_mode) == 0) {
|
2020-05-26 16:54:13 +00:00
|
|
|
//! @todo Make integer print to string.
|
2019-03-18 05:52:32 +00:00
|
|
|
return oxr_error(log,
|
|
|
|
XR_ERROR_ENVIRONMENT_BLEND_MODE_UNSUPPORTED,
|
2020-05-26 16:54:13 +00:00
|
|
|
"(frameEndInfo->environmentBlendMode == %u) "
|
|
|
|
"is not supported",
|
|
|
|
frameEndInfo->environmentBlendMode);
|
2019-03-18 05:52:32 +00:00
|
|
|
}
|
|
|
|
|
2020-02-25 02:25:36 +00:00
|
|
|
/*
|
|
|
|
* Early out for discarded frame if layer count is 0.
|
|
|
|
*/
|
|
|
|
if (frameEndInfo->layerCount == 0) {
|
2020-06-23 16:11:39 +00:00
|
|
|
CALL_CHK(xrt_comp_discard_frame(xc, sess->frame_id.begun));
|
|
|
|
sess->frame_id.begun = -1;
|
2020-02-25 02:25:36 +00:00
|
|
|
sess->frame_started = false;
|
|
|
|
|
|
|
|
return oxr_session_success_result(sess);
|
|
|
|
}
|
2019-03-18 05:52:32 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Layers.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (frameEndInfo->layers == NULL) {
|
2020-01-23 21:13:42 +00:00
|
|
|
return oxr_error(log, XR_ERROR_LAYER_INVALID,
|
2019-03-18 05:52:32 +00:00
|
|
|
"(frameEndInfo->layers == NULL)");
|
|
|
|
}
|
|
|
|
|
2020-04-22 12:59:07 +00:00
|
|
|
for (uint32_t i = 0; i < frameEndInfo->layerCount; i++) {
|
|
|
|
const XrCompositionLayerBaseHeader *layer =
|
|
|
|
frameEndInfo->layers[i];
|
|
|
|
if (layer == NULL) {
|
|
|
|
return oxr_error(log, XR_ERROR_LAYER_INVALID,
|
|
|
|
"(frameEndInfo->layers[%u] == NULL) "
|
|
|
|
"layer can not be null",
|
|
|
|
i);
|
|
|
|
}
|
2019-06-28 14:55:45 +00:00
|
|
|
|
2020-04-22 12:59:07 +00:00
|
|
|
XrResult res;
|
|
|
|
|
|
|
|
switch (layer->type) {
|
|
|
|
case XR_TYPE_COMPOSITION_LAYER_PROJECTION:
|
|
|
|
res = verify_projection_layer(
|
|
|
|
xc, log, i, (XrCompositionLayerProjection *)layer,
|
2020-07-07 00:14:29 +00:00
|
|
|
xdev, frameEndInfo->displayTime);
|
2020-04-22 12:59:07 +00:00
|
|
|
break;
|
|
|
|
case XR_TYPE_COMPOSITION_LAYER_QUAD:
|
|
|
|
res = verify_quad_layer(
|
2020-07-07 00:14:29 +00:00
|
|
|
xc, log, i, (XrCompositionLayerQuad *)layer, xdev,
|
|
|
|
frameEndInfo->displayTime);
|
2020-04-22 12:59:07 +00:00
|
|
|
break;
|
2020-08-10 19:15:18 +00:00
|
|
|
case XR_TYPE_COMPOSITION_LAYER_CUBE_KHR:
|
|
|
|
res = verify_cube_layer(
|
|
|
|
xc, log, i, (XrCompositionLayerCubeKHR *)layer,
|
|
|
|
xdev, frameEndInfo->displayTime);
|
|
|
|
break;
|
|
|
|
case XR_TYPE_COMPOSITION_LAYER_CYLINDER_KHR:
|
|
|
|
res = verify_cylinder_layer(
|
|
|
|
xc, log, i, (XrCompositionLayerCylinderKHR *)layer,
|
|
|
|
xdev, frameEndInfo->displayTime);
|
|
|
|
break;
|
|
|
|
case XR_TYPE_COMPOSITION_LAYER_EQUIRECT_KHR:
|
|
|
|
res = verify_equirect_layer(
|
|
|
|
xc, log, i, (XrCompositionLayerEquirectKHR *)layer,
|
|
|
|
xdev, frameEndInfo->displayTime);
|
|
|
|
break;
|
2020-04-22 12:59:07 +00:00
|
|
|
default:
|
|
|
|
return oxr_error(log, XR_ERROR_LAYER_INVALID,
|
|
|
|
"(frameEndInfo->layers[%u]->type) "
|
|
|
|
"layer type not supported",
|
|
|
|
i);
|
2019-06-28 14:55:45 +00:00
|
|
|
}
|
|
|
|
|
2020-04-22 12:59:07 +00:00
|
|
|
if (res != XR_SUCCESS) {
|
|
|
|
return res;
|
2019-06-28 14:55:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-18 05:52:32 +00:00
|
|
|
|
|
|
|
/*
|
2020-04-22 12:59:07 +00:00
|
|
|
* Done verifying.
|
2019-03-18 05:52:32 +00:00
|
|
|
*/
|
|
|
|
|
2020-05-23 11:24:12 +00:00
|
|
|
struct xrt_pose inv_offset = {0};
|
2020-07-07 00:14:29 +00:00
|
|
|
math_pose_invert(&xdev->tracking_origin->offset, &inv_offset);
|
2020-05-23 11:24:12 +00:00
|
|
|
|
2020-06-23 16:11:39 +00:00
|
|
|
CALL_CHK(xrt_comp_layer_begin(xc, sess->frame_id.begun, blend_mode));
|
2020-04-22 12:59:07 +00:00
|
|
|
|
|
|
|
for (uint32_t i = 0; i < frameEndInfo->layerCount; i++) {
|
|
|
|
const XrCompositionLayerBaseHeader *layer =
|
|
|
|
frameEndInfo->layers[i];
|
|
|
|
assert(layer != NULL);
|
|
|
|
|
|
|
|
switch (layer->type) {
|
|
|
|
case XR_TYPE_COMPOSITION_LAYER_PROJECTION:
|
|
|
|
submit_projection_layer(
|
|
|
|
xc, log, (XrCompositionLayerProjection *)layer,
|
2020-07-07 00:14:29 +00:00
|
|
|
xdev, &inv_offset, frameEndInfo->displayTime);
|
2020-04-22 12:59:07 +00:00
|
|
|
break;
|
|
|
|
case XR_TYPE_COMPOSITION_LAYER_QUAD:
|
2020-07-07 00:14:29 +00:00
|
|
|
submit_quad_layer(
|
2020-07-16 17:34:46 +00:00
|
|
|
sess, xc, log, (XrCompositionLayerQuad *)layer,
|
|
|
|
xdev, &inv_offset, frameEndInfo->displayTime);
|
2020-04-22 12:59:07 +00:00
|
|
|
break;
|
2020-08-10 19:15:18 +00:00
|
|
|
case XR_TYPE_COMPOSITION_LAYER_CUBE_KHR:
|
|
|
|
submit_cube_layer(
|
|
|
|
sess, xc, log, (XrCompositionLayerCubeKHR *)layer,
|
|
|
|
xdev, &inv_offset, frameEndInfo->displayTime);
|
|
|
|
break;
|
|
|
|
case XR_TYPE_COMPOSITION_LAYER_CYLINDER_KHR:
|
|
|
|
submit_cylinder_layer(
|
|
|
|
sess, xc, log,
|
|
|
|
(XrCompositionLayerCylinderKHR *)layer, xdev,
|
|
|
|
&inv_offset, frameEndInfo->displayTime);
|
|
|
|
break;
|
|
|
|
case XR_TYPE_COMPOSITION_LAYER_EQUIRECT_KHR:
|
|
|
|
submit_equirect_layer(
|
|
|
|
sess, xc, log,
|
|
|
|
(XrCompositionLayerEquirectKHR *)layer, xdev,
|
|
|
|
&inv_offset, frameEndInfo->displayTime);
|
|
|
|
break;
|
2020-04-22 12:59:07 +00:00
|
|
|
default: assert(false && "invalid layer type");
|
|
|
|
}
|
2019-03-18 05:52:32 +00:00
|
|
|
}
|
|
|
|
|
2020-06-23 16:11:39 +00:00
|
|
|
CALL_CHK(xrt_comp_layer_commit(xc, sess->frame_id.begun));
|
|
|
|
sess->frame_id.begun = -1;
|
2019-03-18 05:52:32 +00:00
|
|
|
|
|
|
|
sess->frame_started = false;
|
|
|
|
|
2019-09-26 20:25:05 +00:00
|
|
|
return oxr_session_success_result(sess);
|
2019-03-18 05:52:32 +00:00
|
|
|
}
|
|
|
|
|
2019-04-05 22:13:58 +00:00
|
|
|
static XrResult
|
|
|
|
oxr_session_destroy(struct oxr_logger *log, struct oxr_handle_base *hb)
|
|
|
|
{
|
|
|
|
struct oxr_session *sess = (struct oxr_session *)hb;
|
2019-10-28 21:00:36 +00:00
|
|
|
|
2020-05-30 12:26:46 +00:00
|
|
|
XrResult ret = oxr_event_remove_session_events(log, sess);
|
|
|
|
|
2019-10-28 21:00:36 +00:00
|
|
|
// Does a null-ptr check.
|
|
|
|
xrt_comp_destroy(&sess->compositor);
|
2020-06-15 21:46:21 +00:00
|
|
|
for (size_t i = 0; i < sess->num_action_set_attachments; ++i) {
|
|
|
|
oxr_action_set_attachment_teardown(
|
|
|
|
&sess->act_set_attachments[i]);
|
|
|
|
}
|
|
|
|
free(sess->act_set_attachments);
|
|
|
|
sess->act_set_attachments = NULL;
|
|
|
|
sess->num_action_set_attachments = 0;
|
|
|
|
|
|
|
|
// If we tore everything down correctly, these are empty now.
|
2020-08-04 20:30:43 +00:00
|
|
|
assert(sess->act_sets_attachments_by_key == NULL ||
|
|
|
|
u_hashmap_int_empty(sess->act_sets_attachments_by_key));
|
|
|
|
assert(sess->act_attachments_by_key == NULL ||
|
|
|
|
u_hashmap_int_empty(sess->act_attachments_by_key));
|
2019-10-28 21:00:36 +00:00
|
|
|
|
2020-06-15 21:46:21 +00:00
|
|
|
u_hashmap_int_destroy(&sess->act_sets_attachments_by_key);
|
|
|
|
u_hashmap_int_destroy(&sess->act_attachments_by_key);
|
2019-11-13 20:53:16 +00:00
|
|
|
|
2019-04-05 22:13:58 +00:00
|
|
|
free(sess);
|
|
|
|
|
2020-05-30 12:26:46 +00:00
|
|
|
return ret;
|
2019-04-05 22:13:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define OXR_SESSION_ALLOCATE(LOG, SYS, OUT) \
|
|
|
|
do { \
|
|
|
|
OXR_ALLOCATE_HANDLE_OR_RETURN(LOG, OUT, OXR_XR_DEBUG_SESSION, \
|
|
|
|
oxr_session_destroy, \
|
2019-06-03 19:11:31 +00:00
|
|
|
&(SYS)->inst->handle); \
|
|
|
|
(OUT)->sys = (SYS); \
|
2019-04-05 22:13:58 +00:00
|
|
|
} while (0)
|
|
|
|
|
2019-06-03 19:17:45 +00:00
|
|
|
/* Just the allocation and populate part, so we can use early-returns to
|
|
|
|
* simplify code flow and avoid weird if/else */
|
|
|
|
static XrResult
|
|
|
|
oxr_session_create_impl(struct oxr_logger *log,
|
|
|
|
struct oxr_system *sys,
|
|
|
|
const XrSessionCreateInfo *createInfo,
|
|
|
|
struct oxr_session **out_session)
|
|
|
|
{
|
2019-12-03 19:08:10 +00:00
|
|
|
#if defined(XR_USE_PLATFORM_XLIB) && defined(XR_USE_GRAPHICS_API_OPENGL)
|
2019-06-03 19:17:45 +00:00
|
|
|
XrGraphicsBindingOpenGLXlibKHR const *opengl_xlib =
|
|
|
|
OXR_GET_INPUT_FROM_CHAIN(createInfo,
|
|
|
|
XR_TYPE_GRAPHICS_BINDING_OPENGL_XLIB_KHR,
|
|
|
|
XrGraphicsBindingOpenGLXlibKHR);
|
|
|
|
if (opengl_xlib != NULL) {
|
2020-05-30 11:42:41 +00:00
|
|
|
if (!sys->gotten_requirements) {
|
|
|
|
return oxr_error(
|
|
|
|
log, XR_ERROR_VALIDATION_FAILURE,
|
|
|
|
"Has not called "
|
|
|
|
"xrGetOpenGL[ES]GraphicsRequirementsKHR");
|
|
|
|
}
|
|
|
|
|
2019-06-03 19:17:45 +00:00
|
|
|
OXR_SESSION_ALLOCATE(log, sys, *out_session);
|
|
|
|
return oxr_session_populate_gl_xlib(log, sys, opengl_xlib,
|
|
|
|
*out_session);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XR_USE_GRAPHICS_API_VULKAN
|
|
|
|
XrGraphicsBindingVulkanKHR const *vulkan = OXR_GET_INPUT_FROM_CHAIN(
|
|
|
|
createInfo, XR_TYPE_GRAPHICS_BINDING_VULKAN_KHR,
|
|
|
|
XrGraphicsBindingVulkanKHR);
|
|
|
|
if (vulkan != NULL) {
|
2020-05-30 11:42:41 +00:00
|
|
|
if (!sys->gotten_requirements) {
|
|
|
|
return oxr_error(log, XR_ERROR_VALIDATION_FAILURE,
|
|
|
|
"Has not called "
|
|
|
|
"xrGetVulkanGraphicsRequirementsKHR");
|
|
|
|
}
|
|
|
|
|
2019-06-03 19:17:45 +00:00
|
|
|
OXR_SESSION_ALLOCATE(log, sys, *out_session);
|
|
|
|
return oxr_session_populate_vk(log, sys, vulkan, *out_session);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-10-29 16:11:48 +00:00
|
|
|
#ifdef XR_USE_PLATFORM_EGL
|
2020-05-20 15:55:07 +00:00
|
|
|
XrGraphicsBindingEGLMNDX const *egl = OXR_GET_INPUT_FROM_CHAIN(
|
|
|
|
createInfo, XR_TYPE_GRAPHICS_BINDING_EGL_MNDX,
|
|
|
|
XrGraphicsBindingEGLMNDX);
|
2019-10-29 16:11:48 +00:00
|
|
|
if (egl != NULL) {
|
2020-05-30 11:42:41 +00:00
|
|
|
if (!sys->gotten_requirements) {
|
|
|
|
return oxr_error(
|
|
|
|
log, XR_ERROR_VALIDATION_FAILURE,
|
|
|
|
"Has not called "
|
|
|
|
"xrGetOpenGL[ES]GraphicsRequirementsKHR");
|
|
|
|
}
|
|
|
|
|
2019-10-29 16:11:48 +00:00
|
|
|
OXR_SESSION_ALLOCATE(log, sys, *out_session);
|
|
|
|
return oxr_session_populate_egl(log, sys, egl, *out_session);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-06-03 19:17:45 +00:00
|
|
|
/*
|
|
|
|
* Add any new graphics binding structs here - before the headless
|
|
|
|
* check. (order for non-headless checks not specified in standard.)
|
|
|
|
* Any new addition will also need to be added to
|
|
|
|
* oxr_verify_XrSessionCreateInfo and have its own associated verify
|
|
|
|
* function added.
|
|
|
|
*/
|
|
|
|
|
2019-08-19 17:37:50 +00:00
|
|
|
if (sys->inst->extensions.MND_headless) {
|
2019-06-03 19:17:45 +00:00
|
|
|
OXR_SESSION_ALLOCATE(log, sys, *out_session);
|
|
|
|
(*out_session)->compositor = NULL;
|
|
|
|
(*out_session)->create_swapchain = NULL;
|
|
|
|
return XR_SUCCESS;
|
|
|
|
}
|
|
|
|
return oxr_error(log, XR_ERROR_VALIDATION_FAILURE,
|
2020-05-31 15:49:25 +00:00
|
|
|
"(createInfo->next->type) doesn't contain a valid "
|
|
|
|
"graphics binding structs");
|
2019-06-03 19:17:45 +00:00
|
|
|
}
|
|
|
|
|
2019-03-18 05:52:32 +00:00
|
|
|
XrResult
|
|
|
|
oxr_session_create(struct oxr_logger *log,
|
|
|
|
struct oxr_system *sys,
|
2019-06-03 19:17:45 +00:00
|
|
|
const XrSessionCreateInfo *createInfo,
|
2019-03-18 05:52:32 +00:00
|
|
|
struct oxr_session **out_session)
|
|
|
|
{
|
2019-08-16 22:02:38 +00:00
|
|
|
struct oxr_session *sess = NULL;
|
2019-03-18 05:52:32 +00:00
|
|
|
|
2019-06-03 19:17:45 +00:00
|
|
|
/* Try allocating and populating. */
|
|
|
|
XrResult ret = oxr_session_create_impl(log, sys, createInfo, &sess);
|
2019-03-18 05:52:32 +00:00
|
|
|
if (ret != XR_SUCCESS) {
|
2019-08-16 22:02:38 +00:00
|
|
|
if (sess != NULL) {
|
|
|
|
/* clean up allocation first */
|
|
|
|
XrResult cleanup_result =
|
|
|
|
oxr_handle_destroy(log, &sess->handle);
|
|
|
|
assert(cleanup_result == XR_SUCCESS);
|
|
|
|
(void)cleanup_result;
|
|
|
|
}
|
2019-03-18 05:52:32 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-06-17 06:36:38 +00:00
|
|
|
// Init the begin/wait frame semaphore.
|
2020-06-23 17:02:08 +00:00
|
|
|
os_semaphore_init(&sess->sem, 1);
|
|
|
|
|
2020-06-17 06:36:38 +00:00
|
|
|
struct xrt_compositor *xc = sess->compositor;
|
|
|
|
if (xc != NULL) {
|
|
|
|
struct xrt_session_prepare_info xspi = {0};
|
|
|
|
const XrSessionCreateInfoOverlayEXTX *overlay_info =
|
|
|
|
OXR_GET_INPUT_FROM_CHAIN(
|
|
|
|
createInfo, XR_TYPE_SESSION_CREATE_INFO_OVERLAY_EXTX,
|
|
|
|
XrSessionCreateInfoOverlayEXTX);
|
|
|
|
if (overlay_info) {
|
|
|
|
xspi.is_overlay = true;
|
|
|
|
xspi.flags = overlay_info->createFlags;
|
|
|
|
xspi.z_order = overlay_info->sessionLayersPlacement;
|
|
|
|
}
|
|
|
|
xrt_comp_prepare_session(xc, &xspi);
|
|
|
|
}
|
|
|
|
|
2019-03-18 05:52:32 +00:00
|
|
|
sess->ipd_meters = debug_get_num_option_ipd() / 1000.0f;
|
|
|
|
sess->static_prediction_s =
|
|
|
|
debug_get_num_option_prediction_ms() / 1000.0f;
|
|
|
|
|
2020-05-30 17:30:27 +00:00
|
|
|
oxr_session_change_state(log, sess, XR_SESSION_STATE_IDLE);
|
|
|
|
oxr_session_change_state(log, sess, XR_SESSION_STATE_READY);
|
2019-03-18 05:52:32 +00:00
|
|
|
|
2020-06-15 21:46:21 +00:00
|
|
|
u_hashmap_int_create(&sess->act_sets_attachments_by_key);
|
|
|
|
u_hashmap_int_create(&sess->act_attachments_by_key);
|
2019-05-07 12:47:18 +00:00
|
|
|
|
2019-03-18 05:52:32 +00:00
|
|
|
*out_session = sess;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|