st/oxr: Add extension XR_KHR_composition_layer_color_scale_bias

This commit is contained in:
Weijie Wang 2023-12-14 17:15:48 +08:00 committed by Jakob Bornecrantz
parent 14f31f0e1f
commit fa85b5e98a
6 changed files with 72 additions and 0 deletions

View file

@ -415,6 +415,9 @@ endif()
if(NOT DEFINED XRT_FEATURE_OPENXR_LAYER_DEPTH)
set(XRT_FEATURE_OPENXR_LAYER_DEPTH ON)
endif()
if(NOT DEFINED XRT_FEATURE_OPENXR_LAYER_COLOR_SCALE_BIAS)
set(XRT_FEATURE_OPENXR_LAYER_COLOR_SCALE_BIAS OFF)
endif()
if(NOT DEFINED XRT_FEATURE_OPENXR_LAYER_CUBE)
set(XRT_FEATURE_OPENXR_LAYER_CUBE OFF)
endif()
@ -633,6 +636,7 @@ message(STATUS "# FEATURE_OPENXR_INTERACTION_MNDX: ${XRT_FEATURE
message(STATUS "# FEATURE_OPENXR_INTERACTION_MSFT_HAND: ${XRT_FEATURE_OPENXR_INTERACTION_MSFT_HAND}")
message(STATUS "# FEATURE_OPENXR_INTERACTION_OPPO: ${XRT_FEATURE_OPENXR_INTERACTION_OPPO}")
message(STATUS "# FEATURE_OPENXR_INTERACTION_WINMR: ${XRT_FEATURE_OPENXR_INTERACTION_WINMR}")
message(STATUS "# FEATURE_OPENXR_LAYER_COLOR_SCALE_BIAS: ${XRT_FEATURE_OPENXR_LAYER_COLOR_SCALE_BIAS}")
message(STATUS "# FEATURE_OPENXR_LAYER_CUBE: ${XRT_FEATURE_OPENXR_LAYER_CUBE}")
message(STATUS "# FEATURE_OPENXR_LAYER_CYLINDER: ${XRT_FEATURE_OPENXR_LAYER_CYLINDER}")
message(STATUS "# FEATURE_OPENXR_LAYER_DEPTH: ${XRT_FEATURE_OPENXR_LAYER_DEPTH}")

View file

@ -36,6 +36,7 @@ EXTENSIONS = (
['XR_KHR_android_create_instance', 'XR_USE_PLATFORM_ANDROID'],
['XR_KHR_android_thread_settings', 'XR_USE_PLATFORM_ANDROID'],
['XR_KHR_binding_modification'],
['XR_KHR_composition_layer_color_scale_bias', 'XRT_FEATURE_OPENXR_LAYER_COLOR_SCALE_BIAS'],
['XR_KHR_composition_layer_cube', 'XRT_FEATURE_OPENXR_LAYER_CUBE'],
['XR_KHR_composition_layer_cylinder', 'XRT_FEATURE_OPENXR_LAYER_CYLINDER'],
['XR_KHR_composition_layer_depth', 'XRT_FEATURE_OPENXR_LAYER_DEPTH'],

View file

@ -97,6 +97,13 @@ enum xrt_layer_composition_flags
* adjusted for the IPD.
*/
XRT_LAYER_COMPOSITION_VIEW_SPACE_BIT = 1u << 3u,
/*!
* If this flag is set the compositor should use the scale and bias
* from the @ref xrt_layer_data struct.
*/
XRT_LAYER_COMPOSITION_COLOR_BIAS_SCALE = 1u << 4u,
};
/*!
@ -317,6 +324,16 @@ struct xrt_layer_data
*/
bool flip_y;
/*!
* Modulate the color sourced from the images.
*/
struct xrt_colour_rgba_f32 color_scale;
/*!
* Modulate the color sourced from the images.
*/
struct xrt_colour_rgba_f32 color_bias;
/*!
* Union of data values for the various layer types.
*

View file

@ -40,6 +40,7 @@
#cmakedefine XRT_FEATURE_OPENXR_INTERACTION_MSFT_HAND
#cmakedefine XRT_FEATURE_OPENXR_INTERACTION_OPPO
#cmakedefine XRT_FEATURE_OPENXR_INTERACTION_WINMR
#cmakedefine XRT_FEATURE_OPENXR_LAYER_COLOR_SCALE_BIAS
#cmakedefine XRT_FEATURE_OPENXR_LAYER_CUBE
#cmakedefine XRT_FEATURE_OPENXR_LAYER_CYLINDER
#cmakedefine XRT_FEATURE_OPENXR_LAYER_DEPTH

View file

@ -54,6 +54,18 @@
#endif
/*
* XR_KHR_composition_layer_color_scale_bias
*/
#if defined(XR_KHR_composition_layer_color_scale_bias) && defined(XRT_FEATURE_OPENXR_LAYER_COLOR_SCALE_BIAS)
#define OXR_HAVE_KHR_composition_layer_color_scale_bias
#define OXR_EXTENSION_SUPPORT_KHR_composition_layer_color_scale_bias(_) \
_(KHR_composition_layer_color_scale_bias, KHR_COMPOSITION_LAYER_COLOR_SCALE_BIAS)
#else
#define OXR_EXTENSION_SUPPORT_KHR_composition_layer_color_scale_bias(_)
#endif
/*
* XR_KHR_composition_layer_cube
*/
@ -544,6 +556,7 @@
OXR_EXTENSION_SUPPORT_KHR_android_create_instance(_) \
OXR_EXTENSION_SUPPORT_KHR_android_thread_settings(_) \
OXR_EXTENSION_SUPPORT_KHR_binding_modification(_) \
OXR_EXTENSION_SUPPORT_KHR_composition_layer_color_scale_bias(_) \
OXR_EXTENSION_SUPPORT_KHR_composition_layer_cube(_) \
OXR_EXTENSION_SUPPORT_KHR_composition_layer_cylinder(_) \
OXR_EXTENSION_SUPPORT_KHR_composition_layer_depth(_) \

View file

@ -131,6 +131,36 @@ convert_eye_visibility(XrSwapchainUsageFlags xr_visibility)
return visibility;
}
XRT_MAYBE_UNUSED static void
fill_in_xr_color(const struct XrColor4f *src, struct xrt_colour_rgba_f32 *dest)
{
dest->r = src->r;
dest->g = src->g;
dest->b = src->b;
dest->a = src->a;
}
static void
fill_in_color_scale_bias(struct oxr_session *sess,
const XrCompositionLayerBaseHeader *layer,
struct xrt_layer_data *xlayer_data)
{
#ifdef XRT_FEATURE_OPENXR_LAYER_COLOR_SCALE_BIAS
// Is the extension enabled?
if (!sess->sys->inst->extensions.KHR_composition_layer_color_scale_bias) {
return;
}
const XrCompositionLayerColorScaleBiasKHR *color_scale_bias = OXR_GET_INPUT_FROM_CHAIN(
layer->next, XR_TYPE_COMPOSITION_LAYER_COLOR_SCALE_BIAS_KHR, XrCompositionLayerColorScaleBiasKHR);
if (color_scale_bias) {
xlayer_data->flags |= XRT_LAYER_COMPOSITION_COLOR_BIAS_SCALE;
fill_in_xr_color(&color_scale_bias->colorScale, &xlayer_data->color_scale);
fill_in_xr_color(&color_scale_bias->colorBias, &xlayer_data->color_bias);
}
#endif // XRT_FEATURE_OPENXR_LAYER_COLOR_SCALE_BIAS
}
static void
fill_in_sub_image(const struct oxr_swapchain *sc, const XrSwapchainSubImage *oxr_sub, struct xrt_sub_image *xsub)
{
@ -931,6 +961,7 @@ submit_quad_layer(struct oxr_session *sess,
data.quad.pose = pose;
data.quad.size = *size;
fill_in_sub_image(sc, &quad->subImage, &data.quad.sub);
fill_in_color_scale_bias(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);
@ -985,6 +1016,7 @@ submit_projection_layer(struct oxr_session *sess,
data.stereo.r.pose = pose[1];
fill_in_sub_image(scs[0], &proj->views[0].subImage, &data.stereo.l.sub);
fill_in_sub_image(scs[1], &proj->views[1].subImage, &data.stereo.r.sub);
fill_in_color_scale_bias(sess, (XrCompositionLayerBaseHeader *)proj, &data);
#ifdef XRT_FEATURE_OPENXR_LAYER_DEPTH
const XrCompositionLayerDepthInfoKHR *d_l = OXR_GET_INPUT_FROM_CHAIN(
@ -1077,6 +1109,7 @@ submit_cube_layer(struct oxr_session *sess,
data.cube.sub.image_index = sc->released.index;
data.cube.sub.array_index = cube->imageArrayIndex;
fill_in_color_scale_bias(sess, (XrCompositionLayerBaseHeader *)cube, &data);
struct xrt_pose pose = {
.orientation =
@ -1139,6 +1172,7 @@ submit_cylinder_layer(struct oxr_session *sess,
data.cylinder.central_angle = cylinder->centralAngle;
data.cylinder.aspect_ratio = cylinder->aspectRatio;
fill_in_sub_image(sc, &cylinder->subImage, &data.cylinder.sub);
fill_in_color_scale_bias(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);
@ -1182,6 +1216,7 @@ submit_equirect1_layer(struct oxr_session *sess,
data.equirect1.pose = pose;
data.equirect1.radius = equirect->radius;
fill_in_sub_image(sc, &equirect->subImage, &data.equirect1.sub);
fill_in_color_scale_bias(sess, (XrCompositionLayerBaseHeader *)equirect, &data);
struct xrt_vec2 *scale = (struct xrt_vec2 *)&equirect->scale;
@ -1244,6 +1279,7 @@ submit_equirect2_layer(struct oxr_session *sess,
data.equirect2.upper_vertical_angle = equirect->upperVerticalAngle;
data.equirect2.lower_vertical_angle = equirect->lowerVerticalAngle;
fill_in_sub_image(sc, &equirect->subImage, &data.equirect2.sub);
fill_in_color_scale_bias(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);