From 32fc4c76765a9a095e2bf99d37592198a4c3d463 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Fri, 26 Sep 2014 21:32:22 -0700 Subject: [PATCH] d3d9: Try harder to get a shader compile error. --- Common/CommonFuncs.h | 3 ++- Common/Misc.cpp | 20 ++++++++++++++++---- GPU/Directx9/helper/global.cpp | 33 +++++++++++++++++---------------- 3 files changed, 35 insertions(+), 21 deletions(-) diff --git a/Common/CommonFuncs.h b/Common/CommonFuncs.h index d9f9d219e5..049aa8c42b 100644 --- a/Common/CommonFuncs.h +++ b/Common/CommonFuncs.h @@ -98,5 +98,6 @@ extern "C" { // Call directly after the command or use the error num. // This function might change the error code. // Defined in Misc.cpp. -const char* GetLastErrorMsg(); +const char *GetLastErrorMsg(); +const char *GetStringErrorMsg(int errCode); diff --git a/Common/Misc.cpp b/Common/Misc.cpp index 3750bf19a7..f5393cc1f9 100644 --- a/Common/Misc.cpp +++ b/Common/Misc.cpp @@ -30,25 +30,37 @@ // Generic function to get last error message. // Call directly after the command or use the error num. // This function might change the error code. -const char* GetLastErrorMsg() +const char *GetLastErrorMsg() { +#ifndef _XBOX +#ifdef _WIN32 + return GetStringErrorMsg(GetLastError()); +#else + return GetStringErrorMsg(errno); +#endif +#else + return "GetLastErrorMsg"; +#endif +} + +const char *GetStringErrorMsg(int errCode) { static const size_t buff_size = 255; #ifndef _XBOX #ifdef _WIN32 static __declspec(thread) char err_str[buff_size] = {}; - FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), + FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), err_str, buff_size, NULL); #else static __thread char err_str[buff_size] = {}; // Thread safe (XSI-compliant) - strerror_r(errno, err_str, buff_size); + strerror_r(errCode, err_str, buff_size); #endif return err_str; #else - return "GetLastErrorMsg"; + return "GetStringErrorMsg"; #endif } diff --git a/GPU/Directx9/helper/global.cpp b/GPU/Directx9/helper/global.cpp index dbe08ff789..93940164ab 100644 --- a/GPU/Directx9/helper/global.cpp +++ b/GPU/Directx9/helper/global.cpp @@ -1,6 +1,7 @@ #include "global.h" #include "fbo.h" #include "thin3d/d3dx9_loader.h" +#include "Common/CommonFuncs.h" namespace DX9 { @@ -60,16 +61,14 @@ LPDIRECT3DVERTEXSHADER9 pFramebufferVertexShader = NULL; // Vertex Shader LPDIRECT3DPIXELSHADER9 pFramebufferPixelShader = NULL; // Pixel Shader bool CompilePixelShader(const char *code, LPDIRECT3DPIXELSHADER9 *pShader, LPD3DXCONSTANTTABLE *pShaderTable, std::string &errorMessage) { - ID3DXBuffer* pShaderCode = NULL; - ID3DXBuffer* pErrorMsg = NULL; - - HRESULT hr = E_FAIL; + ID3DXBuffer *pShaderCode = nullptr; + ID3DXBuffer *pErrorMsg = nullptr; // Compile pixel shader. - hr = dyn_D3DXCompileShader(code, + HRESULT hr = dyn_D3DXCompileShader(code, (UINT)strlen(code), - NULL, - NULL, + nullptr, + nullptr, "main", "ps_2_0", 0, @@ -80,11 +79,13 @@ bool CompilePixelShader(const char *code, LPDIRECT3DPIXELSHADER9 *pShader, LPD3D if (pErrorMsg) { errorMessage = (CHAR *)pErrorMsg->GetBufferPointer(); pErrorMsg->Release(); + } else if (FAILED(hr)) { + errorMessage = GetStringErrorMsg(hr); } else { errorMessage = ""; } - if (FAILED(hr)) { + if (FAILED(hr) || !pShaderCode) { if (pShaderCode) pShaderCode->Release(); return false; @@ -100,16 +101,14 @@ bool CompilePixelShader(const char *code, LPDIRECT3DPIXELSHADER9 *pShader, LPD3D } bool CompileVertexShader(const char *code, LPDIRECT3DVERTEXSHADER9 *pShader, LPD3DXCONSTANTTABLE *pShaderTable, std::string &errorMessage) { - ID3DXBuffer* pShaderCode = NULL; - ID3DXBuffer* pErrorMsg = NULL; - - HRESULT hr = E_FAIL; + ID3DXBuffer *pShaderCode = nullptr; + ID3DXBuffer *pErrorMsg = nullptr; // Compile pixel shader. - hr = dyn_D3DXCompileShader(code, + HRESULT hr = dyn_D3DXCompileShader(code, (UINT)strlen(code), - NULL, - NULL, + nullptr, + nullptr, "main", "vs_2_0", 0, @@ -120,11 +119,13 @@ bool CompileVertexShader(const char *code, LPDIRECT3DVERTEXSHADER9 *pShader, LPD if (pErrorMsg) { errorMessage = (CHAR *)pErrorMsg->GetBufferPointer(); pErrorMsg->Release(); + } else if (FAILED(hr)) { + errorMessage = GetStringErrorMsg(hr); } else { errorMessage = ""; } - if (FAILED(hr)) { + if (FAILED(hr) || !pShaderCode) { if (pShaderCode) pShaderCode->Release(); return false;