[vlc-devel] [PATCH 25/29] direct3d11: factorize the shader compilation code
Steve Lhomme
robux4 at videolabs.io
Thu Jan 19 11:11:00 CET 2017
Log the error when the compilation fails
---
modules/video_output/win32/direct3d11.c | 122 ++++++++++++++++----------------
1 file changed, 61 insertions(+), 61 deletions(-)
diff --git a/modules/video_output/win32/direct3d11.c b/modules/video_output/win32/direct3d11.c
index 0654096..4b466e2 100644
--- a/modules/video_output/win32/direct3d11.c
+++ b/modules/video_output/win32/direct3d11.c
@@ -1425,6 +1425,42 @@ static void UpdatePicQuadPosition(vout_display_t *vd)
#endif
}
+static ID3DBlob* CompileShader(vout_display_t *vd, const char *psz_shader, bool pixel)
+{
+ vout_display_sys_t *sys = vd->sys;
+ ID3DBlob* pShaderBlob = NULL, *pErrBlob;
+
+ /* TODO : Match the version to the D3D_FEATURE_LEVEL */
+ HRESULT hr = D3DCompile(psz_shader, strlen(psz_shader),
+ NULL, NULL, NULL, pixel ? "PS" : "VS",
+ pixel ? "ps_4_0_level_9_1" : "vs_4_0_level_9_1",
+ 0, 0, &pShaderBlob, &pErrBlob);
+
+ if (FAILED(hr)) {
+ char *err = pErrBlob ? ID3D10Blob_GetBufferPointer(pErrBlob) : NULL;
+ msg_Err(vd, "invalid %s Shader (hr=0x%lX): %s", pixel?"Pixel":"Vertex", hr, err );
+ if (pErrBlob)
+ ID3D10Blob_Release(pErrBlob);
+ return NULL;
+ }
+ return pShaderBlob;
+}
+
+static HRESULT CompilePixelShader(vout_display_t *vd, const char *psz_shader, ID3D11PixelShader **output)
+{
+ vout_display_sys_t *sys = vd->sys;
+ ID3DBlob *pPSBlob = CompileShader(vd, psz_shader, true);
+ if (!pPSBlob)
+ return E_INVALIDARG;
+
+ HRESULT hr = ID3D11Device_CreatePixelShader(sys->d3ddevice,
+ (void *)ID3D10Blob_GetBufferPointer(pPSBlob),
+ ID3D10Blob_GetBufferSize(pPSBlob), NULL, output);
+
+ ID3D10Blob_Release(pPSBlob);
+ return hr;
+}
+
/* TODO : handle errors better
TODO : seperate out into smaller functions like createshaders */
static int Direct3D11CreateResources(vout_display_t *vd, video_format_t *fmt)
@@ -1488,16 +1524,29 @@ static int Direct3D11CreateResources(vout_display_t *vd, video_format_t *fmt)
ID3D11DepthStencilState_Release(pDepthStencilState);
}
- ID3DBlob* pVSBlob = NULL;
- /* TODO : Match the version to the D3D_FEATURE_LEVEL */
- hr = D3DCompile(globVertexShaderFlat, strlen(globVertexShaderFlat),
- NULL, NULL, NULL, "VS", "vs_4_0_level_9_1", 0, 0, &pVSBlob, NULL);
+ ID3D11PixelShader *pPicQuadShader;
+ hr = CompilePixelShader(vd, sys->d3dPxShader, &pPicQuadShader);
+ if (FAILED(hr))
+ {
+ msg_Err(vd, "Failed to create the pixel shader. (hr=0x%lX)", hr);
+ return VLC_EGENERIC;
+ }
- if( FAILED(hr)) {
- msg_Err(vd, "The flat Vertex Shader is invalid. (hr=0x%lX)", hr);
- return VLC_EGENERIC;
+ if (sys->psz_rgbaPxShader != NULL)
+ {
+ hr = CompilePixelShader(vd, sys->psz_rgbaPxShader, &sys->pSPUPixelShader);
+ if (FAILED(hr))
+ {
+ ID3D11PixelShader_Release(pPicQuadShader);
+ msg_Err(vd, "Failed to create the SPU pixel shader. (hr=0x%lX)", hr);
+ return VLC_EGENERIC;
+ }
}
+ ID3DBlob *pVSBlob = CompileShader(vd, globVertexShaderFlat , false);
+ if (!pVSBlob)
+ return VLC_EGENERIC;
+
hr = ID3D11Device_CreateVertexShader(sys->d3ddevice, (void *)ID3D10Blob_GetBufferPointer(pVSBlob),
ID3D10Blob_GetBufferSize(pVSBlob), NULL, &sys->flatVSShader);
@@ -1524,14 +1573,10 @@ static int Direct3D11CreateResources(vout_display_t *vd, video_format_t *fmt)
}
ID3D11DeviceContext_IASetInputLayout(sys->d3dcontext, pVertexLayout);
ID3D11InputLayout_Release(pVertexLayout);
-
- hr = D3DCompile(globVertexShaderProjection, strlen(globVertexShaderProjection),
- NULL, NULL, NULL, "VS", "vs_4_0_level_9_1", 0, 0, &pVSBlob, NULL);
- if( FAILED(hr)) {
- msg_Err(vd, "The projection Vertex Shader is invalid. (hr=0x%lX)", hr);
- return VLC_EGENERIC;
- }
+ pVSBlob = CompileShader(vd, globVertexShaderProjection, false);
+ if (!pVSBlob)
+ return VLC_EGENERIC;
hr = ID3D11Device_CreateVertexShader(sys->d3ddevice, (void *)ID3D10Blob_GetBufferPointer(pVSBlob),
ID3D10Blob_GetBufferSize(pVSBlob), NULL, &sys->projectionVSShader);
@@ -1543,53 +1588,6 @@ static int Direct3D11CreateResources(vout_display_t *vd, video_format_t *fmt)
}
ID3D10Blob_Release(pVSBlob);
- ID3D11DeviceContext_IASetPrimitiveTopology(sys->d3dcontext, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
-
- ID3DBlob* pPSBlob = NULL;
-
- /* TODO : Match the version to the D3D_FEATURE_LEVEL */
- hr = D3DCompile(sys->d3dPxShader, strlen(sys->d3dPxShader),
- NULL, NULL, NULL, "PS", "ps_4_0_level_9_1", 0, 0, &pPSBlob, NULL);
-
-
- if( FAILED(hr)) {
- msg_Err(vd, "The Pixel Shader is invalid. (hr=0x%lX)", hr );
- return VLC_EGENERIC;
- }
-
- ID3D11PixelShader *pPicQuadShader;
- hr = ID3D11Device_CreatePixelShader(sys->d3ddevice, (void *)ID3D10Blob_GetBufferPointer(pPSBlob),
- ID3D10Blob_GetBufferSize(pPSBlob), NULL, &pPicQuadShader);
-
- ID3D10Blob_Release(pPSBlob);
-
- if(FAILED(hr)) {
- msg_Err(vd, "Failed to create the pixel shader. (hr=0x%lX)", hr);
- return VLC_EGENERIC;
- }
-
- if (sys->psz_rgbaPxShader != NULL)
- {
- hr = D3DCompile(sys->psz_rgbaPxShader, strlen(sys->psz_rgbaPxShader),
- NULL, NULL, NULL, "PS", "ps_4_0_level_9_1", 0, 0, &pPSBlob, NULL);
- if( FAILED(hr)) {
- ID3D11PixelShader_Release(pPicQuadShader);
- msg_Err(vd, "The RGBA Pixel Shader is invalid. (hr=0x%lX)", hr );
- return VLC_EGENERIC;
- }
-
- hr = ID3D11Device_CreatePixelShader(sys->d3ddevice, (void *)ID3D10Blob_GetBufferPointer(pPSBlob),
- ID3D10Blob_GetBufferSize(pPSBlob), NULL, &sys->pSPUPixelShader);
-
- ID3D10Blob_Release(pPSBlob);
-
- if(FAILED(hr)) {
- ID3D11PixelShader_Release(pPicQuadShader);
- msg_Err(vd, "Failed to create the SPU pixel shader. (hr=0x%lX)", hr);
- return VLC_EGENERIC;
- }
- }
-
if (AllocQuad( vd, fmt, &sys->picQuad, sys->picQuadConfig, pPicQuadShader,
true, vd->fmt.projection_mode) != VLC_SUCCESS) {
ID3D11PixelShader_Release(pPicQuadShader);
@@ -1598,6 +1596,8 @@ static int Direct3D11CreateResources(vout_display_t *vd, video_format_t *fmt)
}
ID3D11PixelShader_Release(pPicQuadShader);
+ ID3D11DeviceContext_IASetPrimitiveTopology(sys->d3dcontext, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
+
video_format_t core_source;
CropStagingFormat( vd, &core_source );
UpdatePicQuadPosition(vd);
--
2.10.2
More information about the vlc-devel
mailing list