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

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


vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Tue Feb  9 11:49:31 2021 +0100| [21e6f915ff8fdad15baddc1653b1d1019d848835] | committer: Steve Lhomme

direct3d11: separate vertex shader blob compilation from D3D11 vertex 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=21e6f915ff8fdad15baddc1653b1d1019d848835
---

 modules/video_output/win32/d3d11_shaders.c | 59 ++++++++++++------------------
 modules/video_output/win32/d3d11_shaders.h |  8 ++--
 modules/video_output/win32/direct3d11.c    | 16 +++++++-
 3 files changed, 41 insertions(+), 42 deletions(-)

diff --git a/modules/video_output/win32/d3d11_shaders.c b/modules/video_output/win32/d3d11_shaders.c
index 29b22543e5..152e54982c 100644
--- a/modules/video_output/win32/d3d11_shaders.c
+++ b/modules/video_output/win32/d3d11_shaders.c
@@ -155,42 +155,35 @@ void D3D11_ClearRenderTargets(d3d11_device_t *d3d_dev, const d3d_format_t *cfg,
     }
 }
 
-static HRESULT CompileVertexShader(vlc_object_t *obj, const d3d_shader_compiler_t *compiler,
-                                   d3d11_device_t *d3d_dev, bool flat,
-                                   d3d11_vertex_shader_t *output)
+HRESULT (D3D11_CreateVertexShader)(vlc_object_t *obj, d3d_shader_blob *pVSBlob,
+                                   d3d11_device_t *d3d_dev, d3d11_vertex_shader_t *output)
 {
-    d3d_shader_blob pVSBlob = { 0 };
     HRESULT hr;
-    hr = D3D_CompileVertexShader(obj, compiler, d3d_dev->feature_level, flat, &pVSBlob);
-    if (FAILED(hr))
-        return hr;
-
-   hr = ID3D11Device_CreateVertexShader(d3d_dev->d3ddevice, pVSBlob.buffer,
-                                        pVSBlob.buf_size, NULL, &output->shader);
+    hr = ID3D11Device_CreateVertexShader(d3d_dev->d3ddevice, pVSBlob->buffer,
+                                         pVSBlob->buf_size, NULL, &output->shader);
 
-   if(FAILED(hr)) {
-       msg_Err(obj, "Failed to create the flat vertex shader. (hr=0x%lX)", hr);
-       goto error;
-   }
+    if(FAILED(hr)) {
+        msg_Err(obj, "Failed to create the flat vertex shader. (hr=0x%lX)", hr);
+        goto error;
+    }
 
     // must match d3d_vertex_t
-   static D3D11_INPUT_ELEMENT_DESC layout[] = {
-   { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0},
-   { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT,    0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0},
-   };
+    static D3D11_INPUT_ELEMENT_DESC layout[] = {
+        { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0},
+        { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT,    0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0},
+    };
 
-   hr = ID3D11Device_CreateInputLayout(d3d_dev->d3ddevice, layout, 2, pVSBlob.buffer,
-                                       pVSBlob.buf_size, &output->layout);
+    hr = ID3D11Device_CreateInputLayout(d3d_dev->d3ddevice, layout, 2, pVSBlob->buffer,
+                                    pVSBlob->buf_size, &output->layout);
 
-   if(FAILED(hr)) {
-       msg_Err(obj, "Failed to create the vertex input layout. (hr=0x%lX)", hr);
-       goto error;
-   }
+    if(FAILED(hr)) {
+        msg_Err(obj, "Failed to create the vertex input layout. (hr=0x%lX)", hr);
+        goto error;
+    }
 
-   return S_OK;
 error:
-   D3D_ShaderBlobRelease(&pVSBlob);
-   return hr;
+    D3D_ShaderBlobRelease(pVSBlob);
+    return hr;
 }
 
 void D3D11_ReleaseVertexShader(d3d11_vertex_shader_t *shader)
@@ -207,14 +200,8 @@ void D3D11_ReleaseVertexShader(d3d11_vertex_shader_t *shader)
     }
 }
 
-HRESULT (D3D11_CompileFlatVertexShader)(vlc_object_t *obj, const d3d_shader_compiler_t *compiler,
-                                      d3d11_device_t *d3d_dev, d3d11_vertex_shader_t *output)
-{
-    return CompileVertexShader(obj, compiler, d3d_dev, true, output);
-}
-
-HRESULT (D3D11_CompileProjectionVertexShader)(vlc_object_t *obj, const d3d_shader_compiler_t *compiler,
-                                            d3d11_device_t *d3d_dev, d3d11_vertex_shader_t *output)
+HRESULT D3D11_CompileVertexShaderBlob(vlc_object_t *obj, const d3d_shader_compiler_t *compiler,
+                                      d3d11_device_t *d3d_dev, bool flat, d3d_shader_blob *pVSBlob)
 {
-    return CompileVertexShader(obj, compiler, d3d_dev, false, output);
+    return D3D_CompileVertexShader(obj, compiler, d3d_dev->feature_level, flat, pVSBlob);
 }
diff --git a/modules/video_output/win32/d3d11_shaders.h b/modules/video_output/win32/d3d11_shaders.h
index 5ae094890b..7cd3e93e05 100644
--- a/modules/video_output/win32/d3d11_shaders.h
+++ b/modules/video_output/win32/d3d11_shaders.h
@@ -66,11 +66,11 @@ HRESULT D3D11_SetQuadPixelShader(vlc_object_t *, d3d11_device_t *,
                                  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)
+HRESULT D3D11_CompileVertexShaderBlob(vlc_object_t *, const d3d_shader_compiler_t *,
+                                      d3d11_device_t *, bool flat, d3d_shader_blob *);
 
-HRESULT D3D11_CompileProjectionVertexShader(vlc_object_t *, const d3d_shader_compiler_t *, d3d11_device_t *, d3d11_vertex_shader_t *);
-#define D3D11_CompileProjectionVertexShader(a,b,c,d) D3D11_CompileProjectionVertexShader(VLC_OBJECT(a),b,c,d)
+HRESULT D3D11_CreateVertexShader(vlc_object_t *, d3d_shader_blob *, d3d11_device_t *, d3d11_vertex_shader_t *);
+#define D3D11_CreateVertexShader(a,b,c,d) D3D11_CreateVertexShader(VLC_OBJECT(a),b,c,d)
 
 HRESULT D3D11_CreateRenderTargets(d3d11_device_t *, ID3D11Resource *, const d3d_format_t *,
                                   ID3D11RenderTargetView *output[DXGI_MAX_RENDER_TARGET]);
diff --git a/modules/video_output/win32/direct3d11.c b/modules/video_output/win32/direct3d11.c
index ca1bb920ea..0fe64e0959 100644
--- a/modules/video_output/win32/direct3d11.c
+++ b/modules/video_output/win32/direct3d11.c
@@ -1202,13 +1202,25 @@ static int Direct3D11CreateGenericResources(vout_display_t *vd)
         }
     }
 
-    hr = D3D11_CompileFlatVertexShader(vd, &sys->shaders, sys->d3d_dev, &sys->flatVShader);
+    d3d_shader_blob VSBlob = { 0 };
+    hr = D3D11_CompileVertexShaderBlob(VLC_OBJECT(vd), &sys->shaders, sys->d3d_dev, true, &VSBlob);
+    if(FAILED(hr)) {
+      msg_Err(vd, "Failed to compile the flat vertex shader. (hr=0x%lX)", hr);
+      return VLC_EGENERIC;
+    }
+    hr = D3D11_CreateVertexShader(vd, &VSBlob, sys->d3d_dev, &sys->flatVShader);
     if(FAILED(hr)) {
       msg_Err(vd, "Failed to create the vertex input layout. (hr=0x%lX)", hr);
       return VLC_EGENERIC;
     }
 
-    hr = D3D11_CompileProjectionVertexShader(vd, &sys->shaders, sys->d3d_dev, &sys->projectionVShader);
+
+    hr = D3D11_CompileVertexShaderBlob(VLC_OBJECT(vd), &sys->shaders, sys->d3d_dev, false, &VSBlob);
+    if(FAILED(hr)) {
+      msg_Err(vd, "Failed to compile the 360 vertex shader. (hr=0x%lX)", hr);
+      return VLC_EGENERIC;
+    }
+    hr = D3D11_CreateVertexShader(vd, &VSBlob, sys->d3d_dev, &sys->projectionVShader);
     if(FAILED(hr)) {
       msg_Err(vd, "Failed to create the projection vertex shader. (hr=0x%lX)", hr);
       return VLC_EGENERIC;



More information about the vlc-commits mailing list