The open source OpenXR runtime
0
fork

Configure Feed

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

Support muti-localspace on server side

client can have independent localspace to use

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

authored by

Shijian and committed by
Marge Bot
0f07c054 a60e24ef

+122 -3
+25
src/xrt/auxiliary/util/u_space_overseer.c
··· 802 802 return XRT_ERROR_RECENTERING_NOT_SUPPORTED; 803 803 } 804 804 805 + static xrt_result_t 806 + create_local_space(struct xrt_space_overseer *xso, struct xrt_space **out_space) 807 + { 808 + assert(xso->semantic.root != NULL); 809 + struct xrt_space *xs = NULL; 810 + struct xrt_space_relation xsr; 811 + int64_t timestamp_ns = os_monotonic_get_ns(); 812 + xrt_device_get_tracked_pose(xso->head, XRT_INPUT_GENERIC_HEAD_POSE, timestamp_ns, &xsr); 813 + xsr.pose.orientation.x = 0; 814 + xsr.pose.orientation.z = 0; 815 + math_quat_normalize(&xsr.pose.orientation); 816 + create_offset_space(xso, xso->semantic.root, &xsr.pose, &xs); 817 + *out_space = xs; 818 + U_LOG_D("u_space_overseer create_local_space!"); 819 + return XRT_SUCCESS; 820 + } 821 + 805 822 static void 806 823 destroy(struct xrt_space_overseer *xso) 807 824 { ··· 818 835 u_hashmap_int_clear_and_call_for_each(uso->xdev_map, hashmap_unreference_space_items, uso); 819 836 u_hashmap_int_destroy(&uso->xdev_map); 820 837 838 + for (int id = 0; id < XRT_MAX_CLIENT_SPACES; id++) { 839 + struct xrt_space *xslocal = xso->localspace[id]; 840 + xrt_space_reference(&xslocal, NULL); 841 + } 842 + 821 843 pthread_rwlock_destroy(&uso->lock); 822 844 823 845 free(uso); ··· 834 856 u_space_overseer_create(struct xrt_session_event_sink *broadcast) 835 857 { 836 858 struct u_space_overseer *uso = U_TYPED_CALLOC(struct u_space_overseer); 859 + uso->base.create_local_space = create_local_space; 837 860 uso->base.create_offset_space = create_offset_space; 838 861 uso->base.create_pose_space = create_pose_space; 839 862 uso->base.locate_space = locate_space; ··· 918 941 if (root_is_unbounded) { 919 942 xrt_space_reference(&uso->base.semantic.unbounded, uso->base.semantic.root); 920 943 } 944 + 945 + uso->base.head = head; 921 946 922 947 // Set local to the local offset. 923 948 u_space_overseer_create_offset_space(uso, uso->base.semantic.root, local_offset, &uso->base.semantic.local);
+26 -1
src/xrt/include/xrt/xrt_space.h
··· 15 15 extern "C" { 16 16 #endif 17 17 18 - 18 + #define XRT_MAX_CLIENT_SPACES 128 19 19 struct xrt_device; 20 20 21 21 /*! ··· 106 106 * Semantic spaces to be mapped to OpenXR spaces. 107 107 */ 108 108 } semantic; 109 + 110 + //! Ptrs to the localspace 111 + struct xrt_space *localspace[XRT_MAX_CLIENT_SPACES]; 112 + struct xrt_device *head; 109 113 110 114 /*! 111 115 * Create a space with a fixed offset to the parent space. ··· 235 239 * @param[in] xso The space overseer. 236 240 */ 237 241 xrt_result_t (*recenter_local_spaces)(struct xrt_space_overseer *xso); 242 + 243 + /*! 244 + * Create a localspace. 245 + * 246 + * @param[in] xso Owning space overseer. 247 + * @param[out] out_space The newly created localspace. 248 + */ 249 + xrt_result_t (*create_local_space)(struct xrt_space_overseer *xso, struct xrt_space **out_space); 238 250 239 251 /*! 240 252 * Destroy function. ··· 371 383 xrt_space_overseer_recenter_local_spaces(struct xrt_space_overseer *xso) 372 384 { 373 385 return xso->recenter_local_spaces(xso); 386 + } 387 + 388 + /*! 389 + * @copydoc xrt_space_overseer::create_localspace_space 390 + * 391 + * Helper for calling through the function pointer. 392 + * 393 + * @public @memberof xrt_space_overseer 394 + */ 395 + static inline xrt_result_t 396 + xrt_space_overseer_create_local_space(struct xrt_space_overseer *xso, struct xrt_space **out_space) 397 + { 398 + return xso->create_local_space(xso, out_space); 374 399 } 375 400 376 401 /*!
+4
src/xrt/ipc/server/ipc_server.h
··· 116 116 117 117 //! Number of spaces. 118 118 uint32_t space_count; 119 + //! Index of localspace in ipc client. 120 + uint32_t local_space_index; 121 + //! Index of localspace in space overseer. 122 + uint32_t local_space_overseer_index; 119 123 120 124 //! Ptrs to the spaces. 121 125 struct xrt_space *xspcs[IPC_MAX_CLIENT_SPACES];
+62 -2
src/xrt/ipc/server/ipc_server_handler.c
··· 154 154 } 155 155 156 156 157 + static xrt_result_t 158 + get_new_localspace_id(volatile struct ipc_client_state *ics, uint32_t *out_id) 159 + { 160 + // Our handle is just the index for now. 161 + uint32_t index = 0; 162 + for (; index < IPC_MAX_CLIENT_SPACES; index++) { 163 + if (ics->server->xso->localspace[index] == NULL) { 164 + break; 165 + } 166 + } 167 + 168 + if (index >= IPC_MAX_CLIENT_SPACES) { 169 + IPC_ERROR(ics->server, "Too many localspaces!"); 170 + return XRT_ERROR_IPC_FAILURE; 171 + } 172 + 173 + ics->local_space_overseer_index = index; 174 + index = 0; 175 + for (; index < IPC_MAX_CLIENT_SPACES; index++) { 176 + if (ics->xspcs[index] == NULL) { 177 + break; 178 + } 179 + } 180 + 181 + if (index >= IPC_MAX_CLIENT_SPACES) { 182 + IPC_ERROR(ics->server, "Too many spaces!"); 183 + return XRT_ERROR_IPC_FAILURE; 184 + } 185 + 186 + ics->local_space_index = index; 187 + *out_id = index; 188 + 189 + return XRT_SUCCESS; 190 + } 191 + 192 + static xrt_result_t 193 + create_localspace(volatile struct ipc_client_state *ics, uint32_t *out_local_id) 194 + { 195 + uint32_t id = UINT32_MAX; 196 + xrt_result_t xret = get_new_localspace_id(ics, &id); 197 + if (xret != XRT_SUCCESS) { 198 + return xret; 199 + } 200 + 201 + struct xrt_space *xs = NULL; 202 + struct xrt_space_overseer *xso = ics->server->xso; 203 + struct xrt_space **xs_ptr = (struct xrt_space **)&ics->xspcs[id]; 204 + 205 + xrt_space_overseer_create_local_space(xso, &xso->localspace[ics->local_space_overseer_index]); 206 + 207 + xrt_space_reference(xs_ptr, xso->localspace[ics->local_space_overseer_index]); 208 + *out_local_id = id; 209 + 210 + return XRT_SUCCESS; 211 + } 212 + 157 213 /* 158 214 * 159 215 * Handle functions. ··· 366 422 367 423 CREATE(root); 368 424 CREATE(view); 369 - CREATE(local); 370 425 CREATE(local_floor); 371 426 CREATE(stage); 372 427 CREATE(unbounded); 373 428 374 429 #undef CREATE 375 - 430 + create_localspace(ics, out_local_id); 376 431 return XRT_SUCCESS; 377 432 } 378 433 ··· 646 701 // Remove volatile 647 702 struct xrt_space **xs_ptr = (struct xrt_space **)&ics->xspcs[space_id]; 648 703 xrt_space_reference(xs_ptr, NULL); 704 + 705 + if (space_id == ics->local_space_index) { 706 + struct xrt_space *xslocal_ptr = ics->server->xso->localspace[ics->local_space_overseer_index]; 707 + xrt_space_reference(&xslocal_ptr, NULL); 708 + } 649 709 650 710 return XRT_SUCCESS; 651 711 }
+5
src/xrt/ipc/server/ipc_server_per_client_thread.c
··· 67 67 xrt_space_reference((struct xrt_space **)&ics->xspcs[i], NULL); 68 68 } 69 69 70 + if (ics->local_space_overseer_index < IPC_MAX_CLIENT_SPACES && ics->local_space_overseer_index >= 0) { 71 + struct xrt_space *xslocal = ics->server->xso->localspace[ics->local_space_overseer_index]; 72 + xrt_space_reference(&xslocal, NULL); 73 + } 74 + 70 75 // Mark an still in use reference spaces as no longer used. 71 76 for (uint32_t i = 0; i < ARRAY_SIZE(ics->ref_space_used); i++) { 72 77 bool used = ics->ref_space_used[i];