From c046c27815bc1994565d6cef5534adad13d8c365 Mon Sep 17 00:00:00 2001 From: rice1964 Date: Thu, 10 Sep 2009 03:36:32 +0000 Subject: [PATCH] D3D: Minor bug fix and some code cleanup for DirectX API call reduction. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4244 8ced0084-cf51-0410-be5f-012b33b47a6e --- .../Core/VideoCommon/Src/PixelShaderGen.cpp | 2 + Source/Core/VideoCommon/Src/PixelShaderGen.h | 1 + .../Core/VideoCommon/Src/VertexShaderGen.cpp | 2 + Source/Core/VideoCommon/Src/VertexShaderGen.h | 1 + .../Plugin_VideoDX9/Src/PixelShaderCache.cpp | 41 +++++++++---------- .../Plugin_VideoDX9/Src/PixelShaderCache.h | 1 - .../Plugin_VideoDX9/Src/VertexShaderCache.cpp | 14 +++---- .../Plugin_VideoDX9/Src/VertexShaderCache.h | 1 - 8 files changed, 33 insertions(+), 30 deletions(-) diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp index 25685dc9ca..4e55902088 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp @@ -24,6 +24,8 @@ #include "XFMemory.h" // for texture projection mode #include "BPMemory.h" +PIXELSHADERUID last_pixel_shader_uid; + // Mash together all the inputs that contribute to the code of a generated pixel shader into // a unique identifier, basically containing all the bits. Yup, it's a lot .... // It would likely be a lot more efficient to build this incrementally as the attributes diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.h b/Source/Core/VideoCommon/Src/PixelShaderGen.h index 18a8b3b404..9c88a58de4 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderGen.h +++ b/Source/Core/VideoCommon/Src/PixelShaderGen.h @@ -102,5 +102,6 @@ public: const char *GeneratePixelShader(u32 texture_mask, bool dstAlphaEnable, bool HLSL = false); void GetPixelShaderId(PIXELSHADERUID &, u32 texturemask, u32 dstAlphaEnable); +extern PIXELSHADERUID last_pixel_shader_uid; #endif // GCOGL_PIXELSHADER_H diff --git a/Source/Core/VideoCommon/Src/VertexShaderGen.cpp b/Source/Core/VideoCommon/Src/VertexShaderGen.cpp index 7a9dba3c44..1cfc509e22 100644 --- a/Source/Core/VideoCommon/Src/VertexShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/VertexShaderGen.cpp @@ -23,6 +23,8 @@ #include "BPMemory.h" #include "VertexShaderGen.h" +VERTEXSHADERUID last_vertex_shader_uid; + // Mash together all the inputs that contribute to the code of a generated vertex shader into // a unique identifier, basically containing all the bits. Yup, it's a lot .... void GetVertexShaderId(VERTEXSHADERUID& vid, u32 components) diff --git a/Source/Core/VideoCommon/Src/VertexShaderGen.h b/Source/Core/VideoCommon/Src/VertexShaderGen.h index 482c6a68a7..f3a3046efa 100644 --- a/Source/Core/VideoCommon/Src/VertexShaderGen.h +++ b/Source/Core/VideoCommon/Src/VertexShaderGen.h @@ -101,5 +101,6 @@ public: const char *GenerateVertexShader(u32 components, bool D3D); void GetVertexShaderId(VERTEXSHADERUID& vid, u32 components); +extern VERTEXSHADERUID last_vertex_shader_uid; #endif // GCOGL_VERTEXSHADER_H diff --git a/Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.cpp b/Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.cpp index 65387c0c27..92086d6a46 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.cpp @@ -32,43 +32,42 @@ PixelShaderCache::PSCache PixelShaderCache::PixelShaders; const PixelShaderCache::PSCacheEntry *PixelShaderCache::last_entry; -PIXELSHADERUID PixelShaderCache::last_entry_uid; -static float lastPSConstants[C_COLORMATRIX+16][4]; +static float lastPSconstants[C_COLORMATRIX+16][4]; void SetPSConstant4f(int const_number, float f1, float f2, float f3, float f4) { - if( lastPSConstants[const_number][0] != f1 || lastPSConstants[const_number][1] != f2 || - lastPSConstants[const_number][2] != f3 || lastPSConstants[const_number][3] != f4 ) + if( lastPSconstants[const_number][0] != f1 || lastPSconstants[const_number][1] != f2 || + lastPSconstants[const_number][2] != f3 || lastPSconstants[const_number][3] != f4 ) { const float f[4] = {f1, f2, f3, f4}; D3D::dev->SetPixelShaderConstantF(const_number, f, 1); - lastPSConstants[const_number][0] = f1; - lastPSConstants[const_number][1] = f2; - lastPSConstants[const_number][2] = f3; - lastPSConstants[const_number][3] = f4; + lastPSconstants[const_number][0] = f1; + lastPSconstants[const_number][1] = f2; + lastPSconstants[const_number][2] = f3; + lastPSconstants[const_number][3] = f4; } } void SetPSConstant4fv(int const_number, const float *f) { - if( lastPSConstants[const_number][0] != f[0] || lastPSConstants[const_number][1] != f[1] || - lastPSConstants[const_number][2] != f[2] || lastPSConstants[const_number][3] != f[3] ) + if( lastPSconstants[const_number][0] != f[0] || lastPSconstants[const_number][1] != f[1] || + lastPSconstants[const_number][2] != f[2] || lastPSconstants[const_number][3] != f[3] ) { D3D::dev->SetPixelShaderConstantF(const_number, f, 1); - lastPSConstants[const_number][0] = f[0]; - lastPSConstants[const_number][1] = f[1]; - lastPSConstants[const_number][2] = f[2]; - lastPSConstants[const_number][3] = f[3]; + lastPSconstants[const_number][0] = f[0]; + lastPSconstants[const_number][1] = f[1]; + lastPSconstants[const_number][2] = f[2]; + lastPSconstants[const_number][3] = f[3]; } } void PixelShaderCache::Init() { - int i; - for (i=0;i<(C_COLORMATRIX+16)*4;i++) - lastPSConstants[i/4][i%4]= -1; - - memset(&last_entry_uid,0xFF,sizeof(last_entry_uid)); + //memset(lastPSconstants,0xFF,(C_COLORMATRIX+16)*4*sizeof(float)); // why does this not work + //memset(lastPSconstants,0xFF,sizeof(lastPSconstants)); + for( int i=0;i<(C_COLORMATRIX+16)*4;i++) + lastPSconstants[i/4][i%4] = -100000000.0f; + memset(&last_pixel_shader_uid,0xFF,sizeof(last_pixel_shader_uid)); } void PixelShaderCache::Shutdown() @@ -85,7 +84,7 @@ bool PixelShaderCache::SetShader(bool dstAlpha) PIXELSHADERUID uid; GetPixelShaderId(uid, PixelShaderManager::GetTextureMask(), dstAlpha); - if (uid == last_entry_uid) + if (uid == last_pixel_shader_uid) { if (PixelShaders[uid].shader) return true; @@ -93,7 +92,7 @@ bool PixelShaderCache::SetShader(bool dstAlpha) return false; } - memcpy(&last_entry_uid, &uid, sizeof(PIXELSHADERUID)); + memcpy(&last_pixel_shader_uid, &uid, sizeof(PIXELSHADERUID)); PSCache::iterator iter; iter = PixelShaders.find(uid); diff --git a/Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.h b/Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.h index d4f4a559e4..23c32a8e10 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.h +++ b/Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.h @@ -51,7 +51,6 @@ private: static PSCache PixelShaders; static const PSCacheEntry *last_entry; - static PIXELSHADERUID last_entry_uid; public: static void Init(); diff --git a/Source/Plugins/Plugin_VideoDX9/Src/VertexShaderCache.cpp b/Source/Plugins/Plugin_VideoDX9/Src/VertexShaderCache.cpp index e484da0535..c45c684a74 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/VertexShaderCache.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/VertexShaderCache.cpp @@ -32,7 +32,6 @@ VertexShaderCache::VSCache VertexShaderCache::vshaders; const VertexShaderCache::VSCacheEntry *VertexShaderCache::last_entry; -VERTEXSHADERUID VertexShaderCache::last_entry_uid; static float lastVSconstants[C_FOGPARAMS+8][4]; @@ -69,10 +68,11 @@ void SetVSConstant4fv(int const_number, const float *f) void VertexShaderCache::Init() { - for( int i=0; i