From e95b2cf0d5920a0df2d28d27800d10c47266c9f2 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 10 Apr 2016 13:07:08 -0700 Subject: [PATCH] Reduce some repetitive code. --- GPU/Directx9/GPU_DX9.cpp | 22 ++-------------------- GPU/GLES/GPU_GLES.cpp | 22 ++-------------------- GPU/GPUCommon.cpp | 13 +++++++++++++ GPU/GPUCommon.h | 2 ++ GPU/Software/SoftGpu.cpp | 11 +---------- GPU/Vulkan/GPU_Vulkan.cpp | 22 ++-------------------- 6 files changed, 22 insertions(+), 70 deletions(-) diff --git a/GPU/Directx9/GPU_DX9.cpp b/GPU/Directx9/GPU_DX9.cpp index 86928f1023..be499769ca 100644 --- a/GPU/Directx9/GPU_DX9.cpp +++ b/GPU/Directx9/GPU_DX9.cpp @@ -836,16 +836,7 @@ void GPU_DX9::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. - if (inds) { - int indexSize = 1; - if ((vertexType & GE_VTYPE_IDX_MASK) == GE_VTYPE_IDX_16BIT) - indexSize = 2; - else if ((vertexType & GE_VTYPE_IDX_MASK) == GE_VTYPE_IDX_32BIT) - indexSize = 4; - gstate_c.indexAddr += count * indexSize; - } else { - gstate_c.vertexAddr += bytesRead; - } + AdvanceVerts(vertexType, count, bytesRead); } void GPU_DX9::Execute_Bezier(u32 op, u32 diff) { @@ -888,16 +879,7 @@ void GPU_DX9::Execute_Bezier(u32 op, u32 diff) { // After drawing, we advance pointers - see SubmitPrim which does the same. int count = bz_ucount * bz_vcount; - if ((gstate.vertType & GE_VTYPE_IDX_MASK) != 0) { - int indexSize = 1; - if ((gstate.vertType & GE_VTYPE_IDX_MASK) == GE_VTYPE_IDX_16BIT) - indexSize = 2; - else if ((gstate.vertType & GE_VTYPE_IDX_MASK) == GE_VTYPE_IDX_32BIT) - indexSize = 4; - gstate_c.indexAddr += count * indexSize; - } else { - gstate_c.vertexAddr += bytesRead; - } + AdvanceVerts(gstate.vertType, count, bytesRead); } void GPU_DX9::Execute_Spline(u32 op, u32 diff) { diff --git a/GPU/GLES/GPU_GLES.cpp b/GPU/GLES/GPU_GLES.cpp index a84d80568d..e70db2434b 100644 --- a/GPU/GLES/GPU_GLES.cpp +++ b/GPU/GLES/GPU_GLES.cpp @@ -1005,16 +1005,7 @@ void GPU_GLES::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. - if (inds) { - int indexSize = 1; - if ((gstate.vertType & GE_VTYPE_IDX_MASK) == GE_VTYPE_IDX_16BIT) - indexSize = 2; - else if ((gstate.vertType & GE_VTYPE_IDX_MASK) == GE_VTYPE_IDX_32BIT) - indexSize = 4; - gstate_c.indexAddr += count * indexSize; - } else { - gstate_c.vertexAddr += bytesRead; - } + AdvanceVerts(gstate.vertType, count, bytesRead); } void GPU_GLES::Execute_VertexType(u32 op, u32 diff) { @@ -1081,16 +1072,7 @@ void GPU_GLES::Execute_Bezier(u32 op, u32 diff) { // After drawing, we advance pointers - see SubmitPrim which does the same. int count = bz_ucount * bz_vcount; - if ((gstate.vertType & GE_VTYPE_IDX_MASK) != 0) { - int indexSize = 1; - if ((gstate.vertType & GE_VTYPE_IDX_MASK) == GE_VTYPE_IDX_16BIT) - indexSize = 2; - else if ((gstate.vertType & GE_VTYPE_IDX_MASK) == GE_VTYPE_IDX_32BIT) - indexSize = 4; - gstate_c.indexAddr += count * indexSize; - } else { - gstate_c.vertexAddr += bytesRead; - } + AdvanceVerts(gstate.vertType, count, bytesRead); } void GPU_GLES::Execute_Spline(u32 op, u32 diff) { diff --git a/GPU/GPUCommon.cpp b/GPU/GPUCommon.cpp index 3bec703e06..9436393efe 100644 --- a/GPU/GPUCommon.cpp +++ b/GPU/GPUCommon.cpp @@ -1299,3 +1299,16 @@ void GPUCommon::SetCmdValue(u32 op) { gstate.cmdmem[cmd] = op; ExecuteOp(op, diff); } + +void GPUCommon::AdvanceVerts(u32 vertType, int count, int bytesRead) { + if ((vertType & GE_VTYPE_IDX_MASK) != GE_VTYPE_IDX_NONE) { + int indexSize = 1; + if ((vertType & GE_VTYPE_IDX_MASK) == GE_VTYPE_IDX_16BIT) + indexSize = 2; + else if ((vertType & GE_VTYPE_IDX_MASK) == GE_VTYPE_IDX_32BIT) + indexSize = 4; + gstate_c.indexAddr += count * indexSize; + } else { + gstate_c.vertexAddr += bytesRead; + } +} diff --git a/GPU/GPUCommon.h b/GPU/GPUCommon.h index 72abc7eefd..bec039e544 100644 --- a/GPU/GPUCommon.h +++ b/GPU/GPUCommon.h @@ -156,6 +156,8 @@ protected: virtual void FinishDeferred() { } + void AdvanceVerts(u32 vertType, int count, int bytesRead); + // Allows early unlocking with a guard. Do not double unlock. class easy_guard { public: diff --git a/GPU/Software/SoftGpu.cpp b/GPU/Software/SoftGpu.cpp index 0e4a1e212f..573871a632 100644 --- a/GPU/Software/SoftGpu.cpp +++ b/GPU/Software/SoftGpu.cpp @@ -332,16 +332,7 @@ void SoftGPU::ExecuteOp(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. - if (indices) { - int indexSize = 1; - if ((gstate.vertType & GE_VTYPE_IDX_MASK) == GE_VTYPE_IDX_16BIT) - indexSize = 2; - else if ((gstate.vertType & GE_VTYPE_IDX_MASK) == GE_VTYPE_IDX_32BIT) - indexSize = 4; - gstate_c.indexAddr += count * indexSize; - } else { - gstate_c.vertexAddr += bytesRead; - } + AdvanceVerts(gstate.vertType, count, bytesRead); } break; diff --git a/GPU/Vulkan/GPU_Vulkan.cpp b/GPU/Vulkan/GPU_Vulkan.cpp index 36312b4a4e..b5aa4109e7 100644 --- a/GPU/Vulkan/GPU_Vulkan.cpp +++ b/GPU/Vulkan/GPU_Vulkan.cpp @@ -880,16 +880,7 @@ void GPU_Vulkan::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. - if (inds) { - int indexSize = 1; - if ((gstate.vertType & GE_VTYPE_IDX_MASK) == GE_VTYPE_IDX_16BIT) - indexSize = 2; - else if ((gstate.vertType & GE_VTYPE_IDX_MASK) == GE_VTYPE_IDX_32BIT) - indexSize = 4; - gstate_c.indexAddr += count * indexSize; - } else { - gstate_c.vertexAddr += bytesRead; - } + AdvanceVerts(gstate.vertType, count, bytesRead); } void GPU_Vulkan::Execute_VertexType(u32 op, u32 diff) { @@ -938,16 +929,7 @@ void GPU_Vulkan::Execute_Bezier(u32 op, u32 diff) { // After drawing, we advance pointers - see SubmitPrim which does the same. int count = bz_ucount * bz_vcount; - if ((gstate.vertType & GE_VTYPE_IDX_MASK) != 0) { - int indexSize = 1; - if ((gstate.vertType & GE_VTYPE_IDX_MASK) == GE_VTYPE_IDX_16BIT) - indexSize = 2; - else if ((gstate.vertType & GE_VTYPE_IDX_MASK) == GE_VTYPE_IDX_32BIT) - indexSize = 4; - gstate_c.indexAddr += count * indexSize; - } else { - gstate_c.vertexAddr += bytesRead; - } + AdvanceVerts(gstate.vertType, count, bytesRead); } void GPU_Vulkan::Execute_Spline(u32 op, u32 diff) {