From 9aad4dc84806dbfac9fdd6fa04e7d97ceb5fd078 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 26 May 2018 13:14:17 -0700 Subject: [PATCH] GE Debugger: Cleaned repetition in spline preview. --- GPU/Common/SplineCommon.cpp | 10 ++-- GPU/Common/SplineCommon.h | 4 +- Windows/GEDebugger/VertexPreview.cpp | 80 +++++++++++----------------- 3 files changed, 38 insertions(+), 56 deletions(-) diff --git a/GPU/Common/SplineCommon.cpp b/GPU/Common/SplineCommon.cpp index 41eb4aec93..948c31b1f2 100644 --- a/GPU/Common/SplineCommon.cpp +++ b/GPU/Common/SplineCommon.cpp @@ -79,7 +79,7 @@ inline __m128 SSENormalizeMultiplier(bool useSSE4, __m128 v) -static void CopyQuad(u8 *&dest, const SimpleVertex *v1, const SimpleVertex *v2, const SimpleVertex* v3, const SimpleVertex *v4) { +static void CopyQuad(u8 *&dest, const SimpleVertex *v1, const SimpleVertex *v2, const SimpleVertex *v3, const SimpleVertex *v4) { int vertexSize = sizeof(SimpleVertex); memcpy(dest, v1, vertexSize); dest += vertexSize; @@ -458,7 +458,7 @@ static void SplinePatchFullQuality(u8 *&dest, u16 *indices, int &count, const Sp OutputDebugStringA(temp); Crash(); }*/ - SimpleVertex *a = spatch.points[idx]; + const SimpleVertex *a = spatch.points[idx]; AccumulateWeighted(vert_pos, a->pos, fv); if (origTc) { vert->uv[0] += a->uv[0] * f; @@ -877,7 +877,7 @@ void DrawEngineCommon::SubmitSpline(const void *control_points, const void *indi } // TODO: Do something less idiotic to manage this buffer - SimpleVertex **points = new SimpleVertex *[count_u * count_v]; + auto points = new const SimpleVertex *[count_u * count_v]; // Make an array of pointers to the control points, to get rid of indices. for (int idx = 0; idx < count_u * count_v; idx++) { @@ -1013,7 +1013,7 @@ void DrawEngineCommon::SubmitBezier(const void *control_points, const void *indi float *t = tex; float *c = col; for (int idx = 0; idx < count_u * count_v; idx++) { - SimpleVertex *point = simplified_control_points + (indices ? idxConv.convert(idx) : idx); + const SimpleVertex *point = simplified_control_points + (indices ? idxConv.convert(idx) : idx); memcpy(p, point->pos.AsArray(), 3 * sizeof(float)); p += posStride; if (hasTexCoords) { @@ -1026,7 +1026,7 @@ void DrawEngineCommon::SubmitBezier(const void *control_points, const void *indi } } if (!hasColor) { - SimpleVertex *point = simplified_control_points + (indices ? idxConv.convert(0) : 0); + const SimpleVertex *point = simplified_control_points + (indices ? idxConv.convert(0) : 0); memcpy(col, Vec4f::FromRGBA(point->color_32).AsArray(), 4 * sizeof(float)); } } else { diff --git a/GPU/Common/SplineCommon.h b/GPU/Common/SplineCommon.h index 1cddb1ddb2..7291f5bc9f 100644 --- a/GPU/Common/SplineCommon.h +++ b/GPU/Common/SplineCommon.h @@ -36,7 +36,7 @@ struct SimpleVertex { // We decode all vertices into a common format for easy interpolation and stuff. // Not fast but can be optimized later. struct BezierPatch { - SimpleVertex *points[16]; + const SimpleVertex *points[16]; // These are used to generate UVs. int u_index, v_index; @@ -48,7 +48,7 @@ struct BezierPatch { }; struct SplinePatchLocal { - SimpleVertex **points; + const SimpleVertex **points; int tess_u; int tess_v; int count_u; diff --git a/Windows/GEDebugger/VertexPreview.cpp b/Windows/GEDebugger/VertexPreview.cpp index 8714aa05e3..6eeef756dc 100644 --- a/Windows/GEDebugger/VertexPreview.cpp +++ b/Windows/GEDebugger/VertexPreview.cpp @@ -165,7 +165,7 @@ u32 CGEDebugger::PrimPreviewOp() { return 0; } -static void ExpandBezier(int &count, int op, std::vector &vertices, std::vector &indices) { +static void ExpandBezier(int &count, int op, const std::vector &simpleVerts, const std::vector &indices, std::vector &generatedVerts, std::vector &generatedInds) { int count_u = (op & 0x00FF) >> 0; int count_v = (op & 0xFF00) >> 8; @@ -178,15 +178,6 @@ static void ExpandBezier(int &count, int op, std::vector &vertic tess_v = 1; } - std::vector simpleVerts; - simpleVerts.resize(vertices.size()); - for (size_t i = 0; i < vertices.size(); ++i) { - // For now, let's just copy back so we can use TessellateBezierPatch... - simpleVerts[i].uv[0] = vertices[i].u; - simpleVerts[i].uv[1] = vertices[i].v; - simpleVerts[i].pos = Vec3Packedf(vertices[i].x, vertices[i].y, vertices[i].z); - } - // Bezier patches share less control points than spline patches. Otherwise they are pretty much the same (except bezier don't support the open/close thing) int num_patches_u = (count_u - 1) / 3; int num_patches_v = (count_v - 1) / 3; @@ -209,8 +200,6 @@ static void ExpandBezier(int &count, int op, std::vector &vertic } } - std::vector generatedVerts; - std::vector generatedInds; generatedVerts.resize((tess_u + 1) * (tess_v + 1) * total_patches); generatedInds.resize(tess_u * tess_v * 6); @@ -221,19 +210,9 @@ static void ExpandBezier(int &count, int op, std::vector &vertic const BezierPatch &patch = patches[patch_idx]; TessellateBezierPatch(dest, inds, count, tess_u, tess_v, patch, gstate.vertType); } - - vertices.resize(generatedVerts.size()); - for (size_t i = 0; i < vertices.size(); ++i) { - vertices[i].u = generatedVerts[i].uv[0]; - vertices[i].v = generatedVerts[i].uv[1]; - vertices[i].x = generatedVerts[i].pos.x; - vertices[i].y = generatedVerts[i].pos.y; - vertices[i].z = generatedVerts[i].pos.z; - } - indices = generatedInds; } -static void ExpandSpline(int &count, int op, std::vector &vertices, std::vector &indices) { +static void ExpandSpline(int &count, int op, const std::vector &simpleVerts, const std::vector &indices, std::vector &generatedVerts, std::vector &generatedInds) { SplinePatchLocal patch; patch.computeNormals = false; patch.primType = gstate.getPatchPrimitiveType(); @@ -258,16 +237,7 @@ static void ExpandSpline(int &count, int op, std::vector &vertic return; } - std::vector simpleVerts; - simpleVerts.resize(vertices.size()); - for (size_t i = 0; i < vertices.size(); ++i) { - // For now, let's just copy back so we can use TessellateBezierPatch... - simpleVerts[i].uv[0] = vertices[i].u; - simpleVerts[i].uv[1] = vertices[i].v; - simpleVerts[i].pos = Vec3Packedf(vertices[i].x, vertices[i].y, vertices[i].z); - } - - std::vector points; + std::vector points; points.resize(patch.count_u * patch.count_v); // Make an array of pointers to the control points, to get rid of indices. @@ -280,24 +250,12 @@ static void ExpandSpline(int &count, int op, std::vector &vertic int patch_div_t = (patch.count_v - 3) * patch.tess_v; int maxVertexCount = (patch_div_s + 1) * (patch_div_t + 1); - std::vector generatedVerts; - std::vector generatedInds; generatedVerts.resize(maxVertexCount); generatedInds.resize(patch_div_s * patch_div_t * 6); count = 0; u8 *dest = (u8 *)&generatedVerts[0]; TessellateSplinePatch(dest, &generatedInds[0], count, patch, gstate.vertType, maxVertexCount); - - vertices.resize(generatedVerts.size()); - for (size_t i = 0; i < vertices.size(); ++i) { - vertices[i].u = generatedVerts[i].uv[0]; - vertices[i].v = generatedVerts[i].uv[1]; - vertices[i].x = generatedVerts[i].pos.x; - vertices[i].y = generatedVerts[i].pos.y; - vertices[i].z = generatedVerts[i].pos.z; - } - indices = generatedInds; } void CGEDebugger::UpdatePrimPreview(u32 op, int which) { @@ -341,10 +299,34 @@ void CGEDebugger::UpdatePrimPreview(u32 op, int which) { return; } - if (cmd == GE_CMD_BEZIER) { - ExpandBezier(count, op, vertices, indices); - } else if (cmd == GE_CMD_SPLINE) { - ExpandSpline(count, op, vertices, indices); + if (cmd != GE_CMD_PRIM) { + static std::vector generatedVerts; + static std::vector generatedInds; + + static std::vector simpleVerts; + simpleVerts.resize(vertices.size()); + for (size_t i = 0; i < vertices.size(); ++i) { + // For now, let's just copy back so we can use TessellateBezierPatch/TessellateSplinePatch... + simpleVerts[i].uv[0] = vertices[i].u; + simpleVerts[i].uv[1] = vertices[i].v; + simpleVerts[i].pos = Vec3Packedf(vertices[i].x, vertices[i].y, vertices[i].z); + } + + if (cmd == GE_CMD_BEZIER) { + ExpandBezier(count, op, simpleVerts, indices, generatedVerts, generatedInds); + } else if (cmd == GE_CMD_SPLINE) { + ExpandSpline(count, op, simpleVerts, indices, generatedVerts, generatedInds); + } + + vertices.resize(generatedVerts.size()); + for (size_t i = 0; i < vertices.size(); ++i) { + vertices[i].u = generatedVerts[i].uv[0]; + vertices[i].v = generatedVerts[i].uv[1]; + vertices[i].x = generatedVerts[i].pos.x; + vertices[i].y = generatedVerts[i].pos.y; + vertices[i].z = generatedVerts[i].pos.z; + } + indices = generatedInds; } if (prim == GE_PRIM_RECTANGLES) {