From 18a9de3eca2ffe31d19974c8849dbdada6b67fe8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 14 Jul 2026 15:28:21 +0200 Subject: [PATCH] Move AdvanceVerts to GPUStateCache --- GPU/GPUCommon.cpp | 2 +- GPU/GPUCommon.h | 9 --------- GPU/GPUCommonHW.cpp | 22 ++++++++++++---------- GPU/GPUState.h | 10 ++++++++++ GPU/Software/SoftGpu.cpp | 28 ++++++++++++++++------------ 5 files changed, 39 insertions(+), 32 deletions(-) diff --git a/GPU/GPUCommon.cpp b/GPU/GPUCommon.cpp index 7babc15025..4f748f885a 100644 --- a/GPU/GPUCommon.cpp +++ b/GPU/GPUCommon.cpp @@ -1243,7 +1243,7 @@ void GPUCommon::Execute_BoundingBox(u32 op, u32 diff) { // This is the normal case that pretty much always happens, the others are esoteric. currentList->bboxResult = drawEngineCommon_->TestBoundingBox(control_points, inds, count, dec, vertType); } - AdvanceVerts(gstate.vertType, count, bytesRead); + gstate_c.AdvanceVerts(vertType, count, bytesRead); } void GPUCommon::Execute_MorphWeight(u32 op, u32 diff) { diff --git a/GPU/GPUCommon.h b/GPU/GPUCommon.h index af1553be34..9372dcee0d 100644 --- a/GPU/GPUCommon.h +++ b/GPU/GPUCommon.h @@ -320,15 +320,6 @@ protected: // TODO: Unify this. Vulkan and OpenGL are different due to how they buffer data. virtual void FinishDeferred() {} - void AdvanceVerts(u32 vertType, int count, int bytesRead) { - if ((vertType & GE_VTYPE_IDX_MASK) != GE_VTYPE_IDX_NONE) { - const int indexShift = ((vertType & GE_VTYPE_IDX_MASK) >> GE_VTYPE_IDX_SHIFT) - 1; - gstate_c.indexAddr += count << indexShift; - } else { - gstate_c.vertexAddr += bytesRead; - } - } - virtual void BuildReportingInfo() = 0; virtual void UpdateMSAALevel(Draw::DrawContext *draw) {} diff --git a/GPU/GPUCommonHW.cpp b/GPU/GPUCommonHW.cpp index fa0f8c2545..9689295011 100644 --- a/GPU/GPUCommonHW.cpp +++ b/GPU/GPUCommonHW.cpp @@ -1051,7 +1051,7 @@ void GPUCommonHW::Execute_Prim(u32 op, u32 diff) { // After drawing, we advance the vertexAddr (when non indexed) or indexAddr (when indexed). // Some games rely on this, they don't bother reloading VADDR and IADDR. // The VADDR/IADDR registers are NOT updated. - AdvanceVerts(vertexType, count, bytesRead); + gstate_c.AdvanceVerts(vertexType, count, bytesRead); int totalVertCount = count; @@ -1132,7 +1132,7 @@ void GPUCommonHW::Execute_Prim(u32 op, u32 diff) { drawEngineCommon_->SkipPrim(newPrim, count, decoder, &bytesRead); canExtend = false; } - AdvanceVerts(vertexType, count, bytesRead); + gstate_c.AdvanceVerts(vertexType, count, bytesRead); totalVertCount += count; break; } @@ -1301,7 +1301,8 @@ void GPUCommonHW::Execute_Bezier(u32 op, u32 diff) { const void *control_points = Memory::GetPointerUnchecked(gstate_c.vertexAddr); const void *indices = NULL; - if ((gstate.vertType & GE_VTYPE_IDX_MASK) != GE_VTYPE_IDX_NONE) { + const u32 vertType = gstate.vertType; + if ((vertType & GE_VTYPE_IDX_MASK) != GE_VTYPE_IDX_NONE) { if (!Memory::IsValidAddress(gstate_c.indexAddr)) { ERROR_LOG(Log::G3D, "Bad index address %08x!", gstate_c.indexAddr); return; @@ -1309,8 +1310,8 @@ void GPUCommonHW::Execute_Bezier(u32 op, u32 diff) { indices = Memory::GetPointerUnchecked(gstate_c.indexAddr); } - if (vertTypeIsSkinningEnabled(gstate.vertType)) { - DEBUG_LOG_REPORT(Log::G3D, "Unusual bezier/spline vtype: %08x, morph: %d, bones: %d", gstate.vertType, (gstate.vertType & GE_VTYPE_MORPHCOUNT_MASK) >> GE_VTYPE_MORPHCOUNT_SHIFT, vertTypeGetNumBoneWeights(gstate.vertType)); + if (vertTypeIsSkinningEnabled(vertType)) { + DEBUG_LOG_REPORT(Log::G3D, "Unusual bezier/spline vtype: %08x, morph: %d, bones: %d", vertType, (vertType & GE_VTYPE_MORPHCOUNT_MASK) >> GE_VTYPE_MORPHCOUNT_SHIFT, vertTypeGetNumBoneWeights(vertType)); } // Can't flush after setting gstate_c.submitType below since it'll be a mess - it must be done already. @@ -1341,7 +1342,7 @@ void GPUCommonHW::Execute_Bezier(u32 op, u32 diff) { // After drawing, we advance pointers - see SubmitPrim which does the same. const int count = surface.num_points_u * surface.num_points_v; - AdvanceVerts(gstate.vertType, count, bytesRead); + gstate_c.AdvanceVerts(vertType, count, bytesRead); } void GPUCommonHW::Execute_Spline(u32 op, u32 diff) { @@ -1370,7 +1371,8 @@ void GPUCommonHW::Execute_Spline(u32 op, u32 diff) { const void *control_points = Memory::GetPointerUnchecked(gstate_c.vertexAddr); const void *indices = NULL; - if ((gstate.vertType & GE_VTYPE_IDX_MASK) != GE_VTYPE_IDX_NONE) { + const u32 vertType = gstate.vertType; + if ((vertType & GE_VTYPE_IDX_MASK) != GE_VTYPE_IDX_NONE) { if (!Memory::IsValidAddress(gstate_c.indexAddr)) { ERROR_LOG(Log::G3D, "Bad index address %08x!", gstate_c.indexAddr); return; @@ -1378,8 +1380,8 @@ void GPUCommonHW::Execute_Spline(u32 op, u32 diff) { indices = Memory::GetPointerUnchecked(gstate_c.indexAddr); } - if (vertTypeIsSkinningEnabled(gstate.vertType)) { - WARN_LOG_ONCE(unusualcurve, Log::G3D, "Unusual bezier/spline vtype: %08x, morph: %d, bones: %d", gstate.vertType, (gstate.vertType & GE_VTYPE_MORPHCOUNT_MASK) >> GE_VTYPE_MORPHCOUNT_SHIFT, vertTypeGetNumBoneWeights(gstate.vertType)); + if (vertTypeIsSkinningEnabled(vertType)) { + WARN_LOG_ONCE(unusualcurve, Log::G3D, "Unusual bezier/spline vtype: %08x, morph: %d, bones: %d", vertType, (vertType & GE_VTYPE_MORPHCOUNT_MASK) >> GE_VTYPE_MORPHCOUNT_SHIFT, vertTypeGetNumBoneWeights(vertType)); } // Can't flush after setting gstate_c.submitType below since it'll be a mess - it must be done already. @@ -1412,7 +1414,7 @@ void GPUCommonHW::Execute_Spline(u32 op, u32 diff) { // After drawing, we advance pointers - see SubmitPrim which does the same. int count = surface.num_points_u * surface.num_points_v; - AdvanceVerts(gstate.vertType, count, bytesRead); + gstate_c.AdvanceVerts(vertType, count, bytesRead); } void GPUCommonHW::Execute_BlockTransferStart(u32 op, u32 diff) { diff --git a/GPU/GPUState.h b/GPU/GPUState.h index 845579a69a..48959bdfe8 100644 --- a/GPU/GPUState.h +++ b/GPU/GPUState.h @@ -534,6 +534,16 @@ struct GPUStateCache { bool IsDirty(u64 what) const { return (dirty & what) != 0ULL; } + + void AdvanceVerts(u32 vertType, int count, int bytesRead) { + if ((vertType & GE_VTYPE_IDX_MASK) != GE_VTYPE_IDX_NONE) { + const int indexShift = ((vertType & GE_VTYPE_IDX_MASK) >> GE_VTYPE_IDX_SHIFT) - 1; + indexAddr += count << indexShift; + } else { + vertexAddr += bytesRead; + } + } + void SetTextureSolidAlpha(bool solidAlpha) { if (solidAlpha != textureSolidAlpha) { textureSolidAlpha = solidAlpha; diff --git a/GPU/Software/SoftGpu.cpp b/GPU/Software/SoftGpu.cpp index 336df8343c..14e8c9b448 100644 --- a/GPU/Software/SoftGpu.cpp +++ b/GPU/Software/SoftGpu.cpp @@ -853,7 +853,9 @@ void SoftGPU::Execute_Prim(u32 op, u32 diff) { const void *verts = Memory::GetPointerUnchecked(gstate_c.vertexAddr); const void *indices = NULL; - if ((gstate.vertType & GE_VTYPE_IDX_MASK) != GE_VTYPE_IDX_NONE) { + + const u32 vertType = gstate.vertType; + if ((vertType & GE_VTYPE_IDX_MASK) != GE_VTYPE_IDX_NONE) { if (!Memory::IsValidAddress(gstate_c.indexAddr)) { ERROR_LOG_REPORT(Log::G3D, "Software: Bad index address %08x!", gstate_c.indexAddr); return; @@ -864,7 +866,7 @@ void SoftGPU::Execute_Prim(u32 op, u32 diff) { cyclesExecuted += EstimatePerVertexCost() * count; int bytesRead; drawEngine_->transformUnit.SetDirty(dirtyFlags_); - drawEngine_->transformUnit.SubmitPrimitive(verts, indices, prim, count, gstate.vertType, &bytesRead, drawEngine_); + drawEngine_->transformUnit.SubmitPrimitive(verts, indices, prim, count, vertType, &bytesRead, drawEngine_); dirtyFlags_ = drawEngine_->transformUnit.GetDirty(); SoftGPUVRAMDirty mark = (gstate_c.skipDrawReason & SKIPDRAW_SKIPFRAME) != 0 ? SoftGPUVRAMDirty::DIRTY : SoftGPUVRAMDirty::DIRTY | SoftGPUVRAMDirty::REALLY_DIRTY; @@ -873,7 +875,7 @@ void SoftGPU::Execute_Prim(u32 op, u32 diff) { // After drawing, we advance the vertexAddr (when non indexed) or indexAddr (when indexed). // Some games rely on this, they don't bother reloading VADDR and IADDR. // The VADDR/IADDR registers are NOT updated. - AdvanceVerts(gstate.vertType, count, bytesRead); + gstate_c.AdvanceVerts(vertType, count, bytesRead); } void SoftGPU::Execute_Bezier(u32 op, u32 diff) { @@ -890,7 +892,8 @@ void SoftGPU::Execute_Bezier(u32 op, u32 diff) { const void *control_points = Memory::GetPointerUnchecked(gstate_c.vertexAddr); const void *indices = NULL; - if ((gstate.vertType & GE_VTYPE_IDX_MASK) != GE_VTYPE_IDX_NONE) { + const u32 vertType = gstate.vertType; + if ((vertType & GE_VTYPE_IDX_MASK) != GE_VTYPE_IDX_NONE) { if (!Memory::IsValidAddress(gstate_c.indexAddr)) { ERROR_LOG_REPORT(Log::G3D, "Bad index address %08x!", gstate_c.indexAddr); return; @@ -898,8 +901,8 @@ void SoftGPU::Execute_Bezier(u32 op, u32 diff) { indices = Memory::GetPointerUnchecked(gstate_c.indexAddr); } - if ((gstate.vertType & GE_VTYPE_MORPHCOUNT_MASK) || vertTypeIsSkinningEnabled(gstate.vertType)) { - DEBUG_LOG_REPORT(Log::G3D, "Unusual bezier/spline vtype: %08x, morph: %d, bones: %d", gstate.vertType, (gstate.vertType & GE_VTYPE_MORPHCOUNT_MASK) >> GE_VTYPE_MORPHCOUNT_SHIFT, vertTypeGetNumBoneWeights(gstate.vertType)); + if ((vertType & GE_VTYPE_MORPHCOUNT_MASK) || vertTypeIsSkinningEnabled(vertType)) { + DEBUG_LOG_REPORT(Log::G3D, "Unusual bezier/spline vtype: %08x, morph: %d, bones: %d", vertType, (vertType & GE_VTYPE_MORPHCOUNT_MASK) >> GE_VTYPE_MORPHCOUNT_SHIFT, vertTypeGetNumBoneWeights(vertType)); } Spline::BezierSurface surface; @@ -924,7 +927,7 @@ void SoftGPU::Execute_Bezier(u32 op, u32 diff) { // After drawing, we advance pointers - see SubmitPrim which does the same. int count = surface.num_points_u * surface.num_points_v; - AdvanceVerts(gstate.vertType, count, bytesRead); + gstate_c.AdvanceVerts(vertType, count, bytesRead); } void SoftGPU::Execute_Spline(u32 op, u32 diff) { @@ -941,7 +944,8 @@ void SoftGPU::Execute_Spline(u32 op, u32 diff) { const void *control_points = Memory::GetPointerUnchecked(gstate_c.vertexAddr); const void *indices = NULL; - if ((gstate.vertType & GE_VTYPE_IDX_MASK) != GE_VTYPE_IDX_NONE) { + const u32 vertType = gstate.vertType; + if ((vertType & GE_VTYPE_IDX_MASK) != GE_VTYPE_IDX_NONE) { if (!Memory::IsValidAddress(gstate_c.indexAddr)) { ERROR_LOG_REPORT(Log::G3D, "Bad index address %08x!", gstate_c.indexAddr); return; @@ -949,8 +953,8 @@ void SoftGPU::Execute_Spline(u32 op, u32 diff) { indices = Memory::GetPointerUnchecked(gstate_c.indexAddr); } - if ((gstate.vertType & GE_VTYPE_MORPHCOUNT_MASK) || vertTypeIsSkinningEnabled(gstate.vertType)) { - DEBUG_LOG_REPORT(Log::G3D, "Unusual bezier/spline vtype: %08x, morph: %d, bones: %d", gstate.vertType, (gstate.vertType & GE_VTYPE_MORPHCOUNT_MASK) >> GE_VTYPE_MORPHCOUNT_SHIFT, vertTypeGetNumBoneWeights(gstate.vertType)); + if ((vertType & GE_VTYPE_MORPHCOUNT_MASK) || vertTypeIsSkinningEnabled(vertType)) { + DEBUG_LOG_REPORT(Log::G3D, "Unusual bezier/spline vtype: %08x, morph: %d, bones: %d", vertType, (vertType & GE_VTYPE_MORPHCOUNT_MASK) >> GE_VTYPE_MORPHCOUNT_SHIFT, vertTypeGetNumBoneWeights(vertType)); } Spline::SplineSurface surface; @@ -969,7 +973,7 @@ void SoftGPU::Execute_Spline(u32 op, u32 diff) { int bytesRead = 0; drawEngine_->transformUnit.SetDirty(dirtyFlags_); - drawEngineCommon_->SubmitCurve(control_points, indices, surface, gstate.vertType, &bytesRead, "spline"); + drawEngineCommon_->SubmitCurve(control_points, indices, surface, vertType, &bytesRead, "spline"); dirtyFlags_ = drawEngine_->transformUnit.GetDirty(); SoftGPUVRAMDirty mark = (gstate_c.skipDrawReason & SKIPDRAW_SKIPFRAME) != 0 ? SoftGPUVRAMDirty::DIRTY : SoftGPUVRAMDirty::DIRTY | SoftGPUVRAMDirty::REALLY_DIRTY; @@ -977,7 +981,7 @@ void SoftGPU::Execute_Spline(u32 op, u32 diff) { // After drawing, we advance pointers - see SubmitPrim which does the same. int count = surface.num_points_u * surface.num_points_v; - AdvanceVerts(gstate.vertType, count, bytesRead); + gstate_c.AdvanceVerts(vertType, count, bytesRead); } void SoftGPU::Execute_LoadClut(u32 op, u32 diff) {