D3D: Fix bugs in the shader cache, fixes crashes on x64. added some debugging stuff (only active in debug builds). assorted code cleanup.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4145 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
hrydgard
2009-09-01 19:48:45 +00:00
parent b15320bc02
commit 2599659022
12 changed files with 151 additions and 127 deletions

View File

@ -32,6 +32,7 @@
#include <Cg/cgD3D9.h>
VertexShaderCache::VSCache VertexShaderCache::vshaders;
const VertexShaderCache::VSCacheEntry *VertexShaderCache::last_entry;
void SetVSConstant4f(int const_number, float f1, float f2, float f3, float f4)
{
@ -49,7 +50,6 @@ void VertexShaderCache::Init()
}
void VertexShaderCache::Shutdown()
{
VSCache::iterator iter = vshaders.begin();
@ -61,10 +61,7 @@ void VertexShaderCache::Shutdown()
void VertexShaderCache::SetShader(u32 components)
{
if (D3D::GetShaderVersion() < 2)
return; // we are screwed
static LPDIRECT3DVERTEXSHADER9 lastShader = NULL;
static LPDIRECT3DVERTEXSHADER9 last_shader = NULL;
DVSTARTPROFILE();
@ -76,11 +73,12 @@ void VertexShaderCache::SetShader(u32 components)
if (iter != vshaders.end())
{
iter->second.frameCount = frameCount;
VSCacheEntry &entry = iter->second;
if (!lastShader || entry.shader != lastShader)
const VSCacheEntry &entry = iter->second;
last_entry = &entry;
if (!last_shader || entry.shader != last_shader)
{
D3D::dev->SetVertexShader(entry.shader);
lastShader = entry.shader;
last_shader = entry.shader;
}
return;
}
@ -94,7 +92,12 @@ void VertexShaderCache::SetShader(u32 components)
VSCacheEntry entry;
entry.shader = shader;
entry.frameCount = frameCount;
#ifdef _DEBUG
entry.code = code;
#endif
vshaders[uid] = entry;
last_entry = &vshaders[uid];
last_shader = entry.shader;
D3D::dev->SetVertexShader(shader);
@ -145,4 +148,14 @@ void VertexShaderCache::Cleanup()
}
}
SETSTAT(stats.numVertexShadersAlive, (int)vshaders.size());
}
}
#ifdef _DEBUG
std::string VertexShaderCache::GetCurrentShaderCode()
{
if (last_entry)
return last_entry->code;
else
return "(no shader)\n";
}
#endif