Skip to content
Closed
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
5 changes: 4 additions & 1 deletion src/tests/hello_xr/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ void ShowHelp() {
// TODO: Improve/update when things are more settled.
Log::Write(Log::Level::Info,
"HelloXr --graphics|-g <Graphics API> [--formfactor|-ff <Form factor>] [--viewconfig|-vc <View config>] "
"[--blendmode|-bm <Blend mode>] [--space|-s <Space>] [--verbose|-v]");
"[--blendmode|-bm <Blend mode>] [--space|-s <Space>] [--overlay <Overlay placement>] [--verbose|-v]");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any chance to support those parameters for Android? Monado has two flavors, out of process and in process, and we can build two versions with different package name for different usage. Could hello_xr support similar flags to build two versions with different package name, one for normal usage, and one for overlay usage?

Log::Write(Log::Level::Info, "Graphics APIs: D3D11, D3D12, OpenGLES, OpenGL, Vulkan2, Vulkan");
Log::Write(Log::Level::Info, "Form factors: Hmd, Handheld");
Log::Write(Log::Level::Info, "View configurations: Mono, Stereo");
Log::Write(Log::Level::Info, "Environment blend modes: Opaque, Additive, AlphaBlend");
Log::Write(Log::Level::Info, "Spaces: View, Local, Stage");
Log::Write(Log::Level::Info, "Overlay: Integer value: [0, UINT32_MAX]");
}

bool UpdateOptionsFromCommandLine(Options& options, int argc, char* argv[]) {
Expand All @@ -66,6 +67,8 @@ bool UpdateOptionsFromCommandLine(Options& options, int argc, char* argv[]) {
options.EnvironmentBlendMode = getNextArg();
} else if (EqualsIgnoreCase(arg, "--space") || EqualsIgnoreCase(arg, "-s")) {
options.AppSpace = getNextArg();
} else if (EqualsIgnoreCase(arg, "--overlay") || EqualsIgnoreCase(arg, "-o")) {
options.OverlayPlacement = getNextArg();
} else if (EqualsIgnoreCase(arg, "--verbose") || EqualsIgnoreCase(arg, "-v")) {
Log::SetLevel(Log::Level::Verbose);
} else if (EqualsIgnoreCase(arg, "--help") || EqualsIgnoreCase(arg, "-h")) {
Expand Down
28 changes: 28 additions & 0 deletions src/tests/hello_xr/openxr_program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ inline XrEnvironmentBlendMode GetXrEnvironmentBlendMode(const std::string& envir
throw std::invalid_argument(Fmt("Unknown environment blend mode '%s'", environmentBlendModeStr.c_str()));
}

inline uint32_t GetXrOverlayPlacement(const std::string& overlayPlacement) {
try {
unsigned long value = stoul(overlayPlacement);
return static_cast<uint32_t>(value);
} catch (...) {
}
throw std::invalid_argument(Fmt("Invalid overlay placement '%s'", overlayPlacement.c_str()));
}

namespace Math {
namespace Pose {
XrPosef Identity() {
Expand Down Expand Up @@ -224,6 +233,10 @@ struct OpenXrProgram : IOpenXrProgram {
std::transform(graphicsExtensions.begin(), graphicsExtensions.end(), std::back_inserter(extensions),
[](const std::string& ext) { return ext.c_str(); });

if (m_overlayApp) {
extensions.push_back(XR_EXTX_OVERLAY_EXTENSION_NAME);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before adding overlay extension as enabled extensions list, should it need to check whether runtime supports this extension likes xrgears(https://gitlab.freedesktop.org/monado/demos/xrgears/-/merge_requests/10/diffs#575c3212e3fa074fbb40562ade4bdfad41bd74d7_130_136)?

}

XrInstanceCreateInfo createInfo{XR_TYPE_INSTANCE_CREATE_INFO};
createInfo.next = m_platformPlugin->GetInstanceCreateExtension();
createInfo.enabledExtensionCount = (uint32_t)extensions.size();
Expand Down Expand Up @@ -325,6 +338,11 @@ struct OpenXrProgram : IOpenXrProgram {
systemInfo.formFactor = m_formFactor;
CHECK_XRCMD(xrGetSystem(m_instance, &systemInfo, &m_systemId));

if (!m_options->OverlayPlacement.empty()) {
m_overlayApp = true;
m_overlayPlacement = GetXrOverlayPlacement(m_options->OverlayPlacement);
}

Log::Write(Log::Level::Verbose, Fmt("Using system %d for form factor %s", m_systemId, to_string(m_formFactor)));
CHECK(m_instance != XR_NULL_HANDLE);
CHECK(m_systemId != XR_NULL_SYSTEM_ID);
Expand Down Expand Up @@ -581,6 +599,14 @@ struct OpenXrProgram : IOpenXrProgram {
XrSessionCreateInfo createInfo{XR_TYPE_SESSION_CREATE_INFO};
createInfo.next = m_graphicsPlugin->GetGraphicsBinding();
createInfo.systemId = m_systemId;

XrSessionCreateInfoOverlayEXTX overlayCreateInfo = {XR_TYPE_SESSION_CREATE_INFO_OVERLAY_EXTX, nullptr, 0U, 0U};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember OpenXR spec says the next of XrSessionCreateInfoOverlayEXTX can be nullptr, but the overlay will not show correct content on Android when next is nullptr with latest monado. In monado xrgears' new overlay PR, it uses graphic binding as next of overlayCreateInfo (https://gitlab.freedesktop.org/monado/demos/xrgears/-/merge_requests/10/diffs#575c3212e3fa074fbb40562ade4bdfad41bd74d7_593_598). Maybe hello_xr should use m_graphicsPlugin->GetGraphicsBinding() replace nullptr too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea both the graphics binding and XrSessionCreateInfoOverlayEXTX need to be in the next chain of XrSessionCreateInfo. Note that the validation layer has an issue there #264.

if (m_overlayApp) {
overlayCreateInfo.next = createInfo.next;
createInfo.next = &overlayCreateInfo;
overlayCreateInfo.sessionLayersPlacement = m_overlayPlacement;
}

CHECK_XRCMD(xrCreateSession(m_instance, &createInfo, &m_session));
}

Expand Down Expand Up @@ -1020,6 +1046,8 @@ struct OpenXrProgram : IOpenXrProgram {
XrViewConfigurationType m_viewConfigType{XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO};
XrEnvironmentBlendMode m_environmentBlendMode{XR_ENVIRONMENT_BLEND_MODE_OPAQUE};
XrSystemId m_systemId{XR_NULL_SYSTEM_ID};
bool m_overlayApp = false;
uint32_t m_overlayPlacement = 0;

std::vector<XrViewConfigurationView> m_configViews;
std::vector<Swapchain> m_swapchains;
Expand Down
2 changes: 2 additions & 0 deletions src/tests/hello_xr/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ struct Options {
std::string EnvironmentBlendMode{"Opaque"};

std::string AppSpace{"Local"};

std::string OverlayPlacement{""};
};