PixelShaderManager: Disable constant cache (won't work in the non-UBO path of the opengl backend).

ShaderGen: Replace typeid usage with more general code.
This commit is contained in:
NeoBrainX 2013-03-29 20:33:28 +01:00
parent b2517c0308
commit 3c02f227db
6 changed files with 33 additions and 37 deletions

View File

@ -28,7 +28,7 @@
template<class T,class UidType>
void GenerateLightShader(T& object, int index, int litchan_index, const char* lightsName, int coloralpha)
{
#define SetUidField(name, value) if (typeid(T) == typeid(UidType)) { object.GetUidData().name = value; };
#define SetUidField(name, value) if (&object.GetUidData() != NULL) { object.GetUidData().name = value; };
const LitChannel& chan = (litchan_index > 1) ? xfregs.alpha[litchan_index-2] : xfregs.color[litchan_index];
const char* swizzle = "xyzw";
if (coloralpha == 1 ) swizzle = "xyz";

View File

@ -19,7 +19,6 @@
#include <cmath>
#include <assert.h>
#include <locale.h>
#include <typeinfo>
#include "LightingShaderGen.h"
#include "PixelShaderGen.h"
@ -271,13 +270,12 @@ template<class T>
void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u32 components)
{
// TODO: Can be optimized if using alpha pass
#define SetUidField(name, value) if (typeid(T) == typeid(PixelShaderUid)) {out.GetUidData().name = value; };
#define OR_UidField(name, value) if (typeid(T) == typeid(PixelShaderUid)) {out.GetUidData().name |= value; };
if (typeid(T) == typeid(PixelShaderCode))
{
#define SetUidField(name, value) if (&out.GetUidData() != NULL) {out.GetUidData().name = value; };
#define OR_UidField(name, value) if (&out.GetUidData() != NULL) {out.GetUidData().name |= value; };
out.SetBuffer(text);
if (out.GetBuffer() != NULL)
setlocale(LC_NUMERIC, "C"); // Reset locale for compilation
out.SetBuffer(text);
}
/// text[sizeof(text) - 1] = 0x7C; // canary
unsigned int numStages = bpmem.genMode.numtevstages + 1;
@ -669,7 +667,8 @@ void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u
/// if (text[sizeof(text) - 1] != 0x7C)
/// PanicAlert("PixelShader generator - buffer too small, canary has been eaten!");
setlocale(LC_NUMERIC, ""); // restore locale
if (out.GetBuffer() != NULL)
setlocale(LC_NUMERIC, ""); // restore locale
}

View File

@ -46,9 +46,9 @@ static float s_constant_cache[C_PENVCONST_END*4];
inline void SetPSConstant4f(unsigned int const_number, float f1, float f2, float f3, float f4)
{
if (s_constant_cache[const_number*4] == f1 && s_constant_cache[const_number*4+1] == f2 &&
s_constant_cache[const_number*4+2] == f3 && s_constant_cache[const_number*4+3] == f4)
return;
// if (s_constant_cache[const_number*4] == f1 && s_constant_cache[const_number*4+1] == f2 &&
// s_constant_cache[const_number*4+2] == f3 && s_constant_cache[const_number*4+3] == f4)
// return;
g_renderer->SetPSConstant4f(const_number, f1, f2, f3, f4);
s_constant_cache[const_number*4] = f1;
@ -59,9 +59,9 @@ inline void SetPSConstant4f(unsigned int const_number, float f1, float f2, float
inline void SetPSConstant4fv(unsigned int const_number, const float *f)
{
if (s_constant_cache[const_number*4] == f[0] && s_constant_cache[const_number*4+1] == f[1] &&
s_constant_cache[const_number*4+2] == f[2] && s_constant_cache[const_number*4+3] == f[3])
return;
// if (s_constant_cache[const_number*4] == f[0] && s_constant_cache[const_number*4+1] == f[1] &&
// s_constant_cache[const_number*4+2] == f[2] && s_constant_cache[const_number*4+3] == f[3])
// return;
g_renderer->SetPSConstant4fv(const_number, f);
s_constant_cache[const_number*4] = f[0];
@ -72,11 +72,11 @@ inline void SetPSConstant4fv(unsigned int const_number, const float *f)
inline void SetMultiPSConstant4fv(unsigned int const_number, unsigned int count, const float *f)
{
for (unsigned int i = 0; i < 4*count; ++i)
if (s_constant_cache[const_number*4+i] != f[i])
break;
else if (i == 4*count-1)
return;
// for (unsigned int i = 0; i < 4*count; ++i)
// if (s_constant_cache[const_number*4+i] != f[i])
// break;
// else if (i == 4*count-1)
// return;
g_renderer->SetMultiPSConstant4fv(const_number, count, f);
for (unsigned int i = 0; i < 4*count; ++i)
@ -149,7 +149,7 @@ void PixelShaderManager::SetConstants(u32 components)
{
for (int i = 0; i < 8; ++i)
{
if (s_nTexDimsChanged & (1<<i) && constant_profile.ConstantIsUsed(C_TEXDIMS+i))
if ((s_nTexDimsChanged & (1<<i)) && constant_profile.ConstantIsUsed(C_TEXDIMS+i))
{
++necessary_updates;
SetPSTextureDims(i);

View File

@ -33,7 +33,7 @@ public:
const char* GetBuffer() { return NULL; }
void SetBuffer(char* buffer) { }
inline void SetConstantsUsed(unsigned int first_index, unsigned int last_index) {}
uid_data& GetUidData() { return *(uid_data*)NULL; }
uid_data& GetUidData() { return *(uid_data*)NULL; } // TODO: can be moved out, just make this GetUidData<T> instead
};
template<class uid_data>
@ -122,7 +122,8 @@ public:
inline bool ConstantIsUsed(unsigned int index)
{
return constant_usage[index];
return true;
// return constant_usage[index];
}
private:
std::vector<bool> constant_usage; // TODO: Is vector<bool> appropriate here?

View File

@ -17,7 +17,6 @@
#include <math.h>
#include <locale.h>
#include <typeinfo>
#include "NativeVertexFormat.h"
@ -85,14 +84,11 @@ template<class T>
void GenerateVertexShader(T& out, u32 components, API_TYPE api_type)
{
#undef SetUidField
#define SetUidField(name, value) if (typeid(T) == typeid(VertexShaderUid)) {out.GetUidData().name = value; };
#define SetUidField(name, value) if (&out.GetUidData() != NULL) {out.GetUidData().name = value; };
if (typeid(T) == typeid(VertexShaderCode))
{
out.SetBuffer(text);
out.SetBuffer(text);
if (out.GetBuffer() != NULL)
setlocale(LC_NUMERIC, "C"); // Reset locale for compilation
}
// text[sizeof(text) - 1] = 0x7C; // canary
@ -523,7 +519,7 @@ void GenerateVertexShader(T& out, u32 components, API_TYPE api_type)
/// if (text[sizeof(text) - 1] != 0x7C)
/// PanicAlert("VertexShader generator - buffer too small, canary has been eaten!");
if (typeid(T) == typeid(VertexShaderCode))
if (out.GetBuffer() != NULL)
setlocale(LC_NUMERIC, ""); // restore locale
}

View File

@ -201,9 +201,9 @@ SHADER* ProgramShaderCache::SetShader ( DSTALPHA_MODE dstAlphaMode, u32 componen
return &last_entry->shader;
}
}
last_uid = uid;
// Check if shader is already in cache
PCache::iterator iter = pshaders.find(uid);
if (iter != pshaders.end())
@ -215,17 +215,17 @@ SHADER* ProgramShaderCache::SetShader ( DSTALPHA_MODE dstAlphaMode, u32 componen
last_entry->shader.Bind();
return &last_entry->shader;
}
// Make an entry in the table
PCacheEntry& newentry = pshaders[uid];
last_entry = &newentry;
newentry.in_cache = 0;
VertexShaderCode vcode;
PixelShaderCode pcode;
GenerateVertexShaderCode(vcode, components, API_OPENGL);
GeneratePixelShaderCode(pcode, dstAlphaMode, API_OPENGL, components);
if (g_ActiveConfig.bEnableShaderDebugging)
{
newentry.shader.strvprog = vcode.GetBuffer();
@ -260,7 +260,7 @@ bool ProgramShaderCache::CompileShader ( SHADER& shader, const char* vcode, cons
{
GLuint vsid = CompileSingleShader(GL_VERTEX_SHADER, vcode);
GLuint psid = CompileSingleShader(GL_FRAGMENT_SHADER, pcode);
if(!vsid || !psid)
{
glDeleteShader(vsid);