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> template<class T,class UidType>
void GenerateLightShader(T& object, int index, int litchan_index, const char* lightsName, int coloralpha) 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 LitChannel& chan = (litchan_index > 1) ? xfregs.alpha[litchan_index-2] : xfregs.color[litchan_index];
const char* swizzle = "xyzw"; const char* swizzle = "xyzw";
if (coloralpha == 1 ) swizzle = "xyz"; if (coloralpha == 1 ) swizzle = "xyz";

View File

@ -19,7 +19,6 @@
#include <cmath> #include <cmath>
#include <assert.h> #include <assert.h>
#include <locale.h> #include <locale.h>
#include <typeinfo>
#include "LightingShaderGen.h" #include "LightingShaderGen.h"
#include "PixelShaderGen.h" #include "PixelShaderGen.h"
@ -271,13 +270,12 @@ template<class T>
void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u32 components) void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u32 components)
{ {
// TODO: Can be optimized if using alpha pass // TODO: Can be optimized if using alpha pass
#define SetUidField(name, value) if (typeid(T) == typeid(PixelShaderUid)) {out.GetUidData().name = value; }; #define SetUidField(name, value) if (&out.GetUidData() != NULL) {out.GetUidData().name = value; };
#define OR_UidField(name, value) if (typeid(T) == typeid(PixelShaderUid)) {out.GetUidData().name |= value; }; #define OR_UidField(name, value) if (&out.GetUidData() != NULL) {out.GetUidData().name |= value; };
if (typeid(T) == typeid(PixelShaderCode))
{
setlocale(LC_NUMERIC, "C"); // Reset locale for compilation
out.SetBuffer(text); out.SetBuffer(text);
} if (out.GetBuffer() != NULL)
setlocale(LC_NUMERIC, "C"); // Reset locale for compilation
/// text[sizeof(text) - 1] = 0x7C; // canary /// text[sizeof(text) - 1] = 0x7C; // canary
unsigned int numStages = bpmem.genMode.numtevstages + 1; unsigned int numStages = bpmem.genMode.numtevstages + 1;
@ -669,6 +667,7 @@ void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u
/// if (text[sizeof(text) - 1] != 0x7C) /// if (text[sizeof(text) - 1] != 0x7C)
/// PanicAlert("PixelShader generator - buffer too small, canary has been eaten!"); /// PanicAlert("PixelShader generator - buffer too small, canary has been eaten!");
if (out.GetBuffer() != NULL)
setlocale(LC_NUMERIC, ""); // restore locale 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) 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 && // 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) // s_constant_cache[const_number*4+2] == f3 && s_constant_cache[const_number*4+3] == f4)
return; // return;
g_renderer->SetPSConstant4f(const_number, f1, f2, f3, f4); g_renderer->SetPSConstant4f(const_number, f1, f2, f3, f4);
s_constant_cache[const_number*4] = f1; 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) 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] && // 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]) // s_constant_cache[const_number*4+2] == f[2] && s_constant_cache[const_number*4+3] == f[3])
return; // return;
g_renderer->SetPSConstant4fv(const_number, f); g_renderer->SetPSConstant4fv(const_number, f);
s_constant_cache[const_number*4] = f[0]; 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) inline void SetMultiPSConstant4fv(unsigned int const_number, unsigned int count, const float *f)
{ {
for (unsigned int i = 0; i < 4*count; ++i) // for (unsigned int i = 0; i < 4*count; ++i)
if (s_constant_cache[const_number*4+i] != f[i]) // if (s_constant_cache[const_number*4+i] != f[i])
break; // break;
else if (i == 4*count-1) // else if (i == 4*count-1)
return; // return;
g_renderer->SetMultiPSConstant4fv(const_number, count, f); g_renderer->SetMultiPSConstant4fv(const_number, count, f);
for (unsigned int i = 0; i < 4*count; ++i) 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) 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; ++necessary_updates;
SetPSTextureDims(i); SetPSTextureDims(i);

View File

@ -33,7 +33,7 @@ public:
const char* GetBuffer() { return NULL; } const char* GetBuffer() { return NULL; }
void SetBuffer(char* buffer) { } void SetBuffer(char* buffer) { }
inline void SetConstantsUsed(unsigned int first_index, unsigned int last_index) {} 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> template<class uid_data>
@ -122,7 +122,8 @@ public:
inline bool ConstantIsUsed(unsigned int index) inline bool ConstantIsUsed(unsigned int index)
{ {
return constant_usage[index]; return true;
// return constant_usage[index];
} }
private: private:
std::vector<bool> constant_usage; // TODO: Is vector<bool> appropriate here? std::vector<bool> constant_usage; // TODO: Is vector<bool> appropriate here?

View File

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