Make Frozen Time rendering 4 times faster by grouping draw segments in batches of 100 (old algorithm processed 32000 draw segs per sprite!)

This commit is contained in:
Magnus Norddahl 2017-02-05 00:42:42 +01:00
commit 4172d70d95
4 changed files with 200 additions and 62 deletions

View file

@ -40,6 +40,7 @@
#include "swrenderer/things/r_visiblesprite.h"
#include "swrenderer/scene/r_light.h"
#include "swrenderer/viewport/r_viewport.h"
#include "swrenderer/r_renderthread.h"
namespace swrenderer
{
@ -83,4 +84,83 @@ namespace swrenderer
{
InterestingSegments.Push(segment);
}
void DrawSegmentList::BuildSegmentGroups()
{
SegmentGroups.Clear();
unsigned int groupSize = 100;
for (unsigned int index = BeginIndex(); index < EndIndex(); index += groupSize)
{
auto ds = Segment(index);
DrawSegmentGroup group;
group.BeginIndex = index;
group.EndIndex = MIN(index + groupSize, EndIndex());
group.x1 = ds->x1;
group.x2 = ds->x2;
group.neardepth = MIN(ds->sz1, ds->sz2);
group.fardepth = MAX(ds->sz1, ds->sz2);
for (unsigned int groupIndex = group.BeginIndex + 1; groupIndex < group.EndIndex; groupIndex++)
{
ds = Segment(groupIndex);
group.x1 = MIN(group.x1, ds->x1);
group.x2 = MAX(group.x2, ds->x2);
group.neardepth = MIN(group.neardepth, ds->sz1);
group.neardepth = MIN(group.neardepth, ds->sz2);
group.fardepth = MAX(ds->sz1, group.fardepth);
group.fardepth = MAX(ds->sz2, group.fardepth);
}
for (int x = group.x1; x < group.x2; x++)
{
cliptop[x] = 0;
clipbottom[x] = viewheight;
}
for (unsigned int groupIndex = group.BeginIndex; groupIndex < group.EndIndex; groupIndex++)
{
ds = Segment(groupIndex);
// kg3D - no clipping on fake segs
if (ds->fake) continue;
if (ds->silhouette & SIL_BOTTOM)
{
short *clip1 = clipbottom + ds->x1;
const short *clip2 = ds->sprbottomclip;
int i = ds->x2 - ds->x1;
do
{
if (*clip1 > *clip2)
*clip1 = *clip2;
clip1++;
clip2++;
} while (--i);
}
if (ds->silhouette & SIL_TOP)
{
short *clip1 = cliptop + ds->x1;
const short *clip2 = ds->sprtopclip;
int i = ds->x2 - ds->x1;
do
{
if (*clip1 < *clip2)
*clip1 = *clip2;
clip1++;
clip2++;
} while (--i);
}
}
group.sprtopclip = Thread->FrameMemory->AllocMemory<short>(group.x2 - group.x1);
group.sprbottomclip = Thread->FrameMemory->AllocMemory<short>(group.x2 - group.x1);
memcpy(group.sprtopclip, cliptop + group.x1, (group.x2 - group.x1) * sizeof(short));
memcpy(group.sprbottomclip, clipbottom + group.x1, (group.x2 - group.x1) * sizeof(short));
SegmentGroups.Push(group);
}
}
}