The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

xrt: Add attachable device spaces

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

+121 -3
+1
src/xrt/auxiliary/util/u_pretty_print.c
··· 267 267 case XRT_OPERATION_CANCELLED: DG("XRT_OPERATION_CANCELLED"); return; 268 268 case XRT_ERROR_FUTURE_RESULT_NOT_READY: DG("XRT_ERROR_FUTURE_RESULT_NOT_READY"); return; 269 269 case XRT_ERROR_FUTURE_ALREADY_COMPLETE: DG("XRT_ERROR_FUTURE_ALREADY_COMPLETE"); return; 270 + case XRT_ERROR_DEVICE_NOT_ATTACHABLE: DG("XRT_ERROR_DEVICE_NOT_ATTACHABLE"); return; 270 271 } 271 272 // clang-format on 272 273
+68 -3
src/xrt/auxiliary/util/u_space_overseer.c
··· 43 43 U_SPACE_TYPE_POSE, 44 44 U_SPACE_TYPE_OFFSET, 45 45 U_SPACE_TYPE_ROOT, 46 + 47 + /*! 48 + * Space designed to be attachable to others, most importantly it is 49 + * re-attachable, and in order to move all of the spaces that has this 50 + * space as it's parent/next we need a node that can be updated. 51 + */ 52 + U_SPACE_TYPE_ATTACHABLE, 46 53 }; 47 54 48 55 /*! ··· 331 338 m_relation_chain_push_relation(xrc, &xsr); 332 339 } break; 333 340 case U_SPACE_TYPE_OFFSET: m_relation_chain_push_pose_if_not_identity(xrc, &space->offset.pose); break; 334 - case U_SPACE_TYPE_ROOT: return; // Stops the traversing. 341 + case U_SPACE_TYPE_ROOT: return; // Stops the traversing. 342 + case U_SPACE_TYPE_ATTACHABLE: break; // No-op 335 343 } 336 344 337 345 // Please tail-call optimise this miss compiler. ··· 353 361 case U_SPACE_TYPE_NULL: break; 354 362 case U_SPACE_TYPE_POSE: break; 355 363 case U_SPACE_TYPE_OFFSET: break; 356 - case U_SPACE_TYPE_ROOT: return; // Stops the traversing. 364 + case U_SPACE_TYPE_ROOT: return; // Stops the traversing. 365 + case U_SPACE_TYPE_ATTACHABLE: break; // No-op 357 366 } 358 367 359 368 // Can't tail-call optimise this one :( ··· 372 381 } break; 373 382 case U_SPACE_TYPE_OFFSET: m_relation_chain_push_inverted_pose_if_not_identity(xrc, &space->offset.pose); break; 374 383 case U_SPACE_TYPE_ROOT: assert(false); // Should not get here. 384 + case U_SPACE_TYPE_ATTACHABLE: break; // No-op 375 385 } 376 386 } 377 387 ··· 503 513 504 514 if (ptr != NULL) { 505 515 xs = (struct xrt_space *)ptr; 516 + } else if (torig->type == XRT_TRACKING_TYPE_ATTACHABLE) { 517 + /* 518 + * If we ever make u_space_overseer sub-classable make sure 519 + * this calls the right function, can't call interface function 520 + * as the lock is held here. 521 + */ 522 + xs = (struct xrt_space *)create_space(U_SPACE_TYPE_ATTACHABLE, u_space(root)); 523 + u_hashmap_int_insert(uso->xto_map, key, xs); 506 524 } else { 507 525 /* 508 - * If we ever make u_space_overseer sub-classable maek sure 526 + * If we ever make u_space_overseer sub-classable make sure 509 527 * this calls the right function, can't call interface function 510 528 * as the lock is held here. 511 529 */ ··· 1093 1111 return add_device_helper(uso, xdev); 1094 1112 } 1095 1113 1114 + static xrt_result_t 1115 + attach_device(struct xrt_space_overseer *xso, struct xrt_device *xdev, struct xrt_space *space) 1116 + { 1117 + struct u_space_overseer *uso = u_space_overseer(xso); 1118 + 1119 + // Check that the device has the correct tracking origin type. 1120 + if (xdev->tracking_origin == NULL || xdev->tracking_origin->type != XRT_TRACKING_TYPE_ATTACHABLE) { 1121 + U_LOG_E("Device '%s' does not have XRT_TRACKING_TYPE_ATTACHABLE tracking origin type", xdev->str); 1122 + return XRT_ERROR_DEVICE_NOT_ATTACHABLE; 1123 + } 1124 + 1125 + // If no space is provided, use the root space. 1126 + struct xrt_space *target_space = space; 1127 + if (target_space == NULL) { 1128 + target_space = uso->base.semantic.root; 1129 + } 1130 + 1131 + xrt_result_t xret = XRT_SUCCESS; 1132 + pthread_rwlock_wrlock(&uso->lock); 1133 + 1134 + 1135 + void *ptr = NULL; 1136 + uint64_t key = (uint64_t)(intptr_t)xdev->tracking_origin; 1137 + u_hashmap_int_find(uso->xto_map, key, &ptr); 1138 + if (ptr == NULL) { 1139 + U_LOG_E("Device doesn't have space associated with it!"); 1140 + xret = XRT_ERROR_DEVICE_NOT_ATTACHABLE; 1141 + goto err_unlock; 1142 + } 1143 + 1144 + struct u_space *us = (struct u_space *)ptr; 1145 + if (us->type != U_SPACE_TYPE_ATTACHABLE) { 1146 + U_LOG_E("Device doesn't have a attachable space!"); 1147 + xret = XRT_ERROR_DEVICE_NOT_ATTACHABLE; 1148 + goto err_unlock; 1149 + } 1150 + 1151 + // Update the link. 1152 + u_space_reference(&us->next, u_space(target_space)); 1153 + 1154 + err_unlock: 1155 + pthread_rwlock_unlock(&uso->lock); 1156 + 1157 + return xret; 1158 + } 1159 + 1096 1160 static void 1097 1161 destroy(struct xrt_space_overseer *xso) 1098 1162 { ··· 1150 1214 uso->base.get_reference_space_offset = get_reference_space_offset; 1151 1215 uso->base.set_reference_space_offset = set_reference_space_offset; 1152 1216 uso->base.add_device = add_device; 1217 + uso->base.attach_device = attach_device; 1153 1218 uso->base.destroy = destroy; 1154 1219 uso->broadcast = broadcast; 1155 1220
+6
src/xrt/include/xrt/xrt_results.h
··· 251 251 * Invoking complete on an already completed future 252 252 */ 253 253 XRT_ERROR_FUTURE_ALREADY_COMPLETE = -41, 254 + 255 + /*! 256 + * The device's tracking origin is not of type 257 + * XRT_TRACKING_TYPE_ATTACHABLE. 258 + */ 259 + XRT_ERROR_DEVICE_NOT_ATTACHABLE = -42, 254 260 } xrt_result_t;
+33
src/xrt/include/xrt/xrt_space.h
··· 330 330 */ 331 331 xrt_result_t (*add_device)(struct xrt_space_overseer *xso, struct xrt_device *xdev); 332 332 333 + /*! 334 + * Attach a device to a different space then it was associated with 335 + * originally, the space overseer might not support this operation. 336 + * 337 + * For some space overseer implementations this operation requires 338 + * that the device has the tracking origin type of 339 + * @ref XRT_TRACKING_TYPE_ATTACHABLE. Which space that becomes the 340 + * parent space of the device when @p space is NULL is undefined, 341 + * and the device might become un-trackable. 342 + * 343 + * @param[in] xso Owning space overseer. 344 + * @param[in] xdev Device to attach. 345 + * @param[in] space Space to attach the device to, may be NULL. 346 + * 347 + * @return XRT_SUCCESS on success. 348 + * @return XRT_ERROR_DEVICE_NOT_ATTACHABLE if the device does not have 349 + * the XRT_TRACKING_TYPE_ATTACHABLE tracking origin type. 350 + */ 351 + xrt_result_t (*attach_device)(struct xrt_space_overseer *xso, struct xrt_device *xdev, struct xrt_space *space); 352 + 333 353 334 354 /* 335 355 * ··· 560 580 xrt_space_overseer_add_device(struct xrt_space_overseer *xso, struct xrt_device *xdev) 561 581 { 562 582 return xso->add_device(xso, xdev); 583 + } 584 + 585 + /*! 586 + * @copydoc xrt_space_overseer::attach_device 587 + * 588 + * Helper for calling through the function pointer. 589 + * 590 + * @public @memberof xrt_space_overseer 591 + */ 592 + static inline xrt_result_t 593 + xrt_space_overseer_attach_device(struct xrt_space_overseer *xso, struct xrt_device *xdev, struct xrt_space *space) 594 + { 595 + return xso->attach_device(xso, xdev, space); 563 596 } 564 597 565 598 /*!
+4
src/xrt/include/xrt/xrt_tracking.h
··· 1 1 // Copyright 2019, Collabora, Ltd. 2 + // Copyright 2025, NVIDIA CORPORATION. 2 3 // SPDX-License-Identifier: BSL-1.0 3 4 /*! 4 5 * @file ··· 60 61 61 62 // The device(s) are tracked by other methods. 62 63 XRT_TRACKING_TYPE_OTHER, 64 + 65 + // The device(s) are (re)attachable. 66 + XRT_TRACKING_TYPE_ATTACHABLE, 63 67 }; 64 68 65 69 /*!
+9
src/xrt/ipc/client/ipc_client_space_overseer.c
··· 324 324 return XRT_ERROR_NOT_IMPLEMENTED; 325 325 } 326 326 327 + static xrt_result_t 328 + attach_device(struct xrt_space_overseer *xso, struct xrt_device *xdev, struct xrt_space *space) 329 + { 330 + // For IPC client, attachable devices are handled on the server side. 331 + // This should not be called from the client in the typical use case. 332 + return XRT_ERROR_NOT_IMPLEMENTED; 333 + } 334 + 327 335 static void 328 336 destroy(struct xrt_space_overseer *xso) 329 337 { ··· 381 389 icspo->base.get_reference_space_offset = get_reference_space_offset; 382 390 icspo->base.set_reference_space_offset = set_reference_space_offset; 383 391 icspo->base.add_device = add_device; 392 + icspo->base.attach_device = attach_device; 384 393 icspo->base.destroy = destroy; 385 394 icspo->ipc_c = ipc_c; 386 395