From 5e2c30c6403e2dcab6972343fb1f8ed69e16b22a Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Wed, 17 Sep 2014 21:37:53 +0200 Subject: [PATCH] Move GetCurrentSimpleVertices to DrawEngineCommon --- GPU/Common/DrawEngineCommon.cpp | 129 ++++++++++++++++++++++++++ GPU/Common/DrawEngineCommon.h | 6 ++ GPU/Directx9/TransformPipelineDX9.cpp | 127 ------------------------- GPU/Directx9/TransformPipelineDX9.h | 5 +- GPU/GLES/TransformPipeline.cpp | 127 ------------------------- GPU/GLES/TransformPipeline.h | 2 - 6 files changed, 136 insertions(+), 260 deletions(-) diff --git a/GPU/Common/DrawEngineCommon.cpp b/GPU/Common/DrawEngineCommon.cpp index 1e447f6618..1101fdbd86 100644 --- a/GPU/Common/DrawEngineCommon.cpp +++ b/GPU/Common/DrawEngineCommon.cpp @@ -17,9 +17,12 @@ #include "GPU/Common/DrawEngineCommon.h" #include "GPU/Common/SplineCommon.h" +#include "GPU/Common/VertexDecoderCommon.h" #include "GPU/ge_constants.h" #include "GPU/GPUState.h" +#include + DrawEngineCommon::~DrawEngineCommon() { } struct Plane { @@ -36,6 +39,31 @@ static void PlanesFromMatrix(float mtx[16], Plane planes[6]) { planes[4].Set(mtx[3]+mtx[2], mtx[7]+mtx[6], mtx[11]+mtx[10], mtx[15]+mtx[14]); // Near planes[5].Set(mtx[3]-mtx[2], mtx[7]-mtx[6], mtx[11]-mtx[10], mtx[15]-mtx[14]); // Far } + +static Vec3f ClipToScreen(const Vec4f& coords) { + // TODO: Check for invalid parameters (x2 < x1, etc) + float vpx1 = getFloat24(gstate.viewportx1); + float vpx2 = getFloat24(gstate.viewportx2); + float vpy1 = getFloat24(gstate.viewporty1); + float vpy2 = getFloat24(gstate.viewporty2); + float vpz1 = getFloat24(gstate.viewportz1); + float vpz2 = getFloat24(gstate.viewportz2); + + float retx = coords.x * vpx1 / coords.w + vpx2; + float rety = coords.y * vpy1 / coords.w + vpy2; + float retz = coords.z * vpz1 / coords.w + vpz2; + + // 16 = 0xFFFF / 4095.9375 + return Vec3f(retx * 16, rety * 16, retz); +} + +static Vec3f ScreenToDrawing(const Vec3f& coords) { + Vec3f ret; + ret.x = (coords.x - gstate.getOffsetX16()) * (1.0f / 16.0f); + ret.y = (coords.y - gstate.getOffsetY16()) * (1.0f / 16.0f); + ret.z = coords.z; + return ret; +} // This code is HIGHLY unoptimized! // @@ -107,3 +135,104 @@ bool DrawEngineCommon::TestBoundingBox(void* control_points, int vertexCount, u3 return true; } + +// TODO: This probably is not the best interface. +bool DrawEngineCommon::GetCurrentSimpleVertices(int count, std::vector &vertices, std::vector &indices) { + // This is always for the current vertices. + u16 indexLowerBound = 0; + u16 indexUpperBound = count - 1; + + bool savedVertexFullAlpha = gstate_c.vertexFullAlpha; + + if ((gstate.vertType & GE_VTYPE_IDX_MASK) != GE_VTYPE_IDX_NONE) { + const u8 *inds = Memory::GetPointer(gstate_c.indexAddr); + const u16 *inds16 = (const u16 *)inds; + + if (inds) { + GetIndexBounds(inds, count, gstate.vertType, &indexLowerBound, &indexUpperBound); + indices.resize(count); + switch (gstate.vertType & GE_VTYPE_IDX_MASK) { + case GE_VTYPE_IDX_16BIT: + for (int i = 0; i < count; ++i) { + indices[i] = inds16[i]; + } + break; + case GE_VTYPE_IDX_8BIT: + for (int i = 0; i < count; ++i) { + indices[i] = inds[i]; + } + break; + default: + return false; + } + } else { + indices.clear(); + } + } else { + indices.clear(); + } + + static std::vector temp_buffer; + static std::vector simpleVertices; + temp_buffer.resize(std::max((int)indexUpperBound, 8192) * 128 / sizeof(u32)); + simpleVertices.resize(indexUpperBound + 1); + NormalizeVertices((u8 *)(&simpleVertices[0]), (u8 *)(&temp_buffer[0]), Memory::GetPointer(gstate_c.vertexAddr), indexLowerBound, indexUpperBound, gstate.vertType); + + float world[16]; + float view[16]; + float worldview[16]; + float worldviewproj[16]; + ConvertMatrix4x3To4x4(world, gstate.worldMatrix); + ConvertMatrix4x3To4x4(view, gstate.viewMatrix); + Matrix4ByMatrix4(worldview, world, view); + Matrix4ByMatrix4(worldviewproj, worldview, gstate.projMatrix); + + vertices.resize(indexUpperBound + 1); + for (int i = indexLowerBound; i <= indexUpperBound; ++i) { + const SimpleVertex &vert = simpleVertices[i]; + + if (gstate.isModeThrough()) { + if (gstate.vertType & GE_VTYPE_TC_MASK) { + vertices[i].u = vert.uv[0]; + vertices[i].v = vert.uv[1]; + } else { + vertices[i].u = 0.0f; + vertices[i].v = 0.0f; + } + vertices[i].x = vert.pos.x; + vertices[i].y = vert.pos.y; + vertices[i].z = vert.pos.z; + if (gstate.vertType & GE_VTYPE_COL_MASK) { + memcpy(vertices[i].c, vert.color, sizeof(vertices[i].c)); + } else { + memset(vertices[i].c, 0, sizeof(vertices[i].c)); + } + } else { + float clipPos[4]; + Vec3ByMatrix44(clipPos, vert.pos.AsArray(), worldviewproj); + Vec3f screenPos = ClipToScreen(clipPos); + Vec3f drawPos = ScreenToDrawing(screenPos); + + if (gstate.vertType & GE_VTYPE_TC_MASK) { + vertices[i].u = vert.uv[0]; + vertices[i].v = vert.uv[1]; + } else { + vertices[i].u = 0.0f; + vertices[i].v = 0.0f; + } + vertices[i].x = drawPos.x; + vertices[i].y = drawPos.y; + vertices[i].z = drawPos.z; + if (gstate.vertType & GE_VTYPE_COL_MASK) { + memcpy(vertices[i].c, vert.color, sizeof(vertices[i].c)); + } else { + memset(vertices[i].c, 0, sizeof(vertices[i].c)); + } + } + } + + gstate_c.vertexFullAlpha = savedVertexFullAlpha; + + return true; +} + diff --git a/GPU/Common/DrawEngineCommon.h b/GPU/Common/DrawEngineCommon.h index 07229675c9..18439ed3a7 100644 --- a/GPU/Common/DrawEngineCommon.h +++ b/GPU/Common/DrawEngineCommon.h @@ -17,8 +17,12 @@ #pragma once +#include + #include "Common/CommonTypes.h" +#include "GPU/Common/GPUDebugInterface.h" + class DrawEngineCommon { public: virtual ~DrawEngineCommon(); @@ -28,6 +32,8 @@ public: // TODO: This can be shared once the decoder cache / etc. are. virtual u32 NormalizeVertices(u8 *outPtr, u8 *bufPtr, const u8 *inPtr, int lowerBound, int upperBound, u32 vertType) = 0; + bool GetCurrentSimpleVertices(int count, std::vector &vertices, std::vector &indices); + protected: // Vertex collector buffers u8 *decoded; diff --git a/GPU/Directx9/TransformPipelineDX9.cpp b/GPU/Directx9/TransformPipelineDX9.cpp index 1d858024b4..4241b1ae90 100644 --- a/GPU/Directx9/TransformPipelineDX9.cpp +++ b/GPU/Directx9/TransformPipelineDX9.cpp @@ -957,131 +957,4 @@ bool TransformDrawEngineDX9::IsCodePtrVertexDecoder(const u8 *ptr) const { return decJitCache_->IsInSpace(ptr); } -// TODO: Probably move this to common code (with normalization?) - -static Vec3f ClipToScreen(const Vec4f& coords) { - // TODO: Check for invalid parameters (x2 < x1, etc) - float vpx1 = getFloat24(gstate.viewportx1); - float vpx2 = getFloat24(gstate.viewportx2); - float vpy1 = getFloat24(gstate.viewporty1); - float vpy2 = getFloat24(gstate.viewporty2); - float vpz1 = getFloat24(gstate.viewportz1); - float vpz2 = getFloat24(gstate.viewportz2); - - float retx = coords.x * vpx1 / coords.w + vpx2; - float rety = coords.y * vpy1 / coords.w + vpy2; - float retz = coords.z * vpz1 / coords.w + vpz2; - - // 16 = 0xFFFF / 4095.9375 - return Vec3f(retx * 16, rety * 16, retz); -} - -static Vec3f ScreenToDrawing(const Vec3f& coords) { - Vec3f ret; - ret.x = (coords.x - gstate.getOffsetX16()) * (1.0f / 16.0f); - ret.y = (coords.y - gstate.getOffsetY16()) * (1.0f / 16.0f); - ret.z = coords.z; - return ret; -} - -// TODO: This probably is not the best interface. -bool TransformDrawEngineDX9::GetCurrentSimpleVertices(int count, std::vector &vertices, std::vector &indices) { - // This is always for the current vertices. - u16 indexLowerBound = 0; - u16 indexUpperBound = count - 1; - - bool savedVertexFullAlpha = gstate_c.vertexFullAlpha; - - if ((gstate.vertType & GE_VTYPE_IDX_MASK) != GE_VTYPE_IDX_NONE) { - const u8 *inds = Memory::GetPointer(gstate_c.indexAddr); - const u16 *inds16 = (const u16 *)inds; - - if (inds) { - GetIndexBounds(inds, count, gstate.vertType, &indexLowerBound, &indexUpperBound); - indices.resize(count); - switch (gstate.vertType & GE_VTYPE_IDX_MASK) { - case GE_VTYPE_IDX_16BIT: - for (int i = 0; i < count; ++i) { - indices[i] = inds16[i]; - } - break; - case GE_VTYPE_IDX_8BIT: - for (int i = 0; i < count; ++i) { - indices[i] = inds[i]; - } - break; - default: - return false; - } - } else { - indices.clear(); - } - } else { - indices.clear(); - } - - static std::vector temp_buffer; - static std::vector simpleVertices; - temp_buffer.resize(std::max((int)indexUpperBound, 8192) * 128 / sizeof(u32)); - simpleVertices.resize(indexUpperBound + 1); - NormalizeVertices((u8 *)(&simpleVertices[0]), (u8 *)(&temp_buffer[0]), Memory::GetPointer(gstate_c.vertexAddr), indexLowerBound, indexUpperBound, gstate.vertType); - - float world[16]; - float view[16]; - float worldview[16]; - float worldviewproj[16]; - ConvertMatrix4x3To4x4(world, gstate.worldMatrix); - ConvertMatrix4x3To4x4(view, gstate.viewMatrix); - Matrix4ByMatrix4(worldview, world, view); - Matrix4ByMatrix4(worldviewproj, worldview, gstate.projMatrix); - - vertices.resize(indexUpperBound + 1); - for (int i = indexLowerBound; i <= indexUpperBound; ++i) { - const SimpleVertex &vert = simpleVertices[i]; - - if (gstate.isModeThrough()) { - if (gstate.vertType & GE_VTYPE_TC_MASK) { - vertices[i].u = vert.uv[0]; - vertices[i].v = vert.uv[1]; - } else { - vertices[i].u = 0.0f; - vertices[i].v = 0.0f; - } - vertices[i].x = vert.pos.x; - vertices[i].y = vert.pos.y; - vertices[i].z = vert.pos.z; - if (gstate.vertType & GE_VTYPE_COL_MASK) { - memcpy(vertices[i].c, vert.color, sizeof(vertices[i].c)); - } else { - memset(vertices[i].c, 0, sizeof(vertices[i].c)); - } - } else { - float clipPos[4]; - Vec3ByMatrix44(clipPos, vert.pos.AsArray(), worldviewproj); - Vec3f screenPos = ClipToScreen(clipPos); - Vec3f drawPos = ScreenToDrawing(screenPos); - - if (gstate.vertType & GE_VTYPE_TC_MASK) { - vertices[i].u = vert.uv[0]; - vertices[i].v = vert.uv[1]; - } else { - vertices[i].u = 0.0f; - vertices[i].v = 0.0f; - } - vertices[i].x = drawPos.x; - vertices[i].y = drawPos.y; - vertices[i].z = drawPos.z; - if (gstate.vertType & GE_VTYPE_COL_MASK) { - memcpy(vertices[i].c, vert.color, sizeof(vertices[i].c)); - } else { - memset(vertices[i].c, 0, sizeof(vertices[i].c)); - } - } - } - - gstate_c.vertexFullAlpha = savedVertexFullAlpha; - - return true; -} - } // namespace diff --git a/GPU/Directx9/TransformPipelineDX9.h b/GPU/Directx9/TransformPipelineDX9.h index b82c4240dd..dd8afb70a6 100644 --- a/GPU/Directx9/TransformPipelineDX9.h +++ b/GPU/Directx9/TransformPipelineDX9.h @@ -111,8 +111,6 @@ public: void SubmitSpline(void* control_points, void* indices, int count_u, int count_v, int type_u, int type_v, GEPatchPrimType prim_type, u32 vertType); void SubmitBezier(void* control_points, void* indices, int count_u, int count_v, GEPatchPrimType prim_type, u32 vertType); - bool GetCurrentSimpleVertices(int count, std::vector &vertices, std::vector &indices); - void SetShaderManager(ShaderManagerDX9 *shaderManager) { shaderManager_ = shaderManager; } @@ -157,7 +155,6 @@ private: void ApplyDrawState(int prim); void ApplyDrawStateLate(); - bool IsReallyAClear(int numVerts) const; IDirect3DVertexDeclaration9 *SetupDecFmtForDraw(VSShader *vshader, const DecVtxFormat &decFmt, u32 pspFmt); // Preprocessing for spline/bezier @@ -222,4 +219,4 @@ private: VertexDecoderOptions decOptions_; }; -}; +} // namespace diff --git a/GPU/GLES/TransformPipeline.cpp b/GPU/GLES/TransformPipeline.cpp index 153fd03a87..0d2d303f32 100644 --- a/GPU/GLES/TransformPipeline.cpp +++ b/GPU/GLES/TransformPipeline.cpp @@ -939,130 +939,3 @@ void TransformDrawEngine::Resized() { bool TransformDrawEngine::IsCodePtrVertexDecoder(const u8 *ptr) const { return decJitCache_->IsInSpace(ptr); } - -// TODO: Probably move this to common code (with normalization?) - -static Vec3f ClipToScreen(const Vec4f& coords) { - // TODO: Check for invalid parameters (x2 < x1, etc) - float vpx1 = getFloat24(gstate.viewportx1); - float vpx2 = getFloat24(gstate.viewportx2); - float vpy1 = getFloat24(gstate.viewporty1); - float vpy2 = getFloat24(gstate.viewporty2); - float vpz1 = getFloat24(gstate.viewportz1); - float vpz2 = getFloat24(gstate.viewportz2); - - float retx = coords.x * vpx1 / coords.w + vpx2; - float rety = coords.y * vpy1 / coords.w + vpy2; - float retz = coords.z * vpz1 / coords.w + vpz2; - - // 16 = 0xFFFF / 4095.9375 - return Vec3f(retx * 16, rety * 16, retz); -} - -static Vec3f ScreenToDrawing(const Vec3f& coords) { - Vec3f ret; - ret.x = (coords.x - gstate.getOffsetX16()) * (1.0f / 16.0f); - ret.y = (coords.y - gstate.getOffsetY16()) * (1.0f / 16.0f); - ret.z = coords.z; - return ret; -} - -// TODO: This probably is not the best interface. -bool TransformDrawEngine::GetCurrentSimpleVertices(int count, std::vector &vertices, std::vector &indices) { - // This is always for the current vertices. - u16 indexLowerBound = 0; - u16 indexUpperBound = count - 1; - - bool savedVertexFullAlpha = gstate_c.vertexFullAlpha; - - if ((gstate.vertType & GE_VTYPE_IDX_MASK) != GE_VTYPE_IDX_NONE) { - const u8 *inds = Memory::GetPointer(gstate_c.indexAddr); - const u16 *inds16 = (const u16 *)inds; - - if (inds) { - GetIndexBounds(inds, count, gstate.vertType, &indexLowerBound, &indexUpperBound); - indices.resize(count); - switch (gstate.vertType & GE_VTYPE_IDX_MASK) { - case GE_VTYPE_IDX_16BIT: - for (int i = 0; i < count; ++i) { - indices[i] = inds16[i]; - } - break; - case GE_VTYPE_IDX_8BIT: - for (int i = 0; i < count; ++i) { - indices[i] = inds[i]; - } - break; - default: - return false; - } - } else { - indices.clear(); - } - } else { - indices.clear(); - } - - static std::vector temp_buffer; - static std::vector simpleVertices; - temp_buffer.resize(std::max((int)indexUpperBound, 8192) * 128 / sizeof(u32)); - simpleVertices.resize(indexUpperBound + 1); - NormalizeVertices((u8 *)(&simpleVertices[0]), (u8 *)(&temp_buffer[0]), Memory::GetPointer(gstate_c.vertexAddr), indexLowerBound, indexUpperBound, gstate.vertType); - - float world[16]; - float view[16]; - float worldview[16]; - float worldviewproj[16]; - ConvertMatrix4x3To4x4(world, gstate.worldMatrix); - ConvertMatrix4x3To4x4(view, gstate.viewMatrix); - Matrix4ByMatrix4(worldview, world, view); - Matrix4ByMatrix4(worldviewproj, worldview, gstate.projMatrix); - - vertices.resize(indexUpperBound + 1); - for (int i = indexLowerBound; i <= indexUpperBound; ++i) { - const SimpleVertex &vert = simpleVertices[i]; - - if (gstate.isModeThrough()) { - if (gstate.vertType & GE_VTYPE_TC_MASK) { - vertices[i].u = vert.uv[0]; - vertices[i].v = vert.uv[1]; - } else { - vertices[i].u = 0.0f; - vertices[i].v = 0.0f; - } - vertices[i].x = vert.pos.x; - vertices[i].y = vert.pos.y; - vertices[i].z = vert.pos.z; - if (gstate.vertType & GE_VTYPE_COL_MASK) { - memcpy(vertices[i].c, vert.color, sizeof(vertices[i].c)); - } else { - memset(vertices[i].c, 0, sizeof(vertices[i].c)); - } - } else { - float clipPos[4]; - Vec3ByMatrix44(clipPos, vert.pos.AsArray(), worldviewproj); - Vec3f screenPos = ClipToScreen(clipPos); - Vec3f drawPos = ScreenToDrawing(screenPos); - - if (gstate.vertType & GE_VTYPE_TC_MASK) { - vertices[i].u = vert.uv[0]; - vertices[i].v = vert.uv[1]; - } else { - vertices[i].u = 0.0f; - vertices[i].v = 0.0f; - } - vertices[i].x = drawPos.x; - vertices[i].y = drawPos.y; - vertices[i].z = drawPos.z; - if (gstate.vertType & GE_VTYPE_COL_MASK) { - memcpy(vertices[i].c, vert.color, sizeof(vertices[i].c)); - } else { - memset(vertices[i].c, 0, sizeof(vertices[i].c)); - } - } - } - - gstate_c.vertexFullAlpha = savedVertexFullAlpha; - - return true; -} diff --git a/GPU/GLES/TransformPipeline.h b/GPU/GLES/TransformPipeline.h index d1fd21d01d..badbcd675d 100644 --- a/GPU/GLES/TransformPipeline.h +++ b/GPU/GLES/TransformPipeline.h @@ -107,8 +107,6 @@ public: void SubmitSpline(void* control_points, void* indices, int count_u, int count_v, int type_u, int type_v, GEPatchPrimType prim_type, u32 vertType); void SubmitBezier(void* control_points, void* indices, int count_u, int count_v, GEPatchPrimType prim_type, u32 vertType); - bool GetCurrentSimpleVertices(int count, std::vector &vertices, std::vector &indices); - void SetShaderManager(ShaderManager *shaderManager) { shaderManager_ = shaderManager; }