mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2024-11-14 13:27:41 -07:00
dont use templates
bigger code <<< slower code
This commit is contained in:
parent
63a39b130e
commit
785fab024f
@ -112,10 +112,9 @@ void SoftRenderer::SetThreaded(bool threaded) noexcept
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <bool odd>
|
bool SoftRenderer::DoTimings(s32 cycles, bool odd)
|
||||||
bool SoftRenderer::DoTimings(s32 cycles)
|
|
||||||
{
|
{
|
||||||
if constexpr (odd)
|
if (odd)
|
||||||
{
|
{
|
||||||
RasterTimingCounterOdd += cycles;
|
RasterTimingCounterOdd += cycles;
|
||||||
if ((RasterTimingCounterOdd + RasterTimingCounterPrev) < RasterTimingCap) return false;
|
if ((RasterTimingCounterOdd + RasterTimingCounterPrev) < RasterTimingCap) return false;
|
||||||
@ -130,10 +129,9 @@ bool SoftRenderer::DoTimings(s32 cycles)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <bool odd>
|
void SoftRenderer::EndScanline(bool odd)
|
||||||
void SoftRenderer::EndScanline()
|
|
||||||
{
|
{
|
||||||
if constexpr (!odd)
|
if (!odd)
|
||||||
{
|
{
|
||||||
RasterTimingCounterPrev += std::max(RasterTimingCounterOdd, RasterTimingCounterEven);
|
RasterTimingCounterPrev += std::max(RasterTimingCounterOdd, RasterTimingCounterEven);
|
||||||
RasterTimingCounterPrev -= PerScanlineRecup; // wip
|
RasterTimingCounterPrev -= PerScanlineRecup; // wip
|
||||||
@ -962,8 +960,7 @@ void SoftRenderer::RenderShadowMaskScanline(RendererPolygon* rp, s32 y)
|
|||||||
rp->XR = rp->SlopeR.Step();
|
rp->XR = rp->SlopeR.Step();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <bool odd>
|
bool SoftRenderer::RenderPolygonScanline(RendererPolygon* rp, s32 y, bool odd)
|
||||||
bool SoftRenderer::RenderPolygonScanline(RendererPolygon* rp, s32 y)
|
|
||||||
{
|
{
|
||||||
Polygon* polygon = rp->PolyData;
|
Polygon* polygon = rp->PolyData;
|
||||||
u32 polyattr = (polygon->Attr & 0x3F008000);
|
u32 polyattr = (polygon->Attr & 0x3F008000);
|
||||||
@ -984,7 +981,7 @@ bool SoftRenderer::RenderPolygonScanline(RendererPolygon* rp, s32 y)
|
|||||||
|
|
||||||
CheckSlope(rp, y);
|
CheckSlope(rp, y);
|
||||||
|
|
||||||
if (DoTimings<odd>(PerPolyTiming)) return Step(rp, true);
|
if (DoTimings(PerPolyTiming, odd)) return Step(rp, true);
|
||||||
|
|
||||||
Vertex *vlcur, *vlnext, *vrcur, *vrnext;
|
Vertex *vlcur, *vlnext, *vrcur, *vrnext;
|
||||||
s32 xstart, xend;
|
s32 xstart, xend;
|
||||||
@ -1133,7 +1130,7 @@ bool SoftRenderer::RenderPolygonScanline(RendererPolygon* rp, s32 y)
|
|||||||
|
|
||||||
for (; x < xlimit; x++)
|
for (; x < xlimit; x++)
|
||||||
{
|
{
|
||||||
if (pixelsrendered >= 4 && DoTimings<odd>(PerPixelTiming)) return Step(rp, true);
|
if (pixelsrendered >= 4 && DoTimings(PerPixelTiming, odd)) return Step(rp, true);
|
||||||
pixelsrendered++;
|
pixelsrendered++;
|
||||||
|
|
||||||
if (!l_filledge) continue;
|
if (!l_filledge) continue;
|
||||||
@ -1232,7 +1229,7 @@ bool SoftRenderer::RenderPolygonScanline(RendererPolygon* rp, s32 y)
|
|||||||
|
|
||||||
for (; x < xlimit; x++)
|
for (; x < xlimit; x++)
|
||||||
{
|
{
|
||||||
if (pixelsrendered >= 4 && DoTimings<odd>(PerPixelTiming)) return Step(rp, true);
|
if (pixelsrendered >= 4 && DoTimings(PerPixelTiming, odd)) return Step(rp, true);
|
||||||
pixelsrendered++;
|
pixelsrendered++;
|
||||||
|
|
||||||
if (wireframe && !edge) continue;
|
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
|
//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++)
|
for (; x < xlimit; x++)
|
||||||
{
|
{
|
||||||
if (pixelsrendered >= 4 && DoTimings<odd>(PerPixelTiming)) return Step(rp, true);
|
if (pixelsrendered >= 4 && DoTimings(PerPixelTiming, odd)) return Step(rp, true);
|
||||||
pixelsrendered++;
|
pixelsrendered++;
|
||||||
|
|
||||||
if (!r_filledge) continue;
|
if (!r_filledge) continue;
|
||||||
@ -1421,8 +1418,7 @@ bool SoftRenderer::RenderPolygonScanline(RendererPolygon* rp, s32 y)
|
|||||||
return Step(rp, false);
|
return Step(rp, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <bool odd>
|
bool SoftRenderer::RenderScanline(s32 y, int npolys, bool odd)
|
||||||
bool SoftRenderer::RenderScanline(s32 y, int npolys)
|
|
||||||
{
|
{
|
||||||
bool abort = false;
|
bool abort = false;
|
||||||
for (int i = 0; i < npolys; i++)
|
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)
|
else if (y == polygon->YBottom && y != polygon->YTop)
|
||||||
{
|
{
|
||||||
if (DoTimings<odd>(EmptyPolyScanline)) abort = true;
|
if (DoTimings(EmptyPolyScanline, odd)) abort = true;
|
||||||
}
|
}
|
||||||
else if (y >= polygon->YTop && (y < polygon->YBottom || (y == polygon->YTop && polygon->YBottom == polygon->YTop)))
|
else if (y >= polygon->YTop && (y < polygon->YBottom || (y == polygon->YTop && polygon->YBottom == polygon->YTop)))
|
||||||
{
|
{
|
||||||
if (polygon->IsShadowMask)
|
if (polygon->IsShadowMask)
|
||||||
;//RenderShadowMaskScanline(rp, y);
|
;//RenderShadowMaskScanline(rp, y);
|
||||||
else
|
else
|
||||||
if (RenderPolygonScanline<odd>(rp, y)) abort = true;
|
if (RenderPolygonScanline(rp, y, odd)) abort = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BufferOffset = (BufferOffset + 1) & 0x7; // loop if == 8
|
BufferOffset = (BufferOffset + 1) & 0x7; // loop if == 8
|
||||||
EndScanline<odd>();
|
EndScanline(odd);
|
||||||
return abort;
|
return abort;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1492,14 +1488,13 @@ u32 SoftRenderer::CalculateFogDensity(u32 pixeladdr)
|
|||||||
return density;
|
return density;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<bool odd, bool finish>
|
void SoftRenderer::ScanlineFinalPass(s32 y, u8 rdbufferoffset, bool late, bool odd, bool finish)
|
||||||
void SoftRenderer::ScanlineFinalPass(s32 y, u8 rdbufferoffset, bool late)
|
|
||||||
{
|
{
|
||||||
// to consider:
|
// to consider:
|
||||||
// clearing all polygon fog flags if the master flag isn't set?
|
// clearing all polygon fog flags if the master flag isn't set?
|
||||||
// merging all final pass loops into one?
|
// merging all final pass loops into one?
|
||||||
u8 tempoffset;
|
u8 tempoffset;
|
||||||
if constexpr (finish)
|
if (finish)
|
||||||
tempoffset = (BufferOffset - 2 + (!odd));
|
tempoffset = (BufferOffset - 2 + (!odd));
|
||||||
else
|
else
|
||||||
tempoffset = (BufferOffset - 4 + (!odd));
|
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)
|
for (u8 bufferline = 0; bufferline < 48; bufferline += 2)
|
||||||
{
|
{
|
||||||
ClearBuffers(y);
|
ClearBuffers(y);
|
||||||
latebuffer[y] = RenderScanline<true>(y, j);
|
latebuffer[y] = RenderScanline(y, j, true);
|
||||||
latebuffer[y+1] = RenderScanline<false>(y+1, j);
|
latebuffer[y+1] = RenderScanline(y+1, j, false);
|
||||||
|
|
||||||
|
|
||||||
if (prevbufferline >= 0)
|
if (prevbufferline >= 0)
|
||||||
@ -1771,8 +1766,8 @@ void SoftRenderer::RenderPolygons(bool threaded, Polygon** polygons, int npolys)
|
|||||||
|
|
||||||
if (!latebuffer[y-1]) latebuffer[y+1] = false;
|
if (!latebuffer[y-1]) latebuffer[y+1] = false;
|
||||||
|
|
||||||
ScanlineFinalPass<true, false>(y-2, prevbufferline, latebuffer[y-2]);
|
ScanlineFinalPass(y-2, prevbufferline, latebuffer[y-2], true, false);
|
||||||
ScanlineFinalPass<false, false>(y-1, prevbufferline+1, latebuffer[y-1]);
|
ScanlineFinalPass(y-1, prevbufferline+1, latebuffer[y-1], false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
y += 2;
|
y += 2;
|
||||||
@ -1782,8 +1777,8 @@ void SoftRenderer::RenderPolygons(bool threaded, Polygon** polygons, int npolys)
|
|||||||
Platform::Semaphore_Post(Sema_ScanlineCount);
|
Platform::Semaphore_Post(Sema_ScanlineCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
ScanlineFinalPass<true, true>(190, prevbufferline, latebuffer[190]);
|
ScanlineFinalPass(190, prevbufferline, latebuffer[190], true, true);
|
||||||
ScanlineFinalPass<false, true>(191, prevbufferline+1, latebuffer[191]);
|
ScanlineFinalPass(191, prevbufferline+1, latebuffer[191], false, true);
|
||||||
|
|
||||||
if (threaded)
|
if (threaded)
|
||||||
Platform::Semaphore_Post(Sema_ScanlineCount);
|
Platform::Semaphore_Post(Sema_ScanlineCount);
|
||||||
|
@ -454,8 +454,8 @@ private:
|
|||||||
|
|
||||||
melonDS::GPU& GPU;
|
melonDS::GPU& GPU;
|
||||||
RendererPolygon PolygonList[2048];
|
RendererPolygon PolygonList[2048];
|
||||||
template <bool odd> bool DoTimings(s32 cycles);
|
bool DoTimings(s32 cycles, bool odd);
|
||||||
template <bool odd> void EndScanline();
|
void EndScanline(bool odd);
|
||||||
void TextureLookup(u32 texparam, u32 texpal, s16 s, s16 t, u16* color, u8* alpha);
|
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);
|
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);
|
void PlotTranslucentPixel(u32 pixeladdr, u32 color, u32 z, u32 polyattr, u32 shadow);
|
||||||
@ -465,10 +465,10 @@ private:
|
|||||||
bool Step(RendererPolygon* rp, bool abortscanline);
|
bool Step(RendererPolygon* rp, bool abortscanline);
|
||||||
void CheckSlope(RendererPolygon* rp, s32 y);
|
void CheckSlope(RendererPolygon* rp, s32 y);
|
||||||
void RenderShadowMaskScanline(RendererPolygon* rp, s32 y);
|
void RenderShadowMaskScanline(RendererPolygon* rp, s32 y);
|
||||||
template <bool odd> bool RenderPolygonScanline(RendererPolygon* rp, s32 y);
|
bool RenderPolygonScanline(RendererPolygon* rp, s32 y, bool odd);
|
||||||
template <bool odd> bool RenderScanline(s32 y, int npolys);
|
bool RenderScanline(s32 y, int npolys, bool odd);
|
||||||
u32 CalculateFogDensity(u32 pixeladdr);
|
u32 CalculateFogDensity(u32 pixeladdr);
|
||||||
template<bool odd, bool finish> 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 ClearBuffers(s32 y);
|
||||||
void RenderPolygons(bool threaded, Polygon** polygons, int npolys);
|
void RenderPolygons(bool threaded, Polygon** polygons, int npolys);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user