From 38703fc1d293818bb15946cb7c2094cdf9439a3f Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Mon, 10 Aug 2020 20:15:18 +0100 Subject: [PATCH] st/oxr: Add plumbing for layers --- doc/changes/state_trackers/mr.476.md | 1 + scripts/generate_oxr_ext_support.py | 4 + .../oxr/oxr_extension_support.h | 58 ++++++++ src/xrt/state_trackers/oxr/oxr_session.c | 125 ++++++++++++++++++ 4 files changed, 188 insertions(+) create mode 100644 doc/changes/state_trackers/mr.476.md diff --git a/doc/changes/state_trackers/mr.476.md b/doc/changes/state_trackers/mr.476.md new file mode 100644 index 000000000..2cc36ece6 --- /dev/null +++ b/doc/changes/state_trackers/mr.476.md @@ -0,0 +1 @@ +OpenXR: Add stub functions and support plumbing for a lot of layer extensions. diff --git a/scripts/generate_oxr_ext_support.py b/scripts/generate_oxr_ext_support.py index d517dcd45..8e850a4c1 100755 --- a/scripts/generate_oxr_ext_support.py +++ b/scripts/generate_oxr_ext_support.py @@ -14,6 +14,10 @@ EXTENSIONS = ( ['XR_KHR_opengl_enable', 'XR_USE_GRAPHICS_API_OPENGL'], ['XR_KHR_opengl_es_enable', 'XR_USE_GRAPHICS_API_OPENGL_ES'], ['XR_KHR_vulkan_enable', 'XR_USE_GRAPHICS_API_VULKAN'], + ['XR_KHR_composition_layer_depth', 'XRT_FEATURE_OPENXR_LAYER_DEPTH'], + ['XR_KHR_composition_layer_cube', 'XRT_FEATURE_OPENXR_LAYER_CUBE'], + ['XR_KHR_composition_layer_cylinder', 'XRT_FEATURE_OPENXR_LAYER_CYLINDER'], + ['XR_KHR_composition_layer_equirect', 'XRT_FEATURE_OPENXR_LAYER_EQUIRECT'], ['XR_EXT_debug_utils'], ['XR_MND_headless'], ['XR_MND_swapchain_usage_input_attachment_bit'], diff --git a/src/xrt/state_trackers/oxr/oxr_extension_support.h b/src/xrt/state_trackers/oxr/oxr_extension_support.h index dbd0863e4..9120fc1ff 100644 --- a/src/xrt/state_trackers/oxr/oxr_extension_support.h +++ b/src/xrt/state_trackers/oxr/oxr_extension_support.h @@ -16,6 +16,8 @@ #pragma once +#include "xrt/xrt_config_build.h" + // beginning of GENERATED defines - do not modify - used by scripts /* @@ -66,6 +68,58 @@ #endif +/* + * XR_KHR_composition_layer_depth + */ +#if defined(XR_KHR_composition_layer_depth) && \ + defined(XRT_FEATURE_OPENXR_LAYER_DEPTH) +#define OXR_HAVE_KHR_composition_layer_depth +#define OXR_EXTENSION_SUPPORT_KHR_composition_layer_depth(_) \ + _(KHR_composition_layer_depth, KHR_COMPOSITION_LAYER_DEPTH) +#else +#define OXR_EXTENSION_SUPPORT_KHR_composition_layer_depth(_) +#endif + + +/* + * XR_KHR_composition_layer_cube + */ +#if defined(XR_KHR_composition_layer_cube) && \ + defined(XRT_FEATURE_OPENXR_LAYER_CUBE) +#define OXR_HAVE_KHR_composition_layer_cube +#define OXR_EXTENSION_SUPPORT_KHR_composition_layer_cube(_) \ + _(KHR_composition_layer_cube, KHR_COMPOSITION_LAYER_CUBE) +#else +#define OXR_EXTENSION_SUPPORT_KHR_composition_layer_cube(_) +#endif + + +/* + * XR_KHR_composition_layer_cylinder + */ +#if defined(XR_KHR_composition_layer_cylinder) && \ + defined(XRT_FEATURE_OPENXR_LAYER_CYLINDER) +#define OXR_HAVE_KHR_composition_layer_cylinder +#define OXR_EXTENSION_SUPPORT_KHR_composition_layer_cylinder(_) \ + _(KHR_composition_layer_cylinder, KHR_COMPOSITION_LAYER_CYLINDER) +#else +#define OXR_EXTENSION_SUPPORT_KHR_composition_layer_cylinder(_) +#endif + + +/* + * XR_KHR_composition_layer_equirect + */ +#if defined(XR_KHR_composition_layer_equirect) && \ + defined(XRT_FEATURE_OPENXR_LAYER_EQUIRECT) +#define OXR_HAVE_KHR_composition_layer_equirect +#define OXR_EXTENSION_SUPPORT_KHR_composition_layer_equirect(_) \ + _(KHR_composition_layer_equirect, KHR_COMPOSITION_LAYER_EQUIRECT) +#else +#define OXR_EXTENSION_SUPPORT_KHR_composition_layer_equirect(_) +#endif + + /* * XR_EXT_debug_utils */ @@ -165,6 +219,10 @@ OXR_EXTENSION_SUPPORT_KHR_opengl_enable(_) \ OXR_EXTENSION_SUPPORT_KHR_opengl_es_enable(_) \ OXR_EXTENSION_SUPPORT_KHR_vulkan_enable(_) \ + OXR_EXTENSION_SUPPORT_KHR_composition_layer_depth(_) \ + OXR_EXTENSION_SUPPORT_KHR_composition_layer_cube(_) \ + OXR_EXTENSION_SUPPORT_KHR_composition_layer_cylinder(_) \ + OXR_EXTENSION_SUPPORT_KHR_composition_layer_equirect(_) \ OXR_EXTENSION_SUPPORT_EXT_debug_utils(_) \ OXR_EXTENSION_SUPPORT_MND_headless(_) \ OXR_EXTENSION_SUPPORT_MND_swapchain_usage_input_attachment_bit(_) \ diff --git a/src/xrt/state_trackers/oxr/oxr_session.c b/src/xrt/state_trackers/oxr/oxr_session.c index 476a24c24..87285f39c 100644 --- a/src/xrt/state_trackers/oxr/oxr_session.c +++ b/src/xrt/state_trackers/oxr/oxr_session.c @@ -801,6 +801,63 @@ verify_projection_layer(struct xrt_compositor *xc, return XR_SUCCESS; } +static XrResult +verify_cube_layer(struct xrt_compositor *xc, + struct oxr_logger *log, + uint32_t layer_index, + const XrCompositionLayerCubeKHR *cube, + struct xrt_device *head, + uint64_t timestamp) +{ +#ifndef XRT_FEATURE_OPENXR_LAYER_CUBE + return oxr_error(log, XR_ERROR_LAYER_INVALID, + "(frameEndInfo->layers[%u]->type) layer type " + "XrCompositionLayerCubeKHR not supported", + layer_index); +#else + return oxr_error(log, XR_ERROR_RUNTIME_FAILURE, + "XrCompositionLayerCubeKHR not implemented"); +#endif +} + +static XrResult +verify_cylinder_layer(struct xrt_compositor *xc, + struct oxr_logger *log, + uint32_t layer_index, + const XrCompositionLayerCylinderKHR *cylinder, + struct xrt_device *head, + uint64_t timestamp) +{ +#ifndef XRT_FEATURE_OPENXR_LAYER_CYLINDER + return oxr_error(log, XR_ERROR_LAYER_INVALID, + "(frameEndInfo->layers[%u]->type) layer type " + "XrCompositionLayerCylinderKHR not supported", + layer_index); +#else + return oxr_error(log, XR_ERROR_RUNTIME_FAILURE, + "XrCompositionLayerCylinderKHR not implemented"); +#endif +} + +static XrResult +verify_equirect_layer(struct xrt_compositor *xc, + struct oxr_logger *log, + uint32_t layer_index, + const XrCompositionLayerEquirectKHR *equirect, + struct xrt_device *head, + uint64_t timestamp) +{ +#ifndef XRT_FEATURE_OPENXR_LAYER_EQUIRECT + return oxr_error(log, XR_ERROR_LAYER_INVALID, + "(frameEndInfo->layers[%u]->type) layer type " + "XrCompositionLayerEquirectKHR not supported", + layer_index); +#else + return oxr_error(log, XR_ERROR_RUNTIME_FAILURE, + "XrCompositionLayerEquirectKHR not implemented"); +#endif +} + static enum xrt_layer_composition_flags convert_layer_flags(XrSwapchainUsageFlags xr_flags) { @@ -1008,6 +1065,42 @@ submit_projection_layer(struct xrt_compositor *xc, return XR_SUCCESS; } +static void +submit_cube_layer(struct oxr_session *sess, + struct xrt_compositor *xc, + struct oxr_logger *log, + const XrCompositionLayerCubeKHR *cube, + struct xrt_device *head, + struct xrt_pose *inv_offset, + uint64_t timestamp) +{ + // Not implemented +} + +static void +submit_cylinder_layer(struct oxr_session *sess, + struct xrt_compositor *xc, + struct oxr_logger *log, + const XrCompositionLayerCylinderKHR *cylinder, + struct xrt_device *head, + struct xrt_pose *inv_offset, + uint64_t timestamp) +{ + // Not implemented +} + +static void +submit_equirect_layer(struct oxr_session *sess, + struct xrt_compositor *xc, + struct oxr_logger *log, + const XrCompositionLayerEquirectKHR *equirect, + struct xrt_device *head, + struct xrt_pose *inv_offset, + uint64_t timestamp) +{ + // Not implemented +} + XrResult oxr_session_frame_end(struct oxr_logger *log, struct oxr_session *sess, @@ -1115,6 +1208,21 @@ oxr_session_frame_end(struct oxr_logger *log, xc, log, i, (XrCompositionLayerQuad *)layer, xdev, frameEndInfo->displayTime); break; + case XR_TYPE_COMPOSITION_LAYER_CUBE_KHR: + res = verify_cube_layer( + xc, log, i, (XrCompositionLayerCubeKHR *)layer, + xdev, frameEndInfo->displayTime); + break; + case XR_TYPE_COMPOSITION_LAYER_CYLINDER_KHR: + res = verify_cylinder_layer( + xc, log, i, (XrCompositionLayerCylinderKHR *)layer, + xdev, frameEndInfo->displayTime); + break; + case XR_TYPE_COMPOSITION_LAYER_EQUIRECT_KHR: + res = verify_equirect_layer( + xc, log, i, (XrCompositionLayerEquirectKHR *)layer, + xdev, frameEndInfo->displayTime); + break; default: return oxr_error(log, XR_ERROR_LAYER_INVALID, "(frameEndInfo->layers[%u]->type) " @@ -1153,6 +1261,23 @@ oxr_session_frame_end(struct oxr_logger *log, sess, xc, log, (XrCompositionLayerQuad *)layer, xdev, &inv_offset, frameEndInfo->displayTime); break; + case XR_TYPE_COMPOSITION_LAYER_CUBE_KHR: + submit_cube_layer( + sess, xc, log, (XrCompositionLayerCubeKHR *)layer, + xdev, &inv_offset, frameEndInfo->displayTime); + break; + case XR_TYPE_COMPOSITION_LAYER_CYLINDER_KHR: + submit_cylinder_layer( + sess, xc, log, + (XrCompositionLayerCylinderKHR *)layer, xdev, + &inv_offset, frameEndInfo->displayTime); + break; + case XR_TYPE_COMPOSITION_LAYER_EQUIRECT_KHR: + submit_equirect_layer( + sess, xc, log, + (XrCompositionLayerEquirectKHR *)layer, xdev, + &inv_offset, frameEndInfo->displayTime); + break; default: assert(false && "invalid layer type"); } }