[vlc-commits] direct3d11: separate pixel shader blob compilation from D3D11 pixel shader

Steve Lhomme git at videolan.org
Wed Feb 10 11:07:05 UTC 2021


vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Tue Feb  9 11:28:11 2021 +0100| [54af7504983183baa07b9ece76b6ea3c13ab9df8] | committer: Steve Lhomme

direct3d11: separate pixel shader blob compilation from D3D11 pixel shader

Now we can get the blobs from somewhere else and the code will work the same.

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

 modules/video_output/win32/d3d11_quad.c    | 10 +-----
 modules/video_output/win32/d3d11_shaders.c | 53 ++++++++++++++++--------------
 modules/video_output/win32/d3d11_shaders.h |  9 +++--
 modules/video_output/win32/direct3d11.c    | 27 +++++++++++----
 4 files changed, 57 insertions(+), 42 deletions(-)

diff --git a/modules/video_output/win32/d3d11_quad.c b/modules/video_output/win32/d3d11_quad.c
index 8633290c60..b8948b16da 100644
--- a/modules/video_output/win32/d3d11_quad.c
+++ b/modules/video_output/win32/d3d11_quad.c
@@ -157,15 +157,7 @@ void D3D11_ReleaseQuad(d3d11_quad_t *quad)
         ID3D11Buffer_Release(quad->viewpointShaderConstant);
         quad->viewpointShaderConstant = NULL;
     }
-    D3D11_ReleasePixelShader(quad);
-    for (size_t i=0; i<2; i++)
-    {
-        if (quad->SamplerStates[i])
-        {
-            ID3D11SamplerState_Release(quad->SamplerStates[i]);
-            quad->SamplerStates[i] = NULL;
-        }
-    }
+    D3D11_ReleaseQuadPixelShader(quad);
     ReleaseD3D11PictureSys(&quad->picSys);
 }
 
diff --git a/modules/video_output/win32/d3d11_shaders.c b/modules/video_output/win32/d3d11_shaders.c
index 39a407ee8a..29b22543e5 100644
--- a/modules/video_output/win32/d3d11_shaders.c
+++ b/modules/video_output/win32/d3d11_shaders.c
@@ -40,15 +40,22 @@
 #include "d3d_dynamic_shader.h"
 
 HRESULT (D3D11_CompilePixelShader)(vlc_object_t *o, const d3d_shader_compiler_t *compiler,
-                                 d3d11_device_t *d3d_dev,
-                                 bool texture_array,
-                                 const display_info_t *display, bool sharp,
-                                 video_transfer_func_t transfer,
-                                 video_color_primaries_t primaries, bool src_full_range,
-                                 d3d11_quad_t *quad)
+                                   d3d11_device_t *d3d_dev,
+                                   bool texture_array,
+                                   const display_info_t *display,
+                                   video_transfer_func_t transfer,
+                                   video_color_primaries_t primaries, bool src_full_range,
+                                   d3d11_quad_t *quad, d3d_shader_blob pPSBlob[DXGI_MAX_RENDER_TARGET])
 {
-    d3d_shader_blob pPSBlob[DXGI_MAX_RENDER_TARGET] = { 0 };
+    return D3D_CompilePixelShader(o, compiler, d3d_dev->feature_level, texture_array,
+                                  display, transfer, primaries,
+                                  src_full_range, quad->generic.textureFormat, pPSBlob);
+}
 
+HRESULT D3D11_SetQuadPixelShader(vlc_object_t *o, d3d11_device_t *d3d_dev,
+                                bool sharp,
+                                d3d11_quad_t *quad, d3d_shader_blob pPSBlob[DXGI_MAX_RENDER_TARGET])
+{
     D3D11_SAMPLER_DESC sampDesc;
     memset(&sampDesc, 0, sizeof(sampDesc));
     sampDesc.Filter = sharp ? D3D11_FILTER_MIN_MAG_MIP_POINT : D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT;
@@ -74,31 +81,24 @@ HRESULT (D3D11_CompilePixelShader)(vlc_object_t *o, const d3d_shader_compiler_t
         return hr;
     }
 
-    hr = D3D_CompilePixelShader(o, compiler, d3d_dev->feature_level, texture_array,
-                                display, transfer, primaries,
-                                src_full_range, quad->generic.textureFormat, pPSBlob);
+    hr = ID3D11Device_CreatePixelShader(d3d_dev->d3ddevice,
+                                        pPSBlob[0].buffer, pPSBlob[0].buf_size,
+                                        NULL, &quad->d3dpixelShader[0]);
+
+    D3D_ShaderBlobRelease(&pPSBlob[0]);
 
-    if (SUCCEEDED(hr))
+    if (pPSBlob[1].buffer)
     {
         hr = ID3D11Device_CreatePixelShader(d3d_dev->d3ddevice,
-                                            pPSBlob[0].buffer, pPSBlob[0].buf_size,
-                                            NULL, &quad->d3dpixelShader[0]);
+                                            pPSBlob[1].buffer, pPSBlob[1].buf_size,
+                                            NULL, &quad->d3dpixelShader[1]);
 
-        D3D_ShaderBlobRelease(&pPSBlob[0]);
-
-        if (pPSBlob[1].buffer)
-        {
-            hr = ID3D11Device_CreatePixelShader(d3d_dev->d3ddevice,
-                                                pPSBlob[1].buffer, pPSBlob[1].buf_size,
-                                                NULL, &quad->d3dpixelShader[1]);
-
-            D3D_ShaderBlobRelease(&pPSBlob[1]);
-        }
+        D3D_ShaderBlobRelease(&pPSBlob[1]);
     }
     return hr;
 }
 
-void D3D11_ReleasePixelShader(d3d11_quad_t *quad)
+void D3D11_ReleaseQuadPixelShader(d3d11_quad_t *quad)
 {
     for (size_t i=0; i<ARRAY_SIZE(quad->d3dpixelShader); i++)
     {
@@ -107,6 +107,11 @@ void D3D11_ReleasePixelShader(d3d11_quad_t *quad)
             ID3D11PixelShader_Release(quad->d3dpixelShader[i]);
             quad->d3dpixelShader[i] = NULL;
         }
+        if (quad->SamplerStates[i])
+        {
+            ID3D11SamplerState_Release(quad->SamplerStates[i]);
+            quad->SamplerStates[i] = NULL;
+        }
     }
 }
 
diff --git a/modules/video_output/win32/d3d11_shaders.h b/modules/video_output/win32/d3d11_shaders.h
index c0e4b87e2e..5ae094890b 100644
--- a/modules/video_output/win32/d3d11_shaders.h
+++ b/modules/video_output/win32/d3d11_shaders.h
@@ -55,13 +55,16 @@ typedef struct
 
 HRESULT D3D11_CompilePixelShader(vlc_object_t *, const d3d_shader_compiler_t *,
                                  d3d11_device_t *, bool texture_array,
-                                 const display_info_t *, bool sharp,
+                                 const display_info_t *,
                                  video_transfer_func_t, video_color_primaries_t,
                                  bool src_full_range,
-                                 d3d11_quad_t *);
+                                 d3d11_quad_t *, d3d_shader_blob pPSBlob[DXGI_MAX_RENDER_TARGET]);
 #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)
-void D3D11_ReleasePixelShader(d3d11_quad_t *);
+HRESULT D3D11_SetQuadPixelShader(vlc_object_t *, d3d11_device_t *,
+                                 bool sharp,
+                                 d3d11_quad_t *quad, d3d_shader_blob pPSBlob[DXGI_MAX_RENDER_TARGET]);
+void D3D11_ReleaseQuadPixelShader(d3d11_quad_t *);
 
 HRESULT D3D11_CompileFlatVertexShader(vlc_object_t *, const d3d_shader_compiler_t *, d3d11_device_t *, d3d11_vertex_shader_t *);
 #define D3D11_CompileFlatVertexShader(a,b,c,d) D3D11_CompileFlatVertexShader(VLC_OBJECT(a),b,c,d)
diff --git a/modules/video_output/win32/direct3d11.c b/modules/video_output/win32/direct3d11.c
index 2da3146735..ca1bb920ea 100644
--- a/modules/video_output/win32/direct3d11.c
+++ b/modules/video_output/win32/direct3d11.c
@@ -1035,13 +1035,21 @@ 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) ||
             BogusZeroCopy(vd) || !is_d3d11_opaque(fmt->i_chroma);
 
+    d3d_shader_blob pPSBlob[DXGI_MAX_RENDER_TARGET] = { 0 };
     hr = D3D11_CompilePixelShader(vd, &sys->shaders, sys->d3d_dev, !sys->legacy_shader,
-                                  &sys->display, false, fmt->transfer, fmt->primaries,
+                                  &sys->display, fmt->transfer, fmt->primaries,
                                   fmt->color_range == COLOR_RANGE_FULL,
-                                  &sys->picQuad);
+                                  &sys->picQuad, pPSBlob);
     if (FAILED(hr))
     {
-        msg_Err(vd, "Failed to create the pixel shader. (hr=0x%lX)", hr);
+        msg_Err(vd, "Failed to compile the pixel shader. (hr=0x%lX)", hr);
+        return VLC_EGENERIC;
+    }
+    hr = D3D11_SetQuadPixelShader(VLC_OBJECT(vd), sys->d3d_dev, false,
+                                  &sys->picQuad, pPSBlob);
+    if (FAILED(hr))
+    {
+        msg_Err(vd, "Failed to set the pixel shader. (hr=0x%lX)", hr);
         return VLC_EGENERIC;
     }
 
@@ -1176,12 +1184,19 @@ static int Direct3D11CreateGenericResources(vout_display_t *vd)
 
     if (sys->regionQuad.generic.textureFormat != NULL)
     {
+        d3d_shader_blob pPSBlob[DXGI_MAX_RENDER_TARGET] = { 0 };
         hr = D3D11_CompilePixelShader(vd, &sys->shaders, sys->d3d_dev, false,
-                                      &sys->display, true, TRANSFER_FUNC_SRGB, COLOR_PRIMARIES_SRGB, true,
-                                      &sys->regionQuad);
+                                      &sys->display, TRANSFER_FUNC_SRGB, COLOR_PRIMARIES_SRGB, true,
+                                      &sys->regionQuad, pPSBlob);
+        if (FAILED(hr))
+        {
+            msg_Err(vd, "Failed to create the SPU pixel shader. (hr=0x%lX)", hr);
+            return VLC_EGENERIC;
+        }
+        hr = D3D11_SetQuadPixelShader(VLC_OBJECT(vd), sys->d3d_dev, true,
+                                      &sys->regionQuad, pPSBlob);
         if (FAILED(hr))
         {
-            D3D11_ReleasePixelShader(&sys->picQuad);
             msg_Err(vd, "Failed to create the SPU pixel shader. (hr=0x%lX)", hr);
             return VLC_EGENERIC;
         }



More information about the vlc-commits mailing list