Bug 1285692 - Remove unnecessary KeyedMutex usage with DX_interop. - r=jrmuizel
authorJeff Gilbert <jgilbert@mozilla.com>
Fri, 08 Jul 2016 17:54:14 -0700
changeset 353677 92796a154d600385d6d2939f3b3f064bf8e0ae3e
parent 353676 a67661b37e17afb179b76503ca5bf57a5df863ad
child 353678 066c58cd308f44ab8ede90f1e99eb4f74d5fd2c1
push id1324
push usermtabara@mozilla.com
push dateMon, 16 Jan 2017 13:07:44 +0000
treeherdermozilla-release@a01c49833940 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs1285692
milestone51.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
Bug 1285692 - Remove unnecessary KeyedMutex usage with DX_interop. - r=jrmuizel While we've been doing AcquireSync()+LockObject() previously, this doesn't seem to be required. It makes sense that LockObject would AcquireSync (or in-driver equivalent) when given a KeyedMutex'd D3D11Texture, given the wording of the spec that (Un)LockObject synchronizes GL with D3D. Unfortunately, the extension spec doesn't explicitly state this. MozReview-Commit-ID: 3FgNl1npO34
gfx/gl/SharedSurfaceD3D11Interop.cpp
gfx/gl/SharedSurfaceD3D11Interop.h
--- a/gfx/gl/SharedSurfaceD3D11Interop.cpp
+++ b/gfx/gl/SharedSurfaceD3D11Interop.cpp
@@ -240,120 +240,86 @@ SharedSurface_D3D11Interop::Create(const
 
     RefPtr<IDXGIResource> textureDXGI;
     hr = textureD3D->QueryInterface(__uuidof(IDXGIResource), getter_AddRefs(textureDXGI));
     if (FAILED(hr)) {
         NS_WARNING("Failed to open texture for sharing!");
         return nullptr;
     }
 
-    RefPtr<IDXGIKeyedMutex> keyedMutex;
-    hr = textureD3D->QueryInterface((IDXGIKeyedMutex**)getter_AddRefs(keyedMutex));
-    if (FAILED(hr)) {
-        NS_WARNING("Failed to obtained keyed mutex from texture!");
-        return nullptr;
-    }
-
     HANDLE sharedHandle;
     textureDXGI->GetSharedHandle(&sharedHandle);
 
     GLuint renderbufferGL = 0;
     gl->MakeCurrent();
     gl->fGenRenderbuffers(1, &renderbufferGL);
     HANDLE objectWGL = dxgl->RegisterObject(textureD3D, renderbufferGL,
                                             LOCAL_GL_RENDERBUFFER,
                                             LOCAL_WGL_ACCESS_WRITE_DISCARD_NV);
     if (!objectWGL) {
         NS_WARNING("Failed to register D3D object with WGL.");
         return nullptr;
     }
 
     typedef SharedSurface_D3D11Interop ptrT;
     UniquePtr<ptrT> ret ( new ptrT(gl, size, hasAlpha, renderbufferGL, dxgl, objectWGL,
-                                   textureD3D, sharedHandle, keyedMutex) );
+                                   textureD3D, sharedHandle) );
     return Move(ret);
 }
 
 SharedSurface_D3D11Interop::SharedSurface_D3D11Interop(GLContext* gl,
                                                        const gfx::IntSize& size,
                                                        bool hasAlpha,
                                                        GLuint renderbufferGL,
                                                        const RefPtr<DXGLDevice>& dxgl,
                                                        HANDLE objectWGL,
                                                        const RefPtr<ID3D11Texture2D>& textureD3D,
-                                                       HANDLE sharedHandle,
-                                                       const RefPtr<IDXGIKeyedMutex>& keyedMutex)
+                                                       HANDLE sharedHandle)
     : SharedSurface(SharedSurfaceType::DXGLInterop2,
                     AttachmentType::GLRenderbuffer,
                     gl,
                     size,
                     hasAlpha,
                     true)
     , mProdRB(renderbufferGL)
     , mDXGL(dxgl)
     , mObjectWGL(objectWGL)
     , mTextureD3D(textureD3D)
     , mNeedsFinish(gfxPrefs::WebGLDXGLNeedsFinish())
     , mSharedHandle(sharedHandle)
-    , mKeyedMutex(keyedMutex)
-    , mLockedForGL(false)
 { }
 
 SharedSurface_D3D11Interop::~SharedSurface_D3D11Interop()
 {
-    MOZ_ASSERT(!mLockedForGL);
+    MOZ_ASSERT(!IsProducerAcquired());
 
     if (!mDXGL->UnregisterObject(mObjectWGL)) {
         NS_WARNING("Failed to release a DXGL object, possibly leaking it.");
     }
 
     if (!mGL->MakeCurrent())
         return;
 
     mGL->fDeleteRenderbuffers(1, &mProdRB);
 
     // mDXGL is closed when it runs out of refs.
 }
 
 void
 SharedSurface_D3D11Interop::ProducerAcquireImpl()
 {
-    MOZ_ASSERT(!mLockedForGL);
-
-    if (mKeyedMutex) {
-        const uint64_t keyValue = 0;
-        const DWORD timeoutMs = 10000;
-        HRESULT hr = mKeyedMutex->AcquireSync(keyValue, timeoutMs);
-        if (hr == WAIT_TIMEOUT) {
-            // Doubt we should do this? Maybe Wait for ever?
-            MOZ_CRASH("GFX: d3d11Interop timeout");
-        }
-    }
-
-    // Now we have the mutex, we can lock for GL.
     MOZ_ALWAYS_TRUE(mDXGL->LockObject(mObjectWGL));
-
-    mLockedForGL = true;
 }
 
 void
 SharedSurface_D3D11Interop::ProducerReleaseImpl()
 {
-    MOZ_ASSERT(mLockedForGL);
-
     mGL->fFlush();
     MOZ_ALWAYS_TRUE(mDXGL->UnlockObject(mObjectWGL));
 
-    mLockedForGL = false;
-
-    // Now we have unlocked for GL, we can release to consumer.
-    if (mKeyedMutex) {
-        mKeyedMutex->ReleaseSync(0);
-    }
-
     if (mNeedsFinish) {
         mGL->fFinish();
     }
 }
 
 bool
 SharedSurface_D3D11Interop::ToSurfaceDescriptor(layers::SurfaceDescriptor* const out_descriptor)
 {
--- a/gfx/gl/SharedSurfaceD3D11Interop.h
+++ b/gfx/gl/SharedSurfaceD3D11Interop.h
@@ -25,20 +25,16 @@ class SharedSurface_D3D11Interop
 public:
     const GLuint mProdRB;
     const RefPtr<DXGLDevice> mDXGL;
     const HANDLE mObjectWGL;
     const HANDLE mSharedHandle;
     const RefPtr<ID3D11Texture2D> mTextureD3D;
     const bool mNeedsFinish;
 
-protected:
-    RefPtr<IDXGIKeyedMutex> mKeyedMutex;
-    bool mLockedForGL;
-
 public:
     static UniquePtr<SharedSurface_D3D11Interop> Create(const RefPtr<DXGLDevice>& dxgl,
                                                         GLContext* gl,
                                                         const gfx::IntSize& size,
                                                         bool hasAlpha);
 
     static SharedSurface_D3D11Interop* Cast(SharedSurface* surf) {
         MOZ_ASSERT(surf->mType == SharedSurfaceType::DXGLInterop2);
@@ -49,18 +45,17 @@ public:
 protected:
     SharedSurface_D3D11Interop(GLContext* gl,
                                const gfx::IntSize& size,
                                bool hasAlpha,
                                GLuint renderbufferGL,
                                const RefPtr<DXGLDevice>& dxgl,
                                HANDLE objectWGL,
                                const RefPtr<ID3D11Texture2D>& textureD3D,
-                               HANDLE sharedHandle,
-                               const RefPtr<IDXGIKeyedMutex>& keyedMutex);
+                               HANDLE sharedHandle);
 
 public:
     virtual ~SharedSurface_D3D11Interop();
 
     virtual void LockProdImpl() override { }
     virtual void UnlockProdImpl() override { }
 
     virtual void ProducerAcquireImpl() override;