st/oxr: Add extension XR_FB_composition_layer_depth_test

This commit is contained in:
Pingping Meng 2024-01-25 17:25:44 +08:00 committed by pingping meng
parent fcdc206452
commit fd816c838f
6 changed files with 88 additions and 0 deletions

View file

@ -419,6 +419,9 @@ endif()
if(NOT DEFINED XRT_FEATURE_OPENXR_LAYER_FB_SETTINGS)
set(XRT_FEATURE_OPENXR_LAYER_FB_SETTINGS OFF)
endif()
if(NOT DEFINED XRT_FEATURE_OPENXR_LAYER_FB_DEPTH_TEST)
set(XRT_FEATURE_OPENXR_LAYER_FB_DEPTH_TEST OFF)
endif()
# Defaults for OpenXR spaces
if(NOT DEFINED XRT_FEATURE_OPENXR_SPACE_LOCAL_FLOOR)
@ -631,6 +634,7 @@ message(STATUS "# FEATURE_OPENXR_LAYER_EQUIRECT2: ${XRT_FEATURE
message(STATUS "# FEATURE_OPENXR_LAYER_FB_ALPHA_BLEND: ${XRT_FEATURE_OPENXR_LAYER_FB_ALPHA_BLEND}")
message(STATUS "# FEATURE_OPENXR_LAYER_FB_IMAGE_LAYOUT ${XRT_FEATURE_OPENXR_LAYER_FB_IMAGE_LAYOUT}")
message(STATUS "# FEATURE_OPENXR_LAYER_FB_SETTINGS: ${XRT_FEATURE_OPENXR_LAYER_FB_SETTINGS}")
message(STATUS "# FEATURE_OPENXR_LAYER_FB_DEPTH_TEST: ${XRT_FEATURE_OPENXR_LAYER_FB_DEPTH_TEST}")
message(STATUS "# FEATURE_OPENXR_OVERLAY: ${XRT_FEATURE_OPENXR_OVERLAY}")
message(STATUS "# FEATURE_OPENXR_PERFORMANCE_SETTINGS: ${XRT_FEATURE_OPENXR_PERFORMANCE_SETTINGS}")
message(STATUS "# FEATURE_OPENXR_SPACE_LOCAL_FLOOR: ${XRT_FEATURE_OPENXR_SPACE_LOCAL_FLOOR}")

View file

@ -68,6 +68,7 @@ EXTENSIONS = (
['XR_FB_composition_layer_alpha_blend', 'XRT_FEATURE_OPENXR_LAYER_FB_ALPHA_BLEND'],
['XR_FB_composition_layer_image_layout', 'XRT_FEATURE_OPENXR_LAYER_FB_IMAGE_LAYOUT'],
['XR_FB_composition_layer_settings', 'XRT_FEATURE_OPENXR_LAYER_FB_SETTINGS'],
['XR_FB_composition_layer_depth_test', 'XRT_FEATURE_OPENXR_LAYER_FB_DEPTH_TEST'],
['XR_FB_display_refresh_rate', 'XRT_FEATURE_OPENXR_DISPLAY_REFRESH_RATE'],
['XR_ML_ml2_controller_interaction', 'XRT_FEATURE_OPENXR_INTERACTION_ML2'],
['XR_MND_headless', 'XRT_FEATURE_OPENXR_HEADLESS'],

View file

@ -123,6 +123,28 @@ enum xrt_layer_composition_flags
* see @p XrCompositionLayerAlphaBlendFB.
*/
XRT_LAYER_COMPOSITION_ADVANCED_BLENDING_BIT = 1u << 9u,
/*!
* Depth testing is requested when composing this layer if this flag is set,
* see XrCompositionLayerDepthTestFB.
*/
XRT_LAYER_COMPOSITION_DEPTH_TEST = 1u << 10u,
};
/*!
* XrCompareOpFB
*/
enum xrt_compare_op_fb
{
XRT_COMPARE_OP_NEVER_FB = 0,
XRT_COMPARE_OP_LESS_FB = 1,
XRT_COMPARE_OP_EQUAL_FB = 2,
XRT_COMPARE_OP_LESS_OR_EQUAL_FB = 3,
XRT_COMPARE_OP_GREATER_FB = 4,
XRT_COMPARE_OP_NOT_EQUAL_FB = 5,
XRT_COMPARE_OP_GREATER_OR_EQUAL_FB = 6,
XRT_COMPARE_OP_ALWAYS_FB = 7,
XRT_COMPARE_OP_MAX_ENUM_FB = 0x7FFFFFFF
};
/*!
@ -227,6 +249,12 @@ struct xrt_layer_depth_data
float far_z;
};
struct xrt_layer_depth_test_data
{
bool depth_mask;
enum xrt_compare_op_fb compare_op;
};
/*!
* All the pure data values associated with a stereo projection layer with depth
* swapchain attached.
@ -358,6 +386,11 @@ struct xrt_layer_data
*/
enum xrt_layer_composition_flags flags;
/*!
* Depth test data
*/
struct xrt_layer_depth_test_data depth_test;
/*!
* Whether the main compositor should flip the direction of y when
* rendering.

View file

@ -49,6 +49,7 @@
#cmakedefine XRT_FEATURE_OPENXR_LAYER_FB_ALPHA_BLEND
#cmakedefine XRT_FEATURE_OPENXR_LAYER_FB_IMAGE_LAYOUT
#cmakedefine XRT_FEATURE_OPENXR_LAYER_FB_SETTINGS
#cmakedefine XRT_FEATURE_OPENXR_LAYER_FB_DEPTH_TEST
#cmakedefine XRT_FEATURE_OPENXR_OVERLAY
#cmakedefine XRT_FEATURE_OPENXR_SPACE_LOCAL_FLOOR
#cmakedefine XRT_FEATURE_OPENXR_SPACE_UNBOUNDED

View file

@ -418,6 +418,15 @@
#define OXR_EXTENSION_SUPPORT_FB_composition_layer_settings(_)
#endif
/*
* XR_FB_composition_layer_depth_test
*/
#if defined(XR_FB_composition_layer_depth_test) && defined(XRT_FEATURE_OPENXR_LAYER_FB_DEPTH_TEST)
#define OXR_HAVE_FB_composition_layer_depth_test
#define OXR_EXTENSION_SUPPORT_FB_composition_layer_depth_test(_) _(FB_composition_layer_depth_test, FB_COMPOSITION_LAYER_DEPTH_TEST)
#else
#define OXR_EXTENSION_SUPPORT_FB_composition_layer_depth_test(_)
#endif
/*
* XR_FB_display_refresh_rate
@ -636,6 +645,7 @@
OXR_EXTENSION_SUPPORT_FB_composition_layer_alpha_blend(_) \
OXR_EXTENSION_SUPPORT_FB_composition_layer_image_layout(_) \
OXR_EXTENSION_SUPPORT_FB_composition_layer_settings(_) \
OXR_EXTENSION_SUPPORT_FB_composition_layer_depth_test(_) \
OXR_EXTENSION_SUPPORT_FB_display_refresh_rate(_) \
OXR_EXTENSION_SUPPORT_ML_ml2_controller_interaction(_) \
OXR_EXTENSION_SUPPORT_MND_headless(_) \

View file

@ -129,6 +129,22 @@ convert_layer_flags(XrSwapchainUsageFlags xr_flags)
return flags;
}
static enum xrt_compare_op_fb
convert_compare_op(XrCompareOpFB xr_compare_op)
{
switch (xr_compare_op) {
case XR_COMPARE_OP_NEVER_FB: return XRT_COMPARE_OP_NEVER_FB;
case XR_COMPARE_OP_LESS_FB: return XRT_COMPARE_OP_LESS_FB;
case XR_COMPARE_OP_EQUAL_FB: return XRT_COMPARE_OP_EQUAL_FB;
case XR_COMPARE_OP_LESS_OR_EQUAL_FB: return XRT_COMPARE_OP_LESS_OR_EQUAL_FB;
case XR_COMPARE_OP_GREATER_FB: return XRT_COMPARE_OP_GREATER_FB;
case XR_COMPARE_OP_NOT_EQUAL_FB: return XRT_COMPARE_OP_NOT_EQUAL_FB;
case XR_COMPARE_OP_GREATER_OR_EQUAL_FB: return XRT_COMPARE_OP_GREATER_OR_EQUAL_FB;
case XR_COMPARE_OP_ALWAYS_FB: return XRT_COMPARE_OP_ALWAYS_FB;
default: return XRT_COMPARE_OP_MAX_ENUM_FB;
}
}
static enum xrt_layer_eye_visibility
convert_eye_visibility(XrSwapchainUsageFlags xr_visibility)
{
@ -279,6 +295,23 @@ fill_in_layer_settings(struct oxr_session *sess,
#endif // OXR_HAVE_FB_composition_layer_settings
}
static void
fill_in_depth_test(struct oxr_session *sess, const XrCompositionLayerBaseHeader *layer, struct xrt_layer_data *data)
{
#ifdef OXR_HAVE_FB_composition_layer_depth_test
// Is the extension enabled?
if (!sess->sys->inst->extensions.FB_composition_layer_depth_test) {
return;
}
const XrCompositionLayerDepthTestFB *depthTest = OXR_GET_INPUT_FROM_CHAIN(
layer, (XrStructureType)XR_TYPE_COMPOSITION_LAYER_DEPTH_TEST_FB, XrCompositionLayerDepthTestFB);
if (depthTest != NULL) {
data->flags |= XRT_LAYER_COMPOSITION_DEPTH_TEST;
data->depth_test.depth_mask = depthTest->depthMask;
data->depth_test.compare_op = convert_compare_op(depthTest->compareOp);
}
#endif // OXR_HAVE_FB_composition_layer_depth_test
}
/*
*
@ -1148,6 +1181,7 @@ submit_quad_layer(struct oxr_session *sess,
fill_in_y_flip(sess, (XrCompositionLayerBaseHeader *)quad, &data);
fill_in_blend_factors(sess, (XrCompositionLayerBaseHeader *)quad, &data);
fill_in_layer_settings(sess, (XrCompositionLayerBaseHeader *)quad, &data);
fill_in_depth_test(sess, (XrCompositionLayerBaseHeader *)quad, &data);
xrt_result_t xret = xrt_comp_layer_quad(xc, head, sc->swapchain, &data);
OXR_CHECK_XRET(log, sess, xret, xrt_comp_layer_quad);
@ -1244,6 +1278,7 @@ submit_projection_layer(struct oxr_session *sess,
if (d_scs[0] != NULL && d_scs[1] != NULL) {
#ifdef OXR_HAVE_KHR_composition_layer_depth
fill_in_depth_test(sess, (XrCompositionLayerBaseHeader *)proj, &data);
data.type = XRT_LAYER_STEREO_PROJECTION_DEPTH;
xrt_result_t xret = xrt_comp_layer_stereo_projection_depth( //
xc, // compositor
@ -1302,6 +1337,7 @@ submit_cube_layer(struct oxr_session *sess,
fill_in_color_scale_bias(sess, (XrCompositionLayerBaseHeader *)cube, &data);
fill_in_y_flip(sess, (XrCompositionLayerBaseHeader *)cube, &data);
fill_in_blend_factors(sess, (XrCompositionLayerBaseHeader *)cube, &data);
fill_in_depth_test(sess, (XrCompositionLayerBaseHeader *)cube, &data);
struct xrt_pose pose = {
.orientation =
@ -1368,6 +1404,7 @@ submit_cylinder_layer(struct oxr_session *sess,
fill_in_y_flip(sess, (XrCompositionLayerBaseHeader *)cylinder, &data);
fill_in_blend_factors(sess, (XrCompositionLayerBaseHeader *)cylinder, &data);
fill_in_layer_settings(sess, (XrCompositionLayerBaseHeader *)cylinder, &data);
fill_in_depth_test(sess, (XrCompositionLayerBaseHeader *)cylinder, &data);
xrt_result_t xret = xrt_comp_layer_cylinder(xc, head, sc->swapchain, &data);
OXR_CHECK_XRET(log, sess, xret, xrt_comp_layer_cylinder);
@ -1415,6 +1452,7 @@ submit_equirect1_layer(struct oxr_session *sess,
fill_in_y_flip(sess, (XrCompositionLayerBaseHeader *)equirect, &data);
fill_in_blend_factors(sess, (XrCompositionLayerBaseHeader *)equirect, &data);
fill_in_layer_settings(sess, (XrCompositionLayerBaseHeader *)equirect, &data);
fill_in_depth_test(sess, (XrCompositionLayerBaseHeader *)equirect, &data);
struct xrt_vec2 *scale = (struct xrt_vec2 *)&equirect->scale;
struct xrt_vec2 *bias = (struct xrt_vec2 *)&equirect->bias;
@ -1480,6 +1518,7 @@ submit_equirect2_layer(struct oxr_session *sess,
fill_in_y_flip(sess, (XrCompositionLayerBaseHeader *)equirect, &data);
fill_in_blend_factors(sess, (XrCompositionLayerBaseHeader *)equirect, &data);
fill_in_layer_settings(sess, (XrCompositionLayerBaseHeader *)equirect, &data);
fill_in_depth_test(sess, (XrCompositionLayerBaseHeader *)equirect, &data);
xrt_result_t xret = xrt_comp_layer_equirect2(xc, head, sc->swapchain, &data);
OXR_CHECK_XRET(log, sess, xret, xrt_comp_layer_equirect2);