Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix OpenXR Passthrough mode #78135

Merged
merged 1 commit into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,6 @@ bool OpenXRFbPassthroughExtensionWrapper::is_passthrough_enabled() {
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() {
if (passthrough_handle == XR_NULL_HANDLE) {
return false;
Expand All @@ -128,6 +124,13 @@ bool OpenXRFbPassthroughExtensionWrapper::start_passthrough() {
}

// 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);
if (!is_valid_passthrough_result(result, "Failed to create the passthrough layer")) {
stop_passthrough();
Expand All @@ -140,14 +143,18 @@ bool OpenXRFbPassthroughExtensionWrapper::start_passthrough() {
print_error("Main viewport doesn't have transparent background! Passthrough may not properly render.");
}

composition_passthrough_layer.layerHandle = passthrough_layer;

return true;
}

void OpenXRFbPassthroughExtensionWrapper::on_session_created(const XrSession session) {
if (fb_passthrough_ext) {
// 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);
if (!OpenXRAPI::get_singleton()->xr_result(result, "Failed to create passthrough")) {
passthrough_handle = XR_NULL_HANDLE;
Expand All @@ -157,7 +164,8 @@ void OpenXRFbPassthroughExtensionWrapper::on_session_created(const XrSession ses
}

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;
} else {
return nullptr;
Expand All @@ -169,8 +177,6 @@ void OpenXRFbPassthroughExtensionWrapper::stop_passthrough() {
return;
}

composition_passthrough_layer.layerHandle = XR_NULL_HANDLE;

XrResult result;
if (passthrough_layer != XR_NULL_HANDLE) {
// Destroy the layer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,27 +212,12 @@ class OpenXRFbPassthroughExtensionWrapper : public OpenXRExtensionWrapper, publi

Viewport *get_main_viewport();

bool is_composition_passthrough_layer_ready();

static OpenXRFbPassthroughExtensionWrapper *singleton;

bool fb_passthrough_ext = false; // required for any passthrough functionality
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;

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;

XrCompositionLayerPassthroughFB composition_passthrough_layer = {
Expand Down