Bug 1352446 - Fix 32-bit build crash with Oculus VR draft
authorKearwood Gilbert <kgilbert@mozilla.com>
Thu, 08 Jun 2017 14:03:26 -0700
changeset 595929 cc337a384c722f4332dcacaba2d88f8f9722ac1b
parent 595682 58c5151bfd62de934b2286dbd664e69886270e28
child 633828 b5b069ca25efa8a62e71d6a9b2ca9bdbe612e629
push id64475
push userkgilbert@mozilla.com
push dateSat, 17 Jun 2017 00:04:14 +0000
bugs1352446
milestone56.0a1
Bug 1352446 - Fix 32-bit build crash with Oculus VR - Validate GetSharedResourceView in VRDisplayOculus::SubmitFrame and VRDisplayPuppet::SubmitFrame - Correct size of frameIndex to be "long long" rather than "int" for ovr_GetPredictedDisplayTime - Updated to Oculus 1.15.0 SDK - Now sending absolute timestamp of the predicted frame time to ovr_GetTrackingState rather than a delta MozReview-Commit-ID: GLSkqwae7Jp
gfx/vr/gfxVROculus.cpp
gfx/vr/gfxVROculus.h
gfx/vr/gfxVRPuppet.cpp
gfx/vr/ovr_capi_dynamic.h
--- a/gfx/vr/gfxVROculus.cpp
+++ b/gfx/vr/gfxVROculus.cpp
@@ -119,17 +119,17 @@ static pfn_ovr_GetMirrorTextureBufferGL 
 #ifdef HAVE_64BIT_BUILD
 #define BUILD_BITS 64
 #else
 #define BUILD_BITS 32
 #endif
 
 #define OVR_PRODUCT_VERSION 1
 #define OVR_MAJOR_VERSION   1
-#define OVR_MINOR_VERSION   10
+#define OVR_MINOR_VERSION   15
 
 enum class OculusLeftControllerButtonType : uint16_t {
   LThumb,
   IndexTrigger,
   HandTrigger,
   Button_X,
   Button_Y,
   LThumbRest,
@@ -434,36 +434,35 @@ VRDisplayOculus::ZeroSensor()
   ovr_RecenterTrackingOrigin(mSession);
   UpdateStageParameters();
 }
 
 VRHMDSensorState
 VRDisplayOculus::GetSensorState()
 {
   VRHMDSensorState result;
-  double frameDelta = 0.0f;
+  double predictedFrameTime = 0.0f;
   if (gfxPrefs::VRPosePredictionEnabled()) {
     // XXX We might need to call ovr_GetPredictedDisplayTime even if we don't use the result.
     // If we don't call it, the Oculus driver will spew out many warnings...
-    double predictedFrameTime = ovr_GetPredictedDisplayTime(mSession, 0);
-    frameDelta = predictedFrameTime - ovr_GetTimeInSeconds();
+    predictedFrameTime = ovr_GetPredictedDisplayTime(mSession, 0);
   }
-  result = GetSensorState(frameDelta);
+  result = GetSensorState(predictedFrameTime);
   result.inputFrameID = mDisplayInfo.mFrameId;
   result.position[1] -= mEyeHeight;
   mDisplayInfo.mLastSensorState[result.inputFrameID % kVRMaxLatencyFrames] = result;
   return result;
 }
 
 VRHMDSensorState
-VRDisplayOculus::GetSensorState(double timeOffset)
+VRDisplayOculus::GetSensorState(double absTime)
 {
   VRHMDSensorState result;
 
-  ovrTrackingState state = ovr_GetTrackingState(mSession, timeOffset, true);
+  ovrTrackingState state = ovr_GetTrackingState(mSession, absTime, true);
   ovrPoseStatef& pose(state.HeadPose);
 
   result.timestamp = pose.TimeInSeconds;
 
   if (state.StatusFlags & ovrStatus_OrientationTracked) {
     result.flags |= VRDisplayCapabilityFlags::Cap_Orientation;
 
     result.orientation[0] = pose.ThePose.Orientation.x;
@@ -759,16 +758,20 @@ VRDisplayOculus::SubmitFrame(TextureSour
   mContext->IASetIndexBuffer(nullptr, DXGI_FORMAT_R16_UINT, 0);
   mContext->IASetInputLayout(mInputLayout);
   mContext->RSSetViewports(1, &viewport);
   mContext->RSSetScissorRects(1, &scissor);
   mContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
   mContext->VSSetShader(mQuadVS, nullptr, 0);
   mContext->PSSetShader(mQuadPS, nullptr, 0);
   ID3D11ShaderResourceView* srView = aSource->GetShaderResourceView();
+  if (!srView) {
+    NS_WARNING("Failed to get SRV for Oculus");
+    return false;
+  }
   mContext->PSSetShaderResources(0 /* 0 == TexSlot::RGB */, 1, &srView);
   // XXX Use Constant from TexSlot in CompositorD3D11.cpp?
 
   ID3D11SamplerState *sampler = mLinearSamplerState;
   mContext->PSSetSamplers(0, 1, &sampler);
 
   if (!UpdateConstantBuffers()) {
     NS_WARNING("Failed to update constant buffers for Oculus");
--- a/gfx/vr/gfxVROculus.h
+++ b/gfx/vr/gfxVROculus.h
@@ -56,17 +56,17 @@ protected:
   virtual ~VRDisplayOculus();
   void Destroy();
 
   bool RequireSession();
   const ovrHmdDesc& GetHmdDesc();
 
   already_AddRefed<layers::CompositingRenderTargetD3D11> GetNextRenderTarget();
 
-  VRHMDSensorState GetSensorState(double timeOffset);
+  VRHMDSensorState GetSensorState(double absTime);
 
   ovrHmdDesc mDesc;
   ovrSession mSession;
   ovrFovPort mFOVPort[2];
   ovrTextureSwapChain mTextureSet;
   nsTArray<RefPtr<layers::CompositingRenderTargetD3D11>> mRenderTargets;
 
   RefPtr<ID3D11Device> mDevice;
--- a/gfx/vr/gfxVRPuppet.cpp
+++ b/gfx/vr/gfxVRPuppet.cpp
@@ -429,16 +429,20 @@ VRDisplayPuppet::SubmitFrame(TextureSour
       mContext->IASetIndexBuffer(nullptr, DXGI_FORMAT_R16_UINT, 0);
       mContext->IASetInputLayout(mInputLayout);
       mContext->RSSetViewports(1, &viewport);
       mContext->RSSetScissorRects(1, &scissor);
       mContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
       mContext->VSSetShader(mQuadVS, nullptr, 0);
       mContext->PSSetShader(mQuadPS, nullptr, 0);
       ID3D11ShaderResourceView* srView = aSource->GetShaderResourceView();
+      if (!srView) {
+        NS_WARNING("Failed to get SRV for Puppet");
+        return false;
+      }
       mContext->PSSetShaderResources(0 /* 0 == TexSlot::RGB */, 1, &srView);
       // XXX Use Constant from TexSlot in CompositorD3D11.cpp?
 
       ID3D11SamplerState *sampler = mLinearSamplerState;
       mContext->PSSetSamplers(0, 1, &sampler);
 
       if (!UpdateConstantBuffers()) {
         NS_WARNING("Failed to update constant buffers for Puppet");
--- a/gfx/vr/ovr_capi_dynamic.h
+++ b/gfx/vr/ovr_capi_dynamic.h
@@ -403,16 +403,18 @@ typedef struct {
   float IndexTriggerNoDeadzone[ovrHand_Count];
   float HandTriggerNoDeadzone[ovrHand_Count];
   ovrVector2f ThumbstickNoDeadzone[ovrHand_Count];
 } ovrInputState;
 
 typedef enum {
   ovrInit_Debug          = 0x00000001,
   ovrInit_RequestVersion = 0x00000004,
+  ovrInit_Invisible      = 0x00000010,
+  ovrInit_MixedRendering = 0x00000020,
   ovrinit_WritableBits   = 0x00ffffff,
   ovrInit_EnumSize       = 0x7fffffff
 } ovrInitFlags;
 
 typedef enum {
   ovrLogLevel_Debug = 0,
   ovrLogLevel_Info  = 1,
   ovrLogLevel_Error = 2,
@@ -527,17 +529,17 @@ typedef union {
 typedef ovrResult (OVR_PFN* pfn_ovr_GetTextureSwapChainLength)(ovrSession session, ovrTextureSwapChain chain, int* out_Length);
 typedef ovrResult (OVR_PFN* pfn_ovr_GetTextureSwapChainCurrentIndex)(ovrSession session, ovrTextureSwapChain chain, int* out_Index);
 typedef ovrResult (OVR_PFN* pfn_ovr_GetTextureSwapChainDesc)(ovrSession session, ovrTextureSwapChain chain, ovrTextureSwapChainDesc* out_Desc);
 typedef ovrResult (OVR_PFN* pfn_ovr_CommitTextureSwapChain)(ovrSession session, ovrTextureSwapChain chain);
 typedef void (OVR_PFN* pfn_ovr_DestroyTextureSwapChain)(ovrSession session, ovrTextureSwapChain chain);
 typedef void (OVR_PFN* pfn_ovr_DestroyMirrorTexture)(ovrSession session, ovrMirrorTexture mirrorTexture);
 typedef ovrSizei(OVR_PFN* pfn_ovr_GetFovTextureSize)(ovrSession session, ovrEyeType eye, ovrFovPort fov, float pixelsPerDisplayPixel);
 typedef ovrEyeRenderDesc(OVR_PFN* pfn_ovr_GetRenderDesc)(ovrSession session, ovrEyeType eyeType, ovrFovPort fov);
-typedef ovrResult(OVR_PFN* pfn_ovr_SubmitFrame)(ovrSession session, unsigned int frameIndex,
+typedef ovrResult(OVR_PFN* pfn_ovr_SubmitFrame)(ovrSession session, long long frameIndex,
 	const ovrViewScaleDesc* viewScaleDesc,
 	ovrLayerHeader const * const * layerPtrList, unsigned int layerCount);
 typedef double (OVR_PFN* pfn_ovr_GetPredictedDisplayTime)(ovrSession session, long long frameIndex);
 typedef double (OVR_PFN* pfn_ovr_GetTimeInSeconds)();
 
 
 typedef enum {
   ovrPerfHud_Off = 0,