[vlc-commits] direct3d11: store a whole d3d11_device_t in the decoder device

Steve Lhomme git at videolan.org
Fri Feb 7 15:58:59 CET 2020


vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Thu Feb  6 09:36:50 2020 +0100| [048cbddb955fecc9078c788d60756d726b71654e] | committer: Steve Lhomme

direct3d11: store a whole d3d11_device_t in the decoder device

Since it already has one anyway. No need to create external ones as long as you
hold a decoder device (or related video context).

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

 modules/codec/avcodec/d3d11va.c  | 61 ++++++++++++++-----------------
 modules/hw/d3d11/d3d11_device.c  | 13 +++----
 modules/hw/d3d11/d3d11_surface.c | 78 ++++++++++++++++------------------------
 modules/video_chroma/d3d11_fmt.h |  2 +-
 4 files changed, 64 insertions(+), 90 deletions(-)

diff --git a/modules/codec/avcodec/d3d11va.c b/modules/codec/avcodec/d3d11va.c
index 2823240487..4eef4fe6b6 100644
--- a/modules/codec/avcodec/d3d11va.c
+++ b/modules/codec/avcodec/d3d11va.c
@@ -97,7 +97,7 @@ DEFINE_GUID(DXVA2_NoEncrypt,                        0x1b81bed0, 0xa0c7, 0x11d3,
 struct vlc_va_sys_t
 {
     d3d11_handle_t               hd3d;
-    d3d11_device_t               d3d_dev;
+    d3d11_device_t               *d3d_dev;
 
     vlc_video_context            *vctx;
 
@@ -132,7 +132,7 @@ static void SetupAVCodecContext(void *opaque, AVCodecContext *avctx)
     vlc_va_sys_t *sys = opaque;
     sys->hw.cfg = &sys->cfg;
     sys->hw.surface = sys->hw_surface;
-    sys->hw.context_mutex = sys->d3d_dev.context_mutex;
+    sys->hw.context_mutex = sys->d3d_dev->context_mutex;
     sys->hw.workaround = sys->selected_decoder->workaround;
     avctx->hwaccel_context = &sys->hw;
 }
@@ -256,8 +256,8 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat hwfmt, const
     if ( hwfmt != AV_PIX_FMT_D3D11VA_VLD )
         return VLC_EGENERIC;
 
-    d3d11_decoder_device_t *d3d11_device = GetD3D11OpaqueDevice( dec_device );
-    if ( d3d11_device == NULL )
+    d3d11_decoder_device_t *devsys = GetD3D11OpaqueDevice( dec_device );
+    if ( devsys == NULL )
         return VLC_EGENERIC;
 
     vlc_va_sys_t *sys = calloc(1, sizeof (*sys));
@@ -270,15 +270,9 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat hwfmt, const
 
     va->sys = sys;
 
-    sys->d3d_dev.d3ddevice = NULL;
     sys->render_fmt = NULL;
-    HRESULT hr = D3D11_CreateDeviceExternal(va, d3d11_device->device, true, &sys->d3d_dev);
-    if (FAILED(hr))
-    {
-        msg_Err(va, "can't use the provided D3D11 context");
-        goto error;
-    }
-    if (sys->d3d_dev.context_mutex == INVALID_HANDLE_VALUE)
+    sys->d3d_dev = &devsys->d3d_dev;
+    if (sys->d3d_dev->context_mutex == INVALID_HANDLE_VALUE)
         msg_Warn(va, "No mutex found to lock the decoder");
 
     struct va_pool_cfg pool_cfg = {
@@ -298,7 +292,7 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat hwfmt, const
 
     video_format_t final_fmt = *fmt_out;
     static const directx_sys_t dx_sys = { DxGetInputList, DxSetupOutput };
-    sys->selected_decoder = directx_va_Setup(va, &dx_sys, ctx, desc, fmt_in, isXboxHardware(&sys->d3d_dev),
+    sys->selected_decoder = directx_va_Setup(va, &dx_sys, ctx, desc, fmt_in, isXboxHardware(sys->d3d_dev),
                                              &final_fmt, &sys->hw.surface_count);
     if (sys->selected_decoder == NULL)
     {
@@ -312,9 +306,9 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat hwfmt, const
         goto error;
 
     msg_Info(va, "Using D3D11VA (%ls, vendor %x(%s), device %x, revision %x)",
-                sys->d3d_dev.adapterDesc.Description,
-                sys->d3d_dev.adapterDesc.VendorId, DxgiVendorStr(sys->d3d_dev.adapterDesc.VendorId),
-                sys->d3d_dev.adapterDesc.DeviceId, sys->d3d_dev.adapterDesc.Revision);
+                sys->d3d_dev->adapterDesc.Description,
+                sys->d3d_dev->adapterDesc.VendorId, DxgiVendorStr(sys->d3d_dev->adapterDesc.VendorId),
+                sys->d3d_dev->adapterDesc.DeviceId, sys->d3d_dev->adapterDesc.Revision);
 
     sys->vctx = vlc_video_context_Create( dec_device, VLC_VIDEO_CONTEXT_D3D11VA,
                                           sizeof(d3d11_video_context_t), &d3d11_vctx_ops );
@@ -327,7 +321,7 @@ static int Open(vlc_va_t *va, AVCodecContext *ctx, enum PixelFormat hwfmt, const
 
     d3d11_video_context_t *priv = GetD3D11ContextPrivate(sys->vctx);
     priv->format = sys->render_fmt->formatTexture;
-    priv->d3d_dev = sys->d3d_dev;
+    priv->d3d_dev = devsys->d3d_dev;
     ID3D11DeviceContext_AddRef(priv->d3d_dev.d3dcontext);
 
     va->ops = &ops;
@@ -348,9 +342,9 @@ static int D3dCreateDevice(vlc_va_t *va)
     vlc_va_sys_t *sys = va->sys;
     HRESULT hr;
 
-    assert(sys->d3d_dev.d3ddevice && sys->d3d_dev.d3dcontext);
+    assert(sys->d3d_dev->d3ddevice && sys->d3d_dev->d3dcontext);
     void *d3dvidctx = NULL;
-    hr = ID3D11DeviceContext_QueryInterface(sys->d3d_dev.d3dcontext, &IID_ID3D11VideoContext, &d3dvidctx);
+    hr = ID3D11DeviceContext_QueryInterface(sys->d3d_dev->d3dcontext, &IID_ID3D11VideoContext, &d3dvidctx);
     if (FAILED(hr)) {
        msg_Err(va, "Could not Query ID3D11VideoContext Interface. (hr=0x%lX)", hr);
        return VLC_EGENERIC;
@@ -358,7 +352,7 @@ static int D3dCreateDevice(vlc_va_t *va)
     sys->hw.video_context = d3dvidctx;
 
     void *d3dviddev = NULL;
-    hr = ID3D11Device_QueryInterface(sys->d3d_dev.d3ddevice, &IID_ID3D11VideoDevice, &d3dviddev);
+    hr = ID3D11Device_QueryInterface(sys->d3d_dev->d3ddevice, &IID_ID3D11VideoDevice, &d3dviddev);
     if (FAILED(hr)) {
        msg_Err(va, "Could not Query ID3D11VideoDevice Interface. (hr=0x%lX)", hr);
        ID3D11VideoContext_Release(sys->hw.video_context);
@@ -429,8 +423,8 @@ static int DxSetupOutput(vlc_va_t *va, const directx_va_mode_t *mode, const vide
     }
 #endif
 
-    if (!directx_va_canUseDecoder(va, sys->d3d_dev.adapterDesc.VendorId, sys->d3d_dev.adapterDesc.DeviceId,
-                                  mode->guid, sys->d3d_dev.WDDM.build))
+    if (!directx_va_canUseDecoder(va, sys->d3d_dev->adapterDesc.VendorId, sys->d3d_dev->adapterDesc.DeviceId,
+                                  mode->guid, sys->d3d_dev->WDDM.build))
     {
         msg_Warn(va, "GPU blacklisted for %s codec", mode->name);
         return VLC_EGENERIC;
@@ -440,17 +434,17 @@ static int DxSetupOutput(vlc_va_t *va, const directx_va_mode_t *mode, const vide
     int idx = 0;
     const d3d_format_t *decoder_format;
     UINT supportFlags = D3D11_FORMAT_SUPPORT_DECODER_OUTPUT | D3D11_FORMAT_SUPPORT_SHADER_LOAD;
-    decoder_format = FindD3D11Format( va, &va->sys->d3d_dev, 0, D3D11_RGB_FORMAT|D3D11_YUV_FORMAT,
+    decoder_format = FindD3D11Format( va, va->sys->d3d_dev, 0, D3D11_RGB_FORMAT|D3D11_YUV_FORMAT,
                                       mode->bit_depth, mode->log2_chroma_h+1, mode->log2_chroma_w+1,
                                       D3D11_CHROMA_GPU, supportFlags );
     if (decoder_format == NULL)
-        decoder_format = FindD3D11Format( va, &va->sys->d3d_dev, 0, D3D11_RGB_FORMAT|D3D11_YUV_FORMAT,
+        decoder_format = FindD3D11Format( va, va->sys->d3d_dev, 0, D3D11_RGB_FORMAT|D3D11_YUV_FORMAT,
                                         mode->bit_depth, 0, 0, D3D11_CHROMA_GPU, supportFlags );
     if (decoder_format == NULL && mode->bit_depth > 10)
-        decoder_format = FindD3D11Format( va, &va->sys->d3d_dev, 0, D3D11_RGB_FORMAT|D3D11_YUV_FORMAT,
+        decoder_format = FindD3D11Format( va, va->sys->d3d_dev, 0, D3D11_RGB_FORMAT|D3D11_YUV_FORMAT,
                                         10, 0, 0, D3D11_CHROMA_GPU, supportFlags );
     if (decoder_format == NULL)
-        decoder_format = FindD3D11Format( va, &va->sys->d3d_dev, 0, D3D11_RGB_FORMAT|D3D11_YUV_FORMAT,
+        decoder_format = FindD3D11Format( va, va->sys->d3d_dev, 0, D3D11_RGB_FORMAT|D3D11_YUV_FORMAT,
                                         0, 0, 0, D3D11_CHROMA_GPU, supportFlags );
     if (decoder_format != NULL)
     {
@@ -478,14 +472,14 @@ static int DxSetupOutput(vlc_va_t *va, const directx_va_mode_t *mode, const vide
 
        // check if we can create render texture of that format
        // check the decoder can output to that format
-       if ( !DeviceSupportsFormat(sys->d3d_dev.d3ddevice, processorInput[idx]->formatTexture,
+       if ( !DeviceSupportsFormat(sys->d3d_dev->d3ddevice, processorInput[idx]->formatTexture,
                                   D3D11_FORMAT_SUPPORT_SHADER_LOAD) )
        {
 #ifndef ID3D11VideoContext_VideoProcessorBlt
            msg_Dbg(va, "Format %s needs a processor but is not supported",
                    DxgiFormatToStr(processorInput[idx]->formatTexture));
 #else
-           if ( !DeviceSupportsFormat(sys->d3d_dev.d3ddevice, processorInput[idx]->formatTexture,
+           if ( !DeviceSupportsFormat(sys->d3d_dev->d3ddevice, processorInput[idx]->formatTexture,
                                       D3D11_FORMAT_SUPPORT_VIDEO_PROCESSOR_INPUT) )
            {
                msg_Dbg(va, "Format %s needs a processor but is not available",
@@ -529,7 +523,7 @@ static bool CanUseDecoderPadding(const vlc_va_sys_t *sys)
 {
     /* Qualcomm hardware has issues with textures and pixels that should not be
     * part of the decoded area */
-    return sys->d3d_dev.adapterDesc.VendorId != GPU_MANUFACTURER_QUALCOMM;
+    return sys->d3d_dev->adapterDesc.VendorId != GPU_MANUFACTURER_QUALCOMM;
 }
 
 /**
@@ -542,7 +536,7 @@ static int DxCreateDecoderSurfaces(vlc_va_t *va, int codec_id,
     HRESULT hr;
 
     ID3D10Multithread *pMultithread;
-    hr = ID3D11Device_QueryInterface( sys->d3d_dev.d3ddevice, &IID_ID3D10Multithread, (void **)&pMultithread);
+    hr = ID3D11Device_QueryInterface( sys->d3d_dev->d3ddevice, &IID_ID3D10Multithread, (void **)&pMultithread);
     if (SUCCEEDED(hr)) {
         ID3D10Multithread_SetMultithreadProtected(pMultithread, TRUE);
         ID3D10Multithread_Release(pMultithread);
@@ -578,11 +572,11 @@ static int DxCreateDecoderSurfaces(vlc_va_t *va, int codec_id,
     texDesc.BindFlags = D3D11_BIND_DECODER;
     texDesc.CPUAccessFlags = 0;
 
-    if (DeviceSupportsFormat(sys->d3d_dev.d3ddevice, texDesc.Format, D3D11_FORMAT_SUPPORT_SHADER_LOAD))
+    if (DeviceSupportsFormat(sys->d3d_dev->d3ddevice, texDesc.Format, D3D11_FORMAT_SUPPORT_SHADER_LOAD))
         texDesc.BindFlags |= D3D11_BIND_SHADER_RESOURCE;
 
     ID3D11Texture2D *p_texture;
-    hr = ID3D11Device_CreateTexture2D( sys->d3d_dev.d3ddevice, &texDesc, NULL, &p_texture );
+    hr = ID3D11Device_CreateTexture2D( sys->d3d_dev->d3ddevice, &texDesc, NULL, &p_texture );
     if (FAILED(hr)) {
         msg_Err(va, "CreateTexture2D %zu failed. (hr=0x%lX)", surface_count, hr);
         return VLC_EGENERIC;
@@ -605,7 +599,7 @@ static int DxCreateDecoderSurfaces(vlc_va_t *va, int codec_id,
         if (texDesc.BindFlags & D3D11_BIND_SHADER_RESOURCE)
         {
             ID3D11Texture2D *textures[D3D11_MAX_SHADER_VIEW] = {p_texture, p_texture, p_texture};
-            D3D11_AllocateResourceView(va, sys->d3d_dev.d3ddevice, sys->render_fmt, textures, surface_idx,
+            D3D11_AllocateResourceView(va, sys->d3d_dev->d3ddevice, sys->render_fmt, textures, surface_idx,
                                 &sys->renderSrc[surface_idx * D3D11_MAX_SHADER_VIEW]);
         }
     }
@@ -704,7 +698,6 @@ static void DxDestroySurfaces(void *opaque)
         ID3D11VideoDevice_Release(sys->d3ddec);
     if (sys->hw.video_context)
         ID3D11VideoContext_Release(sys->hw.video_context);
-    D3D11_ReleaseDevice( &sys->d3d_dev );
 
     D3D11_Destroy( &sys->hd3d );
 
diff --git a/modules/hw/d3d11/d3d11_device.c b/modules/hw/d3d11/d3d11_device.c
index 23e0b1b534..6c8bd8e42e 100644
--- a/modules/hw/d3d11/d3d11_device.c
+++ b/modules/hw/d3d11/d3d11_device.c
@@ -43,7 +43,6 @@
 
 typedef struct {
     d3d11_handle_t         hd3d;
-    d3d11_device_t         d3d_dev;
 
     struct {
         void                                     *opaque;
@@ -57,7 +56,7 @@ static void D3D11CloseDecoderDevice(vlc_decoder_device *device)
 {
     d3d11_decoder_device *sys = device->sys;
 
-    D3D11_ReleaseDevice(&sys->d3d_dev);
+    D3D11_ReleaseDevice(&sys->dec_device.d3d_dev);
 
     D3D11_Destroy(&sys->hd3d);
 
@@ -88,7 +87,7 @@ static int D3D11OpenDecoderDevice(vlc_decoder_device *device, bool forced, vout_
     ID3D11DeviceContext *d3dcontext = (ID3D11DeviceContext*)(uintptr_t) var_InheritInteger(device, "winrt-d3dcontext");
     if ( likely(d3dcontext != NULL) )
     {
-        D3D11_CreateDeviceExternal(device, d3dcontext, true, &sys->d3d_dev);
+        D3D11_CreateDeviceExternal(device, d3dcontext, true, &sys->dec_device.d3d_dev);
     }
     else
 #endif
@@ -109,7 +108,7 @@ static int D3D11OpenDecoderDevice(vlc_decoder_device *device, bool forced, vout_
                     sys->external.cleanupDeviceCb( sys->external.opaque );
                 goto error;
             }
-            D3D11_CreateDeviceExternal(device, out.device_context, true, &sys->d3d_dev);
+            D3D11_CreateDeviceExternal(device, out.device_context, true, &sys->dec_device.d3d_dev);
         }
         else
         {
@@ -129,7 +128,7 @@ static int D3D11OpenDecoderDevice(vlc_decoder_device *device, bool forced, vout_
 
             HRESULT hr = D3D11_CreateDevice( device, &sys->hd3d, NULL,
                                             true /* is_d3d11_opaque(chroma) */,
-                                            &sys->d3d_dev );
+                                            &sys->dec_device.d3d_dev );
             if ( FAILED( hr ) )
             {
                 D3D11_Destroy(&sys->hd3d);
@@ -138,13 +137,11 @@ static int D3D11OpenDecoderDevice(vlc_decoder_device *device, bool forced, vout_
         }
     }
 
-    if ( !sys->d3d_dev.d3dcontext )
+    if ( !sys->dec_device.d3d_dev.d3dcontext )
     {
         return VLC_EGENERIC;
     }
 
-    sys->dec_device.device = sys->d3d_dev.d3dcontext;
-
     device->ops = &d3d11_dev_ops;
     device->opaque = &sys->dec_device;
     device->type = VLC_DECODER_DEVICE_D3D11VA;
diff --git a/modules/hw/d3d11/d3d11_surface.c b/modules/hw/d3d11/d3d11_surface.c
index 102bd02d73..b50ee16be0 100644
--- a/modules/hw/d3d11/d3d11_surface.c
+++ b/modules/hw/d3d11/d3d11_surface.c
@@ -69,7 +69,7 @@ typedef struct
     ID3D11VideoProcessorOutputView *processorOutput;
     d3d11_processor_t              d3d_proc;
 #endif
-    d3d11_device_t                 d3d_dev;
+    d3d11_device_t                 *d3d_dev;
 
     /* CPU to GPU */
     filter_t   *filter;
@@ -168,32 +168,32 @@ static int assert_staging(filter_t *p_filter, filter_sys_t *sys, DXGI_FORMAT for
     texDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
     texDesc.BindFlags = 0;
 
-    d3d11_device_t d3d_dev = sys->d3d_dev;
+    d3d11_device_t *d3d_dev = sys->d3d_dev;
     sys->staging = NULL;
-    hr = ID3D11Device_CreateTexture2D( d3d_dev.d3ddevice, &texDesc, NULL, &sys->staging);
+    hr = ID3D11Device_CreateTexture2D( d3d_dev->d3ddevice, &texDesc, NULL, &sys->staging);
     /* test if mapping the texture works ref #18746 */
-    if (SUCCEEDED(hr) && FAILED(hr = can_map(sys, d3d_dev.d3dcontext)))
+    if (SUCCEEDED(hr) && FAILED(hr = can_map(sys, d3d_dev->d3dcontext)))
         msg_Dbg(p_filter, "can't map default staging texture (hr=0x%lX)", hr);
 #if CAN_PROCESSOR
     if (FAILED(hr)) {
         /* failed with the this format, try a different one */
         UINT supportFlags = D3D11_FORMAT_SUPPORT_SHADER_LOAD | D3D11_FORMAT_SUPPORT_VIDEO_PROCESSOR_OUTPUT;
         const d3d_format_t *new_fmt =
-                FindD3D11Format( p_filter, &d3d_dev, 0, D3D11_RGB_FORMAT|D3D11_YUV_FORMAT, 0, 0, 0, D3D11_CHROMA_CPU, supportFlags );
+                FindD3D11Format( p_filter, d3d_dev, 0, D3D11_RGB_FORMAT|D3D11_YUV_FORMAT, 0, 0, 0, D3D11_CHROMA_CPU, supportFlags );
         if (new_fmt && texDesc.Format != new_fmt->formatTexture)
         {
             DXGI_FORMAT srcFormat = texDesc.Format;
             texDesc.Format = new_fmt->formatTexture;
-            hr = ID3D11Device_CreateTexture2D( d3d_dev.d3ddevice, &texDesc, NULL, &sys->staging);
+            hr = ID3D11Device_CreateTexture2D( d3d_dev->d3ddevice, &texDesc, NULL, &sys->staging);
             if (SUCCEEDED(hr))
             {
                 texDesc.Usage = D3D11_USAGE_DEFAULT;
                 texDesc.CPUAccessFlags = 0;
                 texDesc.BindFlags |= D3D11_BIND_RENDER_TARGET;
-                hr = ID3D11Device_CreateTexture2D( d3d_dev.d3ddevice, &texDesc, NULL, &sys->procOutTexture);
-                if (SUCCEEDED(hr) && SUCCEEDED(hr = can_map(sys, d3d_dev.d3dcontext)))
+                hr = ID3D11Device_CreateTexture2D( d3d_dev->d3ddevice, &texDesc, NULL, &sys->procOutTexture);
+                if (SUCCEEDED(hr) && SUCCEEDED(hr = can_map(sys, d3d_dev->d3dcontext)))
                 {
-                    if (SetupProcessor(p_filter, &d3d_dev, srcFormat, new_fmt->formatTexture))
+                    if (SetupProcessor(p_filter, d3d_dev, srcFormat, new_fmt->formatTexture))
                     {
                         ID3D11Texture2D_Release(sys->procOutTexture);
                         ID3D11Texture2D_Release(sys->staging);
@@ -266,14 +266,13 @@ static void D3D11_YUY2(filter_t *p_filter, picture_t *src, picture_t *dst)
         srcSlice = 0;
     }
 #endif
-    d3d11_video_context_t *vctx_sys = GetD3D11ContextPrivate(picture_GetVideoContext(src));
-    ID3D11DeviceContext_CopySubresourceRegion(vctx_sys->d3d_dev.d3dcontext, sys->staging_resource,
+    ID3D11DeviceContext_CopySubresourceRegion(sys->d3d_dev->d3dcontext, sys->staging_resource,
                                               0, 0, 0, 0,
                                               srcResource,
                                               srcSlice,
                                               NULL);
 
-    HRESULT hr = ID3D11DeviceContext_Map(vctx_sys->d3d_dev.d3dcontext, sys->staging_resource,
+    HRESULT hr = ID3D11DeviceContext_Map(sys->d3d_dev->d3dcontext, sys->staging_resource,
                                          0, D3D11_MAP_READ, 0, &lock);
     if (FAILED(hr)) {
         msg_Err(p_filter, "Failed to map source surface. (hr=0x%lX)", hr);
@@ -332,7 +331,7 @@ static void D3D11_YUY2(filter_t *p_filter, picture_t *src, picture_t *dst)
         picture_SwapUV( dst );
 
     /* */
-    ID3D11DeviceContext_Unmap(vctx_sys->d3d_dev.d3dcontext, sys->staging_resource, 0);
+    ID3D11DeviceContext_Unmap(sys->d3d_dev->d3dcontext, sys->staging_resource, 0);
     vlc_mutex_unlock(&sys->staging_lock);
 }
 
@@ -381,14 +380,13 @@ static void D3D11_NV12(filter_t *p_filter, picture_t *src, picture_t *dst)
         srcSlice = 0;
     }
 #endif
-    d3d11_video_context_t *vctx_sys = GetD3D11ContextPrivate(picture_GetVideoContext(src));
-    ID3D11DeviceContext_CopySubresourceRegion(vctx_sys->d3d_dev.d3dcontext, sys->staging_resource,
+    ID3D11DeviceContext_CopySubresourceRegion(sys->d3d_dev->d3dcontext, sys->staging_resource,
                                               0, 0, 0, 0,
                                               srcResource,
                                               srcSlice,
                                               NULL);
 
-    HRESULT hr = ID3D11DeviceContext_Map(vctx_sys->d3d_dev.d3dcontext, sys->staging_resource,
+    HRESULT hr = ID3D11DeviceContext_Map(sys->d3d_dev->d3dcontext, sys->staging_resource,
                                          0, D3D11_MAP_READ, 0, &lock);
     if (FAILED(hr)) {
         msg_Err(p_filter, "Failed to map source surface. (hr=0x%lX)", hr);
@@ -415,7 +413,7 @@ static void D3D11_NV12(filter_t *p_filter, picture_t *src, picture_t *dst)
     }
 
     /* */
-    ID3D11DeviceContext_Unmap(vctx_sys->d3d_dev.d3dcontext, sys->staging_resource, 0);
+    ID3D11DeviceContext_Unmap(sys->d3d_dev->d3dcontext, sys->staging_resource, 0);
     vlc_mutex_unlock(&sys->staging_lock);
 }
 
@@ -429,14 +427,13 @@ static void D3D11_RGBA(filter_t *p_filter, picture_t *src, picture_t *dst)
     D3D11_MAPPED_SUBRESOURCE lock;
 
     vlc_mutex_lock(&sys->staging_lock);
-    d3d11_video_context_t *vctx_sys = GetD3D11ContextPrivate(picture_GetVideoContext(src));
-    ID3D11DeviceContext_CopySubresourceRegion(vctx_sys->d3d_dev.d3dcontext, sys->staging_resource,
+    ID3D11DeviceContext_CopySubresourceRegion(sys->d3d_dev->d3dcontext, sys->staging_resource,
                                               0, 0, 0, 0,
                                               p_sys->resource[KNOWN_DXGI_INDEX],
                                               p_sys->slice_index,
                                               NULL);
 
-    HRESULT hr = ID3D11DeviceContext_Map(vctx_sys->d3d_dev.d3dcontext, sys->staging_resource,
+    HRESULT hr = ID3D11DeviceContext_Map(sys->d3d_dev->d3dcontext, sys->staging_resource,
                                          0, D3D11_MAP_READ, 0, &lock);
     if (FAILED(hr)) {
         msg_Err(p_filter, "Failed to map source surface. (hr=0x%lX)", hr);
@@ -453,7 +450,7 @@ static void D3D11_RGBA(filter_t *p_filter, picture_t *src, picture_t *dst)
     plane_CopyPixels( dst->p, &src_planes );
 
     /* */
-    ID3D11DeviceContext_Unmap(vctx_sys->d3d_dev.d3dcontext,
+    ID3D11DeviceContext_Unmap(sys->d3d_dev->d3dcontext,
                               p_sys->resource[KNOWN_DXGI_INDEX], p_sys->slice_index);
     vlc_mutex_unlock(&sys->staging_lock);
 }
@@ -523,15 +520,15 @@ static void NV12_D3D11(filter_t *p_filter, picture_t *src, picture_t *dst)
         return;
     }
 
-    d3d11_device_lock( &sys->d3d_dev );
+    d3d11_device_lock( sys->d3d_dev );
     if (sys->filter == NULL)
     {
         D3D11_MAPPED_SUBRESOURCE lock;
-        HRESULT hr = ID3D11DeviceContext_Map(sys->d3d_dev.d3dcontext, p_sys->resource[KNOWN_DXGI_INDEX],
+        HRESULT hr = ID3D11DeviceContext_Map(sys->d3d_dev->d3dcontext, p_sys->resource[KNOWN_DXGI_INDEX],
                                             0, D3D11_MAP_WRITE_DISCARD, 0, &lock);
         if (FAILED(hr)) {
             msg_Err(p_filter, "Failed to map source surface. (hr=0x%lX)", hr);
-            d3d11_device_unlock( &sys->d3d_dev );
+            d3d11_device_unlock( sys->d3d_dev );
             return;
         }
 
@@ -542,7 +539,7 @@ static void NV12_D3D11(filter_t *p_filter, picture_t *src, picture_t *dst)
         picture_CopyPixels(dst, src);
 
         dst->context = dst_pic_ctx;
-        ID3D11DeviceContext_Unmap(sys->d3d_dev.d3dcontext, p_sys->resource[KNOWN_DXGI_INDEX], 0);
+        ID3D11DeviceContext_Unmap(sys->d3d_dev->d3dcontext, p_sys->resource[KNOWN_DXGI_INDEX], 0);
     }
     else
     {
@@ -552,11 +549,11 @@ static void NV12_D3D11(filter_t *p_filter, picture_t *src, picture_t *dst)
         ID3D11Texture2D_GetDesc( p_staging_sys->texture[KNOWN_DXGI_INDEX], &texDesc);
 
         D3D11_MAPPED_SUBRESOURCE lock;
-        HRESULT hr = ID3D11DeviceContext_Map(sys->d3d_dev.d3dcontext, p_staging_sys->resource[KNOWN_DXGI_INDEX],
+        HRESULT hr = ID3D11DeviceContext_Map(sys->d3d_dev->d3dcontext, p_staging_sys->resource[KNOWN_DXGI_INDEX],
                                             0, D3D11_MAP_WRITE_DISCARD, 0, &lock);
         if (FAILED(hr)) {
             msg_Err(p_filter, "Failed to map source surface. (hr=0x%lX)", hr);
-            d3d11_device_unlock( &sys->d3d_dev );
+            d3d11_device_unlock( sys->d3d_dev );
             return;
         }
 
@@ -568,19 +565,19 @@ static void NV12_D3D11(filter_t *p_filter, picture_t *src, picture_t *dst)
         sys->filter->pf_video_filter(sys->filter, src);
 
         sys->staging_pic->context = staging_pic_ctx;
-        ID3D11DeviceContext_Unmap(sys->d3d_dev.d3dcontext, p_staging_sys->resource[KNOWN_DXGI_INDEX], 0);
+        ID3D11DeviceContext_Unmap(sys->d3d_dev->d3dcontext, p_staging_sys->resource[KNOWN_DXGI_INDEX], 0);
 
         D3D11_BOX copyBox = {
             .right = dst->format.i_width, .bottom = dst->format.i_height, .back = 1,
         };
-        ID3D11DeviceContext_CopySubresourceRegion(sys->d3d_dev.d3dcontext,
+        ID3D11DeviceContext_CopySubresourceRegion(sys->d3d_dev->d3dcontext,
                                                 p_sys->resource[KNOWN_DXGI_INDEX],
                                                 p_sys->slice_index,
                                                 0, 0, 0,
                                                 p_staging_sys->resource[KNOWN_DXGI_INDEX], 0,
                                                 &copyBox);
     }
-    d3d11_device_unlock( &sys->d3d_dev );
+    d3d11_device_unlock( sys->d3d_dev );
     // stop pretending this is a CPU picture
     dst->format.i_chroma = p_filter->fmt_out.video.i_chroma;
     dst->i_planes = 0;
@@ -593,6 +590,7 @@ VIDEO_FILTER_WRAPPER (D3D11_RGBA)
 static picture_t *AllocateCPUtoGPUTexture(filter_t *p_filter)
 {
     video_format_t fmt_staging;
+    filter_sys_t *p_sys = p_filter->p_sys;
 
     d3d11_video_context_t *vctx_sys = GetD3D11ContextPrivate( p_filter->vctx_out );
 
@@ -623,12 +621,11 @@ static picture_t *AllocateCPUtoGPUTexture(filter_t *p_filter)
         goto done;
     }
 
-    filter_sys_t *p_sys = p_filter->p_sys;
-    if (AllocateTextures(p_filter, &p_sys->d3d_dev, cfg,
+    if (AllocateTextures(p_filter, p_sys->d3d_dev, cfg,
                          &p_dst->format, 1, pic_ctx->picsys.texture, p_dst->p) != VLC_SUCCESS)
         goto done;
 
-    if (unlikely(D3D11_AllocateResourceView(p_filter, p_sys->d3d_dev.d3ddevice, cfg,
+    if (unlikely(D3D11_AllocateResourceView(p_filter, p_sys->d3d_dev->d3ddevice, cfg,
                                             pic_ctx->picsys.texture, 0, pic_ctx->picsys.renderSrc) != VLC_SUCCESS))
         goto done;
 
@@ -716,11 +713,9 @@ int D3D11OpenConverter( vlc_object_t *obj )
         return VLC_ENOMEM;
 
     d3d11_video_context_t *vctx_sys = GetD3D11ContextPrivate(p_filter->vctx_in);
-    D3D11_CreateDeviceExternal(obj, vctx_sys->d3d_dev.d3dcontext, false, &p_sys->d3d_dev);
 
     if (assert_staging(p_filter, p_sys, vctx_sys->format) != VLC_SUCCESS)
     {
-        D3D11_ReleaseDevice(&p_sys->d3d_dev);
         return VLC_EGENERIC;
     }
 
@@ -778,14 +773,6 @@ int D3D11OpenCPUConverter( vlc_object_t *obj )
         return VLC_ENOMEM;
     }
 
-    HRESULT hr = D3D11_CreateDeviceExternal(p_filter, devsys->device, true, &p_sys->d3d_dev);
-    if (FAILED(hr) || unlikely(!p_sys->d3d_dev.d3dcontext))
-    {
-        msg_Dbg(p_filter, "D3D11 opaque without a texture");
-        vlc_decoder_device_Release(dec_device);
-        return VLC_EGENERIC;
-    }
-
     p_filter->vctx_out = vlc_video_context_Create(dec_device, VLC_VIDEO_CONTEXT_D3D11VA,
                                           sizeof(d3d11_video_context_t), &d3d11_vctx_ops);
     vlc_decoder_device_Release(dec_device);
@@ -810,7 +797,7 @@ int D3D11OpenCPUConverter( vlc_object_t *obj )
     default:
         vlc_assert_unreachable();
     }
-    vctx_sys->d3d_dev.d3dcontext = p_sys->d3d_dev.d3dcontext;
+    vctx_sys->d3d_dev = devsys->d3d_dev;
     p_filter->p_sys = p_sys;
 
     vlc_fourcc_t d3d_fourcc = DxgiFormatFourcc(vctx_sys->format);
@@ -835,7 +822,6 @@ done:
     if (err != VLC_SUCCESS)
     {
         vlc_video_context_Release(p_filter->vctx_out);
-        D3D11_ReleaseDevice(&p_sys->d3d_dev);
     }
     return err;
 }
@@ -853,7 +839,6 @@ void D3D11CloseConverter( vlc_object_t *obj )
     vlc_mutex_destroy(&p_sys->staging_lock);
     if (p_sys->staging)
         ID3D11Texture2D_Release(p_sys->staging);
-    D3D11_ReleaseDevice(&p_sys->d3d_dev);
 }
 
 void D3D11CloseCPUConverter( vlc_object_t *obj )
@@ -865,5 +850,4 @@ void D3D11CloseCPUConverter( vlc_object_t *obj )
     if (p_sys->staging_pic)
         picture_Release(p_sys->staging_pic);
     vlc_video_context_Release(p_filter->vctx_out);
-    D3D11_ReleaseDevice(&p_sys->d3d_dev);
 }
diff --git a/modules/video_chroma/d3d11_fmt.h b/modules/video_chroma/d3d11_fmt.h
index ada202d1f8..cd67afcb13 100644
--- a/modules/video_chroma/d3d11_fmt.h
+++ b/modules/video_chroma/d3d11_fmt.h
@@ -88,7 +88,7 @@ struct d3d11_pic_context
 
 typedef struct
 {
-    ID3D11DeviceContext *device;
+    d3d11_device_t      d3d_dev;
 } d3d11_decoder_device_t;
 
 typedef struct



More information about the vlc-commits mailing list