GSDX: Added some exceptions on shader compilation failure (with handlers in entry points because people seem to like the plugin struggling on even when nothing works any more) because I am not keen crashing Windows via my graphics driver.

git-svn-id: http://pcsx2.googlecode.com/svn/trunk@5284 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
sudonim1@gmail.com 2012-06-11 02:31:44 +00:00
parent 17f28b24b3
commit 08d8287d3e
5 changed files with 189 additions and 125 deletions

View File

@ -422,130 +422,209 @@ EXPORT_C_(int) GSopen(void** dsp, char* title, int mt)
EXPORT_C GSreset()
{
s_gs->Reset();
try
{
s_gs->Reset();
}
catch (GSDXRecoverableError)
{
}
}
EXPORT_C GSgifSoftReset(uint32 mask)
{
s_gs->SoftReset(mask);
try
{
s_gs->SoftReset(mask);
}
catch (GSDXRecoverableError)
{
}
}
EXPORT_C GSwriteCSR(uint32 csr)
{
s_gs->WriteCSR(csr);
try
{
s_gs->WriteCSR(csr);
}
catch (GSDXRecoverableError)
{
}
}
EXPORT_C GSreadFIFO(uint8* mem)
{
try
{
#ifdef _LINUX
// FIXME: double check which thread call this function
// See fifo2 issue below
if (theApp.GetConfig("renderer", 0) / 3 == 4) {
fprintf(stderr, "Disable FIFO1 on opengl\n");
// FIXME: double check which thread call this function
// See fifo2 issue below
if (theApp.GetConfig("renderer", 0) / 3 == 4) {
fprintf(stderr, "Disable FIFO1 on opengl\n");
}
s_gs->m_wnd.AttachContext();
#endif
s_gs->ReadFIFO(mem, 1);
#ifdef _LINUX
s_gs->m_wnd.DetachContext();
#endif
}
catch (GSDXRecoverableError)
{
}
s_gs->m_wnd.AttachContext();
#endif
s_gs->ReadFIFO(mem, 1);
#ifdef _LINUX
s_gs->m_wnd.DetachContext();
#endif
}
EXPORT_C GSreadFIFO2(uint8* mem, uint32 size)
{
try
{
#ifdef _LINUX
// FIXME called from EE core thread not MTGS which cause
// invalidate data for opengl
if (theApp.GetConfig("renderer", 0) / 3 == 4) {
// FIXME called from EE core thread not MTGS which cause
// invalidate data for opengl
if (theApp.GetConfig("renderer", 0) / 3 == 4) {
#ifdef OGL_DEBUG
fprintf(stderr, "Disable FIFO2(%d) on opengl\n", size);
fprintf(stderr, "Disable FIFO2(%d) on opengl\n", size);
#endif
//return;
}
s_gs->m_wnd.AttachContext();
//return;
}
s_gs->m_wnd.AttachContext();
#endif
s_gs->ReadFIFO(mem, size);
s_gs->ReadFIFO(mem, size);
#ifdef _LINUX
s_gs->m_wnd.DetachContext();
s_gs->m_wnd.DetachContext();
#endif
}
catch (GSDXRecoverableError)
{
}
}
EXPORT_C GSgifTransfer(const uint8* mem, uint32 size)
{
s_gs->Transfer<3>(mem, size);
try
{
s_gs->Transfer<3>(mem, size);
}
catch (GSDXRecoverableError)
{
}
}
EXPORT_C GSgifTransfer1(uint8* mem, uint32 addr)
{
s_gs->Transfer<0>(const_cast<uint8*>(mem) + addr, (0x4000 - addr) / 16);
try
{
s_gs->Transfer<0>(const_cast<uint8*>(mem) + addr, (0x4000 - addr) / 16);
}
catch (GSDXRecoverableError)
{
}
}
EXPORT_C GSgifTransfer2(uint8* mem, uint32 size)
{
s_gs->Transfer<1>(const_cast<uint8*>(mem), size);
try
{
s_gs->Transfer<1>(const_cast<uint8*>(mem), size);
}
catch (GSDXRecoverableError)
{
}
}
EXPORT_C GSgifTransfer3(uint8* mem, uint32 size)
{
s_gs->Transfer<2>(const_cast<uint8*>(mem), size);
try
{
s_gs->Transfer<2>(const_cast<uint8*>(mem), size);
}
catch (GSDXRecoverableError)
{
}
}
EXPORT_C GSvsync(int field)
{
try
{
#ifdef _WINDOWS
if(s_gs->m_wnd.IsManaged())
{
MSG msg;
memset(&msg, 0, sizeof(msg));
while(msg.message != WM_QUIT && PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
if(s_gs->m_wnd.IsManaged())
{
TranslateMessage(&msg);
DispatchMessage(&msg);
MSG msg;
memset(&msg, 0, sizeof(msg));
while(msg.message != WM_QUIT && PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
#endif
s_gs->VSync(field);
s_gs->VSync(field);
}
catch (GSDXRecoverableError)
{
}
}
EXPORT_C_(uint32) GSmakeSnapshot(char* path)
{
string s(path);
if(!s.empty() && s[s.length() - 1] != DIRECTORY_SEPARATOR)
try
{
s = s + DIRECTORY_SEPARATOR;
}
string s(path);
return s_gs->MakeSnapshot(s + "gsdx");
if(!s.empty() && s[s.length() - 1] != DIRECTORY_SEPARATOR)
{
s = s + DIRECTORY_SEPARATOR;
}
return s_gs->MakeSnapshot(s + "gsdx");
}
catch (GSDXRecoverableError)
{
return false;
}
}
EXPORT_C GSkeyEvent(GSKeyEventData* e)
{
s_gs->KeyEvent(e);
try
{
s_gs->KeyEvent(e);
}
catch (GSDXRecoverableError)
{
}
}
EXPORT_C_(int) GSfreeze(int mode, GSFreezeData* data)
{
if(mode == FREEZE_SAVE)
try
{
return s_gs->Freeze(data, false);
if(mode == FREEZE_SAVE)
{
return s_gs->Freeze(data, false);
}
else if(mode == FREEZE_SIZE)
{
return s_gs->Freeze(data, true);
}
else if(mode == FREEZE_LOAD)
{
return s_gs->Defrost(data);
}
}
else if(mode == FREEZE_SIZE)
catch (GSDXRecoverableError)
{
return s_gs->Freeze(data, true);
}
else if(mode == FREEZE_LOAD)
{
return s_gs->Defrost(data);
}
return 0;
@ -553,32 +632,37 @@ EXPORT_C_(int) GSfreeze(int mode, GSFreezeData* data)
EXPORT_C GSconfigure()
{
if(!GSUtil::CheckSSE()) return;
try
{
if(!GSUtil::CheckSSE()) return;
#ifdef _WINDOWS
if(GSSettingsDlg(s_isgsopen2).DoModal() == IDOK)
{
if(s_gs != NULL && s_gs->m_wnd.IsManaged())
if(GSSettingsDlg(s_isgsopen2).DoModal() == IDOK)
{
// Legacy apps like gsdxgui expect this...
if(s_gs != NULL && s_gs->m_wnd.IsManaged())
{
// Legacy apps like gsdxgui expect this...
GSshutdown();
GSshutdown();
}
}
}
#else
// TODO: linux
// TODO: linux
if (RunLinuxDialog())
{
if(s_gs != NULL && s_gs->m_wnd.IsManaged())
if (RunLinuxDialog())
{
GSshutdown();
if(s_gs != NULL && s_gs->m_wnd.IsManaged())
{
GSshutdown();
}
}
}
#endif
} catch (GSDXRecoverableError)
{
}
}
EXPORT_C_(int) GStest()

View File

@ -138,11 +138,11 @@ bool GSDevice11::Create(GSWnd* wnd)
{"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
};
hr = CompileShader(IDR_CONVERT_FX, "vs_main", NULL, &m_convert.vs, il_convert, countof(il_convert), &m_convert.il);
CompileShader(IDR_CONVERT_FX, "vs_main", NULL, &m_convert.vs, il_convert, countof(il_convert), &m_convert.il);
for(int i = 0; i < countof(m_convert.ps); i++)
{
hr = CompileShader(IDR_CONVERT_FX, format("ps_main%d", i).c_str(), NULL, &m_convert.ps[i]);
CompileShader(IDR_CONVERT_FX, format("ps_main%d", i).c_str(), NULL, &m_convert.ps[i]);
}
memset(&dsd, 0, sizeof(dsd));
@ -170,7 +170,7 @@ bool GSDevice11::Create(GSWnd* wnd)
for(int i = 0; i < countof(m_merge.ps); i++)
{
hr = CompileShader(IDR_MERGE_FX, format("ps_main%d", i).c_str(), NULL, &m_merge.ps[i]);
CompileShader(IDR_MERGE_FX, format("ps_main%d", i).c_str(), NULL, &m_merge.ps[i]);
}
memset(&bsd, 0, sizeof(bsd));
@ -198,7 +198,7 @@ bool GSDevice11::Create(GSWnd* wnd)
for(int i = 0; i < countof(m_interlace.ps); i++)
{
hr = CompileShader(IDR_INTERLACE_FX, format("ps_main%d", i).c_str(), NULL, &m_interlace.ps[i]);
CompileShader(IDR_INTERLACE_FX, format("ps_main%d", i).c_str(), NULL, &m_interlace.ps[i]);
}
// Shade Boost
@ -229,7 +229,7 @@ bool GSDevice11::Create(GSWnd* wnd)
hr = m_dev->CreateBuffer(&bd, NULL, &m_shadeboost.cb);
hr = CompileShader(IDR_SHADEBOOST_FX, "ps_main", macro, &m_shadeboost.ps);
CompileShader(IDR_SHADEBOOST_FX, "ps_main", macro, &m_shadeboost.ps);
// fxaa
@ -241,7 +241,7 @@ bool GSDevice11::Create(GSWnd* wnd)
hr = m_dev->CreateBuffer(&bd, NULL, &m_fxaa.cb);
hr = CompileShader(IDR_FXAA_FX, "ps_main", NULL, &m_fxaa.ps);
CompileShader(IDR_FXAA_FX, "ps_main", NULL, &m_fxaa.ps);
//
@ -1184,7 +1184,7 @@ void GSDevice11::OMSetRenderTargets(const GSVector2i& rtsize, int count, ID3D11U
}
}
HRESULT GSDevice11::CompileShader(uint32 id, const char* entry, D3D11_SHADER_MACRO* macro, ID3D11VertexShader** vs, D3D11_INPUT_ELEMENT_DESC* layout, int count, ID3D11InputLayout** il)
void GSDevice11::CompileShader(uint32 id, const char* entry, D3D11_SHADER_MACRO* macro, ID3D11VertexShader** vs, D3D11_INPUT_ELEMENT_DESC* layout, int count, ID3D11InputLayout** il)
{
HRESULT hr;
@ -1203,27 +1203,25 @@ HRESULT GSDevice11::CompileShader(uint32 id, const char* entry, D3D11_SHADER_MAC
if(FAILED(hr))
{
return hr;
throw GSDXRecoverableError();
}
hr = m_dev->CreateVertexShader((void*)shader->GetBufferPointer(), shader->GetBufferSize(), NULL, vs);
if(FAILED(hr))
{
return hr;
throw GSDXRecoverableError();
}
hr = m_dev->CreateInputLayout(layout, count, shader->GetBufferPointer(), shader->GetBufferSize(), il);
if(FAILED(hr))
{
return hr;
throw GSDXRecoverableError();
}
return hr;
}
HRESULT GSDevice11::CompileShader(uint32 id, const char* entry, D3D11_SHADER_MACRO* macro, ID3D11GeometryShader** gs)
void GSDevice11::CompileShader(uint32 id, const char* entry, D3D11_SHADER_MACRO* macro, ID3D11GeometryShader** gs)
{
HRESULT hr;
@ -1242,20 +1240,18 @@ HRESULT GSDevice11::CompileShader(uint32 id, const char* entry, D3D11_SHADER_MAC
if(FAILED(hr))
{
return hr;
throw GSDXRecoverableError();
}
hr = m_dev->CreateGeometryShader((void*)shader->GetBufferPointer(), shader->GetBufferSize(), NULL, gs);
if(FAILED(hr))
{
return hr;
throw GSDXRecoverableError();
}
return hr;
}
HRESULT GSDevice11::CompileShader(uint32 id, const char* entry, D3D11_SHADER_MACRO* macro, ID3D11GeometryShader** gs, D3D11_SO_DECLARATION_ENTRY* layout, int count)
void GSDevice11::CompileShader(uint32 id, const char* entry, D3D11_SHADER_MACRO* macro, ID3D11GeometryShader** gs, D3D11_SO_DECLARATION_ENTRY* layout, int count)
{
HRESULT hr;
@ -1274,20 +1270,18 @@ HRESULT GSDevice11::CompileShader(uint32 id, const char* entry, D3D11_SHADER_MAC
if(FAILED(hr))
{
return hr;
throw GSDXRecoverableError();
}
hr = m_dev->CreateGeometryShaderWithStreamOutput((void*)shader->GetBufferPointer(), shader->GetBufferSize(), layout, count, NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM, NULL, gs);
if(FAILED(hr))
{
return hr;
throw GSDXRecoverableError();
}
return hr;
}
HRESULT GSDevice11::CompileShader(uint32 id, const char* entry, D3D11_SHADER_MACRO* macro, ID3D11PixelShader** ps)
void GSDevice11::CompileShader(uint32 id, const char* entry, D3D11_SHADER_MACRO* macro, ID3D11PixelShader** ps)
{
HRESULT hr;
@ -1306,20 +1300,18 @@ HRESULT GSDevice11::CompileShader(uint32 id, const char* entry, D3D11_SHADER_MAC
if(FAILED(hr))
{
return hr;
throw GSDXRecoverableError();
}
hr = m_dev->CreatePixelShader((void*)shader->GetBufferPointer(), shader->GetBufferSize(),NULL, ps);
if(FAILED(hr))
{
return hr;
throw GSDXRecoverableError();
}
return hr;
}
HRESULT GSDevice11::CompileShader(uint32 id, const char* entry, D3D11_SHADER_MACRO* macro, ID3D11ComputeShader** cs)
void GSDevice11::CompileShader(uint32 id, const char* entry, D3D11_SHADER_MACRO* macro, ID3D11ComputeShader** cs)
{
HRESULT hr;
@ -1338,20 +1330,18 @@ HRESULT GSDevice11::CompileShader(uint32 id, const char* entry, D3D11_SHADER_MAC
if(FAILED(hr))
{
return hr;
throw GSDXRecoverableError();
}
hr = m_dev->CreateComputeShader((void*)shader->GetBufferPointer(), shader->GetBufferSize(),NULL, cs);
if(FAILED(hr))
{
return hr;
throw GSDXRecoverableError();
}
return hr;
}
HRESULT GSDevice11::CompileShader(const char* fn, const char* entry, D3D11_SHADER_MACRO* macro, ID3D11ComputeShader** cs)
void GSDevice11::CompileShader(const char* fn, const char* entry, D3D11_SHADER_MACRO* macro, ID3D11ComputeShader** cs)
{
HRESULT hr;
@ -1370,16 +1360,14 @@ HRESULT GSDevice11::CompileShader(const char* fn, const char* entry, D3D11_SHADE
if(FAILED(hr))
{
return hr;
throw GSDXRecoverableError();
}
hr = m_dev->CreateComputeShader((void*)shader->GetBufferPointer(), shader->GetBufferSize(),NULL, cs);
if(FAILED(hr))
{
return hr;
throw GSDXRecoverableError();
}
return hr;
}

View File

@ -213,11 +213,11 @@ public:
operator ID3D11Device*() {return m_dev;}
operator ID3D11DeviceContext*() {return m_ctx;}
HRESULT CompileShader(uint32 id, const char* entry, D3D11_SHADER_MACRO* macro, ID3D11VertexShader** vs, D3D11_INPUT_ELEMENT_DESC* layout, int count, ID3D11InputLayout** il);
HRESULT CompileShader(uint32 id, const char* entry, D3D11_SHADER_MACRO* macro, ID3D11GeometryShader** gs);
HRESULT CompileShader(uint32 id, const char* entry, D3D11_SHADER_MACRO* macro, ID3D11GeometryShader** gs, D3D11_SO_DECLARATION_ENTRY* layout, int count);
HRESULT CompileShader(uint32 id, const char* entry, D3D11_SHADER_MACRO* macro, ID3D11PixelShader** ps);
HRESULT CompileShader(uint32 id, const char* entry, D3D11_SHADER_MACRO* macro, ID3D11ComputeShader** cs);
HRESULT CompileShader(const char* fn, const char* entry, D3D11_SHADER_MACRO* macro, ID3D11ComputeShader** cs);
void CompileShader(uint32 id, const char* entry, D3D11_SHADER_MACRO* macro, ID3D11VertexShader** vs, D3D11_INPUT_ELEMENT_DESC* layout, int count, ID3D11InputLayout** il);
void CompileShader(uint32 id, const char* entry, D3D11_SHADER_MACRO* macro, ID3D11GeometryShader** gs);
void CompileShader(uint32 id, const char* entry, D3D11_SHADER_MACRO* macro, ID3D11GeometryShader** gs, D3D11_SO_DECLARATION_ENTRY* layout, int count);
void CompileShader(uint32 id, const char* entry, D3D11_SHADER_MACRO* macro, ID3D11PixelShader** ps);
void CompileShader(uint32 id, const char* entry, D3D11_SHADER_MACRO* macro, ID3D11ComputeShader** cs);
void CompileShader(const char* fn, const char* entry, D3D11_SHADER_MACRO* macro, ID3D11ComputeShader** cs);
};

View File

@ -1288,7 +1288,7 @@ void GSDevice9::OMSetRenderTargets(GSTexture* rt, GSTexture* ds, const GSVector4
}
}
HRESULT GSDevice9::CompileShader(uint32 id, const string& entry, const D3DXMACRO* macro, IDirect3DVertexShader9** vs, const D3DVERTEXELEMENT9* layout, int count, IDirect3DVertexDeclaration9** il)
void GSDevice9::CompileShader(uint32 id, const string& entry, const D3DXMACRO* macro, IDirect3DVertexShader9** vs, const D3DVERTEXELEMENT9* layout, int count, IDirect3DVertexDeclaration9** il)
{
vector<D3DXMACRO> m;
@ -1309,24 +1309,20 @@ HRESULT GSDevice9::CompileShader(uint32 id, const string& entry, const D3DXMACRO
printf("%s\n", (const char*)error->GetBufferPointer());
}
ASSERT(SUCCEEDED(hr));
if(FAILED(hr))
{
return hr;
throw GSDXRecoverableError();
}
hr = m_dev->CreateVertexDeclaration(layout, il);
if(FAILED(hr))
{
return hr;
throw GSDXRecoverableError();
}
return S_OK;
}
HRESULT GSDevice9::CompileShader(uint32 id, const string& entry, const D3DXMACRO* macro, IDirect3DPixelShader9** ps)
void GSDevice9::CompileShader(uint32 id, const string& entry, const D3DXMACRO* macro, IDirect3DPixelShader9** ps)
{
uint32 flags = 0;
@ -1358,13 +1354,9 @@ HRESULT GSDevice9::CompileShader(uint32 id, const string& entry, const D3DXMACRO
printf("%s\n", (const char*)error->GetBufferPointer());
}
ASSERT(SUCCEEDED(hr));
if(FAILED(hr))
{
return hr;
throw GSDXRecoverableError();
}
return S_OK;
}

View File

@ -221,8 +221,8 @@ public:
IDirect3DDevice9* operator->() {return m_dev;}
operator IDirect3DDevice9*() {return m_dev;}
HRESULT CompileShader(uint32 id, const string& entry, const D3DXMACRO* macro, IDirect3DVertexShader9** vs, const D3DVERTEXELEMENT9* layout, int count, IDirect3DVertexDeclaration9** il);
HRESULT CompileShader(uint32 id, const string& entry, const D3DXMACRO* macro, IDirect3DPixelShader9** ps);
void CompileShader(uint32 id, const string& entry, const D3DXMACRO* macro, IDirect3DVertexShader9** vs, const D3DVERTEXELEMENT9* layout, int count, IDirect3DVertexDeclaration9** il);
void CompileShader(uint32 id, const string& entry, const D3DXMACRO* macro, IDirect3DPixelShader9** ps);
void SetupVS(VSSelector sel, const VSConstantBuffer* cb);
void SetupGS(GSSelector sel) {}