direct3d11: move the common code in C file rather than inline and use a static lib
authorSteve Lhomme <robUx4@videolabs.io>
Thu, 16 Nov 2017 10:38:48 +0000 (11:38 +0100)
committerJean-Baptiste Kempf <jb@videolan.org>
Thu, 16 Nov 2017 11:34:39 +0000 (12:34 +0100)
Also move some code from dxgi_fmt to d3d11_fmt

Signed-off-by: Jean-Baptiste Kempf <jb@videolan.org>
modules/codec/Makefile.am
modules/video_chroma/Makefile.am
modules/video_chroma/d3d11_fmt.c [new file with mode: 0644]
modules/video_chroma/d3d11_fmt.h
modules/video_chroma/d3d11_surface.c
modules/video_chroma/dxgi_fmt.c
modules/video_chroma/dxgi_fmt.h
modules/video_output/Makefile.am

index 5f4f477..20899d8 100644 (file)
@@ -428,13 +428,19 @@ 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
+if HAVE_WIN32
+noinst_LTLIBRARIES += libd3d11_common.la
+endif
+
 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
index 500ca6c..27b472f 100644 (file)
@@ -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 (file)
index 0000000..2847474
--- /dev/null
@@ -0,0 +1,286 @@
+/*****************************************************************************
+ * d3d11_fmt.c : D3D11 helper calls
+ *****************************************************************************
+ * Copyright © 2017 VLC authors, VideoLAN and VideoLabs
+ *
+ * Authors: Steve Lhomme <robux4@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;
+}
index a41a9c0..ee66ca6 100644 (file)
 #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 */
index f6b98f7..aeb5f43 100644 (file)
@@ -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
index 7e1b60c..29bd446 100644 (file)
@@ -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;
-}
index 8e8cdb5..4961cd4 100644 (file)
@@ -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 */
index 786d6e3..279d4a5 100644 (file)
@@ -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