Bug 1380142: Add a pref to enable the D3D11 debug layer and to break on errors. r=milan draft
authorBas Schouten <bschouten@mozilla.com>
Tue, 11 Jul 2017 22:53:04 +0200
changeset 607088 74b42a35dbf8ab3851a3e441c655862f152ce482
parent 606864 2afdc1569a3ddf83b1c3ea3abd17867f5746d85b
child 636937 7dfee3ad151e3b971b0afe8c974512c7d6f8090e
push id67888
push userbschouten@mozilla.com
push dateTue, 11 Jul 2017 20:53:23 +0000
reviewersmilan
bugs1380142
milestone56.0a1
Bug 1380142: Add a pref to enable the D3D11 debug layer and to break on errors. r=milan MozReview-Commit-ID: 2FrQGXdgJrD
gfx/thebes/DeviceManagerDx.cpp
gfx/thebes/gfxPrefs.h
modules/libpref/init/all.js
--- a/gfx/thebes/DeviceManagerDx.cpp
+++ b/gfx/thebes/DeviceManagerDx.cpp
@@ -385,57 +385,55 @@ DeviceManagerDx::CreateCompositorDevice(
       false,
       textureSharingWorks,
       featureLevel,
       DxgiAdapterDesc::From(desc)));
   }
   mCompositorDevice->SetExceptionMode(0);
 }
 
-//#define BREAK_ON_D3D_ERROR
-
 bool
 DeviceManagerDx::CreateDevice(IDXGIAdapter* aAdapter,
                                  D3D_DRIVER_TYPE aDriverType,
                                  UINT aFlags,
                                  HRESULT& aResOut,
                                  RefPtr<ID3D11Device>& aOutDevice)
 {
-#ifdef BREAK_ON_D3D_ERROR
-  aFlags |= D3D11_CREATE_DEVICE_DEBUG;
-#endif
+  if (gfxPrefs::Direct3D11EnableDebugLayer() || gfxPrefs::Direct3D11BreakOnError()) {
+    aFlags |= D3D11_CREATE_DEVICE_DEBUG;
+  }
 
   MOZ_SEH_TRY {
     aResOut = sD3D11CreateDeviceFn(
       aAdapter, aDriverType, nullptr,
       aFlags,
       mFeatureLevels.Elements(), mFeatureLevels.Length(),
       D3D11_SDK_VERSION, getter_AddRefs(aOutDevice), nullptr, nullptr);
   } MOZ_SEH_EXCEPT (EXCEPTION_EXECUTE_HANDLER) {
     return false;
   }
 
-#ifdef BREAK_ON_D3D_ERROR
-  do {
-    if (!aOutDevice)
-      break;
+  if (gfxPrefs::Direct3D11BreakOnError()) {
+    do {
+      if (!aOutDevice)
+        break;
 
-    RefPtr<ID3D11Debug> debug;
-    if(!SUCCEEDED( aOutDevice->QueryInterface(__uuidof(ID3D11Debug), getter_AddRefs(debug)) ))
-      break;
+      RefPtr<ID3D11Debug> debug;
+      if (!SUCCEEDED(aOutDevice->QueryInterface(__uuidof(ID3D11Debug), getter_AddRefs(debug))))
+        break;
 
-    RefPtr<ID3D11InfoQueue> infoQueue;
-    if(!SUCCEEDED( debug->QueryInterface(__uuidof(ID3D11InfoQueue), getter_AddRefs(infoQueue)) ))
-      break;
+      RefPtr<ID3D11InfoQueue> infoQueue;
+      if (!SUCCEEDED(debug->QueryInterface(__uuidof(ID3D11InfoQueue), getter_AddRefs(infoQueue))))
+        break;
 
-    infoQueue->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_CORRUPTION, true);
-    infoQueue->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_ERROR, true);
-    infoQueue->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_WARNING, true);
-  } while (false);
-#endif
+      infoQueue->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_CORRUPTION, true);
+      infoQueue->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_ERROR, true);
+      infoQueue->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_WARNING, true);
+    } while (false);
+  }
 
   return true;
 }
 
 void
 DeviceManagerDx::CreateWARPCompositorDevice()
 {
   ScopedGfxFeatureReporter reporterWARP("D3D11-WARP", gfxPrefs::LayersD3D11ForceWARP());
--- a/gfx/thebes/gfxPrefs.h
+++ b/gfx/thebes/gfxPrefs.h
@@ -430,16 +430,18 @@ private:
   DECL_GFX_PREF(Once, "gfx.device-reset.limit",                DeviceResetLimitCount, int32_t, 10);
   DECL_GFX_PREF(Once, "gfx.device-reset.threshold-ms",         DeviceResetThresholdMilliseconds, int32_t, -1);
 
   DECL_GFX_PREF(Once, "gfx.direct2d.disabled",                 Direct2DDisabled, bool, false);
   DECL_GFX_PREF(Once, "gfx.direct2d.force-enabled",            Direct2DForceEnabled, bool, false);
   DECL_GFX_PREF(Live, "gfx.direct3d11.reuse-decoder-device",   Direct3D11ReuseDecoderDevice, int32_t, -1);
   DECL_GFX_PREF(Live, "gfx.direct3d11.allow-intel-mutex",      Direct3D11AllowIntelMutex, bool, true);
   DECL_GFX_PREF(Live, "gfx.direct3d11.use-double-buffering",   Direct3D11UseDoubleBuffering, bool, false);
+  DECL_GFX_PREF(Once, "gfx.direct3d11.enable-debug-layer",     Direct3D11EnableDebugLayer, bool, false);
+  DECL_GFX_PREF(Once, "gfx.direct3d11.break-on-error",         Direct3D11BreakOnError, bool, false);
   DECL_GFX_PREF(Live, "gfx.downloadable_fonts.keep_variation_tables", KeepVariationTables, bool, false);
   DECL_GFX_PREF(Live, "gfx.downloadable_fonts.otl_validation", ValidateOTLTables, bool, true);
   DECL_GFX_PREF(Live, "gfx.draw-color-bars",                   CompositorDrawColorBars, bool, false);
   DECL_GFX_PREF(Once, "gfx.e10s.hide-plugins-for-scroll",      HidePluginsForScroll, bool, true);
   DECL_GFX_PREF(Live, "gfx.layerscope.enabled",                LayerScopeEnabled, bool, false);
   DECL_GFX_PREF(Live, "gfx.layerscope.port",                   LayerScopePort, int32_t, 23456);
   // Note that        "gfx.logging.level" is defined in Logging.h.
   DECL_GFX_PREF(Live, "gfx.logging.level",                     GfxLoggingLevel, int32_t, mozilla::gfx::LOG_DEFAULT);
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -4815,16 +4815,19 @@ pref("widget.window-transforms.disabled"
 #ifdef XP_WIN
 // Whether to disable the automatic detection and use of direct2d.
 pref("gfx.direct2d.disabled", false);
 
 // Whether to attempt to enable Direct2D regardless of automatic detection or
 // blacklisting
 pref("gfx.direct2d.force-enabled", false);
 
+pref("gfx.direct3d11.enable-debug-layer", false);
+pref("gfx.direct3d11.break-on-error", false);
+
 pref("layers.prefer-opengl", false);
 #endif
 
 // Copy-on-write canvas
 pref("layers.shared-buffer-provider.enabled", true);
 
 #ifdef XP_WIN
 pref("layers.shared-buffer-provider.enabled", false);