From 2ab7499d8dae3c997bc50438070bae96a5368ad0 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 14 Nov 2021 12:17:41 -0800 Subject: [PATCH] softgpu: Combine sliced rectangles. This mostly affects clears, and reduces overhead. Only about 2% improvement, but it's a small change. --- GPU/Software/RasterizerRectangle.cpp | 36 ++++++++++++++++++++++++++++ GPU/Software/RasterizerRectangle.h | 1 + GPU/Software/TransformUnit.cpp | 7 ++++++ 3 files changed, 44 insertions(+) diff --git a/GPU/Software/RasterizerRectangle.cpp b/GPU/Software/RasterizerRectangle.cpp index ef2438083a..055d4eee67 100644 --- a/GPU/Software/RasterizerRectangle.cpp +++ b/GPU/Software/RasterizerRectangle.cpp @@ -402,5 +402,41 @@ bool DetectRectangleFromThroughModeFan(const VertexData *data, int c, int *tlInd return false; } +bool DetectRectangleSlices(const VertexData data[4]) { + // Color and Z must be flat. + for (int i = 1; i < 4; ++i) { + if (!(data[i].color0 == data[0].color0)) + return false; + if (!(data[i].screenpos.z == data[0].screenpos.z)) + return false; + } + + // Games very commonly use vertical strips of rectangles. Detect and combine. + const auto &tl1 = data[0].screenpos, &br1 = data[1].screenpos; + const auto &tl2 = data[2].screenpos, &br2 = data[3].screenpos; + if (tl1.y == tl2.y && br1.y == br2.y && br1.y > tl1.y) { + if (br1.x == tl2.x && tl1.x < br1.x && tl2.x < br2.x) { + if (!gstate.isTextureMapEnabled() || gstate.isModeClear()) + return true; + + const auto &textl1 = data[0].texturecoords, &texbr1 = data[1].texturecoords; + const auto &textl2 = data[2].texturecoords, &texbr2 = data[3].texturecoords; + if (textl1.y != textl2.y || texbr1.y != texbr2.y || textl1.y > texbr1.y) + return false; + if (texbr1.x != textl2.x || textl1.x > texbr1.x || textl2.x > texbr2.x) + return false; + + // We might be able to compare ratios, but let's expect 1:1. + int texdiff1 = (texbr1.x - textl1.x) * 16.0f; + int texdiff2 = (texbr2.x - textl2.x) * 16.0f; + int posdiff1 = br1.x - tl1.x; + int posdiff2 = br2.x - tl2.x; + return texdiff1 == posdiff1 && texdiff2 == posdiff2; + } + } + + return false; +} + } // namespace Rasterizer diff --git a/GPU/Software/RasterizerRectangle.h b/GPU/Software/RasterizerRectangle.h index 2489e45d60..d6d08b597c 100644 --- a/GPU/Software/RasterizerRectangle.h +++ b/GPU/Software/RasterizerRectangle.h @@ -18,4 +18,5 @@ namespace Rasterizer { bool DetectRectangleFromThroughModeStrip(const VertexData data[4]); bool DetectRectangleFromThroughModeFan(const VertexData *data, int c, int *tlIndex, int *brIndex); + bool DetectRectangleSlices(const VertexData data[4]); } diff --git a/GPU/Software/TransformUnit.cpp b/GPU/Software/TransformUnit.cpp index b5bcf7d305..0f526c91ea 100644 --- a/GPU/Software/TransformUnit.cpp +++ b/GPU/Software/TransformUnit.cpp @@ -425,6 +425,13 @@ void TransformUnit::SubmitPrimitive(void* vertices, void* indices, GEPrimitiveTy } } + if (data_index == 4 && gstate.isModeThrough()) { + if (Rasterizer::DetectRectangleSlices(data)) { + data[1] = data[3]; + data_index = 2; + } + } + if (data_index == 4) { Clipper::ProcessRect(data[0], data[1]); Clipper::ProcessRect(data[2], data[3]);