[vlc-commits] hw:d3d11: add a file to control the D3D11 device common to all filters
Steve Lhomme
git at videolan.org
Thu Nov 23 10:16:59 CET 2017
vlc | branch: master | Steve Lhomme <robUx4 at videolabs.io> | Wed Nov 22 18:18:32 2017 +0100| [8d73a6794f27a50098e3f7b90a3283045fa556cd] | committer: Jean-Baptiste Kempf
hw:d3d11: add a file to control the D3D11 device common to all filters
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=8d73a6794f27a50098e3f7b90a3283045fa556cd
---
modules/hw/d3d11/Makefile.am | 3 +-
modules/hw/d3d11/d3d11_filters.h | 5 ++
modules/hw/d3d11/d3d11_instance.c | 106 ++++++++++++++++++++++++++++++++++++++
3 files changed, 113 insertions(+), 1 deletion(-)
diff --git a/modules/hw/d3d11/Makefile.am b/modules/hw/d3d11/Makefile.am
index 4bca091326..33d17efd8f 100644
--- a/modules/hw/d3d11/Makefile.am
+++ b/modules/hw/d3d11/Makefile.am
@@ -3,7 +3,8 @@ d3d11dir = $(pluginsdir)/d3d11
libdirect3d11_filters_plugin_la_SOURCES = hw/d3d11/d3d11_filters.h \
hw/d3d11/d3d11_filters.c \
hw/d3d11/d3d11_deinterlace.c \
- hw/d3d11/d3d11_surface.c
+ hw/d3d11/d3d11_surface.c \
+ hw/d3d11/d3d11_instance.c
libdirect3d11_filters_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(d3d11dir)'
libdirect3d11_filters_plugin_la_LIBADD = libchroma_copy.la libdeinterlace_common.la libd3d11_common.la
if HAVE_WINSTORE
diff --git a/modules/hw/d3d11/d3d11_filters.h b/modules/hw/d3d11/d3d11_filters.h
index 10f1076ea7..c4433937f9 100644
--- a/modules/hw/d3d11/d3d11_filters.h
+++ b/modules/hw/d3d11/d3d11_filters.h
@@ -25,6 +25,8 @@
#include <vlc_common.h>
+#include "../../video_chroma/d3d11_fmt.h"
+
int D3D11OpenDeinterlace(vlc_object_t *);
void D3D11CloseDeinterlace(vlc_object_t *);
int D3D11OpenConverter(vlc_object_t *);
@@ -32,4 +34,7 @@ void D3D11CloseConverter(vlc_object_t *);
int D3D11OpenCPUConverter(vlc_object_t *);
void D3D11CloseCPUConverter(vlc_object_t *);
+void D3D11_FilterHoldInstance(filter_t *, d3d11_device_t *, D3D11_TEXTURE2D_DESC *);
+void D3D11_FilterReleaseInstance(d3d11_device_t *);
+
#endif /* VLC_D3D11_FILTERS_H */
diff --git a/modules/hw/d3d11/d3d11_instance.c b/modules/hw/d3d11/d3d11_instance.c
new file mode 100644
index 0000000000..1011de4d84
--- /dev/null
+++ b/modules/hw/d3d11/d3d11_instance.c
@@ -0,0 +1,106 @@
+/*****************************************************************************
+ * d3d11_instance.c: D3D11 unique device context instance
+ *****************************************************************************
+ * Copyright © 2017 VLC authors, VideoLAN and VideoLabs
+ *
+ * Authors: Steve Lhomme <robux4 at gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_filter.h>
+#include <vlc_picture.h>
+
+#include <assert.h>
+
+#define COBJMACROS
+#include <d3d11.h>
+
+#include "d3d11_filters.h"
+
+static vlc_mutex_t inst_lock = VLC_STATIC_MUTEX;
+static d3d11_device_t device = { .d3dcontext = NULL };
+static size_t instances = 0;
+
+void D3D11_FilterHoldInstance(filter_t *filter, d3d11_device_t *out, D3D11_TEXTURE2D_DESC *dstDesc)
+{
+ picture_t *pic = filter_NewPicture(filter);
+ if (!pic)
+ {
+ out->d3dcontext = NULL;
+ return;
+ }
+
+ picture_sys_t *p_sys = ActivePictureSys(pic);
+
+ vlc_mutex_lock(&inst_lock);
+ if (p_sys)
+ {
+ out->d3dcontext = p_sys->context;
+ ID3D11DeviceContext_GetDevice(out->d3dcontext, &out->d3ddevice);
+ ID3D11Device_Release(out->d3ddevice);
+ if (device.d3dcontext == NULL)
+ {
+ device = *out;
+ instances++;
+ }
+
+ ID3D11Texture2D_GetDesc(p_sys->texture[KNOWN_DXGI_INDEX], dstDesc);
+ }
+ else
+ {
+ *out = device;
+ if (device.d3dcontext != NULL)
+ instances++;
+
+ memset(dstDesc, 0, sizeof(*dstDesc));
+ if (filter->fmt_in.video.i_chroma == VLC_CODEC_D3D11_OPAQUE_10B)
+ dstDesc->Format = DXGI_FORMAT_P010;
+ else
+ dstDesc->Format = DXGI_FORMAT_NV12;
+ dstDesc->Width = filter->fmt_out.video.i_width;
+ dstDesc->Height = filter->fmt_out.video.i_height;
+ }
+
+ out->owner = false;
+ if (unlikely(out->d3dcontext == NULL))
+ msg_Warn(filter, "no context available");
+ else
+ {
+ ID3D11DeviceContext_AddRef(out->d3dcontext);
+ ID3D11Device_AddRef(out->d3ddevice);
+ }
+
+ vlc_mutex_unlock(&inst_lock);
+
+ picture_Release(pic);
+}
+
+void D3D11_FilterReleaseInstance(d3d11_device_t *d3d_dev)
+{
+ vlc_mutex_lock(&inst_lock);
+ if (d3d_dev->d3dcontext && d3d_dev->d3dcontext == device.d3dcontext)
+ {
+ assert(instances != 0);
+ if (--instances == 0)
+ device.d3dcontext = NULL;
+ }
+ D3D11_ReleaseDevice(d3d_dev);
+ vlc_mutex_unlock(&inst_lock);
+}
More information about the vlc-commits
mailing list