direct3d11: factorize the code to find an appropriate texture format
authorSteve Lhomme <robux4@videolabs.io>
Fri, 28 Apr 2017 15:46:21 +0000 (17:46 +0200)
committerJean-Baptiste Kempf <jb@videolan.org>
Tue, 2 May 2017 08:15:50 +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 e6ee332..1f96940 100644 (file)
@@ -834,25 +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
-        for (const d3d_format_t *output = GetRenderFormatList();
-             output->name != NULL; ++output)
-        {
-            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) );
-
-                hr = ID3D11VideoProcessorEnumerator_CheckVideoProcessorFormat(processorEnumerator,
-                                                                              output->formatTexture, &flags);
-                if (FAILED(hr) || !(flags & D3D11_VIDEO_PROCESSOR_FORMAT_SUPPORT_OUTPUT))
-                    msg_Dbg(va, "Processor format %s not supported for output", DxgiFormatToStr(output->formatTexture));
-                else
-                {
-                    processorOutput = output->formatTexture;
-                    break;
-                }
-            }
-        }
+        const d3d_format_t *found;
+        found = FindD3D11Format( (ID3D11Device*) dx_sys->d3ddev, 0, 0, true,
+                                 D3D11_FORMAT_SUPPORT_SHADER_LOAD | D3D11_FORMAT_SUPPORT_VIDEO_PROCESSOR_OUTPUT);
+        if (found)
+            processorOutput = found->formatTexture;
     }
 
     if (processorOutput != DXGI_FORMAT_UNKNOWN)
index 343154e..f20e488 100644 (file)
@@ -59,4 +59,30 @@ static inline bool DeviceSupportsFormat(ID3D11Device *d3ddevice,
                                                       &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;
+
+        if( DeviceSupportsFormat( d3ddevice, output_format->formatTexture,
+                                  supportFlags ) )
+            return output_format;
+    }
+    return NULL;
+}
+
 #endif /* include-guard */
index 22f350f..6db1769 100644 (file)
@@ -573,34 +573,6 @@ static void Close(vlc_object_t *object)
     free(vd->sys);
 }
 
-static const d3d_format_t *GetOutputFormat(vout_display_t *vd, vlc_fourcc_t i_src_chroma,
-                                           uint8_t bits_per_channel, bool b_allow_opaque,
-                                           bool blendable)
-{
-    vout_display_sys_t *sys = vd->sys;
-    UINT supportFlags = D3D11_FORMAT_SUPPORT_TEXTURE2D | D3D11_FORMAT_SUPPORT_SHADER_LOAD;
-    if (blendable)
-        supportFlags |= D3D11_FORMAT_SUPPORT_BLENDABLE;
-    if (b_allow_opaque && is_d3d11_opaque(i_src_chroma))
-        supportFlags |= D3D11_FORMAT_SUPPORT_DECODER_OUTPUT;
-
-    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 (!b_allow_opaque && is_d3d11_opaque(output_format->fourcc))
-            continue;
-
-        if( DeviceSupportsFormat( sys->d3ddevice, output_format->formatTexture,
-                                  supportFlags ) )
-            return output_format;
-    }
-    return NULL;
-}
-
 /* map texture planes to resource views */
 static int AllocateShaderView(vout_display_t *vd, const d3d_format_t *format,
                               int slice_index, picture_sys_t *picsys)
@@ -1592,7 +1564,10 @@ static int Direct3D11Open(vout_display_t *vd, video_format_t *fmt)
     D3D11SetColorSpace(vd);
 
     // look for the requested pixel format first
-    sys->picQuadConfig = GetOutputFormat(vd, fmt->i_chroma, 0, true, false);
+    UINT supportFlags = D3D11_FORMAT_SUPPORT_SHADER_LOAD;
+    if (is_d3d11_opaque(fmt->i_chroma))
+        supportFlags |= D3D11_FORMAT_SUPPORT_DECODER_OUTPUT;
+    sys->picQuadConfig = FindD3D11Format(sys->d3ddevice, fmt->i_chroma, 0, true, supportFlags);
 
     // look for any pixel format that we can handle with enough pixels per channel
     if ( !sys->picQuadConfig )
@@ -1614,12 +1589,12 @@ static int Direct3D11Open(vout_display_t *vd, video_format_t *fmt)
             break;
         }
 
-        sys->picQuadConfig = GetOutputFormat(vd, 0, bits_per_channel, false, false);
+        sys->picQuadConfig = FindD3D11Format(sys->d3ddevice, 0, bits_per_channel, false, D3D11_FORMAT_SUPPORT_SHADER_LOAD);
     }
 
     // look for any pixel format that we can handle
     if ( !sys->picQuadConfig )
-        sys->picQuadConfig = GetOutputFormat(vd, 0, 0, false, false);
+        sys->picQuadConfig = FindD3D11Format(sys->d3ddevice, 0, 0, false, D3D11_FORMAT_SUPPORT_SHADER_LOAD);
 
     if ( !sys->picQuadConfig )
     {
@@ -1632,9 +1607,11 @@ static int Direct3D11Open(vout_display_t *vd, video_format_t *fmt)
     DxgiFormatMask( sys->picQuadConfig->formatTexture, fmt );
 
     /* check the region pixel format */
-    sys->d3dregion_format = GetOutputFormat(vd, VLC_CODEC_RGBA, 0, false, true);
+    sys->d3dregion_format = FindD3D11Format(sys->d3ddevice, VLC_CODEC_RGBA, 0, false,
+                                            D3D11_FORMAT_SUPPORT_SHADER_LOAD | D3D11_FORMAT_SUPPORT_BLENDABLE);
     if (!sys->d3dregion_format)
-        sys->d3dregion_format = GetOutputFormat(vd, VLC_CODEC_BGRA, 0, false, true);
+        sys->d3dregion_format = FindD3D11Format(sys->d3ddevice, VLC_CODEC_BGRA, 0, false,
+                                                D3D11_FORMAT_SUPPORT_SHADER_LOAD | D3D11_FORMAT_SUPPORT_BLENDABLE);
 
     UpdateRects(vd, NULL, NULL, true);