From 6004d4a4596106056d1fbccfe00f66fa2348a2cb Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 10 Sep 2022 13:28:35 -0700 Subject: [PATCH] softgpu: Refactor duplicate rectangle compat check. This just moves the logic to a single place for changes. --- GPU/Software/RasterizerRectangle.cpp | 52 ++++++++++++---------------- GPU/Software/SoftGpu.cpp | 2 +- 2 files changed, 23 insertions(+), 31 deletions(-) diff --git a/GPU/Software/RasterizerRectangle.cpp b/GPU/Software/RasterizerRectangle.cpp index f25be97f64..7408b1558b 100644 --- a/GPU/Software/RasterizerRectangle.cpp +++ b/GPU/Software/RasterizerRectangle.cpp @@ -321,26 +321,32 @@ bool RectangleFastPath(const VertexData &v0, const VertexData &v1, BinManager &b return false; } +static bool AreCoordsRectangleCompatible(const RasterizerState &state, const VertexData &data0, const VertexData &data1) { + if (!(data1.color0 == data0.color0)) + return false; + if (!(data1.screenpos.z == data0.screenpos.z)) { + // Sometimes, we don't actually care about z. + if (state.pixelID.depthWrite || state.pixelID.DepthTestFunc() != GE_COMP_ALWAYS) + return false; + } + if (!state.throughMode) { + if (!state.throughMode && !(data1.color1 == data0.color1)) + return false; + // Do we have to think about perspective correction or slope mip level? + if (state.enableTextures && data1.clippos.w != data0.clippos.w) + return false; + if (state.pixelID.applyFog && data1.fogdepth != data0.fogdepth) + return false; + } + return true; +} + bool DetectRectangleFromStrip(const RasterizerState &state, const VertexData data[4], int *tlIndex, int *brIndex) { // Color and Z must be flat. Also find the TL and BR meanwhile. int tl = 0, br = 0; for (int i = 1; i < 4; ++i) { - if (!(data[i].color0 == data[0].color0)) + if (!AreCoordsRectangleCompatible(state, data[i], data[0])) return false; - if (!(data[i].screenpos.z == data[0].screenpos.z)) { - // Sometimes, we don't actually care about z. - if (state.pixelID.depthWrite || state.pixelID.DepthTestFunc() != GE_COMP_ALWAYS) - return false; - } - if (!state.throughMode) { - if (!state.throughMode && !(data[i].color1 == data[0].color1)) - return false; - // Do we have to think about perspective correction or slope mip level? - if (state.enableTextures && data[i].clippos.w != data[0].clippos.w) - return false; - if (state.pixelID.applyFog && data[i].fogdepth != data[0].fogdepth) - return false; - } if (data[i].screenpos.x <= data[tl].screenpos.x && data[i].screenpos.y <= data[tl].screenpos.y) tl = i; @@ -394,22 +400,8 @@ bool DetectRectangleFromStrip(const RasterizerState &state, const VertexData dat bool DetectRectangleFromFan(const RasterizerState &state, const VertexData *data, int c, int *tlIndex, int *brIndex) { // Color and Z must be flat. for (int i = 1; i < c; ++i) { - if (!(data[i].color0 == data[0].color0)) + if (!AreCoordsRectangleCompatible(state, data[i], data[0])) return false; - if (!(data[i].screenpos.z == data[0].screenpos.z)) { - // Sometimes, we don't actually care about z. - if (state.pixelID.depthWrite || state.pixelID.DepthTestFunc() != GE_COMP_ALWAYS) - return false; - } - if (!state.throughMode) { - if (!state.throughMode && !(data[i].color1 == data[0].color1)) - return false; - // Do we have to think about perspective correction or slope mip level? - if (state.enableTextures && data[i].clippos.w != data[0].clippos.w) - return false; - if (state.pixelID.applyFog && data[i].fogdepth != data[0].fogdepth) - return false; - } } // Check for the common case: a single TL-TR-BR-BL. diff --git a/GPU/Software/SoftGpu.cpp b/GPU/Software/SoftGpu.cpp index a6fc160af3..18cdb0b314 100644 --- a/GPU/Software/SoftGpu.cpp +++ b/GPU/Software/SoftGpu.cpp @@ -838,7 +838,7 @@ void SoftGPU::Execute_Prim(u32 op, u32 diff) { return; } - const void *verts = Memory::GetPointer(gstate_c.vertexAddr); + const void *verts = Memory::GetPointerUnchecked(gstate_c.vertexAddr); const void *indices = NULL; if ((gstate.vertType & GE_VTYPE_IDX_MASK) != GE_VTYPE_IDX_NONE) { if (!Memory::IsValidAddress(gstate_c.indexAddr)) {