[vlc-commits] d3d11: Store context_mutex in the DeviceContext private data

Hugo Beauzée-Luyssen git at videolan.org
Thu Aug 2 13:08:09 CEST 2018


vlc | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Tue Mar 13 15:56:09 2018 +0100| [0d7d3f6e7ab4fc3b1b962ed9d304d81d88df6a4e] | committer: Steve Lhomme

d3d11: Store context_mutex in the DeviceContext private data

And create it as soon as the DeviceContext is created so they have the same
lifetime.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=0d7d3f6e7ab4fc3b1b962ed9d304d81d88df6a4e
---

 modules/codec/avcodec/d3d11va.c         |  2 +-
 modules/hw/d3d11/d3d11_instance.c       |  4 ++--
 modules/video_chroma/d3d11_fmt.c        | 15 +++++++++++++++
 modules/video_output/win32/direct3d11.c | 13 -------------
 4 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/modules/codec/avcodec/d3d11va.c b/modules/codec/avcodec/d3d11va.c
index 3f2c7bb793..0fefb04615 100644
--- a/modules/codec/avcodec/d3d11va.c
+++ b/modules/codec/avcodec/d3d11va.c
@@ -355,7 +355,7 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat pix_fmt,
             ID3D11DeviceContext_GetDevice( p_sys->context, &sys->d3d_dev.d3ddevice );
             HANDLE context_lock = INVALID_HANDLE_VALUE;
             UINT dataSize = sizeof(context_lock);
-            hr = ID3D11Device_GetPrivateData(sys->d3d_dev.d3ddevice, &GUID_CONTEXT_MUTEX, &dataSize, &context_lock);
+            hr = ID3D11DeviceContext_GetPrivateData(p_sys->context, &GUID_CONTEXT_MUTEX, &dataSize, &context_lock);
             if (FAILED(hr))
                 msg_Warn(va, "No mutex found to lock the decoder");
             sys->d3d_dev.context_mutex = context_lock;
diff --git a/modules/hw/d3d11/d3d11_instance.c b/modules/hw/d3d11/d3d11_instance.c
index 11585b3f4e..373bd8a0e1 100644
--- a/modules/hw/d3d11/d3d11_instance.c
+++ b/modules/hw/d3d11/d3d11_instance.c
@@ -54,8 +54,8 @@ void D3D11_FilterHoldInstance(filter_t *filter, d3d11_device_t *out, D3D11_TEXTU
         ID3D11DeviceContext_GetDevice(out->d3dcontext, &out->d3ddevice);
 
         UINT dataSize = sizeof(out->context_mutex);
-        HRESULT hr = ID3D11Device_GetPrivateData(out->d3ddevice, &GUID_CONTEXT_MUTEX,
-                                                 &dataSize, &out->context_mutex);
+        HRESULT hr = ID3D11DeviceContext_GetPrivateData(out->d3dcontext, &GUID_CONTEXT_MUTEX,
+                                                        &dataSize, &out->context_mutex);
         if (FAILED(hr) || dataSize != sizeof(out->context_mutex))
         {
             msg_Warn(filter, "No mutex found to lock the decoder");
diff --git a/modules/video_chroma/d3d11_fmt.c b/modules/video_chroma/d3d11_fmt.c
index 0057387f86..cd6e263caa 100644
--- a/modules/video_chroma/d3d11_fmt.c
+++ b/modules/video_chroma/d3d11_fmt.c
@@ -219,6 +219,13 @@ void D3D11_ReleaseDevice(d3d11_device_t *d3d_dev)
         ID3D11Device_Release(d3d_dev->d3ddevice);
         d3d_dev->d3ddevice = NULL;
     }
+#if defined(HAVE_ID3D11VIDEODECODER)
+    if( d3d_dev->owner && d3d_dev->context_mutex != INVALID_HANDLE_VALUE )
+    {
+        CloseHandle( d3d_dev->context_mutex );
+        d3d_dev->context_mutex = INVALID_HANDLE_VALUE;
+    }
+#endif
 }
 
 #undef D3D11_CreateDevice
@@ -289,7 +296,15 @@ HRESULT D3D11_CreateDevice(vlc_object_t *obj, d3d11_handle_t *hd3d,
     }
 
     if (SUCCEEDED(hr))
+    {
+#if defined(HAVE_ID3D11VIDEODECODER)
+        out->context_mutex = CreateMutexEx( NULL, NULL, 0, SYNCHRONIZE );
+        ID3D11DeviceContext_SetPrivateData( out->d3dcontext, &GUID_CONTEXT_MUTEX,
+                                            sizeof( out->context_mutex ), &out->context_mutex );
+#endif
+
         out->owner = true;
+    }
 
     return hr;
 }
diff --git a/modules/video_output/win32/direct3d11.c b/modules/video_output/win32/direct3d11.c
index e46a1f2ec0..d1d63d0161 100644
--- a/modules/video_output/win32/direct3d11.c
+++ b/modules/video_output/win32/direct3d11.c
@@ -1461,12 +1461,6 @@ static int Direct3D11CreateGenericResources(vout_display_t *vd)
     vout_display_sys_t *sys = vd->sys;
     HRESULT hr;
 
-#if defined(HAVE_ID3D11VIDEODECODER)
-    sys->d3d_dev.context_mutex = CreateMutexEx( NULL, NULL, 0, SYNCHRONIZE );
-    ID3D11Device_SetPrivateData( sys->d3d_dev.d3ddevice, &GUID_CONTEXT_MUTEX,
-                                 sizeof( sys->d3d_dev.context_mutex ), &sys->d3d_dev.context_mutex );
-#endif
-
     ID3D11BlendState *pSpuBlendState;
     D3D11_BLEND_DESC spuBlendDesc = { 0 };
     spuBlendDesc.RenderTarget[0].BlendEnable = TRUE;
@@ -1626,13 +1620,6 @@ static void Direct3D11DestroyResources(vout_display_t *vd)
             sys->pSPUPixelShader[i] = NULL;
         }
     }
-#if defined(HAVE_ID3D11VIDEODECODER)
-    if( sys->d3d_dev.context_mutex != INVALID_HANDLE_VALUE )
-    {
-        CloseHandle( sys->d3d_dev.context_mutex );
-        sys->d3d_dev.context_mutex = INVALID_HANDLE_VALUE;
-    }
-#endif
 
     msg_Dbg(vd, "Direct3D11 resources destroyed");
 }



More information about the vlc-commits mailing list