[vlc-commits] d3d11: factorize code to check if a format supports some features

Steve Lhomme git at videolan.org
Tue May 2 10:13:43 CEST 2017


vlc | branch: master | Steve Lhomme <robux4 at videolabs.io> | Fri Apr 28 17:46:20 2017 +0200| [ad95425272d2a8728c3e3130b18f26506c4f241b] | committer: Jean-Baptiste Kempf

d3d11: factorize code to check if a format supports some features

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

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

 modules/codec/avcodec/d3d11va.c         | 26 +++++++++-----------------
 modules/video_chroma/dxgi_fmt.h         |  8 ++++++++
 modules/video_output/win32/direct3d11.c | 15 +++++----------
 3 files changed, 22 insertions(+), 27 deletions(-)

diff --git a/modules/codec/avcodec/d3d11va.c b/modules/codec/avcodec/d3d11va.c
index 94f5bc68d2..e6ee332f11 100644
--- a/modules/codec/avcodec/d3d11va.c
+++ b/modules/codec/avcodec/d3d11va.c
@@ -834,15 +834,11 @@ static bool SetupProcessor(vlc_va_t *va, const video_format_t *fmt)
     {
         // check if we can create render texture of that format
         // check the decoder can output to that format
-        const UINT i_quadSupportFlags = D3D11_FORMAT_SUPPORT_TEXTURE2D | D3D11_FORMAT_SUPPORT_SHADER_LOAD;
         for (const d3d_format_t *output = GetRenderFormatList();
              output->name != NULL; ++output)
         {
-            UINT i_formatSupport;
-            if( SUCCEEDED( ID3D11Device_CheckFormatSupport((ID3D11Device*) dx_sys->d3ddev,
-                                                           output->formatTexture,
-                                                           &i_formatSupport)) &&
-                    ( i_formatSupport & i_quadSupportFlags ) == i_quadSupportFlags )
+            if( DeviceSupportsFormat((ID3D11Device*) dx_sys->d3ddev, output->formatTexture,
+                                     D3D11_FORMAT_SUPPORT_TEXTURE2D | D3D11_FORMAT_SUPPORT_SHADER_LOAD))
             {
                 msg_Dbg(va, "Render pixel format %s supported", DxgiFormatToStr(output->formatTexture) );
 
@@ -923,18 +919,14 @@ static int DxSetupOutput(vlc_va_t *va, const GUID *input, const video_format_t *
             continue;
         }
 
-        // check if we can create render texture of that format
-        // check the decoder can output to that format
-        const UINT i_quadSupportFlags = D3D11_FORMAT_SUPPORT_TEXTURE2D | D3D11_FORMAT_SUPPORT_SHADER_LOAD;
-        UINT i_formatSupport;
-        if( SUCCEEDED( ID3D11Device_CheckFormatSupport((ID3D11Device*) dx_sys->d3ddev,
-                                                       processorInput[idx],
-                                                       &i_formatSupport)) &&
-                ( i_formatSupport & i_quadSupportFlags ) != i_quadSupportFlags )
-        {
-            msg_Dbg(va, "Format %s needs a processor", DxgiFormatToStr(processorInput[idx]));
+       // check if we can create render texture of that format
+       // check the decoder can output to that format
+       if ( !DeviceSupportsFormat((ID3D11Device*) dx_sys->d3ddev, processorInput[idx],
+                                  D3D11_FORMAT_SUPPORT_SHADER_LOAD) )
+       {
+           msg_Dbg(va, "Format %s needs a processor", DxgiFormatToStr(processorInput[idx]));
 #ifdef ID3D11VideoContext_VideoProcessorBlt
-            if (!SetupProcessor( va, fmt ))
+           if (!SetupProcessor( va, fmt ))
                 continue;
             msg_Dbg(va, "Using processor %s to %s", DxgiFormatToStr(processorInput[idx]), DxgiFormatToStr(va->sys->processorFormat));
 #else
diff --git a/modules/video_chroma/dxgi_fmt.h b/modules/video_chroma/dxgi_fmt.h
index dd4abfbfdd..343154e8ab 100644
--- a/modules/video_chroma/dxgi_fmt.h
+++ b/modules/video_chroma/dxgi_fmt.h
@@ -51,4 +51,12 @@ typedef struct ID3D11Device ID3D11Device;
 bool isXboxHardware(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;
+}
 #endif /* include-guard */
diff --git a/modules/video_output/win32/direct3d11.c b/modules/video_output/win32/direct3d11.c
index d41e1a02e5..22f350fd19 100644
--- a/modules/video_output/win32/direct3d11.c
+++ b/modules/video_output/win32/direct3d11.c
@@ -578,12 +578,11 @@ static const d3d_format_t *GetOutputFormat(vout_display_t *vd, vlc_fourcc_t i_sr
                                            bool blendable)
 {
     vout_display_sys_t *sys = vd->sys;
-    UINT i_formatSupport;
-    UINT i_quadSupportFlags = D3D11_FORMAT_SUPPORT_TEXTURE2D | D3D11_FORMAT_SUPPORT_SHADER_LOAD;
+    UINT supportFlags = D3D11_FORMAT_SUPPORT_TEXTURE2D | D3D11_FORMAT_SUPPORT_SHADER_LOAD;
     if (blendable)
-        i_quadSupportFlags |= D3D11_FORMAT_SUPPORT_BLENDABLE;
+        supportFlags |= D3D11_FORMAT_SUPPORT_BLENDABLE;
     if (b_allow_opaque && is_d3d11_opaque(i_src_chroma))
-        i_quadSupportFlags |= D3D11_FORMAT_SUPPORT_DECODER_OUTPUT;
+        supportFlags |= D3D11_FORMAT_SUPPORT_DECODER_OUTPUT;
 
     for (const d3d_format_t *output_format = GetRenderFormatList();
          output_format->name != NULL; ++output_format)
@@ -595,13 +594,9 @@ static const d3d_format_t *GetOutputFormat(vout_display_t *vd, vlc_fourcc_t i_sr
         if (!b_allow_opaque && is_d3d11_opaque(output_format->fourcc))
             continue;
 
-        if( SUCCEEDED( ID3D11Device_CheckFormatSupport(sys->d3ddevice,
-                                                       output_format->formatTexture,
-                                                       &i_formatSupport)) &&
-                ( i_formatSupport & i_quadSupportFlags ) == i_quadSupportFlags )
-        {
+        if( DeviceSupportsFormat( sys->d3ddevice, output_format->formatTexture,
+                                  supportFlags ) )
             return output_format;
-        }
     }
     return NULL;
 }



More information about the vlc-commits mailing list