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
This commit is contained in:
rice1964 2009-09-10 03:36:32 +00:00
parent b3194e596e
commit c046c27815
8 changed files with 33 additions and 30 deletions

View File

@ -24,6 +24,8 @@
#include "XFMemory.h" // for texture projection mode #include "XFMemory.h" // for texture projection mode
#include "BPMemory.h" #include "BPMemory.h"
PIXELSHADERUID last_pixel_shader_uid;
// Mash together all the inputs that contribute to the code of a generated pixel shader into // 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 .... // 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 // It would likely be a lot more efficient to build this incrementally as the attributes

View File

@ -102,5 +102,6 @@ public:
const char *GeneratePixelShader(u32 texture_mask, bool dstAlphaEnable, bool HLSL = false); const char *GeneratePixelShader(u32 texture_mask, bool dstAlphaEnable, bool HLSL = false);
void GetPixelShaderId(PIXELSHADERUID &, u32 texturemask, u32 dstAlphaEnable); void GetPixelShaderId(PIXELSHADERUID &, u32 texturemask, u32 dstAlphaEnable);
extern PIXELSHADERUID last_pixel_shader_uid;
#endif // GCOGL_PIXELSHADER_H #endif // GCOGL_PIXELSHADER_H

View File

@ -23,6 +23,8 @@
#include "BPMemory.h" #include "BPMemory.h"
#include "VertexShaderGen.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 // 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 .... // a unique identifier, basically containing all the bits. Yup, it's a lot ....
void GetVertexShaderId(VERTEXSHADERUID& vid, u32 components) void GetVertexShaderId(VERTEXSHADERUID& vid, u32 components)

View File

@ -101,5 +101,6 @@ public:
const char *GenerateVertexShader(u32 components, bool D3D); const char *GenerateVertexShader(u32 components, bool D3D);
void GetVertexShaderId(VERTEXSHADERUID& vid, u32 components); void GetVertexShaderId(VERTEXSHADERUID& vid, u32 components);
extern VERTEXSHADERUID last_vertex_shader_uid;
#endif // GCOGL_VERTEXSHADER_H #endif // GCOGL_VERTEXSHADER_H

View File

@ -32,43 +32,42 @@
PixelShaderCache::PSCache PixelShaderCache::PixelShaders; PixelShaderCache::PSCache PixelShaderCache::PixelShaders;
const PixelShaderCache::PSCacheEntry *PixelShaderCache::last_entry; 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) void SetPSConstant4f(int const_number, float f1, float f2, float f3, float f4)
{ {
if( lastPSConstants[const_number][0] != f1 || lastPSConstants[const_number][1] != f2 || if( lastPSconstants[const_number][0] != f1 || lastPSconstants[const_number][1] != f2 ||
lastPSConstants[const_number][2] != f3 || lastPSConstants[const_number][3] != f4 ) lastPSconstants[const_number][2] != f3 || lastPSconstants[const_number][3] != f4 )
{ {
const float f[4] = {f1, f2, f3, f4}; const float f[4] = {f1, f2, f3, f4};
D3D::dev->SetPixelShaderConstantF(const_number, f, 1); D3D::dev->SetPixelShaderConstantF(const_number, f, 1);
lastPSConstants[const_number][0] = f1; lastPSconstants[const_number][0] = f1;
lastPSConstants[const_number][1] = f2; lastPSconstants[const_number][1] = f2;
lastPSConstants[const_number][2] = f3; lastPSconstants[const_number][2] = f3;
lastPSConstants[const_number][3] = f4; lastPSconstants[const_number][3] = f4;
} }
} }
void SetPSConstant4fv(int const_number, const float *f) void SetPSConstant4fv(int const_number, const float *f)
{ {
if( lastPSConstants[const_number][0] != f[0] || lastPSConstants[const_number][1] != f[1] || 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] ) lastPSconstants[const_number][2] != f[2] || lastPSconstants[const_number][3] != f[3] )
{ {
D3D::dev->SetPixelShaderConstantF(const_number, f, 1); D3D::dev->SetPixelShaderConstantF(const_number, f, 1);
lastPSConstants[const_number][0] = f[0]; lastPSconstants[const_number][0] = f[0];
lastPSConstants[const_number][1] = f[1]; lastPSconstants[const_number][1] = f[1];
lastPSConstants[const_number][2] = f[2]; lastPSconstants[const_number][2] = f[2];
lastPSConstants[const_number][3] = f[3]; lastPSconstants[const_number][3] = f[3];
} }
} }
void PixelShaderCache::Init() void PixelShaderCache::Init()
{ {
int i; //memset(lastPSconstants,0xFF,(C_COLORMATRIX+16)*4*sizeof(float)); // why does this not work
for (i=0;i<(C_COLORMATRIX+16)*4;i++) //memset(lastPSconstants,0xFF,sizeof(lastPSconstants));
lastPSConstants[i/4][i%4]= -1; for( int i=0;i<(C_COLORMATRIX+16)*4;i++)
lastPSconstants[i/4][i%4] = -100000000.0f;
memset(&last_entry_uid,0xFF,sizeof(last_entry_uid)); memset(&last_pixel_shader_uid,0xFF,sizeof(last_pixel_shader_uid));
} }
void PixelShaderCache::Shutdown() void PixelShaderCache::Shutdown()
@ -85,7 +84,7 @@ bool PixelShaderCache::SetShader(bool dstAlpha)
PIXELSHADERUID uid; PIXELSHADERUID uid;
GetPixelShaderId(uid, PixelShaderManager::GetTextureMask(), dstAlpha); GetPixelShaderId(uid, PixelShaderManager::GetTextureMask(), dstAlpha);
if (uid == last_entry_uid) if (uid == last_pixel_shader_uid)
{ {
if (PixelShaders[uid].shader) if (PixelShaders[uid].shader)
return true; return true;
@ -93,7 +92,7 @@ bool PixelShaderCache::SetShader(bool dstAlpha)
return false; return false;
} }
memcpy(&last_entry_uid, &uid, sizeof(PIXELSHADERUID)); memcpy(&last_pixel_shader_uid, &uid, sizeof(PIXELSHADERUID));
PSCache::iterator iter; PSCache::iterator iter;
iter = PixelShaders.find(uid); iter = PixelShaders.find(uid);

View File

@ -51,7 +51,6 @@ private:
static PSCache PixelShaders; static PSCache PixelShaders;
static const PSCacheEntry *last_entry; static const PSCacheEntry *last_entry;
static PIXELSHADERUID last_entry_uid;
public: public:
static void Init(); static void Init();

View File

@ -32,7 +32,6 @@
VertexShaderCache::VSCache VertexShaderCache::vshaders; VertexShaderCache::VSCache VertexShaderCache::vshaders;
const VertexShaderCache::VSCacheEntry *VertexShaderCache::last_entry; const VertexShaderCache::VSCacheEntry *VertexShaderCache::last_entry;
VERTEXSHADERUID VertexShaderCache::last_entry_uid;
static float lastVSconstants[C_FOGPARAMS+8][4]; static float lastVSconstants[C_FOGPARAMS+8][4];
@ -69,10 +68,11 @@ void SetVSConstant4fv(int const_number, const float *f)
void VertexShaderCache::Init() void VertexShaderCache::Init()
{ {
for( int i=0; i<C_FOGPARAMS+8*4; i++) //memset(lastVSconstants,0xFF,(C_FOGPARAMS+8)*4*sizeof(float)); // why does this not work
lastVSconstants[i/4][i%4]=-1; //memset(lastVSconstants,0xFF,sizeof(lastVSconstants));
for( int i=0;i<(C_FOGPARAMS+8)*4;i++)
memset(last_entry_uid.values,0xFF,sizeof(last_entry_uid.values)); lastVSconstants[i/4][i%4] = -100000000.0f;
memset(&last_vertex_shader_uid,0xFF,sizeof(last_vertex_shader_uid));
} }
void VertexShaderCache::Shutdown() void VertexShaderCache::Shutdown()
@ -89,14 +89,14 @@ bool VertexShaderCache::SetShader(u32 components)
VERTEXSHADERUID uid; VERTEXSHADERUID uid;
GetVertexShaderId(uid, components); GetVertexShaderId(uid, components);
if (uid == last_entry_uid) if (uid == last_vertex_shader_uid)
{ {
if (vshaders[uid].shader) if (vshaders[uid].shader)
return true; return true;
else else
return false; return false;
} }
memcpy(&last_entry_uid, &uid, sizeof(VERTEXSHADERUID)); memcpy(&last_vertex_shader_uid, &uid, sizeof(VERTEXSHADERUID));
VSCache::iterator iter; VSCache::iterator iter;
iter = vshaders.find(uid); iter = vshaders.find(uid);

View File

@ -48,7 +48,6 @@ private:
static VSCache vshaders; static VSCache vshaders;
static const VSCacheEntry *last_entry; static const VSCacheEntry *last_entry;
static VERTEXSHADERUID last_entry_uid;
public: public:
static void Init(); static void Init();