[vlc-devel] [PATCH 7/7] qsv: keep the d3d11_decoder_device_t so we don't have to read it each time

Steve Lhomme robux4 at ycbcr.xyz
Fri Aug 14 16:00:29 CEST 2020


We still need the decoder device it's tied to.
---
 modules/codec/qsv.c | 31 +++++++++++++------------------
 1 file changed, 13 insertions(+), 18 deletions(-)

diff --git a/modules/codec/qsv.c b/modules/codec/qsv.c
index 25295315f26..4df403c6410 100644
--- a/modules/codec/qsv.c
+++ b/modules/codec/qsv.c
@@ -304,6 +304,8 @@ typedef struct
                                           //  as it doesn't like constantly changing buffers
     vlc_decoder_device *dec_device;
 #if HAVE_AVCODEC_D3D11VA
+    d3d11_decoder_device_t *d3d11_dev;
+
     size_t           numAllocated;
     QSVFrame         *allocatedFrames[16];
 
@@ -420,8 +422,6 @@ static mfxStatus qsv_frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *request, mf
     if (unlikely(mids == NULL))
         return MFX_ERR_MEMORY_ALLOC;
 
-    d3d11_decoder_device_t *d3d11_dev = GetD3D11OpaqueDevice(p_sys->dec_device);
-
     for (size_t i=0; i < request->NumFrameSuggested &&
                      (i + request->NumFrameSuggested) < ARRAYSIZE(p_sys->allocatedFrames); i++)
     {
@@ -447,7 +447,7 @@ static mfxStatus qsv_frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *request, mf
             desc.StructureByteStride = 0;
 
             ID3D11Buffer *buffer = NULL;
-            HRESULT hr = ID3D11Device_CreateBuffer(d3d11_dev->d3d_dev.d3ddevice, &desc, 0, &buffer);
+            HRESULT hr = ID3D11Device_CreateBuffer(p_sys->d3d11_dev->d3d_dev.d3ddevice, &desc, 0, &buffer);
             if (FAILED(hr))
             {
                 for (;;)
@@ -512,11 +512,10 @@ static mfxStatus qsv_frame_lock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
 {
     encoder_t *enc = pthis;
     encoder_sys_t *p_sys = enc->p_sys;
-    d3d11_decoder_device_t *d3d11_dev = GetD3D11OpaqueDevice(p_sys->dec_device);
     QSVFrame *qf = memIdQsv(mid);
     D3D11_MAPPED_SUBRESOURCE mappedResource;
     HRESULT hr;
-    hr = ID3D11DeviceContext_Map(d3d11_dev->d3d_dev.d3dcontext, qf->surface.Data.MemId, 0, D3D11_MAP_READ, D3D11_MAP_FLAG_DO_NOT_WAIT, &mappedResource);
+    hr = ID3D11DeviceContext_Map(p_sys->d3d11_dev->d3d_dev.d3dcontext, qf->surface.Data.MemId, 0, D3D11_MAP_READ, D3D11_MAP_FLAG_DO_NOT_WAIT, &mappedResource);
     if (FAILED(hr))
         return MFX_ERR_LOCK_MEMORY;
     if (likely(!qf->pic))
@@ -535,9 +534,8 @@ static mfxStatus qsv_frame_unlock(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
     VLC_UNUSED(ptr);
     encoder_t *enc = pthis;
     encoder_sys_t *p_sys = enc->p_sys;
-    d3d11_decoder_device_t *d3d11_dev = GetD3D11OpaqueDevice(p_sys->dec_device);
     QSVFrame *qf = memIdQsv(mid);
-    ID3D11DeviceContext_Unmap(d3d11_dev->d3d_dev.d3dcontext, qf->surface.Data.MemId, 0);
+    ID3D11DeviceContext_Unmap(p_sys->d3d11_dev->d3d_dev.d3dcontext, qf->surface.Data.MemId, 0);
     return MFX_ERR_NONE;
 }
 
@@ -559,11 +557,9 @@ static int assert_D3D11ShadowPool( encoder_t *enc, D3D11_TEXTURE2D_DESC *desc )
     if (unlikely(textureFmt==NULL))
         return VLC_EGENERIC;
 
-    d3d11_decoder_device_t *d3d11_dev = GetD3D11OpaqueDevice(sys->dec_device);
-
     unsigned i;
     for (i=0; i<pool_size; i++)
-        if (AllocateTextures(enc, &d3d11_dev->d3d_dev, textureFmt,
+        if (AllocateTextures(enc, &sys->d3d11_dev->d3d_dev, textureFmt,
                                 &surface_fmt, &sys->copy_pool[i], NULL) != VLC_SUCCESS)
         {
             while (i-- != 0)
@@ -596,8 +592,7 @@ static mfxStatus qsv_frame_get_hdl(mfxHDL pthis, mfxMemId mid, mfxHDL *hdl)
             D3D11_TEXTURE2D_DESC texDesc;
             ID3D11Texture2D_GetDesc(p_sys->texture[0], &texDesc);
             assert_D3D11ShadowPool(enc, &texDesc );
-            d3d11_decoder_device_t *d3d11_dev = GetD3D11OpaqueDevice(sys->dec_device);
-            ID3D11DeviceContext_CopySubresourceRegion(d3d11_dev->d3d_dev.d3dcontext,
+            ID3D11DeviceContext_CopySubresourceRegion(sys->d3d11_dev->d3d_dev.d3dcontext,
                                                       (ID3D11Resource*)sys->copy_pool[p_sys->slice_index],
                                                       0, 0, 0, 0,
                                                       p_sys->resource[0],
@@ -675,6 +670,7 @@ static int Open(vlc_object_t *this)
         if ( sys->dec_device && GetD3D11OpaqueDevice(sys->dec_device) != NULL )
         {
             impl = MFX_IMPL_HARDWARE_ANY | MFX_IMPL_VIA_D3D11;
+            sys->d3d11_dev = GetD3D11OpaqueDevice(sys->dec_device);
         }
 #endif
     }
@@ -712,11 +708,10 @@ static int Open(vlc_object_t *this)
     sys->params.mfx.FrameInfo.FrameRateExtD = enc->fmt_in.video.i_frame_rate_base;
 
 #if HAVE_AVCODEC_D3D11VA
-    if ((impl & MFX_IMPL_VIA_D3D11) && GetD3D11OpaqueDevice(sys->dec_device))
+    if ((impl & MFX_IMPL_VIA_D3D11) && sys->d3d11_dev)
     {
-        d3d11_decoder_device_t *d3d11_dev = GetD3D11OpaqueDevice(sys->dec_device);
         ID3D11Device *d3device;
-        ID3D11DeviceContext_GetDevice(d3d11_dev->d3d_dev.d3dcontext, &d3device);
+        ID3D11DeviceContext_GetDevice(sys->d3d11_dev->d3d_dev.d3dcontext, &d3device);
 
         ID3D10Multithread *pMultithread;
         HRESULT hr = ID3D11Device_QueryInterface( d3device, &IID_ID3D10Multithread, (void **)&pMultithread);
@@ -757,7 +752,7 @@ static int Open(vlc_object_t *this)
     /* Parsing options common to all RC methods and codecs */
     sys->params.IOPattern = MFX_IOPATTERN_OUT_SYSTEM_MEMORY;
 #if HAVE_AVCODEC_D3D11VA
-    if (impl & MFX_IMPL_VIA_D3D11)
+    if ((impl & MFX_IMPL_VIA_D3D11) && sys->d3d11_dev)
         sys->params.IOPattern |=  MFX_IOPATTERN_IN_VIDEO_MEMORY;
     else
 #endif
@@ -843,7 +838,7 @@ static int Open(vlc_object_t *this)
     }
 
 #if HAVE_AVCODEC_D3D11VA
-    if (impl & MFX_IMPL_VIA_D3D11)
+    if ((impl & MFX_IMPL_VIA_D3D11) && sys->d3d11_dev)
     {
         mfxFrameAllocator frame_allocator = {
             .pthis  = enc,
@@ -922,7 +917,7 @@ static int Open(vlc_object_t *this)
 
     /* Vlc module configuration */
 #if HAVE_AVCODEC_D3D11VA
-    if (impl & MFX_IMPL_VIA_D3D11)
+    if ((impl & MFX_IMPL_VIA_D3D11) && sys->d3d11_dev)
     {
         enc->fmt_in.i_codec                = VLC_CODEC_D3D11_OPAQUE;
         enc->fmt_in.video.i_chroma         = VLC_CODEC_D3D11_OPAQUE;
-- 
2.26.2



More information about the vlc-devel mailing list