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
|
2012-09-09 18:16:11 +00:00
|
|
|
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA USA.
|
2010-04-24 21:37:39 +00:00
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
2010-04-25 00:31:27 +00:00
|
|
|
#include "GSRendererDX.h"
|
2012-01-05 02:40:24 +00:00
|
|
|
#include "GSDeviceDX.h"
|
|
|
|
|
2012-01-19 04:53:36 +00:00
|
|
|
GSRendererDX::GSRendererDX(GSTextureCache* tc, const GSVector2& pixelcenter)
|
|
|
|
: GSRendererHW(tc)
|
2012-01-05 02:40:24 +00:00
|
|
|
, m_pixelcenter(pixelcenter)
|
|
|
|
{
|
2016-05-24 19:52:06 +00:00
|
|
|
m_logz = theApp.GetConfigB("logz");
|
|
|
|
m_fba = theApp.GetConfigB("fba");
|
2012-03-06 20:01:27 +00:00
|
|
|
|
2016-05-24 19:52:06 +00:00
|
|
|
if (theApp.GetConfigB("UserHacks")) {
|
|
|
|
UserHacks_AlphaHack = theApp.GetConfigB("UserHacks_AlphaHack");
|
|
|
|
UserHacks_AlphaStencil = theApp.GetConfigB("UserHacks_AlphaStencil");
|
|
|
|
UserHacks_TCOffset = theApp.GetConfigI("UserHacks_TCOffset");
|
|
|
|
} else {
|
|
|
|
UserHacks_AlphaHack = false;
|
|
|
|
UserHacks_AlphaStencil = false;
|
|
|
|
UserHacks_TCOffset = 0;
|
|
|
|
}
|
2013-02-12 10:57:48 +00:00
|
|
|
|
GSdx:
- changed the KH2 fix in GetTextureMinMax to my taste, should give the same results, when the used texture rect is to the left/above the clamped area, it returns [min, min+1], and [max-1, max] for right/below
- m_mem.m_clut.Read32 was returned to its original place from GetAlphaMinMax
- UserHacks_WildHack was moved up to GSState, special UV handlers are only used when this setting is active
- updated xbyak to the latest available (avx2 seems incomplete, the 256-bit promoted old instructions are missing)
- changed vtune's include path to the 2013 edition
Some other not yet commited changes from a year ago:
- WriteImageX overflow crash-fix
- moved colclamp after dithering (sw mode), it makes more sense, no visible changes noticed
- Gif_Tag::analyzeTag(), there was a conditional I didn't like, split the loop into two parts
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@5649 96395faa-99c1-11dd-bbfe-3dabce05a288
2013-06-06 11:36:01 +00:00
|
|
|
UserHacks_TCO_x = (UserHacks_TCOffset & 0xFFFF) / -1000.0f;
|
|
|
|
UserHacks_TCO_y = ((UserHacks_TCOffset >> 16) & 0xFFFF) / -1000.0f;
|
2012-01-05 02:40:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GSRendererDX::~GSRendererDX()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-08-14 16:35:42 +00:00
|
|
|
void GSRendererDX::EmulateAtst(const int pass, const GSTextureCache::Source* tex)
|
|
|
|
{
|
|
|
|
static const uint32 inverted_atst[] = { ATST_ALWAYS, ATST_NEVER, ATST_GEQUAL, ATST_GREATER, ATST_NOTEQUAL, ATST_LESS, ATST_LEQUAL, ATST_EQUAL };
|
2016-08-19 14:02:49 +00:00
|
|
|
int atst = (pass == 2) ? inverted_atst[m_context->TEST.ATST] : m_context->TEST.ATST;
|
2016-08-14 16:35:42 +00:00
|
|
|
|
2016-10-05 07:41:28 +00:00
|
|
|
if (!m_context->TEST.ATE) return;
|
2016-08-14 16:35:42 +00:00
|
|
|
|
|
|
|
switch (atst) {
|
|
|
|
case ATST_LESS:
|
|
|
|
if (tex && tex->m_spritehack_t) {
|
|
|
|
ps_sel.atst = 0;
|
|
|
|
}
|
|
|
|
else {
|
2016-08-19 14:02:49 +00:00
|
|
|
ps_cb.FogColor_AREF.a = (float)m_context->TEST.AREF - 0.1f;
|
2016-08-14 16:35:42 +00:00
|
|
|
ps_sel.atst = 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ATST_LEQUAL:
|
2016-08-19 14:02:49 +00:00
|
|
|
ps_cb.FogColor_AREF.a = (float)m_context->TEST.AREF - 0.1f + 1.0f;
|
2016-08-14 16:35:42 +00:00
|
|
|
ps_sel.atst = 1;
|
|
|
|
break;
|
|
|
|
case ATST_GEQUAL:
|
|
|
|
// Maybe a -1 trick multiplication factor could be used to merge with ATST_LEQUAL case
|
2016-08-19 14:02:49 +00:00
|
|
|
ps_cb.FogColor_AREF.a = (float)m_context->TEST.AREF - 0.1f;
|
2016-08-14 16:35:42 +00:00
|
|
|
ps_sel.atst = 2;
|
|
|
|
break;
|
|
|
|
case ATST_GREATER:
|
|
|
|
// Maybe a -1 trick multiplication factor could be used to merge with ATST_LESS case
|
2016-08-19 14:02:49 +00:00
|
|
|
ps_cb.FogColor_AREF.a = (float)m_context->TEST.AREF - 0.1f + 1.0f;
|
2016-08-14 16:35:42 +00:00
|
|
|
ps_sel.atst = 2;
|
|
|
|
break;
|
|
|
|
case ATST_EQUAL:
|
2016-08-19 14:02:49 +00:00
|
|
|
ps_cb.FogColor_AREF.a = (float)m_context->TEST.AREF;
|
2016-08-14 16:35:42 +00:00
|
|
|
ps_sel.atst = 3;
|
|
|
|
break;
|
|
|
|
case ATST_NOTEQUAL:
|
2016-08-19 14:02:49 +00:00
|
|
|
ps_cb.FogColor_AREF.a = (float)m_context->TEST.AREF;
|
2016-08-14 16:35:42 +00:00
|
|
|
ps_sel.atst = 4;
|
|
|
|
break;
|
|
|
|
case ATST_NEVER:
|
|
|
|
case ATST_ALWAYS:
|
|
|
|
default:
|
|
|
|
ps_sel.atst = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GSRendererDX::EmulateZbuffer()
|
|
|
|
{
|
2016-08-19 14:02:49 +00:00
|
|
|
if (m_context->TEST.ZTE)
|
2016-08-14 16:35:42 +00:00
|
|
|
{
|
2016-08-19 14:02:49 +00:00
|
|
|
om_dssel.ztst = m_context->TEST.ZTST;
|
|
|
|
om_dssel.zwe = !m_context->ZBUF.ZMSK;
|
2016-08-14 16:35:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
om_dssel.ztst = ZTST_ALWAYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32 max_z;
|
2016-08-19 14:02:49 +00:00
|
|
|
if (m_context->ZBUF.PSM == PSM_PSMZ32) {
|
2016-08-14 16:35:42 +00:00
|
|
|
max_z = 0xFFFFFFFF;
|
|
|
|
}
|
2016-08-19 14:02:49 +00:00
|
|
|
else if (m_context->ZBUF.PSM == PSM_PSMZ24) {
|
2016-08-14 16:35:42 +00:00
|
|
|
max_z = 0xFFFFFF;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
max_z = 0xFFFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The real GS appears to do no masking based on the Z buffer format and writing larger Z values
|
|
|
|
// than the buffer supports seems to be an error condition on the real GS, causing it to crash.
|
|
|
|
// We are probably receiving bad coordinates from VU1 in these cases.
|
|
|
|
|
2016-08-19 14:02:49 +00:00
|
|
|
if (om_dssel.ztst >= ZTST_ALWAYS && om_dssel.zwe && (m_context->ZBUF.PSM != PSM_PSMZ32)) {
|
2016-08-14 16:35:42 +00:00
|
|
|
if (m_vt.m_max.p.z > max_z) {
|
|
|
|
ASSERT(m_vt.m_min.p.z > max_z); // sfex capcom logo
|
|
|
|
// Fixme :Following conditional fixes some dialog frame in Wild Arms 3, but may not be what was intended.
|
|
|
|
if (m_vt.m_min.p.z > max_z) {
|
|
|
|
#ifdef _DEBUG
|
2016-08-19 14:02:49 +00:00
|
|
|
fprintf(stdout, "Bad Z size on %s buffers\n", psm_str(m_context->ZBUF.PSM));
|
2016-08-14 16:35:42 +00:00
|
|
|
#endif
|
|
|
|
om_dssel.ztst = ZTST_ALWAYS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GSVertex* v = &m_vertex.buff[0];
|
|
|
|
// Minor optimization of a corner case (it allow to better emulate some alpha test effects)
|
2016-09-18 15:24:33 +00:00
|
|
|
if (om_dssel.ztst == ZTST_GEQUAL && m_vt.m_eq.z && v[0].XYZ.Z == max_z) {
|
2016-08-14 16:35:42 +00:00
|
|
|
#ifdef _DEBUG
|
2016-08-19 14:02:49 +00:00
|
|
|
fprintf(stdout, "Optimize Z test GEQUAL to ALWAYS (%s)\n", psm_str(m_context->ZBUF.PSM));
|
2016-08-14 16:35:42 +00:00
|
|
|
#endif
|
|
|
|
om_dssel.ztst = ZTST_ALWAYS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-05 02:40:24 +00:00
|
|
|
void GSRendererDX::DrawPrims(GSTexture* rt, GSTexture* ds, GSTextureCache::Source* tex)
|
|
|
|
{
|
2015-08-04 17:26:17 +00:00
|
|
|
const GSVector2i& rtsize = ds ? ds->GetSize() : rt->GetSize();
|
|
|
|
const GSVector2& rtscale = ds ? ds->GetScale() : rt->GetScale();
|
2012-01-05 02:40:24 +00:00
|
|
|
|
2016-08-19 14:02:49 +00:00
|
|
|
DATE = m_context->TEST.DATE && m_context->FRAME.PSM != PSM_PSMCT24;
|
2016-08-14 16:35:42 +00:00
|
|
|
|
2016-08-19 14:02:49 +00:00
|
|
|
bool ate_first_pass = m_context->TEST.DoFirstPass();
|
|
|
|
bool ate_second_pass = m_context->TEST.DoSecondPass();
|
2012-01-05 02:40:24 +00:00
|
|
|
|
|
|
|
GSTexture* rtcopy = NULL;
|
|
|
|
|
|
|
|
ASSERT(m_dev != NULL);
|
|
|
|
|
2016-08-14 16:35:42 +00:00
|
|
|
dev = (GSDeviceDX*)m_dev;
|
2012-01-05 02:40:24 +00:00
|
|
|
|
2016-04-29 22:02:49 +00:00
|
|
|
// Channel shuffle effect not supported on DX. Let's keep the logic because it help to
|
|
|
|
// reduce memory requirement (and why not a partial port)
|
|
|
|
if (m_channel_shuffle) {
|
|
|
|
if (m_context->CLAMP.WMS == 3 && ((m_context->CLAMP.MAXU & 0x8) == 8)) {
|
|
|
|
;
|
|
|
|
} else if (m_context->CLAMP.WMS == 3 && ((m_context->CLAMP.MINU & 0x8) == 0)) {
|
|
|
|
;
|
|
|
|
} else {
|
|
|
|
m_channel_shuffle = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-05 02:40:24 +00:00
|
|
|
if(DATE)
|
|
|
|
{
|
|
|
|
if(dev->HasStencil())
|
|
|
|
{
|
|
|
|
GSVector4 s = GSVector4(rtscale.x / rtsize.x, rtscale.y / rtsize.y);
|
2015-05-15 18:40:09 +00:00
|
|
|
GSVector4 off = GSVector4(-1.0f, 1.0f);
|
2012-01-05 02:40:24 +00:00
|
|
|
|
2015-05-15 18:40:09 +00:00
|
|
|
GSVector4 src = ((m_vt.m_min.p.xyxy(m_vt.m_max.p) + off.xxyy()) * s.xyxy()).sat(off.zzyy());
|
|
|
|
GSVector4 dst = src * 2.0f + off.xxxx();
|
2012-01-05 02:40:24 +00:00
|
|
|
|
|
|
|
GSVertexPT1 vertices[] =
|
|
|
|
{
|
|
|
|
{GSVector4(dst.x, -dst.y, 0.5f, 1.0f), GSVector2(src.x, src.y)},
|
|
|
|
{GSVector4(dst.z, -dst.y, 0.5f, 1.0f), GSVector2(src.z, src.y)},
|
|
|
|
{GSVector4(dst.x, -dst.w, 0.5f, 1.0f), GSVector2(src.x, src.w)},
|
|
|
|
{GSVector4(dst.z, -dst.w, 0.5f, 1.0f), GSVector2(src.z, src.w)},
|
|
|
|
};
|
|
|
|
|
|
|
|
dev->SetupDATE(rt, ds, vertices, m_context->TEST.DATM);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rtcopy = dev->CreateRenderTarget(rtsize.x, rtsize.y, false, rt->GetFormat());
|
|
|
|
|
|
|
|
// I'll use VertexTrace when I consider it more trustworthy
|
|
|
|
|
|
|
|
dev->CopyRect(rt, rtcopy, GSVector4i(rtsize).zwxy());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
dev->BeginScene();
|
|
|
|
|
|
|
|
// om
|
|
|
|
|
2016-08-14 16:35:42 +00:00
|
|
|
om_dssel.key = 0;
|
2012-01-05 02:40:24 +00:00
|
|
|
|
2016-08-14 16:35:42 +00:00
|
|
|
EmulateZbuffer();
|
2012-01-05 02:40:24 +00:00
|
|
|
|
2016-08-14 16:35:42 +00:00
|
|
|
if (m_fba)
|
2012-01-05 02:40:24 +00:00
|
|
|
{
|
2016-08-19 14:02:49 +00:00
|
|
|
om_dssel.fba = m_context->FBA.FBA;
|
2012-01-05 02:40:24 +00:00
|
|
|
}
|
|
|
|
|
2016-08-14 16:35:42 +00:00
|
|
|
om_bsel.key = 0;
|
2012-01-05 02:40:24 +00:00
|
|
|
|
2016-08-14 16:35:42 +00:00
|
|
|
if (!IsOpaque())
|
2012-01-05 02:40:24 +00:00
|
|
|
{
|
2012-01-19 04:53:36 +00:00
|
|
|
om_bsel.abe = PRIM->ABE || PRIM->AA1 && m_vt.m_primclass == GS_LINE_CLASS;
|
2012-01-05 02:40:24 +00:00
|
|
|
|
2016-08-19 14:02:49 +00:00
|
|
|
om_bsel.a = m_context->ALPHA.A;
|
|
|
|
om_bsel.b = m_context->ALPHA.B;
|
|
|
|
om_bsel.c = m_context->ALPHA.C;
|
|
|
|
om_bsel.d = m_context->ALPHA.D;
|
2012-01-05 02:40:24 +00:00
|
|
|
|
2016-08-19 14:02:49 +00:00
|
|
|
if (m_env.PABE.PABE)
|
2012-01-05 02:40:24 +00:00
|
|
|
{
|
2016-08-14 16:35:42 +00:00
|
|
|
if (om_bsel.a == 0 && om_bsel.b == 1 && om_bsel.c == 0 && om_bsel.d == 1)
|
2012-01-05 02:40:24 +00:00
|
|
|
{
|
|
|
|
// this works because with PABE alpha blending is on when alpha >= 0x80, but since the pixel shader
|
|
|
|
// cannot output anything over 0x80 (== 1.0) blending with 0x80 or turning it off gives the same result
|
|
|
|
|
|
|
|
om_bsel.abe = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//Breath of Fire Dragon Quarter triggers this in battles. Graphics are fine though.
|
|
|
|
//ASSERT(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-19 14:02:49 +00:00
|
|
|
om_bsel.wrgba = ~GSVector4i::load((int)m_context->FRAME.FBMSK).eq8(GSVector4i::xffffffff()).mask();
|
2012-01-05 02:40:24 +00:00
|
|
|
|
|
|
|
// vs
|
|
|
|
|
|
|
|
GSDeviceDX::VSSelector vs_sel;
|
|
|
|
|
|
|
|
vs_sel.tme = PRIM->TME;
|
|
|
|
vs_sel.fst = PRIM->FST;
|
|
|
|
vs_sel.logz = dev->HasDepth32() ? 0 : m_logz ? 1 : 0;
|
|
|
|
vs_sel.rtcopy = !!rtcopy;
|
|
|
|
|
|
|
|
GSDeviceDX::VSConstantBuffer vs_cb;
|
|
|
|
|
|
|
|
float sx = 2.0f * rtscale.x / (rtsize.x << 4);
|
|
|
|
float sy = 2.0f * rtscale.y / (rtsize.y << 4);
|
2016-08-19 14:02:49 +00:00
|
|
|
float ox = (float)(int)m_context->XYOFFSET.OFX;
|
|
|
|
float oy = (float)(int)m_context->XYOFFSET.OFY;
|
2012-01-05 02:40:24 +00:00
|
|
|
float ox2 = 2.0f * m_pixelcenter.x / rtsize.x;
|
|
|
|
float oy2 = 2.0f * m_pixelcenter.y / rtsize.y;
|
|
|
|
|
|
|
|
//This hack subtracts around half a pixel from OFX and OFY. (Cannot do this directly,
|
|
|
|
//because DX10 and DX9 have a different pixel center.)
|
|
|
|
//
|
|
|
|
//The resulting shifted output aligns better with common blending / corona / blurring effects,
|
|
|
|
//but introduces a few bad pixels on the edges.
|
|
|
|
|
2015-06-05 20:37:34 +00:00
|
|
|
if(rt && rt->LikelyOffset)
|
2012-01-05 02:40:24 +00:00
|
|
|
{
|
|
|
|
// DX9 has pixelcenter set to 0.0, so give it some value here
|
|
|
|
|
|
|
|
if(m_pixelcenter.x == 0 && m_pixelcenter.y == 0) { ox2 = -0.0003f; oy2 = -0.0003f; }
|
|
|
|
|
|
|
|
ox2 *= rt->OffsetHack_modx;
|
|
|
|
oy2 *= rt->OffsetHack_mody;
|
|
|
|
}
|
|
|
|
|
|
|
|
vs_cb.VertexScale = GSVector4(sx, -sy, ldexpf(1, -32), 0.0f);
|
|
|
|
vs_cb.VertexOffset = GSVector4(ox * sx + ox2 + 1, -(oy * sy + oy2 + 1), 0.0f, -1.0f);
|
|
|
|
|
|
|
|
// gs
|
|
|
|
|
|
|
|
GSDeviceDX::GSSelector gs_sel;
|
|
|
|
|
|
|
|
gs_sel.iip = PRIM->IIP;
|
2012-01-19 04:53:36 +00:00
|
|
|
gs_sel.prim = m_vt.m_primclass;
|
2012-01-05 02:40:24 +00:00
|
|
|
|
|
|
|
// ps
|
|
|
|
|
2016-08-14 16:35:42 +00:00
|
|
|
ps_sel.key = 0;
|
|
|
|
ps_ssel.key = 0;
|
2012-01-05 02:40:24 +00:00
|
|
|
|
2015-07-01 07:28:32 +00:00
|
|
|
// Gregory: code is not yet ready so let's only enable it when
|
|
|
|
// CRC is below the FULL level
|
2017-02-13 11:16:27 +00:00
|
|
|
if (m_texture_shuffle && (m_crc_hack_level < CRCHackLevel::Full)) {
|
2015-06-09 23:17:26 +00:00
|
|
|
ps_sel.shuffle = 1;
|
|
|
|
ps_sel.fmt = 0;
|
|
|
|
|
|
|
|
const GIFRegXYOFFSET& o = m_context->XYOFFSET;
|
|
|
|
GSVertex* v = &m_vertex.buff[0];
|
|
|
|
size_t count = m_vertex.next;
|
|
|
|
|
|
|
|
// vertex position is 8 to 16 pixels, therefore it is the 16-31 bits of the colors
|
2015-06-10 18:10:10 +00:00
|
|
|
int pos = (v[0].XYZ.X - o.OFX) & 0xFF;
|
|
|
|
bool write_ba = (pos > 112 && pos < 136);
|
2015-06-09 23:17:26 +00:00
|
|
|
// Read texture is 8 to 16 pixels (same as above)
|
2015-06-10 18:10:10 +00:00
|
|
|
int tex_pos = v[0].U & 0xFF;
|
|
|
|
ps_sel.read_ba = (tex_pos > 112 && tex_pos < 144);
|
2015-06-09 23:17:26 +00:00
|
|
|
|
|
|
|
GL_INS("Color shuffle %s => %s", ps_sel.read_ba ? "BA" : "RG", write_ba ? "BA" : "RG");
|
|
|
|
|
|
|
|
// Convert the vertex info to a 32 bits color format equivalent
|
|
|
|
for (size_t i = 0; i < count; i += 2) {
|
|
|
|
if (write_ba)
|
|
|
|
v[i].XYZ.X -= 128u;
|
|
|
|
else
|
|
|
|
v[i + 1].XYZ.X += 128u;
|
|
|
|
|
|
|
|
if (ps_sel.read_ba)
|
|
|
|
v[i].U -= 128u;
|
|
|
|
else
|
|
|
|
v[i + 1].U += 128u;
|
|
|
|
|
|
|
|
// Height is too big (2x).
|
|
|
|
int tex_offset = v[i].V & 0xF;
|
|
|
|
GSVector4i offset(o.OFY, tex_offset, o.OFY, tex_offset);
|
|
|
|
|
|
|
|
GSVector4i tmp(v[i].XYZ.Y, v[i].V, v[i + 1].XYZ.Y, v[i + 1].V);
|
2015-06-10 18:10:10 +00:00
|
|
|
tmp = GSVector4i(tmp - offset).srl32(1) + offset;
|
2015-06-09 23:17:26 +00:00
|
|
|
|
2016-04-14 10:00:58 +00:00
|
|
|
v[i].XYZ.Y = (uint16)tmp.x;
|
|
|
|
v[i].V = (uint16)tmp.y;
|
|
|
|
v[i + 1].XYZ.Y = (uint16)tmp.z;
|
|
|
|
v[i + 1].V = (uint16)tmp.w;
|
2015-06-09 23:17:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Please bang my head against the wall!
|
|
|
|
// 1/ Reduce the frame mask to a 16 bit format
|
2016-08-19 14:02:49 +00:00
|
|
|
const uint32& m = m_context->FRAME.FBMSK;
|
2015-06-09 23:17:26 +00:00
|
|
|
uint32 fbmask = ((m >> 3) & 0x1F) | ((m >> 6) & 0x3E0) | ((m >> 9) & 0x7C00) | ((m >> 31) & 0x8000);
|
|
|
|
om_bsel.wrgba = 0;
|
|
|
|
|
|
|
|
// 2 Select the new mask (Please someone put SSE here)
|
|
|
|
if ((fbmask & 0xFF) == 0) {
|
|
|
|
if (write_ba)
|
|
|
|
om_bsel.wb = 1;
|
|
|
|
else
|
|
|
|
om_bsel.wr = 1;
|
|
|
|
}
|
|
|
|
else if ((fbmask & 0xFF) != 0xFF) {
|
2016-01-02 17:53:15 +00:00
|
|
|
#ifdef _DEBUG
|
2017-01-22 18:05:23 +00:00
|
|
|
fprintf(stderr, "Please fix me! wb %u wr %u\n", om_bsel.wb, om_bsel.wr);
|
2016-01-02 17:53:15 +00:00
|
|
|
#endif
|
2015-06-09 23:17:26 +00:00
|
|
|
//ASSERT(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
fbmask >>= 8;
|
|
|
|
if ((fbmask & 0xFF) == 0) {
|
|
|
|
if (write_ba)
|
|
|
|
om_bsel.wa = 1;
|
|
|
|
else
|
|
|
|
om_bsel.wg = 1;
|
|
|
|
}
|
|
|
|
else if ((fbmask & 0xFF) != 0xFF) {
|
2016-01-02 17:53:15 +00:00
|
|
|
#ifdef _DEBUG
|
2017-01-22 18:05:23 +00:00
|
|
|
fprintf(stderr, "Please fix me! wa %u wg %u\n", om_bsel.wa, om_bsel.wg);
|
2016-01-02 17:53:15 +00:00
|
|
|
#endif
|
2015-06-09 23:17:26 +00:00
|
|
|
//ASSERT(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else {
|
2016-08-19 14:02:49 +00:00
|
|
|
//ps_sel.fmt = GSLocalMemory::m_psm[m_context->FRAME.PSM].fmt;
|
2015-06-09 23:17:26 +00:00
|
|
|
|
2016-08-19 14:02:49 +00:00
|
|
|
om_bsel.wrgba = ~GSVector4i::load((int)m_context->FRAME.FBMSK).eq8(GSVector4i::xffffffff()).mask();
|
2015-06-09 23:17:26 +00:00
|
|
|
}
|
|
|
|
|
2012-01-05 02:40:24 +00:00
|
|
|
if(DATE)
|
|
|
|
{
|
|
|
|
if(dev->HasStencil())
|
|
|
|
{
|
|
|
|
om_dssel.date = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-19 14:02:49 +00:00
|
|
|
ps_sel.date = 1 + m_context->TEST.DATM;
|
2012-01-05 02:40:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-19 14:02:49 +00:00
|
|
|
if(m_env.COLCLAMP.CLAMP == 0 && /* hack */ !tex && PRIM->PRIM != GS_POINTLIST)
|
2012-01-05 02:40:24 +00:00
|
|
|
{
|
|
|
|
ps_sel.colclip = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ps_sel.clr1 = om_bsel.IsCLR1();
|
2016-08-19 14:02:49 +00:00
|
|
|
ps_sel.fba = m_context->FBA.FBA;
|
|
|
|
ps_sel.aout = m_context->FRAME.PSM == PSM_PSMCT16 || m_context->FRAME.PSM == PSM_PSMCT16S || (m_context->FRAME.FBMSK & 0xff000000) == 0x7f000000 ? 1 : 0;
|
2015-06-09 23:17:26 +00:00
|
|
|
ps_sel.aout &= !ps_sel.shuffle;
|
2012-01-05 02:40:24 +00:00
|
|
|
if(UserHacks_AlphaHack) ps_sel.aout = 1;
|
|
|
|
|
|
|
|
if(PRIM->FGE)
|
|
|
|
{
|
|
|
|
ps_sel.fog = 1;
|
|
|
|
|
2016-08-19 14:02:49 +00:00
|
|
|
ps_cb.FogColor_AREF = GSVector4::rgba32(m_env.FOGCOL.u32[0]) / 255;
|
2012-01-05 02:40:24 +00:00
|
|
|
}
|
|
|
|
|
2016-08-14 16:35:42 +00:00
|
|
|
// Warning must be done after EmulateZbuffer
|
|
|
|
// Depth test is always true so it can be executed in 2 passes (no order required) unlike color.
|
|
|
|
// The idea is to compute first the color which is independent of the alpha test. And then do a 2nd
|
|
|
|
// pass to handle the depth based on the alpha test.
|
2016-08-28 13:13:15 +00:00
|
|
|
bool ate_RGBA_then_Z = false;
|
|
|
|
bool ate_RGB_then_ZA = false;
|
|
|
|
if (ate_first_pass & ate_second_pass) {
|
|
|
|
#ifdef _DEBUG
|
|
|
|
fprintf(stdout, "Complex Alpha Test\n");
|
|
|
|
#endif
|
2016-09-18 15:24:33 +00:00
|
|
|
bool commutative_depth = (om_dssel.ztst == ZTST_GEQUAL && m_vt.m_eq.z) || (om_dssel.ztst == ZTST_ALWAYS);
|
2016-08-28 13:13:15 +00:00
|
|
|
bool commutative_alpha = (m_context->ALPHA.C != 1); // when either Alpha Src or a constant
|
|
|
|
|
|
|
|
ate_RGBA_then_Z = (m_context->TEST.AFAIL == AFAIL_FB_ONLY) & commutative_depth;
|
|
|
|
ate_RGB_then_ZA = (m_context->TEST.AFAIL == AFAIL_RGB_ONLY) & commutative_depth & commutative_alpha;
|
|
|
|
}
|
2012-01-05 02:40:24 +00:00
|
|
|
|
2016-09-19 06:48:32 +00:00
|
|
|
if (ate_RGBA_then_Z) {
|
2016-08-14 16:35:42 +00:00
|
|
|
#ifdef _DEBUG
|
2016-08-28 13:13:15 +00:00
|
|
|
fprintf(stdout, "Alternate ATE handling: ate_RGBA_then_Z\n");
|
2016-08-14 16:35:42 +00:00
|
|
|
#endif
|
|
|
|
// Render all color but don't update depth
|
|
|
|
// ATE is disabled here
|
|
|
|
om_dssel.zwe = false;
|
2016-08-28 13:13:15 +00:00
|
|
|
} else if (ate_RGB_then_ZA) {
|
|
|
|
#ifdef _DEBUG
|
|
|
|
fprintf(stdout, "Alternate ATE handling: ate_RGB_then_ZA\n");
|
|
|
|
#endif
|
|
|
|
// Render RGB color but don't update depth/alpha
|
|
|
|
// ATE is disabled here
|
|
|
|
om_dssel.zwe = false;
|
|
|
|
om_bsel.wa = false;
|
|
|
|
} else {
|
2016-08-14 16:35:42 +00:00
|
|
|
EmulateAtst(1, tex);
|
2012-07-24 02:20:07 +00:00
|
|
|
}
|
|
|
|
|
2016-10-13 22:28:31 +00:00
|
|
|
// Destination alpha pseudo stencil hack: use a stencil operation combined with an alpha test
|
|
|
|
// to only draw pixels which would cause the destination alpha test to fail in the future once.
|
|
|
|
// Unfortunately this also means only drawing those pixels at all, which is why this is a hack.
|
|
|
|
// The interaction with FBA in D3D9 is probably less than ideal.
|
|
|
|
if (UserHacks_AlphaStencil && DATE && dev->HasStencil() && om_bsel.wa && !m_context->TEST.ATE)
|
|
|
|
{
|
|
|
|
if (!m_context->FBA.FBA)
|
|
|
|
{
|
|
|
|
if (m_context->TEST.DATM == 0)
|
|
|
|
ps_sel.atst = 2; // >=
|
|
|
|
else {
|
|
|
|
if (tex && tex->m_spritehack_t)
|
|
|
|
ps_sel.atst = 0; // <
|
|
|
|
else
|
|
|
|
ps_sel.atst = 1; // <
|
|
|
|
}
|
|
|
|
ps_cb.FogColor_AREF.a = (float)0x80;
|
|
|
|
}
|
|
|
|
if (!(m_context->FBA.FBA && m_context->TEST.DATM == 1))
|
|
|
|
om_dssel.alpha_stencil = 1;
|
|
|
|
}
|
|
|
|
|
2012-01-05 02:40:24 +00:00
|
|
|
if(tex)
|
|
|
|
{
|
2016-08-19 14:02:49 +00:00
|
|
|
const GSLocalMemory::psm_t &psm = GSLocalMemory::m_psm[m_context->TEX0.PSM];
|
|
|
|
const GSLocalMemory::psm_t &cpsm = psm.pal > 0 ? GSLocalMemory::m_psm[m_context->TEX0.CPSM] : psm;
|
2016-09-25 14:19:27 +00:00
|
|
|
// The texture cache will handle various format conversion internally for non-target texture
|
|
|
|
// After the conversion the texture will be RGBA8 (aka 32 bits) hence the 0 below
|
|
|
|
int gpu_tex_fmt = (tex->m_target) ? cpsm.fmt : 0;
|
|
|
|
|
2017-02-24 16:55:39 +00:00
|
|
|
bool bilinear = m_vt.IsLinear();
|
2016-10-02 15:19:16 +00:00
|
|
|
bool simple_sample = !tex->m_palette && gpu_tex_fmt == 0 && m_context->CLAMP.WMS < 2 && m_context->CLAMP.WMT < 2;
|
2012-06-11 03:27:16 +00:00
|
|
|
|
2016-08-19 14:02:49 +00:00
|
|
|
ps_sel.wms = m_context->CLAMP.WMS;
|
|
|
|
ps_sel.wmt = m_context->CLAMP.WMT;
|
2015-06-09 23:17:26 +00:00
|
|
|
if (ps_sel.shuffle) {
|
|
|
|
ps_sel.fmt = 0;
|
2015-07-01 07:28:32 +00:00
|
|
|
} else {
|
2016-09-25 14:19:27 +00:00
|
|
|
ps_sel.fmt = tex->m_palette ? gpu_tex_fmt | 4 : gpu_tex_fmt;
|
2015-06-09 23:17:26 +00:00
|
|
|
}
|
2016-08-19 14:02:49 +00:00
|
|
|
ps_sel.aem = m_env.TEXA.AEM;
|
|
|
|
ps_sel.tfx = m_context->TEX0.TFX;
|
|
|
|
ps_sel.tcc = m_context->TEX0.TCC;
|
2012-06-27 00:57:44 +00:00
|
|
|
ps_sel.ltf = bilinear && !simple_sample;
|
2012-01-05 02:40:24 +00:00
|
|
|
ps_sel.rt = tex->m_target;
|
2012-06-19 01:12:01 +00:00
|
|
|
ps_sel.spritehack = tex->m_spritehack_t;
|
2012-07-19 20:40:42 +00:00
|
|
|
ps_sel.point_sampler = !(bilinear && simple_sample);
|
2012-01-05 02:40:24 +00:00
|
|
|
|
|
|
|
int w = tex->m_texture->GetWidth();
|
|
|
|
int h = tex->m_texture->GetHeight();
|
|
|
|
|
2016-08-19 14:02:49 +00:00
|
|
|
int tw = (int)(1 << m_context->TEX0.TW);
|
|
|
|
int th = (int)(1 << m_context->TEX0.TH);
|
2012-01-05 02:40:24 +00:00
|
|
|
|
|
|
|
GSVector4 WH(tw, th, w, h);
|
|
|
|
|
|
|
|
if(PRIM->FST)
|
|
|
|
{
|
|
|
|
vs_cb.TextureScale = GSVector4(1.0f / 16) / WH.xyxy();
|
|
|
|
//Maybe better?
|
|
|
|
//vs_cb.TextureScale = GSVector4(1.0f / 16) * GSVector4(tex->m_texture->GetScale()).xyxy() / WH.zwzw();
|
|
|
|
ps_sel.fst = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ps_cb.WH = WH;
|
|
|
|
ps_cb.HalfTexel = GSVector4(-0.5f, 0.5f).xxyy() / WH.zwzw();
|
2016-08-19 14:02:49 +00:00
|
|
|
ps_cb.MskFix = GSVector4i(m_context->CLAMP.MINU, m_context->CLAMP.MINV, m_context->CLAMP.MAXU, m_context->CLAMP.MAXV);
|
2012-01-05 02:40:24 +00:00
|
|
|
|
2013-02-12 10:57:48 +00:00
|
|
|
// TC Offset Hack
|
|
|
|
ps_sel.tcoffsethack = !!UserHacks_TCOffset;
|
|
|
|
ps_cb.TC_OffsetHack = GSVector4(UserHacks_TCO_x, UserHacks_TCO_y).xyxy() / WH.xyxy();
|
|
|
|
|
2012-01-05 02:40:24 +00:00
|
|
|
GSVector4 clamp(ps_cb.MskFix);
|
2016-08-19 14:02:49 +00:00
|
|
|
GSVector4 ta(m_env.TEXA & GSVector4i::x000000ff());
|
2012-01-05 02:40:24 +00:00
|
|
|
|
|
|
|
ps_cb.MinMax = clamp / WH.xyxy();
|
|
|
|
ps_cb.MinF_TA = (clamp + 0.5f).xyxy(ta) / WH.xyxy(GSVector4(255, 255));
|
|
|
|
|
2016-08-19 14:02:49 +00:00
|
|
|
ps_ssel.tau = (m_context->CLAMP.WMS + 3) >> 1;
|
|
|
|
ps_ssel.tav = (m_context->CLAMP.WMT + 3) >> 1;
|
2012-06-27 00:57:44 +00:00
|
|
|
ps_ssel.ltf = bilinear && simple_sample;
|
2012-01-05 02:40:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ps_sel.tfx = 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
// rs
|
|
|
|
|
2016-08-19 14:02:49 +00:00
|
|
|
GSVector4i scissor = GSVector4i(GSVector4(rtscale).xyxy() * m_context->scissor.in).rintersect(GSVector4i(rtsize).zwxy());
|
2012-01-05 02:40:24 +00:00
|
|
|
|
|
|
|
dev->OMSetRenderTargets(rt, ds, &scissor);
|
|
|
|
dev->PSSetShaderResource(0, tex ? tex->m_texture : NULL);
|
|
|
|
dev->PSSetShaderResource(1, tex ? tex->m_palette : NULL);
|
|
|
|
dev->PSSetShaderResource(2, rtcopy);
|
|
|
|
|
2016-08-19 14:02:49 +00:00
|
|
|
uint8 afix = m_context->ALPHA.FIX;
|
2012-01-05 02:40:24 +00:00
|
|
|
|
2012-01-19 10:24:07 +00:00
|
|
|
SetupIA();
|
|
|
|
|
2012-01-05 02:40:24 +00:00
|
|
|
dev->SetupOM(om_dssel, om_bsel, afix);
|
|
|
|
dev->SetupVS(vs_sel, &vs_cb);
|
|
|
|
dev->SetupGS(gs_sel);
|
|
|
|
dev->SetupPS(ps_sel, &ps_cb, ps_ssel);
|
|
|
|
|
|
|
|
// draw
|
|
|
|
|
2016-08-14 16:35:42 +00:00
|
|
|
if (ate_first_pass)
|
2012-01-05 02:40:24 +00:00
|
|
|
{
|
|
|
|
dev->DrawIndexedPrimitive();
|
|
|
|
|
2016-08-19 14:02:49 +00:00
|
|
|
if (m_env.COLCLAMP.CLAMP == 0 && /* hack */ !tex && PRIM->PRIM != GS_POINTLIST)
|
2012-01-05 02:40:24 +00:00
|
|
|
{
|
|
|
|
GSDeviceDX::OMBlendSelector om_bselneg(om_bsel);
|
|
|
|
GSDeviceDX::PSSelector ps_selneg(ps_sel);
|
|
|
|
|
|
|
|
om_bselneg.negative = 1;
|
|
|
|
ps_selneg.colclip = 2;
|
|
|
|
|
|
|
|
dev->SetupOM(om_dssel, om_bselneg, afix);
|
|
|
|
dev->SetupPS(ps_selneg, &ps_cb, ps_ssel);
|
|
|
|
|
|
|
|
dev->DrawIndexedPrimitive();
|
2012-07-23 20:24:09 +00:00
|
|
|
dev->SetupOM(om_dssel, om_bsel, afix);
|
2012-01-05 02:40:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-14 16:35:42 +00:00
|
|
|
if (ate_second_pass)
|
2012-01-05 02:40:24 +00:00
|
|
|
{
|
2016-08-19 14:02:49 +00:00
|
|
|
ASSERT(!m_env.PABE.PABE);
|
2012-01-05 02:40:24 +00:00
|
|
|
|
2016-08-28 13:13:15 +00:00
|
|
|
if (ate_RGBA_then_Z | ate_RGB_then_ZA) {
|
2016-08-14 16:35:42 +00:00
|
|
|
// Enable ATE as first pass to update the depth
|
|
|
|
// of pixels that passed the alpha test
|
|
|
|
EmulateAtst(1, tex);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// second pass will process the pixels that failed
|
|
|
|
// the alpha test
|
|
|
|
EmulateAtst(2, tex);
|
|
|
|
}
|
2012-01-05 02:40:24 +00:00
|
|
|
|
|
|
|
dev->SetupPS(ps_sel, &ps_cb, ps_ssel);
|
|
|
|
|
|
|
|
bool z = om_dssel.zwe;
|
|
|
|
bool r = om_bsel.wr;
|
|
|
|
bool g = om_bsel.wg;
|
|
|
|
bool b = om_bsel.wb;
|
|
|
|
bool a = om_bsel.wa;
|
|
|
|
|
2016-08-19 14:02:49 +00:00
|
|
|
switch(m_context->TEST.AFAIL)
|
2012-01-05 02:40:24 +00:00
|
|
|
{
|
2016-08-14 16:35:42 +00:00
|
|
|
case 0: z = r = g = b = a = false; break; // none
|
|
|
|
case 1: z = false; break; // rgba
|
|
|
|
case 2: r = g = b = a = false; break; // z
|
|
|
|
case 3: z = a = false; break; // rgb
|
|
|
|
default: __assume(0);
|
|
|
|
}
|
|
|
|
|
2017-03-11 15:00:40 +00:00
|
|
|
// Depth test should be disabled when depth writes are masked and similarly, Alpha test must be disabled
|
|
|
|
// when writes to all of the alpha bits in the Framebuffer are masked.
|
2016-08-28 13:13:15 +00:00
|
|
|
if (ate_RGBA_then_Z) {
|
2016-09-19 06:56:49 +00:00
|
|
|
z = !m_context->ZBUF.ZMSK;
|
2016-08-14 16:35:42 +00:00
|
|
|
r = g = b = a = false;
|
2016-08-28 13:13:15 +00:00
|
|
|
} else if (ate_RGB_then_ZA) {
|
2016-09-19 06:56:49 +00:00
|
|
|
z = !m_context->ZBUF.ZMSK;
|
2017-03-11 15:00:40 +00:00
|
|
|
a = (m_context->FRAME.FBMSK & 0xFF000000) != 0xFF000000;
|
2016-08-28 13:13:15 +00:00
|
|
|
r = g = b = false;
|
2012-01-05 02:40:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(z || r || g || b || a)
|
|
|
|
{
|
|
|
|
om_dssel.zwe = z;
|
|
|
|
om_bsel.wr = r;
|
|
|
|
om_bsel.wg = g;
|
|
|
|
om_bsel.wb = b;
|
|
|
|
om_bsel.wa = a;
|
|
|
|
|
|
|
|
dev->SetupOM(om_dssel, om_bsel, afix);
|
|
|
|
|
|
|
|
dev->DrawIndexedPrimitive();
|
|
|
|
|
2016-08-19 14:02:49 +00:00
|
|
|
if (m_env.COLCLAMP.CLAMP == 0 && /* hack */ !tex && PRIM->PRIM != GS_POINTLIST)
|
2012-01-05 02:40:24 +00:00
|
|
|
{
|
|
|
|
GSDeviceDX::OMBlendSelector om_bselneg(om_bsel);
|
|
|
|
GSDeviceDX::PSSelector ps_selneg(ps_sel);
|
|
|
|
|
|
|
|
om_bselneg.negative = 1;
|
|
|
|
ps_selneg.colclip = 2;
|
|
|
|
|
|
|
|
dev->SetupOM(om_dssel, om_bselneg, afix);
|
|
|
|
dev->SetupPS(ps_selneg, &ps_cb, ps_ssel);
|
|
|
|
|
|
|
|
dev->DrawIndexedPrimitive();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dev->EndScene();
|
|
|
|
|
|
|
|
dev->Recycle(rtcopy);
|
|
|
|
|
|
|
|
if(om_dssel.fba) UpdateFBA(rt);
|
|
|
|
}
|