Skip to content

Commit

Permalink
GE Debugger: Cleaned repetition in spline preview.
Browse files Browse the repository at this point in the history
  • Loading branch information
unknownbrackets committed May 28, 2018
1 parent dea7f61 commit dba3df9
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 56 deletions.
10 changes: 5 additions & 5 deletions GPU/Common/SplineCommon.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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++) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions GPU/Common/SplineCommon.h
Expand Up @@ -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;
Expand All @@ -48,7 +48,7 @@ struct BezierPatch {
};

struct SplinePatchLocal {
SimpleVertex **points;
const SimpleVertex **points;
int tess_u;
int tess_v;
int count_u;
Expand Down
80 changes: 31 additions & 49 deletions Windows/GEDebugger/VertexPreview.cpp
Expand Up @@ -165,7 +165,7 @@ u32 CGEDebugger::PrimPreviewOp() {
return 0;
}

static void ExpandBezier(int &count, int op, std::vector<GPUDebugVertex> &vertices, std::vector<u16> &indices) {
static void ExpandBezier(int &count, int op, const std::vector<SimpleVertex> &simpleVerts, const std::vector<u16> &indices, std::vector<SimpleVertex> &generatedVerts, std::vector<u16> &generatedInds) {
int count_u = (op & 0x00FF) >> 0;
int count_v = (op & 0xFF00) >> 8;

Expand All @@ -178,15 +178,6 @@ static void ExpandBezier(int &count, int op, std::vector<GPUDebugVertex> &vertic
tess_v = 1;
}

std::vector<SimpleVertex> 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;
Expand All @@ -209,8 +200,6 @@ static void ExpandBezier(int &count, int op, std::vector<GPUDebugVertex> &vertic
}
}

std::vector<SimpleVertex> generatedVerts;
std::vector<u16> generatedInds;
generatedVerts.resize((tess_u + 1) * (tess_v + 1) * total_patches);
generatedInds.resize(tess_u * tess_v * 6);

Expand All @@ -221,19 +210,9 @@ static void ExpandBezier(int &count, int op, std::vector<GPUDebugVertex> &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<GPUDebugVertex> &vertices, std::vector<u16> &indices) {
static void ExpandSpline(int &count, int op, const std::vector<SimpleVertex> &simpleVerts, const std::vector<u16> &indices, std::vector<SimpleVertex> &generatedVerts, std::vector<u16> &generatedInds) {
SplinePatchLocal patch;
patch.computeNormals = false;
patch.primType = gstate.getPatchPrimitiveType();
Expand All @@ -258,16 +237,7 @@ static void ExpandSpline(int &count, int op, std::vector<GPUDebugVertex> &vertic
return;
}

std::vector<SimpleVertex> 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<SimpleVertex *> points;
std::vector<const SimpleVertex *> points;
points.resize(patch.count_u * patch.count_v);

// Make an array of pointers to the control points, to get rid of indices.
Expand All @@ -280,24 +250,12 @@ static void ExpandSpline(int &count, int op, std::vector<GPUDebugVertex> &vertic
int patch_div_t = (patch.count_v - 3) * patch.tess_v;
int maxVertexCount = (patch_div_s + 1) * (patch_div_t + 1);

std::vector<SimpleVertex> generatedVerts;
std::vector<u16> 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) {
Expand Down Expand Up @@ -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<SimpleVertex> generatedVerts;
static std::vector<u16> generatedInds;

static std::vector<SimpleVertex> 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) {
Expand Down

0 comments on commit dba3df9

Please sign in to comment.