From 6877ff1af25c754c70ea55e6f25d3ef9921fb317 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 17 Sep 2022 20:15:40 -0700 Subject: [PATCH] softgpu: Fix state/continuation for imm prims. --- GPU/Common/DrawEngineCommon.cpp | 2 +- GPU/Common/DrawEngineCommon.h | 2 +- GPU/GPUCommon.cpp | 4 +++- GPU/GPUCommon.h | 1 + GPU/Software/SoftGpu.cpp | 8 +++++++- GPU/Software/SoftGpu.h | 2 ++ GPU/Software/TransformUnit.cpp | 5 +++-- GPU/Software/TransformUnit.h | 2 +- 8 files changed, 19 insertions(+), 7 deletions(-) diff --git a/GPU/Common/DrawEngineCommon.cpp b/GPU/Common/DrawEngineCommon.cpp index df66890248..9f405b8ccc 100644 --- a/GPU/Common/DrawEngineCommon.cpp +++ b/GPU/Common/DrawEngineCommon.cpp @@ -189,7 +189,7 @@ u32 DrawEngineCommon::NormalizeVertices(u8 *outPtr, u8 *bufPtr, const u8 *inPtr, return DrawEngineCommon::NormalizeVertices(outPtr, bufPtr, inPtr, dec, lowerBound, upperBound, vertType); } -void DrawEngineCommon::DispatchSubmitImm(GEPrimitiveType prim, TransformedVertex *buffer, int vertexCount, int cullMode) { +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 // through vertices. diff --git a/GPU/Common/DrawEngineCommon.h b/GPU/Common/DrawEngineCommon.h index 49c5e73200..40c397649b 100644 --- a/GPU/Common/DrawEngineCommon.h +++ b/GPU/Common/DrawEngineCommon.h @@ -90,7 +90,7 @@ public: SubmitPrim(verts, inds, prim, vertexCount, vertTypeID, cullMode, bytesRead); } - virtual void DispatchSubmitImm(GEPrimitiveType prim, TransformedVertex *buffer, int vertexCount, int cullMode); + virtual void DispatchSubmitImm(GEPrimitiveType prim, TransformedVertex *buffer, int vertexCount, int cullMode, bool continuation); bool TestBoundingBox(const void* control_points, int vertexCount, u32 vertType, int *bytesRead); diff --git a/GPU/GPUCommon.cpp b/GPU/GPUCommon.cpp index e91d32f5d6..0654c5ad89 100644 --- a/GPU/GPUCommon.cpp +++ b/GPU/GPUCommon.cpp @@ -2414,6 +2414,7 @@ void GPUCommon::Execute_ImmVertexAlphaPrim(u32 op, u32 diff) { immPrim_ = (GEPrimitiveType)prim; // Flags seem to only be respected from the first prim. immFlags_ = op & 0x00FFF800; + immFirstSent_ = false; } else if (prim == GE_PRIM_KEEP_PREVIOUS && immPrim_ != GE_PRIM_INVALID) { static constexpr int flushPrimCount[] = { 1, 2, 0, 3, 0, 0, 2, 0 }; // Instead of finding a proper point to flush, we just emit prims when we can. @@ -2467,8 +2468,9 @@ void GPUCommon::FlushImm() { gstate_c.Dirty(DIRTY_VERTEXSHADER_STATE | DIRTY_FRAGMENTSHADER_STATE | DIRTY_RASTER_STATE); } - drawEngineCommon_->DispatchSubmitImm(immPrim_, immBuffer_, immCount_, cullMode); + drawEngineCommon_->DispatchSubmitImm(immPrim_, immBuffer_, immCount_, cullMode, immFirstSent_); immCount_ = 0; + immFirstSent_ = true; gstate.antiAliasEnable = (GE_CMD_ANTIALIASENABLE << 24) | (int)prevAntialias; gstate.shademodel = (GE_CMD_SHADEMODE << 24) | (int)prevShading; diff --git a/GPU/GPUCommon.h b/GPU/GPUCommon.h index 26dd599164..cddb1ccdc1 100644 --- a/GPU/GPUCommon.h +++ b/GPU/GPUCommon.h @@ -355,6 +355,7 @@ protected: int immCount_ = 0; GEPrimitiveType immPrim_ = GE_PRIM_INVALID; uint32_t immFlags_ = 0; + bool immFirstSent_ = false; std::string reportingPrimaryInfo_; std::string reportingFullInfo_; diff --git a/GPU/Software/SoftGpu.cpp b/GPU/Software/SoftGpu.cpp index 48c5258cd5..01c0a46023 100644 --- a/GPU/Software/SoftGpu.cpp +++ b/GPU/Software/SoftGpu.cpp @@ -361,7 +361,7 @@ const SoftwareCommandTableEntry softgpuCommandTable[] = { { GE_CMD_VTCT }, { GE_CMD_VTCQ }, { GE_CMD_VCV }, - { GE_CMD_VAP, FLAG_EXECUTE, SoftDirty::NONE, &GPUCommon::Execute_ImmVertexAlphaPrim }, + { GE_CMD_VAP, FLAG_EXECUTE, SoftDirty::NONE, &SoftGPU::Execute_ImmVertexAlphaPrim }, { GE_CMD_VFC }, { GE_CMD_VSCV }, @@ -1110,6 +1110,12 @@ void SoftGPU::Execute_BoneMtxData(u32 op, u32 diff) { gstate.boneMatrixData = GE_CMD_BONEMATRIXDATA << 24; } +void SoftGPU::Execute_ImmVertexAlphaPrim(u32 op, u32 diff) { + GPUCommon::Execute_ImmVertexAlphaPrim(op, diff); + // We won't flush as often as hardware renderers, so we want to flush right away. + FlushImm(); +} + void SoftGPU::Execute_Call(u32 op, u32 diff) { PROFILE_THIS_SCOPE("gpu_call"); diff --git a/GPU/Software/SoftGpu.h b/GPU/Software/SoftGpu.h index 54880bd477..3ce69dcc18 100644 --- a/GPU/Software/SoftGpu.h +++ b/GPU/Software/SoftGpu.h @@ -187,6 +187,8 @@ public: void Execute_TgenMtxData(u32 op, u32 diff); void Execute_BoneMtxData(u32 op, u32 diff); + void Execute_ImmVertexAlphaPrim(u32 op, u32 diff); + typedef void (SoftGPU::*CmdFunc)(u32 op, u32 diff); protected: diff --git a/GPU/Software/TransformUnit.cpp b/GPU/Software/TransformUnit.cpp index 1278d93483..a57769f5dd 100644 --- a/GPU/Software/TransformUnit.cpp +++ b/GPU/Software/TransformUnit.cpp @@ -70,7 +70,7 @@ void SoftwareDrawEngine::DispatchSubmitPrim(const void *verts, const void *inds, transformUnit.SubmitPrimitive(verts, inds, prim, vertexCount, vertTypeID, bytesRead, this); } -void SoftwareDrawEngine::DispatchSubmitImm(GEPrimitiveType prim, TransformedVertex *buffer, int vertexCount, int cullMode) { +void SoftwareDrawEngine::DispatchSubmitImm(GEPrimitiveType prim, TransformedVertex *buffer, int vertexCount, int cullMode, bool continuation) { uint32_t vertTypeID = GetVertTypeID(gstate.vertType, gstate.getUVGenMode()); int flipCull = cullMode != gstate.getCullMode() ? 1 : 0; @@ -97,7 +97,8 @@ void SoftwareDrawEngine::DispatchSubmitImm(GEPrimitiveType prim, TransformedVert // Before we start, submit 0 prims to reset the prev prim type. // Following submits will always be KEEP_PREVIOUS. - transformUnit.SubmitPrimitive(nullptr, nullptr, prim, 0, vertTypeID, nullptr, this); + if (!continuation) + transformUnit.SubmitPrimitive(nullptr, nullptr, prim, 0, vertTypeID, nullptr, this); for (int i = 0; i < vertexCount; i++) { VertexData vert; diff --git a/GPU/Software/TransformUnit.h b/GPU/Software/TransformUnit.h index bcaf5859c7..465f4bd8ab 100644 --- a/GPU/Software/TransformUnit.h +++ b/GPU/Software/TransformUnit.h @@ -165,7 +165,7 @@ public: void DispatchFlush() override; void DispatchSubmitPrim(const void *verts, const void *inds, GEPrimitiveType prim, int vertexCount, u32 vertType, int cullMode, int *bytesRead) override; - void DispatchSubmitImm(GEPrimitiveType prim, TransformedVertex *buffer, int vertexCount, int cullMode) override; + void DispatchSubmitImm(GEPrimitiveType prim, TransformedVertex *buffer, int vertexCount, int cullMode, bool continuation) override; VertexDecoder *FindVertexDecoder(u32 vtype);