From fc63fecf5ce4fcee22c69695cf566dcb50315607 Mon Sep 17 00:00:00 2001 From: jypeitao Date: Fri, 29 Mar 2024 11:27:59 +0800 Subject: [PATCH] hello xr: change the ViewConfigurationType change the ViewConfigurationType which app expected but runtime not supported to the one the runtime prefers the application to use. --- src/tests/hello_xr/openxr_program.cpp | 50 ++++++++++++++++++--------- 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/src/tests/hello_xr/openxr_program.cpp b/src/tests/hello_xr/openxr_program.cpp index 1c65a740..44a28d91 100644 --- a/src/tests/hello_xr/openxr_program.cpp +++ b/src/tests/hello_xr/openxr_program.cpp @@ -93,6 +93,7 @@ struct OpenXrProgram : IOpenXrProgram { : m_options(options), m_platformPlugin(platformPlugin), m_graphicsPlugin(graphicsPlugin), + m_ViewConfigType(m_options->Parsed.ViewConfigType), m_acceptableBlendModes{XR_ENVIRONMENT_BLEND_MODE_OPAQUE, XR_ENVIRONMENT_BLEND_MODE_ADDITIVE, XR_ENVIRONMENT_BLEND_MODE_ALPHA_BLEND} {} @@ -219,7 +220,7 @@ struct OpenXrProgram : IOpenXrProgram { Log::Write(Log::Level::Info, Fmt("Available View Configuration Types: (%d)", viewConfigTypeCount)); for (XrViewConfigurationType viewConfigType : viewConfigTypes) { Log::Write(Log::Level::Verbose, Fmt(" View Configuration Type: %s %s", to_string(viewConfigType), - viewConfigType == m_options->Parsed.ViewConfigType ? "(Selected)" : "")); + viewConfigType == m_ViewConfigType ? "(Selected)" : "")); XrViewConfigurationProperties viewConfigProperties{XR_TYPE_VIEW_CONFIGURATION_PROPERTIES}; CHECK_XRCMD(xrGetViewConfigurationProperties(m_instance, m_systemId, viewConfigType, &viewConfigProperties)); @@ -277,12 +278,11 @@ struct OpenXrProgram : IOpenXrProgram { XrEnvironmentBlendMode GetPreferredBlendMode() const override { uint32_t count; - CHECK_XRCMD(xrEnumerateEnvironmentBlendModes(m_instance, m_systemId, m_options->Parsed.ViewConfigType, 0, &count, nullptr)); + CHECK_XRCMD(xrEnumerateEnvironmentBlendModes(m_instance, m_systemId, m_ViewConfigType, 0, &count, nullptr)); CHECK(count > 0); std::vector blendModes(count); - CHECK_XRCMD(xrEnumerateEnvironmentBlendModes(m_instance, m_systemId, m_options->Parsed.ViewConfigType, count, &count, - blendModes.data())); + CHECK_XRCMD(xrEnumerateEnvironmentBlendModes(m_instance, m_systemId, m_ViewConfigType, count, &count, blendModes.data())); for (const auto& blendMode : blendModes) { if (m_acceptableBlendModes.count(blendMode)) return blendMode; } @@ -301,6 +301,8 @@ struct OpenXrProgram : IOpenXrProgram { Fmt("Using system %d for form factor %s", m_systemId, to_string(m_options->Parsed.FormFactor))); CHECK(m_instance != XR_NULL_HANDLE); CHECK(m_systemId != XR_NULL_SYSTEM_ID); + + determineFinalViewConfigurationType(); } void InitializeDevice() override { @@ -589,19 +591,12 @@ struct OpenXrProgram : IOpenXrProgram { systemProperties.trackingProperties.orientationTracking == XR_TRUE ? "True" : "False", systemProperties.trackingProperties.positionTracking == XR_TRUE ? "True" : "False")); - // Note: No other view configurations exist at the time this code was written. If this - // condition is not met, the project will need to be audited to see how support should be - // added. - CHECK_MSG(m_options->Parsed.ViewConfigType == XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO, - "Unsupported view configuration type"); - // Query and cache view configuration views. uint32_t viewCount; - CHECK_XRCMD( - xrEnumerateViewConfigurationViews(m_instance, m_systemId, m_options->Parsed.ViewConfigType, 0, &viewCount, nullptr)); + CHECK_XRCMD(xrEnumerateViewConfigurationViews(m_instance, m_systemId, m_ViewConfigType, 0, &viewCount, nullptr)); m_configViews.resize(viewCount, {XR_TYPE_VIEW_CONFIGURATION_VIEW}); - CHECK_XRCMD(xrEnumerateViewConfigurationViews(m_instance, m_systemId, m_options->Parsed.ViewConfigType, viewCount, - &viewCount, m_configViews.data())); + CHECK_XRCMD(xrEnumerateViewConfigurationViews(m_instance, m_systemId, m_ViewConfigType, viewCount, &viewCount, + m_configViews.data())); // Create and cache view buffer for xrLocateViews later. m_views.resize(viewCount, {XR_TYPE_VIEW}); @@ -741,7 +736,7 @@ struct OpenXrProgram : IOpenXrProgram { case XR_SESSION_STATE_READY: { CHECK(m_session != XR_NULL_HANDLE); XrSessionBeginInfo sessionBeginInfo{XR_TYPE_SESSION_BEGIN_INFO}; - sessionBeginInfo.primaryViewConfigurationType = m_options->Parsed.ViewConfigType; + sessionBeginInfo.primaryViewConfigurationType = m_ViewConfigType; CHECK_XRCMD(xrBeginSession(m_session, &sessionBeginInfo)); m_sessionRunning = true; break; @@ -895,7 +890,7 @@ struct OpenXrProgram : IOpenXrProgram { uint32_t viewCountOutput; XrViewLocateInfo viewLocateInfo{XR_TYPE_VIEW_LOCATE_INFO}; - viewLocateInfo.viewConfigurationType = m_options->Parsed.ViewConfigType; + viewLocateInfo.viewConfigurationType = m_ViewConfigType; viewLocateInfo.displayTime = predictedDisplayTime; viewLocateInfo.space = m_appSpace; @@ -990,6 +985,27 @@ struct OpenXrProgram : IOpenXrProgram { return true; } + private: + void determineFinalViewConfigurationType() { + CHECK(m_instance != XR_NULL_HANDLE); + CHECK(m_systemId != 0); + + uint32_t viewConfigTypeCount; + CHECK_XRCMD(xrEnumerateViewConfigurations(m_instance, m_systemId, 0, &viewConfigTypeCount, nullptr)); + std::vector viewConfigTypes(viewConfigTypeCount); + CHECK_XRCMD(xrEnumerateViewConfigurations(m_instance, m_systemId, viewConfigTypeCount, &viewConfigTypeCount, + viewConfigTypes.data())); + CHECK((uint32_t)viewConfigTypes.size() == viewConfigTypeCount); + + auto it = find(viewConfigTypes.begin(), viewConfigTypes.end(), m_ViewConfigType); + if (it == viewConfigTypes.end()) { + Log::Write(Log::Level::Warning, Fmt("Runtime not support xrViewConfigurationType(%d) which app expected, change to the " + "one the runtime prefers the application to use ", + m_ViewConfigType, viewConfigTypes.at(0))); + m_ViewConfigType = viewConfigTypes.at(0); + } + } + private: const std::shared_ptr m_options; std::shared_ptr m_platformPlugin; @@ -999,6 +1015,8 @@ struct OpenXrProgram : IOpenXrProgram { XrSpace m_appSpace{XR_NULL_HANDLE}; XrSystemId m_systemId{XR_NULL_SYSTEM_ID}; + XrViewConfigurationType m_ViewConfigType{XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO}; + std::vector m_configViews; std::vector m_swapchains; std::map> m_swapchainImages;