direct3d11: factorize code to check if a format supports some features
authorSteve Lhomme <robux4@videolabs.io>
Fri, 28 Apr 2017 15:46:20 +0000 (17:46 +0200)
committerJean-Baptiste Kempf <jb@videolan.org>
Tue, 2 May 2017 08:15:45 +0000 (10:15 +0200)
Signed-off-by: Jean-Baptiste Kempf <jb@videolan.org>
modules/codec/avcodec/d3d11va.c
modules/video_chroma/dxgi_fmt.h
modules/video_output/win32/direct3d11.c

index 94f5bc6..e6ee332 100644 (file)
@@ -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
index dd4abfb..343154e 100644 (file)
@@ -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 */
index d41e1a0..22f350f 100644 (file)
@@ -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;
 }