[vlc-commits] direct3d11: compile pixel shader directly into a d3d_quad_t

Steve Lhomme git at videolan.org
Thu Aug 2 13:08:13 CEST 2018


vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Fri Jul 13 11:45:04 2018 +0200| [d07e7dbd7dc5281d17782c49fa9f677e20ab4ead] | committer: Steve Lhomme

direct3d11: compile pixel shader directly into a d3d_quad_t

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

 modules/video_output/win32/d3d11_quad.h    | 25 -----------
 modules/video_output/win32/d3d11_shaders.c | 70 ++++++++++++++----------------
 modules/video_output/win32/d3d11_shaders.h | 35 ++++++++++++---
 modules/video_output/win32/direct3d11.c    |  8 ++--
 4 files changed, 67 insertions(+), 71 deletions(-)

diff --git a/modules/video_output/win32/d3d11_quad.h b/modules/video_output/win32/d3d11_quad.h
index 72aa3a86d7..0ce1ba3625 100644
--- a/modules/video_output/win32/d3d11_quad.h
+++ b/modules/video_output/win32/d3d11_quad.h
@@ -32,31 +32,6 @@
 #define PS_CONST_COLORSPACE  1
 #define PS_CONST_COUNT       2
 
-/* A Quad is texture that can be displayed in a rectangle */
-typedef struct
-{
-    picture_sys_t             picSys;
-    const d3d_format_t        *formatInfo;
-    UINT                      resourceCount;
-    ID3D11Buffer              *pVertexBuffer;
-    UINT                      vertexCount;
-    UINT                      vertexStride;
-    ID3D11VertexShader        *d3dvertexShader;
-    ID3D11Buffer              *pIndexBuffer;
-    UINT                      indexCount;
-    ID3D11Buffer              *pVertexShaderConstants;
-    ID3D11Buffer              *pPixelShaderConstants[PS_CONST_COUNT];
-    ID3D11PixelShader         *d3dpixelShader[D3D11_MAX_SHADER_VIEW];
-    ID3D11SamplerState        *d3dsampState[2];
-    ID3D11InputLayout         *pVertexLayout;
-    D3D11_VIEWPORT            cropViewport[D3D11_MAX_SHADER_VIEW];
-    unsigned int              i_width;
-    unsigned int              i_height;
-    video_projection_mode_t   projection;
-
-    PS_CONSTANT_BUFFER        shaderConstants;
-} d3d_quad_t;
-
 /* matches the D3D11_INPUT_ELEMENT_DESC we setup */
 typedef struct d3d_vertex_t {
     struct {
diff --git a/modules/video_output/win32/d3d11_shaders.c b/modules/video_output/win32/d3d11_shaders.c
index e3bbb0d232..0fa67013ce 100644
--- a/modules/video_output/win32/d3d11_shaders.c
+++ b/modules/video_output/win32/d3d11_shaders.c
@@ -243,10 +243,9 @@ static HRESULT CompileTargetShader(vlc_object_t *o, d3d11_handle_t *hd3d, bool l
 #undef D3D11_CompilePixelShader
 HRESULT D3D11_CompilePixelShader(vlc_object_t *o, d3d11_handle_t *hd3d, bool legacy_shader,
                                  d3d11_device_t *d3d_dev,
-                                 const d3d_format_t *format, const display_info_t *display,
+                                 const display_info_t *display,
                                  video_transfer_func_t transfer, bool src_full_range,
-                                 ID3D11PixelShader *output[D3D11_MAX_SHADER_VIEW],
-                                 ID3D11SamplerState *d3dsampState[2])
+                                 d3d_quad_t *quad)
 {
     static const char *DEFAULT_NOOP = "return rgb";
     const char *psz_sampler[2] = {NULL, NULL};
@@ -257,39 +256,36 @@ HRESULT D3D11_CompilePixelShader(vlc_object_t *o, d3d11_handle_t *hd3d, bool leg
     const char *psz_move_planes[2]    = {DEFAULT_NOOP, DEFAULT_NOOP};
     char *psz_range = NULL;
 
-    if (d3dsampState)
-    {
-        D3D11_SAMPLER_DESC sampDesc;
-        memset(&sampDesc, 0, sizeof(sampDesc));
-        sampDesc.Filter = D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT;
-        sampDesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
-        sampDesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
-        sampDesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
-        sampDesc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
-        sampDesc.MinLOD = 0;
-        sampDesc.MaxLOD = D3D11_FLOAT32_MAX;
-
-        HRESULT hr;
-        hr = ID3D11Device_CreateSamplerState(d3d_dev->d3ddevice, &sampDesc, &d3dsampState[0]);
-        if (FAILED(hr)) {
-            msg_Err(o, "Could not Create the D3d11 Sampler State. (hr=0x%lX)", hr);
-            return hr;
-        }
+    D3D11_SAMPLER_DESC sampDesc;
+    memset(&sampDesc, 0, sizeof(sampDesc));
+    sampDesc.Filter = D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT;
+    sampDesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
+    sampDesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
+    sampDesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
+    sampDesc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
+    sampDesc.MinLOD = 0;
+    sampDesc.MaxLOD = D3D11_FLOAT32_MAX;
+
+    HRESULT hr;
+    hr = ID3D11Device_CreateSamplerState(d3d_dev->d3ddevice, &sampDesc, &quad->d3dsampState[0]);
+    if (FAILED(hr)) {
+        msg_Err(o, "Could not Create the D3d11 Sampler State. (hr=0x%lX)", hr);
+        return hr;
+    }
 
-        sampDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
-        hr = ID3D11Device_CreateSamplerState(d3d_dev->d3ddevice, &sampDesc, &d3dsampState[1]);
-        if (FAILED(hr)) {
-            msg_Err(o, "Could not Create the D3d11 Sampler State. (hr=0x%lX)", hr);
-            ID3D11SamplerState_Release(d3dsampState[0]);
-            return hr;
-        }
+    sampDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
+    hr = ID3D11Device_CreateSamplerState(d3d_dev->d3ddevice, &sampDesc, &quad->d3dsampState[1]);
+    if (FAILED(hr)) {
+        msg_Err(o, "Could not Create the D3d11 Sampler State. (hr=0x%lX)", hr);
+        ID3D11SamplerState_Release(quad->d3dsampState[0]);
+        return hr;
     }
 
     if ( display->pixelFormat->formatTexture == DXGI_FORMAT_NV12 ||
          display->pixelFormat->formatTexture == DXGI_FORMAT_P010 )
     {
         /* we need 2 shaders, one for the Y target, one for the UV target */
-        switch (format->formatTexture)
+        switch (quad->formatInfo->formatTexture)
         {
         case DXGI_FORMAT_NV12:
         case DXGI_FORMAT_P010:
@@ -322,7 +318,7 @@ HRESULT D3D11_CompilePixelShader(vlc_object_t *o, d3d11_handle_t *hd3d, bool leg
                     "return rgb";
             break;
         case DXGI_FORMAT_UNKNOWN:
-            switch (format->fourcc)
+            switch (quad->formatInfo->fourcc)
             {
             case VLC_CODEC_YUVA:
                 /* Y */
@@ -348,7 +344,7 @@ HRESULT D3D11_CompilePixelShader(vlc_object_t *o, d3d11_handle_t *hd3d, bool leg
     }
     else
     {
-        switch (format->formatTexture)
+        switch (quad->formatInfo->formatTexture)
         {
         case DXGI_FORMAT_NV12:
         case DXGI_FORMAT_P010:
@@ -380,7 +376,7 @@ HRESULT D3D11_CompilePixelShader(vlc_object_t *o, d3d11_handle_t *hd3d, bool leg
                     "sample = shaderTexture[0].Sample(samplerState, coords);";
             break;
         case DXGI_FORMAT_UNKNOWN:
-            switch (format->fourcc)
+            switch (quad->formatInfo->fourcc)
             {
             case VLC_CODEC_I420_10L:
                 psz_sampler[0] =
@@ -506,7 +502,7 @@ HRESULT D3D11_CompilePixelShader(vlc_object_t *o, d3d11_handle_t *hd3d, bool leg
         if (src_full_range)
             range_adjust = -1; /* lower the source to studio range */
     }
-    if (!IsRGBShader(format) && !src_full_range)
+    if (!IsRGBShader(quad->formatInfo) && !src_full_range)
         range_adjust--; /* the YUV->RGB conversion already output full range */
 
     if (range_adjust != 0)
@@ -517,7 +513,7 @@ HRESULT D3D11_CompilePixelShader(vlc_object_t *o, d3d11_handle_t *hd3d, bool leg
             FLOAT itu_black_level;
             FLOAT itu_range_factor;
             FLOAT itu_white_level;
-            switch (format->bitsPerChannel)
+            switch (quad->formatInfo->bitsPerChannel)
             {
             case 8:
                 /* Rec. ITU-R BT.709-6 ยง4.6 */
@@ -573,15 +569,15 @@ HRESULT D3D11_CompilePixelShader(vlc_object_t *o, d3d11_handle_t *hd3d, bool leg
         }
     }
 
-    HRESULT hr = CompileTargetShader(o, hd3d, legacy_shader, d3d_dev,
+    hr = CompileTargetShader(o, hd3d, legacy_shader, d3d_dev,
                                      psz_sampler[0], psz_src_transform,
                                      psz_display_transform, psz_tone_mapping,
-                                     psz_adjust_range, psz_move_planes[0], &output[0]);
+                                     psz_adjust_range, psz_move_planes[0], &quad->d3dpixelShader[0]);
     if (!FAILED(hr) && psz_sampler[1])
         hr = CompileTargetShader(o, hd3d, legacy_shader, d3d_dev,
                                  psz_sampler[1], psz_src_transform,
                                  psz_display_transform, psz_tone_mapping,
-                                 psz_adjust_range, psz_move_planes[1], &output[1]);
+                                 psz_adjust_range, psz_move_planes[1], &quad->d3dpixelShader[1]);
     free(psz_range);
 
     return hr;
diff --git a/modules/video_output/win32/d3d11_shaders.h b/modules/video_output/win32/d3d11_shaders.h
index 1a857dd48d..852da4fb3a 100644
--- a/modules/video_output/win32/d3d11_shaders.h
+++ b/modules/video_output/win32/d3d11_shaders.h
@@ -75,6 +75,32 @@ typedef struct {
 const char* globVertexShaderFlat;
 const char* globVertexShaderProjection;
 
+/* A Quad is texture that can be displayed in a rectangle */
+typedef struct
+{
+    picture_sys_t             picSys;
+    const d3d_format_t        *formatInfo;
+    UINT                      resourceCount;
+    ID3D11Buffer              *pVertexBuffer;
+    UINT                      vertexCount;
+    UINT                      vertexStride;
+    ID3D11VertexShader        *d3dvertexShader;
+    ID3D11Buffer              *pIndexBuffer;
+    UINT                      indexCount;
+    ID3D11Buffer              *pVertexShaderConstants;
+    ID3D11Buffer              *pPixelShaderConstants[2];
+    UINT                       PSConstantsCount;
+    ID3D11PixelShader         *d3dpixelShader[D3D11_MAX_SHADER_VIEW];
+    ID3D11SamplerState        *d3dsampState[2];
+    ID3D11InputLayout         *pVertexLayout;
+    D3D11_VIEWPORT            cropViewport[D3D11_MAX_SHADER_VIEW];
+    unsigned int              i_width;
+    unsigned int              i_height;
+    video_projection_mode_t   projection;
+
+    PS_CONSTANT_BUFFER        shaderConstants;
+} d3d_quad_t;
+
 ID3DBlob* D3D11_CompileShader(vlc_object_t *, const d3d11_handle_t *, const d3d11_device_t *,
                               const char *psz_shader, bool pixel);
 #define D3D11_CompileShader(a,b,c,d,e)  D3D11_CompileShader(VLC_OBJECT(a),b,c,d,e)
@@ -82,12 +108,11 @@ ID3DBlob* D3D11_CompileShader(vlc_object_t *, const d3d11_handle_t *, const d3d1
 bool IsRGBShader(const d3d_format_t *);
 
 HRESULT D3D11_CompilePixelShader(vlc_object_t *, d3d11_handle_t *, bool legacy_shader,
-                                 d3d11_device_t *, const d3d_format_t *, const display_info_t *,
+                                 d3d11_device_t *, const display_info_t *,
                                  video_transfer_func_t, bool src_full_range,
-                                 ID3D11PixelShader *output[D3D11_MAX_SHADER_VIEW],
-                                 ID3D11SamplerState *d3dsampState[2]);
-#define D3D11_CompilePixelShader(a,b,c,d,e,f,g,h,i,j) \
-    D3D11_CompilePixelShader(VLC_OBJECT(a),b,c,d,e,f,g,h,i,j)
+                                 d3d_quad_t *);
+#define D3D11_CompilePixelShader(a,b,c,d,e,f,g,h) \
+    D3D11_CompilePixelShader(VLC_OBJECT(a),b,c,d,e,f,g,h)
 
 float GetFormatLuminance(vlc_object_t *, const video_format_t *);
 #define GetFormatLuminance(a,b)  GetFormatLuminance(VLC_OBJECT(a),b)
diff --git a/modules/video_output/win32/direct3d11.c b/modules/video_output/win32/direct3d11.c
index 05db78427d..92a8139a6d 100644
--- a/modules/video_output/win32/direct3d11.c
+++ b/modules/video_output/win32/direct3d11.c
@@ -1401,8 +1401,8 @@ static int Direct3D11CreateFormatResources(vout_display_t *vd, const video_forma
     sys->legacy_shader = sys->d3d_dev.feature_level < D3D_FEATURE_LEVEL_10_0 || !CanUseTextureArray(vd);
 
     hr = D3D11_CompilePixelShader(vd, &sys->hd3d, sys->legacy_shader, &sys->d3d_dev,
-                                  sys->picQuad.formatInfo, &sys->display, fmt->transfer, fmt->b_color_range_full,
-                                  sys->picQuad.d3dpixelShader, sys->picQuad.d3dsampState);
+                                  &sys->display, fmt->transfer, fmt->b_color_range_full,
+                                  &sys->picQuad);
     if (FAILED(hr))
     {
         msg_Err(vd, "Failed to create the pixel shader. (hr=0x%lX)", hr);
@@ -1508,8 +1508,8 @@ static int Direct3D11CreateGenericResources(vout_display_t *vd)
     if (sys->regionQuad.formatInfo != NULL)
     {
         hr = D3D11_CompilePixelShader(vd, &sys->hd3d, sys->legacy_shader, &sys->d3d_dev,
-                                      sys->regionQuad.formatInfo, &sys->display, TRANSFER_FUNC_SRGB, true,
-                                      sys->regionQuad.d3dpixelShader, NULL);
+                                      &sys->display, TRANSFER_FUNC_SRGB, true,
+                                      &sys->regionQuad);
         if (FAILED(hr))
         {
             for (size_t i=0; i<D3D11_MAX_SHADER_VIEW; i++)



More information about the vlc-commits mailing list