Log initialization failures in CompositorD3D11.cpp. (bug 1211109 part 1, r=mattwoodrow)
authorDavid Anderson <danderson@mozilla.com>
Mon, 05 Oct 2015 23:38:40 -0700
changeset 266156 6de70cad784834948e234eb80fe2f6490e8eb8f3
parent 266155 29467b3d2124c963eb6646373839b5c5e4d48fc2
child 266157 34e69198f0187b5a224d12303faed2da6a375cc0
push id66137
push userdanderson@mozilla.com
push dateTue, 06 Oct 2015 06:41:06 +0000
treeherdermozilla-inbound@13badd64d40f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow
bugs1211109
milestone44.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Log initialization failures in CompositorD3D11.cpp. (bug 1211109 part 1, r=mattwoodrow)
gfx/layers/d3d11/CompositorD3D11.cpp
gfx/layers/d3d11/CompositorD3D11.h
--- a/gfx/layers/d3d11/CompositorD3D11.cpp
+++ b/gfx/layers/d3d11/CompositorD3D11.cpp
@@ -116,29 +116,38 @@ private:
   }
   void InitPixelShader(const ShaderBytes& aShader, PixelShaderArray& aArray, MaskType aMaskType) {
     InitPixelShader(aShader, byRef(aArray[aMaskType]));
   }
   void InitVertexShader(const ShaderBytes& aShader, ID3D11VertexShader** aOut) {
     if (!mInitOkay) {
       return;
     }
-    if (FAILED(mDevice->CreateVertexShader(aShader.mData, aShader.mLength, nullptr, aOut))) {
+    if (Failed(mDevice->CreateVertexShader(aShader.mData, aShader.mLength, nullptr, aOut), "create vs")) {
       mInitOkay = false;
     }
   }
   void InitPixelShader(const ShaderBytes& aShader, ID3D11PixelShader** aOut) {
     if (!mInitOkay) {
       return;
     }
-    if (FAILED(mDevice->CreatePixelShader(aShader.mData, aShader.mLength, nullptr, aOut))) {
+    if (Failed(mDevice->CreatePixelShader(aShader.mData, aShader.mLength, nullptr, aOut), "create ps")) {
       mInitOkay = false;
     }
   }
 
+  bool Failed(HRESULT hr, const char* aContext) {
+    if (SUCCEEDED(hr))
+      return false;
+
+    gfxCriticalError(CriticalLog::DefaultOptions(false))
+      << "[D3D11] " << aContext << " failed: " << hexa(hr);
+    return true;
+  }
+
   // Only used during initialization.
   RefPtr<ID3D11Device> mDevice;
   bool mInitOkay;
 };
 
 CompositorD3D11::CompositorD3D11(nsIWidget* aWidget)
   : mAttachments(nullptr)
   , mWidget(aWidget)
@@ -188,16 +197,18 @@ CompositorD3D11::Initialize()
 
   if (!mDevice) {
     return false;
   }
 
   mDevice->GetImmediateContext(byRef(mContext));
 
   if (!mContext) {
+    gfxCriticalError(CriticalLog::DefaultOptions(false))
+      << "[D3D11] failed to get immediate context";
     return false;
   }
 
   mFeatureLevel = mDevice->GetFeatureLevel();
 
   mHwnd = (HWND)mWidget->GetNativeData(NS_NATIVE_WINDOW);
 
   memset(&mVSConstants, 0, sizeof(VertexShaderConstants));
@@ -226,148 +237,148 @@ CompositorD3D11::Initialize()
     };
 
     hr = mDevice->CreateInputLayout(layout,
                                     sizeof(layout) / sizeof(D3D11_INPUT_ELEMENT_DESC),
                                     LayerQuadVS,
                                     sizeof(LayerQuadVS),
                                     byRef(mAttachments->mInputLayout));
 
-    if (FAILED(hr)) {
+    if (Failed(hr, "CreateInputLayout")) {
       return false;
     }
 
     Vertex vertices[] = { {{0.0, 0.0}}, {{1.0, 0.0}}, {{0.0, 1.0}}, {{1.0, 1.0}} };
     CD3D11_BUFFER_DESC bufferDesc(sizeof(vertices), D3D11_BIND_VERTEX_BUFFER);
     D3D11_SUBRESOURCE_DATA data;
     data.pSysMem = (void*)vertices;
 
     hr = mDevice->CreateBuffer(&bufferDesc, &data, byRef(mAttachments->mVertexBuffer));
 
-    if (FAILED(hr)) {
+    if (Failed(hr, "create vertex buffer")) {
       return false;
     }
 
     if (!mAttachments->CreateShaders()) {
       return false;
     }
 
     CD3D11_BUFFER_DESC cBufferDesc(sizeof(VertexShaderConstants),
                                    D3D11_BIND_CONSTANT_BUFFER,
                                    D3D11_USAGE_DYNAMIC,
                                    D3D11_CPU_ACCESS_WRITE);
 
     hr = mDevice->CreateBuffer(&cBufferDesc, nullptr, byRef(mAttachments->mVSConstantBuffer));
-    if (FAILED(hr)) {
+    if (Failed(hr, "create vs buffer")) {
       return false;
     }
 
     cBufferDesc.ByteWidth = sizeof(PixelShaderConstants);
     hr = mDevice->CreateBuffer(&cBufferDesc, nullptr, byRef(mAttachments->mPSConstantBuffer));
-    if (FAILED(hr)) {
+    if (Failed(hr, "create ps buffer")) {
       return false;
     }
 
     CD3D11_RASTERIZER_DESC rastDesc(D3D11_DEFAULT);
     rastDesc.CullMode = D3D11_CULL_NONE;
     rastDesc.ScissorEnable = TRUE;
 
     hr = mDevice->CreateRasterizerState(&rastDesc, byRef(mAttachments->mRasterizerState));
-    if (FAILED(hr)) {
+    if (Failed(hr, "create rasterizer")) {
       return false;
     }
 
     CD3D11_SAMPLER_DESC samplerDesc(D3D11_DEFAULT);
     hr = mDevice->CreateSamplerState(&samplerDesc, byRef(mAttachments->mLinearSamplerState));
-    if (FAILED(hr)) {
+    if (Failed(hr, "create linear sampler")) {
       return false;
     }
 
     samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
     hr = mDevice->CreateSamplerState(&samplerDesc, byRef(mAttachments->mPointSamplerState));
-    if (FAILED(hr)) {
+    if (Failed(hr, "create point sampler")) {
       return false;
     }
 
     CD3D11_BLEND_DESC blendDesc(D3D11_DEFAULT);
     D3D11_RENDER_TARGET_BLEND_DESC rtBlendPremul = {
       TRUE,
       D3D11_BLEND_ONE, D3D11_BLEND_INV_SRC_ALPHA, D3D11_BLEND_OP_ADD,
       D3D11_BLEND_ONE, D3D11_BLEND_INV_SRC_ALPHA, D3D11_BLEND_OP_ADD,
       D3D11_COLOR_WRITE_ENABLE_ALL
     };
     blendDesc.RenderTarget[0] = rtBlendPremul;
     hr = mDevice->CreateBlendState(&blendDesc, byRef(mAttachments->mPremulBlendState));
-    if (FAILED(hr)) {
+    if (Failed(hr, "create pm blender")) {
       return false;
     }
 
     D3D11_RENDER_TARGET_BLEND_DESC rtBlendMultiplyPremul = {
       TRUE,
       D3D11_BLEND_DEST_COLOR, D3D11_BLEND_INV_SRC_ALPHA, D3D11_BLEND_OP_ADD,
       D3D11_BLEND_ONE, D3D11_BLEND_INV_SRC_ALPHA, D3D11_BLEND_OP_ADD,
       D3D11_COLOR_WRITE_ENABLE_ALL
     };
     blendDesc.RenderTarget[0] = rtBlendMultiplyPremul;
     hr = mDevice->CreateBlendState(&blendDesc, byRef(mAttachments->mPremulBlendMultiplyState));
-    if (FAILED(hr)) {
+    if (Failed(hr, "create pm-mul blender")) {
       return false;
     }
 
     D3D11_RENDER_TARGET_BLEND_DESC rtBlendScreenPremul = {
       TRUE,
       D3D11_BLEND_ONE, D3D11_BLEND_INV_SRC_COLOR, D3D11_BLEND_OP_ADD,
       D3D11_BLEND_ONE, D3D11_BLEND_INV_SRC_ALPHA, D3D11_BLEND_OP_ADD,
       D3D11_COLOR_WRITE_ENABLE_ALL
     };
     blendDesc.RenderTarget[0] = rtBlendScreenPremul;
     hr = mDevice->CreateBlendState(&blendDesc, byRef(mAttachments->mPremulBlendScreenState));
-    if (FAILED(hr)) {
+    if (Failed(hr, "create pm-scn blender")) {
       return false;
     }
 
     D3D11_RENDER_TARGET_BLEND_DESC rtBlendNonPremul = {
       TRUE,
       D3D11_BLEND_SRC_ALPHA, D3D11_BLEND_INV_SRC_ALPHA, D3D11_BLEND_OP_ADD,
       D3D11_BLEND_ONE, D3D11_BLEND_INV_SRC_ALPHA, D3D11_BLEND_OP_ADD,
       D3D11_COLOR_WRITE_ENABLE_ALL
     };
     blendDesc.RenderTarget[0] = rtBlendNonPremul;
     hr = mDevice->CreateBlendState(&blendDesc, byRef(mAttachments->mNonPremulBlendState));
-    if (FAILED(hr)) {
+    if (Failed(hr, "create npm blender")) {
       return false;
     }
 
     if (gfxPrefs::ComponentAlphaEnabled()) {
       D3D11_RENDER_TARGET_BLEND_DESC rtBlendComponent = {
         TRUE,
         D3D11_BLEND_ONE,
         D3D11_BLEND_INV_SRC1_COLOR,
         D3D11_BLEND_OP_ADD,
         D3D11_BLEND_ONE,
         D3D11_BLEND_INV_SRC_ALPHA,
         D3D11_BLEND_OP_ADD,
         D3D11_COLOR_WRITE_ENABLE_ALL
       };
       blendDesc.RenderTarget[0] = rtBlendComponent;
       hr = mDevice->CreateBlendState(&blendDesc, byRef(mAttachments->mComponentBlendState));
-      if (FAILED(hr)) {
+      if (Failed(hr, "create component blender")) {
         return false;
       }
     }
 
     D3D11_RENDER_TARGET_BLEND_DESC rtBlendDisabled = {
       FALSE,
       D3D11_BLEND_SRC_ALPHA, D3D11_BLEND_INV_SRC_ALPHA, D3D11_BLEND_OP_ADD,
       D3D11_BLEND_ONE, D3D11_BLEND_INV_SRC_ALPHA, D3D11_BLEND_OP_ADD,
       D3D11_COLOR_WRITE_ENABLE_ALL
     };
     blendDesc.RenderTarget[0] = rtBlendDisabled;
     hr = mDevice->CreateBlendState(&blendDesc, byRef(mAttachments->mDisabledBlendState));
-    if (FAILED(hr)) {
+    if (Failed(hr, "create null blender")) {
       return false;
     }
 
     if (!mAttachments->InitSyncObject()) {
       return false;
     }
     
     //
@@ -389,17 +400,17 @@ CompositorD3D11::Initialize()
                                     byRef(mAttachments->mVRDistortionInputLayout[VRHMDType::Oculus050]));
 
     // XXX shared for now, rename
     mAttachments->mVRDistortionInputLayout[VRHMDType::Cardboard] =
       mAttachments->mVRDistortionInputLayout[VRHMDType::Oculus050];
 
     cBufferDesc.ByteWidth = sizeof(gfx::VRDistortionConstants);
     hr = mDevice->CreateBuffer(&cBufferDesc, nullptr, byRef(mAttachments->mVRDistortionConstants));
-    if (FAILED(hr)) {
+    if (Failed(hr, "create vr buffer ")) {
       return false;
     }
   }
 
   nsRefPtr<IDXGIDevice> dxgiDevice;
   nsRefPtr<IDXGIAdapter> dxgiAdapter;
 
   mDevice->QueryInterface(dxgiDevice.StartAssignment());
@@ -427,17 +438,17 @@ CompositorD3D11::Initialize()
 
 
     /**
      * Create a swap chain, this swap chain will contain the backbuffer for
      * the window we draw to. The front buffer is the full screen front
      * buffer.
      */
     hr = dxgiFactory->CreateSwapChain(dxgiDevice, &swapDesc, byRef(mSwapChain));
-    if (FAILED(hr)) {
+    if (Failed(hr, "create swap chain")) {
      return false;
     }
 
     // We need this because we don't want DXGI to respond to Alt+Enter.
     dxgiFactory->MakeWindowAssociation(swapDesc.OutputWindow,
                                        DXGI_MWA_NO_WINDOW_CHANGES);
   }
 
@@ -1348,22 +1359,22 @@ DeviceAttachmentsD3D11::InitSyncObject()
   // whenever we're using WARP.
   CD3D11_TEXTURE2D_DESC desc(DXGI_FORMAT_B8G8R8A8_UNORM, 1, 1, 1, 1,
                              D3D11_BIND_SHADER_RESOURCE |
                              D3D11_BIND_RENDER_TARGET);
   desc.MiscFlags = D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX;
 
   RefPtr<ID3D11Texture2D> texture;
   HRESULT hr = mDevice->CreateTexture2D(&desc, nullptr, byRef(texture));
-  if (FAILED(hr)) {
+  if (Failed(hr, "create sync texture")) {
     return false;
   }
 
   hr = texture->QueryInterface((IDXGIResource**)byRef(mSyncTexture));
-  if (FAILED(hr)) {
+  if (Failed(hr, "QI sync texture")) {
     return false;
   }
 
   hr = mSyncTexture->GetSharedHandle(&mSyncHandle);
   if (FAILED(hr) || !mSyncHandle) {
     gfxCriticalError() << "Failed to get SharedHandle for sync texture. Result: "
                        << hexa(hr);
     NS_DispatchToMainThread(NS_NewRunnableFunction([] () -> void {
@@ -1503,16 +1514,27 @@ CompositorD3D11::PaintToTarget()
   mTarget->CopySurface(sourceSurface,
                        IntRect(0, 0, bbDesc.Width, bbDesc.Height),
                        IntPoint(-mTargetBounds.x, -mTargetBounds.y));
 
   mTarget->Flush();
   mContext->Unmap(readTexture, 0);
 }
 
+bool
+CompositorD3D11::Failed(HRESULT hr, const char* aContext)
+{
+  if (SUCCEEDED(hr))
+    return false;
+
+  gfxCriticalError(CriticalLog::DefaultOptions(false))
+    << "[D3D11] " << aContext << " failed: " << hexa(hr);
+  return true;
+}
+
 void
 CompositorD3D11::HandleError(HRESULT hr, Severity aSeverity)
 {
   if (SUCCEEDED(hr)) {
     return;
   }
 
   if (aSeverity == Critical) {
--- a/gfx/layers/d3d11/CompositorD3D11.h
+++ b/gfx/layers/d3d11/CompositorD3D11.h
@@ -155,16 +155,20 @@ private:
     DebugAssert,
     Critical,
   };
 
   void HandleError(HRESULT hr, Severity aSeverity = DebugAssert);
   bool Failed(HRESULT hr, Severity aSeverity = DebugAssert);
   bool Succeeded(HRESULT hr, Severity aSeverity = DebugAssert);
 
+  // Same as Failed(), except the severity is critical (with no abort) and
+  // a string prefix must be provided.
+  bool Failed(HRESULT hr, const char* aContext);
+
   // ensure mSize is up to date with respect to mWidget
   void EnsureSize();
   bool VerifyBufferSize();
   void UpdateRenderTarget();
   bool UpdateConstantBuffers();
   void SetSamplerForFilter(gfx::Filter aFilter);
   void SetPSForEffect(Effect *aEffect, MaskType aMaskType, gfx::SurfaceFormat aFormat);
   void PaintToTarget();