From 02fae7c29a3c0e7bd3a23b98653b5322d62dd1c9 Mon Sep 17 00:00:00 2001 From: Simon Zeni Date: Mon, 25 Nov 2024 13:28:42 -0500 Subject: [PATCH] xrt: adapt driver to new compute_distortion api change Co-authored-by: Korcan Hussein Part-of: --- src/xrt/auxiliary/util/u_device.c | 4 ++-- src/xrt/auxiliary/util/u_device.h | 2 +- src/xrt/auxiliary/util/u_distortion_mesh.c | 27 ++++++++-------------- src/xrt/auxiliary/util/u_distortion_mesh.h | 10 +------- src/xrt/drivers/android/android_sensors.c | 5 ++-- src/xrt/drivers/multi_wrapper/multi.c | 3 +-- src/xrt/drivers/north_star/ns_hmd.c | 26 +++++++++++---------- src/xrt/drivers/ohmd/oh_device.c | 8 +++---- src/xrt/drivers/psvr/psvr_device.c | 4 ++-- src/xrt/drivers/rift/rift_distortion.c | 4 ++-- src/xrt/drivers/rift/rift_distortion.h | 2 +- src/xrt/drivers/rift_s/rift_s_hmd.c | 4 ++-- src/xrt/drivers/simula/svr_hmd.c | 4 ++-- src/xrt/drivers/steamvr_lh/device.cpp | 8 +++---- src/xrt/drivers/steamvr_lh/device.hpp | 2 +- src/xrt/drivers/survive/survive_driver.c | 4 ++-- src/xrt/drivers/vive/vive_device.c | 4 ++-- src/xrt/drivers/wmr/wmr_hmd.c | 4 ++-- src/xrt/drivers/xreal_air/xreal_air_hmd.c | 9 +------- src/xrt/include/xrt/xrt_device.h | 5 ++-- src/xrt/ipc/client/ipc_client_hmd.c | 5 ++-- 21 files changed, 61 insertions(+), 83 deletions(-) diff --git a/src/xrt/auxiliary/util/u_device.c b/src/xrt/auxiliary/util/u_device.c index 4a4f664b1..748adcfe3 100644 --- a/src/xrt/auxiliary/util/u_device.c +++ b/src/xrt/auxiliary/util/u_device.c @@ -547,12 +547,12 @@ u_device_ni_get_view_poses(struct xrt_device *xdev, return XRT_ERROR_NOT_IMPLEMENTED; } -bool +xrt_result_t u_device_ni_compute_distortion( struct xrt_device *xdev, uint32_t view, float u, float v, struct xrt_uv_triplet *out_result) { E(compute_distortion); - return false; + return XRT_ERROR_NOT_IMPLEMENTED; } xrt_result_t diff --git a/src/xrt/auxiliary/util/u_device.h b/src/xrt/auxiliary/util/u_device.h index 7a469d512..f5cf50243 100644 --- a/src/xrt/auxiliary/util/u_device.h +++ b/src/xrt/auxiliary/util/u_device.h @@ -248,7 +248,7 @@ u_device_ni_get_view_poses(struct xrt_device *xdev, * * @ingroup aux_util */ -bool +xrt_result_t u_device_ni_compute_distortion( struct xrt_device *xdev, uint32_t view, float u, float v, struct xrt_uv_triplet *out_result); diff --git a/src/xrt/auxiliary/util/u_distortion_mesh.c b/src/xrt/auxiliary/util/u_distortion_mesh.c index 9fae10321..0cbdc93d9 100644 --- a/src/xrt/auxiliary/util/u_distortion_mesh.c +++ b/src/xrt/auxiliary/util/u_distortion_mesh.c @@ -25,7 +25,8 @@ DEBUG_GET_ONCE_NUM_OPTION(mesh_size, "XRT_MESH_SIZE", 64) -typedef bool (*func_calc)(struct xrt_device *xdev, uint32_t view, float u, float v, struct xrt_uv_triplet *result); +typedef xrt_result_t (*func_calc)( + struct xrt_device *xdev, uint32_t view, float u, float v, struct xrt_uv_triplet *result); static int index_for(int row, int col, uint32_t stride, uint32_t offset) @@ -398,30 +399,22 @@ u_compute_distortion_ns_meshgrid( } -bool -u_compute_distortion_none(float u, float v, struct xrt_uv_triplet *result) -{ - result->r.x = u; - result->r.y = v; - result->g.x = u; - result->g.y = v; - result->b.x = u; - result->b.y = v; - return true; -} - - - /* * * No distortion. * */ -bool +xrt_result_t u_distortion_mesh_none(struct xrt_device *xdev, uint32_t view, float u, float v, struct xrt_uv_triplet *result) { - return u_compute_distortion_none(u, v, result); + result->r.x = u; + result->r.y = v; + result->g.x = u; + result->g.y = v; + result->b.x = u; + result->b.y = v; + return XRT_SUCCESS; } void diff --git a/src/xrt/auxiliary/util/u_distortion_mesh.h b/src/xrt/auxiliary/util/u_distortion_mesh.h index 17e603979..edf41bff1 100644 --- a/src/xrt/auxiliary/util/u_distortion_mesh.h +++ b/src/xrt/auxiliary/util/u_distortion_mesh.h @@ -164,20 +164,12 @@ u_compute_distortion_ns_meshgrid( * */ -/*! - * Identity distortion correction sets all result coordinates to u,v. - * - * @ingroup aux_distortion - */ -bool -u_compute_distortion_none(float u, float v, struct xrt_uv_triplet *result); - /*! * Helper function for none distortion devices. * * @ingroup aux_distortion */ -bool +xrt_result_t u_distortion_mesh_none(struct xrt_device *xdev, uint32_t view, float u, float v, struct xrt_uv_triplet *result); diff --git a/src/xrt/drivers/android/android_sensors.c b/src/xrt/drivers/android/android_sensors.c index 017cef670..4c9ae1b89 100644 --- a/src/xrt/drivers/android/android_sensors.c +++ b/src/xrt/drivers/android/android_sensors.c @@ -231,12 +231,13 @@ android_device_get_tracked_pose(struct xrt_device *xdev, * */ -static bool +static xrt_result_t android_device_compute_distortion( struct xrt_device *xdev, uint32_t view, float u, float v, struct xrt_uv_triplet *result) { struct android_device *d = android_device(xdev); - return u_compute_distortion_cardboard(&d->cardboard.values[view], u, v, result); + u_compute_distortion_cardboard(&d->cardboard.values[view], u, v, result); + return XRT_SUCCESS; } diff --git a/src/xrt/drivers/multi_wrapper/multi.c b/src/xrt/drivers/multi_wrapper/multi.c index 414eff097..7d1042cb8 100644 --- a/src/xrt/drivers/multi_wrapper/multi.c +++ b/src/xrt/drivers/multi_wrapper/multi.c @@ -16,7 +16,6 @@ #include "multi.h" - DEBUG_GET_ONCE_LOG_OPTION(multi_log, "MULTI_LOG", U_LOGGING_WARN) #define MULTI_TRACE(d, ...) U_LOG_XDEV_IFL_T(&d->base, d->log_level, __VA_ARGS__) @@ -217,7 +216,7 @@ get_view_poses(struct xrt_device *xdev, return xrt_device_get_tracked_pose(xdev, XRT_INPUT_GENERIC_HEAD_POSE, at_timestamp_ns, out_head_relation); } -static bool +static xrt_result_t compute_distortion(struct xrt_device *xdev, uint32_t view, float u, float v, struct xrt_uv_triplet *result) { struct multi_device *d = (struct multi_device *)xdev; diff --git a/src/xrt/drivers/north_star/ns_hmd.c b/src/xrt/drivers/north_star/ns_hmd.c index 80dbbc698..2a01d9b98 100644 --- a/src/xrt/drivers/north_star/ns_hmd.c +++ b/src/xrt/drivers/north_star/ns_hmd.c @@ -418,12 +418,13 @@ ns_hmd_get_view_poses(struct xrt_device *xdev, return XRT_SUCCESS; } -bool +static xrt_result_t ns_mesh_calc(struct xrt_device *xdev, uint32_t view, float u, float v, struct xrt_uv_triplet *result) { struct ns_hmd *ns = ns_hmd(xdev); NS_DEBUG(ns, "Called!"); // struct xrt_vec2 warped_uv; + switch (ns->config.distortion_type) { case NS_DISTORTION_TYPE_GEOMETRIC_3D: { struct xrt_vec2 uv = {u, v}; @@ -437,19 +438,20 @@ ns_mesh_calc(struct xrt_device *xdev, uint32_t view, float u, float v, struct xr result->g.y = warped_uv.y; result->b.x = warped_uv.x; result->b.y = warped_uv.y; - return true; - } - case NS_DISTORTION_TYPE_POLYNOMIAL_2D: { - return u_compute_distortion_ns_p2d(&ns->config.dist_p2d, view, u, v, result); - } - case NS_DISTORTION_TYPE_MOSHI_MESHGRID: { - return u_compute_distortion_ns_meshgrid(&ns->config.dist_meshgrid, view, u, v, result); - } - default: { - assert(false); - return false; + + res = true; + break; } + case NS_DISTORTION_TYPE_POLYNOMIAL_2D: + u_compute_distortion_ns_p2d(&ns->config.dist_p2d, view, u, v, result); + break; + case NS_DISTORTION_TYPE_MOSHI_MESHGRID: + u_compute_distortion_ns_meshgrid(&ns->config.dist_meshgrid, view, u, v, result); + break; + default: assert(false); break; } + + return XRT_SUCCESS; } /* diff --git a/src/xrt/drivers/ohmd/oh_device.c b/src/xrt/drivers/ohmd/oh_device.c index 1c5d80754..0aca05274 100644 --- a/src/xrt/drivers/ohmd/oh_device.c +++ b/src/xrt/drivers/ohmd/oh_device.c @@ -719,20 +719,20 @@ u_compute_distortion_openhmd(struct openhmd_values *values, float u, float v, st result->b = b_uv; } -static bool +static xrt_result_t compute_distortion_openhmd(struct xrt_device *xdev, uint32_t view, float u, float v, struct xrt_uv_triplet *result) { struct oh_device *ohd = oh_device(xdev); u_compute_distortion_openhmd(&ohd->distortion.openhmd[view], u, v, result); - return true; + return XRT_SUCCESS; } -static bool +static xrt_result_t compute_distortion_vive(struct xrt_device *xdev, uint32_t view, float u, float v, struct xrt_uv_triplet *result) { struct oh_device *ohd = oh_device(xdev); u_compute_distortion_vive(&ohd->distortion.vive[view], u, v, result); - return true; + return XRT_SUCCESS; } static inline void diff --git a/src/xrt/drivers/psvr/psvr_device.c b/src/xrt/drivers/psvr/psvr_device.c index 8bca8e00f..5eeb30b1a 100644 --- a/src/xrt/drivers/psvr/psvr_device.c +++ b/src/xrt/drivers/psvr/psvr_device.c @@ -1006,13 +1006,13 @@ psvr_device_destroy(struct xrt_device *xdev) u_device_free(&psvr->base); } -static bool +static xrt_result_t psvr_compute_distortion(struct xrt_device *xdev, uint32_t view, float u, float v, struct xrt_uv_triplet *result) { struct psvr_device *psvr = psvr_device(xdev); u_compute_distortion_panotools(&psvr->vals, u, v, result); - return true; + return XRT_SUCCESS; } diff --git a/src/xrt/drivers/rift/rift_distortion.c b/src/xrt/drivers/rift/rift_distortion.c index 99f18fbad..6690a09d8 100644 --- a/src/xrt/drivers/rift/rift_distortion.c +++ b/src/xrt/drivers/rift/rift_distortion.c @@ -390,7 +390,7 @@ rift_transform_tan_fov_space_to_screen_ndc(struct rift_distortion_render_info *d } #endif -bool +xrt_result_t rift_hmd_compute_distortion(struct xrt_device *dev, uint32_t view, float u, float v, struct xrt_uv_triplet *out_result) { #define TO_NDC(x) ((x * 2) - 1) @@ -420,7 +420,7 @@ rift_hmd_compute_distortion(struct xrt_device *dev, uint32_t view, float u, floa *out_result = sample_tex_coord; - return true; + return XRT_SUCCESS; #undef TO_NDC } diff --git a/src/xrt/drivers/rift/rift_distortion.h b/src/xrt/drivers/rift/rift_distortion.h index 1d10da57d..52f581601 100644 --- a/src/xrt/drivers/rift/rift_distortion.h +++ b/src/xrt/drivers/rift/rift_distortion.h @@ -36,5 +36,5 @@ rift_calculate_uv_scale_and_offset_from_ndc_scale_and_offset(struct rift_scale_a void rift_fill_in_default_distortions(struct rift_hmd *hmd); -bool +xrt_result_t rift_hmd_compute_distortion(struct xrt_device *dev, uint32_t view, float u, float v, struct xrt_uv_triplet *out_result); diff --git a/src/xrt/drivers/rift_s/rift_s_hmd.c b/src/xrt/drivers/rift_s/rift_s_hmd.c index 12f557e7f..4bc2fcb66 100644 --- a/src/xrt/drivers/rift_s/rift_s_hmd.c +++ b/src/xrt/drivers/rift_s/rift_s_hmd.c @@ -151,12 +151,12 @@ rift_s_hmd_handle_report(struct rift_s_hmd *hmd, timepoint_ns local_ts, rift_s_h } } -static bool +static xrt_result_t rift_s_compute_distortion(struct xrt_device *xdev, uint32_t view, float u, float v, struct xrt_uv_triplet *result) { struct rift_s_hmd *hmd = (struct rift_s_hmd *)(xdev); u_compute_distortion_panotools(&hmd->distortion_vals[view], u, v, result); - return true; + return XRT_SUCCESS; } #if 0 diff --git a/src/xrt/drivers/simula/svr_hmd.c b/src/xrt/drivers/simula/svr_hmd.c index 434aa9977..1c40c269c 100644 --- a/src/xrt/drivers/simula/svr_hmd.c +++ b/src/xrt/drivers/simula/svr_hmd.c @@ -134,7 +134,7 @@ svr_hmd_get_view_poses(struct xrt_device *xdev, } //!@todo: remove hard-coding and move to u_distortion_mesh -bool +static xrt_result_t svr_mesh_calc(struct xrt_device *xdev, uint32_t view, float u, float v, struct xrt_uv_triplet *result) { struct svr_hmd *svr = svr_hmd(xdev); @@ -208,7 +208,7 @@ svr_mesh_calc(struct xrt_device *xdev, uint32_t view, float u, float v, struct x result->g = tc[1]; result->b = tc[2]; - return true; + return XRT_SUCCESS; } diff --git a/src/xrt/drivers/steamvr_lh/device.cpp b/src/xrt/drivers/steamvr_lh/device.cpp index f50ed1f1b..857148eb9 100644 --- a/src/xrt/drivers/steamvr_lh/device.cpp +++ b/src/xrt/drivers/steamvr_lh/device.cpp @@ -218,8 +218,8 @@ HmdDevice::HmdDevice(const DeviceBuilder &builder) : Device(builder) this->inputs = inputs_vec.data(); this->input_count = inputs_vec.size(); - this->xrt_device::get_view_poses = &device_bouncer; -#define SETUP_MEMBER_FUNC(name) this->xrt_device::name = &device_bouncer +#define SETUP_MEMBER_FUNC(name) this->xrt_device::name = &device_bouncer + SETUP_MEMBER_FUNC(get_view_poses); SETUP_MEMBER_FUNC(compute_distortion); SETUP_MEMBER_FUNC(set_brightness); SETUP_MEMBER_FUNC(get_brightness); @@ -620,7 +620,7 @@ HmdDevice::get_view_poses(const xrt_vec3 *default_eye_relation, return XRT_SUCCESS; } -bool +xrt_result_t HmdDevice::compute_distortion(uint32_t view, float u, float v, xrt_uv_triplet *out_result) { vr::EVREye eye = (view == 0) ? vr::Eye_Left : vr::Eye_Right; @@ -628,7 +628,7 @@ HmdDevice::compute_distortion(uint32_t view, float u, float v, xrt_uv_triplet *o out_result->r = {coords.rfRed[0], coords.rfRed[1]}; out_result->g = {coords.rfGreen[0], coords.rfGreen[1]}; out_result->b = {coords.rfBlue[0], coords.rfBlue[1]}; - return true; + return XRT_SUCCESS; } void diff --git a/src/xrt/drivers/steamvr_lh/device.hpp b/src/xrt/drivers/steamvr_lh/device.hpp index 08a04ef40..0d160c87d 100644 --- a/src/xrt/drivers/steamvr_lh/device.hpp +++ b/src/xrt/drivers/steamvr_lh/device.hpp @@ -138,7 +138,7 @@ public: xrt_fov *out_fovs, xrt_pose *out_poses); - bool + xrt_result_t compute_distortion(uint32_t view, float u, float v, xrt_uv_triplet *out_result); void diff --git a/src/xrt/drivers/survive/survive_driver.c b/src/xrt/drivers/survive/survive_driver.c index a1dcf1832..fbe6dd51c 100644 --- a/src/xrt/drivers/survive/survive_driver.c +++ b/src/xrt/drivers/survive/survive_driver.c @@ -901,7 +901,7 @@ survive_device_update_inputs(struct xrt_device *xdev) return XRT_SUCCESS; } -static bool +static xrt_result_t compute_distortion(struct xrt_device *xdev, uint32_t view, float u, float v, struct xrt_uv_triplet *result) { struct survive_device *d = (struct survive_device *)xdev; @@ -913,7 +913,7 @@ compute_distortion(struct xrt_device *xdev, uint32_t view, float u, float v, str result->g.y = 1.0f - result->g.y; result->b.y = 1.0f - result->b.y; } - return true; + return XRT_SUCCESS; } static bool diff --git a/src/xrt/drivers/vive/vive_device.c b/src/xrt/drivers/vive/vive_device.c index 6b8a45be9..697b91cb2 100644 --- a/src/xrt/drivers/vive/vive_device.c +++ b/src/xrt/drivers/vive/vive_device.c @@ -974,7 +974,7 @@ vive_device_setup_ui(struct vive_device *d) u_var_add_ro_text(d, d->gui.hand_status, "Tracker status"); } -static bool +static xrt_result_t compute_distortion(struct xrt_device *xdev, uint32_t view, float u, float v, struct xrt_uv_triplet *result) { XRT_TRACE_MARKER(); @@ -988,7 +988,7 @@ compute_distortion(struct xrt_device *xdev, uint32_t view, float u, float v, str result->g.y = 1.0f - result->g.y; result->b.y = 1.0f - result->b.y; } - return true; + return XRT_SUCCESS; } void diff --git a/src/xrt/drivers/wmr/wmr_hmd.c b/src/xrt/drivers/wmr/wmr_hmd.c index af8ec88fc..c1a969785 100644 --- a/src/xrt/drivers/wmr/wmr_hmd.c +++ b/src/xrt/drivers/wmr/wmr_hmd.c @@ -1247,7 +1247,7 @@ wmr_hmd_destroy(struct xrt_device *xdev) u_device_free(&wh->base); } -static bool +static xrt_result_t compute_distortion_wmr(struct xrt_device *xdev, uint32_t view, float u, float v, struct xrt_uv_triplet *result) { DRV_TRACE_MARKER(); @@ -1304,7 +1304,7 @@ compute_distortion_wmr(struct xrt_device *xdev, uint32_t view, float u, float v, result->g = tc[1]; result->b = tc[2]; - return true; + return XRT_SUCCESS; } /* diff --git a/src/xrt/drivers/xreal_air/xreal_air_hmd.c b/src/xrt/drivers/xreal_air/xreal_air_hmd.c index 3e50b0829..47fd1afb0 100644 --- a/src/xrt/drivers/xreal_air/xreal_air_hmd.c +++ b/src/xrt/drivers/xreal_air/xreal_air_hmd.c @@ -1166,13 +1166,6 @@ xreal_air_hmd_destroy(struct xrt_device *xdev) u_device_free(&hmd->base); } -static bool -xreal_air_hmd_compute_distortion( - struct xrt_device *xdev, uint32_t view, float u, float v, struct xrt_uv_triplet *result) -{ - return u_compute_distortion_none(u, v, result); -} - /* * * Exported functions. @@ -1195,7 +1188,7 @@ xreal_air_hmd_create_device(struct os_hid_device *sensor_device, hmd->base.update_inputs = xreal_air_hmd_update_inputs; hmd->base.get_tracked_pose = xreal_air_hmd_get_tracked_pose; hmd->base.get_view_poses = u_device_get_view_poses; - hmd->base.compute_distortion = xreal_air_hmd_compute_distortion; + hmd->base.compute_distortion = u_distortion_mesh_none; hmd->base.destroy = xreal_air_hmd_destroy; hmd->base.name = XRT_DEVICE_GENERIC_HMD; hmd->base.device_type = XRT_DEVICE_TYPE_HMD; diff --git a/src/xrt/include/xrt/xrt_device.h b/src/xrt/include/xrt/xrt_device.h index cb35e768a..6edf30429 100644 --- a/src/xrt/include/xrt/xrt_device.h +++ b/src/xrt/include/xrt/xrt_device.h @@ -567,7 +567,7 @@ struct xrt_device * @param v vertical texture coordinate * @param[out] out_result corresponding u,v pairs for all three color channels. */ - bool (*compute_distortion)( + xrt_result_t (*compute_distortion)( struct xrt_device *xdev, uint32_t view, float u, float v, struct xrt_uv_triplet *out_result); /*! @@ -887,8 +887,7 @@ static inline xrt_result_t xrt_device_compute_distortion( struct xrt_device *xdev, uint32_t view, float u, float v, struct xrt_uv_triplet *out_result) { - xdev->compute_distortion(xdev, view, u, v, out_result); - return XRT_SUCCESS; + return xdev->compute_distortion(xdev, view, u, v, out_result); } /*! diff --git a/src/xrt/ipc/client/ipc_client_hmd.c b/src/xrt/ipc/client/ipc_client_hmd.c index f1324c8db..32464c4c0 100644 --- a/src/xrt/ipc/client/ipc_client_hmd.c +++ b/src/xrt/ipc/client/ipc_client_hmd.c @@ -177,7 +177,7 @@ ipc_client_hmd_get_view_poses(struct xrt_device *xdev, return xret; } -static bool +static xrt_result_t ipc_client_hmd_compute_distortion( struct xrt_device *xdev, uint32_t view, float u, float v, struct xrt_uv_triplet *out_result) { @@ -191,9 +191,8 @@ ipc_client_hmd_compute_distortion( u, // v, // out_result); // - IPC_CHK_WITH_RET(ich->ipc_c, xret, "ipc_call_device_compute_distortion", false); - return xret == XRT_SUCCESS; + IPC_CHK_ALWAYS_RET(ich->ipc_c, xret, "ipc_call_device_compute_distortion"); } static bool -- 2.51.2