2010-04-25 00:31:27 +00:00
|
|
|
/*
|
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.
|
2010-04-25 00:31:27 +00:00
|
|
|
*
|
2009-02-09 21:15:56 +00:00
|
|
|
* 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.
|
2010-04-25 00:31:27 +00:00
|
|
|
*
|
2009-02-09 21:15:56 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with GNU Make; see the file COPYING. If not, write to
|
2010-04-25 00:31:27 +00:00
|
|
|
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
2009-02-09 21:15:56 +00:00
|
|
|
* 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
|
|
|
|
2011-02-19 03:36:30 +00:00
|
|
|
#include "stdafx.h"
|
2009-02-09 21:15:56 +00:00
|
|
|
#include "GSRasterizer.h"
|
|
|
|
|
2009-12-03 23:08:52 +00:00
|
|
|
// Set this to 1 to remove a lot of non-const div/modulus ops from the rasterization process.
|
|
|
|
// Might likely be a measurable speedup but limits threading to 1, 2, 4, and 8 threads.
|
2009-12-03 23:30:59 +00:00
|
|
|
// note by rama: Speedup is around 5% on average.
|
2009-12-03 23:08:52 +00:00
|
|
|
|
2011-02-07 01:59:05 +00:00
|
|
|
// #define UseConstThreadCount
|
|
|
|
|
|
|
|
#ifdef UseConstThreadCount
|
2009-12-03 23:08:52 +00:00
|
|
|
// ThreadsConst - const number of threads. User-configured threads (in GSdx panel) must match
|
|
|
|
// this value if UseConstThreadCount is enabled. [yeah, it's hacky for now]
|
|
|
|
static const int ThreadsConst = 2;
|
2011-02-07 01:59:05 +00:00
|
|
|
static const int ThreadMaskConst = ThreadsConst - 1;
|
2009-12-03 23:08:52 +00:00
|
|
|
#endif
|
|
|
|
|
2011-02-17 18:22:47 +00:00
|
|
|
#define THREAD_HEIGHT 5
|
|
|
|
|
|
|
|
GSRasterizer::GSRasterizer(IDrawScanline* ds)
|
2009-02-09 21:15:56 +00:00
|
|
|
: m_ds(ds)
|
2011-02-17 18:22:47 +00:00
|
|
|
, m_id(0)
|
|
|
|
, m_threads(1)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2011-03-09 11:52:53 +00:00
|
|
|
m_edge.buff = (GSVertexSW*)vmalloc(sizeof(GSVertexSW) * 2048, false);
|
2011-03-08 01:48:15 +00:00
|
|
|
m_edge.count = 0;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GSRasterizer::~GSRasterizer()
|
|
|
|
{
|
2011-03-09 11:52:53 +00:00
|
|
|
if(m_edge.buff != NULL) vmfree(m_edge.buff, sizeof(GSVertexSW) * 2048);
|
2011-03-08 01:48:15 +00:00
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
delete m_ds;
|
|
|
|
}
|
|
|
|
|
2011-02-19 09:05:15 +00:00
|
|
|
bool GSRasterizer::IsOneOfMyScanlines(int scanline) const
|
2009-12-03 23:08:52 +00:00
|
|
|
{
|
2011-02-07 01:59:05 +00:00
|
|
|
#ifdef UseConstThreadCount
|
|
|
|
|
|
|
|
return ThreadMaskConst == 0 || (scanline & ThreadMaskConst) == m_id;
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2011-02-17 18:22:47 +00:00
|
|
|
return m_threads == 1 || ((scanline >> THREAD_HEIGHT) % m_threads) == m_id;
|
2011-02-07 01:59:05 +00:00
|
|
|
|
|
|
|
#endif
|
2009-12-03 23:08:52 +00:00
|
|
|
}
|
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
void GSRasterizer::Draw(const GSRasterizerData* data)
|
|
|
|
{
|
2011-02-17 18:22:47 +00:00
|
|
|
m_ds->BeginDraw(data->param);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
const GSVertexSW* vertices = data->vertices;
|
|
|
|
const int count = data->count;
|
|
|
|
|
2011-03-08 01:48:15 +00:00
|
|
|
m_scissor = data->scissor;
|
|
|
|
m_fscissor = GSVector4(data->scissor);
|
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
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;
|
2011-03-08 01:48:15 +00:00
|
|
|
for(int i = 0; i < count; i++) DrawPoint(&vertices[i]);
|
2009-02-09 21:15:56 +00:00
|
|
|
break;
|
|
|
|
case GS_LINE_CLASS:
|
|
|
|
ASSERT(!(count & 1));
|
|
|
|
m_stats.prims = count / 2;
|
2011-03-08 01:48:15 +00:00
|
|
|
for(int i = 0; i < count; i += 2) DrawLine(&vertices[i]);
|
2009-02-09 21:15:56 +00:00
|
|
|
break;
|
|
|
|
case GS_TRIANGLE_CLASS:
|
|
|
|
ASSERT(!(count % 3));
|
|
|
|
m_stats.prims = count / 3;
|
2011-03-08 01:48:15 +00:00
|
|
|
for(int i = 0; i < count; i += 3) DrawTriangle(&vertices[i]);
|
2009-02-09 21:15:56 +00:00
|
|
|
break;
|
|
|
|
case GS_SPRITE_CLASS:
|
|
|
|
ASSERT(!(count & 1));
|
|
|
|
m_stats.prims = count / 2;
|
2011-03-08 01:48:15 +00:00
|
|
|
for(int i = 0; i < count; i += 2) DrawSprite(&vertices[i]);
|
2009-02-09 21:15:56 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
__assume(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_stats.ticks = __rdtsc() - start;
|
|
|
|
|
2011-02-17 03:24:37 +00:00
|
|
|
m_ds->EndDraw(m_stats, data->frame);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GSRasterizer::GetStats(GSRasterizerStats& stats)
|
|
|
|
{
|
|
|
|
stats = m_stats;
|
|
|
|
}
|
|
|
|
|
2011-03-08 01:48:15 +00:00
|
|
|
void GSRasterizer::DrawPoint(const GSVertexSW* v)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
GSVector4i p(v->p);
|
|
|
|
|
2011-03-08 01:48:15 +00:00
|
|
|
if(m_scissor.left <= p.x && p.x < m_scissor.right && m_scissor.top <= p.y && p.y < m_scissor.bottom)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-12-03 23:08:52 +00:00
|
|
|
if(IsOneOfMyScanlines(p.y))
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2011-03-08 01:48:15 +00:00
|
|
|
m_stats.pixels++;
|
|
|
|
|
2011-02-16 03:19:36 +00:00
|
|
|
m_ds->SetupPrim(v, *v);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-02-16 03:19:36 +00:00
|
|
|
m_ds->DrawScanline(p.x + 1, p.x, p.y, *v);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-08 01:48:15 +00:00
|
|
|
void GSRasterizer::DrawLine(const GSVertexSW* v)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
GSVertexSW dv = v[1] - v[0];
|
|
|
|
|
|
|
|
GSVector4 dp = dv.p.abs();
|
2009-03-09 01:42:56 +00:00
|
|
|
|
2011-03-09 11:52:53 +00:00
|
|
|
int i = (dp < dp.yxwz()).mask() & 1; // |dx| <= |dy|
|
|
|
|
|
2011-02-16 03:19:36 +00:00
|
|
|
if(m_ds->IsEdge())
|
2009-03-09 01:42:56 +00:00
|
|
|
{
|
|
|
|
GSVertexSW dscan;
|
|
|
|
|
|
|
|
dscan.p = GSVector4::zero();
|
|
|
|
dscan.t = GSVector4::zero();
|
|
|
|
dscan.c = GSVector4::zero();
|
|
|
|
|
2011-03-08 01:48:15 +00:00
|
|
|
DrawEdge(v[0], v[1], dv, i, 0);
|
|
|
|
DrawEdge(v[0], v[1], dv, i, 1);
|
|
|
|
|
2011-03-09 11:52:53 +00:00
|
|
|
Flush(v, dscan, true);
|
2009-03-09 01:42:56 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2011-03-08 01:48:15 +00:00
|
|
|
if(m_scissor.top <= p.y && p.y < m_scissor.bottom)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
GSVertexSW dscan = dv / dv.p.xxxx();
|
|
|
|
|
|
|
|
l.p = l.p.upl(r).xyzw(l.p); // r.x => l.y
|
|
|
|
|
2011-03-08 01:48:15 +00:00
|
|
|
DrawTriangleSection(p.y, p.y + 1, l, dl, dscan);
|
2009-02-24 20:12:46 +00:00
|
|
|
|
2011-03-09 11:52:53 +00:00
|
|
|
Flush(v, dscan);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-03-09 11:52:53 +00:00
|
|
|
int steps = dpi.v[i];
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-03-09 11:52:53 +00:00
|
|
|
if(steps > 0)
|
|
|
|
{
|
|
|
|
GSVertexSW edge = v[0];
|
|
|
|
GSVertexSW dedge = dv / GSVector4(dp.v[i]);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-03-09 11:52:53 +00:00
|
|
|
GSVertexSW* RESTRICT e = m_edge.buff;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-03-09 11:52:53 +00:00
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
GSVector4i p(edge.p);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-03-09 11:52:53 +00:00
|
|
|
if(m_scissor.left <= p.x && p.x < m_scissor.right && m_scissor.top <= p.y && p.y < m_scissor.bottom)
|
|
|
|
{
|
|
|
|
if(IsOneOfMyScanlines(p.y))
|
|
|
|
{
|
|
|
|
*e = edge;
|
|
|
|
|
|
|
|
e->p.i16[0] = (int16)p.x;
|
|
|
|
e->p.i16[1] = (int16)p.y;
|
|
|
|
e->p.i16[2] = (int16)(p.x + 1);
|
|
|
|
|
|
|
|
e++;
|
|
|
|
}
|
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-03-09 11:52:53 +00:00
|
|
|
if(--steps == 0) break;
|
|
|
|
|
|
|
|
edge += dedge;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_edge.count = e - m_edge.buff;
|
|
|
|
|
|
|
|
m_stats.pixels += m_edge.count;
|
|
|
|
|
|
|
|
GSVertexSW dscan;
|
|
|
|
|
|
|
|
dscan.p = GSVector4::zero();
|
|
|
|
dscan.t = GSVector4::zero();
|
|
|
|
dscan.c = GSVector4::zero();
|
|
|
|
|
|
|
|
Flush(v, dscan);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
static const int s_abc[8][4] =
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
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
|
|
|
};
|
|
|
|
|
2011-03-08 01:48:15 +00:00
|
|
|
void GSRasterizer::DrawTriangle(const GSVertexSW* vertices)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2011-03-09 11:52:53 +00:00
|
|
|
// TODO: GSVertexSW::c/t could be merged into a GSVector8
|
2011-03-08 01:48:15 +00:00
|
|
|
|
|
|
|
GSVertexSW v[4];
|
|
|
|
GSVertexSW dv[3];
|
|
|
|
GSVertexSW ddv[3];
|
|
|
|
GSVertexSW longest;
|
|
|
|
GSVertexSW dscan;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
GSVector4 aabb = vertices[0].p.yyyy(vertices[1].p);
|
|
|
|
GSVector4 bccb = vertices[1].p.yyyy(vertices[2].p).xzzx();
|
|
|
|
|
2011-03-08 01:48:15 +00:00
|
|
|
int abc = (aabb > bccb).mask() & 7;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-03-08 01:48:15 +00:00
|
|
|
v[0] = vertices[s_abc[abc][0]];
|
|
|
|
v[1] = vertices[s_abc[abc][1]];
|
|
|
|
v[2] = vertices[s_abc[abc][2]];
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
aabb = v[0].p.yyyy(v[1].p);
|
|
|
|
bccb = v[1].p.yyyy(v[2].p).xzzx();
|
|
|
|
|
2011-03-08 01:48:15 +00:00
|
|
|
int i = (aabb == bccb).mask() & 7;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-03-08 01:48:15 +00:00
|
|
|
GSVector4 tbf = aabb.xzxz(bccb).ceil();
|
|
|
|
GSVector4 tbmax = tbf.max(m_fscissor.yyyy());
|
|
|
|
GSVector4 tbmin = tbf.min(m_fscissor.wwww());
|
|
|
|
GSVector4i tb = GSVector4i(tbmax.xzyw(tbmin));
|
|
|
|
|
|
|
|
dv[0] = v[1] - v[0];
|
|
|
|
dv[1] = v[2] - v[0];
|
|
|
|
dv[2] = v[2] - v[1];
|
2009-03-09 01:42:56 +00:00
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
switch(i)
|
|
|
|
{
|
|
|
|
case 0: // a < b < c
|
2011-03-08 01:48:15 +00:00
|
|
|
ddv[0] = dv[0] / dv[0].p.yyyy();
|
|
|
|
ddv[1] = dv[1] / dv[1].p.yyyy();
|
|
|
|
ddv[2] = dv[2] / dv[2].p.yyyy();
|
|
|
|
longest = ddv[1] * dv[0].p.yyyy() - dv[0];
|
|
|
|
v[3] = v[1] + longest; // point between v[0] and v[2] where y == v[1].y
|
2009-02-09 21:15:56 +00:00
|
|
|
break;
|
|
|
|
case 1: // a == b < c
|
2011-03-08 01:48:15 +00:00
|
|
|
ddv[1] = dv[1] / dv[1].p.yyyy();
|
|
|
|
ddv[2] = dv[2] / dv[2].p.yyyy();
|
2011-03-09 11:52:53 +00:00
|
|
|
longest = dv[0]; // should be negated to be equal to "ddv[1] * dv[0].p.yyyy() - dv[0]", but it's easier to change the index of v/ddv later
|
2009-02-09 21:15:56 +00:00
|
|
|
break;
|
|
|
|
case 4: // a < b == c
|
2011-03-08 01:48:15 +00:00
|
|
|
ddv[0] = dv[0] / dv[0].p.yyyy();
|
|
|
|
ddv[1] = dv[1] / dv[1].p.yyyy();
|
|
|
|
longest = dv[2];
|
2009-02-09 21:15:56 +00:00
|
|
|
break;
|
|
|
|
case 7: // a == b == c
|
2011-03-08 01:48:15 +00:00
|
|
|
return;
|
2009-02-09 21:15:56 +00:00
|
|
|
default:
|
|
|
|
__assume(0);
|
|
|
|
}
|
|
|
|
|
2011-03-08 01:48:15 +00:00
|
|
|
int j = longest.p.upl(longest.p == GSVector4::zero()).mask();
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-03-08 01:48:15 +00:00
|
|
|
if(j & 2) return;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-03-08 01:48:15 +00:00
|
|
|
j &= 1;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-03-08 01:48:15 +00:00
|
|
|
dscan = longest * longest.p.xxxx().rcp();
|
|
|
|
|
|
|
|
if(m_ds->IsEdge())
|
|
|
|
{
|
|
|
|
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);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-03-08 01:48:15 +00:00
|
|
|
GSVector4 a = dx.abs() < dy.abs(); // |dx| <= |dy|
|
|
|
|
GSVector4 b = dx < GSVector4::zero(); // dx < 0
|
|
|
|
GSVector4 c = longest.p.xxxx() < GSVector4::zero(); // longest.p.x < 0
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-03-08 01:48:15 +00:00
|
|
|
int i = a.mask();
|
|
|
|
int j = ((a | b) ^ c).mask() ^ 2; // evil
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-03-08 01:48:15 +00:00
|
|
|
DrawEdge(v[0], v[1], dv[0], i & 1, j & 1);
|
|
|
|
DrawEdge(v[0], v[2], dv[1], i & 2, j & 2);
|
|
|
|
DrawEdge(v[1], v[2], dv[2], i & 4, j & 4);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-03-08 01:48:15 +00:00
|
|
|
GSVertexSW dscan;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-03-08 01:48:15 +00:00
|
|
|
dscan.p = GSVector4::zero();
|
|
|
|
dscan.t = GSVector4::zero();
|
|
|
|
dscan.c = GSVector4::zero();
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-03-09 11:52:53 +00:00
|
|
|
Flush(v, dscan, true);
|
2011-03-08 01:48:15 +00:00
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-03-08 01:48:15 +00:00
|
|
|
switch(i)
|
|
|
|
{
|
|
|
|
case 0: // a < b < c
|
|
|
|
|
|
|
|
if(tb.x < tb.z)
|
|
|
|
{
|
|
|
|
GSVertexSW l = v[0];
|
|
|
|
GSVertexSW dl = ddv[j];
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-03-08 01:48:15 +00:00
|
|
|
GSVector4 dy = tbmax.xxxx() - l.p.yyyy();
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-03-08 01:48:15 +00:00
|
|
|
l.p = l.p.xxzw(); // r.x => l.y
|
|
|
|
dl.p = dl.p.upl(ddv[1 - j].p).xyzw(dl.p); // dr.x => dl.y
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-03-08 01:48:15 +00:00
|
|
|
l += dl * dy;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-03-08 01:48:15 +00:00
|
|
|
DrawTriangleSection(tb.x, tb.z, l, dl, dscan);
|
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-03-08 01:48:15 +00:00
|
|
|
if(tb.y < tb.w)
|
|
|
|
{
|
|
|
|
GSVertexSW l = v[1 + (1 << j)];
|
|
|
|
GSVertexSW dl = ddv[2 - j];
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-03-08 01:48:15 +00:00
|
|
|
GSVector4 dy = tbmax.zzzz() - l.p.yyyy();
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-03-08 01:48:15 +00:00
|
|
|
l.p = l.p.upl(v[3 - (1 << j)].p).xyzw(l.p); // r.x => l.y
|
|
|
|
dl.p = dl.p.upl(ddv[1 + j].p).xyzw(dl.p); // dr.x => dl.y
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-03-08 01:48:15 +00:00
|
|
|
l += dl * dy;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-03-08 01:48:15 +00:00
|
|
|
DrawTriangleSection(tb.y, tb.w, l, dl, dscan);
|
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-03-08 01:48:15 +00:00
|
|
|
break;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-03-08 01:48:15 +00:00
|
|
|
case 1: // a == b < c
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-03-08 01:48:15 +00:00
|
|
|
if(tb.x < tb.w)
|
|
|
|
{
|
|
|
|
GSVertexSW l = v[j];
|
|
|
|
GSVertexSW dl = ddv[1 + j];
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-03-08 01:48:15 +00:00
|
|
|
GSVector4 dy = tbmax.xxxx() - l.p.yyyy();
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-03-08 01:48:15 +00:00
|
|
|
l.p = l.p.upl(v[1 - j].p).xyzw(l.p); // r.x => l.y
|
|
|
|
dl.p = dl.p.upl(ddv[2 - j].p).xyzw(dl.p); // dr.x => dl.y
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-03-08 01:48:15 +00:00
|
|
|
l += dl * dy;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-03-08 01:48:15 +00:00
|
|
|
DrawTriangleSection(tb.x, tb.w, l, dl, dscan);
|
2009-02-24 20:12:46 +00:00
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-03-08 01:48:15 +00:00
|
|
|
break;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-03-08 01:48:15 +00:00
|
|
|
case 4: // a < b == c
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-03-08 01:48:15 +00:00
|
|
|
if(tb.x < tb.w)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2011-03-08 01:48:15 +00:00
|
|
|
GSVertexSW l = v[0];
|
|
|
|
GSVertexSW dl = ddv[j];
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-03-08 01:48:15 +00:00
|
|
|
GSVector4 dy = tbmax.xxxx() - l.p.yyyy();
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-03-08 01:48:15 +00:00
|
|
|
l.p = l.p.xxzw(); // r.x => l.y
|
|
|
|
dl.p = dl.p.upl(ddv[1 - j].p).xyzw(dl.p); // dr.x => dl.y
|
2009-02-19 13:13:20 +00:00
|
|
|
|
2011-03-08 01:48:15 +00:00
|
|
|
l += dl * dy;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-03-08 01:48:15 +00:00
|
|
|
DrawTriangleSection(tb.x, tb.w, l, dl, dscan);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2011-03-08 01:48:15 +00:00
|
|
|
break;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-03-08 01:48:15 +00:00
|
|
|
default:
|
|
|
|
__assume(0);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
2011-03-08 01:48:15 +00:00
|
|
|
|
2011-03-09 11:52:53 +00:00
|
|
|
Flush(v, dscan);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2011-03-08 01:48:15 +00:00
|
|
|
void GSRasterizer::DrawTriangleSection(int top, int bottom, GSVertexSW& l, const GSVertexSW& dl, const GSVertexSW& dscan)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
ASSERT(top < bottom);
|
|
|
|
|
2011-03-09 11:52:53 +00:00
|
|
|
GSVertexSW* RESTRICT e = &m_edge.buff[m_edge.count];
|
2011-03-08 01:48:15 +00:00
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
while(1)
|
|
|
|
{
|
2011-03-09 11:52:53 +00:00
|
|
|
if(IsOneOfMyScanlines(top))
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2011-03-09 11:52:53 +00:00
|
|
|
GSVector4 lrf = l.p.ceil();
|
|
|
|
GSVector4 lrmax = lrf.max(m_fscissor.xxxx());
|
|
|
|
GSVector4 lrmin = lrf.min(m_fscissor.zzzz());
|
|
|
|
GSVector4i lr = GSVector4i(lrmax.xxyy(lrmin));
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-03-09 11:52:53 +00:00
|
|
|
int left = lr.extract32<0>();
|
|
|
|
int right = lr.extract32<2>();
|
2009-02-19 13:13:20 +00:00
|
|
|
|
2011-03-09 11:52:53 +00:00
|
|
|
int pixels = right - left;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-03-09 11:52:53 +00:00
|
|
|
if(pixels > 0)
|
|
|
|
{
|
|
|
|
m_stats.pixels += pixels;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-03-09 11:52:53 +00:00
|
|
|
*e = l + dscan * (lrmax - l.p).xxxx();
|
2011-03-08 01:48:15 +00:00
|
|
|
|
2011-03-09 11:52:53 +00:00
|
|
|
e->p.i16[0] = (int16)left;
|
|
|
|
e->p.i16[1] = (int16)top;
|
|
|
|
e->p.i16[2] = (int16)right;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-03-09 11:52:53 +00:00
|
|
|
e++;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(++top >= bottom) break;
|
|
|
|
|
|
|
|
l += dl;
|
|
|
|
}
|
2011-03-08 01:48:15 +00:00
|
|
|
|
|
|
|
m_edge.count += e - &m_edge.buff[m_edge.count];
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2011-03-08 01:48:15 +00:00
|
|
|
void GSRasterizer::DrawSprite(const GSVertexSW* vertices)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
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());
|
|
|
|
|
2011-03-08 01:48:15 +00:00
|
|
|
r = r.rintersect(m_scissor);
|
2010-04-25 00:31:27 +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];
|
|
|
|
|
2011-02-16 03:19:36 +00:00
|
|
|
if(m_ds->IsRect())
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
if(m_id == 0)
|
|
|
|
{
|
2011-02-16 03:19:36 +00:00
|
|
|
m_ds->DrawRect(r, scan);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
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
|
|
|
|
2011-02-16 03:19:36 +00:00
|
|
|
m_ds->SetupPrim(v, dscan);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-03-09 11:52:53 +00:00
|
|
|
while(1)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2010-04-25 00:31:27 +00:00
|
|
|
if(IsOneOfMyScanlines(r.top))
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-05-14 16:41:52 +00:00
|
|
|
m_stats.pixels += r.width();
|
2011-03-08 01:48:15 +00:00
|
|
|
|
|
|
|
m_ds->DrawScanline(r.right, r.left, r.top, scan);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
2011-03-09 11:52:53 +00:00
|
|
|
|
|
|
|
if(++r.top >= r.bottom) break;
|
|
|
|
|
|
|
|
scan.t += dedge.t;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-08 01:48:15 +00:00
|
|
|
void GSRasterizer::DrawEdge(const GSVertexSW& v0, const GSVertexSW& v1, const GSVertexSW& dv, int orientation, int side)
|
2009-03-09 01:42:56 +00:00
|
|
|
{
|
2010-04-25 00:31:27 +00:00
|
|
|
// orientation:
|
2009-03-09 01:42:56 +00:00
|
|
|
// - true: |dv.p.y| > |dv.p.x|
|
2010-04-25 00:31:27 +00:00
|
|
|
// - false |dv.p.x| > |dv.p.y|
|
|
|
|
// side:
|
2009-03-09 01:42:56 +00:00
|
|
|
// - 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)
|
|
|
|
|
2011-03-09 11:52:53 +00:00
|
|
|
GSVertexSW* RESTRICT e = &m_edge.buff[m_edge.count];
|
2011-03-08 01:48:15 +00:00
|
|
|
|
2009-03-09 01:42:56 +00:00
|
|
|
GSVector4 lrtb = v0.p.upl(v1.p).ceil();
|
|
|
|
|
|
|
|
if(orientation)
|
|
|
|
{
|
2011-03-08 01:48:15 +00:00
|
|
|
GSVector4 tbmax = lrtb.max(m_fscissor.yyyy());
|
|
|
|
GSVector4 tbmin = lrtb.min(m_fscissor.wwww());
|
2009-03-09 01:42:56 +00:00
|
|
|
|
2011-03-09 11:52:53 +00:00
|
|
|
GSVector4i tb = GSVector4i(tbmax.zwzw(tbmin));
|
2009-03-09 01:42:56 +00:00
|
|
|
|
|
|
|
int top, bottom;
|
|
|
|
|
|
|
|
GSVertexSW edge, dedge;
|
|
|
|
|
|
|
|
if((dv.p >= GSVector4::zero()).mask() & 2)
|
|
|
|
{
|
2011-03-09 11:52:53 +00:00
|
|
|
top = tb.extract32<0>();
|
|
|
|
bottom = tb.extract32<3>();
|
2009-03-09 01:42:56 +00:00
|
|
|
|
|
|
|
if(top >= bottom) return;
|
|
|
|
|
|
|
|
edge = v0;
|
|
|
|
dedge = dv / dv.p.yyyy();
|
|
|
|
|
|
|
|
edge += dedge * (tbmax.zzzz() - edge.p.yyyy());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-03-09 11:52:53 +00:00
|
|
|
top = tb.extract32<1>();
|
|
|
|
bottom = tb.extract32<2>();
|
2009-03-09 01:42:56 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2011-03-09 11:52:53 +00:00
|
|
|
int xi = x >> 16;
|
|
|
|
int xf = x & 0xffff;
|
|
|
|
|
|
|
|
if(m_scissor.left <= xi && xi < m_scissor.right && IsOneOfMyScanlines(xi))
|
2009-03-09 01:42:56 +00:00
|
|
|
{
|
2011-03-09 11:52:53 +00:00
|
|
|
m_stats.pixels++;
|
2009-03-09 01:42:56 +00:00
|
|
|
|
2011-03-09 11:52:53 +00:00
|
|
|
*e = edge;
|
2009-03-09 01:42:56 +00:00
|
|
|
|
2011-03-09 11:52:53 +00:00
|
|
|
e->t.u32[3] = (0x10000 - xf) & 0xffff;
|
2009-03-09 01:42:56 +00:00
|
|
|
|
2011-03-09 11:52:53 +00:00
|
|
|
e->p.i16[0] = (int16)xi;
|
|
|
|
e->p.i16[1] = (int16)top;
|
|
|
|
e->p.i16[2] = (int16)(xi + 1);
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2011-03-09 11:52:53 +00:00
|
|
|
e++;
|
2009-03-09 01:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2011-03-09 11:52:53 +00:00
|
|
|
int xi = (x >> 16) + 1;
|
|
|
|
int xf = x & 0xffff;
|
|
|
|
|
|
|
|
if(m_scissor.left <= xi && xi < m_scissor.right && IsOneOfMyScanlines(xi))
|
2009-03-09 01:42:56 +00:00
|
|
|
{
|
2011-03-09 11:52:53 +00:00
|
|
|
m_stats.pixels++;
|
2009-03-09 01:42:56 +00:00
|
|
|
|
2011-03-09 11:52:53 +00:00
|
|
|
*e = edge;
|
2009-03-09 01:42:56 +00:00
|
|
|
|
2011-03-09 11:52:53 +00:00
|
|
|
e->t.u32[3] = xf;
|
2009-03-09 01:42:56 +00:00
|
|
|
|
2011-03-09 11:52:53 +00:00
|
|
|
e->p.i16[0] = (int16)xi;
|
|
|
|
e->p.i16[1] = (int16)top;
|
|
|
|
e->p.i16[2] = (int16)(xi + 1);
|
2009-03-09 01:42:56 +00:00
|
|
|
|
2011-03-09 11:52:53 +00:00
|
|
|
e++;
|
2009-03-09 01:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2011-03-08 01:48:15 +00:00
|
|
|
GSVector4 lrmax = lrtb.max(m_fscissor.xxxx());
|
|
|
|
GSVector4 lrmin = lrtb.min(m_fscissor.zzzz());
|
2009-03-09 01:42:56 +00:00
|
|
|
|
2011-03-09 11:52:53 +00:00
|
|
|
GSVector4i lr = GSVector4i(lrmax.xyxy(lrmin));
|
2009-03-09 01:42:56 +00:00
|
|
|
|
|
|
|
int left, right;
|
|
|
|
|
|
|
|
GSVertexSW edge, dedge;
|
|
|
|
|
|
|
|
if((dv.p >= GSVector4::zero()).mask() & 1)
|
|
|
|
{
|
2011-03-09 11:52:53 +00:00
|
|
|
left = lr.extract32<0>();
|
|
|
|
right = lr.extract32<3>();
|
2009-03-09 01:42:56 +00:00
|
|
|
|
|
|
|
if(left >= right) return;
|
|
|
|
|
|
|
|
edge = v0;
|
|
|
|
dedge = dv / dv.p.xxxx();
|
|
|
|
|
|
|
|
edge += dedge * (lrmax.xxxx() - edge.p.xxxx());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-03-09 11:52:53 +00:00
|
|
|
left = lr.extract32<1>();
|
|
|
|
right = lr.extract32<2>();
|
2009-03-09 01:42:56 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2011-03-09 11:52:53 +00:00
|
|
|
int yi = y >> 16;
|
|
|
|
int yf = y & 0xffff;
|
2009-03-09 01:42:56 +00:00
|
|
|
|
2011-03-09 11:52:53 +00:00
|
|
|
if(m_scissor.top <= yi && yi < m_scissor.bottom && IsOneOfMyScanlines(yi))
|
|
|
|
{
|
|
|
|
m_stats.pixels++;
|
2009-03-09 01:42:56 +00:00
|
|
|
|
2011-03-09 11:52:53 +00:00
|
|
|
*e = edge;
|
|
|
|
|
|
|
|
e->t.u32[3] = (0x10000 - yf) & 0xffff;
|
2009-03-09 01:42:56 +00:00
|
|
|
|
2011-03-09 11:52:53 +00:00
|
|
|
e->p.i16[0] = (int16)left;
|
|
|
|
e->p.i16[1] = (int16)yi;
|
|
|
|
e->p.i16[2] = (int16)(left + 1);
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2011-03-09 11:52:53 +00:00
|
|
|
e++;
|
2009-03-09 01:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2011-03-09 11:52:53 +00:00
|
|
|
int yi = (y >> 16) + 1;
|
|
|
|
int yf = y & 0xffff;
|
2009-03-09 01:42:56 +00:00
|
|
|
|
2011-03-09 11:52:53 +00:00
|
|
|
if(m_scissor.top <= yi && yi < m_scissor.bottom && IsOneOfMyScanlines(yi))
|
|
|
|
{
|
|
|
|
m_stats.pixels++;
|
2009-03-09 01:42:56 +00:00
|
|
|
|
2011-03-09 11:52:53 +00:00
|
|
|
*e = edge;
|
|
|
|
|
|
|
|
e->t.u32[3] = yf;
|
2009-03-09 01:42:56 +00:00
|
|
|
|
2011-03-09 11:52:53 +00:00
|
|
|
e->p.i16[0] = (int16)left;
|
|
|
|
e->p.i16[1] = (int16)yi;
|
|
|
|
e->p.i16[2] = (int16)(left + 1);
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2011-03-09 11:52:53 +00:00
|
|
|
e++;
|
2009-03-09 01:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(++left >= right) break;
|
|
|
|
|
|
|
|
edge += dedge;
|
2009-03-16 22:17:50 +00:00
|
|
|
y += dy;
|
2009-03-09 01:42:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-03-08 01:48:15 +00:00
|
|
|
|
2011-03-09 11:52:53 +00:00
|
|
|
m_edge.count += e - &m_edge.buff[m_edge.count];
|
2011-03-08 01:48:15 +00:00
|
|
|
}
|
|
|
|
|
2011-03-09 11:52:53 +00:00
|
|
|
void GSRasterizer::Flush(const GSVertexSW* vertices, const GSVertexSW& dscan, bool edge)
|
2011-03-08 01:48:15 +00:00
|
|
|
{
|
|
|
|
// TODO: on win64 this could be the place where xmm6-15 are preserved (not by each DrawScanline)
|
|
|
|
|
2011-03-09 11:52:53 +00:00
|
|
|
int count = m_edge.count;
|
2011-03-08 01:48:15 +00:00
|
|
|
|
2011-03-09 11:52:53 +00:00
|
|
|
if(count > 0)
|
2011-03-08 01:48:15 +00:00
|
|
|
{
|
2011-03-09 11:52:53 +00:00
|
|
|
m_ds->SetupPrim(vertices, dscan);
|
2011-03-08 01:48:15 +00:00
|
|
|
|
2011-03-09 11:52:53 +00:00
|
|
|
const GSVertexSW* RESTRICT e = m_edge.buff;
|
2011-03-08 01:48:15 +00:00
|
|
|
|
2011-03-09 11:52:53 +00:00
|
|
|
int i = 0;
|
2011-03-08 01:48:15 +00:00
|
|
|
|
2011-03-09 11:52:53 +00:00
|
|
|
if(!edge)
|
|
|
|
{
|
|
|
|
do {m_ds->DrawScanline(e[i].p.i16[2], e[i].p.i16[0], e[i].p.i16[1], e[i]);}
|
|
|
|
while(++i < count);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
do {m_ds->DrawEdge(e[i].p.i16[2], e[i].p.i16[0], e[i].p.i16[1], e[i]);}
|
|
|
|
while(++i < count);
|
|
|
|
}
|
2011-03-08 01:48:15 +00:00
|
|
|
|
2011-03-09 11:52:53 +00:00
|
|
|
m_edge.count = 0;
|
|
|
|
}
|
2009-03-09 01:42:56 +00:00
|
|
|
}
|
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
//
|
|
|
|
|
2011-02-19 03:36:30 +00:00
|
|
|
GSRasterizerMT::GSRasterizerMT(IDrawScanline* ds, volatile long& sync)
|
2011-02-17 18:22:47 +00:00
|
|
|
: GSRasterizer(ds)
|
2009-02-09 21:15:56 +00:00
|
|
|
, m_sync(sync)
|
|
|
|
, m_data(NULL)
|
|
|
|
{
|
2009-12-03 23:08: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
|
|
|
{
|
2011-02-19 03:36:30 +00:00
|
|
|
Draw(NULL);
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2011-02-12 21:45:16 +00:00
|
|
|
CloseThread();
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GSRasterizerMT::Draw(const GSRasterizerData* data)
|
|
|
|
{
|
2009-12-03 23:08:52 +00:00
|
|
|
m_data = data;
|
2011-02-12 21:45:16 +00:00
|
|
|
|
2011-02-19 03:36:30 +00:00
|
|
|
m_draw.Set();
|
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
|
|
|
{
|
2011-02-19 03:36:30 +00:00
|
|
|
while(m_draw.Wait() && m_data != NULL)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2011-02-19 03:36:30 +00:00
|
|
|
GSRasterizer::Draw(m_data);
|
2011-02-12 21:45:16 +00:00
|
|
|
|
2011-02-19 03:36:30 +00:00
|
|
|
_interlockedbittestandreset(&m_sync, m_id);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
GSRasterizerList::GSRasterizerList()
|
2011-02-17 03:24:37 +00:00
|
|
|
: m_sync(0)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
GSRasterizerList::~GSRasterizerList()
|
|
|
|
{
|
2011-02-12 21:45:16 +00:00
|
|
|
for(size_t i = 0; i < size(); i++) delete (*this)[i];
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2011-02-16 03:19:36 +00:00
|
|
|
void GSRasterizerList::Sync()
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2011-02-07 01:59:05 +00:00
|
|
|
while(m_sync) _mm_pause();
|
|
|
|
|
2011-02-16 03:19:36 +00:00
|
|
|
m_stats.ticks = __rdtsc() - m_start;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-02-17 18:22:47 +00:00
|
|
|
for(int i = 0; i < m_threads; i++)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
GSRasterizerStats s;
|
|
|
|
|
2009-12-03 23:08:52 +00:00
|
|
|
(*this)[i]->GetStats(s);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
m_stats.pixels += s.pixels;
|
2011-02-07 01:59:05 +00:00
|
|
|
m_stats.prims = std::max<int>(m_stats.prims, s.prims);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-17 18:22:47 +00:00
|
|
|
void GSRasterizerList::Draw(const GSRasterizerData* data, int width, int height)
|
2011-02-16 03:19:36 +00:00
|
|
|
{
|
|
|
|
m_stats.Reset();
|
|
|
|
|
|
|
|
m_start = __rdtsc();
|
|
|
|
|
2011-02-17 18:22:47 +00:00
|
|
|
m_threads = std::min<int>(1 + (height >> THREAD_HEIGHT), size());
|
|
|
|
|
|
|
|
m_sync = 0;
|
|
|
|
|
|
|
|
for(int i = 1; i < m_threads; i++)
|
|
|
|
{
|
|
|
|
m_sync |= 1 << i;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(int i = 1; i < m_threads; i++)
|
2011-02-16 03:19:36 +00:00
|
|
|
{
|
2011-02-17 18:22:47 +00:00
|
|
|
(*this)[i]->SetThreadId(i, m_threads);
|
2011-02-16 03:19:36 +00:00
|
|
|
(*this)[i]->Draw(data);
|
|
|
|
}
|
|
|
|
|
2011-02-17 18:22:47 +00:00
|
|
|
(*this)[0]->SetThreadId(0, m_threads);
|
2011-02-16 03:19:36 +00:00
|
|
|
(*this)[0]->Draw(data);
|
|
|
|
}
|
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|