[vlc-commits] direct3d11: don't store the ID3D11DeviceContext and texture format in the picsys

Steve Lhomme git at videolan.org
Wed Dec 11 11:04:22 CET 2019


vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Thu Aug  1 14:34:59 2019 +0200| [e78c8e9d625b2ef319337f8155a847b8467abbcb] | committer: Steve Lhomme

direct3d11: don't store the ID3D11DeviceContext and texture format in the picsys

The ID3D11DeviceContext is carried by the video context and is not needed.

The texture format is also stored in the video context but it wasn't used anyway.

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

 modules/codec/avcodec/d3d11va.c         |  4 ---
 modules/hw/d3d11/d3d11_deinterlace.c    |  7 +++---
 modules/hw/d3d11/d3d11_filters.c        |  9 +++----
 modules/hw/d3d11/d3d11_surface.c        | 43 ++++++++++++++++-----------------
 modules/video_chroma/d3d11_fmt.c        |  4 ---
 modules/video_chroma/d3d11_fmt.h        |  2 --
 modules/video_output/win32/d3d11_quad.c |  4 ---
 7 files changed, 28 insertions(+), 45 deletions(-)

diff --git a/modules/codec/avcodec/d3d11va.c b/modules/codec/avcodec/d3d11va.c
index 27b12ed331..f90e163c82 100644
--- a/modules/codec/avcodec/d3d11va.c
+++ b/modules/codec/avcodec/d3d11va.c
@@ -169,7 +169,6 @@ static picture_context_t *d3d11va_pic_context_copy(picture_context_t *ctx)
 
 static struct d3d11va_pic_context *CreatePicContext(
                                                   ID3D11Resource *p_resource,
-                                                  ID3D11DeviceContext *context,
                                                   UINT slice,
                                                   ID3D11ShaderResourceView *renderSrc[D3D11_MAX_SHADER_VIEW],
                                                   vlc_video_context *vctx)
@@ -185,8 +184,6 @@ static struct d3d11va_pic_context *CreatePicContext(
     D3D11_TEXTURE2D_DESC txDesc;
     ID3D11Texture2D_GetDesc((ID3D11Texture2D*)p_resource, &txDesc);
 
-    pic_ctx->ctx.picsys.formatTexture = txDesc.Format;
-    pic_ctx->ctx.picsys.context = context;
     pic_ctx->ctx.picsys.slice_index = slice;
     for (int i=0;i<D3D11_MAX_SHADER_VIEW; i++)
     {
@@ -213,7 +210,6 @@ static picture_context_t* NewSurfacePicContext(vlc_va_t *va, vlc_va_surface_t *v
 
     struct d3d11va_pic_context *pic_ctx = CreatePicContext(
                                                   p_resource,
-                                                  sys->d3d_dev.d3dcontext,
                                                   viewDesc.Texture2D.ArraySlice,
                                                   resourceView, sys->vctx);
     ID3D11Resource_Release(p_resource);
diff --git a/modules/hw/d3d11/d3d11_deinterlace.c b/modules/hw/d3d11/d3d11_deinterlace.c
index aeb1e2c2c5..aea94749ce 100644
--- a/modules/hw/d3d11/d3d11_deinterlace.c
+++ b/modules/hw/d3d11/d3d11_deinterlace.c
@@ -168,7 +168,9 @@ static int RenderPic( filter_t *p_filter, picture_t *p_outpic, picture_t *p_pic,
         .back = 1,
     };
 
-    ID3D11DeviceContext_CopySubresourceRegion(p_out_sys->context,
+    d3d11_video_context_t *vctx_sys = GetD3D11ContextPrivate(p_filter->vctx_out);
+
+    ID3D11DeviceContext_CopySubresourceRegion(vctx_sys->device,
                                               p_out_sys->resource[KNOWN_DXGI_INDEX],
                                               p_out_sys->slice_index,
                                               0, 0, 0,
@@ -250,9 +252,6 @@ picture_t *AllocPicture( filter_t *p_filter )
     D3D11_AllocateResourceView(p_filter, p_sys->d3d_dev.d3ddevice, cfg, pic_ctx->picsys.texture, 0, pic_ctx->picsys.renderSrc);
 
     pic->p_sys = &pic_ctx->picsys;
-    pic_ctx->picsys.context = vctx_sys->device;
-    pic_ctx->picsys.formatTexture = vctx_sys->format;
-    ID3D11DeviceContext_AddRef(pic_ctx->picsys.context);
     pic_ctx->s = (picture_context_t) {
         d3d11_pic_context_destroy, d3d11_pic_context_copy,
         vlc_video_context_Hold(p_filter->vctx_out),
diff --git a/modules/hw/d3d11/d3d11_filters.c b/modules/hw/d3d11/d3d11_filters.c
index a5803049eb..672322c470 100644
--- a/modules/hw/d3d11/d3d11_filters.c
+++ b/modules/hw/d3d11/d3d11_filters.c
@@ -232,9 +232,6 @@ static picture_t *AllocPicture( filter_t *p_filter )
     D3D11_AllocateResourceView(p_filter, p_sys->d3d_dev.d3ddevice, cfg, pic_ctx->picsys.texture, 0, pic_ctx->picsys.renderSrc);
 
     pic->p_sys = &pic_ctx->picsys;
-    pic_ctx->picsys.context = vctx_sys->device;
-    pic_ctx->picsys.formatTexture = vctx_sys->format;
-    ID3D11DeviceContext_AddRef(pic_ctx->picsys.context);
     pic_ctx->s = (picture_context_t) {
         d3d11_pic_context_destroy, d3d11_pic_context_copy,
         vlc_video_context_Hold(p_filter->vctx_out),
@@ -321,9 +318,11 @@ static picture_t *Filter(filter_t *p_filter, picture_t *p_pic)
         count++;
     }
 
+    d3d11_video_context_t *vctx_sys = GetD3D11ContextPrivate(p_filter->vctx_out);
+
     if (count == 0)
     {
-        ID3D11DeviceContext_CopySubresourceRegion(p_out_sys->context,
+        ID3D11DeviceContext_CopySubresourceRegion(vctx_sys->device,
                                                   p_out_sys->resource[KNOWN_DXGI_INDEX],
                                                   p_out_sys->slice_index,
                                                   0, 0, 0,
@@ -333,7 +332,7 @@ static picture_t *Filter(filter_t *p_filter, picture_t *p_pic)
     }
     else
     {
-        ID3D11DeviceContext_CopySubresourceRegion(p_out_sys->context,
+        ID3D11DeviceContext_CopySubresourceRegion(vctx_sys->device,
                                                   p_out_sys->resource[KNOWN_DXGI_INDEX],
                                                   p_out_sys->slice_index,
                                                   0, 0, 0,
diff --git a/modules/hw/d3d11/d3d11_surface.c b/modules/hw/d3d11/d3d11_surface.c
index 96ad6b2451..d922ff0080 100644
--- a/modules/hw/d3d11/d3d11_surface.c
+++ b/modules/hw/d3d11/d3d11_surface.c
@@ -167,12 +167,11 @@ static int assert_staging(filter_t *p_filter, picture_sys_d3d11_t *p_sys)
     texDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
     texDesc.BindFlags = 0;
 
-    d3d11_device_t d3d_dev = { .d3dcontext = p_sys->context };
-    ID3D11DeviceContext_GetDevice(d3d_dev.d3dcontext, &d3d_dev.d3ddevice);
+    d3d11_device_t d3d_dev = sys->d3d_dev;
     sys->staging = NULL;
     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, p_sys->context)))
+    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)) {
@@ -191,10 +190,9 @@ static int assert_staging(filter_t *p_filter, picture_sys_d3d11_t *p_sys)
                 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, p_sys->context)))
+                if (SUCCEEDED(hr) && SUCCEEDED(hr = can_map(sys, d3d_dev.d3dcontext)))
                 {
-                    d3d11_device_t proc_dev = { .d3ddevice = d3d_dev.d3ddevice, .d3dcontext = p_sys->context };
-                    if (SetupProcessor(p_filter, &proc_dev, srcFormat, new_fmt->formatTexture))
+                    if (SetupProcessor(p_filter, &d3d_dev, srcFormat, new_fmt->formatTexture))
                     {
                         ID3D11Texture2D_Release(sys->procOutTexture);
                         ID3D11Texture2D_Release(sys->staging);
@@ -274,13 +272,14 @@ static void D3D11_YUY2(filter_t *p_filter, picture_t *src, picture_t *dst)
         srcSlice = 0;
     }
 #endif
-    ID3D11DeviceContext_CopySubresourceRegion(p_sys->context, sys->staging_resource,
+    d3d11_video_context_t *vctx_sys = GetD3D11ContextPrivate(picture_GetVideoContext(src));
+    ID3D11DeviceContext_CopySubresourceRegion(vctx_sys->device, sys->staging_resource,
                                               0, 0, 0, 0,
                                               srcResource,
                                               srcSlice,
                                               NULL);
 
-    HRESULT hr = ID3D11DeviceContext_Map(p_sys->context, sys->staging_resource,
+    HRESULT hr = ID3D11DeviceContext_Map(vctx_sys->device, 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);
@@ -339,7 +338,7 @@ static void D3D11_YUY2(filter_t *p_filter, picture_t *src, picture_t *dst)
         picture_SwapUV( dst );
 
     /* */
-    ID3D11DeviceContext_Unmap(p_sys->context, sys->staging_resource, 0);
+    ID3D11DeviceContext_Unmap(vctx_sys->device, sys->staging_resource, 0);
     vlc_mutex_unlock(&sys->staging_lock);
 }
 
@@ -394,13 +393,14 @@ static void D3D11_NV12(filter_t *p_filter, picture_t *src, picture_t *dst)
         srcSlice = 0;
     }
 #endif
-    ID3D11DeviceContext_CopySubresourceRegion(p_sys->context, sys->staging_resource,
+    d3d11_video_context_t *vctx_sys = GetD3D11ContextPrivate(picture_GetVideoContext(src));
+    ID3D11DeviceContext_CopySubresourceRegion(vctx_sys->device, sys->staging_resource,
                                               0, 0, 0, 0,
                                               srcResource,
                                               srcSlice,
                                               NULL);
 
-    HRESULT hr = ID3D11DeviceContext_Map(p_sys->context, sys->staging_resource,
+    HRESULT hr = ID3D11DeviceContext_Map(vctx_sys->device, 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);
@@ -427,7 +427,7 @@ static void D3D11_NV12(filter_t *p_filter, picture_t *src, picture_t *dst)
     }
 
     /* */
-    ID3D11DeviceContext_Unmap(p_sys->context, sys->staging_resource, 0);
+    ID3D11DeviceContext_Unmap(vctx_sys->device, sys->staging_resource, 0);
     vlc_mutex_unlock(&sys->staging_lock);
 }
 
@@ -447,13 +447,14 @@ static void D3D11_RGBA(filter_t *p_filter, picture_t *src, picture_t *dst)
         return;
     }
 
-    ID3D11DeviceContext_CopySubresourceRegion(p_sys->context, sys->staging_resource,
+    d3d11_video_context_t *vctx_sys = GetD3D11ContextPrivate(picture_GetVideoContext(src));
+    ID3D11DeviceContext_CopySubresourceRegion(vctx_sys->device, sys->staging_resource,
                                               0, 0, 0, 0,
                                               p_sys->resource[KNOWN_DXGI_INDEX],
                                               p_sys->slice_index,
                                               NULL);
 
-    HRESULT hr = ID3D11DeviceContext_Map(p_sys->context, sys->staging_resource,
+    HRESULT hr = ID3D11DeviceContext_Map(vctx_sys->device, 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);
@@ -470,7 +471,7 @@ static void D3D11_RGBA(filter_t *p_filter, picture_t *src, picture_t *dst)
     plane_CopyPixels( dst->p, &src_planes );
 
     /* */
-    ID3D11DeviceContext_Unmap(p_sys->context,
+    ID3D11DeviceContext_Unmap(vctx_sys->device,
                               p_sys->resource[KNOWN_DXGI_INDEX], p_sys->slice_index);
     vlc_mutex_unlock(&sys->staging_lock);
 }
@@ -544,7 +545,7 @@ static void NV12_D3D11(filter_t *p_filter, picture_t *src, picture_t *dst)
     if (sys->filter == NULL)
     {
         D3D11_MAPPED_SUBRESOURCE lock;
-        HRESULT hr = ID3D11DeviceContext_Map(p_sys->context, 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);
@@ -559,7 +560,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(p_sys->context, p_sys->resource[KNOWN_DXGI_INDEX], 0);
+        ID3D11DeviceContext_Unmap(sys->d3d_dev.d3dcontext, p_sys->resource[KNOWN_DXGI_INDEX], 0);
     }
     else
     {
@@ -569,7 +570,7 @@ 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(p_sys->context, 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);
@@ -585,12 +586,12 @@ 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(p_sys->context, 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(p_sys->context,
+        ID3D11DeviceContext_CopySubresourceRegion(sys->d3d_dev.d3dcontext,
                                                 p_sys->resource[KNOWN_DXGI_INDEX],
                                                 p_sys->slice_index,
                                                 0, 0, 0,
@@ -634,8 +635,6 @@ static picture_t *AllocateCPUtoGPUTexture(filter_t *p_filter)
     picture_resource_t res = {};
     picture_sys_d3d11_t *res_sys = &pic_ctx->picsys;
     res.p_sys = res_sys;
-    res_sys->context = vctx_sys->device;
-    res_sys->formatTexture = vctx_sys->format;
 
     video_format_Copy(&fmt_staging, &p_filter->fmt_out.video);
     fmt_staging.i_chroma = cfg->fourcc;
diff --git a/modules/video_chroma/d3d11_fmt.c b/modules/video_chroma/d3d11_fmt.c
index 59da5383f2..3a3762023c 100644
--- a/modules/video_chroma/d3d11_fmt.c
+++ b/modules/video_chroma/d3d11_fmt.c
@@ -58,8 +58,6 @@ void AcquireD3D11PictureSys(picture_sys_d3d11_t *p_sys)
         if (p_sys->texture[i])
             ID3D11Texture2D_AddRef(p_sys->texture[i]);
     }
-    if (p_sys->context)
-        ID3D11DeviceContext_AddRef(p_sys->context);
     if (p_sys->processorInput)
         ID3D11VideoProcessorInputView_AddRef(p_sys->processorInput);
     if (p_sys->processorOutput)
@@ -74,8 +72,6 @@ void ReleaseD3D11PictureSys(picture_sys_d3d11_t *p_sys)
         if (p_sys->texture[i])
             ID3D11Texture2D_Release(p_sys->texture[i]);
     }
-    if (p_sys->context)
-        ID3D11DeviceContext_Release(p_sys->context);
     if (p_sys->processorInput)
         ID3D11VideoProcessorInputView_Release(p_sys->processorInput);
     if (p_sys->processorOutput)
diff --git a/modules/video_chroma/d3d11_fmt.h b/modules/video_chroma/d3d11_fmt.h
index b69f0ffd22..35878e6b60 100644
--- a/modules/video_chroma/d3d11_fmt.h
+++ b/modules/video_chroma/d3d11_fmt.h
@@ -72,12 +72,10 @@ typedef struct
         ID3D11Texture2D           *texture[D3D11_MAX_SHADER_VIEW];
         ID3D11Resource            *resource[D3D11_MAX_SHADER_VIEW];
     };
-    ID3D11DeviceContext           *context;
     unsigned                      slice_index;
     ID3D11VideoProcessorInputView  *processorInput;  /* when used as processor input */
     ID3D11VideoProcessorOutputView *processorOutput; /* when used as processor output */
     ID3D11ShaderResourceView      *renderSrc[D3D11_MAX_SHADER_VIEW];
-    DXGI_FORMAT                   formatTexture;
 } picture_sys_d3d11_t;
 
 struct d3d11_pic_context
diff --git a/modules/video_output/win32/d3d11_quad.c b/modules/video_output/win32/d3d11_quad.c
index 0f2a296a85..41dea2950b 100644
--- a/modules/video_output/win32/d3d11_quad.c
+++ b/modules/video_output/win32/d3d11_quad.c
@@ -1048,10 +1048,6 @@ int D3D11_SetupQuad(vlc_object_t *o, d3d11_device_t *d3d_dev, const video_format
     ShaderUpdateConstants(o, d3d_dev, quad, PS_CONST_COLORSPACE, &colorspace);
 
 
-    quad->picSys.formatTexture = quad->textureFormat->formatTexture;
-    quad->picSys.context = d3d_dev->d3dcontext;
-    ID3D11DeviceContext_AddRef(quad->picSys.context);
-
     if (!D3D11_UpdateQuadPosition(o, d3d_dev, quad, output, orientation))
         return VLC_EGENERIC;
 



More information about the vlc-commits mailing list