st/oxr: Better logging when creating transforms

This commit is contained in:
Jakob Bornecrantz 2020-08-18 17:04:56 +01:00
parent 25c78287a2
commit 1109bc7cfb

View file

@ -14,9 +14,42 @@
#include "util/u_misc.h" #include "util/u_misc.h"
#include "openxr/openxr_reflection.h"
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
static const char *
xr_action_type_to_str(XrActionType type)
{
// clang-format off
switch (type) {
#define PRINT(name, value) \
case name: return #name;
XR_LIST_ENUM_XrActionType(PRINT)
#undef PRINT
default: return "XR_ACTION_TYPE_UNKNOWN";
}
// clang-format on
}
static const char *
xrt_input_type_to_str(enum xrt_input_type type)
{
// clang-format off
switch (type) {
case XRT_INPUT_TYPE_VEC1_ZERO_TO_ONE: return "XRT_INPUT_TYPE_VEC1_ZERO_TO_ONE";
case XRT_INPUT_TYPE_VEC1_MINUS_ONE_TO_ONE: return "XRT_INPUT_TYPE_VEC1_MINUS_ONE_TO_ONE";
case XRT_INPUT_TYPE_VEC2_MINUS_ONE_TO_ONE: return "XRT_INPUT_TYPE_VEC2_MINUS_ONE_TO_ONE";
case XRT_INPUT_TYPE_VEC3_MINUS_ONE_TO_ONE: return "XRT_INPUT_TYPE_VEC3_MINUS_ONE_TO_ONE";
case XRT_INPUT_TYPE_BOOLEAN: return "XRT_INPUT_TYPE_BOOLEAN";
case XRT_INPUT_TYPE_POSE: return "XRT_INPUT_TYPE_POSE";
default: return "XRT_INPUT_UNKNOWN";
}
// clang-format on
}
/*! /*!
* Arbitrary but larger than required. * Arbitrary but larger than required.
*/ */
@ -174,12 +207,14 @@ ends_with(const char *str, const char *suffix)
return (len >= suffix_len) && return (len >= suffix_len) &&
(0 == strcmp(str + (len - suffix_len), suffix)); (0 == strcmp(str + (len - suffix_len), suffix));
} }
static inline bool static inline bool
input_is_float(enum xrt_input_type input_type) input_is_float(enum xrt_input_type input_type)
{ {
return (input_type == XRT_INPUT_TYPE_VEC1_MINUS_ONE_TO_ONE) || return (input_type == XRT_INPUT_TYPE_VEC1_MINUS_ONE_TO_ONE) ||
(input_type == XRT_INPUT_TYPE_VEC1_ZERO_TO_ONE); (input_type == XRT_INPUT_TYPE_VEC1_ZERO_TO_ONE);
} }
static inline uint8_t static inline uint8_t
input_dim(enum xrt_input_type input_type) input_dim(enum xrt_input_type input_type)
{ {
@ -218,42 +253,53 @@ extend_transform_array(struct oxr_logger *log,
result_type != XR_ACTION_TYPE_VECTOR2F_INPUT) { result_type != XR_ACTION_TYPE_VECTOR2F_INPUT) {
// reduce dimension // reduce dimension
if (ends_with(bound_path_string, "/x")) { if (ends_with(bound_path_string, "/x")) {
oxr_slog(slog, "Adding transform: get x of Vec2\n"); oxr_slog(slog,
"\t\t\tAdding transform: get x of Vec2\n");
return oxr_input_transform_init_vec2_get_x(transform, return oxr_input_transform_init_vec2_get_x(transform,
parent); parent);
} }
if (ends_with(bound_path_string, "/y")) { if (ends_with(bound_path_string, "/y")) {
oxr_slog(slog, "Adding transform: get y of Vec2\n"); oxr_slog(slog,
"\t\t\tAdding transform: get y of Vec2\n");
return oxr_input_transform_init_vec2_get_y(transform, return oxr_input_transform_init_vec2_get_y(transform,
parent); parent);
} }
oxr_log(log, "No rule to get float from vec2f for binding %s\n", oxr_slog(
bound_path_string); slog,
return NULL; "\t\t\tNo rule to get float from vec2f for binding %s\n",
bound_path_string);
return false;
} }
if (input_type == XRT_INPUT_TYPE_VEC1_MINUS_ONE_TO_ONE && if (input_type == XRT_INPUT_TYPE_VEC1_MINUS_ONE_TO_ONE &&
result_type == XR_ACTION_TYPE_BOOLEAN_INPUT) { result_type == XR_ACTION_TYPE_BOOLEAN_INPUT) {
// 0.2 is for a little deadband around the center. // 0.2 is for a little deadband around the center.
oxr_slog(slog, "Adding transform: threshold [-1, 1] float\n"); oxr_slog(slog,
"\t\t\tAdding transform: threshold [-1, 1] float\n");
return oxr_input_transform_init_threshold(transform, parent, return oxr_input_transform_init_threshold(transform, parent,
0.2f, false); 0.2f, false);
} }
if (input_type == XRT_INPUT_TYPE_VEC1_ZERO_TO_ONE && if (input_type == XRT_INPUT_TYPE_VEC1_ZERO_TO_ONE &&
result_type == XR_ACTION_TYPE_BOOLEAN_INPUT) { result_type == XR_ACTION_TYPE_BOOLEAN_INPUT) {
// Need it pressed nearly all the way // Need it pressed nearly all the way
oxr_slog(slog, "Adding transform: threshold [0, 1] float\n"); oxr_slog(slog,
"\t\t\tAdding transform: threshold [0, 1] float\n");
return oxr_input_transform_init_threshold(transform, parent, return oxr_input_transform_init_threshold(transform, parent,
0.7f, false); 0.7f, false);
} }
if (input_type == XRT_INPUT_TYPE_BOOLEAN && if (input_type == XRT_INPUT_TYPE_BOOLEAN &&
result_type == XR_ACTION_TYPE_FLOAT_INPUT) { result_type == XR_ACTION_TYPE_FLOAT_INPUT) {
// this conversion is in the spec // this conversion is in the spec
oxr_slog(slog, "Adding transform: bool to float\n"); oxr_slog(slog, "\t\t\tAdding transform: bool to float\n");
return oxr_input_transform_init_bool_to_vec1( return oxr_input_transform_init_bool_to_vec1(
transform, parent, XRT_INPUT_TYPE_VEC1_ZERO_TO_ONE, 1.f, transform, parent, XRT_INPUT_TYPE_VEC1_ZERO_TO_ONE, 1.f,
0.f); 0.f);
} }
oxr_slog(slog, "\t\t\tCould not transform!\n");
return false; return false;
} }
@ -279,6 +325,10 @@ oxr_input_transform_create_chain(struct oxr_logger *log,
{ {
struct oxr_input_transform chain[OXR_MAX_INPUT_TRANSFORMS] = {0}; struct oxr_input_transform chain[OXR_MAX_INPUT_TRANSFORMS] = {0};
oxr_slog(slog, "\t\tAdding transform from '%s' to '%s'\n",
xr_action_type_to_str(result_type),
xrt_input_type_to_str(input_type));
struct oxr_input_transform *current_xform = &(chain[0]); struct oxr_input_transform *current_xform = &(chain[0]);
if (!oxr_input_transform_init_root(current_xform, input_type)) { if (!oxr_input_transform_init_root(current_xform, input_type)) {
*out_num_transforms = 0; *out_num_transforms = 0;
@ -293,37 +343,40 @@ oxr_input_transform_create_chain(struct oxr_logger *log,
*out_num_transforms = num_transforms; *out_num_transforms = num_transforms;
*out_transforms = *out_transforms =
oxr_input_transform_clone_chain(chain, num_transforms); oxr_input_transform_clone_chain(chain, num_transforms);
oxr_slog(slog, "\t\t\tUsing identity transform for pose.\n");
return true; return true;
} }
while (!oxr_type_matches_xrt(current_xform->result_type, result_type)) { while (!oxr_type_matches_xrt(current_xform->result_type, result_type)) {
if (num_transforms >= OXR_MAX_INPUT_TRANSFORMS) { if (num_transforms >= OXR_MAX_INPUT_TRANSFORMS) {
// Couldn't finish the transform to the desired type. // Couldn't finish the transform to the desired type.
oxr_log( oxr_slog(slog,
log, "\t\t\tSeem to have gotten into a loop, "
"Seem to have gotten into a loop, trying to make a " "trying to make a rule to transform.\n",
"rule to transform action %s, binding %s\n", action_name, bound_path_string);
action_name, bound_path_string);
*out_num_transforms = 0; *out_num_transforms = 0;
*out_transforms = NULL; *out_transforms = NULL;
return false; return false;
} }
struct oxr_input_transform *new_xform = struct oxr_input_transform *new_xform =
&(chain[num_transforms]); &(chain[num_transforms]);
if (!extend_transform_array(log, slog, new_xform, current_xform, if (!extend_transform_array(log, slog, new_xform, current_xform,
result_type, bound_path_string)) { result_type, bound_path_string)) {
// Couldn't finish the transform to the desired type. // Error has already been logged.
oxr_log(log,
"No rule to transform action %s, binding %s\n",
action_name, bound_path_string);
*out_num_transforms = 0; *out_num_transforms = 0;
*out_transforms = NULL; *out_transforms = NULL;
return false; return false;
} }
num_transforms++; num_transforms++;
current_xform = new_xform; current_xform = new_xform;
} }
*out_num_transforms = num_transforms; *out_num_transforms = num_transforms;
*out_transforms = *out_transforms =
oxr_input_transform_clone_chain(chain, num_transforms); oxr_input_transform_clone_chain(chain, num_transforms);
return true; return true;
} }