From 520f7a0f3a18c82a230e951c64dd0231f6946025 Mon Sep 17 00:00:00 2001 From: Jaklyy <102590697+Jaklyy@users.noreply.github.com> Date: Fri, 19 Apr 2024 10:41:01 -0400 Subject: [PATCH] small optimization --- src/GPU3D_Soft.cpp | 34 ++++++++++++++++++---------------- src/GPU3D_Soft.h | 4 ++-- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/GPU3D_Soft.cpp b/src/GPU3D_Soft.cpp index da6acbc0..d707336b 100644 --- a/src/GPU3D_Soft.cpp +++ b/src/GPU3D_Soft.cpp @@ -174,7 +174,7 @@ u32 SoftRenderer::DoTimingsPixels(s32 pixels, s32* timingcounter) else return 0; } -void SoftRenderer::FindFirstPolyDoTimings(int npolys, s32 y, s32* timingcountereven, s32*timingcounterodd) +void SoftRenderer::FindFirstPolyDoTimings(int npolys, s32 y, int* firstpolyeven, int* firstpolyodd, s32* timingcountereven, s32*timingcounterodd) { // TODO: actually figure this out @@ -184,9 +184,9 @@ void SoftRenderer::FindFirstPolyDoTimings(int npolys, s32 y, s32* timingcountere bool perslope = false; bool etc = false; - for (int i = 0; i < npolys; i++) + for (*firstpolyeven = 0; *firstpolyeven < npolys; (*firstpolyeven)++) { - RendererPolygon* rp = &PolygonList[i]; + RendererPolygon* rp = &PolygonList[*firstpolyeven]; Polygon* polygon = rp->PolyData; if (y >= polygon->YTop && y <= polygon->YBottom) @@ -206,9 +206,9 @@ void SoftRenderer::FindFirstPolyDoTimings(int npolys, s32 y, s32* timingcountere } y++; - for (int i = 0; i < npolys; i++) + for (*firstpolyodd = 0; *firstpolyodd < npolys; (*firstpolyodd)++) { - RendererPolygon* rp = &PolygonList[i]; + RendererPolygon* rp = &PolygonList[*firstpolyodd]; Polygon* polygon = rp->PolyData; if (y >= polygon->YTop && y <= polygon->YBottom) @@ -1518,12 +1518,12 @@ bool SoftRenderer::RenderPolygonScanline(const GPU& gpu, RendererPolygon* rp, s3 } template -void SoftRenderer::RenderScanline(const GPU& gpu, s32 y, int npolys, s32* timingcounter) +void SoftRenderer::RenderScanline(const GPU& gpu, s32 y, int firstpoly, int npolys, s32* timingcounter) { bool abort = false; - for (int i = 0; i < npolys; i++) + for (; firstpoly < npolys; firstpoly++) { - RendererPolygon* rp = &PolygonList[i]; + RendererPolygon* rp = &PolygonList[firstpoly]; Polygon* polygon = rp->PolyData; if (accuracy && y == polygon->YBottom && y != polygon->YTop) @@ -1950,9 +1950,9 @@ void SoftRenderer::FinishPushScanline(s32 y, s32 pixelsremain) /* update sl timeout */\ ScanlineTimeout = SLRead[y-1] - FinalPassLen;\ \ - FindFirstPolyDoTimings(j, y, &rastertimingeven, &rastertimingodd);\ - RenderScanline(gpu, y, j, &rastertimingeven);\ - RenderScanline(gpu, y+1, j, &rastertimingodd);\ + FindFirstPolyDoTimings(j, y, &firstpolyeven, &firstpolyodd, &rastertimingeven, &rastertimingodd);\ + RenderScanline(gpu, y, firstpolyeven, j, &rastertimingeven);\ + RenderScanline(gpu, y+1, firstpolyodd, j, &rastertimingodd);\ \ prevtimespent = timespent;\ RasterTiming += timespent = std::max(std::initializer_list {rastertimingeven, rastertimingodd, FinalPassLen});\ @@ -1969,12 +1969,13 @@ void SoftRenderer::RenderPolygonsFast(GPU& gpu, Polygon** polygons, int npolys) if (polygons[i]->Degenerate) continue; SetupPolygon(&PolygonList[j++], polygons[i]); } + int dummy; - RenderScanline(gpu, 0, j, &dummy); + RenderScanline(gpu, 0, 0, j, &dummy); for (s32 y = 1; y < 192; y++) { - RenderScanline(gpu, y, j, &dummy); + RenderScanline(gpu, y, 0, j, &dummy); ScanlineFinalPass(gpu.GPU3D, y-1, true, true); } @@ -1998,11 +1999,12 @@ void SoftRenderer::RenderPolygonsTiming(GPU& gpu, Polygon** polygons, int npolys s32 scanlineswaiting = 0, slwaitingrd = 0; s32 nextread = 0, nextreadrd = 0; u32 timespent, prevtimespent; + int firstpolyeven, firstpolyodd; - FindFirstPolyDoTimings(j, 0, &rastertimingeven, &rastertimingodd); + FindFirstPolyDoTimings(j, 0, &firstpolyeven, &firstpolyodd, &rastertimingeven, &rastertimingodd); // scanlines are rendered in pairs of two - RenderScanline(gpu, 0, j, &rastertimingeven); - RenderScanline(gpu, 1, j, &rastertimingodd); + RenderScanline(gpu, 0, firstpolyeven, j, &rastertimingeven); + RenderScanline(gpu, 1, firstpolyodd, j, &rastertimingodd); // it can't proceed to the next scanline unless all others steps are done (both scanlines in the pair, and final pass) RasterTiming = timespent = std::max(std::initializer_list {rastertimingeven, rastertimingodd, FinalPassLen}); diff --git a/src/GPU3D_Soft.h b/src/GPU3D_Soft.h index a9a15787..0c4baf79 100644 --- a/src/GPU3D_Soft.h +++ b/src/GPU3D_Soft.h @@ -458,7 +458,7 @@ private: bool DoTimings(s32 cycles, s32* timingcounter); bool CheckTimings(s32 cycles, s32* timingcounter); u32 DoTimingsPixels(s32 pixels, s32* timingcounter); - void FindFirstPolyDoTimings(int npolys, s32 y, s32* timingcountereven, s32*timingcounterodd); + void FindFirstPolyDoTimings(int npolys, s32 y, int* firstpolyeven, int* firstpolyodd, s32* timingcountereven, s32*timingcounterodd); void TextureLookup(const GPU& gpu, u32 texparam, u32 texpal, s16 s, s16 t, u16* color, u8* alpha) const; u32 RenderPixel(const GPU& gpu, const Polygon* polygon, u8 vr, u8 vg, u8 vb, s16 s, s16 t) const; void PlotTranslucentPixel(const GPU3D& gpu3d, u32 pixeladdr, u32 color, u32 z, u32 polyattr, u32 shadow); @@ -469,7 +469,7 @@ private: void CheckSlope(RendererPolygon* rp, s32 y); template bool RenderShadowMaskScanline(const GPU3D& gpu3d, RendererPolygon* rp, s32 y, s32* timingcounter); template bool RenderPolygonScanline(const GPU& gpu, RendererPolygon* rp, s32 y, s32* timingcounter); - template void RenderScanline(const GPU& gpu, s32 y, int npolys, s32* timingcounter); + template void RenderScanline(const GPU& gpu, s32 y, int firstpoly, int npolys, s32* timingcounter); u32 CalculateFogDensity(const GPU3D& gpu3d, u32 pixeladdr) const; bool CheckEdgeMarkingPixel(u32 polyid, u32 z, u32 pixeladdr); bool CheckEdgeMarkingClearPlane(const GPU3D& gpu3d, u32 polyid, u32 z);