Merge pull request #78135 from BastiaanOlij/fix_openxr_passthrough

Fix OpenXR Passthrough mode
This commit is contained in:
Rémi Verschelde 2023-06-23 11:59:16 +02:00
commit fa7f8e34f2
No known key found for this signature in database
GPG Key ID: C3336907360768E1
2 changed files with 15 additions and 24 deletions

View File

@ -107,10 +107,6 @@ bool OpenXRFbPassthroughExtensionWrapper::is_passthrough_enabled() {
return fb_passthrough_ext && passthrough_handle != XR_NULL_HANDLE && passthrough_layer != XR_NULL_HANDLE; return fb_passthrough_ext && passthrough_handle != XR_NULL_HANDLE && passthrough_layer != XR_NULL_HANDLE;
} }
bool OpenXRFbPassthroughExtensionWrapper::is_composition_passthrough_layer_ready() {
return fb_passthrough_ext && passthrough_handle != XR_NULL_HANDLE && composition_passthrough_layer.layerHandle != XR_NULL_HANDLE;
}
bool OpenXRFbPassthroughExtensionWrapper::start_passthrough() { bool OpenXRFbPassthroughExtensionWrapper::start_passthrough() {
if (passthrough_handle == XR_NULL_HANDLE) { if (passthrough_handle == XR_NULL_HANDLE) {
return false; return false;
@ -128,6 +124,13 @@ bool OpenXRFbPassthroughExtensionWrapper::start_passthrough() {
} }
// Create the passthrough layer // Create the passthrough layer
XrPassthroughLayerCreateInfoFB passthrough_layer_config = {
XR_TYPE_PASSTHROUGH_LAYER_CREATE_INFO_FB,
nullptr,
passthrough_handle,
XR_PASSTHROUGH_IS_RUNNING_AT_CREATION_BIT_FB,
XR_PASSTHROUGH_LAYER_PURPOSE_RECONSTRUCTION_FB,
};
result = xrCreatePassthroughLayerFB(OpenXRAPI::get_singleton()->get_session(), &passthrough_layer_config, &passthrough_layer); result = xrCreatePassthroughLayerFB(OpenXRAPI::get_singleton()->get_session(), &passthrough_layer_config, &passthrough_layer);
if (!is_valid_passthrough_result(result, "Failed to create the passthrough layer")) { if (!is_valid_passthrough_result(result, "Failed to create the passthrough layer")) {
stop_passthrough(); stop_passthrough();
@ -140,14 +143,18 @@ bool OpenXRFbPassthroughExtensionWrapper::start_passthrough() {
print_error("Main viewport doesn't have transparent background! Passthrough may not properly render."); print_error("Main viewport doesn't have transparent background! Passthrough may not properly render.");
} }
composition_passthrough_layer.layerHandle = passthrough_layer;
return true; return true;
} }
void OpenXRFbPassthroughExtensionWrapper::on_session_created(const XrSession session) { void OpenXRFbPassthroughExtensionWrapper::on_session_created(const XrSession session) {
if (fb_passthrough_ext) { if (fb_passthrough_ext) {
// Create the passthrough feature and start it. // Create the passthrough feature and start it.
XrPassthroughCreateInfoFB passthrough_create_info = {
XR_TYPE_PASSTHROUGH_CREATE_INFO_FB,
nullptr,
0,
};
XrResult result = xrCreatePassthroughFB(OpenXRAPI::get_singleton()->get_session(), &passthrough_create_info, &passthrough_handle); XrResult result = xrCreatePassthroughFB(OpenXRAPI::get_singleton()->get_session(), &passthrough_create_info, &passthrough_handle);
if (!OpenXRAPI::get_singleton()->xr_result(result, "Failed to create passthrough")) { if (!OpenXRAPI::get_singleton()->xr_result(result, "Failed to create passthrough")) {
passthrough_handle = XR_NULL_HANDLE; passthrough_handle = XR_NULL_HANDLE;
@ -157,7 +164,8 @@ void OpenXRFbPassthroughExtensionWrapper::on_session_created(const XrSession ses
} }
XrCompositionLayerBaseHeader *OpenXRFbPassthroughExtensionWrapper::get_composition_layer() { XrCompositionLayerBaseHeader *OpenXRFbPassthroughExtensionWrapper::get_composition_layer() {
if (is_composition_passthrough_layer_ready()) { if (is_passthrough_enabled()) {
composition_passthrough_layer.layerHandle = passthrough_layer;
return (XrCompositionLayerBaseHeader *)&composition_passthrough_layer; return (XrCompositionLayerBaseHeader *)&composition_passthrough_layer;
} else { } else {
return nullptr; return nullptr;
@ -169,8 +177,6 @@ void OpenXRFbPassthroughExtensionWrapper::stop_passthrough() {
return; return;
} }
composition_passthrough_layer.layerHandle = XR_NULL_HANDLE;
XrResult result; XrResult result;
if (passthrough_layer != XR_NULL_HANDLE) { if (passthrough_layer != XR_NULL_HANDLE) {
// Destroy the layer // Destroy the layer

View File

@ -211,27 +211,12 @@ private:
Viewport *get_main_viewport(); Viewport *get_main_viewport();
bool is_composition_passthrough_layer_ready();
static OpenXRFbPassthroughExtensionWrapper *singleton; static OpenXRFbPassthroughExtensionWrapper *singleton;
bool fb_passthrough_ext = false; // required for any passthrough functionality bool fb_passthrough_ext = false; // required for any passthrough functionality
bool fb_triangle_mesh_ext = false; // only use for projected passthrough bool fb_triangle_mesh_ext = false; // only use for projected passthrough
XrPassthroughCreateInfoFB passthrough_create_info = {
XR_TYPE_PASSTHROUGH_CREATE_INFO_FB,
nullptr,
0,
};
XrPassthroughFB passthrough_handle = XR_NULL_HANDLE; XrPassthroughFB passthrough_handle = XR_NULL_HANDLE;
XrPassthroughLayerCreateInfoFB passthrough_layer_config = {
XR_TYPE_PASSTHROUGH_LAYER_CREATE_INFO_FB,
nullptr,
passthrough_handle,
XR_PASSTHROUGH_IS_RUNNING_AT_CREATION_BIT_FB,
XR_PASSTHROUGH_LAYER_PURPOSE_RECONSTRUCTION_FB,
};
XrPassthroughLayerFB passthrough_layer = XR_NULL_HANDLE; XrPassthroughLayerFB passthrough_layer = XR_NULL_HANDLE;
XrCompositionLayerPassthroughFB composition_passthrough_layer = { XrCompositionLayerPassthroughFB composition_passthrough_layer = {