Skip to content

Commit cab41aa

Browse files
jypeitaotao.pei
authored and
tao.pei
committed
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.
1 parent 99256e9 commit cab41aa

File tree

1 file changed

+36
-13
lines changed

1 file changed

+36
-13
lines changed

Diff for: src/tests/hello_xr/openxr_program.cpp

+36-13
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ struct OpenXrProgram : IOpenXrProgram {
9393
: m_options(options),
9494
m_platformPlugin(platformPlugin),
9595
m_graphicsPlugin(graphicsPlugin),
96+
m_ViewConfigType(m_options->Parsed.ViewConfigType),
9697
m_acceptableBlendModes{XR_ENVIRONMENT_BLEND_MODE_OPAQUE, XR_ENVIRONMENT_BLEND_MODE_ADDITIVE,
9798
XR_ENVIRONMENT_BLEND_MODE_ALPHA_BLEND} {}
9899

@@ -219,7 +220,7 @@ struct OpenXrProgram : IOpenXrProgram {
219220
Log::Write(Log::Level::Info, Fmt("Available View Configuration Types: (%d)", viewConfigTypeCount));
220221
for (XrViewConfigurationType viewConfigType : viewConfigTypes) {
221222
Log::Write(Log::Level::Verbose, Fmt(" View Configuration Type: %s %s", to_string(viewConfigType),
222-
viewConfigType == m_options->Parsed.ViewConfigType ? "(Selected)" : ""));
223+
viewConfigType == m_ViewConfigType ? "(Selected)" : ""));
223224

224225
XrViewConfigurationProperties viewConfigProperties{XR_TYPE_VIEW_CONFIGURATION_PROPERTIES};
225226
CHECK_XRCMD(xrGetViewConfigurationProperties(m_instance, m_systemId, viewConfigType, &viewConfigProperties));
@@ -277,11 +278,11 @@ struct OpenXrProgram : IOpenXrProgram {
277278

278279
XrEnvironmentBlendMode GetPreferredBlendMode() const override {
279280
uint32_t count;
280-
CHECK_XRCMD(xrEnumerateEnvironmentBlendModes(m_instance, m_systemId, m_options->Parsed.ViewConfigType, 0, &count, nullptr));
281+
CHECK_XRCMD(xrEnumerateEnvironmentBlendModes(m_instance, m_systemId, m_ViewConfigType, 0, &count, nullptr));
281282
CHECK(count > 0);
282283

283284
std::vector<XrEnvironmentBlendMode> blendModes(count);
284-
CHECK_XRCMD(xrEnumerateEnvironmentBlendModes(m_instance, m_systemId, m_options->Parsed.ViewConfigType, count, &count,
285+
CHECK_XRCMD(xrEnumerateEnvironmentBlendModes(m_instance, m_systemId, m_ViewConfigType, count, &count,
285286
blendModes.data()));
286287
for (const auto& blendMode : blendModes) {
287288
if (m_acceptableBlendModes.count(blendMode)) return blendMode;
@@ -301,6 +302,8 @@ struct OpenXrProgram : IOpenXrProgram {
301302
Fmt("Using system %d for form factor %s", m_systemId, to_string(m_options->Parsed.FormFactor)));
302303
CHECK(m_instance != XR_NULL_HANDLE);
303304
CHECK(m_systemId != XR_NULL_SYSTEM_ID);
305+
306+
determineFinalViewConfigurationType();
304307
}
305308

306309
void InitializeDevice() override {
@@ -589,18 +592,12 @@ struct OpenXrProgram : IOpenXrProgram {
589592
systemProperties.trackingProperties.orientationTracking == XR_TRUE ? "True" : "False",
590593
systemProperties.trackingProperties.positionTracking == XR_TRUE ? "True" : "False"));
591594

592-
// Note: No other view configurations exist at the time this code was written. If this
593-
// condition is not met, the project will need to be audited to see how support should be
594-
// added.
595-
CHECK_MSG(m_options->Parsed.ViewConfigType == XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO,
596-
"Unsupported view configuration type");
597-
598595
// Query and cache view configuration views.
599596
uint32_t viewCount;
600597
CHECK_XRCMD(
601-
xrEnumerateViewConfigurationViews(m_instance, m_systemId, m_options->Parsed.ViewConfigType, 0, &viewCount, nullptr));
598+
xrEnumerateViewConfigurationViews(m_instance, m_systemId, m_ViewConfigType, 0, &viewCount, nullptr));
602599
m_configViews.resize(viewCount, {XR_TYPE_VIEW_CONFIGURATION_VIEW});
603-
CHECK_XRCMD(xrEnumerateViewConfigurationViews(m_instance, m_systemId, m_options->Parsed.ViewConfigType, viewCount,
600+
CHECK_XRCMD(xrEnumerateViewConfigurationViews(m_instance, m_systemId, m_ViewConfigType, viewCount,
604601
&viewCount, m_configViews.data()));
605602

606603
// Create and cache view buffer for xrLocateViews later.
@@ -741,7 +738,7 @@ struct OpenXrProgram : IOpenXrProgram {
741738
case XR_SESSION_STATE_READY: {
742739
CHECK(m_session != XR_NULL_HANDLE);
743740
XrSessionBeginInfo sessionBeginInfo{XR_TYPE_SESSION_BEGIN_INFO};
744-
sessionBeginInfo.primaryViewConfigurationType = m_options->Parsed.ViewConfigType;
741+
sessionBeginInfo.primaryViewConfigurationType = m_ViewConfigType;
745742
CHECK_XRCMD(xrBeginSession(m_session, &sessionBeginInfo));
746743
m_sessionRunning = true;
747744
break;
@@ -895,7 +892,7 @@ struct OpenXrProgram : IOpenXrProgram {
895892
uint32_t viewCountOutput;
896893

897894
XrViewLocateInfo viewLocateInfo{XR_TYPE_VIEW_LOCATE_INFO};
898-
viewLocateInfo.viewConfigurationType = m_options->Parsed.ViewConfigType;
895+
viewLocateInfo.viewConfigurationType = m_ViewConfigType;
899896
viewLocateInfo.displayTime = predictedDisplayTime;
900897
viewLocateInfo.space = m_appSpace;
901898

@@ -990,6 +987,30 @@ struct OpenXrProgram : IOpenXrProgram {
990987
return true;
991988
}
992989

990+
private:
991+
void determineFinalViewConfigurationType() {
992+
CHECK(m_instance != XR_NULL_HANDLE);
993+
CHECK(m_systemId != 0);
994+
995+
uint32_t viewConfigTypeCount;
996+
CHECK_XRCMD(xrEnumerateViewConfigurations(m_instance, m_systemId, 0, &viewConfigTypeCount,
997+
nullptr));
998+
std::vector<XrViewConfigurationType> viewConfigTypes(viewConfigTypeCount);
999+
CHECK_XRCMD(xrEnumerateViewConfigurations(m_instance, m_systemId, viewConfigTypeCount,
1000+
&viewConfigTypeCount,
1001+
viewConfigTypes.data()));
1002+
CHECK((uint32_t) viewConfigTypes.size() == viewConfigTypeCount);
1003+
1004+
auto it = find(viewConfigTypes.begin(), viewConfigTypes.end(),
1005+
m_ViewConfigType);
1006+
if (it == viewConfigTypes.end()) {
1007+
Log::Write(Log::Level::Warning,
1008+
Fmt("Runtime not support xrViewConfigurationType(%d) which app expected, change to the one the runtime prefers the application to use ",
1009+
m_ViewConfigType, viewConfigTypes.at(0)));
1010+
m_ViewConfigType = viewConfigTypes.at(0);
1011+
}
1012+
}
1013+
9931014
private:
9941015
const std::shared_ptr<const Options> m_options;
9951016
std::shared_ptr<IPlatformPlugin> m_platformPlugin;
@@ -999,6 +1020,8 @@ struct OpenXrProgram : IOpenXrProgram {
9991020
XrSpace m_appSpace{XR_NULL_HANDLE};
10001021
XrSystemId m_systemId{XR_NULL_SYSTEM_ID};
10011022

1023+
XrViewConfigurationType m_ViewConfigType{XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO};
1024+
10021025
std::vector<XrViewConfigurationView> m_configViews;
10031026
std::vector<Swapchain> m_swapchains;
10041027
std::map<XrSwapchain, std::vector<XrSwapchainImageBaseHeader*>> m_swapchainImages;

0 commit comments

Comments
 (0)