mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2024-11-14 13:27:41 -07:00
clean up
This commit is contained in:
parent
1aa86967b5
commit
896df08c5c
30
src/GPU3D.h
30
src/GPU3D.h
@ -351,13 +351,6 @@ public:
|
||||
static constexpr int InitGPU2DTimeout = 51875 * TimingFrac; // 51618? 51874? 52128? | when it finishes reading the first scanline.
|
||||
static constexpr int FrameLength = ScanlineReadInc * 263; // how long the entire frame is. TODO: Verify if we actually need this?
|
||||
|
||||
//static constexpr int GPU2DSpeedFirstInPair = 810 * TimingFrac; // 810 | the delay between finishing reading a pair and beginning reading a new pair.
|
||||
//static constexpr int GPU2DSpeedSecondInPair = 296 * TimingFrac; // 296 | 295??? | the delay between finishing reading the first scanline
|
||||
// and beginning reading the second scanline of a scanline pair.
|
||||
//static constexpr int GPU2DReadScanline = 256 * TimingFrac; // 256 | the time it takes to read a scanline.
|
||||
//static constexpr int GPU2DReadSLPair = 1618 * TimingFrac; // 1618 | notably the same as the scanline increment.
|
||||
//static constexpr int GPU2D48Scanlines = GPU2DReadSLPair * 24; // time to read 48 scanlines.
|
||||
|
||||
// compile-time list of scanline read times
|
||||
// these *should* always occur at the same point in each frame, so it shouldn't matter if we make them fixed
|
||||
static constexpr std::array<u32, 192> SLRead = []() constexpr {
|
||||
@ -373,7 +366,7 @@ public:
|
||||
static constexpr int Arbitrary = 565; // extra value after the scanline is read at which the cutoff of a scanline should be...?
|
||||
// idk why this is needed. im probably doing something wrong.
|
||||
|
||||
// the point at which rdlines decrements not sure why it's different...?
|
||||
// the point at which rdlines decrements. not sure why it's different...?
|
||||
static constexpr std::array<u32, 192> RDDecrement = []() constexpr {
|
||||
std::array<u32, 192> dec {};
|
||||
|
||||
@ -386,28 +379,12 @@ public:
|
||||
|
||||
// GPU 3D Rasterization Timings: For Emulating Scanline Timeout
|
||||
|
||||
//static constexpr int ScanlinePairLength = 2130 * TimingFrac;
|
||||
//static constexpr int ScanlineTimeout = 1686 * TimingFrac; // 2126? 1686?
|
||||
//static constexpr int ScanlineBreak = 4 * TimingFrac;
|
||||
//static constexpr int ScanlineBreak2 = 40 * TimingFrac;
|
||||
//static constexpr int FakeTiming = 2 * TimingFrac;
|
||||
//static constexpr int FraudulentTiming = 1120 * TimingFrac; // bad theory. todo: find a better one.
|
||||
//static constexpr int InitialTiming = 48688 * TimingFrac; // 48688 | add 1618*2 to get the timeout of the second scanline pair
|
||||
//static constexpr int Post50Max = 51116 * TimingFrac; // 51116 | for some reason it doesn't care about how full it actually is,
|
||||
// it just cares about if its the first 50 scanlines to speedrun rendering?
|
||||
static constexpr int FinalPassLen = 500 * TimingFrac; // 496 (might technically be 500?) | the next scanline cannot begin while a scanline's final pass is in progress
|
||||
// (can be interpreted as the minimum amount of cycles for the next scanline
|
||||
// pair to start after the previous pair began) (related to final pass?)
|
||||
static constexpr int ScanlinePushDelay = 242 * TimingFrac;
|
||||
static constexpr int EMGlitchThreshhold = 502 * TimingFrac; // The threshold for the edge marking glitch behavior to change.
|
||||
static constexpr int EMFixNum = 571 * TimingFrac; // Arbitrary value added to fix edge marking glitch, not sure why it's needed?
|
||||
//static constexpr int TimeoutIncrement = 2130 * TimingFrac;
|
||||
//static constexpr int ScanlineIncrementold = 1618 * TimingFrac; // 1618 | how much to regain per scanline pair
|
||||
//static constexpr int ScanlineIncrement = 2114 * TimingFrac; // 2114 | how much time a scanline pair "gains"
|
||||
//static constexpr int AbortIncrement = 12 * TimingFrac; // 12 | how much extra to regain after an aborted scanline (total 2126)
|
||||
// (why does the next pair get more time if the previous scanline is aborted?)
|
||||
//static constexpr int UnderflowFlag = 2 * TimingFrac; // 14 | How many cycles need to be left for the 3ddispcnt rdlines underflow flag to be set
|
||||
//static constexpr int FinishScanline = 512 * TimingFrac;
|
||||
|
||||
// GPU 3D Rasterization Timings II: For Tracking Timing Behaviors
|
||||
|
||||
@ -429,11 +406,6 @@ public:
|
||||
static constexpr int FirstPolyDelay = 4 * TimingFrac; // 4 | Min amount of cycles to begin a scanline? (minimum time it takes to init the first polygon?)
|
||||
// (Amount of time before the end of the cycle a scanline must abort?)
|
||||
|
||||
// static constexpr int RasterTimingCap = 51116 * TimingFrac;
|
||||
// static constexpr int PerScanlineTiming = 1064 * TimingFrac; // approximate currently, used to calc RDLines. TEMPORARY UNTIL ACCURATE "FRAMEBUFFER" CAN BE IMPLEMENTED
|
||||
// static constexpr int PerScanlineRecup = 2112 * TimingFrac; // seems to check out? // should be the "free" time the gpu has to do the calculation
|
||||
// static constexpr int PerRightSlope = 1 * TimingFrac;
|
||||
// static constexpr int FirstPixelTiming;
|
||||
|
||||
class Renderer3D
|
||||
{
|
||||
|
@ -1632,11 +1632,9 @@ void SoftRenderer::ScanlineFinalPass(const GPU3D& gpu3d, s32 y, bool checkprev,
|
||||
if (x == 0)
|
||||
{
|
||||
// edge marking bug emulation
|
||||
if (checkprev)
|
||||
{
|
||||
if (CheckEdgeMarkingClearPlane(gpu3d, polyid, z)) goto pass; // check against the clear plane
|
||||
}
|
||||
else if (CheckEdgeMarkingPixel(polyid, z, pixeladdr-(ScanlineWidth+1))) goto pass; // checks the right edge of the scanline 2 scanlines ago
|
||||
if (checkprev ? CheckEdgeMarkingClearPlane(gpu3d, polyid, z) : // check against the clear plane
|
||||
CheckEdgeMarkingPixel(polyid, z, pixeladdr-1 - ScanlineWidth)) // checks the right edge of the scanline 2 scanlines ago
|
||||
goto pass;
|
||||
}
|
||||
else if (CheckEdgeMarkingPixel(polyid, z, pixeladdr-1)) goto pass; // normal check
|
||||
|
||||
@ -1644,11 +1642,9 @@ void SoftRenderer::ScanlineFinalPass(const GPU3D& gpu3d, s32 y, bool checkprev,
|
||||
if (x == 255)
|
||||
{
|
||||
// edge marking bug emulation
|
||||
if (checknext)
|
||||
{
|
||||
if (CheckEdgeMarkingClearPlane(gpu3d, polyid, z)) goto pass; // check against the clear plane
|
||||
}
|
||||
else if (CheckEdgeMarkingPixel(polyid, z, pixeladdr+(ScanlineWidth+1))) goto pass; // checks the left edge of the scanline 2 scanlines ahead
|
||||
if (checknext ? CheckEdgeMarkingClearPlane(gpu3d, polyid, z) : // check against the clear plane
|
||||
CheckEdgeMarkingPixel(polyid, z, pixeladdr+1 + ScanlineWidth)) // checks the left edge of the scanline 2 scanlines ahead
|
||||
goto pass;
|
||||
}
|
||||
else if (CheckEdgeMarkingPixel(polyid, z, pixeladdr+1)) goto pass; // normal check
|
||||
|
||||
@ -1884,43 +1880,24 @@ void SoftRenderer::ClearBuffers(const GPU& gpu)
|
||||
}
|
||||
}
|
||||
|
||||
u16 SoftRenderer::BeginPushScanline(s32 y, s32 pixelstodraw)
|
||||
void SoftRenderer::RenderPolygonsFast(GPU& gpu, Polygon** polygons, int npolys)
|
||||
{
|
||||
// push the finished scanline to the appropriate frame buffers.
|
||||
// if a scanline is late enough to intersect with the 2d engine read time it will be partially drawn
|
||||
|
||||
u16 start;
|
||||
if (pixelstodraw >= 256 || pixelstodraw <= 0) // if scheduled after or 256 cycles before a scanline read render full scanline
|
||||
int j = 0;
|
||||
for (int i = 0; i < npolys; i++)
|
||||
{
|
||||
start = 0;
|
||||
pixelstodraw = 256;
|
||||
if (polygons[i]->Degenerate) continue;
|
||||
SetupPolygon(&PolygonList[j++], polygons[i]);
|
||||
}
|
||||
else // render partial scanline
|
||||
|
||||
RenderScanline<false>(gpu, 0, 0, j, nullptr);
|
||||
|
||||
for (s32 y = 1; y < 192; y++)
|
||||
{
|
||||
start = ScanlineWidth - pixelstodraw;
|
||||
|
||||
// it seems to read in pairs of two every two cycles? looks jittery
|
||||
bool jitter = pixelstodraw % 2;
|
||||
pixelstodraw += jitter;
|
||||
start -= jitter;
|
||||
RenderScanline<false>(gpu, y, 0, j, nullptr);
|
||||
ScanlineFinalPass<true>(gpu.GPU3D, y-1, true, true);
|
||||
}
|
||||
u8 bufferpos = y % 48;
|
||||
memcpy(&RDBuffer[bufferpos*ScanlineWidth+start], &ColorBuffer[y*ScanlineWidth+start], 4 * pixelstodraw);
|
||||
return start;
|
||||
}
|
||||
|
||||
void SoftRenderer::ReadScanline(s32 y)
|
||||
{
|
||||
u8 bufferpos = y % 48;
|
||||
memcpy(&FinalBuffer[y*ScanlineWidth], &RDBuffer[bufferpos*ScanlineWidth], 4 * ScanlineWidth);
|
||||
}
|
||||
|
||||
void SoftRenderer::FinishPushScanline(s32 y, s32 pixelsremain)
|
||||
{
|
||||
if (pixelsremain = 0) return;
|
||||
|
||||
u8 bufferpos = y % 48;
|
||||
memcpy(&RDBuffer[bufferpos*ScanlineWidth], &ColorBuffer[y*ScanlineWidth], 4 * pixelsremain);
|
||||
ScanlineFinalPass<true>(gpu.GPU3D, 191, true, true);
|
||||
}
|
||||
|
||||
#define RDLINES_COUNT_INCREMENT\
|
||||
@ -1937,10 +1914,11 @@ void SoftRenderer::FinishPushScanline(s32 y, s32 pixelsremain)
|
||||
/* simulate the process of scanlines being read from the 48 scanline buffer */\
|
||||
while (scanlineswaiting >= 47 || RasterTiming >= SLRead[nextread] + Arbitrary)\
|
||||
{\
|
||||
if (RasterTiming < SLRead[nextread] + Arbitrary)\
|
||||
if (RasterTiming < SLRead[nextread] + Arbitrary) /* why + 565? */\
|
||||
{\
|
||||
RasterTiming += timespent = (SLRead[nextread] + Arbitrary) - RasterTiming; /* why + 565? */\
|
||||
timespent = (SLRead[nextread] + Arbitrary) - RasterTiming;\
|
||||
timespent += EMFixNum; /* fixes edge marking bug emulation. not sure why this is needed? */\
|
||||
RasterTiming = (SLRead[nextread] + Arbitrary);\
|
||||
}\
|
||||
scanlineswaiting--;\
|
||||
nextread++;\
|
||||
@ -1961,27 +1939,6 @@ void SoftRenderer::FinishPushScanline(s32 y, s32 pixelsremain)
|
||||
/* set the underflow flag if one of the scanlines came within 14 cycles of visible underflow */\
|
||||
if ((ScanlineTimeout <= RasterTiming) && (gpu.GPU3D.UnderflowFlagVCount == (u16)-1)) gpu.GPU3D.UnderflowFlagVCount = y - (y&1 ? 0 : 1);
|
||||
|
||||
void SoftRenderer::RenderPolygonsFast(GPU& gpu, Polygon** polygons, int npolys)
|
||||
{
|
||||
int j = 0;
|
||||
for (int i = 0; i < npolys; i++)
|
||||
{
|
||||
if (polygons[i]->Degenerate) continue;
|
||||
SetupPolygon(&PolygonList[j++], polygons[i]);
|
||||
}
|
||||
|
||||
int dummy;
|
||||
RenderScanline<false>(gpu, 0, 0, j, &dummy);
|
||||
|
||||
for (s32 y = 1; y < 192; y++)
|
||||
{
|
||||
RenderScanline<false>(gpu, y, 0, j, &dummy);
|
||||
ScanlineFinalPass<true>(gpu.GPU3D, y-1, true, true);
|
||||
}
|
||||
|
||||
ScanlineFinalPass<true>(gpu.GPU3D, 191, true, true);
|
||||
}
|
||||
|
||||
void SoftRenderer::RenderPolygonsTiming(GPU& gpu, Polygon** polygons, int npolys)
|
||||
{
|
||||
int j = 0;
|
||||
@ -1994,7 +1951,7 @@ void SoftRenderer::RenderPolygonsTiming(GPU& gpu, Polygon** polygons, int npolys
|
||||
// reset scanline trackers
|
||||
gpu.GPU3D.UnderflowFlagVCount = -1;
|
||||
gpu.GPU3D.RDLinesTemp = 63;
|
||||
ScanlineTimeout = FrameLength; // CHECKME
|
||||
ScanlineTimeout = 0x7FFFFFFF; // CHECKME: first scanline pair timeout.
|
||||
s32 rastertimingeven, rastertimingodd; // always init to 0 at the start of a scanline render
|
||||
s32 scanlineswaiting = 0, slwaitingrd = 0;
|
||||
s32 nextread = 0, nextreadrd = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user