From 449e3e1360bcc8381f84ffc4efa431d7007bf51b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sat, 28 Dec 2024 16:11:37 +0100 Subject: [PATCH] Very minor soft transform optimization --- GPU/Common/SoftwareTransformCommon.cpp | 8 ++++---- GPU/Common/VertexDecoderCommon.cpp | 6 +++--- GPU/Common/VertexDecoderCommon.h | 17 ++++++++++++++++- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/GPU/Common/SoftwareTransformCommon.cpp b/GPU/Common/SoftwareTransformCommon.cpp index b05ec9100b..dc6e813943 100644 --- a/GPU/Common/SoftwareTransformCommon.cpp +++ b/GPU/Common/SoftwareTransformCommon.cpp @@ -186,7 +186,7 @@ void SoftwareTransform::Transform(int prim, u32 vertType, const DecVtxFormat &de 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); + reader.ReadPosThrough(vert.pos); vert.pos_w = 1.0f; if (hasColor) { @@ -225,7 +225,7 @@ void SoftwareTransform::Transform(int prim, u32 vertType, const DecVtxFormat &de float pos[3]; Vec3f normal(0, 0, 1); Vec3f worldnormal(0, 0, 1); - reader.ReadPos(pos); + reader.ReadPosNonThrough(pos); float ruv[2] = { 0.0f, 0.0f }; if (reader.hasUV()) @@ -984,7 +984,7 @@ u32 NormalizeVertices(SimpleVertex *sverts, u8 *bufPtr, const u8 *inPtr, int low nrm[1] = 0; nrm[2] = 1.0f; } - reader.ReadPos(pos); + reader.ReadPosAuto(pos); // Apply skinning transform directly float weights[8]; @@ -1029,7 +1029,7 @@ u32 NormalizeVertices(SimpleVertex *sverts, u8 *bufPtr, const u8 *inPtr, int low sv.nrm.y = 0.0f; sv.nrm.z = 1.0f; } - reader.ReadPos((float *)&sv.pos); + reader.ReadPosAuto((float *)&sv.pos); } } diff --git a/GPU/Common/VertexDecoderCommon.cpp b/GPU/Common/VertexDecoderCommon.cpp index 12c8f13de0..78b424e977 100644 --- a/GPU/Common/VertexDecoderCommon.cpp +++ b/GPU/Common/VertexDecoderCommon.cpp @@ -185,7 +185,7 @@ void PrintDecodedVertex(const VertexReader &vtx) { } // Etc.. float pos[3]; - vtx.ReadPos(pos); + vtx.ReadPosAuto(pos); printf("P: %f %f %f\n", pos[0], pos[1], pos[2]); } @@ -1420,8 +1420,8 @@ static bool DecodedVertsAreSimilar(const VertexReader &vtx1, const VertexReader return false; } } - vtx1.ReadPos(vec1.AsArray()); - vtx2.ReadPos(vec2.AsArray()); + vtx1.ReadPosAuto(vec1.AsArray()); + vtx2.ReadPosAuto(vec2.AsArray()); float diff = LargestAbsDiff(vec1, vec2, 3); if (diff >= 1.0 / 512.0f) { WARN_LOG(Log::G3D, "Pos diff %f", diff); diff --git a/GPU/Common/VertexDecoderCommon.h b/GPU/Common/VertexDecoderCommon.h index 4b905f03c9..cca574aec4 100644 --- a/GPU/Common/VertexDecoderCommon.h +++ b/GPU/Common/VertexDecoderCommon.h @@ -124,7 +124,7 @@ class VertexReader { public: VertexReader(const u8 *base, const DecVtxFormat &decFmt, int vtype) : base_(base), data_(base), decFmt_(decFmt), vtype_(vtype) {} - void ReadPos(float pos[3]) const { + void ReadPosAuto(float pos[3]) const { // Only DEC_FLOAT_3 is supported. const float *f = (const float *)(data_ + decFmt_.posoff); pos[0] = f[0]; @@ -137,6 +137,21 @@ public: } } + void ReadPosThrough(float pos[3]) const { + // Only DEC_FLOAT_3 is supported. + const float *f = (const float *)(data_ + decFmt_.posoff); + pos[0] = f[0]; + pos[1] = f[1]; + // Integer value passed in a float. Clamped to 0, 65535. + pos[2] = (int)f[2] * (1.0f / 65535.0f); + } + + void ReadPosNonThrough(float pos[3]) const { + // Only DEC_FLOAT_3 is supported. + const float *f = (const float *)(data_ + decFmt_.posoff); + memcpy(pos, f, 12); + } + void ReadPosThroughZ16(float pos[3]) const { // Only DEC_FLOAT_3 is supported. const float *f = (const float *)(data_ + decFmt_.posoff);