Bug 1284672 - Only use a single D3D11 device for compositing and video decoding. r=jrmuizel
☠☠ backed out by 6bcb97503de4 ☠ ☠
authorMatt Woodrow <mwoodrow@mozilla.com>
Mon, 18 Jul 2016 15:41:11 +1200
changeset 330394 fccc189b56d8809b7258da4f7685ea47fc1493a3
parent 330393 a10a4bbf8728d1802d72876c885726b910faff28
child 330395 bbaa820b8c7cf244614cffa3b505c6a492bf28ad
push id9858
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 14:37:10 +0000
treeherdermozilla-aurora@203106ef6cb6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs1284672
milestone50.0a1
Bug 1284672 - Only use a single D3D11 device for compositing and video decoding. r=jrmuizel
gfx/thebes/gfxWindowsPlatform.cpp
gfx/thebes/gfxWindowsPlatform.h
--- a/gfx/thebes/gfxWindowsPlatform.cpp
+++ b/gfx/thebes/gfxWindowsPlatform.cpp
@@ -2068,17 +2068,17 @@ gfxWindowsPlatform::AttemptD3D11DeviceCr
   IDXGIAdapter1* aAdapter, RefPtr<ID3D11Device>& aOutDevice, HRESULT& aResOut)
 {
   MOZ_SEH_TRY {
     aResOut =
       sD3D11CreateDeviceFn(
         aAdapter, D3D_DRIVER_TYPE_UNKNOWN, nullptr,
         // Use D3D11_CREATE_DEVICE_PREVENT_INTERNAL_THREADING_OPTIMIZATIONS
         // to prevent bug 1092260. IE 11 also uses this flag.
-        D3D11_CREATE_DEVICE_BGRA_SUPPORT | D3D11_CREATE_DEVICE_PREVENT_INTERNAL_THREADING_OPTIMIZATIONS,
+        D3D11_CREATE_DEVICE_BGRA_SUPPORT | D3D11_CREATE_DEVICE_PREVENT_INTERNAL_THREADING_OPTIMIZATIONS | D3D11_CREATE_DEVICE_VIDEO_SUPPORT,
         mFeatureLevels.Elements(), mFeatureLevels.Length(),
         D3D11_SDK_VERSION, getter_AddRefs(aOutDevice), nullptr, nullptr);
   } MOZ_SEH_EXCEPT (EXCEPTION_EXECUTE_HANDLER) {
     return false;
   }
   return true;
 }
 
@@ -2607,32 +2607,52 @@ gfxWindowsPlatform::InitializeD2D()
   d2d1_1.SetSuccessful();
 }
 
 bool
 gfxWindowsPlatform::CreateD3D11DecoderDeviceHelper(
   IDXGIAdapter1* aAdapter, RefPtr<ID3D11Device>& aDevice, HRESULT& aResOut)
 {
   MOZ_SEH_TRY{
+    // Disable threading optimizations on this device to match what we use for
+    // the compositor device. This may not be necessary.
     aResOut =
       sD3D11CreateDeviceFn(
         aAdapter, D3D_DRIVER_TYPE_UNKNOWN, nullptr,
-        D3D11_CREATE_DEVICE_VIDEO_SUPPORT,
+        D3D11_CREATE_DEVICE_PREVENT_INTERNAL_THREADING_OPTIMIZATIONS | D3D11_CREATE_DEVICE_VIDEO_SUPPORT,
         mFeatureLevels.Elements(), mFeatureLevels.Length(),
         D3D11_SDK_VERSION, getter_AddRefs(aDevice), nullptr, nullptr);
 
   } MOZ_SEH_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
     return false;
   }
   return true;
 }
 
 already_AddRefed<ID3D11Device>
 gfxWindowsPlatform::CreateD3D11DecoderDevice()
 {
+  if (mD3D11Device && !mD3D11DecoderDevice) {
+    mD3D11DecoderDevice = mD3D11Device;
+
+    // The WMF documentation on MSDN suggests that we need to enable multithreading
+    // on devices used for video, and we get errors if we don't. I'm not entirely sure
+    // what actually this does since d3d11 devices are meant to be threadsafe already.
+    RefPtr<ID3D10Multithread> multi;
+    mD3D11DecoderDevice->QueryInterface(__uuidof(ID3D10Multithread), getter_AddRefs(multi));
+    if (multi) {
+      multi->SetMultithreadProtected(TRUE);
+    }
+  }
+
+  if (mD3D11DecoderDevice) {
+    RefPtr<ID3D11Device> dev = mD3D11DecoderDevice;
+    return dev.forget();
+  }
+
    if (!sD3D11CreateDeviceFn) {
     // We should just be on Windows Vista or XP in this case.
     return nullptr;
   }
 
   RefPtr<IDXGIAdapter1> adapter = GetDXGIAdapter();
 
   if (!adapter) {
@@ -2650,16 +2670,18 @@ gfxWindowsPlatform::CreateD3D11DecoderDe
     return nullptr;
   }
 
   RefPtr<ID3D10Multithread> multi;
   device->QueryInterface(__uuidof(ID3D10Multithread), getter_AddRefs(multi));
 
   multi->SetMultithreadProtected(TRUE);
 
+  mD3D11DecoderDevice = device;
+
   return device.forget();
 }
 
 bool
 gfxWindowsPlatform::DwmCompositionEnabled()
 {
   if (!IsVistaOrLater()) {
     return false;
--- a/gfx/thebes/gfxWindowsPlatform.h
+++ b/gfx/thebes/gfxWindowsPlatform.h
@@ -325,16 +325,17 @@ private:
     RefPtr<IDWriteRenderingParams> mRenderingParams[TEXT_RENDERING_COUNT];
     DWRITE_MEASURING_MODE mMeasuringMode;
 
     mozilla::Mutex mDeviceLock;
     RefPtr<IDXGIAdapter1> mAdapter;
     RefPtr<ID3D11Device> mD3D11Device;
     RefPtr<ID3D11Device> mD3D11ContentDevice;
     RefPtr<ID3D11Device> mD3D11ImageBridgeDevice;
+    RefPtr<ID3D11Device> mD3D11DecoderDevice;
     RefPtr<mozilla::layers::DeviceManagerD3D9> mDeviceManager;
     mozilla::Atomic<bool> mIsWARP;
     bool mHasDeviceReset;
     bool mHasFakeDeviceReset;
     mozilla::Atomic<bool> mCompositorD3D11TextureSharingWorks;
     mozilla::Atomic<bool> mHasD3D9DeviceReset;
     DeviceResetReason mDeviceResetReason;