[vlc-devel] [PATCH 02/11] direct3d11: move the common code in C file rather than inline and use a static lib
Steve Lhomme
robux4 at videolabs.io
Thu Nov 16 11:38:48 CET 2017
Also move some code from dxgi_fmt to d3d11_fmt
--
replaces https://patches.videolan.org/patch/18680/
- remove duplicates
---
modules/codec/Makefile.am | 8 +-
modules/video_chroma/Makefile.am | 5 +-
modules/video_chroma/d3d11_fmt.c | 286 +++++++++++++++++++++++++++++++++++
modules/video_chroma/d3d11_fmt.h | 181 +++-------------------
modules/video_chroma/d3d11_surface.c | 3 +-
modules/video_chroma/dxgi_fmt.c | 52 -------
modules/video_chroma/dxgi_fmt.h | 52 +------
modules/video_output/Makefile.am | 15 +-
8 files changed, 329 insertions(+), 273 deletions(-)
create mode 100644 modules/video_chroma/d3d11_fmt.c
diff --git a/modules/codec/Makefile.am b/modules/codec/Makefile.am
index 5f4f477bbf..f41985d27c 100644
--- a/modules/codec/Makefile.am
+++ b/modules/codec/Makefile.am
@@ -428,13 +428,17 @@ if HAVE_AVCODEC_DXVA2
codec_LTLIBRARIES += libdxva2_plugin.la
endif
+libd3d11_common_la_SOURCES = video_chroma/d3d11_fmt.c video_chroma/d3d11_fmt.h \
+ video_chroma/dxgi_fmt.c video_chroma/dxgi_fmt.h
+libd3d11_common_la_LDFLAGS = -static
+noinst_LTLIBRARIES += libd3d11_common.la
+
libd3d11va_plugin_la_SOURCES = \
codec/avcodec/d3d11va.c codec/avcodec/directx_va.c codec/avcodec/directx_va.h \
codec/avcodec/va_surface.c codec/avcodec/va_surface.h codec/avcodec/va_surface_internal.h \
- video_chroma/d3d11_fmt.h video_chroma/dxgi_fmt.c video_chroma/dxgi_fmt.h \
packetizer/h264_nal.c packetizer/h264_nal.h \
packetizer/hevc_nal.c packetizer/hevc_nal.h
-libd3d11va_plugin_la_LIBADD = $(LIBCOM) -luuid
+libd3d11va_plugin_la_LIBADD = libd3d11_common.la $(LIBCOM) -luuid
if HAVE_WINSTORE
libd3d11va_plugin_la_LIBADD += -ld3d11
endif
diff --git a/modules/video_chroma/Makefile.am b/modules/video_chroma/Makefile.am
index 500ca6c497..27b472f363 100644
--- a/modules/video_chroma/Makefile.am
+++ b/modules/video_chroma/Makefile.am
@@ -128,9 +128,8 @@ chroma_LTLIBRARIES += \
endif
# D3D11VA
-libd3d11_surface_plugin_la_SOURCES = video_chroma/d3d11_surface.c \
- video_chroma/d3d11_fmt.h video_chroma/dxgi_fmt.c video_chroma/dxgi_fmt.h
-libd3d11_surface_plugin_la_LIBADD = libchroma_copy.la
+libd3d11_surface_plugin_la_SOURCES = video_chroma/d3d11_surface.c
+libd3d11_surface_plugin_la_LIBADD = libchroma_copy.la libd3d11_common.la
if HAVE_AVCODEC_D3D11VA
chroma_LTLIBRARIES += \
diff --git a/modules/video_chroma/d3d11_fmt.c b/modules/video_chroma/d3d11_fmt.c
new file mode 100644
index 0000000000..2847474c4f
--- /dev/null
+++ b/modules/video_chroma/d3d11_fmt.c
@@ -0,0 +1,286 @@
+/*****************************************************************************
+ * d3d11_fmt.c : D3D11 helper calls
+ *****************************************************************************
+ * 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_common.h>
+#include <vlc_picture.h>
+
+#define COBJMACROS
+#include <d3d11.h>
+#include <assert.h>
+
+#include "d3d11_fmt.h"
+
+#include "../codec/avcodec/va_surface.h"
+
+picture_sys_t *ActivePictureSys(picture_t *p_pic)
+{
+ struct va_pic_context *pic_ctx = (struct va_pic_context*)p_pic->context;
+ return pic_ctx ? &pic_ctx->picsys : p_pic->p_sys;
+}
+
+void AcquirePictureSys(picture_sys_t *p_sys)
+{
+ for (int i=0; i<D3D11_MAX_SHADER_VIEW; i++) {
+ if (p_sys->resourceView[i])
+ ID3D11ShaderResourceView_AddRef(p_sys->resourceView[i]);
+ if (p_sys->texture[i])
+ ID3D11Texture2D_AddRef(p_sys->texture[i]);
+ }
+ if (p_sys->context)
+ ID3D11DeviceContext_AddRef(p_sys->context);
+ if (p_sys->decoder)
+ ID3D11VideoDecoderOutputView_AddRef(p_sys->decoder);
+ if (p_sys->processorInput)
+ ID3D11VideoProcessorInputView_AddRef(p_sys->processorInput);
+ if (p_sys->processorOutput)
+ ID3D11VideoProcessorOutputView_AddRef(p_sys->processorOutput);
+}
+
+void ReleasePictureSys(picture_sys_t *p_sys)
+{
+ for (int i=0; i<D3D11_MAX_SHADER_VIEW; i++) {
+ if (p_sys->resourceView[i])
+ ID3D11ShaderResourceView_Release(p_sys->resourceView[i]);
+ if (p_sys->texture[i])
+ ID3D11Texture2D_Release(p_sys->texture[i]);
+ }
+ if (p_sys->context)
+ ID3D11DeviceContext_Release(p_sys->context);
+ if (p_sys->decoder)
+ ID3D11VideoDecoderOutputView_Release(p_sys->decoder);
+ if (p_sys->processorInput)
+ ID3D11VideoProcessorInputView_Release(p_sys->processorInput);
+ if (p_sys->processorOutput)
+ ID3D11VideoProcessorOutputView_Release(p_sys->processorOutput);
+}
+
+/* map texture planes to resource views */
+int AllocateShaderView(vlc_object_t *obj, ID3D11Device *d3ddevice,
+ const d3d_format_t *format,
+ ID3D11Texture2D *p_texture[D3D11_MAX_SHADER_VIEW], UINT slice_index,
+ ID3D11ShaderResourceView *resourceView[D3D11_MAX_SHADER_VIEW])
+{
+ HRESULT hr;
+ int i;
+ D3D11_SHADER_RESOURCE_VIEW_DESC resviewDesc = { 0 };
+ D3D11_TEXTURE2D_DESC texDesc;
+ ID3D11Texture2D_GetDesc(p_texture[0], &texDesc);
+ assert(texDesc.BindFlags & D3D11_BIND_SHADER_RESOURCE);
+
+ if (texDesc.ArraySize == 1)
+ {
+ resviewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
+ resviewDesc.Texture2D.MipLevels = 1;
+ }
+ else
+ {
+ resviewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY;
+ resviewDesc.Texture2DArray.MipLevels = -1;
+ resviewDesc.Texture2DArray.ArraySize = 1;
+ resviewDesc.Texture2DArray.FirstArraySlice = slice_index;
+ }
+ for (i=0; i<D3D11_MAX_SHADER_VIEW; i++)
+ {
+ resviewDesc.Format = format->resourceFormat[i];
+ if (resviewDesc.Format == DXGI_FORMAT_UNKNOWN)
+ resourceView[i] = NULL;
+ else
+ {
+ hr = ID3D11Device_CreateShaderResourceView(d3ddevice, (ID3D11Resource*)p_texture[i], &resviewDesc, &resourceView[i]);
+ if (FAILED(hr)) {
+ msg_Err(obj, "Could not Create the Texture ResourceView %d slice %d. (hr=0x%lX)", i, slice_index, hr);
+ break;
+ }
+ }
+ }
+
+ if (i != D3D11_MAX_SHADER_VIEW)
+ {
+ while (--i >= 0)
+ {
+ ID3D11ShaderResourceView_Release(resourceView[i]);
+ resourceView[i] = NULL;
+ }
+ return VLC_EGENERIC;
+ }
+
+ return VLC_SUCCESS;
+}
+
+HRESULT D3D11_CreateDevice(vlc_object_t *obj, HINSTANCE hdecoder_dll,
+ bool hw_decoding,
+ ID3D11Device **pp_d3ddevice,
+ ID3D11DeviceContext **pp_d3dcontext)
+{
+#if !VLC_WINSTORE_APP
+# define D3D11CreateDevice(args...) pf_CreateDevice(args)
+ /* */
+ PFN_D3D11_CREATE_DEVICE pf_CreateDevice;
+ pf_CreateDevice = (void *)GetProcAddress(hdecoder_dll, "D3D11CreateDevice");
+ if (!pf_CreateDevice) {
+ msg_Err(obj, "Cannot locate reference to D3D11CreateDevice ABI in DLL");
+ return E_NOINTERFACE;
+ }
+#endif
+
+ HRESULT hr = E_NOTIMPL;
+ UINT creationFlags = 0;
+
+ if (hw_decoding)
+ creationFlags |= D3D11_CREATE_DEVICE_VIDEO_SUPPORT;
+
+#if !defined(NDEBUG)
+# if !VLC_WINSTORE_APP
+ if (IsDebuggerPresent())
+# endif
+ {
+ HINSTANCE sdklayer_dll = LoadLibrary(TEXT("d3d11_1sdklayers.dll"));
+ if (sdklayer_dll) {
+ creationFlags |= D3D11_CREATE_DEVICE_DEBUG;
+ FreeLibrary(sdklayer_dll);
+ }
+ }
+#endif
+
+ static const D3D_DRIVER_TYPE driverAttempts[] = {
+ D3D_DRIVER_TYPE_HARDWARE,
+#if 0 /* ifndef NDEBUG */
+ D3D_DRIVER_TYPE_REFERENCE,
+#endif
+ };
+
+ static D3D_FEATURE_LEVEL D3D11_features[] = {
+ D3D_FEATURE_LEVEL_11_1, D3D_FEATURE_LEVEL_11_0,
+ D3D_FEATURE_LEVEL_10_1, D3D_FEATURE_LEVEL_10_0,
+ D3D_FEATURE_LEVEL_9_3, D3D_FEATURE_LEVEL_9_2, D3D_FEATURE_LEVEL_9_1
+ };
+
+ for (UINT driver = 0; driver < ARRAY_SIZE(driverAttempts); driver++) {
+ D3D_FEATURE_LEVEL i_feature_level;
+ hr = D3D11CreateDevice(NULL, driverAttempts[driver], NULL, creationFlags,
+ D3D11_features, ARRAY_SIZE(D3D11_features), D3D11_SDK_VERSION,
+ pp_d3ddevice, &i_feature_level, pp_d3dcontext);
+ if (SUCCEEDED(hr)) {
+#ifndef NDEBUG
+ msg_Dbg(obj, "Created the D3D11 device 0x%p ctx 0x%p type %d level %x.",
+ (void *)*pp_d3ddevice, (void *)*pp_d3dcontext,
+ driverAttempts[driver], i_feature_level);
+#endif
+ /* we can work with legacy levels but only if forced */
+ if ( obj->obj.force || i_feature_level >= D3D_FEATURE_LEVEL_11_0 )
+ break;
+ msg_Dbg(obj, "Incompatible feature level %x", i_feature_level);
+ ID3D11DeviceContext_Release(*pp_d3dcontext);
+ *pp_d3dcontext = NULL;
+ ID3D11Device_Release(*pp_d3ddevice);
+ *pp_d3ddevice = NULL;
+ hr = E_NOTIMPL;
+ }
+ }
+ return hr;
+}
+
+IDXGIAdapter *D3D11DeviceAdapter(ID3D11Device *d3ddev)
+{
+ IDXGIDevice *pDXGIDevice = NULL;
+ HRESULT hr = ID3D11Device_QueryInterface(d3ddev, &IID_IDXGIDevice, (void **)&pDXGIDevice);
+ if (FAILED(hr)) {
+ return NULL;
+ }
+
+ IDXGIAdapter *p_adapter;
+ hr = IDXGIDevice_GetAdapter(pDXGIDevice, &p_adapter);
+ IDXGIDevice_Release(pDXGIDevice);
+ if (FAILED(hr)) {
+ return NULL;
+ }
+ return p_adapter;
+}
+
+bool isXboxHardware(ID3D11Device *d3ddev)
+{
+ IDXGIAdapter *p_adapter = D3D11DeviceAdapter(d3ddev);
+ if (!p_adapter)
+ return NULL;
+
+ bool result = false;
+ DXGI_ADAPTER_DESC adapterDesc;
+ if (SUCCEEDED(IDXGIAdapter_GetDesc(p_adapter, &adapterDesc))) {
+ if (adapterDesc.VendorId == 0 &&
+ adapterDesc.DeviceId == 0 &&
+ !wcscmp(L"ROOT\\SraKmd\\0000", adapterDesc.Description))
+ result = true;
+ }
+
+ IDXGIAdapter_Release(p_adapter);
+ return result;
+}
+
+bool isNvidiaHardware(ID3D11Device *d3ddev)
+{
+ IDXGIAdapter *p_adapter = D3D11DeviceAdapter(d3ddev);
+ if (!p_adapter)
+ return NULL;
+
+ bool result = false;
+ DXGI_ADAPTER_DESC adapterDesc;
+ if (SUCCEEDED(IDXGIAdapter_GetDesc(p_adapter, &adapterDesc))) {
+ result = adapterDesc.VendorId == 0x10DE;
+ }
+
+ IDXGIAdapter_Release(p_adapter);
+ return result;
+}
+
+const d3d_format_t *FindD3D11Format(ID3D11Device *d3ddevice,
+ vlc_fourcc_t i_src_chroma,
+ uint8_t bits_per_channel,
+ bool allow_opaque,
+ UINT supportFlags)
+{
+ supportFlags |= D3D11_FORMAT_SUPPORT_TEXTURE2D;
+ for (const d3d_format_t *output_format = GetRenderFormatList();
+ output_format->name != NULL; ++output_format)
+ {
+ if (i_src_chroma && i_src_chroma != output_format->fourcc)
+ continue;
+ if (bits_per_channel && bits_per_channel > output_format->bitsPerChannel)
+ continue;
+ if (!allow_opaque && (output_format->fourcc == VLC_CODEC_D3D11_OPAQUE ||
+ output_format->fourcc == VLC_CODEC_D3D11_OPAQUE_10B))
+ continue;
+
+ DXGI_FORMAT textureFormat;
+ if (output_format->formatTexture == DXGI_FORMAT_UNKNOWN)
+ textureFormat = output_format->resourceFormat[0];
+ else
+ textureFormat = output_format->formatTexture;
+
+ if( DeviceSupportsFormat( d3ddevice, textureFormat, supportFlags ) )
+ return output_format;
+ }
+ return NULL;
+}
diff --git a/modules/video_chroma/d3d11_fmt.h b/modules/video_chroma/d3d11_fmt.h
index a41a9c0631..ee66ca6222 100644
--- a/modules/video_chroma/d3d11_fmt.h
+++ b/modules/video_chroma/d3d11_fmt.h
@@ -23,10 +23,7 @@
#ifndef VLC_VIDEOCHROMA_D3D11_FMT_H_
#define VLC_VIDEOCHROMA_D3D11_FMT_H_
-#include <vlc_picture.h>
-
#include <d3d11.h>
-#include <assert.h>
#include "dxgi_fmt.h"
@@ -50,176 +47,44 @@ struct picture_sys_t
#include "../codec/avcodec/va_surface.h"
-static inline picture_sys_t *ActivePictureSys(picture_t *p_pic)
-{
- struct va_pic_context *pic_ctx = (struct va_pic_context*)p_pic->context;
- return pic_ctx ? &pic_ctx->picsys : p_pic->p_sys;
-}
+picture_sys_t *ActivePictureSys(picture_t *p_pic);
/* index to use for texture/resource that use a known DXGI format
* (ie not DXGI_FORMAT_UNKNWON) */
#define KNOWN_DXGI_INDEX 0
-static inline void AcquirePictureSys(picture_sys_t *p_sys)
-{
- for (int i=0; i<D3D11_MAX_SHADER_VIEW; i++) {
- if (p_sys->resourceView[i])
- ID3D11ShaderResourceView_AddRef(p_sys->resourceView[i]);
- if (p_sys->texture[i])
- ID3D11Texture2D_AddRef(p_sys->texture[i]);
- }
- if (p_sys->context)
- ID3D11DeviceContext_AddRef(p_sys->context);
- if (p_sys->decoder)
- ID3D11VideoDecoderOutputView_AddRef(p_sys->decoder);
- if (p_sys->processorInput)
- ID3D11VideoProcessorInputView_AddRef(p_sys->processorInput);
- if (p_sys->processorOutput)
- ID3D11VideoProcessorOutputView_AddRef(p_sys->processorOutput);
-}
+void AcquirePictureSys(picture_sys_t *p_sys);
-static inline void ReleasePictureSys(picture_sys_t *p_sys)
-{
- for (int i=0; i<D3D11_MAX_SHADER_VIEW; i++) {
- if (p_sys->resourceView[i])
- ID3D11ShaderResourceView_Release(p_sys->resourceView[i]);
- if (p_sys->texture[i])
- ID3D11Texture2D_Release(p_sys->texture[i]);
- }
- if (p_sys->context)
- ID3D11DeviceContext_Release(p_sys->context);
- if (p_sys->decoder)
- ID3D11VideoDecoderOutputView_Release(p_sys->decoder);
- if (p_sys->processorInput)
- ID3D11VideoProcessorInputView_Release(p_sys->processorInput);
- if (p_sys->processorOutput)
- ID3D11VideoProcessorOutputView_Release(p_sys->processorOutput);
-}
+void ReleasePictureSys(picture_sys_t *p_sys);
/* map texture planes to resource views */
-static inline int AllocateShaderView(vlc_object_t *obj, ID3D11Device *d3ddevice,
+int AllocateShaderView(vlc_object_t *obj, ID3D11Device *d3ddevice,
const d3d_format_t *format,
ID3D11Texture2D *p_texture[D3D11_MAX_SHADER_VIEW], UINT slice_index,
- ID3D11ShaderResourceView *resourceView[D3D11_MAX_SHADER_VIEW])
-{
- HRESULT hr;
- int i;
- D3D11_SHADER_RESOURCE_VIEW_DESC resviewDesc = { 0 };
- D3D11_TEXTURE2D_DESC texDesc;
- ID3D11Texture2D_GetDesc(p_texture[0], &texDesc);
- assert(texDesc.BindFlags & D3D11_BIND_SHADER_RESOURCE);
-
- if (texDesc.ArraySize == 1)
- {
- resviewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
- resviewDesc.Texture2D.MipLevels = 1;
- }
- else
- {
- resviewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY;
- resviewDesc.Texture2DArray.MipLevels = -1;
- resviewDesc.Texture2DArray.ArraySize = 1;
- resviewDesc.Texture2DArray.FirstArraySlice = slice_index;
- }
- for (i=0; i<D3D11_MAX_SHADER_VIEW; i++)
- {
- resviewDesc.Format = format->resourceFormat[i];
- if (resviewDesc.Format == DXGI_FORMAT_UNKNOWN)
- resourceView[i] = NULL;
- else
- {
- hr = ID3D11Device_CreateShaderResourceView(d3ddevice, (ID3D11Resource*)p_texture[i], &resviewDesc, &resourceView[i]);
- if (FAILED(hr)) {
- msg_Err(obj, "Could not Create the Texture ResourceView %d slice %d. (hr=0x%lX)", i, slice_index, hr);
- break;
- }
- }
- }
-
- if (i != D3D11_MAX_SHADER_VIEW)
- {
- while (--i >= 0)
- {
- ID3D11ShaderResourceView_Release(resourceView[i]);
- resourceView[i] = NULL;
- }
- return VLC_EGENERIC;
- }
-
- return VLC_SUCCESS;
-}
+ ID3D11ShaderResourceView *resourceView[D3D11_MAX_SHADER_VIEW]);
-static inline HRESULT D3D11_CreateDevice(vlc_object_t *obj, HINSTANCE hdecoder_dll,
+HRESULT D3D11_CreateDevice(vlc_object_t *obj, HINSTANCE hdecoder_dll,
bool hw_decoding,
ID3D11Device **pp_d3ddevice,
- ID3D11DeviceContext **pp_d3dcontext)
-{
-#if !VLC_WINSTORE_APP
-# define D3D11CreateDevice(args...) pf_CreateDevice(args)
- /* */
- PFN_D3D11_CREATE_DEVICE pf_CreateDevice;
- pf_CreateDevice = (void *)GetProcAddress(hdecoder_dll, "D3D11CreateDevice");
- if (!pf_CreateDevice) {
- msg_Err(obj, "Cannot locate reference to D3D11CreateDevice ABI in DLL");
- return E_NOINTERFACE;
- }
-#endif
-
- HRESULT hr = E_NOTIMPL;
- UINT creationFlags = 0;
-
- if (hw_decoding)
- creationFlags |= D3D11_CREATE_DEVICE_VIDEO_SUPPORT;
-
-#if !defined(NDEBUG)
-# if !VLC_WINSTORE_APP
- if (IsDebuggerPresent())
-# endif
- {
- HINSTANCE sdklayer_dll = LoadLibrary(TEXT("d3d11_1sdklayers.dll"));
- if (sdklayer_dll) {
- creationFlags |= D3D11_CREATE_DEVICE_DEBUG;
- FreeLibrary(sdklayer_dll);
- }
- }
-#endif
-
- static const D3D_DRIVER_TYPE driverAttempts[] = {
- D3D_DRIVER_TYPE_HARDWARE,
-#if 0 /* ifndef NDEBUG */
- D3D_DRIVER_TYPE_REFERENCE,
-#endif
- };
+ ID3D11DeviceContext **pp_d3dcontext);
- static D3D_FEATURE_LEVEL D3D11_features[] = {
- D3D_FEATURE_LEVEL_11_1, D3D_FEATURE_LEVEL_11_0,
- D3D_FEATURE_LEVEL_10_1, D3D_FEATURE_LEVEL_10_0,
- D3D_FEATURE_LEVEL_9_3, D3D_FEATURE_LEVEL_9_2, D3D_FEATURE_LEVEL_9_1
- };
+bool isXboxHardware(ID3D11Device *d3ddev);
+bool isNvidiaHardware(ID3D11Device *d3ddev);
+IDXGIAdapter *D3D11DeviceAdapter(ID3D11Device *d3ddev);
- for (UINT driver = 0; driver < ARRAY_SIZE(driverAttempts); driver++) {
- D3D_FEATURE_LEVEL i_feature_level;
- hr = D3D11CreateDevice(NULL, driverAttempts[driver], NULL, creationFlags,
- D3D11_features, ARRAY_SIZE(D3D11_features), D3D11_SDK_VERSION,
- pp_d3ddevice, &i_feature_level, pp_d3dcontext);
- if (SUCCEEDED(hr)) {
-#ifndef NDEBUG
- msg_Dbg(obj, "Created the D3D11 device 0x%p ctx 0x%p type %d level %x.",
- (void *)*pp_d3ddevice, (void *)*pp_d3dcontext,
- driverAttempts[driver], i_feature_level);
-#endif
- /* we can work with legacy levels but only if forced */
- if ( obj->obj.force || i_feature_level >= D3D_FEATURE_LEVEL_11_0 )
- break;
- msg_Dbg(obj, "Incompatible feature level %x", i_feature_level);
- ID3D11DeviceContext_Release(*pp_d3dcontext);
- *pp_d3dcontext = NULL;
- ID3D11Device_Release(*pp_d3ddevice);
- *pp_d3ddevice = NULL;
- hr = E_NOTIMPL;
- }
- }
- return hr;
+static inline bool DeviceSupportsFormat(ID3D11Device *d3ddevice,
+ DXGI_FORMAT format, UINT supportFlags)
+{
+ UINT i_formatSupport;
+ return SUCCEEDED( ID3D11Device_CheckFormatSupport(d3ddevice, format,
+ &i_formatSupport) )
+ && ( i_formatSupport & supportFlags ) == supportFlags;
}
+const d3d_format_t *FindD3D11Format(ID3D11Device *d3ddevice,
+ vlc_fourcc_t i_src_chroma,
+ uint8_t bits_per_channel,
+ bool allow_opaque,
+ UINT supportFlags);
+
#endif /* include-guard */
diff --git a/modules/video_chroma/d3d11_surface.c b/modules/video_chroma/d3d11_surface.c
index d2b5ad15e4..076dcd23e7 100644
--- a/modules/video_chroma/d3d11_surface.c
+++ b/modules/video_chroma/d3d11_surface.c
@@ -34,8 +34,9 @@
#include <vlc_picture.h>
#include <vlc_modules.h>
-#include "copy.h"
+#include <assert.h>
+#include "copy.h"
#include <windows.h>
#define COBJMACROS
diff --git a/modules/video_chroma/dxgi_fmt.c b/modules/video_chroma/dxgi_fmt.c
index 7e1b60cee0..29bd446769 100644
--- a/modules/video_chroma/dxgi_fmt.c
+++ b/modules/video_chroma/dxgi_fmt.c
@@ -128,55 +128,3 @@ void DxgiFormatMask(DXGI_FORMAT format, video_format_t *fmt)
fmt->i_bmask = 0xff000000;
}
}
-
-IDXGIAdapter *D3D11DeviceAdapter(ID3D11Device *d3ddev)
-{
- IDXGIDevice *pDXGIDevice = NULL;
- HRESULT hr = ID3D11Device_QueryInterface(d3ddev, &IID_IDXGIDevice, (void **)&pDXGIDevice);
- if (FAILED(hr)) {
- return NULL;
- }
-
- IDXGIAdapter *p_adapter;
- hr = IDXGIDevice_GetAdapter(pDXGIDevice, &p_adapter);
- IDXGIDevice_Release(pDXGIDevice);
- if (FAILED(hr)) {
- return NULL;
- }
- return p_adapter;
-}
-
-bool isXboxHardware(ID3D11Device *d3ddev)
-{
- IDXGIAdapter *p_adapter = D3D11DeviceAdapter(d3ddev);
- if (!p_adapter)
- return NULL;
-
- bool result = false;
- DXGI_ADAPTER_DESC adapterDesc;
- if (SUCCEEDED(IDXGIAdapter_GetDesc(p_adapter, &adapterDesc))) {
- if (adapterDesc.VendorId == 0 &&
- adapterDesc.DeviceId == 0 &&
- !wcscmp(L"ROOT\\SraKmd\\0000", adapterDesc.Description))
- result = true;
- }
-
- IDXGIAdapter_Release(p_adapter);
- return result;
-}
-
-bool isNvidiaHardware(ID3D11Device *d3ddev)
-{
- IDXGIAdapter *p_adapter = D3D11DeviceAdapter(d3ddev);
- if (!p_adapter)
- return NULL;
-
- bool result = false;
- DXGI_ADAPTER_DESC adapterDesc;
- if (SUCCEEDED(IDXGIAdapter_GetDesc(p_adapter, &adapterDesc))) {
- result = adapterDesc.VendorId == 0x10DE;
- }
-
- IDXGIAdapter_Release(p_adapter);
- return result;
-}
diff --git a/modules/video_chroma/dxgi_fmt.h b/modules/video_chroma/dxgi_fmt.h
index 8e8cdb5e5b..4961cd4a08 100644
--- a/modules/video_chroma/dxgi_fmt.h
+++ b/modules/video_chroma/dxgi_fmt.h
@@ -42,53 +42,9 @@ typedef struct
DXGI_FORMAT resourceFormat[D3D11_MAX_SHADER_VIEW];
} d3d_format_t;
-extern const char *DxgiFormatToStr(DXGI_FORMAT format);
-extern vlc_fourcc_t DxgiFormatFourcc(DXGI_FORMAT format);
-extern const d3d_format_t *GetRenderFormatList(void);
-extern void DxgiFormatMask(DXGI_FORMAT format, video_format_t *);
-
-typedef struct ID3D11Device ID3D11Device;
-bool isXboxHardware(ID3D11Device *d3ddev);
-bool isNvidiaHardware(ID3D11Device *d3ddev);
-IDXGIAdapter *D3D11DeviceAdapter(ID3D11Device *d3ddev);
-
-static inline bool DeviceSupportsFormat(ID3D11Device *d3ddevice,
- DXGI_FORMAT format, UINT supportFlags)
-{
- UINT i_formatSupport;
- return SUCCEEDED( ID3D11Device_CheckFormatSupport(d3ddevice, format,
- &i_formatSupport) )
- && ( i_formatSupport & supportFlags ) == supportFlags;
-}
-
-static inline const d3d_format_t *FindD3D11Format(ID3D11Device *d3ddevice,
- vlc_fourcc_t i_src_chroma,
- uint8_t bits_per_channel,
- bool allow_opaque,
- UINT supportFlags)
-{
- supportFlags |= D3D11_FORMAT_SUPPORT_TEXTURE2D;
- for (const d3d_format_t *output_format = GetRenderFormatList();
- output_format->name != NULL; ++output_format)
- {
- if (i_src_chroma && i_src_chroma != output_format->fourcc)
- continue;
- if (bits_per_channel && bits_per_channel > output_format->bitsPerChannel)
- continue;
- if (!allow_opaque && (output_format->fourcc == VLC_CODEC_D3D11_OPAQUE ||
- output_format->fourcc == VLC_CODEC_D3D11_OPAQUE_10B))
- continue;
-
- DXGI_FORMAT textureFormat;
- if (output_format->formatTexture == DXGI_FORMAT_UNKNOWN)
- textureFormat = output_format->resourceFormat[0];
- else
- textureFormat = output_format->formatTexture;
-
- if( DeviceSupportsFormat( d3ddevice, textureFormat, supportFlags ) )
- return output_format;
- }
- return NULL;
-}
+const char *DxgiFormatToStr(DXGI_FORMAT format);
+vlc_fourcc_t DxgiFormatFourcc(DXGI_FORMAT format);
+const d3d_format_t *GetRenderFormatList(void);
+void DxgiFormatMask(DXGI_FORMAT format, video_format_t *);
#endif /* include-guard */
diff --git a/modules/video_output/Makefile.am b/modules/video_output/Makefile.am
index 786d6e3261..279d4a5d87 100644
--- a/modules/video_output/Makefile.am
+++ b/modules/video_output/Makefile.am
@@ -263,8 +263,7 @@ libdirect3d9_deinterlace_plugin_la_SOURCES = video_output/win32/dxva2_deinterlac
video_chroma/d3d9_fmt.h
libdirect3d9_deinterlace_plugin_la_LIBADD = $(LIBCOM) libdeinterlace_common.la
libdirect3d9_deinterlace_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(voutdir)'
-libdirect3d9_adjust_plugin_la_SOURCES = video_output/win32/d3d9_adjust.c \
- video_chroma/dxgi_fmt.c video_chroma/dxgi_fmt.h
+libdirect3d9_adjust_plugin_la_SOURCES = video_output/win32/d3d9_adjust.c
libdirect3d9_adjust_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(voutdir)'
libdirect3d9_adjust_plugin_la_LIBADD = $(LIBCOM)
if HAVE_WIN32_DESKTOP
@@ -274,11 +273,10 @@ EXTRA_LTLIBRARIES += libdirect3d9_plugin.la libdirect3d9_deinterlace_plugin.la l
endif
libdirect3d11_plugin_la_SOURCES = video_output/win32/direct3d11.c \
- video_chroma/d3d11_fmt.h video_chroma/dxgi_fmt.c video_chroma/dxgi_fmt.h \
video_output/win32/common.c video_output/win32/common.h
libdirect3d11_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) \
-DMODULE_NAME_IS_direct3d11
-libdirect3d11_plugin_la_LIBADD = libchroma_copy.la $(LIBCOM) -luuid
+libdirect3d11_plugin_la_LIBADD = libchroma_copy.la libd3d11_common.la $(LIBCOM) -luuid
if !HAVE_WINSTORE
libdirect3d11_plugin_la_SOURCES += video_output/win32/events.c \
video_output/win32/events.h \
@@ -292,13 +290,12 @@ libdirect3d11_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(voutdir)'
vout_LTLIBRARIES += $(LTLIBdirect3d11)
EXTRA_LTLIBRARIES += libdirect3d11_plugin.la
-libdirect3d11_deinterlace_plugin_la_SOURCES = video_output/win32/d3d11_deinterlace.c \
- video_chroma/dxgi_fmt.c video_chroma/dxgi_fmt.h
+libdirect3d11_deinterlace_plugin_la_SOURCES = video_output/win32/d3d11_deinterlace.c
libdirect3d11_deinterlace_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(voutdir)'
-libdirect3d11_deinterlace_plugin_la_LIBADD = libdeinterlace_common.la
-libdirect3d11_adjust_plugin_la_SOURCES = video_output/win32/d3d11_adjust.c \
- video_chroma/dxgi_fmt.c video_chroma/dxgi_fmt.h
+libdirect3d11_deinterlace_plugin_la_LIBADD = libdeinterlace_common.la libd3d11_common.la
+libdirect3d11_adjust_plugin_la_SOURCES = video_output/win32/d3d11_adjust.c
libdirect3d11_adjust_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(voutdir)'
+libdirect3d11_adjust_plugin_la_LIBADD = libd3d11_common.la
video_filter_LTLIBRARIES += $(LTLIBdirect3d11_deinterlace) $(LTLIBdirect3d11_adjust)
EXTRA_LTLIBRARIES += libdirect3d11_deinterlace_plugin.la libdirect3d11_adjust_plugin.la
--
2.14.2
More information about the vlc-devel
mailing list