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 "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

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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);

View File

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

View File

@ -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<C_FOGPARAMS+8*4; i++)
lastVSconstants[i/4][i%4]=-1;
memset(last_entry_uid.values,0xFF,sizeof(last_entry_uid.values));
//memset(lastVSconstants,0xFF,(C_FOGPARAMS+8)*4*sizeof(float)); // why does this not work
//memset(lastVSconstants,0xFF,sizeof(lastVSconstants));
for( int i=0;i<(C_FOGPARAMS+8)*4;i++)
lastVSconstants[i/4][i%4] = -100000000.0f;
memset(&last_vertex_shader_uid,0xFF,sizeof(last_vertex_shader_uid));
}
void VertexShaderCache::Shutdown()
@ -89,14 +89,14 @@ bool VertexShaderCache::SetShader(u32 components)
VERTEXSHADERUID uid;
GetVertexShaderId(uid, components);
if (uid == last_entry_uid)
if (uid == last_vertex_shader_uid)
{
if (vshaders[uid].shader)
return true;
else
return false;
}
memcpy(&last_entry_uid, &uid, sizeof(VERTEXSHADERUID));
memcpy(&last_vertex_shader_uid, &uid, sizeof(VERTEXSHADERUID));
VSCache::iterator iter;
iter = vshaders.find(uid);

View File

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