@@ -52,6 +52,11 @@ namespace OpenXRVk
52
52
{
53
53
WARN_IF_UNSUCCESSFUL (result);
54
54
}
55
+
56
+ // Notify the input system that we have a new predicted display time.
57
+ // The new predicted display time will be used to calculate XrPoses for the current frame.
58
+ session->UpdateXrSpaceLocations (*this , m_frameState.predictedDisplayTime , m_views);
59
+
55
60
// Always return true as we want EndFrame to always be called.
56
61
return true ;
57
62
}
@@ -112,36 +117,10 @@ namespace OpenXRVk
112
117
{
113
118
XR::SwapChain::View* baseSwapChainView = baseSwapChain->GetView (viewIndex);
114
119
SwapChain::View* swapChainView = static_cast <SwapChain::View*>(baseSwapChainView);
115
- Space* xrSpace = static_cast <Space*>(GetSession ()->GetSpace ());
116
- Instance* instance = static_cast <Instance*>(GetDescriptor ().m_instance .get ());
117
- Session* session = static_cast <Session*>(GetSession ().get ());
118
- XrSession xrSession = session->GetXrSession ();
119
120
XrSwapchain swapChainHandle = swapChainView->GetSwapChainHandle ();
120
121
121
- XrViewState viewState{ XR_TYPE_VIEW_STATE };
122
- uint32_t viewCapacityInput = aznumeric_cast<uint32_t >(m_views.size ());
123
-
124
- XrViewLocateInfo viewLocateInfo{ XR_TYPE_VIEW_LOCATE_INFO };
125
- viewLocateInfo.viewConfigurationType = instance->GetViewConfigType ();
126
- viewLocateInfo.displayTime = m_frameState.predictedDisplayTime ;
127
- viewLocateInfo.space = xrSpace->GetXrSpace (OpenXRVk::SpaceType::View);
128
-
129
- XrResult result = xrLocateViews (xrSession, &viewLocateInfo, &viewState, viewCapacityInput, &m_viewCountOutput, m_views.data ());
130
- ASSERT_IF_UNSUCCESSFUL (result);
131
-
132
- if ((viewState.viewStateFlags & XR_VIEW_STATE_POSITION_VALID_BIT) == 0 ||
133
- (viewState.viewStateFlags & XR_VIEW_STATE_ORIENTATION_VALID_BIT) == 0 )
134
- {
135
- // There is no valid tracking poses for the views
136
- return false ;
137
- }
138
-
139
- AZ_Assert (m_viewCountOutput == viewCapacityInput, " Size mismatch between xrLocateViews %i and xrEnumerateViewConfigurationViews %i" , m_viewCountOutput, viewCapacityInput);
140
- AZ_Assert (m_viewCountOutput == static_cast <SwapChain*>(baseSwapChain)->GetViewConfigs ().size (), " Size mismatch between xrLocateViews %i and xrEnumerateViewConfigurationViews %i" , m_viewCountOutput, static_cast <SwapChain*>(baseSwapChain)->GetViewConfigs ().size ());
141
-
142
- m_projectionLayerViews.resize (m_viewCountOutput);
143
122
XrSwapchainImageAcquireInfo acquireInfo{ XR_TYPE_SWAPCHAIN_IMAGE_ACQUIRE_INFO };
144
- result = xrAcquireSwapchainImage (swapChainHandle, &acquireInfo, &baseSwapChainView->m_activeImageIndex );
123
+ auto result = xrAcquireSwapchainImage (swapChainHandle, &acquireInfo, &baseSwapChainView->m_activeImageIndex );
145
124
baseSwapChainView->m_isImageAcquired = (result == XR_SUCCESS);
146
125
WARN_IF_UNSUCCESSFUL (result);
147
126
@@ -150,6 +129,9 @@ namespace OpenXRVk
150
129
result = xrWaitSwapchainImage (swapChainHandle, &waitInfo);
151
130
ASSERT_IF_UNSUCCESSFUL (result);
152
131
132
+ // REMARK: The data in m_views was updated during BeginFrameInternal(), which
133
+ // calls session->UpdateXrSpaceLocations(...).
134
+ m_projectionLayerViews.resize (m_views.size ());
153
135
m_projectionLayerViews[viewIndex] = { XR_TYPE_COMPOSITION_LAYER_PROJECTION_VIEW };
154
136
m_projectionLayerViews[viewIndex].pose = m_views[viewIndex].pose ;
155
137
m_projectionLayerViews[viewIndex].fov = m_views[viewIndex].fov ;
@@ -189,30 +171,23 @@ namespace OpenXRVk
189
171
190
172
AZ::RHI::ResultCode Device::GetViewFov (AZ::u32 viewIndex, AZ::RPI::FovData& outFovData) const
191
173
{
192
- if (viewIndex < m_projectionLayerViews .size ())
174
+ if (viewIndex < m_views .size ())
193
175
{
194
- outFovData.m_angleLeft = m_projectionLayerViews [viewIndex].fov .angleLeft ;
195
- outFovData.m_angleRight = m_projectionLayerViews [viewIndex].fov .angleRight ;
196
- outFovData.m_angleUp = m_projectionLayerViews [viewIndex].fov .angleUp ;
197
- outFovData.m_angleDown = m_projectionLayerViews [viewIndex].fov .angleDown ;
176
+ outFovData.m_angleLeft = m_views [viewIndex].fov .angleLeft ;
177
+ outFovData.m_angleRight = m_views [viewIndex].fov .angleRight ;
178
+ outFovData.m_angleUp = m_views [viewIndex].fov .angleUp ;
179
+ outFovData.m_angleDown = m_views [viewIndex].fov .angleDown ;
198
180
return AZ::RHI::ResultCode::Success;
199
181
}
200
182
return AZ::RHI::ResultCode::Fail;
201
183
}
202
184
203
185
AZ::RHI::ResultCode Device::GetViewPose (AZ::u32 viewIndex, AZ::RPI::PoseData& outPoseData) const
204
186
{
205
- if (viewIndex < m_projectionLayerViews .size ())
187
+ if (viewIndex < m_views .size ())
206
188
{
207
- const XrQuaternionf& orientation = m_projectionLayerViews[viewIndex].pose .orientation ;
208
- const XrVector3f& position = m_projectionLayerViews[viewIndex].pose .position ;
209
- outPoseData.m_orientation .Set (orientation.x ,
210
- orientation.y ,
211
- orientation.z ,
212
- orientation.w );
213
- outPoseData.m_position .Set (position.x ,
214
- position.y ,
215
- position.z );
189
+ outPoseData.m_orientation = AzQuaternionFromXrPose (m_views[viewIndex].pose );
190
+ outPoseData.m_position = AzPositionFromXrPose (m_views[viewIndex].pose );
216
191
return AZ::RHI::ResultCode::Success;
217
192
}
218
193
return AZ::RHI::ResultCode::Fail;
@@ -231,4 +206,5 @@ namespace OpenXRVk
231
206
m_xrVkDevice = VK_NULL_HANDLE;
232
207
m_xrVkPhysicalDevice = VK_NULL_HANDLE;
233
208
}
209
+
234
210
}
0 commit comments