Monado OpenXR Runtime
Loading...
Searching...
No Matches
oxr_input.c File Reference

Holds input related functions. More...

#include "xrt/xrt_compiler.h"
#include "util/u_debug.h"
#include "util/u_time.h"
#include "util/u_misc.h"
#include "math/m_vec2.h"
#include "oxr_input.h"
#include "oxr_resolver_for_bindings.h"
#include "oxr_binding.h"
#include "oxr_binding_registry.h"
#include "oxr_pair_hashset.h"
#include "oxr_priority_group_cache.h"
#include "oxr_subaction.h"
#include "oxr_dpad_state.h"
#include "oxr_input_transform.h"
#include "oxr_instance_action_context.h"
#include "oxr_generated_bindings.h"
#include "oxr_handle_base.h"
#include "oxr_suggested_profile_array.h"
#include "oxr_session_action_context.h"
#include "../oxr_objects.h"
#include "../oxr_logger.h"
#include "../oxr_two_call.h"
#include "../oxr_conversions.h"
#include "../oxr_xret.h"
#include "../oxr_roles.h"
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
Include dependency graph for oxr_input.c:

Data Structures

struct  oxr_profiles_per_subaction
 

Macros

#define INFO_MEMBER(X)   struct oxr_profile_resolver_info X;
 
#define ACCUMULATE_SUBACTION_PATHS(X)   subaction_paths->X |= new_subaction_paths->X;
 
#define CACHE_TEARDOWN(X)   oxr_action_cache_teardown(&(act_attached->X));
 
#define GET_POSE_INPUT(X)
 
#define GET_BINDING_DEVICE(NAME, IOC)   binding_device_from_cache((IOC), (IOC)->info.NAME)
 Every top-level role (left, right, gamepad, head, eyes) is looked up in the io cache via the matching xrt_io_cache_info role index.
 
#define RESOLVE_INFO(NAME, NAME_CAPS, PATH, LOCALIZED_NAME)
 
#define BIND_SUBACTION(NAME, NAME_CAPS, PATH, LOCALIZED_NAME)
 
#define RESET_ANY(NAME)   act_attached->any_pose_subaction_path.NAME = false;
 
#define POSE_ANY(NAME)
 
#define ACCUMULATE_CACHE(NAME, NAME_CAPS, PATH, LOCALIZED_NAME)
 
#define BOOL_CHECK(NAME)   oxr_state_update_bool(&active, &value, &timestamp, &act_attached->NAME.current);
 
#define VEC1_CHECK(NAME)   oxr_state_update_vec1(&active, &value, &timestamp, &act_attached->NAME.current);
 
#define VEC2_CHECK(NAME)   oxr_state_update_vec2(&active, &x, &y, &distance, &timestamp, &act_attached->NAME.current);
 
#define UPDATE_SELECT(X)
 
#define CACHE_TEARDOWN(X)   oxr_action_cache_teardown(&(act_attached->X));
 
#define POPULATE_PROFILE(X)
 
#define ACCUMULATE_REQUESTED(X)    any_action_with_subactionpath |= subaction_paths.X && act_attached->act_ref->subaction_paths.X;
 
#define ACCUMULATE_PATHS(X)
 

Functions

static void get_action_set_attachment (struct oxr_session_action_context *sess_context, XrActionSet actionSet, struct oxr_action_set_attachment **out_act_set_attached, struct oxr_action_set **out_act_set)
 Given an Action Set handle, return the oxr_action_set and the associated oxr_action_set_attachment in the given Session.
 
static void oxr_action_cache_update (struct oxr_logger *log, struct oxr_session *sess, uint32_t countActionSets, const XrActiveActionSet *actionSets, struct oxr_action_attachment *act_attached, struct oxr_action_cache *cache, int64_t time, struct oxr_subaction_paths *subaction_path, bool select)
 
static void oxr_action_attachment_update (struct oxr_logger *log, struct oxr_session *sess, uint32_t countActionSets, const XrActiveActionSet *actionSets, struct oxr_action_attachment *act_attached, int64_t time, struct oxr_subaction_paths subaction_paths)
 
static void oxr_action_bind_io (struct oxr_logger *log, struct oxr_sink_logger *slog, const struct oxr_session_action_context *sess_context, const struct oxr_profile_resolver_info *info, const struct xrt_io_cache_device *dev, XrPath subaction_path, struct oxr_action_cache *cache, struct oxr_action_attachment *act_attached)
 
static void reset_last_sync_priorities (struct oxr_session_action_context *action_context)
 
static void reset_inactive_sync_priority_state (struct oxr_session_action_context *action_context)
 
void oxr_action_set_attachment_teardown (struct oxr_action_set_attachment *act_set_attached)
 
static void oxr_action_set_ref_destroy_cb (struct oxr_refcounted *orc)
 
static XrResult oxr_action_set_destroy_cb (struct oxr_logger *log, struct oxr_handle_base *hb)
 
XrResult oxr_action_set_create (struct oxr_logger *log, struct oxr_instance *inst, struct oxr_instance_action_context *inst_context, const XrActionSetCreateInfo *createInfo, struct oxr_action_set **out_act_set)
 
static void oxr_action_ref_destroy_cb (struct oxr_refcounted *orc)
 
static XrResult oxr_action_destroy_cb (struct oxr_logger *log, struct oxr_handle_base *hb)
 
XrResult oxr_action_create (struct oxr_logger *log, struct oxr_action_set *act_set, const XrActionCreateInfo *createInfo, struct oxr_action **out_act)
 
XrResult oxr_action_get_pose_input (struct oxr_session *sess, uint32_t act_key, const struct oxr_subaction_paths *subaction_paths_ptr, struct oxr_action_input **out_input)
 
static const struct xrt_io_cache_device * binding_device_from_cache (const struct oxr_io_cache *io_cache, int32_t index)
 Look up the cache device entry for a role slot, where index is one of the xrt_io_cache_info role indices (left, right, gamepad, head, eyes).
 
static void resolve_binding_infos_from_roles (struct oxr_logger *log, const struct oxr_instance_path_cache *path_cache, const struct oxr_session_action_context *action_context, const struct oxr_suggested_profile_array *suggested_profiles, const struct oxr_roles *roles, bool debug_bindings, struct oxr_profiles_per_subaction *out_infos)
 
void oxr_action_cache_stop_output (struct oxr_logger *log, struct oxr_session *sess, struct oxr_action_cache *cache)
 
static uint32_t oxr_get_action_set_priority (const struct oxr_action_set_ref *act_set_ref, const XrActiveActionSetPrioritiesEXT *activePriorities)
 
static void accumulate_priority_group_cache (struct oxr_action_cache *cache, uint32_t priority)
 
static void oxr_session_rebuild_priority_group_states (struct oxr_session_action_context *action_context, uint32_t countActionSets, const XrActiveActionSet *actionSets, const XrActiveActionSetPrioritiesEXT *activePriorities)
 
static bool input_suppressed (const struct oxr_action_attachment *act_attached, const struct oxr_action_input *action_input)
 
static bool oxr_input_combine_input (struct oxr_session *sess, uint32_t countActionSets, const XrActiveActionSet *actionSets, struct oxr_action_attachment *act_attached, struct oxr_subaction_paths *subaction_path, struct oxr_action_cache *cache, struct oxr_input_value_tagged *out_input, int64_t *out_timestamp, bool *out_is_active)
 
static bool oxr_state_equal_bool (const struct oxr_action_state *a, const struct oxr_action_state *b)
 
static bool oxr_state_equal_vec1 (const struct oxr_action_state *a, const struct oxr_action_state *b)
 
static bool oxr_state_equal_vec2 (const struct oxr_action_state *a, const struct oxr_action_state *b)
 
static void oxr_state_update_bool (bool *active, bool *value, XrTime *timestamp, const struct oxr_action_state *new_state)
 
static void oxr_state_update_vec1 (bool *active, float *value, XrTime *timestamp, const struct oxr_action_state *new_state)
 
static void oxr_state_update_vec2 (bool *active, float *x, float *y, float *distance, XrTime *timestamp, const struct oxr_action_state *new_state)
 
XrResult oxr_session_attach_action_sets (struct oxr_logger *log, const struct oxr_instance_action_context *inst_context, struct oxr_session_attached_actions *attached_actions, struct oxr_session_action_context *sess_context, const XrSessionActionSetsAttachInfo *bindInfo)
 
static void session_clear_action_bindings (struct oxr_session_action_context *action_context)
 Tear down the resolved input/output bindings of every attached action.
 
static XrResult session_update_action_bindings (struct oxr_logger *log, struct oxr_instance *inst, struct oxr_session_action_context *action_context, const struct oxr_roles *roles, bool *out_interaction_profile_changed)
 
static XrResult session_sync_io_cache_locked (struct oxr_logger *log, struct oxr_instance *inst, struct oxr_session_action_context *sess_context, const struct oxr_roles *roles, bool *out_interaction_profile_changed)
 
XrResult oxr_action_sync_data (struct oxr_logger *log, struct oxr_session *sess, uint32_t countActionSets, const XrActiveActionSet *actionSets, const XrActiveActionSetPrioritiesEXT *activePriorities)
 
XrResult oxr_action_sync_data_with_context (struct oxr_logger *log, struct oxr_session *sess, struct oxr_session_action_context *sess_context, uint32_t countActionSets, const XrActiveActionSet *actionSets, const XrActiveActionSetPrioritiesEXT *activePriorities, bool *out_interaction_profile_changed)
 
static void add_path_to_set (XrPath path_set[32], XrPath new_path, uint32_t *inout_path_count)
 
static void add_cache_bound_sources (const struct oxr_action_attachment *act_attached, const struct oxr_action_cache *cache, XrPath path_set[32], uint32_t *inout_path_count)
 
XrResult oxr_action_enumerate_bound_sources (struct oxr_logger *log, struct oxr_session *sess, uint32_t act_key, uint32_t sourceCapacityInput, uint32_t *sourceCountOutput, XrPath *sources)
 

Detailed Description

Macro Definition Documentation

◆ ACCUMULATE_CACHE

#define ACCUMULATE_CACHE (   NAME,
  NAME_CAPS,
  PATH,
  LOCALIZED_NAME 
)
Value:
if (act_set_attached->requested_subaction_paths.any || act_set_attached->requested_subaction_paths.NAME) { \
accumulate_priority_group_cache(&act_attached->NAME, priority); \
}

◆ ACCUMULATE_PATHS

#define ACCUMULATE_PATHS (   X)
Value:
do { \
const struct oxr_action_set_attachment *act_set_attached = act_attached->act_set_attached; \
const bool subaction_path_active = \
act_set_attached->requested_subaction_paths.any || act_set_attached->requested_subaction_paths.X; \
if (subaction_path_active) { \
add_cache_bound_sources(act_attached, &act_attached->X, temp, &path_count); \
} \
} while (false);
The data associated with the attachment of an Action Set (oxr_action_set) to as Session (oxr_session)...
Definition oxr_objects.h:1511
struct oxr_subaction_paths requested_subaction_paths
Which sub-action paths are requested on the latest sync.
Definition oxr_objects.h:1522

◆ BIND_SUBACTION

#define BIND_SUBACTION (   NAME,
  NAME_CAPS,
  PATH,
  LOCALIZED_NAME 
)
Value:
if (act_ref->subaction_paths.NAME || act_ref->subaction_paths.any) { \
oxr_slog(&slog, "\tFor: %s\n", #NAME); \
struct oxr_session_action_context *sess_context = act_attached->act_set_attached->sess_context; \
const struct xrt_io_cache_device *dev = GET_BINDING_DEVICE(NAME, &sess_context->io_cache); \
oxr_action_bind_io(log, &slog, sess_context, &resolver_infos->NAME, dev, inst->path_cache.NAME, \
&act_attached->NAME, act_attached); \
}
#define GET_BINDING_DEVICE(NAME, IOC)
Every top-level role (left, right, gamepad, head, eyes) is looked up in the io cache via the matching...
Definition oxr_input.c:570
This holds all of the action state that belongs on the session level.
Definition oxr_session_action_context.h:69
Per-device layout entry describing where a device's inputs and outputs sit in the flattened cache arr...
Definition xrt_io_cache.h:31

◆ GET_BINDING_DEVICE

#define GET_BINDING_DEVICE (   NAME,
  IOC 
)    binding_device_from_cache((IOC), (IOC)->info.NAME)

Every top-level role (left, right, gamepad, head, eyes) is looked up in the io cache via the matching xrt_io_cache_info role index.

◆ GET_POSE_INPUT

#define GET_POSE_INPUT (   X)
Value:
if (act_attached->X.current.active && subaction_paths.X) { \
*out_input = act_attached->X.inputs; \
return XR_SUCCESS; \
}

◆ POPULATE_PROFILE

#define POPULATE_PROFILE (   X)
Value:
do { \
XrPath path = profiles.X.profile != NULL ? profiles.X.profile->path : XR_NULL_PATH; \
if (path == XR_NULL_PATH) { \
break; /* Only update on "active" interaction profiles per sub-action path. */ \
} \
if (action_context->X != path) { \
action_context->X = path; \
interaction_profile_changed = true; \
} \
} while (false);

◆ POSE_ANY

#define POSE_ANY (   NAME)
Value:
if ((act_ref->subaction_paths.NAME || act_ref->subaction_paths.any) && act_attached->NAME.input_count > 0) { \
act_attached->any_pose_subaction_path.NAME = true; \
oxr_slog(&slog, "\tFor: <any>\n\t\tBinding any pose to " #NAME ".\n"); \
} else

◆ RESOLVE_INFO

#define RESOLVE_INFO (   NAME,
  NAME_CAPS,
  PATH,
  LOCALIZED_NAME 
)
Value:
do { \
const struct xrt_io_cache_device *dev = GET_BINDING_DEVICE(NAME, io_cache); \
if (dev == NULL) { \
oxr_slog(&slog, "\n\t" #NAME ": No device"); \
break; \
} \
oxr_slog(&slog, "\n\t" #NAME ": (%s)", u_str_xrt_device_name(dev->name)); \
oxr_resolver_populate_profile(log, &slog, action_context->binding_registry, suggested_profiles, dev, \
path_cache->NAME, GET_PROFILE_NAME_BY_ROLE(roles, NAME), \
&out_infos->NAME); \
} while (false);
enum xrt_device_name name
Device name enum.
Definition xrt_io_cache.h:39

◆ UPDATE_SELECT

#define UPDATE_SELECT (   X)
Value:
struct oxr_subaction_paths subaction_paths_##X = {0}; \
subaction_paths_##X.X = true; \
bool select_##X = subaction_paths.X || subaction_paths.any; \
oxr_action_cache_update(log, sess, countActionSets, actionSets, act_attached, &act_attached->X, time, \
&subaction_paths_##X, select_##X);
A parsed equivalent of a list of sub-action paths.
Definition oxr_subaction.h:99

Function Documentation

◆ binding_device_from_cache()

static const struct xrt_io_cache_device * binding_device_from_cache ( const struct oxr_io_cache *  io_cache,
int32_t  index 
)
static

Look up the cache device entry for a role slot, where index is one of the xrt_io_cache_info role indices (left, right, gamepad, head, eyes).

Every top-level role is resolved purely through the xrt_io_cache; returns NULL when the role has no assigned device.

References xrt_io_cache_info::devices, and oxr_io_cache::info.

◆ get_action_set_attachment()

static void get_action_set_attachment ( struct oxr_session_action_context *  sess_context,
XrActionSet  actionSet,
struct oxr_action_set_attachment **  out_act_set_attached,
struct oxr_action_set **  out_act_set 
)
static

Given an Action Set handle, return the oxr_action_set and the associated oxr_action_set_attachment in the given Session.

References oxr_action_set::act_set_key, and XRT_CAST_OXR_HANDLE_TO_PTR.

Referenced by oxr_action_sync_data_with_context().

◆ oxr_action_create()

◆ oxr_action_sync_data_with_context()

XrResult oxr_action_sync_data_with_context ( struct oxr_logger *  log,
struct oxr_session *  sess,
struct oxr_session_action_context *  sess_context,
uint32_t  countActionSets,
const XrActiveActionSet *  actionSets,
const XrActiveActionSetPrioritiesEXT *  activePriorities,
bool *  out_interaction_profile_changed 
)

◆ session_clear_action_bindings()

static void session_clear_action_bindings ( struct oxr_session_action_context *  action_context)
static

Tear down the resolved input/output bindings of every attached action.

Used before recreating the io cache: the bindings hold pointers into the cache's snapshot arrays, so they must be dropped before those arrays go away.

References oxr_action_set_attachment::act_attachments, oxr_action_attachment::act_set_attached, oxr_session_action_context::act_set_attachments, oxr_action_set_attachment::action_attachment_count, oxr_session_action_context::action_set_attachment_count, and OXR_FOR_EACH_SUBACTION_PATH.