mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2024-11-14 13:27:41 -07:00
attempt at some cleanup
This commit is contained in:
parent
b32f519c5a
commit
e1cbadbe60
@ -1877,6 +1877,43 @@ void SoftRenderer::FinishPushScanline(s32 y, s32 pixelsremain)
|
|||||||
memcpy(&RDBuffer[bufferpos*ScanlineWidth], &ColorBuffer[y*ScanlineWidth], 4 * pixelsremain);
|
memcpy(&RDBuffer[bufferpos*ScanlineWidth], &ColorBuffer[y*ScanlineWidth], 4 * pixelsremain);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define RDLINES_COUNT_INCREMENT\
|
||||||
|
/* feels wrong, needs improvement */\
|
||||||
|
while (RasterTiming >= RDDecrement[nextreadrd])\
|
||||||
|
{\
|
||||||
|
slwaitingrd--;\
|
||||||
|
nextreadrd++;\
|
||||||
|
/* update rdlines_count register */\
|
||||||
|
if (gpu.GPU3D.RDLinesTemp > slwaitingrd) gpu.GPU3D.RDLinesTemp = slwaitingrd;\
|
||||||
|
}
|
||||||
|
|
||||||
|
#define SCANLINE_BUFFER_SIM\
|
||||||
|
/* simulate the process of scanlines being read from the 48 scanline buffer */\
|
||||||
|
while (scanlineswaiting >= 47 || RasterTiming >= SLRead[nextread] + Arbitrary)\
|
||||||
|
{\
|
||||||
|
if (RasterTiming < SLRead[nextread] + Arbitrary)\
|
||||||
|
{\
|
||||||
|
RasterTiming += timespent = (SLRead[nextread] + Arbitrary) - RasterTiming; /* why + 565? */\
|
||||||
|
timespent += EMFixNum; /* fixes edge marking bug emulation. not sure why this is needed? */\
|
||||||
|
}\
|
||||||
|
scanlineswaiting--;\
|
||||||
|
nextread++;\
|
||||||
|
}
|
||||||
|
|
||||||
|
#define RENDER_SCANLINES(y)\
|
||||||
|
/* update sl timeout */\
|
||||||
|
ScanlineTimeout = SLRead[y-1] - FinalPassLen;\
|
||||||
|
\
|
||||||
|
RenderScanline(gpu, y, j, &rastertimingeven);\
|
||||||
|
RenderScanline(gpu, y+1, j, &rastertimingodd);\
|
||||||
|
\
|
||||||
|
prevtimespent = timespent;\
|
||||||
|
RasterTiming += timespent = std::max(std::initializer_list<s32> {rastertimingeven, rastertimingodd, FinalPassLen});\
|
||||||
|
RasterTiming += std::clamp(ScanlineTimeout - RasterTiming, 0, 12);\
|
||||||
|
\
|
||||||
|
/* set the underflow flag if one of the scanlines came within 14 cycles of visible underflow */\
|
||||||
|
if (ScanlineTimeout <= RasterTiming) gpu.GPU3D.RDLinesUnderflow = true;
|
||||||
|
|
||||||
void SoftRenderer::RenderPolygons(GPU& gpu, Polygon** polygons, int npolys)
|
void SoftRenderer::RenderPolygons(GPU& gpu, Polygon** polygons, int npolys)
|
||||||
{
|
{
|
||||||
int j = 0;
|
int j = 0;
|
||||||
@ -1885,26 +1922,19 @@ void SoftRenderer::RenderPolygons(GPU& gpu, Polygon** polygons, int npolys)
|
|||||||
if (polygons[i]->Degenerate) continue;
|
if (polygons[i]->Degenerate) continue;
|
||||||
SetupPolygon(&PolygonList[j++], polygons[i]);
|
SetupPolygon(&PolygonList[j++], polygons[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
//init internal buffer
|
//init internal buffer
|
||||||
ClearBuffers(gpu);
|
ClearBuffers(gpu);
|
||||||
|
|
||||||
// reset scanline trackers
|
// reset scanline trackers
|
||||||
gpu.GPU3D.RDLinesUnderflow = false;
|
gpu.GPU3D.RDLinesUnderflow = false;
|
||||||
gpu.GPU3D.RDLinesTemp = 63;
|
gpu.GPU3D.RDLinesTemp = 63;
|
||||||
|
|
||||||
ScanlineTimeout = FrameLength; // CHECKME
|
ScanlineTimeout = FrameLength; // CHECKME
|
||||||
|
s32 rastertimingeven, rastertimingodd; // always init to 0 at the start of a scanline render
|
||||||
s32 rastertimingeven; // always init to 0 at the start of a scanline render
|
s32 scanlineswaiting = 0, slwaitingrd = 0;
|
||||||
s32 rastertimingodd;
|
s32 nextread = 0, nextreadrd = 0;
|
||||||
|
u32 timespent, prevtimespent;
|
||||||
|
|
||||||
s32 scanlineswaiting = 0;
|
|
||||||
s32 nextread = 0;
|
|
||||||
s32 slwaitingrd = 0;
|
|
||||||
s32 nextreadrd = 0;
|
|
||||||
|
|
||||||
u32 timespent;
|
|
||||||
u32 prevtimespent;
|
|
||||||
|
|
||||||
// scanlines are rendered in pairs of two
|
// scanlines are rendered in pairs of two
|
||||||
RenderScanline(gpu, 0, j, &rastertimingeven);
|
RenderScanline(gpu, 0, j, &rastertimingeven);
|
||||||
@ -1914,113 +1944,46 @@ void SoftRenderer::RenderPolygons(GPU& gpu, Polygon** polygons, int npolys)
|
|||||||
RasterTiming = timespent = std::max(std::initializer_list<s32> {rastertimingeven, rastertimingodd, FinalPassLen});
|
RasterTiming = timespent = std::max(std::initializer_list<s32> {rastertimingeven, rastertimingodd, FinalPassLen});
|
||||||
// 12 cycles at the end of a "timeout" are always used for w/e reason
|
// 12 cycles at the end of a "timeout" are always used for w/e reason
|
||||||
RasterTiming += std::clamp(ScanlineTimeout - RasterTiming, 0, 12);
|
RasterTiming += std::clamp(ScanlineTimeout - RasterTiming, 0, 12);
|
||||||
|
|
||||||
// if first pair was not delayed past the first read, then later scanlines cannot either
|
// if first pair was not delayed past the first read, then later scanlines cannot either
|
||||||
// this allows us to implement a fast path
|
// this allows us to implement a fast path
|
||||||
//if (SLRead[0] - timespent + ScanlinePushDelay >= 256)
|
//if (SLRead[0] - timespent + ScanlinePushDelay >= 256)
|
||||||
{
|
{
|
||||||
// begin scanline timeout
|
RENDER_SCANLINES(2)
|
||||||
ScanlineTimeout = SLRead[1] - FinalPassLen;
|
|
||||||
|
|
||||||
RenderScanline(gpu, 2, j, &rastertimingeven);
|
|
||||||
RenderScanline(gpu, 3, j, &rastertimingodd);
|
|
||||||
|
|
||||||
// the time spent on the previous scanline pair is important for emulating the edge marking bug properly
|
|
||||||
prevtimespent = timespent;
|
|
||||||
RasterTiming += timespent = std::max(std::initializer_list<s32> {rastertimingeven, rastertimingodd, FinalPassLen});
|
|
||||||
RasterTiming += std::clamp(ScanlineTimeout - RasterTiming, 0, 12);
|
|
||||||
|
|
||||||
// set the underflow flag if one of the scanlines came within 14 cycles of visible underflow
|
|
||||||
if (ScanlineTimeout <= RasterTiming) gpu.GPU3D.RDLinesUnderflow = true;
|
|
||||||
|
|
||||||
scanlineswaiting++;
|
scanlineswaiting++;
|
||||||
slwaitingrd++;
|
slwaitingrd++;
|
||||||
|
|
||||||
// simulate the process of scanlines being read from the 48 scanline buffer
|
|
||||||
while (RasterTiming >= SLRead[nextread] + Arbitrary)
|
|
||||||
{
|
|
||||||
if (RasterTiming < SLRead[nextread] + Arbitrary)
|
|
||||||
{
|
|
||||||
RasterTiming += timespent = (SLRead[nextread] + Arbitrary) - RasterTiming; // why + 565?
|
|
||||||
timespent += EMFixNum; // fixes edge marking bug emulation. not sure why this is needed?
|
|
||||||
}
|
|
||||||
scanlineswaiting--;
|
|
||||||
nextread++;
|
|
||||||
// update rdlines_count register
|
|
||||||
//if (gpu.GPU3D.RDLinesTemp > scanlineswaiting) gpu.GPU3D.RDLinesTemp = scanlineswaiting; // TODO: not accurate, rdlines appears to update early in some manner?
|
|
||||||
}
|
|
||||||
|
|
||||||
// feels wrong, needs improvement.
|
SCANLINE_BUFFER_SIM
|
||||||
while (RasterTiming >= RDDecrement[nextreadrd])
|
|
||||||
{
|
RDLINES_COUNT_INCREMENT
|
||||||
slwaitingrd--;
|
|
||||||
nextreadrd++;
|
|
||||||
// update rdlines_count register
|
|
||||||
if (gpu.GPU3D.RDLinesTemp > slwaitingrd) gpu.GPU3D.RDLinesTemp = slwaitingrd;
|
|
||||||
}
|
|
||||||
|
|
||||||
// final pass pairs are the previous scanline pair offset -1 scanline, thus we start with only building one
|
// final pass pairs are the previous scanline pair offset -1 scanline, thus we start with only building one
|
||||||
ScanlineFinalPass<true>(gpu.GPU3D, 0, true, timespent >= EMGlitchThreshhold);
|
ScanlineFinalPass<true>(gpu.GPU3D, 0, true, timespent >= EMGlitchThreshhold);
|
||||||
|
|
||||||
|
// main loop
|
||||||
for (int y = 4; y < 192; y+=2)
|
for (int y = 4; y < 192; y+=2)
|
||||||
{
|
{
|
||||||
//update sl timeout
|
RENDER_SCANLINES(y)
|
||||||
ScanlineTimeout = SLRead[y-1] - FinalPassLen;
|
|
||||||
|
|
||||||
RenderScanline(gpu, y, j, &rastertimingeven);
|
|
||||||
RenderScanline(gpu, y+1, j, &rastertimingodd);
|
|
||||||
|
|
||||||
prevtimespent = timespent;
|
|
||||||
RasterTiming += timespent = std::max(std::initializer_list<s32> {rastertimingeven, rastertimingodd, FinalPassLen});
|
|
||||||
RasterTiming += std::clamp(ScanlineTimeout - RasterTiming, 0, 12);
|
|
||||||
|
|
||||||
// set the underflow flag if one of the scanlines came within 14 cycles of visible underflow
|
|
||||||
if (ScanlineTimeout <= RasterTiming) gpu.GPU3D.RDLinesUnderflow = true;
|
|
||||||
|
|
||||||
scanlineswaiting += 2;
|
scanlineswaiting += 2;
|
||||||
slwaitingrd += 2;
|
slwaitingrd += 2;
|
||||||
|
|
||||||
// simulate the process of scanlines being read from the 48 scanline buffer
|
SCANLINE_BUFFER_SIM
|
||||||
while (scanlineswaiting >= 47 || RasterTiming >= SLRead[nextread] + Arbitrary)
|
|
||||||
{
|
|
||||||
if (RasterTiming < SLRead[nextread] + Arbitrary)
|
|
||||||
{
|
|
||||||
RasterTiming += timespent = (SLRead[nextread] + Arbitrary) - RasterTiming; // why + 565?
|
|
||||||
timespent += EMFixNum; // fixes edge marking bug emulation. not sure why this is needed?
|
|
||||||
}
|
|
||||||
scanlineswaiting--;
|
|
||||||
nextread++;
|
|
||||||
// update rdlines_count register
|
|
||||||
//if (gpu.GPU3D.RDLinesTemp > scanlineswaiting) gpu.GPU3D.RDLinesTemp = scanlineswaiting; // TODO: not accurate, rdlines appears to update early in some manner?
|
|
||||||
}
|
|
||||||
|
|
||||||
// feels wrong, needs improvement.
|
RDLINES_COUNT_INCREMENT
|
||||||
while (RasterTiming >= RDDecrement[nextreadrd])
|
|
||||||
{
|
|
||||||
slwaitingrd--;
|
|
||||||
nextreadrd++;
|
|
||||||
// update rdlines_count register
|
|
||||||
if (gpu.GPU3D.RDLinesTemp > slwaitingrd) gpu.GPU3D.RDLinesTemp = slwaitingrd;
|
|
||||||
}
|
|
||||||
|
|
||||||
ScanlineFinalPass<true>(gpu.GPU3D, y-3, prevtimespent >= EMGlitchThreshhold || y-3 == 1, timespent >= EMGlitchThreshhold);
|
ScanlineFinalPass<true>(gpu.GPU3D, y-3, prevtimespent >= EMGlitchThreshhold || y-3 == 1, timespent >= EMGlitchThreshhold);
|
||||||
ScanlineFinalPass<true>(gpu.GPU3D, y-2, prevtimespent >= EMGlitchThreshhold, timespent >= EMGlitchThreshhold);
|
ScanlineFinalPass<true>(gpu.GPU3D, y-2, prevtimespent >= EMGlitchThreshhold, timespent >= EMGlitchThreshhold);
|
||||||
}
|
}
|
||||||
scanlineswaiting += 2;
|
|
||||||
slwaitingrd += 2;
|
scanlineswaiting += 2;
|
||||||
prevtimespent = timespent;
|
slwaitingrd += 2;
|
||||||
|
prevtimespent = timespent;
|
||||||
|
|
||||||
// emulate read timings one last time, since it shouldn't matter after this
|
// emulate read timings one last time, since it shouldn't matter after this
|
||||||
// additionally dont bother tracking rdlines anymore since it shouldn't be able to decrement anymore (CHECKME)
|
// additionally dont bother tracking rdlines anymore since it shouldn't be able to decrement anymore (CHECKME)
|
||||||
while (scanlineswaiting >= 47 || RasterTiming >= SLRead[nextread] + Arbitrary)
|
SCANLINE_BUFFER_SIM
|
||||||
{
|
|
||||||
if (RasterTiming < SLRead[nextread] + Arbitrary)
|
|
||||||
{
|
|
||||||
RasterTiming += timespent = (SLRead[nextread] + Arbitrary) - RasterTiming; // why + 565?
|
|
||||||
timespent += EMFixNum; // fixes edge marking bug emulation. not sure why this is needed?
|
|
||||||
}
|
|
||||||
scanlineswaiting--;
|
|
||||||
nextread++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// finish the last 3 scanlines
|
// finish the last 3 scanlines
|
||||||
ScanlineFinalPass<true>(gpu.GPU3D, 189, prevtimespent >= EMGlitchThreshhold, timespent >= EMGlitchThreshhold);
|
ScanlineFinalPass<true>(gpu.GPU3D, 189, prevtimespent >= EMGlitchThreshhold, timespent >= EMGlitchThreshhold);
|
||||||
@ -2030,20 +1993,14 @@ void SoftRenderer::RenderPolygons(GPU& gpu, Polygon** polygons, int npolys)
|
|||||||
}
|
}
|
||||||
/*else
|
/*else
|
||||||
{
|
{
|
||||||
ScanlineFinalPass(gpu, 0, false, false);
|
Coming soon^tm to a melonDS near you
|
||||||
|
|
||||||
s32 pixelstopush = SLRead[0] - (timespent + ScanlinePushDelay);
|
|
||||||
if (pixelstopush > 256) pixelstopush = 256;
|
|
||||||
//timespent + ScanlinePushDelay + ScanlineReadSpeed > SLRead[0]
|
|
||||||
|
|
||||||
rastertimingeven = 0;
|
|
||||||
rastertimingodd = 0;
|
|
||||||
|
|
||||||
RenderScanline(gpu, 2, j, &rastertimingeven);
|
|
||||||
RenderScanline(gpu, 3, j, &rastertimingodd);
|
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#undef RENDER_SCANLINES
|
||||||
|
#undef SCANLINE_BUFFER_SIM
|
||||||
|
#undef RDLINES_COUNT_INCREMENT
|
||||||
|
|
||||||
void SoftRenderer::VCount144(GPU& gpu)
|
void SoftRenderer::VCount144(GPU& gpu)
|
||||||
{
|
{
|
||||||
if (RenderThreadRunning.load(std::memory_order_relaxed) && !gpu.GPU3D.AbortFrame)
|
if (RenderThreadRunning.load(std::memory_order_relaxed) && !gpu.GPU3D.AbortFrame)
|
||||||
|
Loading…
Reference in New Issue
Block a user