diff --git a/src/GPU3D_Soft.cpp b/src/GPU3D_Soft.cpp index 04544b84..4aaf00ea 100644 --- a/src/GPU3D_Soft.cpp +++ b/src/GPU3D_Soft.cpp @@ -112,10 +112,9 @@ void SoftRenderer::SetThreaded(bool threaded) noexcept } } -template -bool SoftRenderer::DoTimings(s32 cycles) +bool SoftRenderer::DoTimings(s32 cycles, bool odd) { - if constexpr (odd) + if (odd) { RasterTimingCounterOdd += cycles; if ((RasterTimingCounterOdd + RasterTimingCounterPrev) < RasterTimingCap) return false; @@ -130,10 +129,9 @@ bool SoftRenderer::DoTimings(s32 cycles) return true; } -template -void SoftRenderer::EndScanline() +void SoftRenderer::EndScanline(bool odd) { - if constexpr (!odd) + if (!odd) { RasterTimingCounterPrev += std::max(RasterTimingCounterOdd, RasterTimingCounterEven); RasterTimingCounterPrev -= PerScanlineRecup; // wip @@ -962,8 +960,7 @@ void SoftRenderer::RenderShadowMaskScanline(RendererPolygon* rp, s32 y) rp->XR = rp->SlopeR.Step(); } -template -bool SoftRenderer::RenderPolygonScanline(RendererPolygon* rp, s32 y) +bool SoftRenderer::RenderPolygonScanline(RendererPolygon* rp, s32 y, bool odd) { Polygon* polygon = rp->PolyData; u32 polyattr = (polygon->Attr & 0x3F008000); @@ -984,7 +981,7 @@ bool SoftRenderer::RenderPolygonScanline(RendererPolygon* rp, s32 y) CheckSlope(rp, y); - if (DoTimings(PerPolyTiming)) return Step(rp, true); + if (DoTimings(PerPolyTiming, odd)) return Step(rp, true); Vertex *vlcur, *vlnext, *vrcur, *vrnext; s32 xstart, xend; @@ -1133,7 +1130,7 @@ bool SoftRenderer::RenderPolygonScanline(RendererPolygon* rp, s32 y) for (; x < xlimit; x++) { - if (pixelsrendered >= 4 && DoTimings(PerPixelTiming)) return Step(rp, true); + if (pixelsrendered >= 4 && DoTimings(PerPixelTiming, odd)) return Step(rp, true); pixelsrendered++; if (!l_filledge) continue; @@ -1232,7 +1229,7 @@ bool SoftRenderer::RenderPolygonScanline(RendererPolygon* rp, s32 y) for (; x < xlimit; x++) { - if (pixelsrendered >= 4 && DoTimings(PerPixelTiming)) return Step(rp, true); + if (pixelsrendered >= 4 && DoTimings(PerPixelTiming, odd)) return Step(rp, true); pixelsrendered++; if (wireframe && !edge) continue; @@ -1328,7 +1325,7 @@ bool SoftRenderer::RenderPolygonScanline(RendererPolygon* rp, s32 y) //if (rp->SlopeR.Increment != 0 && DoTimings(PerRightSlope, odd)) return Step(rp, true); // should be fine to not immediately return? might be wrong for (; x < xlimit; x++) { - if (pixelsrendered >= 4 && DoTimings(PerPixelTiming)) return Step(rp, true); + if (pixelsrendered >= 4 && DoTimings(PerPixelTiming, odd)) return Step(rp, true); pixelsrendered++; if (!r_filledge) continue; @@ -1421,8 +1418,7 @@ bool SoftRenderer::RenderPolygonScanline(RendererPolygon* rp, s32 y) return Step(rp, false); } -template -bool SoftRenderer::RenderScanline(s32 y, int npolys) +bool SoftRenderer::RenderScanline(s32 y, int npolys, bool odd) { bool abort = false; for (int i = 0; i < npolys; i++) @@ -1437,19 +1433,19 @@ bool SoftRenderer::RenderScanline(s32 y, int npolys) } else if (y == polygon->YBottom && y != polygon->YTop) { - if (DoTimings(EmptyPolyScanline)) abort = true; + if (DoTimings(EmptyPolyScanline, odd)) abort = true; } else if (y >= polygon->YTop && (y < polygon->YBottom || (y == polygon->YTop && polygon->YBottom == polygon->YTop))) { if (polygon->IsShadowMask) ;//RenderShadowMaskScanline(rp, y); else - if (RenderPolygonScanline(rp, y)) abort = true; + if (RenderPolygonScanline(rp, y, odd)) abort = true; } } BufferOffset = (BufferOffset + 1) & 0x7; // loop if == 8 - EndScanline(); + EndScanline(odd); return abort; } @@ -1492,14 +1488,13 @@ u32 SoftRenderer::CalculateFogDensity(u32 pixeladdr) return density; } -template -void SoftRenderer::ScanlineFinalPass(s32 y, u8 rdbufferoffset, bool late) +void SoftRenderer::ScanlineFinalPass(s32 y, u8 rdbufferoffset, bool late, bool odd, bool finish) { // to consider: // clearing all polygon fog flags if the master flag isn't set? // merging all final pass loops into one? u8 tempoffset; - if constexpr (finish) + if (finish) tempoffset = (BufferOffset - 2 + (!odd)); else tempoffset = (BufferOffset - 4 + (!odd)); @@ -1761,8 +1756,8 @@ void SoftRenderer::RenderPolygons(bool threaded, Polygon** polygons, int npolys) for (u8 bufferline = 0; bufferline < 48; bufferline += 2) { ClearBuffers(y); - latebuffer[y] = RenderScanline(y, j); - latebuffer[y+1] = RenderScanline(y+1, j); + latebuffer[y] = RenderScanline(y, j, true); + latebuffer[y+1] = RenderScanline(y+1, j, false); if (prevbufferline >= 0) @@ -1771,8 +1766,8 @@ void SoftRenderer::RenderPolygons(bool threaded, Polygon** polygons, int npolys) if (!latebuffer[y-1]) latebuffer[y+1] = false; - ScanlineFinalPass(y-2, prevbufferline, latebuffer[y-2]); - ScanlineFinalPass(y-1, prevbufferline+1, latebuffer[y-1]); + ScanlineFinalPass(y-2, prevbufferline, latebuffer[y-2], true, false); + ScanlineFinalPass(y-1, prevbufferline+1, latebuffer[y-1], false, false); } y += 2; @@ -1782,8 +1777,8 @@ void SoftRenderer::RenderPolygons(bool threaded, Polygon** polygons, int npolys) Platform::Semaphore_Post(Sema_ScanlineCount); } - ScanlineFinalPass(190, prevbufferline, latebuffer[190]); - ScanlineFinalPass(191, prevbufferline+1, latebuffer[191]); + ScanlineFinalPass(190, prevbufferline, latebuffer[190], true, true); + ScanlineFinalPass(191, prevbufferline+1, latebuffer[191], false, true); if (threaded) Platform::Semaphore_Post(Sema_ScanlineCount); diff --git a/src/GPU3D_Soft.h b/src/GPU3D_Soft.h index aac79076..d9b925f3 100644 --- a/src/GPU3D_Soft.h +++ b/src/GPU3D_Soft.h @@ -454,8 +454,8 @@ private: melonDS::GPU& GPU; RendererPolygon PolygonList[2048]; - template bool DoTimings(s32 cycles); - template void EndScanline(); + bool DoTimings(s32 cycles, bool odd); + void EndScanline(bool odd); void TextureLookup(u32 texparam, u32 texpal, s16 s, s16 t, u16* color, u8* alpha); u32 RenderPixel(Polygon* polygon, u8 vr, u8 vg, u8 vb, s16 s, s16 t); void PlotTranslucentPixel(u32 pixeladdr, u32 color, u32 z, u32 polyattr, u32 shadow); @@ -465,10 +465,10 @@ private: bool Step(RendererPolygon* rp, bool abortscanline); void CheckSlope(RendererPolygon* rp, s32 y); void RenderShadowMaskScanline(RendererPolygon* rp, s32 y); - template bool RenderPolygonScanline(RendererPolygon* rp, s32 y); - template bool RenderScanline(s32 y, int npolys); + bool RenderPolygonScanline(RendererPolygon* rp, s32 y, bool odd); + bool RenderScanline(s32 y, int npolys, bool odd); u32 CalculateFogDensity(u32 pixeladdr); - template void ScanlineFinalPass(s32 y, u8 rdbufferoffset, bool late); + void ScanlineFinalPass(s32 y, u8 rdbufferoffset, bool late, bool odd, bool finish); void ClearBuffers(s32 y); void RenderPolygons(bool threaded, Polygon** polygons, int npolys);