mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-26 15:49:50 -06:00
Fix a vertex shader generation bug that crashed Super Monkey Ball. Better shader error handling. Random warning fixes.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4170 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
@ -57,10 +57,8 @@ void PixelShaderCache::Shutdown()
|
||||
PixelShaders.clear();
|
||||
}
|
||||
|
||||
void PixelShaderCache::SetShader(bool dstAlpha)
|
||||
bool PixelShaderCache::SetShader(bool dstAlpha)
|
||||
{
|
||||
static LPDIRECT3DPIXELSHADER9 last_shader = NULL;
|
||||
|
||||
DVSTARTPROFILE();
|
||||
|
||||
PIXELSHADERUID uid;
|
||||
@ -68,19 +66,14 @@ void PixelShaderCache::SetShader(bool dstAlpha)
|
||||
|
||||
PSCache::iterator iter;
|
||||
iter = PixelShaders.find(uid);
|
||||
|
||||
if (iter != PixelShaders.end())
|
||||
{
|
||||
iter->second.frameCount = frameCount;
|
||||
const PSCacheEntry &entry = iter->second;
|
||||
D3D::dev->SetPixelShader(entry.shader);
|
||||
last_entry = &entry;
|
||||
if (!last_shader || entry.shader != last_shader)
|
||||
{
|
||||
D3D::dev->SetPixelShader(entry.shader);
|
||||
last_shader = entry.shader;
|
||||
DEBUGGER_PAUSE_COUNT_N(NEXT_PIXEL_SHADER_CHANGE);
|
||||
}
|
||||
return;
|
||||
DEBUGGER_PAUSE_COUNT_N(NEXT_PIXEL_SHADER_CHANGE);
|
||||
return true;
|
||||
}
|
||||
|
||||
const char *code = GeneratePixelShader(PixelShaderManager::GetTextureMask(), dstAlpha, true);
|
||||
@ -88,26 +81,27 @@ void PixelShaderCache::SetShader(bool dstAlpha)
|
||||
|
||||
if (shader)
|
||||
{
|
||||
//Make an entry in the table
|
||||
// Make an entry in the table
|
||||
PSCacheEntry newentry;
|
||||
newentry.shader = shader;
|
||||
newentry.frameCount = frameCount;
|
||||
#ifdef _DEBUG
|
||||
#if defined(_DEBUG) || defined(DEBUGFAST)
|
||||
newentry.code = code;
|
||||
#endif
|
||||
PixelShaders[uid] = newentry;
|
||||
last_entry = &PixelShaders[uid];
|
||||
|
||||
D3D::dev->SetPixelShader(shader);
|
||||
last_shader = shader;
|
||||
|
||||
INCSTAT(stats.numPixelShadersCreated);
|
||||
SETSTAT(stats.numPixelShadersAlive, (int)PixelShaders.size());
|
||||
return true;
|
||||
}
|
||||
else if (g_Config.bShowShaderErrors)
|
||||
{
|
||||
PanicAlert("Failed to compile Pixel Shader:\n\n%s", code);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@ -131,7 +125,7 @@ void PixelShaderCache::Cleanup()
|
||||
SETSTAT(stats.numPixelShadersAlive, (int)PixelShaders.size());
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
#if defined(_DEBUG) || defined(DEBUGFAST)
|
||||
std::string PixelShaderCache::GetCurrentShaderCode()
|
||||
{
|
||||
if (last_entry)
|
||||
|
@ -36,7 +36,7 @@ private:
|
||||
{
|
||||
LPDIRECT3DPIXELSHADER9 shader;
|
||||
int frameCount;
|
||||
#ifdef _DEBUG
|
||||
#if defined(_DEBUG) || defined(DEBUGFAST)
|
||||
std::string code;
|
||||
#endif
|
||||
PSCacheEntry() : shader(NULL), frameCount(0) {}
|
||||
@ -56,8 +56,8 @@ public:
|
||||
static void Init();
|
||||
static void Cleanup();
|
||||
static void Shutdown();
|
||||
static void SetShader(bool dstAlpha);
|
||||
#ifdef _DEBUG
|
||||
static bool SetShader(bool dstAlpha);
|
||||
#if defined(_DEBUG) || defined(DEBUGFAST)
|
||||
static std::string GetCurrentShaderCode();
|
||||
#endif
|
||||
static LPDIRECT3DPIXELSHADER9 CompileCgShader(const char *pstrprogram);
|
||||
|
@ -185,10 +185,6 @@ void Flush()
|
||||
DVSTARTPROFILE();
|
||||
if (collection != C_NOTHING)
|
||||
{
|
||||
// setup the pointers
|
||||
if (g_nativeVertexFmt)
|
||||
g_nativeVertexFmt->SetupVertexPointers();
|
||||
|
||||
u32 usedtextures = 0;
|
||||
for (u32 i = 0; i < (u32)bpmem.genMode.numtevstages + 1; ++i) {
|
||||
if (bpmem.tevorders[i/2].getEnable(i & 1))
|
||||
@ -230,8 +226,10 @@ void Flush()
|
||||
VertexShaderManager::SetConstants();
|
||||
PixelShaderManager::SetConstants();
|
||||
|
||||
PixelShaderCache::SetShader(false);
|
||||
VertexShaderCache::SetShader(g_nativeVertexFmt->m_components);
|
||||
if (!PixelShaderCache::SetShader(false))
|
||||
goto shader_fail;
|
||||
if (!VertexShaderCache::SetShader(g_nativeVertexFmt->m_components))
|
||||
goto shader_fail;
|
||||
|
||||
int stride = g_nativeVertexFmt->GetVertexStride();
|
||||
g_nativeVertexFmt->SetupVertexPointers();
|
||||
@ -245,12 +243,12 @@ void Flush()
|
||||
D3DFMT_INDEX16,
|
||||
fakeVBuffer,
|
||||
stride))) {
|
||||
#ifdef _DEBUG
|
||||
#if defined(_DEBUG) || defined(DEBUGFAST)
|
||||
std::string error_shaders;
|
||||
error_shaders.append(VertexShaderCache::GetCurrentShaderCode());
|
||||
error_shaders.append(PixelShaderCache::GetCurrentShaderCode());
|
||||
File::WriteStringToFile(true, error_shaders, "bad_shader_combo.txt");
|
||||
PanicAlert("DrawIndexedPrimitiveUP failed. Shaders written to shaders.txt.");
|
||||
PanicAlert("DrawIndexedPrimitiveUP failed. Shaders written to bad_shader_combo.txt.");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@ -263,7 +261,8 @@ void Flush()
|
||||
if (bpmem.dstalpha.enable && bpmem.blendmode.alphaupdate)
|
||||
{
|
||||
DWORD write = 0;
|
||||
PixelShaderCache::SetShader(true);
|
||||
if (!PixelShaderCache::SetShader(true))
|
||||
goto shader_fail;
|
||||
|
||||
// update alpha only
|
||||
Renderer::SetRenderState(D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_ALPHA);
|
||||
@ -280,12 +279,12 @@ void Flush()
|
||||
D3DFMT_INDEX16,
|
||||
fakeVBuffer,
|
||||
stride))) {
|
||||
#ifdef _DEBUG
|
||||
#if defined(_DEBUG) || defined(DEBUGFAST)
|
||||
std::string error_shaders;
|
||||
error_shaders.append(VertexShaderCache::GetCurrentShaderCode());
|
||||
error_shaders.append(PixelShaderCache::GetCurrentShaderCode());
|
||||
File::WriteStringToFile(true, error_shaders, "bad_shader_combo.txt");
|
||||
PanicAlert("DrawIndexedPrimitiveUP failed. Shaders written to shaders.txt.");
|
||||
PanicAlert("DrawIndexedPrimitiveUP failed (dstalpha). Shaders written to bad_shader_combo.txt.");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@ -309,7 +308,7 @@ void Flush()
|
||||
|
||||
INCSTAT(stats.thisFrame.numDrawCalls);
|
||||
}
|
||||
|
||||
shader_fail:
|
||||
collection = C_NOTHING;
|
||||
VertexManager::s_pCurBufferPointer = fakeVBuffer;
|
||||
DEBUGGER_PAUSE_COUNT_N(NEXT_FLUSH);
|
||||
|
@ -57,11 +57,8 @@ void VertexShaderCache::Shutdown()
|
||||
vshaders.clear();
|
||||
}
|
||||
|
||||
|
||||
void VertexShaderCache::SetShader(u32 components)
|
||||
bool VertexShaderCache::SetShader(u32 components)
|
||||
{
|
||||
static LPDIRECT3DVERTEXSHADER9 last_shader = NULL;
|
||||
|
||||
DVSTARTPROFILE();
|
||||
|
||||
VERTEXSHADERUID uid;
|
||||
@ -73,15 +70,10 @@ void VertexShaderCache::SetShader(u32 components)
|
||||
{
|
||||
iter->second.frameCount = frameCount;
|
||||
const VSCacheEntry &entry = iter->second;
|
||||
D3D::dev->SetVertexShader(entry.shader);
|
||||
last_entry = &entry;
|
||||
if (!last_shader || entry.shader != last_shader)
|
||||
{
|
||||
D3D::dev->SetVertexShader(entry.shader);
|
||||
last_shader = entry.shader;
|
||||
|
||||
DEBUGGER_PAUSE_COUNT_N(NEXT_VERTEX_SHADER_CHANGE);
|
||||
}
|
||||
return;
|
||||
DEBUGGER_PAUSE_COUNT_N(NEXT_VERTEX_SHADER_CHANGE);
|
||||
return true;
|
||||
}
|
||||
|
||||
const char *code = GenerateVertexShader(components, true);
|
||||
@ -93,22 +85,23 @@ void VertexShaderCache::SetShader(u32 components)
|
||||
VSCacheEntry entry;
|
||||
entry.shader = shader;
|
||||
entry.frameCount = frameCount;
|
||||
#ifdef _DEBUG
|
||||
#if defined(_DEBUG) || defined(DEBUGFAST)
|
||||
entry.code = code;
|
||||
#endif
|
||||
vshaders[uid] = entry;
|
||||
last_entry = &vshaders[uid];
|
||||
last_shader = entry.shader;
|
||||
|
||||
D3D::dev->SetVertexShader(shader);
|
||||
|
||||
INCSTAT(stats.numVertexShadersCreated);
|
||||
SETSTAT(stats.numVertexShadersAlive, (int)vshaders.size());
|
||||
return true;
|
||||
}
|
||||
else if (g_Config.bShowShaderErrors)
|
||||
{
|
||||
PanicAlert("Failed to compile Vertex Shader:\n\n%s", code);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void VertexShaderCache::Cleanup()
|
||||
@ -129,7 +122,7 @@ void VertexShaderCache::Cleanup()
|
||||
SETSTAT(stats.numVertexShadersAlive, (int)vshaders.size());
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
#if defined(_DEBUG) || defined(DEBUGFAST)
|
||||
std::string VertexShaderCache::GetCurrentShaderCode()
|
||||
{
|
||||
if (last_entry)
|
||||
|
@ -33,7 +33,7 @@ private:
|
||||
{
|
||||
LPDIRECT3DVERTEXSHADER9 shader;
|
||||
int frameCount;
|
||||
#ifdef _DEBUG
|
||||
#if defined(_DEBUG) || defined(DEBUGFAST)
|
||||
std::string code;
|
||||
#endif
|
||||
VSCacheEntry() : shader(NULL), frameCount(0) {}
|
||||
@ -53,8 +53,8 @@ public:
|
||||
static void Init();
|
||||
static void Cleanup();
|
||||
static void Shutdown();
|
||||
static void SetShader(u32 components);
|
||||
#ifdef _DEBUG
|
||||
static bool SetShader(u32 components);
|
||||
#if defined(_DEBUG) || defined(DEBUGFAST)
|
||||
static std::string GetCurrentShaderCode();
|
||||
#endif
|
||||
static LPDIRECT3DVERTEXSHADER9 CompileCgShader(const char *pstrprogram);
|
||||
|
Reference in New Issue
Block a user