Bug 1285692 - Remove unnecessary KeyedMutex usage with DX_interop. - r=jrmuizel
☠☠ backed out by c1b834b45a99 ☠ ☠
authorJeff Gilbert <jgilbert@mozilla.com>
Fri, 08 Jul 2016 17:54:14 -0700
changeset 330696 45136034045a6b0e44ddf1119b29c40b53b2ca30
parent 330695 9d0676755cf83ade1bfcc75e968da5e3454efd74
child 330697 d65c0c29e778e90b032b84c8dbb94931963a02cb
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
bugs1285692
milestone50.0a1
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;