Skip to content

Commit

Permalink
openxr quad layers mode uses stereo
Browse files Browse the repository at this point in the history
Summary:
The current quad layers implementation uses a single quad layer with `XR_EYE_VISIBILITY_BOTH`. This works but isn't respecting multiview/stereo.

This diff adds proper stereo by adding multiple quads with `XR_EYE_VISIBILITY_LEFT` and `XR_EYE_VISIBILITY_RIGHT`, both pointing at different array layers in the swapchain image.

Reviewed By: trivedivivek

Differential Revision: D49523415

fbshipit-source-id: 27ab92a36736916251284c39b6f8dddb684dd4ff
  • Loading branch information
Vadym Martsynovskyy authored and facebook-github-bot committed Sep 22, 2023
1 parent 4336bd5 commit e332a69
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 28 deletions.
42 changes: 28 additions & 14 deletions shell/openxr/desktop/XrApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,15 +516,21 @@ void XrApp::render() {

void XrApp::endFrame(XrFrameState frameState) {
#ifdef USE_COMPOSITION_LAYER_QUAD
XrCompositionLayerQuad layer{};
layer.next = nullptr;
layer.type = XR_TYPE_COMPOSITION_LAYER_QUAD;
layer.layerFlags = XR_COMPOSITION_LAYER_BLEND_TEXTURE_SOURCE_ALPHA_BIT;
layer.space = stageSpace_;
layer.eyeVisibility = XR_EYE_VISIBILITY_BOTH;
memset(&layer.subImage, 0, sizeof(XrSwapchainSubImage));
layer.pose = {{0.f, 0.f, 0.f, 1.f}, {0.f, 0.f, 0.f}};
layer.size = {1.f, 1.f};
std::array<XrCompositionLayerQuad, kNumViews> quadLayers{};
XrEyeVisibility eye = XR_EYE_VISIBILITY_LEFT;
for (auto& layer : quadLayers) {
layer.next = nullptr;
layer.type = XR_TYPE_COMPOSITION_LAYER_QUAD;
layer.layerFlags = XR_COMPOSITION_LAYER_BLEND_TEXTURE_SOURCE_ALPHA_BIT;
layer.space = stageSpace_;
layer.eyeVisibility = eye;
memset(&layer.subImage, 0, sizeof(XrSwapchainSubImage));
layer.pose = {{0.f, 0.f, 0.f, 1.f}, {0.f, 0.f, 0.f}};
layer.size = {1.f, 1.f};
if (eye == XR_EYE_VISIBILITY_LEFT) {
eye = XR_EYE_VISIBILITY_RIGHT;
}
}
#endif

std::array<XrCompositionLayerProjectionView, kNumViews> projectionViews;
Expand Down Expand Up @@ -574,25 +580,33 @@ void XrApp::endFrame(XrFrameState frameState) {
depthInfos[i].nearZ = appParams.depthParams.nearZ;
depthInfos[i].farZ = appParams.depthParams.farZ;
#ifdef USE_COMPOSITION_LAYER_QUAD
layer.subImage = projectionViews[0].subImage;
quadLayers[i].subImage = projectionViews[i].subImage;
#endif
}

const XrCompositionLayerBaseHeader* const layers[] = {
#ifdef USE_COMPOSITION_LAYER_QUAD
(const XrCompositionLayerBaseHeader*)&layer
std::array<const XrCompositionLayerBaseHeader*, kNumViews> quadLayersBase{};
for (uint32_t i = 0; i < quadLayers.size(); i++) {
quadLayersBase[i] = (const XrCompositionLayerBaseHeader*)&quadLayers[i];
}
#else
(const XrCompositionLayerBaseHeader*)&projection
#endif
const XrCompositionLayerBaseHeader* const layers[] = {
(const XrCompositionLayerBaseHeader*)&projection,
};
#endif

XrFrameEndInfo endFrameInfo = {
XR_TYPE_FRAME_END_INFO,
nullptr,
frameState.predictedDisplayTime,
XR_ENVIRONMENT_BLEND_MODE_OPAQUE,
#ifdef USE_COMPOSITION_LAYER_QUAD
quadLayersBase.size(),
quadLayersBase.data(),
#else
1,
layers,
#endif
};

XR_CHECK(xrEndFrame(session_, &endFrameInfo));
Expand Down
42 changes: 28 additions & 14 deletions shell/openxr/mobile/XrApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,15 +541,21 @@ void XrApp::render() {

void XrApp::endFrame(XrFrameState frameState) {
#ifdef USE_COMPOSITION_LAYER_QUAD
XrCompositionLayerQuad layer{};
layer.next = nullptr;
layer.type = XR_TYPE_COMPOSITION_LAYER_QUAD;
layer.layerFlags = XR_COMPOSITION_LAYER_BLEND_TEXTURE_SOURCE_ALPHA_BIT;
layer.space = stageSpace_;
layer.eyeVisibility = XR_EYE_VISIBILITY_BOTH;
memset(&layer.subImage, 0, sizeof(XrSwapchainSubImage));
layer.pose = {{0.f, 0.f, 0.f, 1.f}, {0.f, 0.f, 0.f}};
layer.size = {1.f, 1.f};
std::array<XrCompositionLayerQuad, kNumViews> quadLayers{};
XrEyeVisibility eye = XR_EYE_VISIBILITY_LEFT;
for (auto& layer : quadLayers) {
layer.next = nullptr;
layer.type = XR_TYPE_COMPOSITION_LAYER_QUAD;
layer.layerFlags = XR_COMPOSITION_LAYER_BLEND_TEXTURE_SOURCE_ALPHA_BIT;
layer.space = stageSpace_;
layer.eyeVisibility = eye;
memset(&layer.subImage, 0, sizeof(XrSwapchainSubImage));
layer.pose = {{0.f, 0.f, 0.f, 1.f}, {0.f, 0.f, 0.f}};
layer.size = {1.f, 1.f};
if (eye == XR_EYE_VISIBILITY_LEFT) {
eye = XR_EYE_VISIBILITY_RIGHT;
}
}
#endif

std::array<XrCompositionLayerProjectionView, kNumViews> projectionViews;
Expand Down Expand Up @@ -599,25 +605,33 @@ void XrApp::endFrame(XrFrameState frameState) {
depthInfos[i].nearZ = appParams.depthParams.nearZ;
depthInfos[i].farZ = appParams.depthParams.farZ;
#ifdef USE_COMPOSITION_LAYER_QUAD
layer.subImage = projectionViews[0].subImage;
quadLayers[i].subImage = projectionViews[i].subImage;
#endif
}

const XrCompositionLayerBaseHeader* const layers[] = {
#ifdef USE_COMPOSITION_LAYER_QUAD
(const XrCompositionLayerBaseHeader*)&layer
std::array<const XrCompositionLayerBaseHeader*, kNumViews> quadLayersBase{};
for (uint32_t i = 0; i < quadLayers.size(); i++) {
quadLayersBase[i] = (const XrCompositionLayerBaseHeader*)&quadLayers[i];
}
#else
(const XrCompositionLayerBaseHeader*)&projection
#endif
const XrCompositionLayerBaseHeader* const layers[] = {
(const XrCompositionLayerBaseHeader*)&projection,
};
#endif

XrFrameEndInfo endFrameInfo = {
XR_TYPE_FRAME_END_INFO,
nullptr,
frameState.predictedDisplayTime,
XR_ENVIRONMENT_BLEND_MODE_OPAQUE,
#ifdef USE_COMPOSITION_LAYER_QUAD
quadLayersBase.size(),
quadLayersBase.data(),
#else
1,
layers,
#endif
};

XR_CHECK(xrEndFrame(session_, &endFrameInfo));
Expand Down

0 comments on commit e332a69

Please sign in to comment.