From fec232f8a8dde1648e3031d8057c33cfea8778ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 17 Dec 2024 16:58:10 +0100 Subject: [PATCH 1/6] GPU: Move things around a little, out of DrawEngine. --- GPU/Common/DrawEngineCommon.cpp | 106 +------------------------ GPU/Common/DrawEngineCommon.h | 2 - GPU/Common/SoftwareTransformCommon.cpp | 103 ++++++++++++++++++++++++ GPU/Common/SoftwareTransformCommon.h | 3 + GPU/Common/SplineCommon.h | 14 +--- GPU/Common/TransformCommon.h | 12 +++ GPU/Software/TransformUnit.cpp | 3 +- 7 files changed, 124 insertions(+), 119 deletions(-) diff --git a/GPU/Common/DrawEngineCommon.cpp b/GPU/Common/DrawEngineCommon.cpp index 502d115b53..7b87756b4b 100644 --- a/GPU/Common/DrawEngineCommon.cpp +++ b/GPU/Common/DrawEngineCommon.cpp @@ -27,6 +27,7 @@ #include "GPU/Common/DrawEngineCommon.h" #include "GPU/Common/SplineCommon.h" #include "GPU/Common/VertexDecoderCommon.h" +#include "GPU/Common/SoftwareTransformCommon.h" #include "GPU/ge_constants.h" #include "GPU/GPUState.h" @@ -140,7 +141,7 @@ u32 DrawEngineCommon::NormalizeVertices(u8 *outPtr, u8 *bufPtr, const u8 *inPtr, VertexDecoder *dec = GetVertexDecoder(vertTypeID); if (vertexSize) *vertexSize = dec->VertexSize(); - return DrawEngineCommon::NormalizeVertices(outPtr, bufPtr, inPtr, dec, lowerBound, upperBound, vertType); + return ::NormalizeVertices(outPtr, bufPtr, inPtr, lowerBound, upperBound, dec, vertType); } void DrawEngineCommon::DispatchSubmitImm(GEPrimitiveType prim, TransformedVertex *buffer, int vertexCount, int cullMode, bool continuation) { @@ -750,109 +751,6 @@ bool DrawEngineCommon::GetCurrentSimpleVertices(int count, std::vectorDecodeVerts(bufPtr, inPtr, &gstate_c.uv, lowerBound, upperBound); - - // OK, morphing eliminated but bones still remain to be taken care of. - // Let's do a partial software transform where we only do skinning. - - VertexReader reader(bufPtr, dec->GetDecVtxFmt(), vertType); - - SimpleVertex *sverts = (SimpleVertex *)outPtr; - - const u8 defaultColor[4] = { - (u8)gstate.getMaterialAmbientR(), - (u8)gstate.getMaterialAmbientG(), - (u8)gstate.getMaterialAmbientB(), - (u8)gstate.getMaterialAmbientA(), - }; - - // Let's have two separate loops, one for non skinning and one for skinning. - if (!dec->skinInDecode && (vertType & GE_VTYPE_WEIGHT_MASK) != GE_VTYPE_WEIGHT_NONE) { - int numBoneWeights = vertTypeGetNumBoneWeights(vertType); - for (int i = lowerBound; i <= upperBound; i++) { - reader.Goto(i - lowerBound); - SimpleVertex &sv = sverts[i]; - if (vertType & GE_VTYPE_TC_MASK) { - reader.ReadUV(sv.uv); - } - - if (vertType & GE_VTYPE_COL_MASK) { - sv.color_32 = reader.ReadColor0_8888(); - } else { - memcpy(sv.color, defaultColor, 4); - } - - float nrm[3], pos[3]; - float bnrm[3], bpos[3]; - - if (vertType & GE_VTYPE_NRM_MASK) { - // Normals are generated during tessellation anyway, not sure if any need to supply - reader.ReadNrm(nrm); - } else { - nrm[0] = 0; - nrm[1] = 0; - nrm[2] = 1.0f; - } - reader.ReadPos(pos); - - // Apply skinning transform directly - float weights[8]; - reader.ReadWeights(weights); - // Skinning - Vec3Packedf psum(0, 0, 0); - Vec3Packedf nsum(0, 0, 0); - for (int w = 0; w < numBoneWeights; w++) { - if (weights[w] != 0.0f) { - Vec3ByMatrix43(bpos, pos, gstate.boneMatrix + w * 12); - Vec3Packedf tpos(bpos); - psum += tpos * weights[w]; - - Norm3ByMatrix43(bnrm, nrm, gstate.boneMatrix + w * 12); - Vec3Packedf tnorm(bnrm); - nsum += tnorm * weights[w]; - } - } - sv.pos = psum; - sv.nrm = nsum; - } - } else { - for (int i = lowerBound; i <= upperBound; i++) { - reader.Goto(i - lowerBound); - SimpleVertex &sv = sverts[i]; - if (vertType & GE_VTYPE_TC_MASK) { - reader.ReadUV(sv.uv); - } else { - sv.uv[0] = 0.0f; // This will get filled in during tessellation - sv.uv[1] = 0.0f; - } - if (vertType & GE_VTYPE_COL_MASK) { - sv.color_32 = reader.ReadColor0_8888(); - } else { - memcpy(sv.color, defaultColor, 4); - } - if (vertType & GE_VTYPE_NRM_MASK) { - // Normals are generated during tessellation anyway, not sure if any need to supply - reader.ReadNrm((float *)&sv.nrm); - } else { - sv.nrm.x = 0.0f; - sv.nrm.y = 0.0f; - sv.nrm.z = 1.0f; - } - reader.ReadPos((float *)&sv.pos); - } - } - - // Okay, there we are! Return the new type (but keep the index bits) - return GE_VTYPE_TC_FLOAT | GE_VTYPE_COL_8888 | GE_VTYPE_NRM_FLOAT | GE_VTYPE_POS_FLOAT | (vertType & (GE_VTYPE_IDX_MASK | GE_VTYPE_THROUGH)); -} - void DrawEngineCommon::ApplyFramebufferRead(FBOTexState *fboTexState) { if (gstate_c.Use(GPU_USE_FRAMEBUFFER_FETCH)) { *fboTexState = FBO_TEX_READ_FRAMEBUFFER; diff --git a/GPU/Common/DrawEngineCommon.h b/GPU/Common/DrawEngineCommon.h index c8733ecbaa..828bc213d0 100644 --- a/GPU/Common/DrawEngineCommon.h +++ b/GPU/Common/DrawEngineCommon.h @@ -88,8 +88,6 @@ public: bool GetCurrentSimpleVertices(int count, std::vector &vertices, std::vector &indices); - static u32 NormalizeVertices(u8 *outPtr, u8 *bufPtr, const u8 *inPtr, VertexDecoder *dec, int lowerBound, int upperBound, u32 vertType); - // Dispatches the queued-up draws. virtual void Flush() = 0; diff --git a/GPU/Common/SoftwareTransformCommon.cpp b/GPU/Common/SoftwareTransformCommon.cpp index c2a8b8f1ff..6fa5d76f16 100644 --- a/GPU/Common/SoftwareTransformCommon.cpp +++ b/GPU/Common/SoftwareTransformCommon.cpp @@ -934,3 +934,106 @@ bool SoftwareTransform::ExpandPoints(int vertexCount, int &maxIndex, int vertsSi inds = newInds; return true; } + +// This normalizes a set of vertices in any format to SimpleVertex format, by processing away morphing AND skinning. +// The rest of the transform pipeline like lighting will go as normal, either hardware or software. +// The implementation is initially a bit inefficient but shouldn't be a big deal. +// An intermediate buffer of not-easy-to-predict size is stored at bufPtr. +u32 NormalizeVertices(u8 *outPtr, u8 *bufPtr, const u8 *inPtr, int lowerBound, int upperBound, VertexDecoder *dec, u32 vertType) { + // First, decode the vertices into a GPU compatible format. This step can be eliminated but will need a separate + // implementation of the vertex decoder. + dec->DecodeVerts(bufPtr, inPtr, &gstate_c.uv, lowerBound, upperBound); + + // OK, morphing eliminated but bones still remain to be taken care of. + // Let's do a partial software transform where we only do skinning. + + VertexReader reader(bufPtr, dec->GetDecVtxFmt(), vertType); + + SimpleVertex *sverts = (SimpleVertex *)outPtr; + + const u8 defaultColor[4] = { + (u8)gstate.getMaterialAmbientR(), + (u8)gstate.getMaterialAmbientG(), + (u8)gstate.getMaterialAmbientB(), + (u8)gstate.getMaterialAmbientA(), + }; + + // Let's have two separate loops, one for non skinning and one for skinning. + if (!dec->skinInDecode && (vertType & GE_VTYPE_WEIGHT_MASK) != GE_VTYPE_WEIGHT_NONE) { + int numBoneWeights = vertTypeGetNumBoneWeights(vertType); + for (int i = lowerBound; i <= upperBound; i++) { + reader.Goto(i - lowerBound); + SimpleVertex &sv = sverts[i]; + if (vertType & GE_VTYPE_TC_MASK) { + reader.ReadUV(sv.uv); + } + + if (vertType & GE_VTYPE_COL_MASK) { + sv.color_32 = reader.ReadColor0_8888(); + } else { + memcpy(sv.color, defaultColor, 4); + } + + float nrm[3], pos[3]; + float bnrm[3], bpos[3]; + + if (vertType & GE_VTYPE_NRM_MASK) { + // Normals are generated during tessellation anyway, not sure if any need to supply + reader.ReadNrm(nrm); + } else { + nrm[0] = 0; + nrm[1] = 0; + nrm[2] = 1.0f; + } + reader.ReadPos(pos); + + // Apply skinning transform directly + float weights[8]; + reader.ReadWeights(weights); + // Skinning + Vec3Packedf psum(0, 0, 0); + Vec3Packedf nsum(0, 0, 0); + for (int w = 0; w < numBoneWeights; w++) { + if (weights[w] != 0.0f) { + Vec3ByMatrix43(bpos, pos, gstate.boneMatrix + w * 12); + Vec3Packedf tpos(bpos); + psum += tpos * weights[w]; + + Norm3ByMatrix43(bnrm, nrm, gstate.boneMatrix + w * 12); + Vec3Packedf tnorm(bnrm); + nsum += tnorm * weights[w]; + } + } + sv.pos = psum; + sv.nrm = nsum; + } + } else { + for (int i = lowerBound; i <= upperBound; i++) { + reader.Goto(i - lowerBound); + SimpleVertex &sv = sverts[i]; + if (vertType & GE_VTYPE_TC_MASK) { + reader.ReadUV(sv.uv); + } else { + sv.uv[0] = 0.0f; // This will get filled in during tessellation + sv.uv[1] = 0.0f; + } + if (vertType & GE_VTYPE_COL_MASK) { + sv.color_32 = reader.ReadColor0_8888(); + } else { + memcpy(sv.color, defaultColor, 4); + } + if (vertType & GE_VTYPE_NRM_MASK) { + // Normals are generated during tessellation anyway, not sure if any need to supply + reader.ReadNrm((float *)&sv.nrm); + } else { + sv.nrm.x = 0.0f; + sv.nrm.y = 0.0f; + sv.nrm.z = 1.0f; + } + reader.ReadPos((float *)&sv.pos); + } + } + + // Okay, there we are! Return the new type (but keep the index bits) + return GE_VTYPE_TC_FLOAT | GE_VTYPE_COL_8888 | GE_VTYPE_NRM_FLOAT | GE_VTYPE_POS_FLOAT | (vertType & (GE_VTYPE_IDX_MASK | GE_VTYPE_THROUGH)); +} diff --git a/GPU/Common/SoftwareTransformCommon.h b/GPU/Common/SoftwareTransformCommon.h index 457fd6a253..d6d72b32dc 100644 --- a/GPU/Common/SoftwareTransformCommon.h +++ b/GPU/Common/SoftwareTransformCommon.h @@ -84,3 +84,6 @@ protected: const SoftwareTransformParams ¶ms_; Lin::Matrix4x4 projMatrix_; }; + +// Slow. See description in the cpp file. +u32 NormalizeVertices(u8 *outPtr, u8 *bufPtr, const u8 *inPtr, int lowerBound, int upperBound, VertexDecoder *dec, u32 vertType); diff --git a/GPU/Common/SplineCommon.h b/GPU/Common/SplineCommon.h index e3acec7a67..bec51004e8 100644 --- a/GPU/Common/SplineCommon.h +++ b/GPU/Common/SplineCommon.h @@ -22,22 +22,12 @@ #include "Common/Swap.h" #include "GPU/Math3D.h" #include "GPU/ge_constants.h" +#include "GPU/Common/TransformCommon.h" + #include "Core/Config.h" #define HALF_CEIL(x) (x + 1) / 2 // Integer ceil = (int)ceil((float)x / 2.0f) -// PSP compatible format so we can use the end of the pipeline in beziers etc -// 8 + 4 + 12 + 12 = 36 bytes -struct SimpleVertex { - float uv[2]; - union { - u8 color[4]; - u32_le color_32; - }; - Vec3Packedf nrm; - Vec3Packedf pos; -}; - class SimpleBufferManager; namespace Spline { diff --git a/GPU/Common/TransformCommon.h b/GPU/Common/TransformCommon.h index 4da0a83113..9911bcff4a 100644 --- a/GPU/Common/TransformCommon.h +++ b/GPU/Common/TransformCommon.h @@ -22,6 +22,7 @@ #include "Common/CommonTypes.h" #include "GPU/ge_constants.h" #include "GPU/Math3D.h" +#include "GPU/GPU.h" struct Color4 { float r, g, b, a; @@ -94,3 +95,14 @@ private: float lcolor[3][4][3]; }; +// PSP compatible format so we can use the end of the pipeline in beziers etc +// 8 + 4 + 12 + 12 = 36 bytes +struct SimpleVertex { + float uv[2]; + union { + u8 color[4]; + u32_le color_32; + }; + Vec3Packedf nrm; + Vec3Packedf pos; +}; diff --git a/GPU/Software/TransformUnit.cpp b/GPU/Software/TransformUnit.cpp index ea03a5b360..0baf088473 100644 --- a/GPU/Software/TransformUnit.cpp +++ b/GPU/Software/TransformUnit.cpp @@ -27,6 +27,7 @@ #include "GPU/GPUState.h" #include "GPU/Common/DrawEngineCommon.h" #include "GPU/Common/VertexDecoderCommon.h" +#include "GPU/Common/SoftwareTransformCommon.h" #include "GPU/Common/SplineCommon.h" #include "GPU/Common/TextureDecoder.h" #include "GPU/Debugger/Debugger.h" @@ -979,7 +980,7 @@ bool TransformUnit::GetCurrentSimpleVertices(int count, std::vector Date: Tue, 17 Dec 2024 17:11:11 +0100 Subject: [PATCH 2/6] Some NormalizeVertices interface cleanup --- GPU/Common/DrawEngineCommon.cpp | 14 ++++++-------- GPU/Common/DrawEngineCommon.h | 2 +- GPU/Common/SoftwareTransformCommon.cpp | 4 +--- GPU/Common/SoftwareTransformCommon.h | 3 ++- GPU/Common/SplineCommon.cpp | 7 ++++--- GPU/Software/TransformUnit.cpp | 2 +- 6 files changed, 15 insertions(+), 17 deletions(-) diff --git a/GPU/Common/DrawEngineCommon.cpp b/GPU/Common/DrawEngineCommon.cpp index 7b87756b4b..21e9fda064 100644 --- a/GPU/Common/DrawEngineCommon.cpp +++ b/GPU/Common/DrawEngineCommon.cpp @@ -37,7 +37,7 @@ enum { TRANSFORMED_VERTEX_BUFFER_SIZE = VERTEX_BUFFER_MAX * sizeof(TransformedVertex) }; -DrawEngineCommon::DrawEngineCommon() : decoderMap_(16) { +DrawEngineCommon::DrawEngineCommon() : decoderMap_(32) { if (g_Config.bVertexDecoderJit && (g_Config.iCpuCore == (int)CPUCore::JIT || g_Config.iCpuCore == (int)CPUCore::JIT_IR)) { decJitCache_ = new VertexDecoderJitCache(); } @@ -136,7 +136,7 @@ void DrawEngineCommon::NotifyConfigChanged() { useHWTessellation_ = UpdateUseHWTessellation(g_Config.bHardwareTessellation); } -u32 DrawEngineCommon::NormalizeVertices(u8 *outPtr, u8 *bufPtr, const u8 *inPtr, int lowerBound, int upperBound, u32 vertType, int *vertexSize) { +u32 DrawEngineCommon::NormalizeVertices(SimpleVertex *outPtr, u8 *bufPtr, const u8 *inPtr, int lowerBound, int upperBound, u32 vertType, int *vertexSize) { const u32 vertTypeID = GetVertTypeID(vertType, gstate.getUVGenMode(), applySkinInDecode_); VertexDecoder *dec = GetVertexDecoder(vertTypeID); if (vertexSize) @@ -303,11 +303,9 @@ bool DrawEngineCommon::TestBoundingBox(const void *vdata, const void *inds, int } // TODO: Avoid normalization if just plain skinning. // Force software skinning. - bool wasApplyingSkinInDecode = applySkinInDecode_; - applySkinInDecode_ = true; - NormalizeVertices((u8 *)corners, temp_buffer, (const u8 *)vdata, indexLowerBound, indexUpperBound, vertType); - applySkinInDecode_ = wasApplyingSkinInDecode; - + const u32 vertTypeID = GetVertTypeID(vertType, gstate.getUVGenMode(), true); + VertexDecoder *dec = GetVertexDecoder(vertTypeID); + ::NormalizeVertices(corners, temp_buffer, (const u8 *)vdata, indexLowerBound, indexUpperBound, dec, vertType); IndexConverter conv(vertType, inds); for (int i = 0; i < vertexCount; i++) { verts[i * 3] = corners[conv(i)].pos.x; @@ -680,7 +678,7 @@ bool DrawEngineCommon::GetCurrentSimpleVertices(int count, 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::GetPointerUnchecked(gstate_c.vertexAddr), indexLowerBound, indexUpperBound, gstate.vertType); + NormalizeVertices(&simpleVertices[0], (u8 *)(&temp_buffer[0]), Memory::GetPointerUnchecked(gstate_c.vertexAddr), indexLowerBound, indexUpperBound, gstate.vertType); float world[16]; float view[16]; diff --git a/GPU/Common/DrawEngineCommon.h b/GPU/Common/DrawEngineCommon.h index 828bc213d0..4154d91b2d 100644 --- a/GPU/Common/DrawEngineCommon.h +++ b/GPU/Common/DrawEngineCommon.h @@ -157,7 +157,7 @@ protected: int DecodeInds(); // Preprocessing for spline/bezier - u32 NormalizeVertices(u8 *outPtr, u8 *bufPtr, const u8 *inPtr, int lowerBound, int upperBound, u32 vertType, int *vertexSize = nullptr); + u32 NormalizeVertices(SimpleVertex *outPtr, u8 *bufPtr, const u8 *inPtr, int lowerBound, int upperBound, u32 vertType, int *vertexSize = nullptr); int ComputeNumVertsToDecode() const; diff --git a/GPU/Common/SoftwareTransformCommon.cpp b/GPU/Common/SoftwareTransformCommon.cpp index 6fa5d76f16..3cff2f50bf 100644 --- a/GPU/Common/SoftwareTransformCommon.cpp +++ b/GPU/Common/SoftwareTransformCommon.cpp @@ -939,7 +939,7 @@ bool SoftwareTransform::ExpandPoints(int vertexCount, int &maxIndex, int vertsSi // The rest of the transform pipeline like lighting will go as normal, either hardware or software. // The implementation is initially a bit inefficient but shouldn't be a big deal. // An intermediate buffer of not-easy-to-predict size is stored at bufPtr. -u32 NormalizeVertices(u8 *outPtr, u8 *bufPtr, const u8 *inPtr, int lowerBound, int upperBound, VertexDecoder *dec, u32 vertType) { +u32 NormalizeVertices(SimpleVertex *sverts, u8 *bufPtr, const u8 *inPtr, int lowerBound, int upperBound, VertexDecoder *dec, u32 vertType) { // First, decode the vertices into a GPU compatible format. This step can be eliminated but will need a separate // implementation of the vertex decoder. dec->DecodeVerts(bufPtr, inPtr, &gstate_c.uv, lowerBound, upperBound); @@ -949,8 +949,6 @@ u32 NormalizeVertices(u8 *outPtr, u8 *bufPtr, const u8 *inPtr, int lowerBound, i VertexReader reader(bufPtr, dec->GetDecVtxFmt(), vertType); - SimpleVertex *sverts = (SimpleVertex *)outPtr; - const u8 defaultColor[4] = { (u8)gstate.getMaterialAmbientR(), (u8)gstate.getMaterialAmbientG(), diff --git a/GPU/Common/SoftwareTransformCommon.h b/GPU/Common/SoftwareTransformCommon.h index d6d72b32dc..14cb027f4a 100644 --- a/GPU/Common/SoftwareTransformCommon.h +++ b/GPU/Common/SoftwareTransformCommon.h @@ -20,6 +20,7 @@ #include "Common/CommonTypes.h" #include "Common/Math/lin/matrix4x4.h" #include "GPU/Common/VertexDecoderCommon.h" +#include "GPU/Common/TransformCommon.h" class FramebufferManagerCommon; class TextureCacheCommon; @@ -86,4 +87,4 @@ protected: }; // Slow. See description in the cpp file. -u32 NormalizeVertices(u8 *outPtr, u8 *bufPtr, const u8 *inPtr, int lowerBound, int upperBound, VertexDecoder *dec, u32 vertType); +u32 NormalizeVertices(SimpleVertex *sverts, u8 *bufPtr, const u8 *inPtr, int lowerBound, int upperBound, VertexDecoder *dec, u32 vertType); diff --git a/GPU/Common/SplineCommon.cpp b/GPU/Common/SplineCommon.cpp index 06bebe5617..075f30767a 100644 --- a/GPU/Common/SplineCommon.cpp +++ b/GPU/Common/SplineCommon.cpp @@ -507,7 +507,8 @@ void DrawEngineCommon::SubmitCurve(const void *control_points, const void *indic if (indices) GetIndexBounds(indices, num_points, vertType, &index_lower_bound, &index_upper_bound); - VertexDecoder *origVDecoder = GetVertexDecoder(GetVertTypeID(vertType, gstate.getUVGenMode(), applySkinInDecode_)); + u32 vertTypeID = GetVertTypeID(vertType, gstate.getUVGenMode(), applySkinInDecode_); + VertexDecoder *origVDecoder = GetVertexDecoder(vertTypeID); *bytesRead = num_points * origVDecoder->VertexSize(); // Simplify away bones and morph before proceeding @@ -525,7 +526,7 @@ void DrawEngineCommon::SubmitCurve(const void *control_points, const void *indic } u32 origVertType = vertType; - vertType = NormalizeVertices((u8 *)simplified_control_points, temp_buffer, (u8 *)control_points, index_lower_bound, index_upper_bound, vertType); + vertType = NormalizeVertices(simplified_control_points, temp_buffer, (u8 *)control_points, index_lower_bound, index_upper_bound, vertType); VertexDecoder *vdecoder = GetVertexDecoder(vertType); @@ -574,7 +575,7 @@ void DrawEngineCommon::SubmitCurve(const void *control_points, const void *indic gstate_c.uv.vOff = 0; } - uint32_t vertTypeID = GetVertTypeID(vertTypeWithIndex16, gstate.getUVGenMode(), applySkinInDecode_); + vertTypeID = GetVertTypeID(vertTypeWithIndex16, gstate.getUVGenMode(), applySkinInDecode_); int generatedBytesRead; if (output.count) DispatchSubmitPrim(output.vertices, output.indices, PatchPrimToPrim(surface.primType), output.count, vertTypeID, true, &generatedBytesRead); diff --git a/GPU/Software/TransformUnit.cpp b/GPU/Software/TransformUnit.cpp index 0baf088473..b4ddf38965 100644 --- a/GPU/Software/TransformUnit.cpp +++ b/GPU/Software/TransformUnit.cpp @@ -980,7 +980,7 @@ bool TransformUnit::GetCurrentSimpleVertices(int count, std::vector Date: Tue, 17 Dec 2024 17:27:54 +0100 Subject: [PATCH 3/6] Remove the member function NormalizeVertices --- GPU/Common/DrawEngineCommon.cpp | 24 ++++-------------------- GPU/Common/DrawEngineCommon.h | 14 ++++++++++---- GPU/Common/SplineCommon.cpp | 3 ++- 3 files changed, 16 insertions(+), 25 deletions(-) diff --git a/GPU/Common/DrawEngineCommon.cpp b/GPU/Common/DrawEngineCommon.cpp index 21e9fda064..83ccb211b0 100644 --- a/GPU/Common/DrawEngineCommon.cpp +++ b/GPU/Common/DrawEngineCommon.cpp @@ -64,17 +64,6 @@ void DrawEngineCommon::Init() { NotifyConfigChanged(); } -VertexDecoder *DrawEngineCommon::GetVertexDecoder(u32 vtype) { - VertexDecoder *dec; - if (decoderMap_.Get(vtype, &dec)) - return dec; - dec = new VertexDecoder(); - _assert_(dec); - dec->SetVertexType(vtype, decOptions_, decJitCache_); - decoderMap_.Insert(vtype, dec); - return dec; -} - std::vector DrawEngineCommon::DebugGetVertexLoaderIDs() { std::vector ids; decoderMap_.Iterate([&](const uint32_t vtype, VertexDecoder *decoder) { @@ -136,14 +125,6 @@ void DrawEngineCommon::NotifyConfigChanged() { useHWTessellation_ = UpdateUseHWTessellation(g_Config.bHardwareTessellation); } -u32 DrawEngineCommon::NormalizeVertices(SimpleVertex *outPtr, u8 *bufPtr, const u8 *inPtr, int lowerBound, int upperBound, u32 vertType, int *vertexSize) { - const u32 vertTypeID = GetVertTypeID(vertType, gstate.getUVGenMode(), applySkinInDecode_); - VertexDecoder *dec = GetVertexDecoder(vertTypeID); - if (vertexSize) - *vertexSize = dec->VertexSize(); - return ::NormalizeVertices(outPtr, bufPtr, inPtr, lowerBound, upperBound, dec, vertType); -} - void DrawEngineCommon::DispatchSubmitImm(GEPrimitiveType prim, TransformedVertex *buffer, int vertexCount, int cullMode, bool continuation) { // Instead of plumbing through properly (we'd need to inject these pretransformed vertices in the middle // of SoftwareTransform(), which would take a lot of refactoring), we'll cheat and just turn these into @@ -678,7 +659,10 @@ bool DrawEngineCommon::GetCurrentSimpleVertices(int count, std::vector simpleVertices; temp_buffer.resize(std::max((int)indexUpperBound, 8192) * 128 / sizeof(u32)); simpleVertices.resize(indexUpperBound + 1); - NormalizeVertices(&simpleVertices[0], (u8 *)(&temp_buffer[0]), Memory::GetPointerUnchecked(gstate_c.vertexAddr), indexLowerBound, indexUpperBound, gstate.vertType); + + const u32 vertTypeID = GetVertTypeID(gstate.vertType, gstate.getUVGenMode(), applySkinInDecode_); + VertexDecoder *dec = GetVertexDecoder(vertTypeID); + NormalizeVertices(&simpleVertices[0], (u8 *)(&temp_buffer[0]), Memory::GetPointerUnchecked(gstate_c.vertexAddr), indexLowerBound, indexUpperBound, dec, gstate.vertType); float world[16]; float view[16]; diff --git a/GPU/Common/DrawEngineCommon.h b/GPU/Common/DrawEngineCommon.h index 4154d91b2d..8577d50af3 100644 --- a/GPU/Common/DrawEngineCommon.h +++ b/GPU/Common/DrawEngineCommon.h @@ -141,7 +141,16 @@ public: return numDrawVerts_; } - VertexDecoder *GetVertexDecoder(u32 vtype); + VertexDecoder *GetVertexDecoder(u32 vtype) { + VertexDecoder *dec; + if (decoderMap_.Get(vtype, &dec)) + return dec; + dec = new VertexDecoder(); + _assert_(dec); + dec->SetVertexType(vtype, decOptions_, decJitCache_); + decoderMap_.Insert(vtype, dec); + return dec; + } virtual void ClearTrackedVertexArrays() {} @@ -156,9 +165,6 @@ protected: void DecodeVerts(VertexDecoder *dec, u8 *dest); int DecodeInds(); - // Preprocessing for spline/bezier - u32 NormalizeVertices(SimpleVertex *outPtr, u8 *bufPtr, const u8 *inPtr, int lowerBound, int upperBound, u32 vertType, int *vertexSize = nullptr); - int ComputeNumVertsToDecode() const; void ApplyFramebufferRead(FBOTexState *fboTexState); diff --git a/GPU/Common/SplineCommon.cpp b/GPU/Common/SplineCommon.cpp index 075f30767a..4c5e2ad948 100644 --- a/GPU/Common/SplineCommon.cpp +++ b/GPU/Common/SplineCommon.cpp @@ -24,6 +24,7 @@ #include "GPU/Common/GPUStateUtils.h" #include "GPU/Common/SplineCommon.h" #include "GPU/Common/DrawEngineCommon.h" +#include "GPU/Common/SoftwareTransformCommon.h" #include "GPU/ge_constants.h" #include "GPU/GPUState.h" // only needed for UVScale stuff @@ -526,7 +527,7 @@ void DrawEngineCommon::SubmitCurve(const void *control_points, const void *indic } u32 origVertType = vertType; - vertType = NormalizeVertices(simplified_control_points, temp_buffer, (u8 *)control_points, index_lower_bound, index_upper_bound, vertType); + vertType = ::NormalizeVertices(simplified_control_points, temp_buffer, (u8 *)control_points, index_lower_bound, index_upper_bound, origVDecoder, vertType); VertexDecoder *vdecoder = GetVertexDecoder(vertType); From fe4504f6124c0628184b445ebd128143ceac7157 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 17 Dec 2024 17:30:07 +0100 Subject: [PATCH 4/6] Small simplification --- GPU/Common/DrawEngineCommon.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/GPU/Common/DrawEngineCommon.h b/GPU/Common/DrawEngineCommon.h index 8577d50af3..1dadb31288 100644 --- a/GPU/Common/DrawEngineCommon.h +++ b/GPU/Common/DrawEngineCommon.h @@ -107,9 +107,13 @@ public: bool TestBoundingBoxFast(const void *control_points, int vertexCount, u32 vertType); bool TestBoundingBoxThrough(const void *vdata, int vertexCount, u32 vertType); + void FlushPartialDecode() { + DecodeVerts(dec_, decoded_); + } + void FlushSkin() { if (dec_->skinInDecode) { - DecodeVerts(dec_, decoded_); + FlushPartialDecode(); } } From 61b14df329f1963391b0c9fc13304a56fe993c15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 17 Dec 2024 17:35:24 +0100 Subject: [PATCH 5/6] Delete obsolete empty function ClearTrackedVertexArrays --- GPU/Common/DrawEngineCommon.cpp | 1 - GPU/Common/DrawEngineCommon.h | 2 -- GPU/D3D11/DrawEngineD3D11.cpp | 1 - GPU/Directx9/DrawEngineDX9.cpp | 1 - GPU/GLES/DrawEngineGLES.cpp | 2 -- GPU/GLES/DrawEngineGLES.h | 3 --- GPU/GPUCommonHW.cpp | 1 - 7 files changed, 11 deletions(-) diff --git a/GPU/Common/DrawEngineCommon.cpp b/GPU/Common/DrawEngineCommon.cpp index 83ccb211b0..ed58732a7d 100644 --- a/GPU/Common/DrawEngineCommon.cpp +++ b/GPU/Common/DrawEngineCommon.cpp @@ -119,7 +119,6 @@ void DrawEngineCommon::NotifyConfigChanged() { delete decoder; }); decoderMap_.Clear(); - ClearTrackedVertexArrays(); useHWTransform_ = g_Config.bHardwareTransform; useHWTessellation_ = UpdateUseHWTessellation(g_Config.bHardwareTessellation); diff --git a/GPU/Common/DrawEngineCommon.h b/GPU/Common/DrawEngineCommon.h index 1dadb31288..38f41eca15 100644 --- a/GPU/Common/DrawEngineCommon.h +++ b/GPU/Common/DrawEngineCommon.h @@ -156,8 +156,6 @@ public: return dec; } - virtual void ClearTrackedVertexArrays() {} - void AssertEmpty() { _dbg_assert_(numDrawVerts_ == 0 && numDrawInds_ == 0); } diff --git a/GPU/D3D11/DrawEngineD3D11.cpp b/GPU/D3D11/DrawEngineD3D11.cpp index 4ad2b8bf51..d536d1e4c5 100644 --- a/GPU/D3D11/DrawEngineD3D11.cpp +++ b/GPU/D3D11/DrawEngineD3D11.cpp @@ -115,7 +115,6 @@ void DrawEngineD3D11::DestroyDeviceObjects() { draw_->SetInvalidationCallback(InvalidationCallback()); } - ClearTrackedVertexArrays(); ClearInputLayoutMap(); delete tessDataTransferD3D11; tessDataTransferD3D11 = nullptr; diff --git a/GPU/Directx9/DrawEngineDX9.cpp b/GPU/Directx9/DrawEngineDX9.cpp index d557148beb..84e3826df3 100644 --- a/GPU/Directx9/DrawEngineDX9.cpp +++ b/GPU/Directx9/DrawEngineDX9.cpp @@ -111,7 +111,6 @@ void DrawEngineDX9::DestroyDeviceObjects() { if (draw_) { draw_->SetInvalidationCallback(InvalidationCallback()); } - ClearTrackedVertexArrays(); } struct DeclTypeInfo { diff --git a/GPU/GLES/DrawEngineGLES.cpp b/GPU/GLES/DrawEngineGLES.cpp index d96631174c..f2cc6a6c4c 100644 --- a/GPU/GLES/DrawEngineGLES.cpp +++ b/GPU/GLES/DrawEngineGLES.cpp @@ -130,8 +130,6 @@ void DrawEngineGLES::DestroyDeviceObjects() { frameData_[i].pushIndex = nullptr; } - ClearTrackedVertexArrays(); - if (softwareInputLayout_) render_->DeleteInputLayout(softwareInputLayout_); softwareInputLayout_ = nullptr; diff --git a/GPU/GLES/DrawEngineGLES.h b/GPU/GLES/DrawEngineGLES.h index 9d05fdb429..1d4f8ce513 100644 --- a/GPU/GLES/DrawEngineGLES.h +++ b/GPU/GLES/DrawEngineGLES.h @@ -79,8 +79,6 @@ public: void DeviceLost() override; void DeviceRestore(Draw::DrawContext *draw) override; - void ClearTrackedVertexArrays() override {} - void BeginFrame() override; void EndFrame(); @@ -103,7 +101,6 @@ private: void InitDeviceObjects(); void DestroyDeviceObjects(); - void DoFlush(); void ApplyDrawState(int prim); void ApplyDrawStateLate(bool setStencil, int stencilValue); diff --git a/GPU/GPUCommonHW.cpp b/GPU/GPUCommonHW.cpp index 4db8f3bd87..b4a8c97a7d 100644 --- a/GPU/GPUCommonHW.cpp +++ b/GPU/GPUCommonHW.cpp @@ -554,7 +554,6 @@ void GPUCommonHW::DoState(PointerWrap &p) { // None of these are necessary when saving. if (p.mode == p.MODE_READ && !PSP_CoreParameter().frozen) { textureCache_->Clear(true); - drawEngineCommon_->ClearTrackedVertexArrays(); gstate_c.Dirty(DIRTY_TEXTURE_IMAGE); framebufferManager_->DestroyAllFBOs(); From 15b4f0c29964fbc916d8a986bef18af4abc1546d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 17 Dec 2024 19:27:01 +0100 Subject: [PATCH 6/6] Lookup the decoder outside of DrawEngine --- GPU/Common/DrawEngineCommon.cpp | 10 +++++++--- GPU/Common/DrawEngineCommon.h | 13 +++++++------ GPU/GPUCommonHW.cpp | 6 ++++-- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/GPU/Common/DrawEngineCommon.cpp b/GPU/Common/DrawEngineCommon.cpp index ed58732a7d..0ea6f18a60 100644 --- a/GPU/Common/DrawEngineCommon.cpp +++ b/GPU/Common/DrawEngineCommon.cpp @@ -168,7 +168,8 @@ void DrawEngineCommon::DispatchSubmitImm(GEPrimitiveType prim, TransformedVertex uint32_t vertTypeID = GetVertTypeID(vtype, 0, applySkinInDecode_); bool clockwise = !gstate.isCullEnabled() || gstate.getCullMode() == cullMode; - SubmitPrim(&temp[0], nullptr, prim, vertexCount, vertTypeID, clockwise, &bytesRead); + VertexDecoder *dec = GetVertexDecoder(vertTypeID); + SubmitPrim(&temp[0], nullptr, prim, vertexCount, dec, vertTypeID, clockwise, &bytesRead); Flush(); if (!prevThrough) { @@ -826,7 +827,7 @@ void DrawEngineCommon::SkipPrim(GEPrimitiveType prim, int vertexCount, u32 vertT } // vertTypeID is the vertex type but with the UVGen mode smashed into the top bits. -bool DrawEngineCommon::SubmitPrim(const void *verts, const void *inds, GEPrimitiveType prim, int vertexCount, u32 vertTypeID, bool clockwise, int *bytesRead) { +bool DrawEngineCommon::SubmitPrim(const void *verts, const void *inds, GEPrimitiveType prim, int vertexCount, VertexDecoder *dec, u32 vertTypeID, bool clockwise, int *bytesRead) { if (!indexGen.PrimCompatible(prevPrim_, prim) || numDrawVerts_ >= MAX_DEFERRED_DRAW_VERTS || numDrawInds_ >= MAX_DEFERRED_DRAW_INDS || vertexCountInDrawCalls_ + vertexCount > VERTEX_BUFFER_MAX) { Flush(); } @@ -846,8 +847,11 @@ bool DrawEngineCommon::SubmitPrim(const void *verts, const void *inds, GEPrimiti // If vtype has changed, setup the vertex decoder. Don't need to nullcheck dec_ since we set lastVType_ to an invalid value whenever we null it. if (vertTypeID != lastVType_) { - dec_ = GetVertexDecoder(vertTypeID); + dec_ = dec; + _dbg_assert_(dec->VertexType() == vertTypeID); lastVType_ = vertTypeID; + } else { + _dbg_assert_(dec_->VertexType() == lastVType_); } *bytesRead = vertexCount * dec_->VertexSize(); diff --git a/GPU/Common/DrawEngineCommon.h b/GPU/Common/DrawEngineCommon.h index 38f41eca15..fd538c04ed 100644 --- a/GPU/Common/DrawEngineCommon.h +++ b/GPU/Common/DrawEngineCommon.h @@ -95,7 +95,8 @@ public: // is different. Should probably refactor that. // Note that vertTypeID should be computed using GetVertTypeID(). virtual void DispatchSubmitPrim(const void *verts, const void *inds, GEPrimitiveType prim, int vertexCount, u32 vertTypeID, bool clockwise, int *bytesRead) { - SubmitPrim(verts, inds, prim, vertexCount, vertTypeID, clockwise, bytesRead); + VertexDecoder *dec = GetVertexDecoder(vertTypeID); + SubmitPrim(verts, inds, prim, vertexCount, dec, vertTypeID, clockwise, bytesRead); } virtual void DispatchSubmitImm(GEPrimitiveType prim, TransformedVertex *buffer, int vertexCount, int cullMode, bool continuation); @@ -118,7 +119,7 @@ public: } int ExtendNonIndexedPrim(const uint32_t *cmd, const uint32_t *stall, u32 vertTypeID, bool clockwise, int *bytesRead, bool isTriangle); - bool SubmitPrim(const void *verts, const void *inds, GEPrimitiveType prim, int vertexCount, u32 vertTypeID, bool clockwise, int *bytesRead); + bool SubmitPrim(const void *verts, const void *inds, GEPrimitiveType prim, int vertexCount, VertexDecoder *dec, u32 vertTypeID, bool clockwise, int *bytesRead); void SkipPrim(GEPrimitiveType prim, int vertexCount, u32 vertTypeID, int *bytesRead); template @@ -145,14 +146,14 @@ public: return numDrawVerts_; } - VertexDecoder *GetVertexDecoder(u32 vtype) { + VertexDecoder *GetVertexDecoder(u32 vertTypeID) { VertexDecoder *dec; - if (decoderMap_.Get(vtype, &dec)) + if (decoderMap_.Get(vertTypeID, &dec)) return dec; dec = new VertexDecoder(); _assert_(dec); - dec->SetVertexType(vtype, decOptions_, decJitCache_); - decoderMap_.Insert(vtype, dec); + dec->SetVertexType(vertTypeID, decOptions_, decJitCache_); + decoderMap_.Insert(vertTypeID, dec); return dec; } diff --git a/GPU/GPUCommonHW.cpp b/GPU/GPUCommonHW.cpp index b4a8c97a7d..d4f11518b0 100644 --- a/GPU/GPUCommonHW.cpp +++ b/GPU/GPUCommonHW.cpp @@ -997,6 +997,7 @@ void GPUCommonHW::Execute_Prim(u32 op, u32 diff) { int cullMode = gstate.getCullMode(); uint32_t vertTypeID = GetVertTypeID(vertexType, gstate.getUVGenMode(), g_Config.bSoftwareSkinning); + VertexDecoder *decoder = drawEngineCommon_->GetVertexDecoder(vertTypeID); // Through mode early-out for simple float 2D draws, like in Fate Extra CCC (very beneficial there due to avoiding texture loads) if ((vertexType & (GE_VTYPE_THROUGH_MASK | GE_VTYPE_POS_MASK | GE_VTYPE_IDX_MASK)) == (GE_VTYPE_THROUGH_MASK | GE_VTYPE_POS_FLOAT | GE_VTYPE_IDX_NONE)) { @@ -1037,7 +1038,7 @@ void GPUCommonHW::Execute_Prim(u32 op, u32 diff) { // Cuts down on checking, while not losing that much efficiency. bool onePassed = false; if (passCulling) { - if (!drawEngineCommon_->SubmitPrim(verts, inds, prim, count, vertTypeID, true, &bytesRead)) { + if (!drawEngineCommon_->SubmitPrim(verts, inds, prim, count, decoder, vertTypeID, true, &bytesRead)) { canExtend = false; } onePassed = true; @@ -1115,7 +1116,7 @@ void GPUCommonHW::Execute_Prim(u32 op, u32 diff) { } } if (passCulling) { - if (!drawEngineCommon_->SubmitPrim(verts, inds, newPrim, count, vertTypeID, clockwise, &bytesRead)) { + if (!drawEngineCommon_->SubmitPrim(verts, inds, newPrim, count, decoder, vertTypeID, clockwise, &bytesRead)) { canExtend = false; } // As soon as one passes, assume we don't need to check the rest of this batch. @@ -1140,6 +1141,7 @@ void GPUCommonHW::Execute_Prim(u32 op, u32 diff) { canExtend = false; // TODO: Might support extending between some vertex types in the future. vertexType = data; vertTypeID = GetVertTypeID(vertexType, gstate.getUVGenMode(), g_Config.bSoftwareSkinning); + decoder = drawEngineCommon_->GetVertexDecoder(vertTypeID); } break; }