From 6367d5dc8ffc773a5b36219146ab5d16a65651b5 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 8 Jan 2022 20:53:01 -0800 Subject: [PATCH 1/2] softgpu: Draw top left of rectangles first. This helps when things do self-rendering, since this way we won't read from things we've just written to when scaling down. See #11623. --- GPU/Software/Clipper.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/GPU/Software/Clipper.cpp b/GPU/Software/Clipper.cpp index 0fc8053e52..70fa09066f 100644 --- a/GPU/Software/Clipper.cpp +++ b/GPU/Software/Clipper.cpp @@ -244,10 +244,10 @@ void ProcessRect(const VertexData& v0, const VertexData& v1) Rasterizer::ClearRectangle(v0, v1); } else { // Four triangles to do backfaces as well. Two of them will get backface culled. - Rasterizer::DrawTriangle(*topleft, *topright, *bottomright); - Rasterizer::DrawTriangle(*bottomright, *topright, *topleft); - Rasterizer::DrawTriangle(*bottomright, *bottomleft, *topleft); - Rasterizer::DrawTriangle(*topleft, *bottomleft, *bottomright); + Rasterizer::DrawTriangle(*topleft, *topright, *bottomleft); + Rasterizer::DrawTriangle(*bottomleft, *topright, *topleft); + Rasterizer::DrawTriangle(*topright, *bottomright, *bottomleft); + Rasterizer::DrawTriangle(*bottomleft, *bottomright, *topright); } } } From 88ef2d1ac186d74bc41d1103a788493d3654c32b Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 8 Jan 2022 21:05:08 -0800 Subject: [PATCH 2/2] softgpu: Skip threading when rendering to self. This will probably always be a problem to thread. --- GPU/Software/Rasterizer.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/GPU/Software/Rasterizer.cpp b/GPU/Software/Rasterizer.cpp index a8ca4ce89e..34046823a9 100644 --- a/GPU/Software/Rasterizer.cpp +++ b/GPU/Software/Rasterizer.cpp @@ -961,14 +961,21 @@ void DrawTriangle(const VertexData& v0, const VertexData& v1, const VertexData& const int MIN_LINES_PER_THREAD = 4; - if (rangeY >= 12 && rangeX >= rangeY * 4) { + const uint32_t renderTarget = gstate.getFrameBufAddress() & 0x0FFFFFFF; + bool selfRender = (gstate.getTextureAddress(0) & 0x0FFFFFFF) == renderTarget; + if (gstate.isMipmapEnabled()) { + for (int i = 0; i <= gstate.getTextureMaxLevel(); ++i) + selfRender = selfRender || (gstate.getTextureAddress(i) & 0x0FFFFFFF) == renderTarget; + } + + if (rangeY >= 12 && rangeX >= rangeY * 4 && !selfRender) { auto bound = [&](int a, int b) -> void { int x1 = minX + a * 16 * 2; int x2 = std::min(maxX, minX + b * 16 * 2 - 1); drawSlice(v0, v1, v2, x1, minY, x2, maxY, pixelID, drawPixel, sampler); }; ParallelRangeLoop(&g_threadManager, bound, 0, rangeX, MIN_LINES_PER_THREAD); - } else if (rangeY >= 12 && rangeX >= 12) { + } else if (rangeY >= 12 && rangeX >= 12 && !selfRender) { auto bound = [&](int a, int b) -> void { int y1 = minY + a * 16 * 2; int y2 = std::min(maxY, minY + b * 16 * 2 - 1);