[vlc-devel] [PATCH 20/29] direct3d11: keep the whole config when selecting the quad output format

Steve Lhomme robux4 at videolabs.io
Thu Jan 19 11:10:55 CET 2017


Rather than keeping a few fields we keep a const pointer with all the data.
---
 modules/video_output/win32/common.h     | 10 ++------
 modules/video_output/win32/direct3d11.c | 42 +++++++++++++--------------------
 2 files changed, 19 insertions(+), 33 deletions(-)

diff --git a/modules/video_output/win32/common.h b/modules/video_output/win32/common.h
index a478762..857e658 100644
--- a/modules/video_output/win32/common.h
+++ b/modules/video_output/win32/common.h
@@ -45,13 +45,7 @@
 #include "events.h"
 
 #ifdef MODULE_NAME_IS_direct3d11
-typedef struct
-{
-    DXGI_FORMAT   textureFormat;
-    DXGI_FORMAT   resourceFormatYRGB;
-    DXGI_FORMAT   resourceFormatUV;
-} d3d_quad_cfg_t;
-
+#include "../../video_chroma/dxgi_fmt.h"
 #ifdef HAVE_ID3D11VIDEODECODER
 /* VLC_CODEC_D3D11_OPAQUE */
 struct picture_sys_t
@@ -199,7 +193,7 @@ struct vout_display_sys_t
     ID3D11Device             *d3ddevice;       /* D3D device */
     ID3D11DeviceContext      *d3dcontext;      /* D3D context */
     d3d_quad_t               picQuad;
-    d3d_quad_cfg_t           picQuadConfig;
+    const d3d_format_t       *picQuadConfig;
 
     /* staging quad to adjust visible borders */
     d3d_quad_t               stagingQuad;
diff --git a/modules/video_output/win32/direct3d11.c b/modules/video_output/win32/direct3d11.c
index 4f3f404..ea35e0c 100644
--- a/modules/video_output/win32/direct3d11.c
+++ b/modules/video_output/win32/direct3d11.c
@@ -46,8 +46,6 @@
 
 #include "common.h"
 
-#include "../../video_chroma/dxgi_fmt.h"
-
 #if !VLC_WINSTORE_APP
 # define D3D11CreateDevice(args...)             sys->OurD3D11CreateDevice(args)
 # define D3DCompile(args...)                    sys->OurD3DCompile(args)
@@ -153,7 +151,7 @@ static void Direct3D11DeleteRegions(int, picture_t **);
 static int Direct3D11MapSubpicture(vout_display_t *, int *, picture_t ***, subpicture_t *);
 
 static int AllocQuad(vout_display_t *, const video_format_t *, d3d_quad_t *,
-                     d3d_quad_cfg_t *, ID3D11PixelShader *, bool b_visible,
+                     const d3d_format_t *, ID3D11PixelShader *, bool b_visible,
                      video_projection_mode_t);
 static void ReleaseQuad(d3d_quad_t *);
 static void UpdatePicQuadPosition(vout_display_t *);
@@ -507,7 +505,7 @@ static picture_pool_t *Pool(vout_display_t *vd, unsigned pool_size)
     texDesc.Width = vd->fmt.i_width;
     texDesc.Height = vd->fmt.i_height;
     texDesc.MipLevels = 1;
-    texDesc.Format = vd->sys->picQuadConfig.textureFormat;
+    texDesc.Format = vd->sys->picQuadConfig->formatTexture;
     texDesc.SampleDesc.Count = 1;
     texDesc.MiscFlags = 0; //D3D11_RESOURCE_MISC_SHARED;
     texDesc.Usage = D3D11_USAGE_DEFAULT;
@@ -1238,9 +1236,7 @@ static int Direct3D11Open(vout_display_t *vd, video_format_t *fmt)
                              (char *)&i_src_chroma );
                 fmt->i_chroma = output_format->fourcc;
                 DxgiFormatMask( output_format->formatTexture, fmt );
-                sys->picQuadConfig.textureFormat      = output_format->formatTexture;
-                sys->picQuadConfig.resourceFormatYRGB = output_format->formatY;
-                sys->picQuadConfig.resourceFormatUV   = output_format->formatUV;
+                sys->picQuadConfig = output_format;
                 break;
             }
         }
@@ -1281,9 +1277,7 @@ static int Direct3D11Open(vout_display_t *vd, video_format_t *fmt)
                                  (char *)&i_src_chroma );
                     fmt->i_chroma = output_format->fourcc;
                     DxgiFormatMask( output_format->formatTexture, fmt );
-                    sys->picQuadConfig.textureFormat      = output_format->formatTexture;
-                    sys->picQuadConfig.resourceFormatYRGB = output_format->formatY;
-                    sys->picQuadConfig.resourceFormatUV   = output_format->formatUV;
+                    sys->picQuadConfig = output_format;
                     break;
                 }
             }
@@ -1305,9 +1299,7 @@ static int Direct3D11Open(vout_display_t *vd, video_format_t *fmt)
                              (char *)&i_src_chroma );
                 fmt->i_chroma = output_format->fourcc;
                 DxgiFormatMask( output_format->formatTexture, fmt );
-                sys->picQuadConfig.textureFormat      = output_format->formatTexture;
-                sys->picQuadConfig.resourceFormatYRGB = output_format->formatY;
-                sys->picQuadConfig.resourceFormatUV   = output_format->formatUV;
+                sys->picQuadConfig = output_format;
                 break;
             }
         }
@@ -1338,8 +1330,8 @@ static int Direct3D11Open(vout_display_t *vd, video_format_t *fmt)
         sys->d3dregion_format = DXGI_FORMAT_UNKNOWN;
     }
 
-    if (sys->picQuadConfig.resourceFormatYRGB == DXGI_FORMAT_R8_UNORM ||
-        sys->picQuadConfig.resourceFormatYRGB == DXGI_FORMAT_R16_UNORM)
+    if (sys->picQuadConfig->formatY == DXGI_FORMAT_R8_UNORM ||
+        sys->picQuadConfig->formatY == DXGI_FORMAT_R16_UNORM)
         sys->d3dPxShader = globPixelShaderBiplanarYUV_2RGB;
     else
     if (fmt->i_chroma == VLC_CODEC_YUYV)
@@ -1882,15 +1874,15 @@ static bool AllocQuadVertices(vout_display_t *vd, d3d_quad_t *quad, video_projec
 }
 
 static int AllocQuad(vout_display_t *vd, const video_format_t *fmt, d3d_quad_t *quad,
-                     d3d_quad_cfg_t *cfg, ID3D11PixelShader *d3dpixelShader, bool b_visible,
+                     const d3d_format_t *cfg, ID3D11PixelShader *d3dpixelShader, bool b_visible,
                      video_projection_mode_t projection)
 {
     vout_display_sys_t *sys = vd->sys;
     D3D11_MAPPED_SUBRESOURCE mappedResource;
     HRESULT hr;
     static const FLOAT FULL_TO_STUDIO_SHIFT = 16.f / 256.f;
-    const bool RGB_shader = cfg->resourceFormatYRGB != DXGI_FORMAT_R8_UNORM &&
-        cfg->resourceFormatYRGB != DXGI_FORMAT_R16_UNORM &&
+    const bool RGB_shader = cfg->formatY != DXGI_FORMAT_R8_UNORM &&
+        cfg->formatY != DXGI_FORMAT_R16_UNORM &&
         fmt->i_chroma != VLC_CODEC_YUYV;
 
     /* pixel shader constant buffer */
@@ -2016,7 +2008,7 @@ static int AllocQuad(vout_display_t *vd, const video_format_t *fmt, d3d_quad_t *
     texDesc.Width  = b_visible ? fmt->i_visible_width  : fmt->i_width;
     texDesc.Height = b_visible ? fmt->i_visible_height : fmt->i_height;
     texDesc.MipLevels = texDesc.ArraySize = 1;
-    texDesc.Format = cfg->textureFormat;
+    texDesc.Format = cfg->formatTexture;
     texDesc.SampleDesc.Count = 1;
     texDesc.Usage = D3D11_USAGE_DYNAMIC;
     texDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
@@ -2062,7 +2054,7 @@ static int AllocQuad(vout_display_t *vd, const video_format_t *fmt, d3d_quad_t *
     /* map texture planes to resource views */
     D3D11_SHADER_RESOURCE_VIEW_DESC resviewDesc;
     memset(&resviewDesc, 0, sizeof(resviewDesc));
-    resviewDesc.Format = cfg->resourceFormatYRGB;
+    resviewDesc.Format = cfg->formatY;
     resviewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
     resviewDesc.Texture2D.MipLevels = texDesc.MipLevels;
 
@@ -2072,9 +2064,9 @@ static int AllocQuad(vout_display_t *vd, const video_format_t *fmt, d3d_quad_t *
         goto error;
     }
 
-    if( cfg->resourceFormatUV )
+    if( cfg->formatUV )
     {
-        resviewDesc.Format = cfg->resourceFormatUV;
+        resviewDesc.Format = cfg->formatUV;
         hr = ID3D11Device_CreateShaderResourceView(sys->d3ddevice, (ID3D11Resource *)quad->pTexture, &resviewDesc, &quad->picSys.resourceView[1]);
         if (FAILED(hr)) {
             msg_Err(vd, "Could not Create the UV D3d11 Texture ResourceView. (hr=0x%lX)", hr);
@@ -2301,9 +2293,9 @@ static int Direct3D11MapSubpicture(vout_display_t *vd, int *subpicture_region_co
             if (unlikely(d3dquad==NULL)) {
                 continue;
             }
-            d3d_quad_cfg_t rgbaCfg = {
-                .textureFormat      = sys->d3dregion_format,
-                .resourceFormatYRGB = sys->d3dregion_format,
+            d3d_format_t rgbaCfg = {
+                .formatTexture      = sys->d3dregion_format,
+                .formatY            = sys->d3dregion_format,
             };
             err = AllocQuad( vd, &r->fmt, d3dquad, &rgbaCfg, sys->pSPUPixelShader,
                              false, PROJECTION_MODE_RECTANGULAR );
-- 
2.10.2



More information about the vlc-devel mailing list