From 259b10d42a516c1dc9da1e4a4e957991e6eccae2 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 12 Feb 2022 00:03:40 -0800 Subject: [PATCH] softgpu: Turn more tri strips into rects. This catches a common case in Valkyrie Profile. Rotation is resolved by just always using tl/br. --- GPU/Software/RasterizerRectangle.cpp | 41 ++++++++++++++-------------- GPU/Software/RasterizerRectangle.h | 2 +- GPU/Software/TransformUnit.cpp | 5 ++-- 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/GPU/Software/RasterizerRectangle.cpp b/GPU/Software/RasterizerRectangle.cpp index e45f789162..ae9e920ff0 100644 --- a/GPU/Software/RasterizerRectangle.cpp +++ b/GPU/Software/RasterizerRectangle.cpp @@ -306,8 +306,9 @@ bool RectangleFastPath(const VertexData &v0, const VertexData &v1, BinManager &b return false; } -bool DetectRectangleFromThroughModeStrip(const RasterizerState &state, const VertexData data[4]) { - // Color and Z must be flat. +bool DetectRectangleFromThroughModeStrip(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)) return false; @@ -316,26 +317,30 @@ bool DetectRectangleFromThroughModeStrip(const RasterizerState &state, const Ver if (state.pixelID.depthWrite || state.pixelID.DepthTestFunc() != GE_COMP_ALWAYS) return false; } + + if (data[i].screenpos.x <= data[tl].screenpos.x && data[i].screenpos.y <= data[tl].screenpos.y) + tl = i; + if (data[i].screenpos.x >= data[br].screenpos.x && data[i].screenpos.y >= data[br].screenpos.y) + br = i; } + *tlIndex = tl; + *brIndex = br; + // OK, now let's look at data to detect rectangles. There are a few possibilities // but we focus on Darkstalkers for now. if (data[0].screenpos.x == data[1].screenpos.x && data[0].screenpos.y == data[2].screenpos.y && data[2].screenpos.x == data[3].screenpos.x && - data[1].screenpos.y == data[3].screenpos.y && - data[1].screenpos.y > data[0].screenpos.y && - data[2].screenpos.x > data[0].screenpos.x) { - // Okay, this is in the shape of a triangle, but what about rotation/texture? - if (!gstate.isTextureMapEnabled()) + data[1].screenpos.y == data[3].screenpos.y) { + // Okay, this is in the shape of a rectangle, but what about texture? + if (!state.enableTextures) return true; if (data[0].texturecoords.x == data[1].texturecoords.x && data[0].texturecoords.y == data[2].texturecoords.y && data[2].texturecoords.x == data[3].texturecoords.x && - data[1].texturecoords.y == data[3].texturecoords.y && - data[1].texturecoords.y > data[0].texturecoords.y && - data[2].texturecoords.x > data[0].texturecoords.x) { + data[1].texturecoords.y == data[3].texturecoords.y) { // It's a rectangle! return true; } @@ -345,19 +350,15 @@ bool DetectRectangleFromThroughModeStrip(const RasterizerState &state, const Ver if (data[0].screenpos.x == data[2].screenpos.x && data[0].screenpos.y == data[1].screenpos.y && data[1].screenpos.x == data[3].screenpos.x && - data[2].screenpos.y == data[3].screenpos.y && - data[2].screenpos.y > data[0].screenpos.y && - data[1].screenpos.x > data[0].screenpos.x) { - // Okay, this is in the shape of a triangle, but what about rotation/texture? - if (!gstate.isTextureMapEnabled()) + data[2].screenpos.y == data[3].screenpos.y) { + // Okay, this is in the shape of a rectangle, but what about texture? + if (!state.enableTextures) return true; if (data[0].texturecoords.x == data[2].texturecoords.x && data[0].texturecoords.y == data[1].texturecoords.y && data[1].texturecoords.x == data[3].texturecoords.x && - data[2].texturecoords.y == data[3].texturecoords.y && - data[2].texturecoords.y > data[0].texturecoords.y && - data[1].texturecoords.x > data[0].texturecoords.x) { + data[2].texturecoords.y == data[3].texturecoords.y) { // It's a rectangle! return true; } @@ -393,7 +394,7 @@ bool DetectRectangleFromThroughModeFan(const RasterizerState &state, const Verte } // Do we need to think about rotation? - if (!gstate.isTextureMapEnabled()) + if (!state.enableTextures) return true; const auto &textl = data[*tlIndex].texturecoords, &textr = data[*tlIndex ^ 1].texturecoords; @@ -426,7 +427,7 @@ bool DetectRectangleSlices(const RasterizerState &state, const VertexData data[4 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()) + if (!state.enableTextures) return true; const auto &textl1 = data[0].texturecoords, &texbr1 = data[1].texturecoords; diff --git a/GPU/Software/RasterizerRectangle.h b/GPU/Software/RasterizerRectangle.h index 181f18e15b..8d94cff536 100644 --- a/GPU/Software/RasterizerRectangle.h +++ b/GPU/Software/RasterizerRectangle.h @@ -20,7 +20,7 @@ namespace Rasterizer { bool RectangleFastPath(const VertexData &v0, const VertexData &v1, BinManager &binner); void DrawSprite(const VertexData &v0, const VertexData &v1, const BinCoords &range, const RasterizerState &state); - bool DetectRectangleFromThroughModeStrip(const RasterizerState &state, const VertexData data[4]); + bool DetectRectangleFromThroughModeStrip(const RasterizerState &state, const VertexData data[4], int *tlIndex, int *brIndex); bool DetectRectangleFromThroughModeFan(const RasterizerState &state, const VertexData *data, int c, int *tlIndex, int *brIndex); bool DetectRectangleSlices(const RasterizerState &state, const VertexData data[4]); } diff --git a/GPU/Software/TransformUnit.cpp b/GPU/Software/TransformUnit.cpp index 3eadaaf047..6ea3060d7e 100644 --- a/GPU/Software/TransformUnit.cpp +++ b/GPU/Software/TransformUnit.cpp @@ -661,8 +661,9 @@ void TransformUnit::SubmitPrimitive(void* vertices, void* indices, GEPrimitiveTy } // If a strip is effectively a rectangle, draw it as such! - if (!outside_range_flag && Rasterizer::DetectRectangleFromThroughModeStrip(binner_->State(), data)) { - Clipper::ProcessRect(data[0], data[3], *binner_); + int tl = -1, br = -1; + if (!outside_range_flag && Rasterizer::DetectRectangleFromThroughModeStrip(binner_->State(), data, &tl, &br)) { + Clipper::ProcessRect(data[tl], data[br], *binner_); break; } }