[vlc-commits] direct3d11: pick the output format based on chroma subsampling

Steve Lhomme git at videolan.org
Wed Oct 17 16:07:57 CEST 2018


vlc/vlc-3.0 | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Mon Oct 15 14:22:40 2018 +0200| [b9065345eef1d1d63c3274003974d013bd8fc41e] | committer: Steve Lhomme

direct3d11: pick the output format based on chroma subsampling

Don't subsample if we don't have to.

In any case we can display in YUVA or RGBA that have no subsampling.

Fixes #20421

(cherry picked from commit f6a25bd66d88eaad77e90e16de08f1fc8f9aec72)

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

 modules/hw/d3d11/d3d11_surface.c        |  2 +-
 modules/video_chroma/d3d11_fmt.c        |  6 ++++
 modules/video_chroma/d3d11_fmt.h        |  5 +++-
 modules/video_output/win32/direct3d11.c | 52 ++++++++++++++++++++++++++-------
 4 files changed, 52 insertions(+), 13 deletions(-)

diff --git a/modules/hw/d3d11/d3d11_surface.c b/modules/hw/d3d11/d3d11_surface.c
index e9a421122c..cc3d2615dc 100644
--- a/modules/hw/d3d11/d3d11_surface.c
+++ b/modules/hw/d3d11/d3d11_surface.c
@@ -217,7 +217,7 @@ static int assert_staging(filter_t *p_filter, picture_sys_t *p_sys)
         /* failed with the this format, try a different one */
         UINT supportFlags = D3D11_FORMAT_SUPPORT_SHADER_LOAD | D3D11_FORMAT_SUPPORT_VIDEO_PROCESSOR_OUTPUT;
         const d3d_format_t *new_fmt =
-                FindD3D11Format( p_filter, &d3d_dev, 0, false, 0, false, supportFlags );
+                FindD3D11Format( p_filter, &d3d_dev, 0, false, 0, 0, 0, false, supportFlags );
         if (new_fmt && texDesc.Format != new_fmt->formatTexture)
         {
             DXGI_FORMAT srcFormat = texDesc.Format;
diff --git a/modules/video_chroma/d3d11_fmt.c b/modules/video_chroma/d3d11_fmt.c
index 7a728f9dfb..5d785cb591 100644
--- a/modules/video_chroma/d3d11_fmt.c
+++ b/modules/video_chroma/d3d11_fmt.c
@@ -502,6 +502,8 @@ const d3d_format_t *FindD3D11Format(vlc_object_t *o,
                                     vlc_fourcc_t i_src_chroma,
                                     bool rgb_only,
                                     uint8_t bits_per_channel,
+                                    uint8_t widthDenominator,
+                                    uint8_t heightDenominator,
                                     bool allow_opaque,
                                     UINT supportFlags)
 {
@@ -517,6 +519,10 @@ const d3d_format_t *FindD3D11Format(vlc_object_t *o,
             continue;
         if (rgb_only && vlc_fourcc_IsYUV(output_format->fourcc))
             continue;
+        if (widthDenominator && widthDenominator < output_format->widthDenominator)
+            continue;
+        if (heightDenominator && heightDenominator < output_format->heightDenominator)
+            continue;
 
         DXGI_FORMAT textureFormat;
         if (output_format->formatTexture == DXGI_FORMAT_UNKNOWN)
diff --git a/modules/video_chroma/d3d11_fmt.h b/modules/video_chroma/d3d11_fmt.h
index 49ac0313b1..a0a33b5f19 100644
--- a/modules/video_chroma/d3d11_fmt.h
+++ b/modules/video_chroma/d3d11_fmt.h
@@ -132,9 +132,12 @@ const d3d_format_t *FindD3D11Format(vlc_object_t *,
                                     vlc_fourcc_t i_src_chroma,
                                     bool rgb_only,
                                     uint8_t bits_per_channel,
+                                    uint8_t widthDenominator,
+                                    uint8_t heightDenominator,
                                     bool allow_opaque,
                                     UINT supportFlags);
-#define FindD3D11Format(a,b,c,d,e,f,g)  FindD3D11Format(VLC_OBJECT(a),b,c,d,e,f,g)
+#define FindD3D11Format(a,b,c,d,e,f,g,h,i)  \
+    FindD3D11Format(VLC_OBJECT(a),b,c,d,e,f,g,h,i)
 
 int AllocateTextures(vlc_object_t *, d3d11_device_t *, const d3d_format_t *,
                      const video_format_t *, unsigned pool_size, ID3D11Texture2D *textures[]);
diff --git a/modules/video_output/win32/direct3d11.c b/modules/video_output/win32/direct3d11.c
index 00797bfc78..ef5b72b592 100644
--- a/modules/video_output/win32/direct3d11.c
+++ b/modules/video_output/win32/direct3d11.c
@@ -1199,27 +1199,33 @@ static const d3d_format_t *GetDirectRenderingFormat(vout_display_t *vd, vlc_four
     UINT supportFlags = D3D11_FORMAT_SUPPORT_SHADER_LOAD;
     if (is_d3d11_opaque(i_src_chroma))
         supportFlags |= D3D11_FORMAT_SUPPORT_DECODER_OUTPUT;
-    return FindD3D11Format( vd, &vd->sys->d3d_dev, i_src_chroma, false, 0, is_d3d11_opaque(i_src_chroma), supportFlags );
+    return FindD3D11Format( vd, &vd->sys->d3d_dev, i_src_chroma, false, 0, 0, 0, is_d3d11_opaque(i_src_chroma), supportFlags );
 }
 
 static const d3d_format_t *GetDirectDecoderFormat(vout_display_t *vd, vlc_fourcc_t i_src_chroma)
 {
     UINT supportFlags = D3D11_FORMAT_SUPPORT_DECODER_OUTPUT;
-    return FindD3D11Format( vd, &vd->sys->d3d_dev, i_src_chroma, false, 0, is_d3d11_opaque(i_src_chroma), supportFlags );
+    return FindD3D11Format( vd, &vd->sys->d3d_dev, i_src_chroma, false, 0, 0, 0, is_d3d11_opaque(i_src_chroma), supportFlags );
 }
 
-static const d3d_format_t *GetDisplayFormatByDepth(vout_display_t *vd, uint8_t bit_depth, bool from_processor, bool rgb_only)
+static const d3d_format_t *GetDisplayFormatByDepth(vout_display_t *vd, uint8_t bit_depth,
+                                                   uint8_t widthDenominator,
+                                                   uint8_t heightDenominator,
+                                                   bool from_processor,
+                                                   bool rgb_only)
 {
     UINT supportFlags = D3D11_FORMAT_SUPPORT_SHADER_LOAD;
     if (from_processor)
         supportFlags |= D3D11_FORMAT_SUPPORT_VIDEO_PROCESSOR_OUTPUT;
-    return FindD3D11Format( vd, &vd->sys->d3d_dev, 0, rgb_only, bit_depth, false, supportFlags );
+    return FindD3D11Format( vd, &vd->sys->d3d_dev, 0, rgb_only,
+                            bit_depth, widthDenominator, heightDenominator,
+                            false, supportFlags );
 }
 
 static const d3d_format_t *GetBlendableFormat(vout_display_t *vd, vlc_fourcc_t i_src_chroma)
 {
     UINT supportFlags = D3D11_FORMAT_SUPPORT_SHADER_LOAD | D3D11_FORMAT_SUPPORT_BLENDABLE;
-    return FindD3D11Format( vd, &vd->sys->d3d_dev, i_src_chroma, false, 0, false, supportFlags );
+    return FindD3D11Format( vd, &vd->sys->d3d_dev, i_src_chroma, false, 0, 0, 0, false, supportFlags );
 }
 
 static int Direct3D11Open(vout_display_t *vd)
@@ -1324,20 +1330,38 @@ static int SetupOutputFormat(vout_display_t *vd, video_format_t *fmt)
     if ( !sys->picQuad.formatInfo )
     {
         uint8_t bits_per_channel;
+        uint8_t widthDenominator, heightDenominator;
         switch (fmt->i_chroma)
         {
         case VLC_CODEC_D3D11_OPAQUE:
             bits_per_channel = 8;
+            widthDenominator = heightDenominator = 2;
             break;
         case VLC_CODEC_D3D11_OPAQUE_10B:
             bits_per_channel = 10;
+            widthDenominator = heightDenominator = 2;
             break;
         default:
             {
                 const vlc_chroma_description_t *p_format = vlc_fourcc_GetChromaDescription(fmt->i_chroma);
-                bits_per_channel = p_format == NULL ||
-                                   p_format->pixel_bits == 0 ? 8 : p_format->pixel_bits /
-                                                               (p_format->plane_count==1 ? p_format->pixel_size : 1);
+                if (p_format == NULL)
+                {
+                    bits_per_channel = 8;
+                    widthDenominator = heightDenominator = 2;
+                }
+                else
+                {
+                    bits_per_channel = p_format->pixel_bits == 0 ? 8 : p_format->pixel_bits /
+                                                                   (p_format->plane_count==1 ? p_format->pixel_size : 1);
+                    widthDenominator = heightDenominator = 1;
+                    for (size_t i=0; i<p_format->plane_count; i++)
+                    {
+                        if (widthDenominator < p_format->p[i].w.den)
+                            widthDenominator = p_format->p[i].w.den;
+                        if (heightDenominator < p_format->p[i].h.den)
+                            heightDenominator = p_format->p[1].h.den;
+                    }
+                }
             }
             break;
         }
@@ -1349,14 +1373,20 @@ static int SetupOutputFormat(vout_display_t *vd, video_format_t *fmt)
             decoder_format = sys->picQuad.formatInfo;
 
         bool is_rgb = !vlc_fourcc_IsYUV(fmt->i_chroma);
-        sys->picQuad.formatInfo = GetDisplayFormatByDepth(vd, bits_per_channel, decoder_format!=NULL, is_rgb);
+        sys->picQuad.formatInfo = GetDisplayFormatByDepth(vd, bits_per_channel,
+                                                          widthDenominator,
+                                                          heightDenominator,
+                                                          decoder_format!=NULL, is_rgb);
         if (!sys->picQuad.formatInfo && is_rgb)
-            sys->picQuad.formatInfo = GetDisplayFormatByDepth(vd, bits_per_channel, decoder_format!=NULL, false);
+            sys->picQuad.formatInfo = GetDisplayFormatByDepth(vd, bits_per_channel,
+                                                              widthDenominator,
+                                                              heightDenominator,
+                                                              decoder_format!=NULL, false);
     }
 
     // look for any pixel format that we can handle
     if ( !sys->picQuad.formatInfo )
-        sys->picQuad.formatInfo = GetDisplayFormatByDepth(vd, 0, false, false);
+        sys->picQuad.formatInfo = GetDisplayFormatByDepth(vd, 0, 0, 0, false, false);
 
     if ( !sys->picQuad.formatInfo )
     {



More information about the vlc-commits mailing list