[vlc-commits] direct3d11: add a helper to create a flat pixel shader

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


vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Fri Jul 13 13:10:29 2018 +0200| [2e0b9970a120ea55346681f3776de91b326321f0] | committer: Steve Lhomme

direct3d11: add a helper to create a flat pixel shader

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

 modules/video_output/win32/d3d11_shaders.c | 38 ++++++++++++++++++++++++++++++
 modules/video_output/win32/d3d11_shaders.h |  3 +++
 modules/video_output/win32/direct3d11.c    | 25 ++------------------
 3 files changed, 43 insertions(+), 23 deletions(-)

diff --git a/modules/video_output/win32/d3d11_shaders.c b/modules/video_output/win32/d3d11_shaders.c
index 0fa67013ce..a5ff626358 100644
--- a/modules/video_output/win32/d3d11_shaders.c
+++ b/modules/video_output/win32/d3d11_shaders.c
@@ -699,3 +699,41 @@ void D3D11_ClearRenderTargets(d3d11_device_t *d3d_dev, const d3d_format_t *cfg,
         vlc_assert_unreachable();
     }
 }
+
+#undef D3D11_CompileFlatVertexShader
+HRESULT D3D11_CompileFlatVertexShader(vlc_object_t *obj, d3d11_handle_t *hd3d,
+                                      d3d11_device_t *d3d_dev, d3d_quad_t *quad)
+{
+    HRESULT hr;
+    ID3DBlob *pVSBlob = D3D11_CompileShader(obj, hd3d, d3d_dev, globVertexShaderFlat, false);
+    if (!pVSBlob)
+        goto error;
+
+    hr = ID3D11Device_CreateVertexShader(d3d_dev->d3ddevice, (void *)ID3D10Blob_GetBufferPointer(pVSBlob),
+                                         ID3D10Blob_GetBufferSize(pVSBlob), NULL, &quad->d3dvertexShader);
+
+    if(FAILED(hr)) {
+        msg_Err(obj, "Failed to create the flat vertex shader. (hr=0x%lX)", hr);
+        goto error;
+    }
+
+    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, (void *)ID3D10Blob_GetBufferPointer(pVSBlob),
+                                        ID3D10Blob_GetBufferSize(pVSBlob), &quad->pVertexLayout);
+
+    ID3D10Blob_Release(pVSBlob);
+    pVSBlob = NULL;
+    if(FAILED(hr)) {
+        msg_Err(obj, "Failed to create the vertex input layout. (hr=0x%lX)", hr);
+        goto error;
+    }
+
+    return S_OK;
+error:
+    return hr;
+}
+
diff --git a/modules/video_output/win32/d3d11_shaders.h b/modules/video_output/win32/d3d11_shaders.h
index 852da4fb3a..bdf363322d 100644
--- a/modules/video_output/win32/d3d11_shaders.h
+++ b/modules/video_output/win32/d3d11_shaders.h
@@ -114,6 +114,9 @@ HRESULT D3D11_CompilePixelShader(vlc_object_t *, d3d11_handle_t *, bool legacy_s
 #define D3D11_CompilePixelShader(a,b,c,d,e,f,g,h) \
     D3D11_CompilePixelShader(VLC_OBJECT(a),b,c,d,e,f,g,h)
 
+HRESULT D3D11_CompileFlatVertexShader(vlc_object_t *, d3d11_handle_t *, d3d11_device_t *, d3d_quad_t *);
+#define D3D11_CompileFlatVertexShader(a,b,c,d) D3D11_CompileFlatVertexShader(VLC_OBJECT(a),b,c,d)
+
 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 a38672dbaa..4caa92775f 100644
--- a/modules/video_output/win32/direct3d11.c
+++ b/modules/video_output/win32/direct3d11.c
@@ -1523,34 +1523,13 @@ static int Direct3D11CreateGenericResources(vout_display_t *vd)
         }
     }
 
-    ID3DBlob *pVSBlob = D3D11_CompileShader(vd, &sys->hd3d, &sys->d3d_dev, globVertexShaderFlat, false);
-    if (!pVSBlob)
-        return VLC_EGENERIC;
-
-    hr = ID3D11Device_CreateVertexShader(sys->d3d_dev.d3ddevice, (void *)ID3D10Blob_GetBufferPointer(pVSBlob),
-                                        ID3D10Blob_GetBufferSize(pVSBlob), NULL, &sys->regionQuad.d3dvertexShader);
-
-    if(FAILED(hr)) {
-      ID3D10Blob_Release(pVSBlob);
-      msg_Err(vd, "Failed to create the flat vertex shader. (hr=0x%lX)", hr);
-      return VLC_EGENERIC;
-    }
-
-    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(sys->d3d_dev.d3ddevice, layout, 2, (void *)ID3D10Blob_GetBufferPointer(pVSBlob),
-                                        ID3D10Blob_GetBufferSize(pVSBlob), &sys->regionQuad.pVertexLayout);
-
-    ID3D10Blob_Release(pVSBlob);
-
+    hr = D3D11_CompileFlatVertexShader(vd, &sys->hd3d, &sys->d3d_dev, &sys->regionQuad);
     if(FAILED(hr)) {
       msg_Err(vd, "Failed to create the vertex input layout. (hr=0x%lX)", hr);
       return VLC_EGENERIC;
     }
 
+    ID3DBlob *pVSBlob;
     pVSBlob = D3D11_CompileShader(vd, &sys->hd3d, &sys->d3d_dev, globVertexShaderProjection, false);
     if (!pVSBlob)
         return VLC_EGENERIC;



More information about the vlc-commits mailing list