2010-04-25 00:31:27 +00:00
|
|
|
/*
|
2010-04-24 21:37:39 +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
|
|
|
*
|
2010-04-24 21:37:39 +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
|
|
|
*
|
2010-04-24 21:37:39 +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.
|
2010-04-24 21:37:39 +00:00
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "GSVertexTrace.h"
|
|
|
|
#include "GSUtil.h"
|
|
|
|
#include "GSState.h"
|
|
|
|
|
2011-02-28 11:08:52 +00:00
|
|
|
const GSVector4 GSVertexTrace::s_minmax(FLT_MAX, -FLT_MAX);
|
2011-02-16 03:19:36 +00:00
|
|
|
|
2010-04-24 21:37:39 +00:00
|
|
|
GSVertexTrace::GSVertexTrace(const GSState* state)
|
|
|
|
: m_state(state)
|
|
|
|
{
|
2012-01-19 04:53:36 +00:00
|
|
|
#define InitUpdate3(P, IIP, TME, FST, COLOR) \
|
|
|
|
m_fmm[COLOR][FST][TME][IIP][P] = &GSVertexTrace::FindMinMax<P, IIP, TME, FST, COLOR>;
|
|
|
|
|
|
|
|
#define InitUpdate2(P, IIP, TME) \
|
|
|
|
InitUpdate3(P, IIP, TME, 0, 0) \
|
|
|
|
InitUpdate3(P, IIP, TME, 0, 1) \
|
|
|
|
InitUpdate3(P, IIP, TME, 1, 0) \
|
|
|
|
InitUpdate3(P, IIP, TME, 1, 1) \
|
|
|
|
|
|
|
|
#define InitUpdate(P) \
|
|
|
|
InitUpdate2(P, 0, 0) \
|
|
|
|
InitUpdate2(P, 0, 1) \
|
|
|
|
InitUpdate2(P, 1, 0) \
|
|
|
|
InitUpdate2(P, 1, 1) \
|
|
|
|
|
|
|
|
InitUpdate(GS_POINT_CLASS);
|
|
|
|
InitUpdate(GS_LINE_CLASS);
|
|
|
|
InitUpdate(GS_TRIANGLE_CLASS);
|
|
|
|
InitUpdate(GS_SPRITE_CLASS);
|
2010-04-24 21:37:39 +00:00
|
|
|
}
|
|
|
|
|
2012-01-05 02:40:24 +00:00
|
|
|
void GSVertexTrace::Update(const void* vertex, const uint32* index, int count, GS_PRIM_CLASS primclass)
|
2010-04-24 21:37:39 +00:00
|
|
|
{
|
2012-01-19 04:53:36 +00:00
|
|
|
m_primclass = primclass;
|
|
|
|
|
|
|
|
uint32 iip = m_state->PRIM->IIP;
|
|
|
|
uint32 tme = m_state->PRIM->TME;
|
|
|
|
uint32 fst = m_state->PRIM->FST;
|
|
|
|
uint32 color = !(m_state->PRIM->TME && m_state->m_context->TEX0.TFX == TFX_DECAL && m_state->m_context->TEX0.TCC);
|
|
|
|
|
|
|
|
(this->*m_fmm[color][fst][tme][iip][primclass])(vertex, index, count);
|
|
|
|
|
2012-01-05 02:40:24 +00:00
|
|
|
m_eq.value = (m_min.c == m_max.c).mask() | ((m_min.p == m_max.p).mask() << 16) | ((m_min.t == m_max.t).mask() << 20);
|
2010-04-24 21:37:39 +00:00
|
|
|
|
2012-01-05 02:40:24 +00:00
|
|
|
m_alpha.valid = false;
|
2010-04-24 21:37:39 +00:00
|
|
|
|
2012-01-05 02:40:24 +00:00
|
|
|
if(m_state->PRIM->TME)
|
2010-04-24 21:37:39 +00:00
|
|
|
{
|
2012-01-05 02:40:24 +00:00
|
|
|
const GIFRegTEX1& TEX1 = m_state->m_context->TEX1;
|
2010-04-24 21:37:39 +00:00
|
|
|
|
2012-01-05 02:40:24 +00:00
|
|
|
m_filter.mmag = TEX1.IsMagLinear();
|
|
|
|
m_filter.mmin = TEX1.IsMinLinear();
|
2010-04-24 21:37:39 +00:00
|
|
|
|
2012-01-05 02:40:24 +00:00
|
|
|
if(TEX1.MXL == 0) // MXL == 0 => MMIN ignored, tested it on ps2
|
|
|
|
{
|
|
|
|
m_filter.linear = m_filter.mmag;
|
2011-03-12 22:10:58 +00:00
|
|
|
|
2012-01-05 02:40:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-03-12 22:10:58 +00:00
|
|
|
|
2012-01-05 02:40:24 +00:00
|
|
|
float K = (float)TEX1.K / 16;
|
2011-03-12 22:10:58 +00:00
|
|
|
|
2012-01-05 02:40:24 +00:00
|
|
|
if(TEX1.LCM == 0 && m_state->PRIM->FST == 0) // FST == 1 => Q is not interpolated
|
|
|
|
{
|
|
|
|
// LOD = log2(1/|Q|) * (1 << L) + K
|
2011-03-12 22:10:58 +00:00
|
|
|
|
2012-01-05 02:40:24 +00:00
|
|
|
GSVector4::storel(&m_lod, m_max.t.uph(m_min.t).log2(3).neg() * (float)(1 << TEX1.L) + K);
|
2011-03-12 22:10:58 +00:00
|
|
|
|
2012-01-05 02:40:24 +00:00
|
|
|
if(m_lod.x > m_lod.y) {float tmp = m_lod.x; m_lod.x = m_lod.y; m_lod.y = tmp;}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_lod.x = K;
|
|
|
|
m_lod.y = K;
|
|
|
|
}
|
2011-03-12 22:10:58 +00:00
|
|
|
|
2012-01-05 02:40:24 +00:00
|
|
|
if(m_lod.y <= 0)
|
|
|
|
{
|
|
|
|
m_filter.linear = m_filter.mmag;
|
|
|
|
}
|
|
|
|
else if(m_lod.x > 0)
|
|
|
|
{
|
|
|
|
m_filter.linear = m_filter.mmin;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_filter.linear = m_filter.mmag | m_filter.mmin;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-03-12 22:10:58 +00:00
|
|
|
|
2012-01-19 04:53:36 +00:00
|
|
|
template<GS_PRIM_CLASS primclass, uint32 iip, uint32 tme, uint32 fst, uint32 color>
|
|
|
|
void GSVertexTrace::FindMinMax(const void* vertex, const uint32* index, int count)
|
2012-01-05 02:40:24 +00:00
|
|
|
{
|
2012-01-19 04:53:36 +00:00
|
|
|
const GSDrawingContext* context = m_state->m_context;
|
2011-03-12 22:10:58 +00:00
|
|
|
|
2012-01-19 04:53:36 +00:00
|
|
|
bool sprite = primclass == GS_SPRITE_CLASS;
|
2011-03-12 22:10:58 +00:00
|
|
|
|
2012-01-19 04:53:36 +00:00
|
|
|
int n = 1;
|
|
|
|
|
|
|
|
switch(primclass)
|
2011-03-12 22:10:58 +00:00
|
|
|
{
|
2012-01-19 04:53:36 +00:00
|
|
|
case GS_POINT_CLASS:
|
|
|
|
n = 1;
|
|
|
|
break;
|
|
|
|
case GS_LINE_CLASS:
|
|
|
|
case GS_SPRITE_CLASS:
|
|
|
|
n = 2;
|
|
|
|
break;
|
|
|
|
case GS_TRIANGLE_CLASS:
|
|
|
|
n = 3;
|
|
|
|
break;
|
2011-03-12 22:10:58 +00:00
|
|
|
}
|
2012-01-05 02:40:24 +00:00
|
|
|
|
2012-01-19 04:53:36 +00:00
|
|
|
GSVector4 pmin = s_minmax.xxxx();
|
|
|
|
GSVector4 pmax = s_minmax.yyyy();
|
|
|
|
GSVector4 tmin = s_minmax.xxxx();
|
|
|
|
GSVector4 tmax = s_minmax.yyyy();
|
|
|
|
GSVector4i cmin = GSVector4i::xffffffff();
|
|
|
|
GSVector4i cmax = GSVector4i::zero();
|
2011-03-12 22:10:58 +00:00
|
|
|
|
2012-01-20 00:34:44 +00:00
|
|
|
// TODO: SSE41 has integer min/max, use that for xy/z/uv/f
|
|
|
|
|
2012-01-19 04:53:36 +00:00
|
|
|
const GSVertex* RESTRICT v = (GSVertex*)vertex;
|
2010-04-24 21:37:39 +00:00
|
|
|
|
2012-01-19 04:53:36 +00:00
|
|
|
for(int i = 0; i < count; i += n)
|
|
|
|
{
|
|
|
|
GSVector4 q;
|
|
|
|
GSVector4i f;
|
2010-04-24 21:37:39 +00:00
|
|
|
|
2012-01-19 04:53:36 +00:00
|
|
|
if(sprite)
|
|
|
|
{
|
|
|
|
if(tme && !fst)
|
|
|
|
{
|
|
|
|
q = GSVector4::load<true>(&v[index[i + 1]]).wwww();
|
|
|
|
}
|
2011-03-12 22:10:58 +00:00
|
|
|
|
2012-01-19 04:53:36 +00:00
|
|
|
f = GSVector4i(v[index[i + 1]].m[1]).wwww();
|
|
|
|
}
|
2010-04-24 21:37:39 +00:00
|
|
|
|
2012-01-19 04:53:36 +00:00
|
|
|
for(int j = 0; j < n; j++)
|
|
|
|
{
|
|
|
|
GSVector4i c(v[index[i + j]].m[0]);
|
2010-04-24 21:37:39 +00:00
|
|
|
|
2012-01-19 04:53:36 +00:00
|
|
|
if(color && (iip || j == n - 1)) // TODO: unroll, to avoid j == n - 1
|
|
|
|
{
|
|
|
|
cmin = cmin.min_u8(c);
|
|
|
|
cmax = cmax.max_u8(c);
|
|
|
|
}
|
2010-04-24 21:37:39 +00:00
|
|
|
|
2012-01-19 04:53:36 +00:00
|
|
|
if(tme)
|
|
|
|
{
|
|
|
|
if(!fst)
|
|
|
|
{
|
|
|
|
GSVector4 stq = GSVector4::cast(c);
|
2010-04-24 21:37:39 +00:00
|
|
|
|
2012-01-19 04:53:36 +00:00
|
|
|
GSVector4 q2 = !sprite ? stq.wwww() : q;
|
2010-04-24 21:37:39 +00:00
|
|
|
|
2012-01-19 04:53:36 +00:00
|
|
|
stq = (stq.xyww() * q2.rcpnr()).xyww(q2);
|
2010-04-24 21:37:39 +00:00
|
|
|
|
2012-01-19 04:53:36 +00:00
|
|
|
tmin = tmin.min(stq);
|
|
|
|
tmax = tmax.max(stq);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GSVector4i uv(v[index[i + j]].m[1]);
|
2010-04-24 21:37:39 +00:00
|
|
|
|
2012-01-19 04:53:36 +00:00
|
|
|
GSVector4 st = GSVector4(uv.uph16()).xyxy();
|
2011-03-12 22:10:58 +00:00
|
|
|
|
2012-01-19 04:53:36 +00:00
|
|
|
tmin = tmin.min(st);
|
|
|
|
tmax = tmax.max(st);
|
|
|
|
}
|
|
|
|
}
|
2010-04-24 21:37:39 +00:00
|
|
|
|
2012-01-19 04:53:36 +00:00
|
|
|
GSVector4i xyzf(v[index[i + j]].m[1]);
|
2010-04-24 21:37:39 +00:00
|
|
|
|
2012-01-19 04:53:36 +00:00
|
|
|
GSVector4i xy = xyzf.upl16();
|
|
|
|
GSVector4i z = xyzf.yyyy().srl32(1);
|
|
|
|
|
|
|
|
GSVector4 p = GSVector4(xy.upl64(z.upl32(!sprite ? xyzf.wwww() : f)));
|
|
|
|
|
|
|
|
pmin = pmin.min(p);
|
|
|
|
pmax = pmax.max(p);
|
|
|
|
}
|
|
|
|
}
|
2010-04-24 21:37:39 +00:00
|
|
|
|
|
|
|
GSVector4 o(context->XYOFFSET);
|
|
|
|
GSVector4 s(1.0f / 16, 1.0f / 16, 2.0f, 1.0f);
|
|
|
|
|
2012-01-19 04:53:36 +00:00
|
|
|
m_min.p = (pmin - o) * s;
|
|
|
|
m_max.p = (pmax - o) * s;
|
2010-04-24 21:37:39 +00:00
|
|
|
|
2012-01-19 04:53:36 +00:00
|
|
|
if(tme)
|
2010-04-24 21:37:39 +00:00
|
|
|
{
|
2012-01-19 04:53:36 +00:00
|
|
|
if(fst)
|
2010-04-24 21:37:39 +00:00
|
|
|
{
|
|
|
|
s = GSVector4(1 << (16 - 4), 1).xxyy();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
s = GSVector4(0x10000 << context->TEX0.TW, 0x10000 << context->TEX0.TH, 1, 1);
|
|
|
|
}
|
|
|
|
|
2012-01-19 04:53:36 +00:00
|
|
|
m_min.t = tmin * s;
|
|
|
|
m_max.t = tmax * s;
|
2010-04-24 21:37:39 +00:00
|
|
|
}
|
|
|
|
|
2012-01-19 04:53:36 +00:00
|
|
|
if(color)
|
|
|
|
{
|
|
|
|
m_min.c = cmin.zzzz().u8to32();
|
|
|
|
m_max.c = cmax.zzzz().u8to32();
|
|
|
|
}
|
2010-04-24 21:37:39 +00:00
|
|
|
}
|