[vlc-devel] [PATCH 16/20] hw:d3d11: use d3d11_device_t instead of ID3D11Device
Steve Lhomme
robux4 at videolabs.io
Wed Nov 22 18:18:35 CET 2017
Keep the device for the lifetime of the filter
---
modules/hw/d3d11/d3d11_deinterlace.c | 30 +++++++++++++++---------------
modules/hw/d3d11/d3d11_filters.c | 33 +++++++++++++++++----------------
modules/hw/d3d11/d3d11_surface.c | 18 ++++++++++++------
3 files changed, 44 insertions(+), 37 deletions(-)
diff --git a/modules/hw/d3d11/d3d11_deinterlace.c b/modules/hw/d3d11/d3d11_deinterlace.c
index 1b977d9847..9d466ef78e 100644
--- a/modules/hw/d3d11/d3d11_deinterlace.c
+++ b/modules/hw/d3d11/d3d11_deinterlace.c
@@ -51,6 +51,7 @@ typedef UINT D3D11_VIDEO_PROCESSOR_PROCESSOR_CAPS;
struct filter_sys_t
{
+ d3d11_device_t d3d_dev;
ID3D11VideoDevice *d3dviddev;
ID3D11VideoContext *d3dvidctx;
ID3D11VideoProcessor *videoProcessor;
@@ -285,7 +286,6 @@ int D3D11OpenDeinterlace(vlc_object_t *obj)
{
filter_t *filter = (filter_t *)obj;
HRESULT hr;
- ID3D11Device *d3ddevice = NULL;
ID3D11VideoProcessorEnumerator *processorEnumerator = NULL;
if (!is_d3d11_opaque(filter->fmt_in.video.i_chroma))
@@ -293,6 +293,11 @@ int D3D11OpenDeinterlace(vlc_object_t *obj)
if (!video_format_IsSimilar(&filter->fmt_in.video, &filter->fmt_out.video))
return VLC_EGENERIC;
+ filter_sys_t *sys = malloc(sizeof (*sys));
+ if (unlikely(sys == NULL))
+ return VLC_ENOMEM;
+ memset(sys, 0, sizeof (*sys));
+
picture_t *dst = filter_NewPicture(filter);
if (dst == NULL)
return VLC_EGENERIC;
@@ -305,21 +310,16 @@ int D3D11OpenDeinterlace(vlc_object_t *obj)
D3D11_TEXTURE2D_DESC dstDesc;
ID3D11Texture2D_GetDesc(dst->p_sys->texture[KNOWN_DXGI_INDEX], &dstDesc);
+ sys->d3d_dev.d3dcontext = dst->p_sys->context;
+ ID3D11DeviceContext_GetDevice(sys->d3d_dev.d3dcontext, &sys->d3d_dev.d3ddevice);
- filter_sys_t *sys = malloc(sizeof (*sys));
- if (unlikely(sys == NULL))
- goto error;
- memset(sys, 0, sizeof (*sys));
-
- ID3D11DeviceContext_GetDevice(dst->p_sys->context, &d3ddevice);
-
- hr = ID3D11Device_QueryInterface(d3ddevice, &IID_ID3D11VideoDevice, (void **)&sys->d3dviddev);
+ hr = ID3D11Device_QueryInterface(sys->d3d_dev.d3ddevice, &IID_ID3D11VideoDevice, (void **)&sys->d3dviddev);
if (FAILED(hr)) {
msg_Err(filter, "Could not Query ID3D11VideoDevice Interface. (hr=0x%lX)", hr);
goto error;
}
- hr = ID3D11DeviceContext_QueryInterface(dst->p_sys->context, &IID_ID3D11VideoContext, (void **)&sys->d3dvidctx);
+ hr = ID3D11DeviceContext_QueryInterface(sys->d3d_dev.d3dcontext, &IID_ID3D11VideoContext, (void **)&sys->d3dvidctx);
if (FAILED(hr)) {
msg_Err(filter, "Could not Query ID3D11VideoContext Interface from the picture. (hr=0x%lX)", hr);
goto error;
@@ -327,7 +327,7 @@ int D3D11OpenDeinterlace(vlc_object_t *obj)
HANDLE context_lock = INVALID_HANDLE_VALUE;
UINT dataSize = sizeof(context_lock);
- hr = ID3D11Device_GetPrivateData(d3ddevice, &GUID_CONTEXT_MUTEX, &dataSize, &context_lock);
+ hr = ID3D11Device_GetPrivateData(sys->d3d_dev.d3ddevice, &GUID_CONTEXT_MUTEX, &dataSize, &context_lock);
if (FAILED(hr))
msg_Warn(filter, "No mutex found to lock the decoder");
sys->context_mutex = context_lock;
@@ -442,7 +442,7 @@ int D3D11OpenDeinterlace(vlc_object_t *obj)
texDesc.Height = dstDesc.Height;
texDesc.Width = dstDesc.Width;
- hr = ID3D11Device_CreateTexture2D( d3ddevice, &texDesc, NULL, &sys->outTexture );
+ hr = ID3D11Device_CreateTexture2D( sys->d3d_dev.d3ddevice, &texDesc, NULL, &sys->outTexture );
if (FAILED(hr)) {
msg_Err(filter, "CreateTexture2D failed. (hr=0x%0lx)", hr);
goto error;
@@ -493,12 +493,9 @@ int D3D11OpenDeinterlace(vlc_object_t *obj)
filter->pf_flush = Flush;
filter->p_sys = sys;
- ID3D11Device_Release(d3ddevice);
picture_Release(dst);
return VLC_SUCCESS;
error:
- if (d3ddevice)
- ID3D11Device_Release(d3ddevice);
picture_Release(dst);
if (sys->outTexture)
@@ -511,6 +508,8 @@ error:
ID3D11VideoContext_Release(sys->d3dvidctx);
if (sys->d3dviddev)
ID3D11VideoDevice_Release(sys->d3dviddev);
+ if (sys->d3d_dev.d3dcontext)
+ D3D11_ReleaseDevice(&sys->d3d_dev);
return VLC_EGENERIC;
}
@@ -526,6 +525,7 @@ void D3D11CloseDeinterlace(vlc_object_t *obj)
ID3D11VideoProcessorEnumerator_Release(sys->procEnumerator);
ID3D11VideoContext_Release(sys->d3dvidctx);
ID3D11VideoDevice_Release(sys->d3dviddev);
+ D3D11_ReleaseDevice(&sys->d3d_dev);
free(sys);
}
diff --git a/modules/hw/d3d11/d3d11_filters.c b/modules/hw/d3d11/d3d11_filters.c
index 70764a3e87..de97ee2582 100644
--- a/modules/hw/d3d11/d3d11_filters.c
+++ b/modules/hw/d3d11/d3d11_filters.c
@@ -69,6 +69,7 @@ struct filter_sys_t
struct filter_level Hue;
struct filter_level Saturation;
+ d3d11_device_t d3d_dev;
ID3D11VideoDevice *d3dviddev;
ID3D11VideoContext *d3dvidctx;
ID3D11VideoProcessor *videoProcessor;
@@ -329,7 +330,6 @@ static int D3D11OpenAdjust(vlc_object_t *obj)
{
filter_t *filter = (filter_t *)obj;
HRESULT hr;
- ID3D11Device *d3ddevice = NULL;
ID3D11VideoProcessorEnumerator *processorEnumerator = NULL;
if (!is_d3d11_opaque(filter->fmt_in.video.i_chroma))
@@ -337,6 +337,11 @@ static int D3D11OpenAdjust(vlc_object_t *obj)
if (!video_format_IsSimilar(&filter->fmt_in.video, &filter->fmt_out.video))
return VLC_EGENERIC;
+ filter_sys_t *sys = malloc(sizeof (*sys));
+ if (unlikely(sys == NULL))
+ return VLC_ENOMEM;
+ memset(sys, 0, sizeof (*sys));
+
picture_t *dst = filter_NewPicture(filter);
if (dst == NULL)
return VLC_EGENERIC;
@@ -349,21 +354,16 @@ static int D3D11OpenAdjust(vlc_object_t *obj)
D3D11_TEXTURE2D_DESC dstDesc;
ID3D11Texture2D_GetDesc(dst->p_sys->texture[KNOWN_DXGI_INDEX], &dstDesc);
+ sys->d3d_dev.d3dcontext = dst->p_sys->context;
+ ID3D11DeviceContext_GetDevice(sys->d3d_dev.d3dcontext, &sys->d3d_dev.d3ddevice);
- filter_sys_t *sys = malloc(sizeof (*sys));
- if (unlikely(sys == NULL))
- goto error;
- memset(sys, 0, sizeof (*sys));
-
- ID3D11DeviceContext_GetDevice(dst->p_sys->context, &d3ddevice);
-
- hr = ID3D11Device_QueryInterface(d3ddevice, &IID_ID3D11VideoDevice, (void **)&sys->d3dviddev);
+ hr = ID3D11Device_QueryInterface(sys->d3d_dev.d3ddevice, &IID_ID3D11VideoDevice, (void **)&sys->d3dviddev);
if (FAILED(hr)) {
msg_Err(filter, "Could not Query ID3D11VideoDevice Interface. (hr=0x%lX)", hr);
goto error;
}
- hr = ID3D11DeviceContext_QueryInterface(dst->p_sys->context, &IID_ID3D11VideoContext, (void **)&sys->d3dvidctx);
+ hr = ID3D11DeviceContext_QueryInterface(sys->d3d_dev.d3dcontext, &IID_ID3D11VideoContext, (void **)&sys->d3dvidctx);
if (FAILED(hr)) {
msg_Err(filter, "Could not Query ID3D11VideoContext Interface from the picture. (hr=0x%lX)", hr);
goto error;
@@ -371,7 +371,7 @@ static int D3D11OpenAdjust(vlc_object_t *obj)
HANDLE context_lock = INVALID_HANDLE_VALUE;
UINT dataSize = sizeof(context_lock);
- hr = ID3D11Device_GetPrivateData(d3ddevice, &GUID_CONTEXT_MUTEX, &dataSize, &context_lock);
+ hr = ID3D11Device_GetPrivateData(sys->d3d_dev.d3ddevice, &GUID_CONTEXT_MUTEX, &dataSize, &context_lock);
if (FAILED(hr))
msg_Warn(filter, "No mutex found to lock the decoder");
sys->context_mutex = context_lock;
@@ -501,12 +501,12 @@ static int D3D11OpenAdjust(vlc_object_t *obj)
texDesc.Height = dstDesc.Height;
texDesc.Width = dstDesc.Width;
- hr = ID3D11Device_CreateTexture2D( d3ddevice, &texDesc, NULL, &sys->out[0].texture );
+ hr = ID3D11Device_CreateTexture2D( sys->d3d_dev.d3ddevice, &texDesc, NULL, &sys->out[0].texture );
if (FAILED(hr)) {
msg_Err(filter, "CreateTexture2D failed. (hr=0x%0lx)", hr);
goto error;
}
- hr = ID3D11Device_CreateTexture2D( d3ddevice, &texDesc, NULL, &sys->out[1].texture );
+ hr = ID3D11Device_CreateTexture2D( sys->d3d_dev.d3ddevice, &texDesc, NULL, &sys->out[1].texture );
if (FAILED(hr)) {
ID3D11Texture2D_Release(sys->out[0].texture);
msg_Err(filter, "CreateTexture2D failed. (hr=0x%0lx)", hr);
@@ -556,12 +556,9 @@ static int D3D11OpenAdjust(vlc_object_t *obj)
filter->pf_video_filter = Filter;
filter->p_sys = sys;
- ID3D11Device_Release(d3ddevice);
picture_Release(dst);
return VLC_SUCCESS;
error:
- if (d3ddevice)
- ID3D11Device_Release(d3ddevice);
picture_Release(dst);
for (int i=0; i<PROCESSOR_SLICES; i++)
@@ -584,6 +581,8 @@ error:
ID3D11VideoContext_Release(sys->d3dvidctx);
if (sys->d3dviddev)
ID3D11VideoDevice_Release(sys->d3dviddev);
+ if (sys->d3d_dev.d3dcontext)
+ D3D11_ReleaseDevice(&sys->d3d_dev);
return VLC_EGENERIC;
}
@@ -613,6 +612,8 @@ static void D3D11CloseAdjust(vlc_object_t *obj)
ID3D11VideoContext_Release(sys->d3dvidctx);
ID3D11VideoDevice_Release(sys->d3dviddev);
+ D3D11_ReleaseDevice(&sys->d3d_dev);
+
free(sys);
}
diff --git a/modules/hw/d3d11/d3d11_surface.c b/modules/hw/d3d11/d3d11_surface.c
index 8acd61814a..b946c3acbb 100644
--- a/modules/hw/d3d11/d3d11_surface.c
+++ b/modules/hw/d3d11/d3d11_surface.c
@@ -70,6 +70,7 @@ struct filter_sys_t {
ID3D11VideoProcessorEnumerator *procEnumerator;
ID3D11VideoProcessor *videoProcessor;
#endif
+ d3d11_device_t d3d_dev;
/* CPU to GPU */
filter_t *filter;
@@ -698,6 +699,8 @@ int D3D11OpenCPUConverter( vlc_object_t *obj )
return VLC_EGENERIC;
}
+ d3d11_device_t d3d_dev;
+ D3D11_TEXTURE2D_DESC texDesc;
picture_t *peek = filter_NewPicture(p_filter);
if (peek == NULL)
return VLC_EGENERIC;
@@ -710,7 +713,6 @@ int D3D11OpenCPUConverter( vlc_object_t *obj )
video_format_Init(&fmt_staging, 0);
- D3D11_TEXTURE2D_DESC texDesc;
ID3D11Texture2D_GetDesc( peek->p_sys->texture[KNOWN_DXGI_INDEX], &texDesc);
vlc_fourcc_t d3d_fourcc = DxgiFormatFourcc(texDesc.Format);
if (d3d_fourcc == 0)
@@ -723,7 +725,7 @@ int D3D11OpenCPUConverter( vlc_object_t *obj )
err = VLC_ENOMEM;
goto done;
}
- res.p_sys->context = peek->p_sys->context;
+ res.p_sys->context = d3d_dev.d3dcontext = peek->p_sys->context;
res.p_sys->formatTexture = texDesc.Format;
video_format_Copy(&fmt_staging, &p_filter->fmt_out.video);
@@ -747,10 +749,8 @@ int D3D11OpenCPUConverter( vlc_object_t *obj )
texDesc.BindFlags = 0;
texDesc.Height = p_dst->format.i_height; /* make sure we match picture_Setup() */
- ID3D11Device *p_device;
- ID3D11DeviceContext_GetDevice(peek->p_sys->context, &p_device);
- HRESULT hr = ID3D11Device_CreateTexture2D( p_device, &texDesc, NULL, &texture);
- ID3D11Device_Release(p_device);
+ ID3D11DeviceContext_GetDevice(peek->p_sys->context, &d3d_dev.d3ddevice);
+ HRESULT hr = ID3D11Device_CreateTexture2D( d3d_dev.d3ddevice, &texDesc, NULL, &texture);
if (FAILED(hr)) {
msg_Err(p_filter, "Failed to create a %s staging texture to extract surface pixels (hr=0x%0lx)", DxgiFormatToStr(texDesc.Format), hr );
goto done;
@@ -792,8 +792,13 @@ done:
DeleteFilter( p_cpu_filter );
if (texture)
ID3D11Texture2D_Release(texture);
+ D3D11_ReleaseDevice(&d3d_dev);
free(p_sys);
}
+ else
+ {
+ p_sys->d3d_dev = d3d_dev;
+ }
return err;
}
@@ -815,6 +820,7 @@ 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);
D3D11_Destroy(&p_sys->hd3d);
free( p_sys );
p_filter->p_sys = NULL;
--
2.14.2
More information about the vlc-devel
mailing list