[vlc-commits] direct3d11: add a helper to create a projection d3d_quad

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


vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Fri Jul 13 13:19:51 2018 +0200| [19ef2aa90de3ab0d0fc79462e1706ec2883c3108] | committer: Steve Lhomme

direct3d11: add a helper to create a projection d3d_quad

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

 modules/video_output/win32/d3d11_shaders.c | 74 +++++++++++++++++-------------
 modules/video_output/win32/d3d11_shaders.h |  3 ++
 modules/video_output/win32/direct3d11.c    | 11 +----
 3 files changed, 47 insertions(+), 41 deletions(-)

diff --git a/modules/video_output/win32/d3d11_shaders.c b/modules/video_output/win32/d3d11_shaders.c
index a5ff626358..a16f47f455 100644
--- a/modules/video_output/win32/d3d11_shaders.c
+++ b/modules/video_output/win32/d3d11_shaders.c
@@ -700,40 +700,52 @@ void D3D11_ClearRenderTargets(d3d11_device_t *d3d_dev, const d3d_format_t *cfg,
     }
 }
 
+static HRESULT D3D11_CompileVertexShader(vlc_object_t *obj, d3d11_handle_t *hd3d,
+                                         d3d11_device_t *d3d_dev, const char *psz_shader, d3d_quad_t *quad)
+{
+   HRESULT hr;
+   ID3DBlob *pVSBlob = D3D11_CompileShader(obj, hd3d, d3d_dev, psz_shader, 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;
+}
+
 #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;
+    return D3D11_CompileVertexShader(obj, hd3d, d3d_dev, globVertexShaderFlat, quad);
 }
 
+#undef D3D11_CompileProjectionVertexShader
+HRESULT D3D11_CompileProjectionVertexShader(vlc_object_t *obj, d3d11_handle_t *hd3d,
+                                            d3d11_device_t *d3d_dev, d3d_quad_t *quad)
+{
+    return D3D11_CompileVertexShader(obj, hd3d, d3d_dev, globVertexShaderProjection, quad);
+}
diff --git a/modules/video_output/win32/d3d11_shaders.h b/modules/video_output/win32/d3d11_shaders.h
index bdf363322d..dc8266c892 100644
--- a/modules/video_output/win32/d3d11_shaders.h
+++ b/modules/video_output/win32/d3d11_shaders.h
@@ -117,6 +117,9 @@ HRESULT D3D11_CompilePixelShader(vlc_object_t *, d3d11_handle_t *, bool legacy_s
 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)
 
+HRESULT D3D11_CompileProjectionVertexShader(vlc_object_t *, d3d11_handle_t *, d3d11_device_t *, d3d_quad_t *);
+#define D3D11_CompileProjectionVertexShader(a,b,c,d) D3D11_CompileProjectionVertexShader(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 4e8d3bdb91..693503cdf0 100644
--- a/modules/video_output/win32/direct3d11.c
+++ b/modules/video_output/win32/direct3d11.c
@@ -1529,20 +1529,11 @@ static int Direct3D11CreateGenericResources(vout_display_t *vd)
       return VLC_EGENERIC;
     }
 
-    ID3DBlob *pVSBlob;
-    pVSBlob = D3D11_CompileShader(vd, &sys->hd3d, &sys->d3d_dev, globVertexShaderProjection, false);
-    if (!pVSBlob)
-        return VLC_EGENERIC;
-
-    hr = ID3D11Device_CreateVertexShader(sys->d3d_dev.d3ddevice, (void *)ID3D10Blob_GetBufferPointer(pVSBlob),
-                                        ID3D10Blob_GetBufferSize(pVSBlob), NULL, &sys->projectionQuad.d3dvertexShader);
-
+    hr = D3D11_CompileProjectionVertexShader(vd, &sys->hd3d, &sys->d3d_dev, &sys->projectionQuad);
     if(FAILED(hr)) {
-      ID3D10Blob_Release(pVSBlob);
       msg_Err(vd, "Failed to create the projection vertex shader. (hr=0x%lX)", hr);
       return VLC_EGENERIC;
     }
-    ID3D10Blob_Release(pVSBlob);
 
     UpdatePicQuadPosition(vd);
 



More information about the vlc-commits mailing list