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
|
|
|
|
2018-10-02 00:16:38 +00:00
|
|
|
if (theApp.GetConfigB("UserHacks"))
|
|
|
|
{
|
2016-05-24 19:52:06 +00:00
|
|
|
UserHacks_AlphaHack = theApp.GetConfigB("UserHacks_AlphaHack");
|
|
|
|
UserHacks_AlphaStencil = theApp.GetConfigB("UserHacks_AlphaStencil");
|
2017-02-17 09:59:21 +00:00
|
|
|
UserHacks_HPO = theApp.GetConfigI("UserHacks_HalfPixelOffset");
|
2018-10-02 00:16:38 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-05-24 19:52:06 +00:00
|
|
|
UserHacks_AlphaHack = false;
|
|
|
|
UserHacks_AlphaStencil = false;
|
2017-02-17 09:59:21 +00:00
|
|
|
UserHacks_HPO = 0;
|
2016-05-24 19:52:06 +00:00
|
|
|
}
|
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)
|
|
|
|
{
|
2017-03-03 21:18:49 +00:00
|
|
|
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
|
|
|
|
2018-10-02 00:16:38 +00:00
|
|
|
switch (atst)
|
|
|
|
{
|
2017-03-03 21:18:49 +00:00
|
|
|
case ATST_LESS:
|
2018-10-02 00:16:38 +00:00
|
|
|
if (tex && tex->m_spritehack_t)
|
|
|
|
{
|
2017-03-03 21:18:49 +00:00
|
|
|
m_ps_sel.atst = 0;
|
2018-10-02 00:16:38 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-03-03 21:18:49 +00:00
|
|
|
ps_cb.FogColor_AREF.a = (float)m_context->TEST.AREF - 0.1f;
|
|
|
|
m_ps_sel.atst = 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ATST_LEQUAL:
|
|
|
|
ps_cb.FogColor_AREF.a = (float)m_context->TEST.AREF - 0.1f + 1.0f;
|
2017-02-17 09:59:21 +00:00
|
|
|
m_ps_sel.atst = 1;
|
2017-03-03 21:18:49 +00:00
|
|
|
break;
|
|
|
|
case ATST_GEQUAL:
|
|
|
|
// Maybe a -1 trick multiplication factor could be used to merge with ATST_LEQUAL case
|
|
|
|
ps_cb.FogColor_AREF.a = (float)m_context->TEST.AREF - 0.1f;
|
|
|
|
m_ps_sel.atst = 2;
|
|
|
|
break;
|
|
|
|
case ATST_GREATER:
|
|
|
|
// Maybe a -1 trick multiplication factor could be used to merge with ATST_LESS case
|
|
|
|
ps_cb.FogColor_AREF.a = (float)m_context->TEST.AREF - 0.1f + 1.0f;
|
|
|
|
m_ps_sel.atst = 2;
|
|
|
|
break;
|
|
|
|
case ATST_EQUAL:
|
|
|
|
ps_cb.FogColor_AREF.a = (float)m_context->TEST.AREF;
|
|
|
|
m_ps_sel.atst = 3;
|
|
|
|
break;
|
|
|
|
case ATST_NOTEQUAL:
|
|
|
|
ps_cb.FogColor_AREF.a = (float)m_context->TEST.AREF;
|
|
|
|
m_ps_sel.atst = 4;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ATST_NEVER: // Draw won't be done so no need to implement it in shader
|
|
|
|
case ATST_ALWAYS:
|
|
|
|
default:
|
|
|
|
m_ps_sel.atst = 0;
|
|
|
|
break;
|
2016-08-14 16:35:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GSRendererDX::EmulateZbuffer()
|
|
|
|
{
|
2016-08-19 14:02:49 +00:00
|
|
|
if (m_context->TEST.ZTE)
|
2016-08-14 16:35:42 +00:00
|
|
|
{
|
2018-11-13 00:25:15 +00:00
|
|
|
m_om_dssel.ztst = m_context->TEST.ZTST;
|
|
|
|
m_om_dssel.zwe = !m_context->ZBUF.ZMSK;
|
2016-08-14 16:35:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-11-13 00:25:15 +00:00
|
|
|
m_om_dssel.ztst = ZTST_ALWAYS;
|
2016-08-14 16:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32 max_z;
|
2018-10-02 00:16:38 +00:00
|
|
|
if (m_context->ZBUF.PSM == PSM_PSMZ32)
|
|
|
|
{
|
2016-08-14 16:35:42 +00:00
|
|
|
max_z = 0xFFFFFFFF;
|
|
|
|
}
|
2018-10-02 00:16:38 +00:00
|
|
|
else if (m_context->ZBUF.PSM == PSM_PSMZ24)
|
|
|
|
{
|
2016-08-14 16:35:42 +00:00
|
|
|
max_z = 0xFFFFFF;
|
|
|
|
}
|
2018-10-02 00:16:38 +00:00
|
|
|
else
|
|
|
|
{
|
2016-08-14 16:35:42 +00:00
|
|
|
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.
|
|
|
|
|
2018-11-13 00:25:15 +00:00
|
|
|
if (m_om_dssel.ztst >= ZTST_ALWAYS && m_om_dssel.zwe && (m_context->ZBUF.PSM != PSM_PSMZ32))
|
2018-10-02 00:16:38 +00:00
|
|
|
{
|
|
|
|
if (m_vt.m_max.p.z > max_z)
|
|
|
|
{
|
2016-08-14 16:35:42 +00:00
|
|
|
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.
|
2018-10-02 00:16:38 +00:00
|
|
|
if (m_vt.m_min.p.z > max_z)
|
|
|
|
{
|
2016-08-14 16:35:42 +00:00
|
|
|
#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
|
2018-11-13 00:25:15 +00:00
|
|
|
m_om_dssel.ztst = ZTST_ALWAYS;
|
2016-08-14 16:35:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GSVertex* v = &m_vertex.buff[0];
|
|
|
|
// Minor optimization of a corner case (it allow to better emulate some alpha test effects)
|
2018-11-13 00:25:15 +00:00
|
|
|
if (m_om_dssel.ztst == ZTST_GEQUAL && m_vt.m_eq.z && v[0].XYZ.Z == max_z)
|
2018-10-02 00:16:38 +00:00
|
|
|
{
|
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
|
2018-11-13 00:25:15 +00:00
|
|
|
m_om_dssel.ztst = ZTST_ALWAYS;
|
2016-08-14 16:35:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-17 09:59:21 +00:00
|
|
|
void GSRendererDX::EmulateTextureSampler(const GSTextureCache::Source* tex)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
|
|
|
const uint8 wms = m_context->CLAMP.WMS;
|
|
|
|
const uint8 wmt = m_context->CLAMP.WMT;
|
|
|
|
bool complex_wms_wmt = !!((wms | wmt) & 2);
|
|
|
|
|
|
|
|
bool bilinear = m_vt.IsLinear();
|
|
|
|
bool shader_emulated_sampler = tex->m_palette || cpsm.fmt != 0 || complex_wms_wmt;
|
|
|
|
|
|
|
|
// 1 and 0 are equivalent
|
|
|
|
m_ps_sel.wms = (wms & 2) ? wms : 0;
|
|
|
|
m_ps_sel.wmt = (wmt & 2) ? wmt : 0;
|
|
|
|
|
|
|
|
int w = tex->m_texture->GetWidth();
|
|
|
|
int h = tex->m_texture->GetHeight();
|
|
|
|
|
|
|
|
int tw = (int)(1 << m_context->TEX0.TW);
|
|
|
|
int th = (int)(1 << m_context->TEX0.TH);
|
|
|
|
|
|
|
|
GSVector4 WH(tw, th, w, h);
|
|
|
|
|
|
|
|
// Performance note:
|
|
|
|
// 1/ Don't set 0 as it is the default value
|
|
|
|
// 2/ Only keep aem when it is useful (avoid useless shader permutation)
|
2018-10-02 00:16:38 +00:00
|
|
|
if (m_ps_sel.shuffle)
|
|
|
|
{
|
2017-02-17 09:59:21 +00:00
|
|
|
// Force a 32 bits access (normally shuffle is done on 16 bits)
|
2018-10-02 00:16:38 +00:00
|
|
|
// m_ps_sel.fmt = 0; // removed as an optimization
|
2017-02-17 09:59:21 +00:00
|
|
|
m_ps_sel.aem = m_env.TEXA.AEM;
|
|
|
|
ASSERT(tex->m_target);
|
|
|
|
|
|
|
|
// Shuffle is a 16 bits format, so aem is always required
|
|
|
|
GSVector4 ta(m_env.TEXA & GSVector4i::x000000ff());
|
|
|
|
ps_cb.MinF_TA = (GSVector4(ps_cb.MskFix) + 0.5f).xyxy(ta) / WH.xyxy(GSVector4(255, 255));
|
|
|
|
|
|
|
|
bilinear &= m_vt.IsLinear();
|
|
|
|
|
|
|
|
GSVector4 half_offset = RealignTargetTextureCoordinate(tex);
|
|
|
|
vs_cb.Texture_Scale_Offset.z = half_offset.x;
|
|
|
|
vs_cb.Texture_Scale_Offset.w = half_offset.y;
|
|
|
|
|
2018-10-02 00:16:38 +00:00
|
|
|
}
|
|
|
|
else if (tex->m_target)
|
|
|
|
{
|
2017-02-17 09:59:21 +00:00
|
|
|
// Use an old target. AEM and index aren't resolved it must be done
|
|
|
|
// on the GPU
|
|
|
|
|
|
|
|
// Select the 32/24/16 bits color (AEM)
|
|
|
|
m_ps_sel.fmt = cpsm.fmt;
|
|
|
|
m_ps_sel.aem = m_env.TEXA.AEM;
|
|
|
|
|
|
|
|
// Don't upload AEM if format is 32 bits
|
2018-10-02 00:16:38 +00:00
|
|
|
if (cpsm.fmt)
|
|
|
|
{
|
2017-02-17 09:59:21 +00:00
|
|
|
GSVector4 ta(m_env.TEXA & GSVector4i::x000000ff());
|
|
|
|
ps_cb.MinF_TA = (GSVector4(ps_cb.MskFix) + 0.5f).xyxy(ta) / WH.xyxy(GSVector4(255, 255));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Select the index format
|
2018-10-02 00:16:38 +00:00
|
|
|
if (tex->m_palette)
|
|
|
|
{
|
2017-02-17 09:59:21 +00:00
|
|
|
// FIXME Potentially improve fmt field in GSLocalMemory
|
|
|
|
if (m_context->TEX0.PSM == PSM_PSMT4HL)
|
|
|
|
m_ps_sel.fmt |= 1 << 2;
|
|
|
|
else if (m_context->TEX0.PSM == PSM_PSMT4HH)
|
|
|
|
m_ps_sel.fmt |= 2 << 2;
|
|
|
|
else
|
|
|
|
m_ps_sel.fmt |= 3 << 2;
|
|
|
|
|
|
|
|
// Alpha channel of the RT is reinterpreted as an index. Star
|
|
|
|
// Ocean 3 uses it to emulate a stencil buffer. It is a very
|
|
|
|
// bad idea to force bilinear filtering on it.
|
|
|
|
bilinear &= m_vt.IsLinear();
|
|
|
|
}
|
|
|
|
|
2018-12-12 18:03:08 +00:00
|
|
|
// Depth format
|
|
|
|
if (tex->m_texture->GetType() == GSTexture::DepthStencil)
|
|
|
|
{
|
|
|
|
// Require a float conversion if the texure is a depth format
|
|
|
|
m_ps_sel.depth_fmt = (psm.bpp == 16) ? 2 : 1;
|
|
|
|
// m_vs_sel.int_fst = !PRIM->FST; // select float/int coordinate
|
|
|
|
|
|
|
|
// Don't force interpolation on depth format
|
|
|
|
bilinear &= m_vt.IsLinear();
|
|
|
|
}
|
|
|
|
|
2017-02-17 09:59:21 +00:00
|
|
|
GSVector4 half_offset = RealignTargetTextureCoordinate(tex);
|
|
|
|
vs_cb.Texture_Scale_Offset.z = half_offset.x;
|
|
|
|
vs_cb.Texture_Scale_Offset.w = half_offset.y;
|
|
|
|
}
|
2018-10-02 00:16:38 +00:00
|
|
|
else if (tex->m_palette)
|
|
|
|
{
|
2017-02-17 09:59:21 +00:00
|
|
|
// Use a standard 8 bits texture. AEM is already done on the CLUT
|
|
|
|
// Therefore you only need to set the index
|
|
|
|
// m_ps_sel.aem = 0; // removed as an optimization
|
|
|
|
|
|
|
|
// Note 4 bits indexes are converted to 8 bits
|
|
|
|
m_ps_sel.fmt = 3 << 2;
|
|
|
|
|
|
|
|
}
|
2018-10-02 00:16:38 +00:00
|
|
|
else
|
|
|
|
{
|
2017-02-17 09:59:21 +00:00
|
|
|
// Standard texture. Both index and AEM expansion were already done by the CPU.
|
2018-10-02 00:16:38 +00:00
|
|
|
// m_ps_sel.fmt = 0; // removed as an optimization
|
|
|
|
// m_ps_sel.aem = 0; // removed as an optimization
|
2017-02-17 09:59:21 +00:00
|
|
|
}
|
|
|
|
|
2018-10-02 00:16:38 +00:00
|
|
|
if (m_context->TEX0.TFX == TFX_MODULATE && m_vt.m_eq.rgba == 0xFFFF && m_vt.m_min.c.eq(GSVector4i(128)))
|
|
|
|
{
|
2017-02-17 09:59:21 +00:00
|
|
|
// Micro optimization that reduces GPU load (removes 5 instructions on the FS program)
|
|
|
|
m_ps_sel.tfx = TFX_DECAL;
|
|
|
|
}
|
2018-10-02 00:16:38 +00:00
|
|
|
else
|
|
|
|
{
|
2017-02-17 09:59:21 +00:00
|
|
|
m_ps_sel.tfx = m_context->TEX0.TFX;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_ps_sel.tcc = m_context->TEX0.TCC;
|
|
|
|
|
|
|
|
m_ps_sel.ltf = bilinear && shader_emulated_sampler;
|
|
|
|
|
|
|
|
m_ps_sel.rt = tex->m_target;
|
|
|
|
m_ps_sel.spritehack = tex->m_spritehack_t;
|
2018-08-21 22:51:19 +00:00
|
|
|
m_ps_sel.point_sampler = !bilinear || shader_emulated_sampler;
|
2017-02-17 09:59:21 +00:00
|
|
|
|
|
|
|
if (PRIM->FST)
|
|
|
|
{
|
|
|
|
GSVector4 TextureScale = GSVector4(0.0625f) / WH.xyxy();
|
|
|
|
vs_cb.Texture_Scale_Offset.x = TextureScale.x;
|
|
|
|
vs_cb.Texture_Scale_Offset.y = TextureScale.y;
|
|
|
|
//Maybe better?
|
|
|
|
//vs_cb.TextureScale = GSVector4(1.0f / 16) * GSVector4(tex->m_texture->GetScale()).xyxy() / WH.zwzw();
|
|
|
|
m_ps_sel.fst = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ps_cb.WH = WH;
|
|
|
|
ps_cb.HalfTexel = GSVector4(-0.5f, 0.5f).xxyy() / WH.zwzw();
|
2018-10-02 00:16:38 +00:00
|
|
|
if (complex_wms_wmt)
|
|
|
|
{
|
2017-02-17 09:59:21 +00:00
|
|
|
ps_cb.MskFix = GSVector4i(m_context->CLAMP.MINU, m_context->CLAMP.MINV, m_context->CLAMP.MAXU, m_context->CLAMP.MAXV);
|
|
|
|
ps_cb.MinMax = GSVector4(ps_cb.MskFix) / WH.xyxy();
|
|
|
|
}
|
|
|
|
|
|
|
|
// TC Offset Hack
|
2018-09-10 20:13:34 +00:00
|
|
|
m_ps_sel.tcoffsethack = m_userhacks_tcoffset;
|
2018-09-10 16:22:27 +00:00
|
|
|
ps_cb.TC_OffsetHack = GSVector4(m_userhacks_tcoffset_x, m_userhacks_tcoffset_y).xyxy() / WH.xyxy();
|
2017-02-17 09:59:21 +00:00
|
|
|
|
2018-08-01 21:58:46 +00:00
|
|
|
// Only enable clamping in CLAMP mode. REGION_CLAMP will be done manually in the shader
|
|
|
|
m_ps_ssel.tau = (wms != CLAMP_CLAMP);
|
|
|
|
m_ps_ssel.tav = (wmt != CLAMP_CLAMP);
|
2017-02-17 09:59:21 +00:00
|
|
|
m_ps_ssel.ltf = bilinear && !shader_emulated_sampler;
|
|
|
|
}
|
|
|
|
|
2018-09-14 13:43:24 +00:00
|
|
|
void GSRendererDX::ResetStates()
|
|
|
|
{
|
|
|
|
m_vs_sel.key = 0;
|
|
|
|
m_gs_sel.key = 0;
|
|
|
|
m_ps_sel.key = 0;
|
|
|
|
|
2018-11-13 00:25:15 +00:00
|
|
|
m_ps_ssel.key = 0;
|
2018-11-13 00:56:11 +00:00
|
|
|
m_om_bsel.key = 0;
|
2018-11-13 00:25:15 +00:00
|
|
|
m_om_dssel.key = 0;
|
2018-09-14 13:43:24 +00:00
|
|
|
}
|
|
|
|
|
2012-01-05 02:40:24 +00:00
|
|
|
void GSRendererDX::DrawPrims(GSTexture* rt, GSTexture* ds, GSTextureCache::Source* tex)
|
|
|
|
{
|
2018-10-18 05:02:45 +00:00
|
|
|
GSTexture* rtcopy = NULL;
|
|
|
|
|
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
|
|
|
|
2018-10-04 03:39:01 +00:00
|
|
|
bool DATE = m_context->TEST.DATE && m_context->FRAME.PSM != PSM_PSMCT24;
|
2018-11-29 07:25:55 +00:00
|
|
|
bool DATE_one = false;
|
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
|
|
|
|
2018-09-14 13:43:24 +00:00
|
|
|
ResetStates();
|
2017-02-17 09:59:21 +00:00
|
|
|
vs_cb.Texture_Scale_Offset = GSVector4(0.0f);
|
|
|
|
|
2012-01-05 02:40:24 +00:00
|
|
|
ASSERT(m_dev != NULL);
|
2016-08-14 16:35:42 +00:00
|
|
|
dev = (GSDeviceDX*)m_dev;
|
2012-01-05 02:40:24 +00:00
|
|
|
|
2018-10-18 05:02:45 +00:00
|
|
|
// HLE implementation of the channel selection effect
|
|
|
|
//
|
|
|
|
// Warning it must be done at the begining because it will change the vertex list
|
2018-12-11 15:18:40 +00:00
|
|
|
EmulateChannelShuffle(&rt, tex);
|
2016-04-29 22:02:49 +00:00
|
|
|
|
2017-03-18 13:19:48 +00:00
|
|
|
// Upscaling hack to avoid various line/grid issues
|
|
|
|
MergeSprite(tex);
|
|
|
|
|
2018-10-18 05:02:45 +00:00
|
|
|
EmulateTextureShuffleAndFbmask();
|
|
|
|
|
2018-11-28 19:33:15 +00:00
|
|
|
// DATE: selection of the algorithm.
|
|
|
|
|
|
|
|
if (DATE)
|
|
|
|
{
|
2018-11-30 08:34:16 +00:00
|
|
|
if (m_om_bsel.wa && !m_context->TEST.ATE)
|
2018-11-28 19:33:15 +00:00
|
|
|
{
|
|
|
|
// Performance note: check alpha range with GetAlphaMinMax()
|
|
|
|
GetAlphaMinMax();
|
|
|
|
if (m_context->TEST.DATM && m_vt.m_alpha.max < 128)
|
|
|
|
{
|
|
|
|
// Only first pixel (write 0) will pass (alpha is 1)
|
|
|
|
// fprintf(stderr, "Fast DATE with alpha %d-%d\n", m_vt.m_alpha.min, m_vt.m_alpha.max);
|
2018-11-29 07:25:55 +00:00
|
|
|
DATE_one = true;
|
2018-11-28 19:33:15 +00:00
|
|
|
}
|
|
|
|
else if (!m_context->TEST.DATM && m_vt.m_alpha.min >= 128)
|
|
|
|
{
|
|
|
|
// Only first pixel (write 1) will pass (alpha is 0)
|
|
|
|
// fprintf(stderr, "Fast DATE with alpha %d-%d\n", m_vt.m_alpha.min, m_vt.m_alpha.max);
|
2018-11-29 07:25:55 +00:00
|
|
|
DATE_one = true;
|
2018-11-28 19:33:15 +00:00
|
|
|
}
|
|
|
|
else if ((m_vt.m_primclass == GS_SPRITE_CLASS /*&& m_drawlist.size() < 50*/) || (m_index.tail < 100))
|
|
|
|
{
|
|
|
|
// Direct3D doesn't support Slow DATE_GL45.
|
2018-11-29 07:25:55 +00:00
|
|
|
// Let's make sure it triggers this check and continues to use the old DATE code to avoid any issues with Fast Accurate Date.
|
2018-11-28 19:33:15 +00:00
|
|
|
// m_drawlist.size() isn't supported on D3D so there will be more games hitting this code path,
|
2018-11-29 07:25:55 +00:00
|
|
|
// it should be fine with regular DATE since originally it ran with it anyway.
|
2018-11-30 08:34:16 +00:00
|
|
|
// Note: Potentially Alpha Stencil might emulate SLOW DATE to some degree. Perhaps some of the code can be implemented here.
|
2018-11-28 19:33:15 +00:00
|
|
|
// fprintf(stderr, "Slow DATE with alpha %d-%d is not supported\n", m_vt.m_alpha.min, m_vt.m_alpha.max);
|
|
|
|
}
|
2018-11-30 08:34:16 +00:00
|
|
|
else if (!UserHacks_AlphaStencil)
|
2018-11-28 19:33:15 +00:00
|
|
|
{
|
|
|
|
if (m_accurate_date)
|
|
|
|
{
|
|
|
|
// fprintf(stderr, "Fast Accurate DATE with alpha %d-%d\n", m_vt.m_alpha.min, m_vt.m_alpha.max);
|
2018-11-29 07:25:55 +00:00
|
|
|
DATE_one = true;
|
2018-11-28 19:33:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// DATE is already true, no need for another check.
|
|
|
|
// fprintf(stderr, "Inaccurate DATE with alpha %d-%d\n", m_vt.m_alpha.min, m_vt.m_alpha.max);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!m_om_bsel.wa && !m_context->TEST.ATE)
|
|
|
|
{
|
|
|
|
// TODO: is it legal ? Likely but it need to be tested carefully.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-18 05:02:45 +00:00
|
|
|
// Blend
|
|
|
|
|
|
|
|
if (!IsOpaque())
|
|
|
|
{
|
2018-11-13 00:56:11 +00:00
|
|
|
m_om_bsel.abe = PRIM->ABE || PRIM->AA1 && m_vt.m_primclass == GS_LINE_CLASS;
|
2018-10-18 05:02:45 +00:00
|
|
|
|
2018-11-13 00:56:11 +00:00
|
|
|
m_om_bsel.a = m_context->ALPHA.A;
|
|
|
|
m_om_bsel.b = m_context->ALPHA.B;
|
|
|
|
m_om_bsel.c = m_context->ALPHA.C;
|
|
|
|
m_om_bsel.d = m_context->ALPHA.D;
|
2018-10-18 05:02:45 +00:00
|
|
|
|
|
|
|
if (m_env.PABE.PABE)
|
|
|
|
{
|
2018-11-13 00:56:11 +00:00
|
|
|
if (m_om_bsel.a == 0 && m_om_bsel.b == 1 && m_om_bsel.c == 0 && m_om_bsel.d == 1)
|
2018-10-18 05:02:45 +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
|
|
|
|
|
2018-11-13 00:56:11 +00:00
|
|
|
m_om_bsel.abe = 0;
|
2018-10-18 05:02:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//Breath of Fire Dragon Quarter triggers this in battles. Graphics are fine though.
|
|
|
|
//ASSERT(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8 afix = m_context->ALPHA.FIX;
|
|
|
|
|
|
|
|
if (m_ps_sel.dfmt == 1)
|
|
|
|
{
|
|
|
|
if (m_context->ALPHA.C == 1)
|
|
|
|
{
|
|
|
|
// 24 bits no alpha channel so use 1.0f fix factor as equivalent
|
|
|
|
m_context->ALPHA.C = 2;
|
|
|
|
afix = 0x00000001;
|
|
|
|
}
|
|
|
|
// Disable writing of the alpha channel
|
2018-11-13 00:56:11 +00:00
|
|
|
m_om_bsel.wa = 0;
|
2018-10-18 05:02:45 +00:00
|
|
|
}
|
|
|
|
|
2018-10-02 00:16:38 +00:00
|
|
|
if (DATE)
|
2012-01-05 02:40:24 +00:00
|
|
|
{
|
2018-10-02 00:16:38 +00:00
|
|
|
if (dev->HasStencil())
|
2012-01-05 02:40:24 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
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
|
|
|
{
|
2018-11-13 00:25:15 +00:00
|
|
|
m_om_dssel.fba = m_context->FBA.FBA;
|
2012-01-05 02:40:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// vs
|
|
|
|
|
2018-09-14 13:43:24 +00:00
|
|
|
m_vs_sel.tme = PRIM->TME;
|
|
|
|
m_vs_sel.fst = PRIM->FST;
|
|
|
|
m_vs_sel.logz = !dev->HasDepth32() && m_logz;
|
|
|
|
m_vs_sel.rtcopy = rtcopy != nullptr;
|
2012-01-05 02:40:24 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
2018-10-02 00:16:38 +00:00
|
|
|
if (rt && rt->LikelyOffset && UserHacks_HPO == 1)
|
2012-01-05 02:40:24 +00:00
|
|
|
{
|
|
|
|
// DX9 has pixelcenter set to 0.0, so give it some value here
|
|
|
|
|
2018-10-02 00:16:38 +00:00
|
|
|
if (m_pixelcenter.x == 0 && m_pixelcenter.y == 0)
|
|
|
|
{
|
|
|
|
ox2 = -0.0003f; oy2 = -0.0003f;
|
|
|
|
}
|
2012-01-05 02:40:24 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2017-03-03 21:18:49 +00:00
|
|
|
m_gs_sel.iip = PRIM->IIP;
|
|
|
|
m_gs_sel.prim = m_vt.m_primclass;
|
2012-01-05 02:40:24 +00:00
|
|
|
|
|
|
|
// ps
|
|
|
|
|
2018-10-02 00:16:38 +00:00
|
|
|
if (DATE)
|
2012-01-05 02:40:24 +00:00
|
|
|
{
|
2018-10-02 00:16:38 +00:00
|
|
|
if (dev->HasStencil())
|
2012-01-05 02:40:24 +00:00
|
|
|
{
|
2018-11-13 00:25:15 +00:00
|
|
|
m_om_dssel.date = 1;
|
2018-11-29 07:25:55 +00:00
|
|
|
if (DATE_one)
|
|
|
|
{
|
|
|
|
m_om_dssel.date_one = 1;
|
|
|
|
}
|
2012-01-05 02:40:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-02-17 09:59:21 +00:00
|
|
|
m_ps_sel.date = 1 + m_context->TEST.DATM;
|
2012-01-05 02:40:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-03 03:50:54 +00:00
|
|
|
bool colclip_wrap = m_env.COLCLAMP.CLAMP == 0 && !tex && PRIM->PRIM != GS_POINTLIST;
|
|
|
|
if (colclip_wrap)
|
2012-01-05 02:40:24 +00:00
|
|
|
{
|
2018-11-13 00:56:11 +00:00
|
|
|
if ((m_context->ALPHA.A == m_context->ALPHA.B) || !m_om_bsel.abe) // Optimize-away colclip
|
2018-10-03 05:41:10 +00:00
|
|
|
{
|
|
|
|
// No addition neither substraction so no risk of overflow the [0:255] range.
|
|
|
|
colclip_wrap = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_ps_sel.colclip = 1;
|
|
|
|
// fprintf(stderr, "COLCLIP ENABLED (blending is %d/%d/%d/%d)\n", m_context->ALPHA.A, m_context->ALPHA.B, m_context->ALPHA.C, m_context->ALPHA.D);
|
|
|
|
}
|
2012-01-05 02:40:24 +00:00
|
|
|
}
|
|
|
|
|
2018-11-13 00:56:11 +00:00
|
|
|
m_ps_sel.clr1 = m_om_bsel.IsCLR1();
|
2017-02-17 09:59:21 +00:00
|
|
|
m_ps_sel.fba = m_context->FBA.FBA;
|
2018-12-15 04:46:15 +00:00
|
|
|
|
|
|
|
if (m_ps_sel.shuffle)
|
|
|
|
{
|
|
|
|
m_ps_sel.aout = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_ps_sel.aout = UserHacks_AlphaHack || m_context->FRAME.PSM == PSM_PSMCT16 || m_context->FRAME.PSM == PSM_PSMCT16S || (m_context->FRAME.FBMSK & 0xff000000) == 0x7f000000 ? 1 : 0;
|
|
|
|
}
|
2012-01-05 02:40:24 +00:00
|
|
|
|
2018-10-02 00:16:38 +00:00
|
|
|
if (PRIM->FGE)
|
2012-01-05 02:40:24 +00:00
|
|
|
{
|
2017-02-17 09:59:21 +00:00
|
|
|
m_ps_sel.fog = 1;
|
2012-01-05 02:40:24 +00:00
|
|
|
|
2018-08-01 21:58:46 +00:00
|
|
|
GSVector4 fc = GSVector4::rgba32(m_env.FOGCOL.u32[0]);
|
|
|
|
#if _M_SSE >= 0x401
|
|
|
|
// Blend AREF to avoid to load a random value for alpha (dirty cache)
|
|
|
|
ps_cb.FogColor_AREF = fc.blend32<8>(ps_cb.FogColor_AREF) / 255;
|
|
|
|
#else
|
|
|
|
ps_cb.FogColor_AREF = fc / 255;
|
|
|
|
#endif
|
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;
|
2018-10-02 00:16:38 +00:00
|
|
|
if (ate_first_pass & ate_second_pass)
|
|
|
|
{
|
2016-08-28 13:13:15 +00:00
|
|
|
#ifdef _DEBUG
|
|
|
|
fprintf(stdout, "Complex Alpha Test\n");
|
|
|
|
#endif
|
2018-11-13 00:25:15 +00:00
|
|
|
bool commutative_depth = (m_om_dssel.ztst == ZTST_GEQUAL && m_vt.m_eq.z) || (m_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
|
|
|
|
2018-10-02 00:16:38 +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
|
2018-11-13 00:25:15 +00:00
|
|
|
m_om_dssel.zwe = false;
|
2018-10-02 00:16:38 +00:00
|
|
|
}
|
|
|
|
else if (ate_RGB_then_ZA)
|
|
|
|
{
|
2016-08-28 13:13:15 +00:00
|
|
|
#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
|
2018-11-13 00:25:15 +00:00
|
|
|
m_om_dssel.zwe = false;
|
2018-11-13 00:56:11 +00:00
|
|
|
m_om_bsel.wa = false;
|
2018-10-02 00:16:38 +00:00
|
|
|
}
|
|
|
|
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.
|
2018-11-30 08:34:16 +00:00
|
|
|
if (UserHacks_AlphaStencil && DATE && !DATE_one && dev->HasStencil() && m_om_bsel.wa && !m_context->TEST.ATE)
|
2016-10-13 22:28:31 +00:00
|
|
|
{
|
2018-11-30 08:34:16 +00:00
|
|
|
// fprintf(stderr, "Alpha Stencil detected\n");
|
2016-10-13 22:28:31 +00:00
|
|
|
if (!m_context->FBA.FBA)
|
|
|
|
{
|
|
|
|
if (m_context->TEST.DATM == 0)
|
2017-02-17 09:59:21 +00:00
|
|
|
m_ps_sel.atst = 2; // >=
|
2018-10-02 00:16:38 +00:00
|
|
|
else
|
|
|
|
{
|
2016-10-13 22:28:31 +00:00
|
|
|
if (tex && tex->m_spritehack_t)
|
2017-02-17 09:59:21 +00:00
|
|
|
m_ps_sel.atst = 0; // <
|
2016-10-13 22:28:31 +00:00
|
|
|
else
|
2017-02-17 09:59:21 +00:00
|
|
|
m_ps_sel.atst = 1; // <
|
2016-10-13 22:28:31 +00:00
|
|
|
}
|
|
|
|
ps_cb.FogColor_AREF.a = (float)0x80;
|
|
|
|
}
|
|
|
|
if (!(m_context->FBA.FBA && m_context->TEST.DATM == 1))
|
2018-11-28 19:33:15 +00:00
|
|
|
m_om_dssel.date_one = 1;
|
2016-10-13 22:28:31 +00:00
|
|
|
}
|
|
|
|
|
2018-10-02 00:16:38 +00:00
|
|
|
if (tex)
|
2012-01-05 02:40:24 +00:00
|
|
|
{
|
2017-02-17 09:59:21 +00:00
|
|
|
EmulateTextureSampler(tex);
|
2012-01-05 02:40:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-02-17 09:59:21 +00:00
|
|
|
m_ps_sel.tfx = 4;
|
2012-01-05 02:40:24 +00:00
|
|
|
}
|
|
|
|
|
2018-10-18 09:04:43 +00:00
|
|
|
if (m_game.title == CRC::ICO)
|
|
|
|
{
|
|
|
|
GSVertex* v = &m_vertex.buff[0];
|
|
|
|
const GSVideoMode mode = GetVideoMode();
|
|
|
|
if (tex && m_vt.m_primclass == GS_SPRITE_CLASS && m_vertex.next == 2 && PRIM->ABE && // Blend texture
|
|
|
|
((v[1].U == 8200 && v[1].V == 7176 && mode == GSVideoMode::NTSC) || // at display resolution 512x448
|
|
|
|
(v[1].U == 8200 && v[1].V == 8200 && mode == GSVideoMode::PAL)) && // at display resolution 512x512
|
|
|
|
tex->m_TEX0.PSM == PSM_PSMT8H) // i.e. read the alpha channel of a 32 bits texture
|
|
|
|
{
|
|
|
|
// Note potentially we can limit to TBP0:0x2800
|
2012-01-05 02:40:24 +00:00
|
|
|
|
2018-10-18 09:04:43 +00:00
|
|
|
// DX doesn't support depth or channel shuffle yet so we can just do a partial port that skips the bad drawcalls,
|
|
|
|
// this way we can purge any remaining crc hacks.
|
|
|
|
throw GSDXRecoverableError();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// rs
|
2018-12-11 15:18:40 +00:00
|
|
|
const GSVector4& hacked_scissor = m_channel_shuffle ? GSVector4(0, 0, 1024, 1024) : m_context->scissor.in;
|
|
|
|
GSVector4i scissor = GSVector4i(GSVector4(rtscale).xyxy() * hacked_scissor).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);
|
|
|
|
|
2017-03-03 21:18:49 +00:00
|
|
|
SetupIA(sx, sy);
|
2012-01-19 10:24:07 +00:00
|
|
|
|
2018-11-13 00:56:11 +00:00
|
|
|
dev->SetupOM(m_om_dssel, m_om_bsel, afix);
|
2018-09-14 13:43:24 +00:00
|
|
|
dev->SetupVS(m_vs_sel, &vs_cb);
|
2017-03-03 21:18:49 +00:00
|
|
|
dev->SetupGS(m_gs_sel, &gs_cb);
|
2017-02-17 09:59:21 +00:00
|
|
|
dev->SetupPS(m_ps_sel, &ps_cb, m_ps_ssel);
|
2012-01-05 02:40:24 +00:00
|
|
|
|
|
|
|
// draw
|
|
|
|
|
2016-08-14 16:35:42 +00:00
|
|
|
if (ate_first_pass)
|
2012-01-05 02:40:24 +00:00
|
|
|
{
|
|
|
|
dev->DrawIndexedPrimitive();
|
|
|
|
|
2018-10-03 03:50:54 +00:00
|
|
|
if (colclip_wrap)
|
2012-01-05 02:40:24 +00:00
|
|
|
{
|
2018-11-13 00:56:11 +00:00
|
|
|
GSDeviceDX::OMBlendSelector om_bselneg(m_om_bsel);
|
2017-02-17 09:59:21 +00:00
|
|
|
GSDeviceDX::PSSelector ps_selneg(m_ps_sel);
|
2012-01-05 02:40:24 +00:00
|
|
|
|
|
|
|
om_bselneg.negative = 1;
|
|
|
|
ps_selneg.colclip = 2;
|
|
|
|
|
2018-11-13 00:25:15 +00:00
|
|
|
dev->SetupOM(m_om_dssel, om_bselneg, afix);
|
2017-02-17 09:59:21 +00:00
|
|
|
dev->SetupPS(ps_selneg, &ps_cb, m_ps_ssel);
|
2012-01-05 02:40:24 +00:00
|
|
|
|
|
|
|
dev->DrawIndexedPrimitive();
|
2018-11-13 00:56:11 +00:00
|
|
|
dev->SetupOM(m_om_dssel, m_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
|
|
|
|
2018-10-02 00:16:38 +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);
|
|
|
|
}
|
2018-10-02 00:16:38 +00:00
|
|
|
else
|
|
|
|
{
|
2016-08-14 16:35:42 +00:00
|
|
|
// second pass will process the pixels that failed
|
|
|
|
// the alpha test
|
|
|
|
EmulateAtst(2, tex);
|
|
|
|
}
|
2012-01-05 02:40:24 +00:00
|
|
|
|
2017-02-17 09:59:21 +00:00
|
|
|
dev->SetupPS(m_ps_sel, &ps_cb, m_ps_ssel);
|
2012-01-05 02:40:24 +00:00
|
|
|
|
2018-11-13 00:25:15 +00:00
|
|
|
bool z = m_om_dssel.zwe;
|
2018-11-13 00:56:11 +00:00
|
|
|
bool r = m_om_bsel.wr;
|
|
|
|
bool g = m_om_bsel.wg;
|
|
|
|
bool b = m_om_bsel.wb;
|
|
|
|
bool a = m_om_bsel.wa;
|
2012-01-05 02:40:24 +00:00
|
|
|
|
2016-08-19 14:02:49 +00:00
|
|
|
switch(m_context->TEST.AFAIL)
|
2012-01-05 02:40:24 +00:00
|
|
|
{
|
2018-10-08 21:58:15 +00:00
|
|
|
case AFAIL_KEEP: z = r = g = b = a = false; break; // none
|
|
|
|
case AFAIL_FB_ONLY: z = false; break; // rgba
|
|
|
|
case AFAIL_ZB_ONLY: r = g = b = a = false; break; // z
|
|
|
|
case AFAIL_RGB_ONLY: z = a = false; break; // rgb
|
2016-08-14 16:35:42 +00:00
|
|
|
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.
|
2018-10-02 00:16:38 +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;
|
2018-10-02 00:16:38 +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
|
|
|
}
|
|
|
|
|
2018-10-02 00:16:38 +00:00
|
|
|
if (z || r || g || b || a)
|
2012-01-05 02:40:24 +00:00
|
|
|
{
|
2018-11-13 00:25:15 +00:00
|
|
|
m_om_dssel.zwe = z;
|
2018-11-13 00:56:11 +00:00
|
|
|
m_om_bsel.wr = r;
|
|
|
|
m_om_bsel.wg = g;
|
|
|
|
m_om_bsel.wb = b;
|
|
|
|
m_om_bsel.wa = a;
|
2012-01-05 02:40:24 +00:00
|
|
|
|
2018-11-13 00:56:11 +00:00
|
|
|
dev->SetupOM(m_om_dssel, m_om_bsel, afix);
|
2012-01-05 02:40:24 +00:00
|
|
|
|
|
|
|
dev->DrawIndexedPrimitive();
|
|
|
|
|
2018-10-03 03:50:54 +00:00
|
|
|
if (colclip_wrap)
|
2012-01-05 02:40:24 +00:00
|
|
|
{
|
2018-11-13 00:56:11 +00:00
|
|
|
GSDeviceDX::OMBlendSelector om_bselneg(m_om_bsel);
|
2017-02-17 09:59:21 +00:00
|
|
|
GSDeviceDX::PSSelector ps_selneg(m_ps_sel);
|
2012-01-05 02:40:24 +00:00
|
|
|
|
|
|
|
om_bselneg.negative = 1;
|
|
|
|
ps_selneg.colclip = 2;
|
|
|
|
|
2018-11-13 00:25:15 +00:00
|
|
|
dev->SetupOM(m_om_dssel, om_bselneg, afix);
|
2017-02-17 09:59:21 +00:00
|
|
|
dev->SetupPS(ps_selneg, &ps_cb, m_ps_ssel);
|
2012-01-05 02:40:24 +00:00
|
|
|
|
|
|
|
dev->DrawIndexedPrimitive();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dev->EndScene();
|
|
|
|
|
|
|
|
dev->Recycle(rtcopy);
|
|
|
|
|
2018-11-13 00:25:15 +00:00
|
|
|
if (m_om_dssel.fba) UpdateFBA(rt);
|
2012-01-05 02:40:24 +00:00
|
|
|
}
|