Fix a few graphics issues, optimize shader ID generation (fewer shaders)

This commit is contained in:
Henrik Rydgard committed 2013-01-22 22:03:41 +01:00
1 parent 29f1ae5f70
commit e04f5156ee
5 files changed
+81 -61

No files matched your search

+50 -43
View File
@@ -41,19 +41,27 @@
void ComputeFragmentShaderID(FragmentShaderID *id)
{
memset(&id->d[0], 0, sizeof(id->d));
bool enableFog = gstate.isFogEnabled() && !gstate.isModeThrough() && !gstate.isModeClear();
int lmode = (gstate.lmode & 1) && (gstate.lightingEnable & 1);
if (gstate.clearmode & 1) {
// We only need one clear shader, so let's ignore the rest of the bits.
id->d[0] = 1;
} else {
// id->d[0] |= (gstate.clearmode & 1);
id->d[0] |= (gstate.texfunc & 0x7) << 1;
id->d[0] |= ((gstate.texfunc & 0x100) >> 8) << 4; // rgb or rgba
id->d[0] |= ((gstate.texfunc & 0x10000) >> 16) << 5; // color double
id->d[0] |= (gstate.lmode & 1) << 6;
id->d[0] |= (gstate.textureMapEnable & 1) << 7;
if (gstate.textureMapEnable & 1) {
id->d[0] |= 1 << 1;
id->d[0] |= (gstate.texfunc & 0x7) << 2;
id->d[0] |= ((gstate.texfunc & 0x100) >> 8) << 5; // rgb or rgba
id->d[0] |= ((gstate.texfunc & 0x10000) >> 16) << 6; // color double
}
id->d[0] |= (lmode & 1) << 6;
id->d[0] |= (gstate.alphaTestEnable & 1) << 8;
id->d[0] |= (gstate.alphatest & 0x7) << 9; // alpha test func
id->d[0] |= (gstate.fogEnable & 1) << 12;
if (gstate.alphaTestEnable & 1)
id->d[0] |= (gstate.alphatest & 0x7) << 9; // alpha test func
id->d[0] |= (gstate.colorTestEnable & 1) << 12;
if (gstate.colorTestEnable & 1)
id->d[0] |= (gstate.colortest & 0x3) << 13; // alpha test func
id->d[0] |= (enableFog & 1) << 15;
}
}
@@ -70,7 +78,7 @@ void GenerateFragmentShader(char *buffer)
WRITE(p, "#version 110\n");
#endif
int lmode = gstate.lmode & 1;
int lmode = (gstate.lmode & 1) && (gstate.lightingEnable & 1);
int doTexture = (gstate.textureMapEnable & 1) && !(gstate.clearmode & 1);
bool enableFog = gstate.isFogEnabled() && !gstate.isModeThrough() && !gstate.isModeClear();
@@ -104,7 +112,7 @@ void GenerateFragmentShader(char *buffer)
const char *secondary = "";
// Secondary color for specular on top of texture
if (lmode) {
WRITE(p, " vec4 s = vec4(v_color1, 0.0);");
WRITE(p, " vec4 s = vec4(v_color1, 0.0);\n");
secondary = " + s";
} else {
WRITE(p, " vec4 s = vec4(0.0, 0.0, 0.0, 0.0);\n");
@@ -114,42 +122,41 @@ void GenerateFragmentShader(char *buffer)
if (gstate.textureMapEnable & 1) {
WRITE(p, " vec4 t = texture2D(tex, v_texcoord);\n");
WRITE(p, " vec4 p = clamp(v_color0, 0.0, 1.0);\n");
if (gstate.texfunc & 0x100) { // texfmt == RGBA
switch (gstate.texfunc & 0x7) {
case GE_TEXFUNC_MODULATE:
WRITE(p, " v = t * p%s;\n", secondary); break;
case GE_TEXFUNC_DECAL:
WRITE(p, " v = vec4(1.0 - t.a * p.rgb + t.a * u_texenv.rgb, p.a)%s;\n", secondary); break;
case GE_TEXFUNC_BLEND:
WRITE(p, " v = vec4((1.0 - t.rgb) * p.rgb + t.rgb * u_texenv.rgb, p.a * t.a)%s;\n", secondary); break;
case GE_TEXFUNC_REPLACE:
WRITE(p, " v = t%s;\n", secondary); break;
case GE_TEXFUNC_ADD:
WRITE(p, " v = vec4(t.rgb + p.rgb, p.a * t.a)%s;\n", secondary); break;
default:
WRITE(p, " v = p;\n"); break;
}
} else { // texfmt == RGB
switch (gstate.texfunc & 0x7) {
case GE_TEXFUNC_MODULATE:
WRITE(p, " v = vec4(t.rgb * p.rgb, p.a)%s;\n", secondary); break;
case GE_TEXFUNC_DECAL:
WRITE(p, " v = vec4(t.rgb, p.a)%s;\n", secondary); break;
case GE_TEXFUNC_BLEND:
WRITE(p, " v = vec4(1.0 - t.rgb) * p.rgb + t.rgb * u_texenv.rgb, p.a)%s;\n", secondary); break;
case GE_TEXFUNC_REPLACE:
WRITE(p, " v = vec4(t.rgb, p.a)%s;\n", secondary); break;
case GE_TEXFUNC_ADD:
WRITE(p, " v = vec4(t.rgb + p.rgb, p.a)%s;\n", secondary); break;
default:
WRITE(p, " v = p;\n"); break;
}
}
} else {
// No texture mapping
WRITE(p, " vec4 t = vec4(1.0, 1.0, 1.0, 1.0);\n");
WRITE(p, " vec4 p = clamp(v_color0, 0.0, 1.0);\n");
}
if (gstate.texfunc & 0x100) { // texfmt == RGBA
switch (gstate.texfunc & 0x7) {
case GE_TEXFUNC_MODULATE:
WRITE(p, " v = t * p%s;\n", secondary); break;
case GE_TEXFUNC_DECAL:
WRITE(p, " v = vec4(1.0 - t.a * p.rgb + t.a * u_texenv.rgb, p.a)%s;\n", secondary); break;
case GE_TEXFUNC_BLEND:
WRITE(p, " v = vec4((1.0 - t.rgb) * p.rgb + t.rgb * u_texenv.rgb, p.a * t.a)%s;\n", secondary); break;
case GE_TEXFUNC_REPLACE:
WRITE(p, " v = t%s;\n", secondary); break;
case GE_TEXFUNC_ADD:
WRITE(p, " v = vec4(t.rgb + p.rgb, p.a * t.a)%s;\n", secondary); break;
default:
WRITE(p, " v = p;\n"); break;
}
} else { // texfmt == RGB
switch (gstate.texfunc & 0x7) {
case GE_TEXFUNC_MODULATE:
WRITE(p, " v = vec4(t.rgb * p.rgb, p.a)%s;\n", secondary); break;
case GE_TEXFUNC_DECAL:
WRITE(p, " v = vec4(t.rgb, p.a)%s;\n", secondary); break;
case GE_TEXFUNC_BLEND:
WRITE(p, " v = vec4(1.0 - t.rgb) * p.rgb + t.rgb * u_texenv.rgb, p.a)%s;\n", secondary); break;
case GE_TEXFUNC_REPLACE:
WRITE(p, " v = vec4(t.rgb, p.a)%s;\n", secondary); break;
case GE_TEXFUNC_ADD:
WRITE(p, " v = vec4(t.rgb + p.rgb, p.a)%s;\n", secondary); break;
default:
WRITE(p, " v = p;\n"); break;
}
WRITE(p, " v = clamp(v_color0, 0.0, 1.0)%s;\n", secondary);
}
// Color doubling
if (gstate.texfunc & 0x10000) {
+11 -2
View File
@@ -15,6 +15,15 @@
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#ifdef _WIN32
#define SHADERLOG
#endif
#ifdef SHADERLOG
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif
#include <map>
#include "math/lin/matrix4x4.h"
@@ -26,8 +35,8 @@
Shader::Shader(const char *code, uint32_t shaderType) {
source_ = code;
#ifdef _WIN32
// OutputDebugString(code);
#ifdef SHADERLOG
OutputDebugString(code);
#endif
shader = glCreateShader(shaderType);
glShaderSource(shader, 1, &code, 0);
+3 -2
View File
@@ -299,8 +299,8 @@ const GlTypeInfo GLComp[8] = {
{GL_FLOAT, 2, GL_FALSE}, // DEC_FLOAT_2,
{GL_FLOAT, 3, GL_FALSE}, // DEC_FLOAT_3,
{GL_FLOAT, 4, GL_FALSE}, // DEC_FLOAT_4,
{GL_BYTE, 3, GL_TRUE}, // DEC_S8_3,
{GL_SHORT, 3, GL_TRUE},// DEC_S16_3,
{GL_BYTE, 4, GL_TRUE}, // DEC_S8_3,
{GL_SHORT, 4, GL_TRUE},// DEC_S16_3,
{GL_UNSIGNED_BYTE, 4, GL_TRUE},// DEC_U8_4,
};
@@ -489,6 +489,7 @@ void TransformDrawEngine::SoftwareTransformAndDraw(
c0[1] = ((gstate.materialambient >> 8) & 0xFF) / 255.f;
c0[2] = ((gstate.materialambient >> 16)& 0xFF) / 255.f;
c0[3] = (gstate.materialalpha & 0xFF) / 255.f;
memset(c1, 0, sizeof(c1));
}
}
+2 -4
View File
@@ -383,20 +383,18 @@ void VertexDecoder::Step_PosS8Through() const
{
float *v = (float *)(decoded_ + decFmt.posoff);
const s8 *sv = (const s8*)(ptr_ + posoff);
const u8 *uv = (const u8*)(ptr_ + posoff);
v[0] = sv[0];
v[1] = sv[1];
v[2] = uv[2];
v[2] = sv[2];
}
void VertexDecoder::Step_PosS16Through() const
{
float *v = (float *)(decoded_ + decFmt.posoff);
const s16 *sv = (const s16*)(ptr_ + posoff);
const u16 *uv = (const u16*)(ptr_ + posoff);
v[0] = sv[0];
v[1] = sv[1];
v[2] = uv[2];
v[2] = sv[2];
}
void VertexDecoder::Step_PosFloatThrough() const
+15 -10
View File
@@ -52,9 +52,10 @@ void ComputeVertexShaderID(VertexShaderID *id, int prim)
bool hasNormal = (gstate.vertType & GE_VTYPE_NRM_MASK) != 0;
bool hasBones = (gstate.vertType & GE_VTYPE_WEIGHT_MASK) != 0;
bool enableFog = gstate.isFogEnabled() && !gstate.isModeThrough() && !gstate.isModeClear();
bool lmode = (gstate.lmode & 1) && (gstate.lightingEnable & 1);
memset(id->d, 0, sizeof(id->d));
id->d[0] = gstate.lmode & 1;
id->d[0] = lmode & 1;
id->d[0] |= ((int)gstate.isModeThrough()) << 1;
id->d[0] |= ((int)enableFog) << 2;
id->d[0] |= doTexture << 3;
@@ -78,15 +79,19 @@ void ComputeVertexShaderID(VertexShaderID *id, int prim)
// Bones
id->d[0] |= (gstate.getNumBoneWeights() - 1) << 22;
// Light bits
for (int i = 0; i < 4; i++) {
id->d[1] |= (gstate.ltype[i] & 3) << (i * 4);
id->d[1] |= ((gstate.ltype[i] >> 8) & 3) << (i * 4 + 2);
}
id->d[1] |= (gstate.materialupdate & 7) << 16;
// Okay, d[1] coming up. ==============
id->d[1] |= (gstate.lightingEnable & 1) << 19;
for (int i = 0; i < 4; i++) {
id->d[1] |= (gstate.lightEnable[i] & 1) << (20 + i);
if (gstate.lightingEnable & 1) {
// Light bits
for (int i = 0; i < 4; i++) {
id->d[1] |= (gstate.ltype[i] & 3) << (i * 4);
id->d[1] |= ((gstate.ltype[i] >> 8) & 3) << (i * 4 + 2);
}
id->d[1] |= (gstate.materialupdate & 7) << 16;
for (int i = 0; i < 4; i++) {
id->d[1] |= (gstate.lightEnable[i] & 1) << (20 + i);
}
}
}
}
@@ -127,7 +132,7 @@ void GenerateVertexShader(int prim, char *buffer) {
WRITE(p, "#version 110\n");
#endif
int lmode = gstate.lmode & 1;
int lmode = (gstate.lmode & 1) && (gstate.lightingEnable & 1);
int doTexture = (gstate.textureMapEnable & 1) && !(gstate.clearmode & 1);
bool hwXForm = CanUseHardwareTransform(prim);