The open source OpenXR runtime

d/blubur_s1: Wire up Poly3k distortion

Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/2590>

authored by

Beyley Cardellio and committed by
Marge Bot
384b347e b2ffa637

+159 -32
+155 -32
src/xrt/drivers/blubur_s1/blubur_s1_hmd.c
··· 14 14 #include "util/u_distortion_mesh.h" 15 15 #include "util/u_misc.h" 16 16 #include "util/u_time.h" 17 + #include "util/u_debug.h" 17 18 18 19 #include "blubur_s1_interface.h" 19 20 #include "blubur_s1_internal.h" 20 21 22 + 23 + DEBUG_GET_ONCE_BOOL_OPTION(blubur_s1_test_distortion, "BLUBUR_S1_TEST_DISTORTION", false) 24 + 25 + #define VIEW_SIZE (1440) 26 + #define PANEL_WIDTH (VIEW_SIZE * 2) 21 27 22 28 static struct blubur_s1_hmd * 23 29 blubur_s1_hmd(struct xrt_device *xdev) ··· 33 39 } 34 40 35 41 static xrt_result_t 36 - blubur_s1_hmd_compute_distortion( 42 + blubur_s1_hmd_compute_poly_3k_distortion( 43 + struct xrt_device *xdev, uint32_t view, float u, float v, struct xrt_uv_triplet *out_result) 44 + { 45 + struct blubur_s1_hmd *hmd = blubur_s1_hmd(xdev); 46 + 47 + struct u_poly_3k_eye_values *values = &hmd->poly_3k_values[view]; 48 + u_compute_distortion_poly_3k(values, view, u, v, out_result); 49 + 50 + return XRT_SUCCESS; 51 + } 52 + 53 + static xrt_result_t 54 + blubur_s1_hmd_compute_test_distortion( 37 55 struct xrt_device *xdev, uint32_t view, float u, float v, struct xrt_uv_triplet *out_result) 38 56 { 39 57 float x = u * 2.0f - 1.0f; ··· 76 94 77 95 // TODO: track pose 78 96 *out_relation = (struct xrt_space_relation){ 79 - .relation_flags = 0, 97 + .relation_flags = XRT_SPACE_RELATION_ORIENTATION_VALID_BIT, 98 + .pose = 99 + { 100 + .orientation = XRT_QUAT_IDENTITY, 101 + }, 80 102 }; 81 103 82 104 return XRT_SUCCESS; ··· 92 114 } 93 115 94 116 static xrt_result_t 95 - blubur_s1_get_view_poses(struct xrt_device *xdev, 96 - const struct xrt_vec3 *default_eye_relation, 97 - int64_t at_timestamp_ns, 98 - uint32_t view_count, 99 - struct xrt_space_relation *out_head_relation, 100 - struct xrt_fov *out_fovs, 101 - struct xrt_pose *out_poses) 117 + blubur_s1_hmd_get_view_poses(struct xrt_device *xdev, 118 + const struct xrt_vec3 *default_eye_relation, 119 + int64_t at_timestamp_ns, 120 + uint32_t view_count, 121 + struct xrt_space_relation *out_head_relation, 122 + struct xrt_fov *out_fovs, 123 + struct xrt_pose *out_poses) 102 124 { 103 125 return u_device_get_view_poses(xdev, default_eye_relation, at_timestamp_ns, view_count, out_head_relation, 104 126 out_fovs, out_poses); 105 127 } 106 128 129 + static void 130 + blubur_s1_hmd_fill_in_poly_3k(struct blubur_s1_hmd *hmd) 131 + { 132 + hmd->poly_3k_values[0] = (struct u_poly_3k_eye_values){ 133 + .channels = 134 + { 135 + { 136 + .display_size = {PANEL_WIDTH, VIEW_SIZE}, 137 + .eye_center = {711.37015431841485f, 702.64004980572099f}, 138 + .k = 139 + { 140 + 2.4622190410034843e-007f, 141 + 1.0691119647014047e-012f, 142 + 6.9872433537257567e-019f, 143 + }, 144 + }, 145 + { 146 + .display_size = {PANEL_WIDTH, VIEW_SIZE}, 147 + .eye_center = {710.34756994635097f, 702.30352808724865f}, 148 + .k = 149 + { 150 + 3.3081468849915169e-007f, 151 + 6.6872723393907828e-013f, 152 + 1.5518253834715642e-018f, 153 + }, 154 + }, 155 + { 156 + .display_size = {PANEL_WIDTH, VIEW_SIZE}, 157 + .eye_center = {709.19922270098721f, 702.42895617576141f}, 158 + .k = 159 + { 160 + 4.6306924021839207e-007f, 161 + 1.5032174824131911e-013f, 162 + 2.6240474534705725e-018f, 163 + }, 164 + }, 165 + }, 166 + }; 167 + // NOTE: these distortion values appear to exhibit the Y offset bug that some WMR headsets do, worked around it 168 + // by copying eye center Y to the other eye 169 + hmd->poly_3k_values[1] = (struct u_poly_3k_eye_values){ 170 + .channels = 171 + { 172 + { 173 + .display_size = {PANEL_WIDTH, VIEW_SIZE}, 174 + .eye_center = {2166.0195141711984f, 175 + hmd->poly_3k_values->channels[0].eye_center.y /* 693.80762487779759f */}, 176 + .k = 177 + { 178 + 1.6848296693566205e-007f, 179 + 1.1446999540490656e-012f, 180 + 1.8794325973106313e-019f, 181 + }, 182 + }, 183 + { 184 + .display_size = {PANEL_WIDTH, VIEW_SIZE}, 185 + .eye_center = {2164.9567320272263f, 186 + hmd->poly_3k_values->channels[1].eye_center.y /* 693.8666328641682f */}, 187 + .k = 188 + { 189 + 2.2979021408214227e-007f, 190 + 9.2094643470416607e-013f, 191 + 6.8614927296300735e-019f, 192 + }, 193 + }, 194 + { 195 + .display_size = {PANEL_WIDTH, VIEW_SIZE}, 196 + .eye_center = {2164.0315727658904f, 197 + hmd->poly_3k_values->channels[2].eye_center.y /* 693.45351818980896f */}, 198 + .k = 199 + { 200 + 3.1993667496208384e-007f, 201 + 6.1930456677642785e-013f, 202 + 1.2848584929803272e-018f, 203 + }, 204 + }, 205 + }, 206 + }; 207 + 208 + struct xrt_matrix_3x3 affine_xform[2] = { 209 + { 210 + .v = 211 + { 212 + 886.745f, 0.205964f, 710.326f, // 213 + 0, 886.899f, 706.657f, // 214 + 0, 0, 1, // 215 + }, 216 + }, 217 + { 218 + .v = 219 + { 220 + 880.317f, 0.277553f, 2163.58f, // 221 + 0, 879.669f, 698.35f, // 222 + 0, 0, 1, // 223 + }, 224 + }, 225 + }; 226 + 227 + for (int i = 0; i < 2; i++) { 228 + math_matrix_3x3_inverse(&affine_xform[i], &hmd->poly_3k_values[i].inv_affine_xform); 229 + 230 + u_compute_distortion_bounds_poly_3k( 231 + &hmd->poly_3k_values[i].inv_affine_xform, hmd->poly_3k_values[i].channels, i, 232 + &hmd->base.hmd->distortion.fov[i], &hmd->poly_3k_values[i].tex_x_range, 233 + &hmd->poly_3k_values[i].tex_y_range); 234 + } 235 + } 236 + 107 237 struct blubur_s1_hmd * 108 238 blubur_s1_hmd_create(struct os_hid_device *dev, const char *serial) 109 239 { ··· 117 247 hmd->base.name = XRT_DEVICE_GENERIC_HMD; 118 248 hmd->base.device_type = XRT_DEVICE_TYPE_HMD; 119 249 120 - const int view_size = 1440; 121 - 122 - hmd->base.hmd->screens[0].w_pixels = view_size * 2; 123 - hmd->base.hmd->screens[0].h_pixels = view_size; 250 + hmd->base.hmd->screens[0].w_pixels = PANEL_WIDTH; 251 + hmd->base.hmd->screens[0].h_pixels = VIEW_SIZE; 124 252 hmd->base.hmd->screens[0].nominal_frame_interval_ns = 1000000000LLU / 120; // 120hz 125 253 126 254 hmd->base.hmd->view_count = 2; ··· 129 257 { 130 258 .x_pixels = 0, 131 259 .y_pixels = 0, 132 - .w_pixels = view_size, 133 - .h_pixels = view_size, 260 + .w_pixels = VIEW_SIZE, 261 + .h_pixels = VIEW_SIZE, 134 262 }, 135 263 .display = 136 264 { 137 - .w_pixels = view_size, 138 - .h_pixels = view_size, 265 + .w_pixels = VIEW_SIZE, 266 + .h_pixels = VIEW_SIZE, 139 267 }, 140 268 .rot = u_device_rotation_ident, 141 269 }; 142 270 hmd->base.hmd->views[1] = (struct xrt_view){ 143 271 .viewport = 144 272 { 145 - .x_pixels = view_size, 273 + .x_pixels = VIEW_SIZE, 146 274 .y_pixels = 0, 147 - .w_pixels = view_size, 148 - .h_pixels = view_size, 275 + .w_pixels = VIEW_SIZE, 276 + .h_pixels = VIEW_SIZE, 149 277 }, 150 278 .display = 151 279 { 152 - .w_pixels = view_size, 153 - .h_pixels = view_size, 280 + .w_pixels = VIEW_SIZE, 281 + .h_pixels = VIEW_SIZE, 154 282 }, 155 283 .rot = u_device_rotation_ident, 156 284 }; ··· 158 286 hmd->base.hmd->blend_modes[0] = XRT_BLEND_MODE_OPAQUE; 159 287 hmd->base.hmd->blend_mode_count = 1; 160 288 161 - // TODO: what's the real FOV? 162 - hmd->base.hmd->distortion.fov[0] = (struct xrt_fov){ 163 - .angle_left = 45.0f * (M_PI / 180.0f), 164 - .angle_right = 45.0f * (M_PI / 180.0f), 165 - .angle_up = 45.0f * (M_PI / 180.0f), 166 - .angle_down = 45.0f * (M_PI / 180.0f), 167 - }; 168 - hmd->base.hmd->distortion.fov[1] = hmd->base.hmd->distortion.fov[0]; 289 + blubur_s1_hmd_fill_in_poly_3k(hmd); 169 290 170 291 hmd->base.hmd->distortion.models = XRT_DISTORTION_MODEL_COMPUTE; 171 292 hmd->base.hmd->distortion.preferred = XRT_DISTORTION_MODEL_COMPUTE; 172 - hmd->base.compute_distortion = blubur_s1_hmd_compute_distortion; 293 + hmd->base.compute_distortion = debug_get_bool_option_blubur_s1_test_distortion() 294 + ? blubur_s1_hmd_compute_test_distortion 295 + : blubur_s1_hmd_compute_poly_3k_distortion; 173 296 u_distortion_mesh_fill_in_compute(&hmd->base); 174 297 175 298 snprintf(hmd->base.str, XRT_DEVICE_NAME_LEN, "Blubur S1"); ··· 183 306 hmd->base.update_inputs = blubur_s1_hmd_update_inputs; 184 307 hmd->base.get_tracked_pose = blubur_s1_hmd_get_tracked_pose; 185 308 hmd->base.get_presence = blubur_s1_hmd_get_presence; 186 - hmd->base.get_view_poses = blubur_s1_get_view_poses; 309 + hmd->base.get_view_poses = blubur_s1_hmd_get_view_poses; 187 310 188 311 return hmd; 189 312 }
+4
src/xrt/drivers/blubur_s1/blubur_s1_internal.h
··· 9 9 10 10 #pragma once 11 11 12 + #include "util/u_distortion_mesh.h" 13 + 12 14 #include "blubur_s1_interface.h" 13 15 14 16 15 17 struct blubur_s1_hmd 16 18 { 17 19 struct xrt_device base; 20 + 21 + struct u_poly_3k_eye_values poly_3k_values[2]; 18 22 };