2009-02-09 21:15:56 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2007-2009 Gabest
|
|
|
|
* http://www.gabest.org
|
|
|
|
*
|
|
|
|
* This Program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This Program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with GNU Make; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2009-02-20 10:59:10 +00:00
|
|
|
// TODO: JIT Draw* (flags: depth, texture, color (+iip), scissor)
|
2009-02-15 02:27:51 +00:00
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
#include "StdAfx.h"
|
|
|
|
#include "GSRasterizer.h"
|
|
|
|
|
|
|
|
GSRasterizer::GSRasterizer(IDrawScanline* ds, int id, int threads)
|
|
|
|
: m_ds(ds)
|
|
|
|
, m_id(id)
|
|
|
|
, m_threads(threads)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
GSRasterizer::~GSRasterizer()
|
|
|
|
{
|
|
|
|
delete m_ds;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GSRasterizer::Draw(const GSRasterizerData* data)
|
|
|
|
{
|
2009-02-15 02:27:51 +00:00
|
|
|
m_dsf.ssl = NULL;
|
2009-03-09 01:42:56 +00:00
|
|
|
m_dsf.ssle = NULL;
|
2009-02-15 02:27:51 +00:00
|
|
|
m_dsf.ssp = NULL;
|
2009-03-09 01:42:56 +00:00
|
|
|
m_dsf.sr = NULL;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
m_ds->BeginDraw(data, &m_dsf);
|
|
|
|
|
|
|
|
const GSVector4i scissor = data->scissor;
|
|
|
|
const GSVertexSW* vertices = data->vertices;
|
|
|
|
const int count = data->count;
|
|
|
|
|
|
|
|
m_stats.Reset();
|
|
|
|
|
2009-05-15 11:11:26 +00:00
|
|
|
int64 start = __rdtsc();
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
switch(data->primclass)
|
|
|
|
{
|
|
|
|
case GS_POINT_CLASS:
|
|
|
|
m_stats.prims = count;
|
|
|
|
for(int i = 0; i < count; i++) DrawPoint(&vertices[i], scissor);
|
|
|
|
break;
|
|
|
|
case GS_LINE_CLASS:
|
|
|
|
ASSERT(!(count & 1));
|
|
|
|
m_stats.prims = count / 2;
|
|
|
|
for(int i = 0; i < count; i += 2) DrawLine(&vertices[i], scissor);
|
|
|
|
break;
|
|
|
|
case GS_TRIANGLE_CLASS:
|
|
|
|
ASSERT(!(count % 3));
|
|
|
|
m_stats.prims = count / 3;
|
|
|
|
for(int i = 0; i < count; i += 3) DrawTriangle(&vertices[i], scissor);
|
|
|
|
break;
|
|
|
|
case GS_SPRITE_CLASS:
|
|
|
|
ASSERT(!(count & 1));
|
|
|
|
m_stats.prims = count / 2;
|
|
|
|
for(int i = 0; i < count; i += 2) DrawSprite(&vertices[i], scissor);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
__assume(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_stats.ticks = __rdtsc() - start;
|
|
|
|
|
|
|
|
m_ds->EndDraw(m_stats);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GSRasterizer::GetStats(GSRasterizerStats& stats)
|
|
|
|
{
|
|
|
|
stats = m_stats;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GSRasterizer::DrawPoint(const GSVertexSW* v, const GSVector4i& scissor)
|
|
|
|
{
|
|
|
|
// TODO: round to closest for point, prestep for line
|
|
|
|
|
|
|
|
GSVector4i p(v->p);
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
if(scissor.left <= p.x && p.x < scissor.right && scissor.top <= p.y && p.y < scissor.bottom)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
if((p.y % m_threads) == m_id)
|
|
|
|
{
|
2009-02-20 10:59:10 +00:00
|
|
|
m_dsf.ssp(v, *v);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-02-22 16:28:39 +00:00
|
|
|
m_dsf.ssl(p.x + 1, p.x, p.y, *v);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
m_stats.pixels++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GSRasterizer::DrawLine(const GSVertexSW* v, const GSVector4i& scissor)
|
|
|
|
{
|
|
|
|
GSVertexSW dv = v[1] - v[0];
|
|
|
|
|
|
|
|
GSVector4 dp = dv.p.abs();
|
2009-03-09 01:42:56 +00:00
|
|
|
|
|
|
|
if(m_dsf.ssle)
|
|
|
|
{
|
|
|
|
int i = (dp < dp.yxwz()).mask() & 1; // |x| <= |y|
|
|
|
|
|
|
|
|
GSVertexSW dscan;
|
|
|
|
|
|
|
|
dscan.p = GSVector4::zero();
|
|
|
|
dscan.t = GSVector4::zero();
|
|
|
|
dscan.c = GSVector4::zero();
|
|
|
|
|
|
|
|
m_dsf.ssp(v, dscan);
|
|
|
|
|
|
|
|
DrawEdge(v[0], v[1], dv, scissor, i, 0);
|
|
|
|
DrawEdge(v[0], v[1], dv, scissor, i, 1);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
GSVector4i dpi(dp);
|
|
|
|
|
|
|
|
if(dpi.y == 0)
|
|
|
|
{
|
|
|
|
if(dpi.x > 0)
|
|
|
|
{
|
|
|
|
// shortcut for horizontal lines
|
|
|
|
|
|
|
|
GSVector4 mask = (v[0].p > v[1].p).xxxx();
|
|
|
|
|
|
|
|
GSVertexSW l, dl;
|
|
|
|
|
|
|
|
l.p = v[0].p.blend8(v[1].p, mask);
|
|
|
|
l.t = v[0].t.blend8(v[1].t, mask);
|
|
|
|
l.c = v[0].c.blend8(v[1].c, mask);
|
|
|
|
|
|
|
|
GSVector4 r;
|
|
|
|
|
|
|
|
r = v[1].p.blend8(v[0].p, mask);
|
|
|
|
|
|
|
|
GSVector4i p(l.p);
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
if(scissor.top <= p.y && p.y < scissor.bottom)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
GSVertexSW dscan = dv / dv.p.xxxx();
|
|
|
|
|
2009-02-20 10:59:10 +00:00
|
|
|
m_dsf.ssp(v, dscan);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
l.p = l.p.upl(r).xyzw(l.p); // r.x => l.y
|
|
|
|
|
2009-02-24 20:12:46 +00:00
|
|
|
GSVector4 fscissor(scissor);
|
|
|
|
|
|
|
|
DrawTriangleSection(p.y, p.y + 1, l, dl, dscan, fscissor);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int i = dpi.x > dpi.y ? 0 : 1;
|
|
|
|
|
|
|
|
GSVertexSW edge = v[0];
|
|
|
|
GSVertexSW dedge = dv / dp.v[i];
|
|
|
|
|
|
|
|
// TODO: prestep + clip with the scissor
|
|
|
|
|
|
|
|
int steps = dpi.v[i];
|
|
|
|
|
|
|
|
while(steps-- > 0)
|
|
|
|
{
|
|
|
|
DrawPoint(&edge, scissor);
|
|
|
|
|
|
|
|
edge += dedge;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const int s_abc[8][4] =
|
|
|
|
{
|
2009-02-24 20:12:46 +00:00
|
|
|
{0, 1, 2, 0}, // c >= b >= a
|
|
|
|
{1, 0, 2, 0}, // c >= a > b
|
2009-02-09 21:15:56 +00:00
|
|
|
{0, 0, 0, 0},
|
2009-02-24 20:12:46 +00:00
|
|
|
{1, 2, 0, 0}, // a > c >= b
|
|
|
|
{0, 2, 1, 0}, // b > c >= a
|
2009-02-09 21:15:56 +00:00
|
|
|
{0, 0, 0, 0},
|
2009-02-24 20:12:46 +00:00
|
|
|
{2, 0, 1, 0}, // b >= a > c
|
|
|
|
{2, 1, 0, 0}, // a > b > c
|
2009-02-09 21:15:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void GSRasterizer::DrawTriangle(const GSVertexSW* vertices, const GSVector4i& scissor)
|
|
|
|
{
|
|
|
|
GSVertexSW v[3];
|
|
|
|
|
|
|
|
GSVector4 aabb = vertices[0].p.yyyy(vertices[1].p);
|
|
|
|
GSVector4 bccb = vertices[1].p.yyyy(vertices[2].p).xzzx();
|
|
|
|
|
|
|
|
int i = (aabb > bccb).mask() & 7;
|
|
|
|
|
|
|
|
v[0] = vertices[s_abc[i][0]];
|
|
|
|
v[1] = vertices[s_abc[i][1]];
|
|
|
|
v[2] = vertices[s_abc[i][2]];
|
|
|
|
|
|
|
|
aabb = v[0].p.yyyy(v[1].p);
|
|
|
|
bccb = v[1].p.yyyy(v[2].p).xzzx();
|
|
|
|
|
|
|
|
i = (aabb == bccb).mask() & 7;
|
|
|
|
|
2009-03-09 01:42:56 +00:00
|
|
|
if(m_dsf.ssle)
|
|
|
|
{
|
|
|
|
DrawTriangleEdge(v, scissor);
|
|
|
|
}
|
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
switch(i)
|
|
|
|
{
|
|
|
|
case 0: // a < b < c
|
|
|
|
DrawTriangleTopBottom(v, scissor);
|
|
|
|
break;
|
|
|
|
case 1: // a == b < c
|
|
|
|
DrawTriangleBottom(v, scissor);
|
|
|
|
break;
|
|
|
|
case 4: // a < b == c
|
|
|
|
DrawTriangleTop(v, scissor);
|
|
|
|
break;
|
|
|
|
case 7: // a == b == c
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
__assume(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-09 01:42:56 +00:00
|
|
|
void GSRasterizer::DrawTriangleEdge(const GSVertexSW* v, const GSVector4i& scissor)
|
|
|
|
{
|
|
|
|
GSVertexSW dv[3];
|
|
|
|
|
|
|
|
dv[0] = v[1] - v[0];
|
|
|
|
dv[1] = v[2] - v[0];
|
|
|
|
dv[2] = v[2] - v[1];
|
|
|
|
|
|
|
|
GSVector4 dx = dv[0].p.upl(dv[1].p).xyxy(dv[2].p);
|
|
|
|
GSVector4 dy = dv[0].p.upl(dv[1].p).zwyx(dv[2].p);
|
|
|
|
|
|
|
|
GSVector4 a = dx.abs() < dy.abs(); // |x| <= |y|
|
|
|
|
GSVector4 b = dx < GSVector4::zero(); // x < 0
|
|
|
|
GSVector4 c = dv[1].p * (dv[0].p / dv[1].p).yyyy() < dv[0].p; // longest.p.x < 0
|
|
|
|
|
|
|
|
int i = a.mask();
|
|
|
|
int j = ((a | b) ^ c.xxxx()).mask() ^ 2; // evil
|
|
|
|
|
|
|
|
GSVertexSW dscan;
|
|
|
|
|
|
|
|
dscan.p = GSVector4::zero();
|
|
|
|
dscan.t = GSVector4::zero();
|
|
|
|
dscan.c = GSVector4::zero();
|
|
|
|
|
|
|
|
m_dsf.ssp(v, dscan); // TODO: don't call it twice (can't be sure about the second call if the triangle is too small)
|
|
|
|
|
|
|
|
DrawEdge(v[0], v[1], dv[0], scissor, i & 1, j & 1);
|
|
|
|
DrawEdge(v[0], v[2], dv[1], scissor, i & 2, j & 2);
|
|
|
|
DrawEdge(v[1], v[2], dv[2], scissor, i & 4, j & 4);
|
|
|
|
}
|
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
void GSRasterizer::DrawTriangleTop(GSVertexSW* v, const GSVector4i& scissor)
|
|
|
|
{
|
|
|
|
GSVertexSW longest;
|
|
|
|
|
|
|
|
longest.p = v[2].p - v[1].p;
|
|
|
|
|
2009-05-22 01:22:52 +00:00
|
|
|
int i = longest.p.upl(longest.p == GSVector4::zero()).mask();
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
if(i & 2) return;
|
|
|
|
|
|
|
|
i &= 1;
|
|
|
|
|
|
|
|
GSVertexSW& l = v[0];
|
|
|
|
GSVector4& r = v[0].p;
|
|
|
|
|
2009-02-24 20:12:46 +00:00
|
|
|
GSVector4 fscissor(scissor);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-02-24 20:12:46 +00:00
|
|
|
GSVector4 tb = l.p.upl(v[2].p).ceil();
|
|
|
|
|
|
|
|
GSVector4 tbmax = tb.maxv(fscissor.yyyy());
|
|
|
|
GSVector4 tbmin = tb.minv(fscissor.wwww());
|
|
|
|
|
|
|
|
GSVector4i tbi = GSVector4i(tbmax.zzww(tbmin));
|
|
|
|
|
|
|
|
int top = tbi.extract32<0>();
|
|
|
|
int bottom = tbi.extract32<2>();
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
if(top >= bottom) return;
|
|
|
|
|
|
|
|
longest.t = v[2].t - v[1].t;
|
|
|
|
longest.c = v[2].c - v[1].c;
|
|
|
|
|
|
|
|
GSVertexSW dscan = longest * longest.p.xxxx().rcp();
|
|
|
|
|
2009-05-22 01:22:52 +00:00
|
|
|
GSVertexSW vl = v[1 + i] - l;
|
|
|
|
GSVector4 vr = v[2 - i].p - r;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
GSVertexSW dl = vl / vl.p.yyyy();
|
|
|
|
GSVector4 dr = vr / vr.yyyy();
|
|
|
|
|
2009-02-24 20:12:46 +00:00
|
|
|
GSVector4 dy = tbmax.zzzz() - l.p.yyyy();
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
l.p = l.p.upl(r).xyzw(l.p); // r.x => l.y
|
|
|
|
dl.p = dl.p.upl(dr).xyzw(dl.p); // dr.x => dl.y
|
|
|
|
|
2009-02-24 20:12:46 +00:00
|
|
|
l += dl * dy;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-02-20 10:59:10 +00:00
|
|
|
m_dsf.ssp(v, dscan);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-02-24 20:12:46 +00:00
|
|
|
DrawTriangleSection(top, bottom, l, dl, dscan, fscissor);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GSRasterizer::DrawTriangleBottom(GSVertexSW* v, const GSVector4i& scissor)
|
|
|
|
{
|
|
|
|
GSVertexSW longest;
|
|
|
|
|
|
|
|
longest.p = v[1].p - v[0].p;
|
|
|
|
|
2009-05-22 01:22:52 +00:00
|
|
|
int i = longest.p.upl(longest.p == GSVector4::zero()).mask();
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
if(i & 2) return;
|
|
|
|
|
|
|
|
i &= 1;
|
|
|
|
|
2009-05-22 01:22:52 +00:00
|
|
|
GSVertexSW& l = v[i];
|
|
|
|
GSVector4& r = v[1 - i].p;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-02-24 20:12:46 +00:00
|
|
|
GSVector4 fscissor(scissor);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-02-24 20:12:46 +00:00
|
|
|
GSVector4 tb = l.p.upl(v[2].p).ceil();
|
|
|
|
|
|
|
|
GSVector4 tbmax = tb.maxv(fscissor.yyyy());
|
|
|
|
GSVector4 tbmin = tb.minv(fscissor.wwww());
|
|
|
|
|
|
|
|
GSVector4i tbi = GSVector4i(tbmax.zzww(tbmin));
|
|
|
|
|
|
|
|
int top = tbi.extract32<0>();
|
|
|
|
int bottom = tbi.extract32<2>();
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
if(top >= bottom) return;
|
|
|
|
|
|
|
|
longest.t = v[1].t - v[0].t;
|
|
|
|
longest.c = v[1].c - v[0].c;
|
|
|
|
|
|
|
|
GSVertexSW dscan = longest * longest.p.xxxx().rcp();
|
|
|
|
|
|
|
|
GSVertexSW vl = v[2] - l;
|
|
|
|
GSVector4 vr = v[2].p - r;
|
|
|
|
|
|
|
|
GSVertexSW dl = vl / vl.p.yyyy();
|
|
|
|
GSVector4 dr = vr / vr.yyyy();
|
|
|
|
|
2009-02-24 20:12:46 +00:00
|
|
|
GSVector4 dy = tbmax.zzzz() - l.p.yyyy();
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
l.p = l.p.upl(r).xyzw(l.p); // r.x => l.y
|
|
|
|
dl.p = dl.p.upl(dr).xyzw(dl.p); // dr.x => dl.y
|
|
|
|
|
2009-02-24 20:12:46 +00:00
|
|
|
l += dl * dy;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-02-20 10:59:10 +00:00
|
|
|
m_dsf.ssp(v, dscan);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-02-24 20:12:46 +00:00
|
|
|
DrawTriangleSection(top, bottom, l, dl, dscan, fscissor);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GSRasterizer::DrawTriangleTopBottom(GSVertexSW* v, const GSVector4i& scissor)
|
|
|
|
{
|
|
|
|
GSVertexSW dv[3];
|
|
|
|
|
|
|
|
dv[0] = v[1] - v[0];
|
|
|
|
dv[1] = v[2] - v[0];
|
|
|
|
|
2009-02-24 20:12:46 +00:00
|
|
|
GSVertexSW longest = dv[1] * (dv[0].p / dv[1].p).yyyy() - dv[0];
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-22 01:22:52 +00:00
|
|
|
int i = longest.p.upl(longest.p == GSVector4::zero()).mask();
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
if(i & 2) return;
|
|
|
|
|
|
|
|
i &= 1;
|
|
|
|
|
|
|
|
GSVertexSW dscan = longest * longest.p.xxxx().rcp();
|
|
|
|
|
2009-02-20 10:59:10 +00:00
|
|
|
m_dsf.ssp(v, dscan);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-02-24 20:12:46 +00:00
|
|
|
GSVector4 fscissor(scissor);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-02-24 20:12:46 +00:00
|
|
|
GSVector4 tb = v[0].p.upl(v[1].p).zwzw(v[1].p.upl(v[2].p)).ceil();
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-02-24 20:12:46 +00:00
|
|
|
GSVector4 tbmax = tb.maxv(fscissor.yyyy());
|
|
|
|
GSVector4 tbmin = tb.minv(fscissor.wwww());
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-02-24 20:12:46 +00:00
|
|
|
GSVector4i tbi = GSVector4i(tbmax.xzyw(tbmin));
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-02-24 20:12:46 +00:00
|
|
|
int top = tbi.extract32<0>();
|
|
|
|
int bottom = tbi.extract32<2>();
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-02-24 20:12:46 +00:00
|
|
|
GSVertexSW& l = v[0];
|
|
|
|
GSVector4 r = v[0].p;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-22 01:22:52 +00:00
|
|
|
GSVertexSW dl = dv[i] / dv[i].p.yyyy();
|
|
|
|
GSVector4 dr = dv[1 - i].p / dv[1 - i].p.yyyy();
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-02-24 20:12:46 +00:00
|
|
|
GSVector4 dy = tbmax.xxxx() - l.p.yyyy();
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-02-24 20:12:46 +00:00
|
|
|
l += dl * dy;
|
|
|
|
r += dr * dy;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
if(top < bottom)
|
|
|
|
{
|
2009-02-24 20:12:46 +00:00
|
|
|
DrawTriangleSection(top, bottom, l, dl, r, dr, dscan, fscissor);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2009-02-24 20:12:46 +00:00
|
|
|
top = tbi.y;
|
|
|
|
bottom = tbi.w;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
if(top < bottom)
|
|
|
|
{
|
2009-05-22 01:22:52 +00:00
|
|
|
if(i == 0)
|
2009-02-24 20:12:46 +00:00
|
|
|
{
|
|
|
|
l = v[1];
|
|
|
|
dv[2] = v[2] - v[1];
|
|
|
|
dl = dv[2] / dv[2].p.yyyy();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
r = v[1].p;
|
|
|
|
dv[2].p = v[2].p - v[1].p;
|
|
|
|
dr = dv[2].p / dv[2].p.yyyy();
|
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-02-24 20:12:46 +00:00
|
|
|
l += dl * (tbmax.zzzz() - l.p.yyyy());
|
|
|
|
r += dr * (tbmax.zzzz() - r.yyyy());
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
l.p = l.p.upl(r).xyzw(l.p); // r.x => l.y
|
|
|
|
dl.p = dl.p.upl(dr).xyzw(dl.p); // dr.x => dl.y
|
|
|
|
|
2009-02-24 20:12:46 +00:00
|
|
|
DrawTriangleSection(top, bottom, l, dl, dscan, fscissor);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-24 20:12:46 +00:00
|
|
|
void GSRasterizer::DrawTriangleSection(int top, int bottom, GSVertexSW& l, const GSVertexSW& dl, GSVector4& r, const GSVector4& dr, const GSVertexSW& dscan, const GSVector4& fscissor)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
ASSERT(top < bottom);
|
|
|
|
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if((top % m_threads) == m_id)
|
|
|
|
{
|
2009-02-24 20:12:46 +00:00
|
|
|
GSVector4 lr = l.p.xyxy(r).ceil();
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-02-24 20:12:46 +00:00
|
|
|
GSVector4 lrmax = lr.maxv(fscissor.xxxx());
|
|
|
|
GSVector4 lrmin = lr.minv(fscissor.zzzz());
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-02-24 20:12:46 +00:00
|
|
|
GSVector4i lri = GSVector4i(lrmax.xxzz(lrmin));
|
2009-02-19 13:13:20 +00:00
|
|
|
|
2009-02-24 20:12:46 +00:00
|
|
|
int left = lri.extract32<0>();
|
|
|
|
int right = lri.extract32<2>();
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
int pixels = right - left;
|
|
|
|
|
|
|
|
if(pixels > 0)
|
|
|
|
{
|
|
|
|
m_stats.pixels += pixels;
|
|
|
|
|
2009-02-24 20:12:46 +00:00
|
|
|
GSVertexSW scan = l + dscan * (lrmax - l.p).xxxx();
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-02-22 16:28:39 +00:00
|
|
|
m_dsf.ssl(right, left, top, scan);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while(0);
|
|
|
|
|
|
|
|
if(++top >= bottom) break;
|
|
|
|
|
|
|
|
l += dl;
|
|
|
|
r += dr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-24 20:12:46 +00:00
|
|
|
void GSRasterizer::DrawTriangleSection(int top, int bottom, GSVertexSW& l, const GSVertexSW& dl, const GSVertexSW& dscan, const GSVector4& fscissor)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
ASSERT(top < bottom);
|
|
|
|
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if((top % m_threads) == m_id)
|
|
|
|
{
|
2009-02-24 20:12:46 +00:00
|
|
|
GSVector4 lr = l.p.ceil();
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-02-24 20:12:46 +00:00
|
|
|
GSVector4 lrmax = lr.maxv(fscissor.xxxx());
|
|
|
|
GSVector4 lrmin = lr.minv(fscissor.zzzz());
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-02-24 20:12:46 +00:00
|
|
|
GSVector4i lri = GSVector4i(lrmax.xxyy(lrmin));
|
2009-02-19 13:13:20 +00:00
|
|
|
|
2009-02-24 20:12:46 +00:00
|
|
|
int left = lri.extract32<0>();
|
|
|
|
int right = lri.extract32<2>();
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
int pixels = right - left;
|
|
|
|
|
|
|
|
if(pixels > 0)
|
|
|
|
{
|
|
|
|
m_stats.pixels += pixels;
|
|
|
|
|
2009-02-24 20:12:46 +00:00
|
|
|
GSVertexSW scan = l + dscan * (lrmax - l.p).xxxx();
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-02-22 16:28:39 +00:00
|
|
|
m_dsf.ssl(right, left, top, scan);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while(0);
|
|
|
|
|
|
|
|
if(++top >= bottom) break;
|
|
|
|
|
|
|
|
l += dl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GSRasterizer::DrawSprite(const GSVertexSW* vertices, const GSVector4i& scissor)
|
|
|
|
{
|
|
|
|
GSVertexSW v[2];
|
|
|
|
|
|
|
|
GSVector4 mask = (vertices[0].p < vertices[1].p).xyzw(GSVector4::zero());
|
|
|
|
|
|
|
|
v[0].p = vertices[1].p.blend8(vertices[0].p, mask);
|
|
|
|
v[0].t = vertices[1].t.blend8(vertices[0].t, mask);
|
|
|
|
v[0].c = vertices[1].c;
|
|
|
|
|
|
|
|
v[1].p = vertices[0].p.blend8(vertices[1].p, mask);
|
|
|
|
v[1].t = vertices[0].t.blend8(vertices[1].t, mask);
|
|
|
|
|
|
|
|
GSVector4i r(v[0].p.xyxy(v[1].p).ceil());
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
r = r.rintersect(scissor);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
if(r.rempty()) return;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
GSVertexSW scan = v[0];
|
|
|
|
|
|
|
|
if(m_dsf.sr)
|
|
|
|
{
|
|
|
|
if(m_id == 0)
|
|
|
|
{
|
|
|
|
(m_ds->*m_dsf.sr)(r, scan);
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
m_stats.pixels += r.width() * r.height();
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
GSVector4 zero = GSVector4::zero();
|
|
|
|
|
|
|
|
GSVertexSW dedge, dscan;
|
|
|
|
|
|
|
|
dedge.p = zero;
|
|
|
|
dscan.p = zero;
|
|
|
|
|
|
|
|
dedge.c = zero;
|
|
|
|
dscan.c = zero;
|
|
|
|
|
|
|
|
GSVertexSW dv = v[1] - v[0];
|
|
|
|
|
|
|
|
dedge.t = (dv.t / dv.p.yyyy()).xyxy(zero).wyww();
|
|
|
|
dscan.t = (dv.t / dv.p.xxxx()).xyxy(zero).xwww();
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
if(scan.p.y < (float)r.top) scan.t += dedge.t * ((float)r.top - scan.p.y);
|
|
|
|
if(scan.p.x < (float)r.left) scan.t += dscan.t * ((float)r.left - scan.p.x);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-02-20 10:59:10 +00:00
|
|
|
m_dsf.ssp(v, dscan);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
for(; r.top < r.bottom; r.top++, scan.t += dedge.t)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-05-14 16:41:52 +00:00
|
|
|
if((r.top % m_threads) == m_id)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-05-14 16:41:52 +00:00
|
|
|
m_dsf.ssl(r.right, r.left, r.top, scan);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
m_stats.pixels += r.width();
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-09 01:42:56 +00:00
|
|
|
void GSRasterizer::DrawEdge(const GSVertexSW& v0, const GSVertexSW& v1, const GSVertexSW& dv, const GSVector4i& scissor, int orientation, int side)
|
|
|
|
{
|
|
|
|
// orientation:
|
|
|
|
// - true: |dv.p.y| > |dv.p.x|
|
|
|
|
// - false |dv.p.x| > |dv.p.y|
|
|
|
|
// side:
|
|
|
|
// - true: top/left edge
|
|
|
|
// - false: bottom/right edge
|
|
|
|
|
|
|
|
// TODO: bit slow and too much duplicated code
|
|
|
|
// TODO: inner pre-step is still missing (hardly noticable)
|
|
|
|
|
|
|
|
GSVector4 fscissor(scissor);
|
|
|
|
|
|
|
|
GSVector4 lrtb = v0.p.upl(v1.p).ceil();
|
|
|
|
|
|
|
|
if(orientation)
|
|
|
|
{
|
|
|
|
GSVector4 tbmax = lrtb.maxv(fscissor.yyyy());
|
|
|
|
GSVector4 tbmin = lrtb.minv(fscissor.wwww());
|
|
|
|
|
|
|
|
GSVector4i tbi = GSVector4i(tbmax.zwzw(tbmin));
|
|
|
|
|
|
|
|
int top, bottom;
|
|
|
|
|
|
|
|
GSVertexSW edge, dedge;
|
|
|
|
|
|
|
|
if((dv.p >= GSVector4::zero()).mask() & 2)
|
|
|
|
{
|
|
|
|
top = tbi.extract32<0>();
|
|
|
|
bottom = tbi.extract32<3>();
|
|
|
|
|
|
|
|
if(top >= bottom) return;
|
|
|
|
|
|
|
|
edge = v0;
|
|
|
|
dedge = dv / dv.p.yyyy();
|
|
|
|
|
|
|
|
edge += dedge * (tbmax.zzzz() - edge.p.yyyy());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
top = tbi.extract32<1>();
|
|
|
|
bottom = tbi.extract32<2>();
|
|
|
|
|
|
|
|
if(top >= bottom) return;
|
|
|
|
|
|
|
|
edge = v1;
|
|
|
|
dedge = dv / dv.p.yyyy();
|
|
|
|
|
|
|
|
edge += dedge * (tbmax.wwww() - edge.p.yyyy());
|
|
|
|
}
|
|
|
|
|
2009-03-16 22:17:50 +00:00
|
|
|
GSVector4i p = GSVector4i(edge.p.upl(dedge.p) * 0x10000);
|
|
|
|
|
|
|
|
int x = p.extract32<0>();
|
|
|
|
int dx = p.extract32<1>();
|
|
|
|
|
2009-03-09 01:42:56 +00:00
|
|
|
if(side)
|
|
|
|
{
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
2009-03-16 22:17:50 +00:00
|
|
|
int xi = x >> 16;
|
|
|
|
int xf = x & 0xffff;
|
2009-03-09 01:42:56 +00:00
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
if(scissor.left <= xi && xi < scissor.right && (xi % m_threads) == m_id)
|
2009-03-16 22:17:50 +00:00
|
|
|
{
|
|
|
|
m_stats.pixels++;
|
2009-03-09 01:42:56 +00:00
|
|
|
|
2009-03-16 22:17:50 +00:00
|
|
|
edge.t.u32[3] = (0x10000 - xf) & 0xffff;
|
2009-03-09 01:42:56 +00:00
|
|
|
|
2009-03-16 22:17:50 +00:00
|
|
|
m_dsf.ssle(xi + 1, xi, top, edge);
|
|
|
|
|
|
|
|
edge.t.u32[3] = 0;
|
2009-03-09 01:42:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
while(0);
|
|
|
|
|
|
|
|
if(++top >= bottom) break;
|
|
|
|
|
|
|
|
edge += dedge;
|
2009-03-16 22:17:50 +00:00
|
|
|
x += dx;
|
2009-03-09 01:42:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
2009-03-16 22:17:50 +00:00
|
|
|
int xi = (x >> 16) + 1;
|
|
|
|
int xf = x & 0xffff;
|
2009-03-09 01:42:56 +00:00
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
if(scissor.left <= xi && xi < scissor.right && (xi % m_threads) == m_id)
|
2009-03-16 22:17:50 +00:00
|
|
|
{
|
|
|
|
m_stats.pixels++;
|
2009-03-09 01:42:56 +00:00
|
|
|
|
2009-03-16 22:17:50 +00:00
|
|
|
edge.t.u32[3] = xf;
|
2009-03-09 01:42:56 +00:00
|
|
|
|
2009-03-16 22:17:50 +00:00
|
|
|
m_dsf.ssle(xi + 1, xi, top, edge);
|
2009-03-09 01:42:56 +00:00
|
|
|
|
2009-03-16 22:17:50 +00:00
|
|
|
edge.t.u32[3] = 0;
|
2009-03-09 01:42:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
while(0);
|
|
|
|
|
|
|
|
if(++top >= bottom) break;
|
|
|
|
|
|
|
|
edge += dedge;
|
2009-03-16 22:17:50 +00:00
|
|
|
x += dx;
|
2009-03-09 01:42:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GSVector4 lrmax = lrtb.maxv(fscissor.xxxx());
|
|
|
|
GSVector4 lrmin = lrtb.minv(fscissor.zzzz());
|
|
|
|
|
|
|
|
GSVector4i lri = GSVector4i(lrmax.xyxy(lrmin));
|
|
|
|
|
|
|
|
int left, right;
|
|
|
|
|
|
|
|
GSVertexSW edge, dedge;
|
|
|
|
|
|
|
|
if((dv.p >= GSVector4::zero()).mask() & 1)
|
|
|
|
{
|
|
|
|
left = lri.extract32<0>();
|
|
|
|
right = lri.extract32<3>();
|
|
|
|
|
|
|
|
if(left >= right) return;
|
|
|
|
|
|
|
|
edge = v0;
|
|
|
|
dedge = dv / dv.p.xxxx();
|
|
|
|
|
|
|
|
edge += dedge * (lrmax.xxxx() - edge.p.xxxx());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
left = lri.extract32<1>();
|
|
|
|
right = lri.extract32<2>();
|
|
|
|
|
|
|
|
if(left >= right) return;
|
|
|
|
|
|
|
|
edge = v1;
|
|
|
|
dedge = dv / dv.p.xxxx();
|
|
|
|
|
|
|
|
edge += dedge * (lrmax.yyyy() - edge.p.xxxx());
|
|
|
|
}
|
|
|
|
|
2009-03-16 22:17:50 +00:00
|
|
|
GSVector4i p = GSVector4i(edge.p.upl(dedge.p) * 0x10000);
|
|
|
|
|
|
|
|
int y = p.extract32<2>();
|
|
|
|
int dy = p.extract32<3>();
|
|
|
|
|
2009-03-09 01:42:56 +00:00
|
|
|
if(side)
|
|
|
|
{
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
2009-03-16 22:17:50 +00:00
|
|
|
int yi = y >> 16;
|
|
|
|
int yf = y & 0xffff;
|
2009-03-09 01:42:56 +00:00
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
if(scissor.top <= yi && yi < scissor.bottom && (yi % m_threads) == m_id)
|
2009-03-16 22:17:50 +00:00
|
|
|
{
|
|
|
|
m_stats.pixels++;
|
2009-03-09 01:42:56 +00:00
|
|
|
|
2009-03-16 22:17:50 +00:00
|
|
|
edge.t.u32[3] = (0x10000 - yf) & 0xffff;
|
2009-03-09 01:42:56 +00:00
|
|
|
|
2009-03-16 22:17:50 +00:00
|
|
|
m_dsf.ssle(left + 1, left, yi, edge);
|
|
|
|
|
|
|
|
edge.t.u32[3] = 0;
|
2009-03-09 01:42:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
while(0);
|
|
|
|
|
|
|
|
if(++left >= right) break;
|
|
|
|
|
|
|
|
edge += dedge;
|
2009-03-16 22:17:50 +00:00
|
|
|
y += dy;
|
2009-03-09 01:42:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
2009-03-16 22:17:50 +00:00
|
|
|
int yi = (y >> 16) + 1;
|
|
|
|
int yf = y & 0xffff;
|
2009-03-09 01:42:56 +00:00
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
if(scissor.top <= yi && yi < scissor.bottom && (yi % m_threads) == m_id)
|
2009-03-16 22:17:50 +00:00
|
|
|
{
|
|
|
|
m_stats.pixels++;
|
2009-03-09 01:42:56 +00:00
|
|
|
|
2009-03-16 22:17:50 +00:00
|
|
|
edge.t.u32[3] = yf;
|
2009-03-09 01:42:56 +00:00
|
|
|
|
2009-03-16 22:17:50 +00:00
|
|
|
m_dsf.ssle(left + 1, left, yi, edge);
|
|
|
|
|
|
|
|
edge.t.u32[3] = 0;
|
2009-03-09 01:42:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
while(0);
|
|
|
|
|
|
|
|
if(++left >= right) break;
|
|
|
|
|
|
|
|
edge += dedge;
|
2009-03-16 22:17:50 +00:00
|
|
|
y += dy;
|
2009-03-09 01:42:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
GSRasterizerMT::GSRasterizerMT(IDrawScanline* ds, int id, int threads, long* sync)
|
|
|
|
: GSRasterizer(ds, id, threads)
|
|
|
|
, m_sync(sync)
|
|
|
|
, m_exit(false)
|
|
|
|
, m_data(NULL)
|
|
|
|
{
|
|
|
|
if(id > 0)
|
|
|
|
{
|
2009-05-14 16:41:52 +00:00
|
|
|
CreateThread();
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-16 01:42:08 +00:00
|
|
|
GSRasterizerMT::~GSRasterizerMT()
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-05-14 16:41:52 +00:00
|
|
|
m_exit = true;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GSRasterizerMT::Draw(const GSRasterizerData* data)
|
|
|
|
{
|
|
|
|
if(m_id == 0)
|
|
|
|
{
|
|
|
|
__super::Draw(data);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_data = data;
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
_interlockedbittestandset(m_sync, m_id);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
void GSRasterizerMT::ThreadProc()
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
// _mm_setcsr(MXCSR);
|
|
|
|
|
|
|
|
while(!m_exit)
|
|
|
|
{
|
|
|
|
if(*m_sync & (1 << m_id))
|
|
|
|
{
|
|
|
|
__super::Draw(m_data);
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
_interlockedbittestandreset(m_sync, m_id);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_mm_pause();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
GSRasterizerList::GSRasterizerList()
|
|
|
|
{
|
2009-02-22 16:28:39 +00:00
|
|
|
// User/Source Coding Rule 24. (M impact, ML generality) Place each
|
|
|
|
// synchronization variable alone, separated by 128 bytes or in a separate cache
|
|
|
|
// line.
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-02-22 16:28:39 +00:00
|
|
|
m_sync = (long*)_aligned_malloc(128, 64);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
*m_sync = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
GSRasterizerList::~GSRasterizerList()
|
|
|
|
{
|
2009-06-16 01:42:08 +00:00
|
|
|
FreeRasterizers();
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-06-16 01:42:08 +00:00
|
|
|
_aligned_free(m_sync);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GSRasterizerList::FreeRasterizers()
|
|
|
|
{
|
2009-05-11 08:18:00 +00:00
|
|
|
for(list<IRasterizer*>::iterator i = begin(); i != end(); i++)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-05-11 08:18:00 +00:00
|
|
|
delete *i;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
2009-05-11 08:18:00 +00:00
|
|
|
|
|
|
|
clear();
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GSRasterizerList::Draw(const GSRasterizerData* data)
|
|
|
|
{
|
|
|
|
*m_sync = 0;
|
|
|
|
|
|
|
|
m_stats.Reset();
|
|
|
|
|
2009-05-15 11:11:26 +00:00
|
|
|
int64 start = __rdtsc();
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-11 08:18:00 +00:00
|
|
|
for(list<IRasterizer*>::reverse_iterator i = rbegin(); i != rend(); i++)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-05-11 08:18:00 +00:00
|
|
|
(*i)->Draw(data);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
while(*m_sync)
|
|
|
|
{
|
|
|
|
_mm_pause();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_stats.ticks = __rdtsc() - start;
|
|
|
|
|
2009-05-11 08:18:00 +00:00
|
|
|
for(list<IRasterizer*>::iterator i = begin(); i != end(); i++)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
GSRasterizerStats s;
|
|
|
|
|
2009-05-11 08:18:00 +00:00
|
|
|
(*i)->GetStats(s);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
m_stats.pixels += s.pixels;
|
|
|
|
m_stats.prims = max(m_stats.prims, s.prims);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GSRasterizerList::GetStats(GSRasterizerStats& stats)
|
|
|
|
{
|
|
|
|
stats = m_stats;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GSRasterizerList::PrintStats()
|
|
|
|
{
|
2009-05-11 08:18:00 +00:00
|
|
|
if(!empty())
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-05-11 08:18:00 +00:00
|
|
|
front()->PrintStats();
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
}
|