From 6e8a40112b5863ba5465f805659bc5c286928161 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Tue, 14 Nov 2023 21:26:43 +0000 Subject: [PATCH] st/oxr: Handle view index for visibility mask --- src/xrt/state_trackers/oxr/oxr_api_session.c | 2 +- src/xrt/state_trackers/oxr/oxr_instance.c | 6 ++++-- src/xrt/state_trackers/oxr/oxr_objects.h | 3 ++- src/xrt/state_trackers/oxr/oxr_session.c | 21 +++++++++++++------- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/xrt/state_trackers/oxr/oxr_api_session.c b/src/xrt/state_trackers/oxr/oxr_api_session.c index 7b3fa7860..a3cd533e4 100644 --- a/src/xrt/state_trackers/oxr/oxr_api_session.c +++ b/src/xrt/state_trackers/oxr/oxr_api_session.c @@ -303,7 +303,7 @@ oxr_xrGetVisibilityMaskKHR(XrSession session, OXR_VERIFY_ARG_NOT_NULL(&log, visibilityMask->indices); } - return oxr_session_get_visibility_mask(&log, sess, visibilityMaskType, visibilityMask); + return oxr_session_get_visibility_mask(&log, sess, visibilityMaskType, viewIndex, visibilityMask); } #endif // OXR_HAVE_KHR_visibility_mask diff --git a/src/xrt/state_trackers/oxr/oxr_instance.c b/src/xrt/state_trackers/oxr/oxr_instance.c index 7ddb42eff..4af25e866 100644 --- a/src/xrt/state_trackers/oxr/oxr_instance.c +++ b/src/xrt/state_trackers/oxr/oxr_instance.c @@ -69,8 +69,10 @@ oxr_instance_destroy(struct oxr_logger *log, struct oxr_handle_base *hb) u_hashset_destroy(&inst->action_sets.loc_store); // Free the mask here, no system destroy yet. - free(inst->system.visibility_mask); - inst->system.visibility_mask = NULL; + for (uint32_t i = 0; i < ARRAY_SIZE(inst->system.visibility_mask); i++) { + free(inst->system.visibility_mask[i]); + inst->system.visibility_mask[i] = NULL; + } xrt_space_overseer_destroy(&inst->system.xso); os_mutex_destroy(&inst->system.sync_actions_mutex); diff --git a/src/xrt/state_trackers/oxr/oxr_objects.h b/src/xrt/state_trackers/oxr/oxr_objects.h index 13fa1382d..e4e823c8e 100644 --- a/src/xrt/state_trackers/oxr/oxr_objects.h +++ b/src/xrt/state_trackers/oxr/oxr_objects.h @@ -766,6 +766,7 @@ XrResult oxr_session_get_visibility_mask(struct oxr_logger *log, struct oxr_session *session, XrVisibilityMaskTypeKHR visibilityMaskType, + uint32_t viewIndex, XrVisibilityMaskKHR *visibilityMask); #endif // OXR_HAVE_KHR_visibility_mask @@ -1291,7 +1292,7 @@ struct oxr_system struct xrt_system_roles dynamic_roles_cache; struct os_mutex sync_actions_mutex; - struct xrt_visibility_mask *visibility_mask; + struct xrt_visibility_mask *visibility_mask[2]; #ifdef XR_USE_GRAPHICS_API_VULKAN //! The instance/device we create when vulkan_enable2 is used diff --git a/src/xrt/state_trackers/oxr/oxr_session.c b/src/xrt/state_trackers/oxr/oxr_session.c index ce2c95744..040e2550d 100644 --- a/src/xrt/state_trackers/oxr/oxr_session.c +++ b/src/xrt/state_trackers/oxr/oxr_session.c @@ -1177,23 +1177,30 @@ XrResult oxr_session_get_visibility_mask(struct oxr_logger *log, struct oxr_session *sess, XrVisibilityMaskTypeKHR visibilityMaskType, + uint32_t viewIndex, XrVisibilityMaskKHR *visibilityMask) { struct oxr_system *sys = sess->sys; struct xrt_device *xdev = GET_XDEV_BY_ROLE(sess->sys, head); enum xrt_visibility_mask_type type = convert_mask_type(visibilityMaskType); - if (sys->visibility_mask && sys->visibility_mask->type != type) { - free(sys->visibility_mask); - sys->visibility_mask = NULL; + assert(viewIndex < ARRAY_SIZE(sys->visibility_mask)); + + struct xrt_visibility_mask *mask = sys->visibility_mask[viewIndex]; + + // Do we need to free the mask. + if (mask != NULL && mask->type != type) { + free(mask); + mask = NULL; + sys->visibility_mask[viewIndex] = NULL; } - if (sys->visibility_mask == NULL) { - xrt_device_get_visibility_mask(xdev, type, 0, &sys->visibility_mask); + // If we didn't have any cached mask get it. + if (mask == NULL) { + xrt_device_get_visibility_mask(xdev, type, viewIndex, &mask); + sys->visibility_mask[viewIndex] = mask; } - struct xrt_visibility_mask *mask = sys->visibility_mask; - visibilityMask->vertexCountOutput = mask->vertex_count; visibilityMask->indexCountOutput = mask->index_count;