mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-12-06 04:33:49 +01:00
Simplify transform in throughmode/sw (rectangles.)
This should make it a bit faster, a bit less work.
This commit is contained in:
1 parent
8c8613b2db
commit
39cb74a8d3
6 files changed
+86
-52
No files matched your search
@@ -158,7 +158,7 @@ void SoftwareTransform(
|
||||
// not really sure what a sensible value might be.
|
||||
fog_slope = fog_slope < 0.0f ? -10000.0f : 10000.0f;
|
||||
}
|
||||
if (my_isnan(fog_slope)) {
|
||||
if (my_isnan(fog_slope)) {
|
||||
// Workaround for https://github.com/hrydgard/ppsspp/issues/5384#issuecomment-38365988
|
||||
// Just put the fog far away at a large finite distance.
|
||||
// Infinities and NaNs are rather unpredictable in shaders on many GPUs
|
||||
@@ -170,34 +170,50 @@ void SoftwareTransform(
|
||||
VertexReader reader(decoded, decVtxFormat, vertType);
|
||||
// We flip in the fragment shader for GE_TEXMAP_TEXTURE_MATRIX.
|
||||
const bool flipV = gstate_c.flipTexture && gstate.getUVGenMode() != GE_TEXMAP_TEXTURE_MATRIX;
|
||||
for (int index = 0; index < maxIndex; index++) {
|
||||
reader.Goto(index);
|
||||
|
||||
float v[3] = {0, 0, 0};
|
||||
Vec4f c0 = Vec4f(1, 1, 1, 1);
|
||||
Vec4f c1 = Vec4f(0, 0, 0, 0);
|
||||
float uv[3] = {0, 0, 1};
|
||||
float fogCoef = 1.0f;
|
||||
|
||||
if (throughmode) {
|
||||
if (throughmode) {
|
||||
for (int index = 0; index < maxIndex; index++) {
|
||||
// Do not touch the coordinates or the colors. No lighting.
|
||||
reader.ReadPos(v);
|
||||
reader.Goto(index);
|
||||
// TODO: Write to a flexible buffer, we don't always need all four components.
|
||||
TransformedVertex &vert = transformed[index];
|
||||
reader.ReadPos(vert.pos);
|
||||
|
||||
if (reader.hasColor0()) {
|
||||
reader.ReadColor0(&c0.x);
|
||||
// c1 is already 0.
|
||||
reader.ReadColor0_8888(vert.color0);
|
||||
} else {
|
||||
c0 = Vec4f::FromRGBA(gstate.getMaterialAmbientRGBA());
|
||||
vert.color0_32 = gstate.getMaterialAmbientRGBA();
|
||||
}
|
||||
|
||||
if (reader.hasUV()) {
|
||||
reader.ReadUV(uv);
|
||||
reader.ReadUV(vert.uv);
|
||||
|
||||
uv[0] *= uscale;
|
||||
uv[1] *= vscale;
|
||||
vert.u *= uscale;
|
||||
vert.v *= vscale;
|
||||
}
|
||||
else
|
||||
{
|
||||
vert.u = 0.0f;
|
||||
vert.v = 0.0f;
|
||||
}
|
||||
fogCoef = 1.0f;
|
||||
// Scale UV?
|
||||
} else {
|
||||
|
||||
if (flipV) {
|
||||
vert.v = 1.0f - vert.v;
|
||||
}
|
||||
|
||||
// Ignore color1 and fog, never used in throughmode anyway.
|
||||
// The w of uv is also never used (hardcoded to 1.0.)
|
||||
}
|
||||
} else {
|
||||
for (int index = 0; index < maxIndex; index++) {
|
||||
reader.Goto(index);
|
||||
|
||||
float v[3] = {0, 0, 0};
|
||||
Vec4f c0 = Vec4f(1, 1, 1, 1);
|
||||
Vec4f c1 = Vec4f(0, 0, 0, 0);
|
||||
float uv[3] = {0, 0, 1};
|
||||
float fogCoef = 1.0f;
|
||||
|
||||
// We do software T&L for now
|
||||
float out[3];
|
||||
float pos[3];
|
||||
@@ -369,17 +385,17 @@ void SoftwareTransform(
|
||||
// Transform the coord by the view matrix.
|
||||
Vec3ByMatrix43(v, out, gstate.viewMatrix);
|
||||
fogCoef = (v[2] + fog_end) * fog_slope;
|
||||
}
|
||||
|
||||
// TODO: Write to a flexible buffer, we don't always need all four components.
|
||||
memcpy(&transformed[index].x, v, 3 * sizeof(float));
|
||||
transformed[index].fog = fogCoef;
|
||||
memcpy(&transformed[index].u, uv, 3 * sizeof(float));
|
||||
if (flipV) {
|
||||
transformed[index].v = 1.0f - transformed[index].v;
|
||||
// TODO: Write to a flexible buffer, we don't always need all four components.
|
||||
memcpy(&transformed[index].x, v, 3 * sizeof(float));
|
||||
transformed[index].fog = fogCoef;
|
||||
memcpy(&transformed[index].u, uv, 3 * sizeof(float));
|
||||
if (flipV) {
|
||||
transformed[index].v = 1.0f - transformed[index].v;
|
||||
}
|
||||
transformed[index].color0_32 = c0.ToRGBA();
|
||||
transformed[index].color1_32 = c1.ToRGBA();
|
||||
}
|
||||
transformed[index].color0_32 = c0.ToRGBA();
|
||||
transformed[index].color1_32 = c1.ToRGBA();
|
||||
}
|
||||
|
||||
// Here's the best opportunity to try to detect rectangles used to clear the screen, and
|
||||
|
||||
@@ -75,8 +75,18 @@ struct DecVtxFormat {
|
||||
// This struct too.
|
||||
struct TransformedVertex
|
||||
{
|
||||
float x, y, z, fog; // in case of morph, preblend during decode
|
||||
float u; float v; float w; // scaled by uscale, vscale, if there
|
||||
union {
|
||||
struct {
|
||||
float x, y, z, fog; // in case of morph, preblend during decode
|
||||
};
|
||||
float pos[4];
|
||||
};
|
||||
union {
|
||||
struct {
|
||||
float u; float v; float w; // scaled by uscale, vscale, if there
|
||||
};
|
||||
float uv[3];
|
||||
};
|
||||
union {
|
||||
u8 color0[4]; // prelit
|
||||
u32 color0_32;
|
||||
|
||||
@@ -412,7 +412,7 @@ void ComputeFragmentShaderIDDX9(FragmentShaderIDDX9 *id) {
|
||||
// We only need one clear shader, so let's ignore the rest of the bits.
|
||||
id0 = 1;
|
||||
} else {
|
||||
bool lmode = gstate.isUsingSecondaryColor() && gstate.isLightingEnabled();
|
||||
bool lmode = gstate.isUsingSecondaryColor() && gstate.isLightingEnabled() && !gstate.isModeThrough();
|
||||
bool enableFog = gstate.isFogEnabled() && !gstate.isModeThrough();
|
||||
bool enableAlphaTest = gstate.isAlphaTestEnabled() && !IsAlphaTestTriviallyTrue() && !g_Config.bDisableAlphaTest;
|
||||
bool alphaTestAgainstZero = IsAlphaTestAgainstZero();
|
||||
@@ -497,7 +497,7 @@ void ComputeFragmentShaderIDDX9(FragmentShaderIDDX9 *id) {
|
||||
void GenerateFragmentShaderDX9(char *buffer) {
|
||||
char *p = buffer;
|
||||
|
||||
bool lmode = gstate.isUsingSecondaryColor() && gstate.isLightingEnabled();
|
||||
bool lmode = gstate.isUsingSecondaryColor() && gstate.isLightingEnabled() && !gstate.isModeThrough();
|
||||
bool doTexture = gstate.isTextureMapEnabled() && !gstate.isModeClear();
|
||||
bool enableFog = gstate.isFogEnabled() && !gstate.isModeThrough() && !gstate.isModeClear();
|
||||
bool enableAlphaTest = gstate.isAlphaTestEnabled() && !IsAlphaTestTriviallyTrue() && !gstate.isModeClear() && !g_Config.bDisableAlphaTest;
|
||||
|
||||
@@ -232,7 +232,7 @@ void GenerateVertexShaderDX9(int prim, char *buffer, bool useHWTransform) {
|
||||
WRITE(p, "%s", boneWeightAttrDecl[TranslateNumBones(vertTypeGetNumBoneWeights(vertType))]);
|
||||
}
|
||||
if (doTexture && hasTexcoord) {
|
||||
if (doTextureProjection)
|
||||
if (doTextureProjection && !throughmode)
|
||||
WRITE(p, " float3 texcoord : TEXCOORD0;\n");
|
||||
else
|
||||
WRITE(p, " float2 texcoord : TEXCOORD0;\n");
|
||||
@@ -265,7 +265,7 @@ void GenerateVertexShaderDX9(int prim, char *buffer, bool useHWTransform) {
|
||||
WRITE(p, " float2 v_texcoord: TEXCOORD0;\n");
|
||||
}
|
||||
WRITE(p, " float4 v_color0 : COLOR0;\n");
|
||||
if (lmode)
|
||||
if (lmode && !throughmode)
|
||||
WRITE(p, " float3 v_color1 : COLOR1;\n");
|
||||
|
||||
if (enableFog) {
|
||||
@@ -279,18 +279,22 @@ void GenerateVertexShaderDX9(int prim, char *buffer, bool useHWTransform) {
|
||||
// Simple pass-through of vertex data to fragment shader
|
||||
if (doTexture) {
|
||||
if (doTextureProjection) {
|
||||
WRITE(p, " Out.v_texcoord = In.texcoord;\n");
|
||||
if (throughmode) {
|
||||
WRITE(p, " Out.v_texcoord = float3(In.texcoord.x, In.texcoord.y, 1.0);\n");
|
||||
} else {
|
||||
WRITE(p, " Out.v_texcoord = In.texcoord;\n");
|
||||
}
|
||||
} else {
|
||||
WRITE(p, " Out.v_texcoord = In.texcoord.xy;\n");
|
||||
}
|
||||
}
|
||||
if (hasColor) {
|
||||
WRITE(p, " Out.v_color0 = In.color0;\n");
|
||||
if (lmode)
|
||||
if (lmode && !throughmode)
|
||||
WRITE(p, " Out.v_color1 = In.color1.rgb;\n");
|
||||
} else {
|
||||
WRITE(p, " Out.v_color0 = In.u_matambientalpha;\n");
|
||||
if (lmode)
|
||||
if (lmode && !throughmode)
|
||||
WRITE(p, " Out.v_color1 = float3(0.0);\n");
|
||||
}
|
||||
if (enableFog) {
|
||||
@@ -493,9 +497,9 @@ void GenerateVertexShaderDX9(int prim, char *buffer, bool useHWTransform) {
|
||||
if (lmode) {
|
||||
WRITE(p, " Out.v_color0 = clamp(lightSum0, 0.0, 1.0);\n");
|
||||
// v_color1 only exists when lmode = 1.
|
||||
if (specularIsZero) {
|
||||
if (specularIsZero && !throughmode) {
|
||||
WRITE(p, " Out.v_color1 = float3(0, 0, 0);\n");
|
||||
} else {
|
||||
} else if (!throughmode) {
|
||||
WRITE(p, " Out.v_color1 = clamp(lightSum1, 0.0, 1.0);\n");
|
||||
}
|
||||
} else {
|
||||
@@ -512,7 +516,7 @@ void GenerateVertexShaderDX9(int prim, char *buffer, bool useHWTransform) {
|
||||
} else {
|
||||
WRITE(p, " Out.v_color0 = u_matambientalpha;\n");
|
||||
}
|
||||
if (lmode)
|
||||
if (lmode && !throughmode)
|
||||
WRITE(p, " Out.v_color1 = float3(0, 0, 0);\n");
|
||||
}
|
||||
|
||||
|
||||
@@ -394,7 +394,7 @@ void ComputeFragmentShaderID(ShaderID *id) {
|
||||
// We only need one clear shader, so let's ignore the rest of the bits.
|
||||
id0 = 1;
|
||||
} else {
|
||||
bool lmode = gstate.isUsingSecondaryColor() && gstate.isLightingEnabled();
|
||||
bool lmode = gstate.isUsingSecondaryColor() && gstate.isLightingEnabled() && !gstate.isModeThrough();
|
||||
bool enableFog = gstate.isFogEnabled() && !gstate.isModeThrough();
|
||||
bool enableAlphaTest = gstate.isAlphaTestEnabled() && !IsAlphaTestTriviallyTrue() && !g_Config.bDisableAlphaTest;
|
||||
bool alphaTestAgainstZero = IsAlphaTestAgainstZero();
|
||||
@@ -568,7 +568,7 @@ void GenerateFragmentShader(char *buffer) {
|
||||
varying = "in";
|
||||
}
|
||||
|
||||
bool lmode = gstate.isUsingSecondaryColor() && gstate.isLightingEnabled();
|
||||
bool lmode = gstate.isUsingSecondaryColor() && gstate.isLightingEnabled() && !gstate.isModeThrough();
|
||||
bool doTexture = gstate.isTextureMapEnabled() && !gstate.isModeClear();
|
||||
bool enableFog = gstate.isFogEnabled() && !gstate.isModeThrough() && !gstate.isModeClear();
|
||||
bool enableAlphaTest = gstate.isAlphaTestEnabled() && !IsAlphaTestTriviallyTrue() && !gstate.isModeClear() && !g_Config.bDisableAlphaTest;
|
||||
|
||||
@@ -257,14 +257,14 @@ void GenerateVertexShader(int prim, u32 vertType, char *buffer, bool useHWTransf
|
||||
WRITE(p, "%s mediump vec3 normal;\n", attribute);
|
||||
|
||||
if (doTexture && hasTexcoord) {
|
||||
if (!useHWTransform && doTextureProjection)
|
||||
if (!useHWTransform && doTextureProjection && !throughmode)
|
||||
WRITE(p, "%s vec3 texcoord;\n", attribute);
|
||||
else
|
||||
WRITE(p, "%s vec2 texcoord;\n", attribute);
|
||||
}
|
||||
if (hasColor) {
|
||||
WRITE(p, "%s lowp vec4 color0;\n", attribute);
|
||||
if (lmode && !useHWTransform) // only software transform supplies color1 as vertex data
|
||||
if (lmode && !useHWTransform && !throughmode) // only software transform supplies color1 as vertex data
|
||||
WRITE(p, "%s lowp vec3 color1;\n", attribute);
|
||||
}
|
||||
|
||||
@@ -337,7 +337,7 @@ void GenerateVertexShader(int prim, u32 vertType, char *buffer, bool useHWTransf
|
||||
}
|
||||
|
||||
WRITE(p, "%s %s lowp vec4 v_color0;\n", shading, varying);
|
||||
if (lmode) {
|
||||
if (lmode && !throughmode) {
|
||||
WRITE(p, "%s %s lowp vec3 v_color1;\n", shading, varying);
|
||||
}
|
||||
if (doTexture) {
|
||||
@@ -362,15 +362,19 @@ void GenerateVertexShader(int prim, u32 vertType, char *buffer, bool useHWTransf
|
||||
if (!useHWTransform) {
|
||||
// Simple pass-through of vertex data to fragment shader
|
||||
if (doTexture) {
|
||||
WRITE(p, " v_texcoord = texcoord;\n");
|
||||
if (throughmode && doTextureProjection) {
|
||||
WRITE(p, " v_texcoord = vec3(texcoord, 1.0);\n");
|
||||
} else {
|
||||
WRITE(p, " v_texcoord = texcoord;\n");
|
||||
}
|
||||
}
|
||||
if (hasColor) {
|
||||
WRITE(p, " v_color0 = color0;\n");
|
||||
if (lmode)
|
||||
if (lmode && !throughmode)
|
||||
WRITE(p, " v_color1 = color1;\n");
|
||||
} else {
|
||||
WRITE(p, " v_color0 = u_matambientalpha;\n");
|
||||
if (lmode)
|
||||
if (lmode && !throughmode)
|
||||
WRITE(p, " v_color1 = vec3(0.0);\n");
|
||||
}
|
||||
if (enableFog) {
|
||||
@@ -580,9 +584,9 @@ void GenerateVertexShader(int prim, u32 vertType, char *buffer, bool useHWTransf
|
||||
if (lmode) {
|
||||
WRITE(p, " v_color0 = clamp(lightSum0, 0.0, 1.0);\n");
|
||||
// v_color1 only exists when lmode = 1.
|
||||
if (specularIsZero) {
|
||||
if (specularIsZero && !throughmode) {
|
||||
WRITE(p, " v_color1 = vec3(0.0);\n");
|
||||
} else {
|
||||
} else if (!throughmode) {
|
||||
WRITE(p, " v_color1 = clamp(lightSum1, 0.0, 1.0);\n");
|
||||
}
|
||||
} else {
|
||||
@@ -599,7 +603,7 @@ void GenerateVertexShader(int prim, u32 vertType, char *buffer, bool useHWTransf
|
||||
} else {
|
||||
WRITE(p, " v_color0 = u_matambientalpha;\n");
|
||||
}
|
||||
if (lmode)
|
||||
if (lmode && !throughmode)
|
||||
WRITE(p, " v_color1 = vec3(0.0);\n");
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user