Fix Windows build.

This commit is contained in:
NeoBrainX 2011-09-29 22:54:52 +02:00
parent 81c614fa07
commit 2b3b32872d
8 changed files with 64 additions and 46 deletions

View File

@ -41,6 +41,7 @@ namespace DX11
PixelShaderCache::PSCache PixelShaderCache::PixelShaders; PixelShaderCache::PSCache PixelShaderCache::PixelShaders;
const PixelShaderCache::PSCacheEntry* PixelShaderCache::last_entry; const PixelShaderCache::PSCacheEntry* PixelShaderCache::last_entry;
PIXELSHADERUID PixelShaderCache::last_uid;
LinearDiskCache<PIXELSHADERUID, u8> g_ps_disk_cache; LinearDiskCache<PIXELSHADERUID, u8> g_ps_disk_cache;
@ -415,6 +416,8 @@ void PixelShaderCache::Init()
if (g_Config.bEnableShaderDebugging) if (g_Config.bEnableShaderDebugging)
Clear(); Clear();
last_entry = NULL;
} }
// ONLY to be used during shutdown. // ONLY to be used during shutdown.
@ -423,6 +426,8 @@ void PixelShaderCache::Clear()
for (PSCache::iterator iter = PixelShaders.begin(); iter != PixelShaders.end(); iter++) for (PSCache::iterator iter = PixelShaders.begin(); iter != PixelShaders.end(); iter++)
iter->second.Destroy(); iter->second.Destroy();
PixelShaders.clear(); PixelShaders.clear();
last_entry = NULL;
} }
// Used in Swap() when AA mode has changed // Used in Swap() when AA mode has changed
@ -457,25 +462,26 @@ void PixelShaderCache::Shutdown()
bool PixelShaderCache::SetShader(DSTALPHA_MODE dstAlphaMode, u32 components) bool PixelShaderCache::SetShader(DSTALPHA_MODE dstAlphaMode, u32 components)
{ {
PIXELSHADERUID uid; PIXELSHADERUID uid;
GetPixelShaderId(&uid, dstAlphaMode); GetPixelShaderId(&uid, dstAlphaMode, components);
// Check if the shader is already set // Check if the shader is already set
if (uid == last_pixel_shader_uid && PixelShaders[uid].frameCount == frameCount) if (last_entry)
{
if (uid == last_uid)
{ {
PSCache::const_iterator iter = PixelShaders.find(uid);
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE,true); GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE,true);
ValidatePixelShaderIDs(API_D3D11, PixelShaders[uid].safe_uid, PixelShaders[uid].code, dstAlphaMode, components); ValidatePixelShaderIDs(API_D3D11, last_entry->safe_uid, last_entry->code, dstAlphaMode, components);
return (iter != PixelShaders.end() && iter->second.shader); return (last_entry->shader != NULL);
}
} }
memcpy(&last_pixel_shader_uid, &uid, sizeof(PIXELSHADERUID)); last_uid = uid;
// Check if the shader is already in the cache // Check if the shader is already in the cache
PSCache::iterator iter; PSCache::iterator iter;
iter = PixelShaders.find(uid); iter = PixelShaders.find(uid);
if (iter != PixelShaders.end()) if (iter != PixelShaders.end())
{ {
iter->second.frameCount = frameCount;
const PSCacheEntry &entry = iter->second; const PSCacheEntry &entry = iter->second;
last_entry = &entry; last_entry = &entry;
@ -504,7 +510,7 @@ bool PixelShaderCache::SetShader(DSTALPHA_MODE dstAlphaMode, u32 components)
if (g_ActiveConfig.bEnableShaderDebugging && success) if (g_ActiveConfig.bEnableShaderDebugging && success)
{ {
PixelShaders[uid].code = code; PixelShaders[uid].code = code;
GetSafePixelShaderId(&PixelShaders[uid].safe_uid, dstAlphaMode); GetSafePixelShaderId(&PixelShaders[uid].safe_uid, dstAlphaMode, components);
} }
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true); GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true);
@ -523,7 +529,6 @@ bool PixelShaderCache::InsertByteCode(const PIXELSHADERUID &uid, const void* byt
// Make an entry in the table // Make an entry in the table
PSCacheEntry newentry; PSCacheEntry newentry;
newentry.shader = shader; newentry.shader = shader;
newentry.frameCount = frameCount;
PixelShaders[uid] = newentry; PixelShaders[uid] = newentry;
last_entry = &PixelShaders[uid]; last_entry = &PixelShaders[uid];

View File

@ -53,12 +53,11 @@ private:
struct PSCacheEntry struct PSCacheEntry
{ {
ID3D11PixelShader* shader; ID3D11PixelShader* shader;
int frameCount;
PIXELSHADERUIDSAFE safe_uid; PIXELSHADERUIDSAFE safe_uid;
std::string code; std::string code;
PSCacheEntry() : shader(NULL), frameCount(0) {} PSCacheEntry() : shader(NULL) {}
void Destroy() { SAFE_RELEASE(shader); } void Destroy() { SAFE_RELEASE(shader); }
}; };
@ -66,6 +65,7 @@ private:
static PSCache PixelShaders; static PSCache PixelShaders;
static const PSCacheEntry* last_entry; static const PSCacheEntry* last_entry;
static PIXELSHADERUID last_uid;
}; };
} // namespace DX11 } // namespace DX11

View File

@ -37,6 +37,7 @@ namespace DX11 {
VertexShaderCache::VSCache VertexShaderCache::vshaders; VertexShaderCache::VSCache VertexShaderCache::vshaders;
const VertexShaderCache::VSCacheEntry *VertexShaderCache::last_entry; const VertexShaderCache::VSCacheEntry *VertexShaderCache::last_entry;
VERTEXSHADERUID VertexShaderCache::last_uid;
static ID3D11VertexShader* SimpleVertexShader = NULL; static ID3D11VertexShader* SimpleVertexShader = NULL;
static ID3D11VertexShader* ClearVertexShader = NULL; static ID3D11VertexShader* ClearVertexShader = NULL;
@ -177,6 +178,8 @@ void VertexShaderCache::Init()
if (g_Config.bEnableShaderDebugging) if (g_Config.bEnableShaderDebugging)
Clear(); Clear();
last_entry = NULL;
} }
void VertexShaderCache::Clear() void VertexShaderCache::Clear()
@ -184,6 +187,8 @@ void VertexShaderCache::Clear()
for (VSCache::iterator iter = vshaders.begin(); iter != vshaders.end(); ++iter) for (VSCache::iterator iter = vshaders.begin(); iter != vshaders.end(); ++iter)
iter->second.Destroy(); iter->second.Destroy();
vshaders.clear(); vshaders.clear();
last_entry = NULL;
} }
void VertexShaderCache::Shutdown() void VertexShaderCache::Shutdown()
@ -205,19 +210,21 @@ bool VertexShaderCache::SetShader(u32 components)
{ {
VERTEXSHADERUID uid; VERTEXSHADERUID uid;
GetVertexShaderId(&uid, components); GetVertexShaderId(&uid, components);
if (uid == last_vertex_shader_uid && vshaders[uid].frameCount == frameCount) if (last_entry)
{
if (uid == last_uid)
{ {
GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true); GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true);
ValidateVertexShaderIDs(API_D3D11, vshaders[uid].safe_uid, vshaders[uid].code, components); ValidateVertexShaderIDs(API_D3D11, last_entry->safe_uid, last_entry->code, components);
return (vshaders[uid].shader != NULL); return (last_entry->shader != NULL);
}
} }
memcpy(&last_vertex_shader_uid, &uid, sizeof(VERTEXSHADERUID)); last_uid = uid;
VSCache::iterator iter = vshaders.find(uid); VSCache::iterator iter = vshaders.find(uid);
if (iter != vshaders.end()) if (iter != vshaders.end())
{ {
iter->second.frameCount = frameCount;
const VSCacheEntry &entry = iter->second; const VSCacheEntry &entry = iter->second;
last_entry = &entry; last_entry = &entry;
@ -264,7 +271,6 @@ bool VertexShaderCache::InsertByteCode(const VERTEXSHADERUID &uid, D3DBlob* bcod
// Make an entry in the table // Make an entry in the table
VSCacheEntry entry; VSCacheEntry entry;
entry.shader = shader; entry.shader = shader;
entry.frameCount = frameCount;
entry.SetByteCode(bcodeblob); entry.SetByteCode(bcodeblob);
vshaders[uid] = entry; vshaders[uid] = entry;

View File

@ -51,12 +51,11 @@ private:
{ {
ID3D11VertexShader* shader; ID3D11VertexShader* shader;
D3DBlob* bytecode; // needed to initialize the input layout D3DBlob* bytecode; // needed to initialize the input layout
int frameCount;
VERTEXSHADERUIDSAFE safe_uid; VERTEXSHADERUIDSAFE safe_uid;
std::string code; std::string code;
VSCacheEntry() : shader(NULL), bytecode(NULL), frameCount(0) {} VSCacheEntry() : shader(NULL), bytecode(NULL) {}
void SetByteCode(D3DBlob* blob) void SetByteCode(D3DBlob* blob)
{ {
SAFE_RELEASE(bytecode); SAFE_RELEASE(bytecode);
@ -73,6 +72,7 @@ private:
static VSCache vshaders; static VSCache vshaders;
static const VSCacheEntry* last_entry; static const VSCacheEntry* last_entry;
static VERTEXSHADERUID last_uid;
}; };
} // namespace DX11 } // namespace DX11

View File

@ -43,6 +43,7 @@ namespace DX9
PixelShaderCache::PSCache PixelShaderCache::PixelShaders; PixelShaderCache::PSCache PixelShaderCache::PixelShaders;
const PixelShaderCache::PSCacheEntry *PixelShaderCache::last_entry; const PixelShaderCache::PSCacheEntry *PixelShaderCache::last_entry;
PIXELSHADERUID PixelShaderCache::last_uid;
static LinearDiskCache<PIXELSHADERUID, u8> g_ps_disk_cache; static LinearDiskCache<PIXELSHADERUID, u8> g_ps_disk_cache;
static std::set<u32> unique_shaders; static std::set<u32> unique_shaders;
@ -233,6 +234,8 @@ static LPDIRECT3DPIXELSHADER9 CreateCopyShader(int copyMatrixType, int depthConv
void PixelShaderCache::Init() void PixelShaderCache::Init()
{ {
last_entry = NULL;
//program used for clear screen //program used for clear screen
{ {
char pprog[3072]; char pprog[3072];
@ -295,7 +298,7 @@ void PixelShaderCache::Clear()
iter->second.Destroy(); iter->second.Destroy();
PixelShaders.clear(); PixelShaders.clear();
memset(&last_pixel_shader_uid, 0xFF, sizeof(last_pixel_shader_uid)); last_entry = NULL;
} }
void PixelShaderCache::Shutdown() void PixelShaderCache::Shutdown()
@ -331,25 +334,26 @@ bool PixelShaderCache::SetShader(DSTALPHA_MODE dstAlphaMode, u32 components)
{ {
const API_TYPE api = ((D3D::GetCaps().PixelShaderVersion >> 8) & 0xFF) < 3 ? API_D3D9_SM20 : API_D3D9_SM30; const API_TYPE api = ((D3D::GetCaps().PixelShaderVersion >> 8) & 0xFF) < 3 ? API_D3D9_SM20 : API_D3D9_SM30;
PIXELSHADERUID uid; PIXELSHADERUID uid;
GetPixelShaderId(&uid, dstAlphaMode); GetPixelShaderId(&uid, dstAlphaMode, components);
// Check if the shader is already set // Check if the shader is already set
if (uid == last_pixel_shader_uid && PixelShaders[uid].frameCount == frameCount) if (last_entry)
{
if (uid == last_uid)
{ {
PSCache::const_iterator iter = PixelShaders.find(uid);
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true); GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true);
ValidatePixelShaderIDs(api, PixelShaders[uid].safe_uid, PixelShaders[uid].code, dstAlphaMode, components); ValidatePixelShaderIDs(api, last_entry->safe_uid, last_entry->code, dstAlphaMode, components);
return (iter != PixelShaders.end() && iter->second.shader); return last_entry->shader != NULL;
}
} }
memcpy(&last_pixel_shader_uid, &uid, sizeof(PIXELSHADERUID)); last_uid = uid;
// Check if the shader is already in the cache // Check if the shader is already in the cache
PSCache::iterator iter; PSCache::iterator iter;
iter = PixelShaders.find(uid); iter = PixelShaders.find(uid);
if (iter != PixelShaders.end()) if (iter != PixelShaders.end())
{ {
iter->second.frameCount = frameCount;
const PSCacheEntry &entry = iter->second; const PSCacheEntry &entry = iter->second;
last_entry = &entry; last_entry = &entry;
@ -398,7 +402,7 @@ bool PixelShaderCache::SetShader(DSTALPHA_MODE dstAlphaMode, u32 components)
if (g_ActiveConfig.bEnableShaderDebugging && success) if (g_ActiveConfig.bEnableShaderDebugging && success)
{ {
PixelShaders[uid].code = code; PixelShaders[uid].code = code;
GetSafePixelShaderId(&PixelShaders[uid].safe_uid, dstAlphaMode); GetSafePixelShaderId(&PixelShaders[uid].safe_uid, dstAlphaMode, components);
} }
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true); GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true);
@ -412,7 +416,6 @@ bool PixelShaderCache::InsertByteCode(const PIXELSHADERUID &uid, const u8 *bytec
// Make an entry in the table // Make an entry in the table
PSCacheEntry newentry; PSCacheEntry newentry;
newentry.shader = shader; newentry.shader = shader;
newentry.frameCount = frameCount;
PixelShaders[uid] = newentry; PixelShaders[uid] = newentry;
last_entry = &PixelShaders[uid]; last_entry = &PixelShaders[uid];

View File

@ -40,12 +40,11 @@ private:
{ {
LPDIRECT3DPIXELSHADER9 shader; LPDIRECT3DPIXELSHADER9 shader;
bool owns_shader; bool owns_shader;
int frameCount;
PIXELSHADERUIDSAFE safe_uid; PIXELSHADERUIDSAFE safe_uid;
std::string code; std::string code;
PSCacheEntry() : shader(NULL), owns_shader(true), frameCount(0) {} PSCacheEntry() : shader(NULL), owns_shader(true) {}
void Destroy() void Destroy()
{ {
if (shader && owns_shader) if (shader && owns_shader)
@ -58,6 +57,7 @@ private:
static PSCache PixelShaders; static PSCache PixelShaders;
static const PSCacheEntry *last_entry; static const PSCacheEntry *last_entry;
static PIXELSHADERUID last_uid;
static void Clear(); static void Clear();
public: public:

View File

@ -38,6 +38,7 @@ namespace DX9
VertexShaderCache::VSCache VertexShaderCache::vshaders; VertexShaderCache::VSCache VertexShaderCache::vshaders;
const VertexShaderCache::VSCacheEntry *VertexShaderCache::last_entry; const VertexShaderCache::VSCacheEntry *VertexShaderCache::last_entry;
VERTEXSHADERUID VertexShaderCache::last_uid;
#define MAX_SSAA_SHADERS 3 #define MAX_SSAA_SHADERS 3
@ -154,6 +155,8 @@ void VertexShaderCache::Init()
if (g_Config.bEnableShaderDebugging) if (g_Config.bEnableShaderDebugging)
Clear(); Clear();
last_entry = NULL;
} }
void VertexShaderCache::Clear() void VertexShaderCache::Clear()
@ -162,7 +165,7 @@ void VertexShaderCache::Clear()
iter->second.Destroy(); iter->second.Destroy();
vshaders.clear(); vshaders.clear();
memset(&last_vertex_shader_uid, 0xFF, sizeof(last_vertex_shader_uid)); last_entry = NULL;
} }
void VertexShaderCache::Shutdown() void VertexShaderCache::Shutdown()
@ -187,19 +190,21 @@ bool VertexShaderCache::SetShader(u32 components)
{ {
VERTEXSHADERUID uid; VERTEXSHADERUID uid;
GetVertexShaderId(&uid, components); GetVertexShaderId(&uid, components);
if (uid == last_vertex_shader_uid && vshaders[uid].frameCount == frameCount) if (last_entry)
{
if (uid == last_uid)
{ {
GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true); GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true);
ValidateVertexShaderIDs(API_D3D9, vshaders[uid].safe_uid, vshaders[uid].code, components); ValidateVertexShaderIDs(API_D3D9, last_entry->safe_uid, last_entry->code, components);
return (vshaders[uid].shader != NULL); return (last_entry->shader != NULL);
}
} }
memcpy(&last_vertex_shader_uid, &uid, sizeof(VERTEXSHADERUID)); last_uid = uid;
VSCache::iterator iter = vshaders.find(uid); VSCache::iterator iter = vshaders.find(uid);
if (iter != vshaders.end()) if (iter != vshaders.end())
{ {
iter->second.frameCount = frameCount;
const VSCacheEntry &entry = iter->second; const VSCacheEntry &entry = iter->second;
last_entry = &entry; last_entry = &entry;
@ -237,7 +242,6 @@ bool VertexShaderCache::InsertByteCode(const VERTEXSHADERUID &uid, const u8 *byt
// Make an entry in the table // Make an entry in the table
VSCacheEntry entry; VSCacheEntry entry;
entry.shader = shader; entry.shader = shader;
entry.frameCount = frameCount;
vshaders[uid] = entry; vshaders[uid] = entry;
last_entry = &vshaders[uid]; last_entry = &vshaders[uid];

View File

@ -34,12 +34,11 @@ private:
struct VSCacheEntry struct VSCacheEntry
{ {
LPDIRECT3DVERTEXSHADER9 shader; LPDIRECT3DVERTEXSHADER9 shader;
int frameCount;
//#if defined(_DEBUG) || defined(DEBUGFAST)
std::string code; std::string code;
VERTEXSHADERUIDSAFE safe_uid; VERTEXSHADERUIDSAFE safe_uid;
//#endif
VSCacheEntry() : shader(NULL), frameCount(0) {} VSCacheEntry() : shader(NULL) {}
void Destroy() void Destroy()
{ {
if (shader) if (shader)
@ -52,6 +51,7 @@ private:
static VSCache vshaders; static VSCache vshaders;
static const VSCacheEntry *last_entry; static const VSCacheEntry *last_entry;
static VERTEXSHADERUID last_uid;
static void Clear(); static void Clear();
public: public: