Minor VertexReader optimizations

This commit is contained in:
Henrik Rydgård 2022-12-01 15:47:29 +01:00
parent 423fa6d848
commit d02f46cb27
2 changed files with 9 additions and 10 deletions

View file

@ -205,6 +205,9 @@ void SoftwareTransform::Decode(int prim, u32 vertType, const DecVtxFormat &decVt
VertexReader reader(decoded, decVtxFormat, vertType); VertexReader reader(decoded, decVtxFormat, vertType);
if (throughmode) { if (throughmode) {
const u32 materialAmbientRGBA = gstate.getMaterialAmbientRGBA();
const bool hasColor = reader.hasColor0();
const bool hasUV = reader.hasUV();
for (int index = 0; index < maxIndex; index++) { for (int index = 0; index < maxIndex; index++) {
// Do not touch the coordinates or the colors. No lighting. // Do not touch the coordinates or the colors. No lighting.
reader.Goto(index); reader.Goto(index);
@ -213,7 +216,7 @@ void SoftwareTransform::Decode(int prim, u32 vertType, const DecVtxFormat &decVt
reader.ReadPos(vert.pos); reader.ReadPos(vert.pos);
vert.pos_w = 1.0f; vert.pos_w = 1.0f;
if (reader.hasColor0()) { if (hasColor) {
if (provokeIndOffset != 0 && index + provokeIndOffset < maxIndex) { if (provokeIndOffset != 0 && index + provokeIndOffset < maxIndex) {
reader.Goto(index + provokeIndOffset); reader.Goto(index + provokeIndOffset);
reader.ReadColor0_8888(vert.color0); reader.ReadColor0_8888(vert.color0);
@ -222,10 +225,10 @@ void SoftwareTransform::Decode(int prim, u32 vertType, const DecVtxFormat &decVt
reader.ReadColor0_8888(vert.color0); reader.ReadColor0_8888(vert.color0);
} }
} else { } else {
vert.color0_32 = gstate.getMaterialAmbientRGBA(); vert.color0_32 = materialAmbientRGBA;
} }
if (reader.hasUV()) { if (hasUV) {
reader.ReadUV(vert.uv); reader.ReadUV(vert.uv);
vert.u *= uscale; vert.u *= uscale;
@ -240,6 +243,7 @@ void SoftwareTransform::Decode(int prim, u32 vertType, const DecVtxFormat &decVt
// The w of uv is also never used (hardcoded to 1.0.) // The w of uv is also never used (hardcoded to 1.0.)
} }
} else { } else {
const Vec4f materialAmbientRGBA = Vec4f::FromRGBA(gstate.getMaterialAmbientRGBA());
// Okay, need to actually perform the full transform. // Okay, need to actually perform the full transform.
for (int index = 0; index < maxIndex; index++) { for (int index = 0; index < maxIndex; index++) {
reader.Goto(index); reader.Goto(index);
@ -267,7 +271,7 @@ void SoftwareTransform::Decode(int prim, u32 vertType, const DecVtxFormat &decVt
if (reader.hasColor0()) if (reader.hasColor0())
reader.ReadColor0(unlitColor.AsArray()); reader.ReadColor0(unlitColor.AsArray());
else else
unlitColor = Vec4f::FromRGBA(gstate.getMaterialAmbientRGBA()); unlitColor = materialAmbientRGBA;
if (reader.hasNormal()) if (reader.hasNormal())
reader.ReadNrm(normal.AsArray()); reader.ReadNrm(normal.AsArray());

View file

@ -166,7 +166,6 @@ public:
} }
break; break;
default: default:
ERROR_LOG_REPORT_ONCE(fmtnrm, G3D, "Reader: Unsupported Nrm Format %d", decFmt_.nrmfmt);
memset(nrm, 0, sizeof(float) * 3); memset(nrm, 0, sizeof(float) * 3);
break; break;
} }
@ -188,7 +187,6 @@ public:
memcpy(color, data_ + decFmt_.c0off, 16); memcpy(color, data_ + decFmt_.c0off, 16);
break; break;
default: default:
ERROR_LOG_REPORT_ONCE(fmtc0, G3D, "Reader: Unsupported C0 Format %d", decFmt_.c0fmt);
memset(color, 0, sizeof(float) * 4); memset(color, 0, sizeof(float) * 4);
break; break;
} }
@ -199,8 +197,7 @@ public:
case DEC_U8_4: case DEC_U8_4:
{ {
const u8 *b = (const u8 *)(data_ + decFmt_.c0off); const u8 *b = (const u8 *)(data_ + decFmt_.c0off);
for (int i = 0; i < 4; i++) memcpy(color, b, 4);
color[i] = b[i];
} }
break; break;
case DEC_FLOAT_4: case DEC_FLOAT_4:
@ -211,7 +208,6 @@ public:
} }
break; break;
default: default:
ERROR_LOG_REPORT_ONCE(fmtc0_8888, G3D, "Reader: Unsupported C0 Format %d", decFmt_.c0fmt);
memset(color, 0, sizeof(u8) * 4); memset(color, 0, sizeof(u8) * 4);
break; break;
} }
@ -231,7 +227,6 @@ public:
memcpy(color, data_ + decFmt_.c1off, 12); memcpy(color, data_ + decFmt_.c1off, 12);
break; break;
default: default:
ERROR_LOG_REPORT_ONCE(fmtc1, G3D, "Reader: Unsupported C1 Format %d", decFmt_.c1fmt);
memset(color, 0, sizeof(float) * 3); memset(color, 0, sizeof(float) * 3);
break; break;
} }