dxgi_fmt: provide the list of resource view types in an array
authorSteve Lhomme <robUx4@videolabs.io>
Thu, 2 Feb 2017 13:54:08 +0000 (14:54 +0100)
committerJean-Baptiste Kempf <jb@videolan.org>
Wed, 8 Feb 2017 12:49:59 +0000 (13:49 +0100)
Signed-off-by: Jean-Baptiste Kempf <jb@videolan.org>
modules/video_chroma/d3d11_fmt.h
modules/video_chroma/dxgi_fmt.c
modules/video_chroma/dxgi_fmt.h
modules/video_output/win32/direct3d11.c

index b1886d7..5fbab72 100644 (file)
@@ -35,7 +35,7 @@ struct picture_sys_t
     ID3D11DeviceContext           *context;
     unsigned                      slice_index;
     ID3D11VideoProcessorInputView *inputView; /* when used as processor input */
-    ID3D11ShaderResourceView      *resourceView[2];
+    ID3D11ShaderResourceView      *resourceView[D3D11_MAX_SHADER_VIEW];
 };
 
 #endif /* include-guard */
index 0b84d6f..9fbf702 100644 (file)
@@ -66,28 +66,28 @@ static const dxgi_format_t dxgi_formats[] = {
 };
 
 static const d3d_format_t d3d_formats[] = {
-    { "NV12",     DXGI_FORMAT_NV12,           VLC_CODEC_NV12,              8, 2, 2, DXGI_FORMAT_R8_UNORM,       DXGI_FORMAT_R8G8_UNORM },
-    { "VA_NV12",  DXGI_FORMAT_NV12,           VLC_CODEC_D3D11_OPAQUE,      8, 2, 2, DXGI_FORMAT_R8_UNORM,       DXGI_FORMAT_R8G8_UNORM },
-    { "P010",     DXGI_FORMAT_P010,           VLC_CODEC_P010,             10, 2, 2, DXGI_FORMAT_R16_UNORM,      DXGI_FORMAT_R16G16_UNORM },
-    { "VA_P010",  DXGI_FORMAT_P010,           VLC_CODEC_D3D11_OPAQUE_10B, 10, 2, 2, DXGI_FORMAT_R16_UNORM,      DXGI_FORMAT_R16G16_UNORM },
-    { "YUY2",     DXGI_FORMAT_YUY2,           VLC_CODEC_YUYV,              8, 2, 2, DXGI_FORMAT_R8G8B8A8_UNORM, 0 },
+    { "NV12",     DXGI_FORMAT_NV12,           VLC_CODEC_NV12,              8, 2, 2, { DXGI_FORMAT_R8_UNORM,       DXGI_FORMAT_R8G8_UNORM } },
+    { "VA_NV12",  DXGI_FORMAT_NV12,           VLC_CODEC_D3D11_OPAQUE,      8, 2, 2, { DXGI_FORMAT_R8_UNORM,       DXGI_FORMAT_R8G8_UNORM } },
+    { "P010",     DXGI_FORMAT_P010,           VLC_CODEC_P010,             10, 2, 2, { DXGI_FORMAT_R16_UNORM,      DXGI_FORMAT_R16G16_UNORM } },
+    { "VA_P010",  DXGI_FORMAT_P010,           VLC_CODEC_D3D11_OPAQUE_10B, 10, 2, 2, { DXGI_FORMAT_R16_UNORM,      DXGI_FORMAT_R16G16_UNORM } },
+    { "YUY2",     DXGI_FORMAT_YUY2,           VLC_CODEC_YUYV,              8, 2, 2, { DXGI_FORMAT_R8G8B8A8_UNORM } },
 #ifdef BROKEN_PIXEL
-    { "AYUV",     DXGI_FORMAT_AYUV,           VLC_CODEC_YUVA,          8, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM,     0 },
-    { "Y416",     DXGI_FORMAT_Y416,           VLC_CODEC_I444_16L,     16, 1, 1, DXGI_FORMAT_R16G16B16A16_UINT,  0 },
+    { "AYUV",     DXGI_FORMAT_AYUV,           VLC_CODEC_YUVA,          8, 1, 1, { DXGI_FORMAT_R8G8B8A8_UNORM } },
+    { "Y416",     DXGI_FORMAT_Y416,           VLC_CODEC_I444_16L,     16, 1, 1, { DXGI_FORMAT_R16G16B16A16_UINT } },
 #endif
 #ifdef UNTESTED
-    { "Y210",     DXGI_FORMAT_Y210,           VLC_CODEC_I422_10L,     10, 2, 1, DXGI_FORMAT_R16G16B16A16_UNORM, 0 },
-    { "Y410",     DXGI_FORMAT_Y410,           VLC_CODEC_I444,         10, 1, 1, DXGI_FORMAT_R10G10B10A2_UNORM,  0 },
-    { "NV11",     DXGI_FORMAT_NV11,           VLC_CODEC_I411,          8, 4, 1, DXGI_FORMAT_R8_UNORM,           DXGI_FORMAT_R8G8_UNORM },
+    { "Y210",     DXGI_FORMAT_Y210,           VLC_CODEC_I422_10L,     10, 2, 1, { DXGI_FORMAT_R16G16B16A16_UNORM } },
+    { "Y410",     DXGI_FORMAT_Y410,           VLC_CODEC_I444,         10, 1, 1, { DXGI_FORMAT_R10G10B10A2_UNORM } },
+    { "NV11",     DXGI_FORMAT_NV11,           VLC_CODEC_I411,          8, 4, 1, { DXGI_FORMAT_R8_UNORM,           DXGI_FORMAT_R8G8_UNORM} },
 #endif
-    { "R8G8B8A8", DXGI_FORMAT_R8G8B8A8_UNORM, VLC_CODEC_RGBA,          8, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM,     0 },
-    { "VA_RGBA",  DXGI_FORMAT_R8G8B8A8_UNORM, VLC_CODEC_D3D11_OPAQUE,  8, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM,     0 },
-    { "B8G8R8A8", DXGI_FORMAT_B8G8R8A8_UNORM, VLC_CODEC_BGRA,          8, 1, 1, DXGI_FORMAT_B8G8R8A8_UNORM,     0 },
-    { "VA_BGRA",  DXGI_FORMAT_B8G8R8A8_UNORM, VLC_CODEC_D3D11_OPAQUE,  8, 1, 1, DXGI_FORMAT_B8G8R8A8_UNORM,     0 },
-    { "R8G8B8X8", DXGI_FORMAT_B8G8R8X8_UNORM, VLC_CODEC_RGB32,         8, 1, 1, DXGI_FORMAT_B8G8R8X8_UNORM,     0 },
-    { "B5G6R5",   DXGI_FORMAT_B5G6R5_UNORM,   VLC_CODEC_RGB16,         5, 1, 1, DXGI_FORMAT_B5G6R5_UNORM,       0 },
-
-    { NULL, 0, 0, 0, 0, 0, 0, 0}
+    { "R8G8B8A8", DXGI_FORMAT_R8G8B8A8_UNORM, VLC_CODEC_RGBA,          8, 1, 1, { DXGI_FORMAT_R8G8B8A8_UNORM } },
+    { "VA_RGBA",  DXGI_FORMAT_R8G8B8A8_UNORM, VLC_CODEC_D3D11_OPAQUE,  8, 1, 1, { DXGI_FORMAT_R8G8B8A8_UNORM } },
+    { "B8G8R8A8", DXGI_FORMAT_B8G8R8A8_UNORM, VLC_CODEC_BGRA,          8, 1, 1, { DXGI_FORMAT_B8G8R8A8_UNORM } },
+    { "VA_BGRA",  DXGI_FORMAT_B8G8R8A8_UNORM, VLC_CODEC_D3D11_OPAQUE,  8, 1, 1, { DXGI_FORMAT_B8G8R8A8_UNORM } },
+    { "R8G8B8X8", DXGI_FORMAT_B8G8R8X8_UNORM, VLC_CODEC_RGB32,         8, 1, 1, { DXGI_FORMAT_B8G8R8X8_UNORM } },
+    { "B5G6R5",   DXGI_FORMAT_B5G6R5_UNORM,   VLC_CODEC_RGB16,         5, 1, 1, { DXGI_FORMAT_B5G6R5_UNORM } },
+
+    { NULL, 0, 0, 0, 0, 0, {} }
 };
 
 const char *DxgiFormatToStr(DXGI_FORMAT format)
index 190bd69..dd4abfb 100644 (file)
@@ -29,6 +29,8 @@
 #include <vlc_common.h>
 #include <vlc_fourcc.h>
 
+#define D3D11_MAX_SHADER_VIEW  2
+
 typedef struct
 {
     const char   *name;
@@ -37,8 +39,7 @@ typedef struct
     uint8_t      bitsPerChannel;
     uint8_t      widthDenominator;
     uint8_t      heightDenominator;
-    DXGI_FORMAT  formatY;
-    DXGI_FORMAT  formatUV;
+    DXGI_FORMAT  resourceFormat[D3D11_MAX_SHADER_VIEW];
 } d3d_format_t;
 
 extern const char *DxgiFormatToStr(DXGI_FORMAT format);
index 55f3d8a..73fc1b1 100644 (file)
@@ -254,6 +254,9 @@ static const char* globVertexShaderFlat = "\
   }\
 ";
 
+#define STRINGIZE2(s) #s
+#define STRINGIZE(s) STRINGIZE2(s)
+
 static const char* globVertexShaderProjection = "\
   cbuffer VS_PROJECTION_CONST : register(b0)\
   {\
@@ -296,7 +299,14 @@ static const char* globPixelShaderDefault = "\
     float Opacity;\
     float opacityPadding[3];\
   };\
-  Texture2D shaderTexture;\
+  cbuffer PS_COLOR_TRANSFORM : register(b1)\
+  {\
+    float WhitePointX;\
+    float WhitePointY;\
+    float WhitePointZ;\
+    float whitePadding;\
+  };\
+  Texture2D shaderTexture[" STRINGIZE(D3D11_MAX_SHADER_VIEW) "];\
   SamplerState SampleType;\
   \
   struct PS_INPUT\
@@ -309,7 +319,7 @@ static const char* globPixelShaderDefault = "\
   {\
     float4 rgba; \
     \
-    rgba = shaderTexture.Sample(SampleType, In.Texture);\
+    rgba = shaderTexture[0].Sample(SampleType, In.Texture);\
     rgba.a = rgba.a * Opacity;\
     return rgba; \
   }\
@@ -330,8 +340,7 @@ static const char *globPixelShaderBiplanarYUV_2RGB = "\
     float whitePadding;\
     float4x4 Colorspace;\
   };\
-  Texture2D shaderTextureY;\
-  Texture2D shaderTextureUV;\
+  Texture2D shaderTexture[" STRINGIZE(D3D11_MAX_SHADER_VIEW) "];\
   SamplerState SampleType;\
   \
   struct PS_INPUT\
@@ -344,8 +353,8 @@ static const char *globPixelShaderBiplanarYUV_2RGB = "\
   {\
     float4 yuv;\
     float4 rgba;\
-    yuv.x  = shaderTextureY.Sample(SampleType, In.Texture).x;\
-    yuv.yz = shaderTextureUV.Sample(SampleType, In.Texture).xy;\
+    yuv.x  = shaderTexture[0].Sample(SampleType, In.Texture).x;\
+    yuv.yz = shaderTexture[1].Sample(SampleType, In.Texture).xy;\
     yuv.a  = Opacity;\
     yuv.x  += WhitePointX;\
     yuv.y  += WhitePointY;\
@@ -369,7 +378,7 @@ static const char *globPixelShaderBiplanarYUYV_2RGB = "\
     float whitePadding;\
     float4x4 Colorspace;\
   };\
-  Texture2D shaderTextureYUYV;\
+  Texture2D shaderTexture[" STRINGIZE(D3D11_MAX_SHADER_VIEW) "];\
   SamplerState SampleType;\
   \
   struct PS_INPUT\
@@ -382,9 +391,9 @@ static const char *globPixelShaderBiplanarYUYV_2RGB = "\
   {\
     float4 yuv;\
     float4 rgba;\
-    yuv.x  = shaderTextureYUYV.Sample(SampleType, In.Texture).x;\
-    yuv.y  = shaderTextureYUYV.Sample(SampleType, In.Texture).y;\
-    yuv.z  = shaderTextureYUYV.Sample(SampleType, In.Texture).a;\
+    yuv.x  = shaderTexture[0].Sample(SampleType, In.Texture).x;\
+    yuv.y  = shaderTexture[0].Sample(SampleType, In.Texture).y;\
+    yuv.z  = shaderTexture[0].Sample(SampleType, In.Texture).a;\
     yuv.a  = Opacity;\
     yuv.x  += WhitePointX;\
     yuv.y  += WhitePointY;\
@@ -673,6 +682,10 @@ static void DestroyDisplayPoolPicture(picture_t *picture)
 {
     picture_sys_t *p_sys = (picture_sys_t*) picture->p_sys;
 
+    for (int i=0; i<D3D11_MAX_SHADER_VIEW; i++) {
+        if (p_sys->resourceView[i])
+            ID3D11ShaderResourceView_Release(p_sys->resourceView[i]);
+    }
     if (p_sys->texture)
         ID3D11Texture2D_Release(p_sys->texture);
     if (p_sys->context)
@@ -1075,7 +1088,7 @@ static void Prepare(vout_display_t *vd, picture_t *picture, subpicture_t *subpic
     }
 }
 
-static void DisplayD3DPicture(vout_display_sys_t *sys, d3d_quad_t *quad, ID3D11ShaderResourceView *resourceView[2])
+static void DisplayD3DPicture(vout_display_sys_t *sys, d3d_quad_t *quad, ID3D11ShaderResourceView *resourceView[D3D11_MAX_SHADER_VIEW])
 {
     UINT stride = sizeof(d3d_vertex_t);
     UINT offset = 0;
@@ -1093,7 +1106,7 @@ static void DisplayD3DPicture(vout_display_sys_t *sys, d3d_quad_t *quad, ID3D11S
     ID3D11DeviceContext_PSSetShader(sys->d3dcontext, quad->d3dpixelShader, NULL, 0);
 
     ID3D11DeviceContext_PSSetConstantBuffers(sys->d3dcontext, 0, quad->PSConstantsCount, quad->pPixelShaderConstants);
-    ID3D11DeviceContext_PSSetShaderResources(sys->d3dcontext, 0, 2, resourceView);
+    ID3D11DeviceContext_PSSetShaderResources(sys->d3dcontext, 0, D3D11_MAX_SHADER_VIEW, resourceView);
 
     ID3D11DeviceContext_RSSetViewports(sys->d3dcontext, 1, &quad->cropViewport);
 
@@ -1319,9 +1332,9 @@ 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.textureFormat = output_format->formatTexture;
+                sys->picQuadConfig.resourceFormatYRGB = output_format->resourceFormat[0];
+                sys->picQuadConfig.resourceFormatUV   = output_format->resourceFormat[1];
                 break;
             }
         }
@@ -1363,8 +1376,8 @@ static int Direct3D11Open(vout_display_t *vd, video_format_t *fmt)
                     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.resourceFormatYRGB = output_format->resourceFormat[0];
+                    sys->picQuadConfig.resourceFormatUV   = output_format->resourceFormat[1];
                     break;
                 }
             }
@@ -1387,8 +1400,8 @@ static int Direct3D11Open(vout_display_t *vd, video_format_t *fmt)
                 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.resourceFormatYRGB = output_format->resourceFormat[0];
+                sys->picQuadConfig.resourceFormatUV   = output_format->resourceFormat[1];
                 break;
             }
         }
@@ -2183,15 +2196,12 @@ static void ReleaseQuad(d3d_quad_t *quad)
         ID3D11Texture2D_Release(quad->pTexture);
         quad->pTexture = NULL;
     }
-    if (quad->picSys.resourceView[0])
-    {
-        ID3D11ShaderResourceView_Release(quad->picSys.resourceView[0]);
-        quad->picSys.resourceView[0] = NULL;
-    }
-    if (quad->picSys.resourceView[1])
-    {
-        ID3D11ShaderResourceView_Release(quad->picSys.resourceView[1]);
-        quad->picSys.resourceView[1] = NULL;
+    for (int i=0; i<D3D11_MAX_SHADER_VIEW; i++) {
+        if (quad->picSys.resourceView[i])
+        {
+            ID3D11ShaderResourceView_Release(quad->picSys.resourceView[i]);
+            quad->picSys.resourceView[i] = NULL;
+        }
     }
     if (quad->d3dpixelShader)
     {