st/oxr: Use xrt_instance_create_system

This commit is contained in:
Jakob Bornecrantz 2022-05-09 17:43:00 +01:00
parent 634d495301
commit 3c6bf7b912
4 changed files with 43 additions and 59 deletions

View file

@ -327,15 +327,16 @@ oxr_hand_tracker_create(struct oxr_logger *log,
hand_tracker->hand = createInfo->hand;
hand_tracker->hand_joint_set = createInfo->handJointSet;
//! @todo: move hand tracking device selection to oxr_system.
// if no xdev with hand tracking is found, create hand tracker without xdev.
for (uint32_t i = 0; i < sess->sys->xdev_count; i++) {
struct xrt_device *xdev = sess->sys->xdevs[i];
if (!xdev || !xdev->hand_tracking_supported) {
continue;
}
// Find the assigned device.
struct xrt_device *xdev = NULL;
if (createInfo->hand == XR_HAND_LEFT_EXT) {
xdev = sess->sys->xsysd->roles.hand_tracking.left;
} else if (createInfo->hand == XR_HAND_RIGHT_EXT) {
xdev = sess->sys->xsysd->roles.hand_tracking.right;
}
// Find the correct input on the device.
if (xdev != NULL && xdev->hand_tracking_supported) {
for (uint32_t j = 0; j < xdev->input_count; j++) {
struct xrt_input *input = &xdev->inputs[j];
@ -348,10 +349,11 @@ oxr_hand_tracker_create(struct oxr_logger *log,
break;
}
}
}
if (hand_tracker->xdev != NULL) {
break;
}
// Sanity checking.
if (xdev != NULL && hand_tracker->xdev == NULL) {
oxr_warn(log, "We got hand tracking xdev but it didn't have a hand tracking input.");
}
*out_hand_tracker = hand_tracker;

View file

@ -1448,8 +1448,8 @@ oxr_action_sync_data(struct oxr_logger *log,
int64_t now = time_state_get_now(sess->sys->inst->timekeeping);
// Loop over all xdev devices.
for (size_t i = 0; i < sess->sys->xdev_count; i++) {
oxr_xdev_update(sess->sys->xdevs[i]);
for (size_t i = 0; i < sess->sys->xsysd->xdev_count; i++) {
oxr_xdev_update(sess->sys->xsysd->xdevs[i]);
}
// Reset all action set attachments.

View file

@ -76,9 +76,7 @@ oxr_instance_destroy(struct oxr_logger *log, struct oxr_handle_base *hb)
u_hashset_destroy(&inst->action_sets.name_store);
u_hashset_destroy(&inst->action_sets.loc_store);
for (size_t i = 0; i < inst->system.xdev_count; i++) {
oxr_xdev_destroy(&inst->system.xdevs[i]);
}
xrt_system_devices_destroy(&inst->system.xsysd);
/* ---- HACK ---- */
oxr_sdl2_hack_stop(&inst->hack);
@ -103,14 +101,6 @@ cache_path(struct oxr_logger *log, struct oxr_instance *inst, const char *str, X
oxr_path_get_or_create(log, inst, str, strlen(str), out_path);
}
#define NUM_XDEVS 16
static inline size_t
min_size_t(size_t a, size_t b)
{
return a < b ? a : b;
}
static bool
starts_with(const char *with, const char *string)
{
@ -181,7 +171,6 @@ oxr_instance_create(struct oxr_logger *log,
struct oxr_instance **out_instance)
{
struct oxr_instance *inst = NULL;
struct xrt_device *xdevs[NUM_XDEVS] = {0};
int xinst_ret;
int m_ret;
int h_ret;
@ -269,30 +258,34 @@ oxr_instance_create(struct oxr_logger *log,
return ret;
}
struct oxr_system *sys = &inst->system;
xinst_ret = xrt_instance_select(inst->xinst, xdevs, NUM_XDEVS);
if (xinst_ret != 0) {
ret = oxr_error(log, XR_ERROR_RUNTIME_FAILURE, "Failed to select device(s)");
// Create the compositor if we are not headless.
if (!inst->extensions.MND_headless) {
xret = xrt_instance_create_system(inst->xinst, &sys->xsysd, &sys->xsysc);
} else {
xret = xrt_instance_create_system(inst->xinst, &sys->xsysd, NULL);
}
if (xret != XRT_SUCCESS) {
ret = oxr_error(log, XR_ERROR_INITIALIZATION_FAILED, "Failed to create the system '%i'", xret);
oxr_instance_destroy(log, &inst->handle);
return ret;
}
struct oxr_system *sys = &inst->system;
#define POPULATE_ROLES(X) sys->role.X = XRT_DEVICE_ROLE_UNASSIGNED;
OXR_FOR_EACH_VALID_SUBACTION_PATH(POPULATE_ROLES)
#undef POPULATE_ROLES
sys->xdev_count = min_size_t(ARRAY_SIZE(sys->xdevs), NUM_XDEVS);
for (uint32_t i = 0; i < sys->xdev_count; i++) {
sys->xdevs[i] = xdevs[i];
}
for (size_t i = sys->xdev_count; i < NUM_XDEVS; i++) {
oxr_xdev_destroy(&xdevs[i]);
ret = XR_SUCCESS;
if (sys->xsysd == NULL) {
ret = oxr_error(log, XR_ERROR_RUNTIME_FAILURE, "Huh?! Field sys->xsysd was NULL?");
} else if (!inst->extensions.MND_headless && sys->xsysc == NULL) {
ret = oxr_error(log, XR_ERROR_RUNTIME_FAILURE, "Huh?! Field sys->xsysc was NULL?");
} else if (inst->extensions.MND_headless && sys->xsysc != NULL) {
ret = oxr_error(log, XR_ERROR_RUNTIME_FAILURE, "Huh?! Field sys->xsysc was not NULL?");
}
u_device_assign_xdev_roles(xdevs, NUM_XDEVS, &sys->role.head, &sys->role.left, &sys->role.right);
if (ret != XR_SUCCESS) {
oxr_instance_destroy(log, &inst->handle);
return ret;
}
// Did we find any HMD
// @todo Headless with only controllers?
@ -313,18 +306,6 @@ oxr_instance_create(struct oxr_logger *log,
// Sets the enabled extensions, this is where we should do any extra validation.
inst->extensions = *extensions;
// Create the compositor, if we are not headless.
if (!inst->extensions.MND_headless) {
xret = xrt_instance_create_system_compositor(inst->xinst, dev, &sys->xsysc);
if (ret < 0 || sys->xsysc == NULL) {
ret = oxr_error(log, XR_ERROR_INITIALIZATION_FAILED,
"Failed to create the system compositor '%i'", xret);
oxr_instance_destroy(log, &inst->handle);
return ret;
}
}
ret = oxr_system_fill_in(log, inst, 1, &inst->system);
if (ret != XR_SUCCESS) {
oxr_instance_destroy(log, &inst->handle);
@ -344,7 +325,7 @@ oxr_instance_create(struct oxr_logger *log,
u_var_add_root((void *)inst, "XrInstance", true);
/* ---- HACK ---- */
oxr_sdl2_hack_start(inst->hack, inst->xinst, sys->xdevs);
oxr_sdl2_hack_start(inst->hack, inst->xinst, sys->xsysd->xdevs);
/* ---- HACK ---- */
oxr_log(log,

View file

@ -9,6 +9,7 @@
#pragma once
#include "xrt/xrt_system.h"
#include "xrt/xrt_device.h"
#include "xrt/xrt_tracking.h"
#include "xrt/xrt_compositor.h"
@ -1163,12 +1164,12 @@ struct oxr_system
{
struct oxr_instance *inst;
//! System devices used in all session types.
struct xrt_system_devices *xsysd;
//! System compositor, used to create session compositors.
struct xrt_system_compositor *xsysc;
struct xrt_device *xdevs[16];
size_t xdev_count;
/* index for xdevs array */
struct
{
@ -1206,7 +1207,7 @@ struct oxr_system
#endif
};
#define GET_XDEV_BY_ROLE(SYS, ROLE) SYS->role.ROLE == XRT_DEVICE_ROLE_UNASSIGNED ? NULL : SYS->xdevs[SYS->role.ROLE]
#define GET_XDEV_BY_ROLE(SYS, ROLE) ((SYS)->xsysd->roles.ROLE)
#define MAKE_EXT_STATUS(mixed_case, all_caps) bool mixed_case;
/*!