From 2b3b32872d2a01aba7195dc31a5270cf9613f5c1 Mon Sep 17 00:00:00 2001 From: NeoBrainX Date: Thu, 29 Sep 2011 22:54:52 +0200 Subject: [PATCH] Fix Windows build. --- .../Plugin_VideoDX11/Src/PixelShaderCache.cpp | 25 +++++++++++-------- .../Plugin_VideoDX11/Src/PixelShaderCache.h | 4 +-- .../Src/VertexShaderCache.cpp | 20 +++++++++------ .../Plugin_VideoDX11/Src/VertexShaderCache.h | 4 +-- .../Plugin_VideoDX9/Src/PixelShaderCache.cpp | 25 +++++++++++-------- .../Plugin_VideoDX9/Src/PixelShaderCache.h | 4 +-- .../Plugin_VideoDX9/Src/VertexShaderCache.cpp | 20 +++++++++------ .../Plugin_VideoDX9/Src/VertexShaderCache.h | 8 +++--- 8 files changed, 64 insertions(+), 46 deletions(-) diff --git a/Source/Plugins/Plugin_VideoDX11/Src/PixelShaderCache.cpp b/Source/Plugins/Plugin_VideoDX11/Src/PixelShaderCache.cpp index 656f8ddff2..7e4af031bd 100644 --- a/Source/Plugins/Plugin_VideoDX11/Src/PixelShaderCache.cpp +++ b/Source/Plugins/Plugin_VideoDX11/Src/PixelShaderCache.cpp @@ -41,6 +41,7 @@ namespace DX11 PixelShaderCache::PSCache PixelShaderCache::PixelShaders; const PixelShaderCache::PSCacheEntry* PixelShaderCache::last_entry; +PIXELSHADERUID PixelShaderCache::last_uid; LinearDiskCache g_ps_disk_cache; @@ -415,6 +416,8 @@ void PixelShaderCache::Init() if (g_Config.bEnableShaderDebugging) Clear(); + + last_entry = NULL; } // ONLY to be used during shutdown. @@ -423,6 +426,8 @@ void PixelShaderCache::Clear() for (PSCache::iterator iter = PixelShaders.begin(); iter != PixelShaders.end(); iter++) iter->second.Destroy(); PixelShaders.clear(); + + last_entry = NULL; } // Used in Swap() when AA mode has changed @@ -457,25 +462,26 @@ void PixelShaderCache::Shutdown() bool PixelShaderCache::SetShader(DSTALPHA_MODE dstAlphaMode, u32 components) { PIXELSHADERUID uid; - GetPixelShaderId(&uid, dstAlphaMode); + GetPixelShaderId(&uid, dstAlphaMode, components); // Check if the shader is already set - if (uid == last_pixel_shader_uid && PixelShaders[uid].frameCount == frameCount) + if (last_entry) { - PSCache::const_iterator iter = PixelShaders.find(uid); - GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE,true); - ValidatePixelShaderIDs(API_D3D11, PixelShaders[uid].safe_uid, PixelShaders[uid].code, dstAlphaMode, components); - return (iter != PixelShaders.end() && iter->second.shader); + if (uid == last_uid) + { + GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE,true); + ValidatePixelShaderIDs(API_D3D11, last_entry->safe_uid, last_entry->code, dstAlphaMode, components); + 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 PSCache::iterator iter; iter = PixelShaders.find(uid); if (iter != PixelShaders.end()) { - iter->second.frameCount = frameCount; const PSCacheEntry &entry = iter->second; last_entry = &entry; @@ -504,7 +510,7 @@ bool PixelShaderCache::SetShader(DSTALPHA_MODE dstAlphaMode, u32 components) if (g_ActiveConfig.bEnableShaderDebugging && success) { 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); @@ -523,7 +529,6 @@ bool PixelShaderCache::InsertByteCode(const PIXELSHADERUID &uid, const void* byt // Make an entry in the table PSCacheEntry newentry; newentry.shader = shader; - newentry.frameCount = frameCount; PixelShaders[uid] = newentry; last_entry = &PixelShaders[uid]; diff --git a/Source/Plugins/Plugin_VideoDX11/Src/PixelShaderCache.h b/Source/Plugins/Plugin_VideoDX11/Src/PixelShaderCache.h index f5a9cf34b8..874a47e4c1 100644 --- a/Source/Plugins/Plugin_VideoDX11/Src/PixelShaderCache.h +++ b/Source/Plugins/Plugin_VideoDX11/Src/PixelShaderCache.h @@ -53,12 +53,11 @@ private: struct PSCacheEntry { ID3D11PixelShader* shader; - int frameCount; PIXELSHADERUIDSAFE safe_uid; std::string code; - PSCacheEntry() : shader(NULL), frameCount(0) {} + PSCacheEntry() : shader(NULL) {} void Destroy() { SAFE_RELEASE(shader); } }; @@ -66,6 +65,7 @@ private: static PSCache PixelShaders; static const PSCacheEntry* last_entry; + static PIXELSHADERUID last_uid; }; } // namespace DX11 diff --git a/Source/Plugins/Plugin_VideoDX11/Src/VertexShaderCache.cpp b/Source/Plugins/Plugin_VideoDX11/Src/VertexShaderCache.cpp index a12acfedfd..d9dae4cf91 100644 --- a/Source/Plugins/Plugin_VideoDX11/Src/VertexShaderCache.cpp +++ b/Source/Plugins/Plugin_VideoDX11/Src/VertexShaderCache.cpp @@ -37,6 +37,7 @@ namespace DX11 { VertexShaderCache::VSCache VertexShaderCache::vshaders; const VertexShaderCache::VSCacheEntry *VertexShaderCache::last_entry; +VERTEXSHADERUID VertexShaderCache::last_uid; static ID3D11VertexShader* SimpleVertexShader = NULL; static ID3D11VertexShader* ClearVertexShader = NULL; @@ -177,6 +178,8 @@ void VertexShaderCache::Init() if (g_Config.bEnableShaderDebugging) Clear(); + + last_entry = NULL; } void VertexShaderCache::Clear() @@ -184,6 +187,8 @@ void VertexShaderCache::Clear() for (VSCache::iterator iter = vshaders.begin(); iter != vshaders.end(); ++iter) iter->second.Destroy(); vshaders.clear(); + + last_entry = NULL; } void VertexShaderCache::Shutdown() @@ -205,19 +210,21 @@ bool VertexShaderCache::SetShader(u32 components) { VERTEXSHADERUID uid; GetVertexShaderId(&uid, components); - if (uid == last_vertex_shader_uid && vshaders[uid].frameCount == frameCount) + if (last_entry) { - GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true); - ValidateVertexShaderIDs(API_D3D11, vshaders[uid].safe_uid, vshaders[uid].code, components); - return (vshaders[uid].shader != NULL); + if (uid == last_uid) + { + GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true); + ValidateVertexShaderIDs(API_D3D11, last_entry->safe_uid, last_entry->code, components); + return (last_entry->shader != NULL); + } } - memcpy(&last_vertex_shader_uid, &uid, sizeof(VERTEXSHADERUID)); + last_uid = uid; VSCache::iterator iter = vshaders.find(uid); if (iter != vshaders.end()) { - iter->second.frameCount = frameCount; const VSCacheEntry &entry = iter->second; last_entry = &entry; @@ -264,7 +271,6 @@ bool VertexShaderCache::InsertByteCode(const VERTEXSHADERUID &uid, D3DBlob* bcod // Make an entry in the table VSCacheEntry entry; entry.shader = shader; - entry.frameCount = frameCount; entry.SetByteCode(bcodeblob); vshaders[uid] = entry; diff --git a/Source/Plugins/Plugin_VideoDX11/Src/VertexShaderCache.h b/Source/Plugins/Plugin_VideoDX11/Src/VertexShaderCache.h index d614989b0a..6d9537606a 100644 --- a/Source/Plugins/Plugin_VideoDX11/Src/VertexShaderCache.h +++ b/Source/Plugins/Plugin_VideoDX11/Src/VertexShaderCache.h @@ -51,12 +51,11 @@ private: { ID3D11VertexShader* shader; D3DBlob* bytecode; // needed to initialize the input layout - int frameCount; VERTEXSHADERUIDSAFE safe_uid; std::string code; - VSCacheEntry() : shader(NULL), bytecode(NULL), frameCount(0) {} + VSCacheEntry() : shader(NULL), bytecode(NULL) {} void SetByteCode(D3DBlob* blob) { SAFE_RELEASE(bytecode); @@ -73,6 +72,7 @@ private: static VSCache vshaders; static const VSCacheEntry* last_entry; + static VERTEXSHADERUID last_uid; }; } // namespace DX11 diff --git a/Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.cpp b/Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.cpp index 34d1c37594..14943e8f8f 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.cpp @@ -43,6 +43,7 @@ namespace DX9 PixelShaderCache::PSCache PixelShaderCache::PixelShaders; const PixelShaderCache::PSCacheEntry *PixelShaderCache::last_entry; +PIXELSHADERUID PixelShaderCache::last_uid; static LinearDiskCache g_ps_disk_cache; static std::set unique_shaders; @@ -233,6 +234,8 @@ static LPDIRECT3DPIXELSHADER9 CreateCopyShader(int copyMatrixType, int depthConv void PixelShaderCache::Init() { + last_entry = NULL; + //program used for clear screen { char pprog[3072]; @@ -295,7 +298,7 @@ void PixelShaderCache::Clear() iter->second.Destroy(); PixelShaders.clear(); - memset(&last_pixel_shader_uid, 0xFF, sizeof(last_pixel_shader_uid)); + last_entry = NULL; } 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; PIXELSHADERUID uid; - GetPixelShaderId(&uid, dstAlphaMode); + GetPixelShaderId(&uid, dstAlphaMode, components); // Check if the shader is already set - if (uid == last_pixel_shader_uid && PixelShaders[uid].frameCount == frameCount) + if (last_entry) { - PSCache::const_iterator iter = PixelShaders.find(uid); - GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true); - ValidatePixelShaderIDs(api, PixelShaders[uid].safe_uid, PixelShaders[uid].code, dstAlphaMode, components); - return (iter != PixelShaders.end() && iter->second.shader); + if (uid == last_uid) + { + GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true); + ValidatePixelShaderIDs(api, last_entry->safe_uid, last_entry->code, dstAlphaMode, components); + 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 PSCache::iterator iter; iter = PixelShaders.find(uid); if (iter != PixelShaders.end()) { - iter->second.frameCount = frameCount; const PSCacheEntry &entry = iter->second; last_entry = &entry; @@ -398,7 +402,7 @@ bool PixelShaderCache::SetShader(DSTALPHA_MODE dstAlphaMode, u32 components) if (g_ActiveConfig.bEnableShaderDebugging && success) { 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); @@ -412,7 +416,6 @@ bool PixelShaderCache::InsertByteCode(const PIXELSHADERUID &uid, const u8 *bytec // Make an entry in the table PSCacheEntry newentry; newentry.shader = shader; - newentry.frameCount = frameCount; PixelShaders[uid] = newentry; last_entry = &PixelShaders[uid]; diff --git a/Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.h b/Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.h index d323311fe0..c771984d36 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.h +++ b/Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.h @@ -40,12 +40,11 @@ private: { LPDIRECT3DPIXELSHADER9 shader; bool owns_shader; - int frameCount; PIXELSHADERUIDSAFE safe_uid; std::string code; - PSCacheEntry() : shader(NULL), owns_shader(true), frameCount(0) {} + PSCacheEntry() : shader(NULL), owns_shader(true) {} void Destroy() { if (shader && owns_shader) @@ -58,6 +57,7 @@ private: static PSCache PixelShaders; static const PSCacheEntry *last_entry; + static PIXELSHADERUID last_uid; static void Clear(); public: diff --git a/Source/Plugins/Plugin_VideoDX9/Src/VertexShaderCache.cpp b/Source/Plugins/Plugin_VideoDX9/Src/VertexShaderCache.cpp index 5458157d80..9448c07371 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/VertexShaderCache.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/VertexShaderCache.cpp @@ -38,6 +38,7 @@ namespace DX9 VertexShaderCache::VSCache VertexShaderCache::vshaders; const VertexShaderCache::VSCacheEntry *VertexShaderCache::last_entry; +VERTEXSHADERUID VertexShaderCache::last_uid; #define MAX_SSAA_SHADERS 3 @@ -154,6 +155,8 @@ void VertexShaderCache::Init() if (g_Config.bEnableShaderDebugging) Clear(); + + last_entry = NULL; } void VertexShaderCache::Clear() @@ -162,7 +165,7 @@ void VertexShaderCache::Clear() iter->second.Destroy(); vshaders.clear(); - memset(&last_vertex_shader_uid, 0xFF, sizeof(last_vertex_shader_uid)); + last_entry = NULL; } void VertexShaderCache::Shutdown() @@ -187,19 +190,21 @@ bool VertexShaderCache::SetShader(u32 components) { VERTEXSHADERUID uid; GetVertexShaderId(&uid, components); - if (uid == last_vertex_shader_uid && vshaders[uid].frameCount == frameCount) + if (last_entry) { - GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true); - ValidateVertexShaderIDs(API_D3D9, vshaders[uid].safe_uid, vshaders[uid].code, components); - return (vshaders[uid].shader != NULL); + if (uid == last_uid) + { + GFX_DEBUGGER_PAUSE_AT(NEXT_VERTEX_SHADER_CHANGE, true); + ValidateVertexShaderIDs(API_D3D9, last_entry->safe_uid, last_entry->code, components); + return (last_entry->shader != NULL); + } } - memcpy(&last_vertex_shader_uid, &uid, sizeof(VERTEXSHADERUID)); + last_uid = uid; VSCache::iterator iter = vshaders.find(uid); if (iter != vshaders.end()) { - iter->second.frameCount = frameCount; const VSCacheEntry &entry = iter->second; last_entry = &entry; @@ -237,7 +242,6 @@ bool VertexShaderCache::InsertByteCode(const VERTEXSHADERUID &uid, const u8 *byt // Make an entry in the table VSCacheEntry entry; entry.shader = shader; - entry.frameCount = frameCount; vshaders[uid] = entry; last_entry = &vshaders[uid]; diff --git a/Source/Plugins/Plugin_VideoDX9/Src/VertexShaderCache.h b/Source/Plugins/Plugin_VideoDX9/Src/VertexShaderCache.h index 686f8b7c6d..c9c447e35b 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/VertexShaderCache.h +++ b/Source/Plugins/Plugin_VideoDX9/Src/VertexShaderCache.h @@ -34,12 +34,11 @@ private: struct VSCacheEntry { LPDIRECT3DVERTEXSHADER9 shader; - int frameCount; -//#if defined(_DEBUG) || defined(DEBUGFAST) + std::string code; VERTEXSHADERUIDSAFE safe_uid; -//#endif - VSCacheEntry() : shader(NULL), frameCount(0) {} + + VSCacheEntry() : shader(NULL) {} void Destroy() { if (shader) @@ -52,6 +51,7 @@ private: static VSCache vshaders; static const VSCacheEntry *last_entry; + static VERTEXSHADERUID last_uid; static void Clear(); public: