[vlc-devel] [PATCH 08/11] d3d11: set the ID3D11DeviceContext globally

Steve Lhomme robux4 at videolabs.io
Thu Nov 16 11:38:54 CET 2017


So filters that don't have direct access to the vout pool can still use the same
D3D11 device/context.
---
 modules/codec/avcodec/d3d11va.c         | 10 ++++++++++
 modules/video_chroma/d3d11_fmt.h        |  3 +++
 modules/video_output/win32/direct3d11.c |  7 +++++++
 3 files changed, 20 insertions(+)

diff --git a/modules/codec/avcodec/d3d11va.c b/modules/codec/avcodec/d3d11va.c
index cfea13cc7b..57cab0158e 100644
--- a/modules/codec/avcodec/d3d11va.c
+++ b/modules/codec/avcodec/d3d11va.c
@@ -117,6 +117,7 @@ struct vlc_va_sys_t
     ID3D11VideoContext           *d3dvidctx;
     DXGI_FORMAT                  render;
 
+    bool                         external_device;
     ID3D11DeviceContext          *d3dctx;
     HANDLE                       context_mutex;
 
@@ -371,6 +372,7 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat pix_fmt,
 
             sys->d3dctx = p_sys->context;
             sys->d3dvidctx = d3dvidctx;
+            sys->external_device = true;
 
             assert(p_sys->texture[KNOWN_DXGI_INDEX] != NULL);
             D3D11_TEXTURE2D_DESC dstDesc;
@@ -458,6 +460,12 @@ static int D3dCreateDevice(vlc_va_t *va)
     }
 #endif
 
+    vlc_value_t v;
+    /* only one object is allowed to set the D3D11 context */
+    assert(var_GetChecked(va->obj.libvlc, D3D11_GLOBAL_CONTEXT_NAME, VLC_VAR_ADDRESS, &v) == VLC_ENOVAR);
+    var_Create(va->obj.libvlc, D3D11_GLOBAL_CONTEXT_NAME, VLC_VAR_ADDRESS);
+    var_SetAddress(va->obj.libvlc, D3D11_GLOBAL_CONTEXT_NAME, hd3d11.d3dcontext);
+
     return VLC_SUCCESS;
 }
 
@@ -473,6 +481,8 @@ static void D3dDestroyDevice(vlc_va_t *va)
         ID3D11DeviceContext_Release(va->sys->d3dctx);
     if (dx_sys->d3ddev)
         ID3D11Device_Release(dx_sys->d3ddev);
+    if (!va->sys->external_device)
+        var_Destroy(va->obj.libvlc, D3D11_GLOBAL_CONTEXT_NAME);
 }
 /**
  * It describes our Direct3D object
diff --git a/modules/video_chroma/d3d11_fmt.h b/modules/video_chroma/d3d11_fmt.h
index bdc886c9b6..5a9e5a3249 100644
--- a/modules/video_chroma/d3d11_fmt.h
+++ b/modules/video_chroma/d3d11_fmt.h
@@ -29,6 +29,9 @@
 
 DEFINE_GUID(GUID_CONTEXT_MUTEX, 0x472e8835, 0x3f8e, 0x4f93, 0xa0, 0xcb, 0x25, 0x79, 0x77, 0x6c, 0xed, 0x86);
 
+/* this global value should go away when we have proper pools handling */
+#define D3D11_GLOBAL_CONTEXT_NAME  "_d3d11-device"
+
 typedef struct
 {
     ID3D11Device             *d3ddevice;       /* D3D device */
diff --git a/modules/video_output/win32/direct3d11.c b/modules/video_output/win32/direct3d11.c
index 73e627ef35..b44a60de15 100644
--- a/modules/video_output/win32/direct3d11.c
+++ b/modules/video_output/win32/direct3d11.c
@@ -565,6 +565,7 @@ static void Close(vlc_object_t *object)
     Direct3D11Close(vd);
     CommonClean(vd);
     Direct3D11Destroy(vd);
+    var_Destroy(vd->obj.libvlc, D3D11_GLOBAL_CONTEXT_NAME);
     free(vd->sys);
 }
 
@@ -1506,6 +1507,12 @@ static int Direct3D11Open(vout_display_t *vd, video_format_t *fmt)
     }
 #endif
 
+    vlc_value_t v;
+    /* only one object is allowed to set the D3D11 context */
+    assert(var_GetChecked(vd->obj.libvlc, D3D11_GLOBAL_CONTEXT_NAME, VLC_VAR_ADDRESS, &v) == VLC_ENOVAR);
+    var_Create(vd->obj.libvlc, D3D11_GLOBAL_CONTEXT_NAME, VLC_VAR_ADDRESS);
+    var_SetAddress(vd->obj.libvlc, D3D11_GLOBAL_CONTEXT_NAME, vd->sys->hd3d11.d3dcontext);
+
     IDXGISwapChain_QueryInterface( sys->dxgiswapChain, &IID_IDXGISwapChain4, (void **)&sys->dxgiswapChain4);
 
     D3D11SetColorSpace(vd);
-- 
2.14.2



More information about the vlc-devel mailing list