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 "GSRendererDX11.h"
|
|
|
|
#include "GSCrc.h"
|
|
|
|
#include "resource.h"
|
|
|
|
|
|
|
|
GSRendererDX11::GSRendererDX11()
|
|
|
|
: GSRendererDX<GSVertexHW11>(new GSTextureCache11(this), GSVector2(-0.5f, -0.5f))
|
|
|
|
{
|
|
|
|
InitVertexKick<GSRendererDX11>();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GSRendererDX11::CreateDevice(GSDevice* dev)
|
|
|
|
{
|
|
|
|
if(!__super::CreateDevice(dev))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-08-17 04:38:49 +00:00
|
|
|
void GSRendererDX11::DoVertexKick()
|
2010-04-24 21:37:39 +00:00
|
|
|
{
|
2010-08-17 04:38:49 +00:00
|
|
|
const bool tme = PRIM->TME;
|
|
|
|
const bool fst = PRIM->FST;
|
|
|
|
|
2010-04-24 21:37:39 +00:00
|
|
|
GSVertexHW11& dst = m_vl.AddTail();
|
|
|
|
|
|
|
|
dst.vi[0] = m_v.vi[0];
|
|
|
|
dst.vi[1] = m_v.vi[1];
|
|
|
|
|
|
|
|
#ifdef USE_UPSCALE_HACKS
|
|
|
|
if(tme && fst)
|
|
|
|
{
|
|
|
|
//GSVector4::storel(&dst.ST, m_v.GetUV());
|
|
|
|
int Udiff = 0;
|
|
|
|
int Vdiff = 0;
|
|
|
|
int Uadjust = 0;
|
|
|
|
int Vadjust = 0;
|
2010-04-25 00:31:27 +00:00
|
|
|
int multiplier = upscale_Multiplier();
|
|
|
|
|
2010-04-24 21:37:39 +00:00
|
|
|
if (multiplier > 1) {
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-04-24 21:37:39 +00:00
|
|
|
Udiff = m_v.UV.U & 4095;
|
|
|
|
Vdiff = m_v.UV.V & 4095;
|
|
|
|
if (Udiff != 0){
|
|
|
|
if (Udiff >= 4080) {/*printf("U+ %d %d\n", Udiff, m_v.UV.U);*/ Uadjust = -1; }
|
|
|
|
else if (Udiff <= 16) {/*printf("U- %d %d\n", Udiff, m_v.UV.U);*/ Uadjust = 1; }
|
|
|
|
}
|
|
|
|
if (Vdiff != 0){
|
|
|
|
if (Vdiff >= 4080) {/*printf("V+ %d %d\n", Vdiff, m_v.UV.V);*/ Vadjust = -1; }
|
|
|
|
else if (Vdiff <= 16) {/*printf("V- %d %d\n", Vdiff, m_v.UV.V);*/ Vadjust = 1; }
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-04-24 21:37:39 +00:00
|
|
|
Udiff = m_v.UV.U & 255;
|
|
|
|
Vdiff = m_v.UV.V & 255;
|
|
|
|
if (Udiff != 0){
|
2010-04-25 00:31:27 +00:00
|
|
|
if (Udiff >= 248) { Uadjust = -1; }
|
2010-04-24 21:37:39 +00:00
|
|
|
else if (Udiff <= 8) { Uadjust = 1; }
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-04-24 21:37:39 +00:00
|
|
|
if (Vdiff != 0){
|
|
|
|
if (Vdiff >= 248) { Vadjust = -1; }
|
|
|
|
else if (Vdiff <= 8) { Vadjust = 1; }
|
|
|
|
}
|
|
|
|
|
|
|
|
Udiff = m_v.UV.U & 15;
|
|
|
|
Vdiff = m_v.UV.V & 15;
|
|
|
|
if (Udiff != 0){
|
2010-04-25 00:31:27 +00:00
|
|
|
if (Udiff >= 15) { Uadjust = -1; }
|
2010-04-24 21:37:39 +00:00
|
|
|
else if (Udiff <= 1) { Uadjust = 1; }
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-04-24 21:37:39 +00:00
|
|
|
if (Vdiff != 0){
|
|
|
|
if (Vdiff >= 15) { Vadjust = -1; }
|
|
|
|
else if (Vdiff <= 1) { Vadjust = 1; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dst.ST.S = (float)m_v.UV.U - Uadjust;
|
2010-04-25 00:31:27 +00:00
|
|
|
dst.ST.T = (float)m_v.UV.V - Vadjust;
|
2010-04-24 21:37:39 +00:00
|
|
|
}
|
|
|
|
else if (tme)
|
|
|
|
{
|
|
|
|
// Wip :p
|
|
|
|
//dst.XYZ.X += 5;
|
|
|
|
//dst.XYZ.Y += 5;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if(tme && fst)
|
|
|
|
{
|
|
|
|
GSVector4::storel(&dst.ST, m_v.GetUV());
|
|
|
|
}
|
|
|
|
#endif
|
2010-08-17 04:38:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template< uint32 prim >
|
|
|
|
void GSRendererDX11::DrawingKick( bool skip )
|
|
|
|
{
|
|
|
|
int count;
|
|
|
|
|
|
|
|
GSVertexHW11* v = BaseDrawingKick<prim>(count);
|
|
|
|
if (skip || !v) return;
|
|
|
|
|
|
|
|
GSVector4i scissor = m_context->scissor.dx10;
|
|
|
|
|
|
|
|
GSVector4i pmin, pmax;
|
2010-04-24 21:37:39 +00:00
|
|
|
|
2010-08-17 04:38:49 +00:00
|
|
|
#if _M_SSE >= 0x401
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-08-17 04:38:49 +00:00
|
|
|
GSVector4i v0, v1, v2;
|
|
|
|
|
|
|
|
switch(prim)
|
2010-04-24 21:37:39 +00:00
|
|
|
{
|
2010-08-17 04:38:49 +00:00
|
|
|
case GS_POINTLIST:
|
|
|
|
v0 = GSVector4i::load((int)v[0].p.xy).upl16();
|
|
|
|
pmin = v0;
|
|
|
|
pmax = v0;
|
|
|
|
break;
|
|
|
|
case GS_LINELIST:
|
|
|
|
case GS_LINESTRIP:
|
|
|
|
case GS_SPRITE:
|
|
|
|
v0 = GSVector4i::load((int)v[0].p.xy);
|
|
|
|
v1 = GSVector4i::load((int)v[1].p.xy);
|
|
|
|
pmin = v0.min_u16(v1).upl16();
|
|
|
|
pmax = v0.max_u16(v1).upl16();
|
|
|
|
break;
|
|
|
|
case GS_TRIANGLELIST:
|
|
|
|
case GS_TRIANGLESTRIP:
|
|
|
|
case GS_TRIANGLEFAN:
|
|
|
|
v0 = GSVector4i::load((int)v[0].p.xy);
|
|
|
|
v1 = GSVector4i::load((int)v[1].p.xy);
|
|
|
|
v2 = GSVector4i::load((int)v[2].p.xy);
|
|
|
|
pmin = v0.min_u16(v1).min_u16(v2).upl16();
|
|
|
|
pmax = v0.max_u16(v1).max_u16(v2).upl16();
|
|
|
|
break;
|
|
|
|
}
|
2010-04-24 21:37:39 +00:00
|
|
|
|
2010-08-17 04:38:49 +00:00
|
|
|
#else
|
2010-04-24 21:37:39 +00:00
|
|
|
|
2010-08-17 04:38:49 +00:00
|
|
|
switch(prim)
|
|
|
|
{
|
|
|
|
case GS_POINTLIST:
|
|
|
|
pmin.x = v[0].p.x;
|
|
|
|
pmin.y = v[0].p.y;
|
|
|
|
pmax.x = v[0].p.x;
|
|
|
|
pmax.y = v[0].p.y;
|
|
|
|
break;
|
|
|
|
case GS_LINELIST:
|
|
|
|
case GS_LINESTRIP:
|
|
|
|
case GS_SPRITE:
|
|
|
|
pmin.x = std::min<uint16>(v[0].p.x, v[1].p.x);
|
|
|
|
pmin.y = std::min<uint16>(v[0].p.y, v[1].p.y);
|
|
|
|
pmax.x = std::max<uint16>(v[0].p.x, v[1].p.x);
|
|
|
|
pmax.y = std::max<uint16>(v[0].p.y, v[1].p.y);
|
|
|
|
break;
|
|
|
|
case GS_TRIANGLELIST:
|
|
|
|
case GS_TRIANGLESTRIP:
|
|
|
|
case GS_TRIANGLEFAN:
|
|
|
|
pmin.x = std::min<uint16>(std::min<uint16>(v[0].p.x, v[1].p.x), v[2].p.x);
|
|
|
|
pmin.y = std::min<uint16>(std::min<uint16>(v[0].p.y, v[1].p.y), v[2].p.y);
|
|
|
|
pmax.x = std::max<uint16>(std::max<uint16>(v[0].p.x, v[1].p.x), v[2].p.x);
|
|
|
|
pmax.y = std::max<uint16>(std::max<uint16>(v[0].p.y, v[1].p.y), v[2].p.y);
|
|
|
|
break;
|
|
|
|
}
|
2010-04-24 21:37:39 +00:00
|
|
|
|
2010-08-17 04:38:49 +00:00
|
|
|
#endif
|
2010-04-24 21:37:39 +00:00
|
|
|
|
2010-08-17 04:38:49 +00:00
|
|
|
GSVector4i test = (pmax < scissor) | (pmin > scissor.zwxy());
|
2010-04-24 21:37:39 +00:00
|
|
|
|
2010-08-17 04:38:49 +00:00
|
|
|
switch(prim)
|
|
|
|
{
|
|
|
|
case GS_TRIANGLELIST:
|
|
|
|
case GS_TRIANGLESTRIP:
|
|
|
|
case GS_TRIANGLEFAN:
|
|
|
|
case GS_SPRITE:
|
|
|
|
test |= pmin == pmax;
|
|
|
|
break;
|
|
|
|
}
|
2010-04-24 21:37:39 +00:00
|
|
|
|
2010-08-17 04:38:49 +00:00
|
|
|
if(test.mask() & 0xff)
|
|
|
|
{
|
|
|
|
return;
|
2010-04-24 21:37:39 +00:00
|
|
|
}
|
2010-08-17 04:38:49 +00:00
|
|
|
|
|
|
|
m_count += count;
|
2010-04-24 21:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GSRendererDX11::Draw(GSTexture* rt, GSTexture* ds, GSTextureCache::Source* tex)
|
|
|
|
{
|
|
|
|
switch(m_vt.m_primclass)
|
|
|
|
{
|
|
|
|
case GS_POINT_CLASS:
|
|
|
|
m_topology = D3D11_PRIMITIVE_TOPOLOGY_POINTLIST;
|
|
|
|
m_perfmon.Put(GSPerfMon::Prim, m_count);
|
|
|
|
break;
|
2010-04-25 00:31:27 +00:00
|
|
|
case GS_LINE_CLASS:
|
2010-04-24 21:37:39 +00:00
|
|
|
case GS_SPRITE_CLASS:
|
|
|
|
m_topology = D3D11_PRIMITIVE_TOPOLOGY_LINELIST;
|
|
|
|
m_perfmon.Put(GSPerfMon::Prim, m_count / 2);
|
|
|
|
break;
|
|
|
|
case GS_TRIANGLE_CLASS:
|
|
|
|
m_topology = D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
|
|
|
|
m_perfmon.Put(GSPerfMon::Prim, m_count / 3);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
__assume(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
__super::Draw(rt, ds, tex);
|
|
|
|
}
|