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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2011-02-19 03:36:30 +00:00
|
|
|
#include "stdafx.h"
|
2009-02-09 21:15:56 +00:00
|
|
|
#include "GSDrawScanline.h"
|
|
|
|
#include "GSTextureCacheSW.h"
|
|
|
|
|
2011-02-17 18:22:47 +00:00
|
|
|
GSDrawScanline::GSDrawScanline()
|
2011-02-17 03:24:37 +00:00
|
|
|
: m_sp_map("GSSetupPrim", &m_local)
|
|
|
|
, m_ds_map("GSDrawScanline", &m_local)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2011-02-17 03:24:37 +00:00
|
|
|
memset(&m_local, 0, sizeof(m_local));
|
|
|
|
|
2011-02-17 18:22:47 +00:00
|
|
|
m_local.gd = &m_global;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GSDrawScanline::~GSDrawScanline()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-02-17 18:22:47 +00:00
|
|
|
void GSDrawScanline::BeginDraw(const void* param)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2011-02-17 18:22:47 +00:00
|
|
|
memcpy(&m_global, param, sizeof(m_global));
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-02-17 18:22:47 +00:00
|
|
|
m_ds = m_ds_map[m_global.sel];
|
|
|
|
|
|
|
|
if(m_global.sel.aa1)
|
2009-03-09 01:42:56 +00:00
|
|
|
{
|
|
|
|
GSScanlineSelector sel;
|
|
|
|
|
2011-02-17 18:22:47 +00:00
|
|
|
sel.key = m_global.sel.key;
|
2009-03-09 01:42:56 +00:00
|
|
|
sel.zwrite = 0;
|
|
|
|
sel.edge = 1;
|
|
|
|
|
2011-02-16 03:19:36 +00:00
|
|
|
m_de = m_ds_map[sel];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_de = NULL;
|
2009-03-09 01:42:56 +00:00
|
|
|
}
|
|
|
|
|
2011-02-17 18:22:47 +00:00
|
|
|
if(m_global.sel.IsSolidRect())
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2011-02-16 03:19:36 +00:00
|
|
|
m_dr = (DrawRectPtr)&GSDrawScanline::DrawRect;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_dr = NULL;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2009-02-13 09:28:51 +00:00
|
|
|
// doesn't need all bits => less functions generated
|
2009-02-11 07:05:44 +00:00
|
|
|
|
2009-02-13 09:28:51 +00:00
|
|
|
GSScanlineSelector sel;
|
2009-02-11 07:05:44 +00:00
|
|
|
|
2009-02-13 09:28:51 +00:00
|
|
|
sel.key = 0;
|
2009-02-11 07:05:44 +00:00
|
|
|
|
2011-02-17 18:22:47 +00:00
|
|
|
sel.iip = m_global.sel.iip;
|
|
|
|
sel.tfx = m_global.sel.tfx;
|
|
|
|
sel.tcc = m_global.sel.tcc;
|
|
|
|
sel.fst = m_global.sel.fst;
|
|
|
|
sel.fge = m_global.sel.fge;
|
|
|
|
sel.sprite = m_global.sel.sprite;
|
|
|
|
sel.fb = m_global.sel.fb;
|
|
|
|
sel.zb = m_global.sel.zb;
|
|
|
|
sel.zoverflow = m_global.sel.zoverflow;
|
2009-02-11 07:05:44 +00:00
|
|
|
|
2011-02-16 03:19:36 +00:00
|
|
|
m_sp = m_sp_map[sel];
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2011-02-17 03:24:37 +00:00
|
|
|
void GSDrawScanline::EndDraw(const GSRasterizerStats& stats, uint64 frame)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2011-02-17 03:24:37 +00:00
|
|
|
m_ds_map.UpdateStats(stats, frame);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2011-02-16 03:19:36 +00:00
|
|
|
void GSDrawScanline::DrawRect(const GSVector4i& r, const GSVertexSW& v)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
ASSERT(r.y >= 0);
|
|
|
|
ASSERT(r.w >= 0);
|
|
|
|
|
|
|
|
// FIXME: sometimes the frame and z buffer may overlap, the outcome is undefined
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
uint32 m;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-02-17 18:22:47 +00:00
|
|
|
m = m_global.zm.u32[0];
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
if(m != 0xffffffff)
|
|
|
|
{
|
2011-02-17 18:22:47 +00:00
|
|
|
const int* zbr = m_global.zbr;
|
|
|
|
const int* zbc = m_global.zbc;
|
2011-02-17 03:24:37 +00:00
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
uint32 z = (uint32)v.p.z;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-02-17 18:22:47 +00:00
|
|
|
if(m_global.sel.zpsm != 2)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
if(m == 0)
|
|
|
|
{
|
2011-02-17 03:24:37 +00:00
|
|
|
DrawRectT<uint32, false>(zbr, zbc, r, z, m);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-02-17 03:24:37 +00:00
|
|
|
DrawRectT<uint32, true>(zbr, zbc, r, z, m);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(m == 0)
|
|
|
|
{
|
2011-02-17 03:24:37 +00:00
|
|
|
DrawRectT<uint16, false>(zbr, zbc, r, z, m);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-02-17 03:24:37 +00:00
|
|
|
DrawRectT<uint16, true>(zbr, zbc, r, z, m);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-17 18:22:47 +00:00
|
|
|
m = m_global.fm.u32[0];
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
if(m != 0xffffffff)
|
|
|
|
{
|
2011-02-17 18:22:47 +00:00
|
|
|
const int* fbr = m_global.fbr;
|
|
|
|
const int* fbc = m_global.fbc;
|
2011-02-17 03:24:37 +00:00
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
uint32 c = (GSVector4i(v.c) >> 7).rgba32();
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-02-17 18:22:47 +00:00
|
|
|
if(m_global.sel.fba)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
c |= 0x80000000;
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2011-02-17 18:22:47 +00:00
|
|
|
if(m_global.sel.fpsm != 2)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
if(m == 0)
|
|
|
|
{
|
2011-02-17 03:24:37 +00:00
|
|
|
DrawRectT<uint32, false>(fbr, fbc, r, c, m);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-02-17 03:24:37 +00:00
|
|
|
DrawRectT<uint32, true>(fbr, fbc, r, c, m);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
c = ((c & 0xf8) >> 3) | ((c & 0xf800) >> 6) | ((c & 0xf80000) >> 9) | ((c & 0x80000000) >> 16);
|
|
|
|
|
|
|
|
if(m == 0)
|
|
|
|
{
|
2011-02-17 03:24:37 +00:00
|
|
|
DrawRectT<uint16, false>(fbr, fbc, r, c, m);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-02-17 03:24:37 +00:00
|
|
|
DrawRectT<uint16, true>(fbr, fbc, r, c, m);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
template<class T, bool masked>
|
2011-02-16 03:19:36 +00:00
|
|
|
void GSDrawScanline::DrawRectT(const int* RESTRICT row, const int* RESTRICT col, const GSVector4i& r, uint32 c, uint32 m)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
if(m == 0xffffffff) return;
|
|
|
|
|
|
|
|
GSVector4i color((int)c);
|
|
|
|
GSVector4i mask((int)m);
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
if(sizeof(T) == sizeof(uint16))
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
color = color.xxzzlh();
|
|
|
|
mask = mask.xxzzlh();
|
|
|
|
}
|
|
|
|
|
|
|
|
color = color.andnot(mask);
|
|
|
|
|
2011-03-12 22:10:58 +00:00
|
|
|
GSVector4i br = r.ralign<Align_Inside>(GSVector2i(8 * 4 / sizeof(T), 8));
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-06-20 20:28:36 +00:00
|
|
|
if(!br.rempty())
|
|
|
|
{
|
|
|
|
FillRect<T, masked>(row, col, GSVector4i(r.x, r.y, r.z, br.y), c, m);
|
|
|
|
FillRect<T, masked>(row, col, GSVector4i(r.x, br.w, r.z, r.w), c, m);
|
|
|
|
|
|
|
|
if(r.x < br.x || br.z < r.z)
|
|
|
|
{
|
|
|
|
FillRect<T, masked>(row, col, GSVector4i(r.x, br.y, br.x, br.w), c, m);
|
|
|
|
FillRect<T, masked>(row, col, GSVector4i(br.z, br.y, r.z, br.w), c, m);
|
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-06-20 20:28:36 +00:00
|
|
|
FillBlock<T, masked>(row, col, br, color, mask);
|
|
|
|
}
|
|
|
|
else
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-06-20 20:28:36 +00:00
|
|
|
FillRect<T, masked>(row, col, r, c, m);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
template<class T, bool masked>
|
2009-07-06 16:35:06 +00:00
|
|
|
void GSDrawScanline::FillRect(const int* RESTRICT row, const int* RESTRICT col, const GSVector4i& r, uint32 c, uint32 m)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
if(r.x >= r.z) return;
|
|
|
|
|
2011-02-17 18:22:47 +00:00
|
|
|
T* vm = (T*)m_global.vm;
|
2011-02-17 03:24:37 +00:00
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
for(int y = r.y; y < r.w; y++)
|
|
|
|
{
|
2011-02-17 03:24:37 +00:00
|
|
|
T* RESTRICT d = &vm[row[y]];
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
for(int x = r.x; x < r.z; x++)
|
|
|
|
{
|
2009-07-06 16:35:06 +00:00
|
|
|
d[col[x]] = (T)(!masked ? c : (c | (d[col[x]] & m)));
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
template<class T, bool masked>
|
2009-07-06 16:35:06 +00:00
|
|
|
void GSDrawScanline::FillBlock(const int* RESTRICT row, const int* RESTRICT col, const GSVector4i& r, const GSVector4i& c, const GSVector4i& m)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
if(r.x >= r.z) return;
|
|
|
|
|
2011-02-17 18:22:47 +00:00
|
|
|
T* vm = (T*)m_global.vm;
|
2011-02-17 03:24:37 +00:00
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
for(int y = r.y; y < r.w; y += 8)
|
|
|
|
{
|
2011-02-17 03:24:37 +00:00
|
|
|
T* RESTRICT d = &vm[row[y]];
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
for(int x = r.x; x < r.z; x += 8 * 4 / sizeof(T))
|
|
|
|
{
|
2009-07-06 16:35:06 +00:00
|
|
|
GSVector4i* RESTRICT p = (GSVector4i*)&d[col[x]];
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
for(int i = 0; i < 16; i += 4)
|
|
|
|
{
|
|
|
|
p[i + 0] = !masked ? c : (c | (p[i + 0] & m));
|
|
|
|
p[i + 1] = !masked ? c : (c | (p[i + 1] & m));
|
|
|
|
p[i + 2] = !masked ? c : (c | (p[i + 2] & m));
|
|
|
|
p[i + 3] = !masked ? c : (c | (p[i + 3] & m));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|