2011-11-16 22:17:37 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2011-2011 Gregory hainaut
|
|
|
|
* Copyright (C) 2007-2009 Gabest
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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.
|
2011-11-16 22:17:37 +00:00
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2013-01-10 13:13:59 +00:00
|
|
|
#include "stdafx.h"
|
2011-11-16 22:17:37 +00:00
|
|
|
#include "GSRendererOGL.h"
|
|
|
|
#include "GSRenderer.h"
|
|
|
|
|
|
|
|
|
|
|
|
GSRendererOGL::GSRendererOGL()
|
2012-02-11 10:22:02 +00:00
|
|
|
: GSRendererHW(new GSTextureCacheOGL(this))
|
2011-11-16 22:17:37 +00:00
|
|
|
{
|
2016-05-24 19:52:06 +00:00
|
|
|
m_accurate_date = theApp.GetConfigB("accurate_date");
|
2015-07-19 07:34:32 +00:00
|
|
|
|
2016-05-24 19:52:06 +00:00
|
|
|
m_sw_blending = theApp.GetConfigI("accurate_blending_unit");
|
2015-05-08 08:40:43 +00:00
|
|
|
|
2016-01-11 17:56:08 +00:00
|
|
|
// Hope nothing requires too many draw calls.
|
|
|
|
m_drawlist.reserve(2048);
|
|
|
|
|
2016-05-24 19:52:06 +00:00
|
|
|
UserHacks_TCOffset = theApp.GetConfigI("UserHacks_TCOffset");
|
2015-05-08 08:40:43 +00:00
|
|
|
UserHacks_TCO_x = (UserHacks_TCOffset & 0xFFFF) / -1000.0f;
|
|
|
|
UserHacks_TCO_y = ((UserHacks_TCOffset >> 16) & 0xFFFF) / -1000.0f;
|
2016-05-24 19:52:06 +00:00
|
|
|
UserHacks_merge_sprite = theApp.GetConfigB("UserHacks_merge_pp_sprite");
|
2016-08-21 16:34:03 +00:00
|
|
|
UserHacks_unscale_pt_ln = theApp.GetConfigB("UserHacks_unscale_point_line");
|
2017-02-26 15:09:55 +00:00
|
|
|
UserHacks_HPO = theApp.GetConfigI("UserHacks_HalfPixelOffset");
|
2017-02-24 16:55:39 +00:00
|
|
|
UserHacks_tri_filter = static_cast<TriFiltering>(theApp.GetConfigI("UserHacks_TriFilter"));
|
2015-05-08 08:40:43 +00:00
|
|
|
|
2015-09-11 10:19:49 +00:00
|
|
|
m_prim_overlap = PRIM_OVERLAP_UNKNOW;
|
2016-06-07 17:08:54 +00:00
|
|
|
ResetStates();
|
2015-09-11 10:19:49 +00:00
|
|
|
|
2016-05-24 19:52:06 +00:00
|
|
|
if (!theApp.GetConfigB("UserHacks")) {
|
2015-05-08 08:40:43 +00:00
|
|
|
UserHacks_TCOffset = 0;
|
|
|
|
UserHacks_TCO_x = 0;
|
|
|
|
UserHacks_TCO_y = 0;
|
2016-05-10 06:12:07 +00:00
|
|
|
UserHacks_merge_sprite = false;
|
2016-08-21 16:34:03 +00:00
|
|
|
UserHacks_unscale_pt_ln = false;
|
2016-06-21 07:51:47 +00:00
|
|
|
UserHacks_HPO = 0;
|
2017-02-24 16:55:39 +00:00
|
|
|
UserHacks_tri_filter = TriFiltering::None;
|
2015-05-08 08:40:43 +00:00
|
|
|
}
|
2011-11-16 22:17:37 +00:00
|
|
|
}
|
|
|
|
|
2011-12-19 21:03:23 +00:00
|
|
|
bool GSRendererOGL::CreateDevice(GSDevice* dev)
|
|
|
|
{
|
2016-09-10 18:08:14 +00:00
|
|
|
return GSRenderer::CreateDevice(dev);
|
2011-12-19 21:03:23 +00:00
|
|
|
}
|
2011-11-16 22:17:37 +00:00
|
|
|
|
2016-06-07 17:12:34 +00:00
|
|
|
void GSRendererOGL::Lines2Sprites()
|
2013-05-27 16:53:38 +00:00
|
|
|
{
|
2016-08-31 07:22:35 +00:00
|
|
|
ASSERT(m_vt.m_primclass == GS_SPRITE_CLASS);
|
2013-05-27 16:53:38 +00:00
|
|
|
|
2013-08-14 10:18:38 +00:00
|
|
|
// each sprite converted to quad needs twice the space
|
2013-05-27 16:53:38 +00:00
|
|
|
|
2013-08-14 10:18:38 +00:00
|
|
|
while(m_vertex.tail * 2 > m_vertex.maxcount)
|
|
|
|
{
|
|
|
|
GrowVertexBuffer();
|
|
|
|
}
|
2013-05-27 16:53:38 +00:00
|
|
|
|
2013-08-14 10:18:38 +00:00
|
|
|
// assume vertices are tightly packed and sequentially indexed (it should be the case)
|
2013-05-27 16:53:38 +00:00
|
|
|
|
2015-05-19 22:51:37 +00:00
|
|
|
if (m_vertex.next >= 2)
|
2013-08-14 10:18:38 +00:00
|
|
|
{
|
|
|
|
size_t count = m_vertex.next;
|
2013-05-27 16:53:38 +00:00
|
|
|
|
2013-08-14 10:18:38 +00:00
|
|
|
int i = (int)count * 2 - 4;
|
|
|
|
GSVertex* s = &m_vertex.buff[count - 2];
|
|
|
|
GSVertex* q = &m_vertex.buff[count * 2 - 4];
|
|
|
|
uint32* RESTRICT index = &m_index.buff[count * 3 - 6];
|
2013-05-27 16:53:38 +00:00
|
|
|
|
2013-08-14 10:18:38 +00:00
|
|
|
for(; i >= 0; i -= 4, s -= 2, q -= 4, index -= 6)
|
2013-05-27 16:53:38 +00:00
|
|
|
{
|
2013-08-14 10:18:38 +00:00
|
|
|
GSVertex v0 = s[0];
|
|
|
|
GSVertex v1 = s[1];
|
2013-05-27 16:53:38 +00:00
|
|
|
|
2013-08-14 10:18:38 +00:00
|
|
|
v0.RGBAQ = v1.RGBAQ;
|
|
|
|
v0.XYZ.Z = v1.XYZ.Z;
|
|
|
|
v0.FOG = v1.FOG;
|
2013-05-27 16:53:38 +00:00
|
|
|
|
2017-03-10 23:24:38 +00:00
|
|
|
if (PRIM->TME && !PRIM->FST) {
|
|
|
|
GSVector4 st0 = GSVector4::loadl(&v0.ST.u64);
|
|
|
|
GSVector4 st1 = GSVector4::loadl(&v1.ST.u64);
|
|
|
|
GSVector4 Q = GSVector4(v1.RGBAQ.Q, v1.RGBAQ.Q, v1.RGBAQ.Q, v1.RGBAQ.Q);
|
|
|
|
GSVector4 st = st0.upld(st1) / Q;
|
|
|
|
|
|
|
|
GSVector4::storel(&v0.ST.u64, st);
|
|
|
|
GSVector4::storeh(&v1.ST.u64, st);
|
|
|
|
|
|
|
|
v0.RGBAQ.Q = 1.0f;
|
|
|
|
v1.RGBAQ.Q = 1.0f;
|
|
|
|
}
|
|
|
|
|
2013-08-14 10:18:38 +00:00
|
|
|
q[0] = v0;
|
|
|
|
q[3] = v1;
|
2013-05-27 16:53:38 +00:00
|
|
|
|
2013-08-14 10:18:38 +00:00
|
|
|
// swap x, s, u
|
2013-05-27 16:53:38 +00:00
|
|
|
|
2013-08-14 10:18:38 +00:00
|
|
|
uint16 x = v0.XYZ.X;
|
|
|
|
v0.XYZ.X = v1.XYZ.X;
|
|
|
|
v1.XYZ.X = x;
|
2013-05-27 16:53:38 +00:00
|
|
|
|
2013-08-14 10:18:38 +00:00
|
|
|
float s = v0.ST.S;
|
|
|
|
v0.ST.S = v1.ST.S;
|
|
|
|
v1.ST.S = s;
|
2013-05-27 16:53:38 +00:00
|
|
|
|
2013-08-14 10:18:38 +00:00
|
|
|
uint16 u = v0.U;
|
|
|
|
v0.U = v1.U;
|
|
|
|
v1.U = u;
|
2013-05-27 16:53:38 +00:00
|
|
|
|
2013-08-14 10:18:38 +00:00
|
|
|
q[1] = v0;
|
|
|
|
q[2] = v1;
|
2013-05-27 16:53:38 +00:00
|
|
|
|
2013-08-14 10:18:38 +00:00
|
|
|
index[0] = i + 0;
|
|
|
|
index[1] = i + 1;
|
|
|
|
index[2] = i + 2;
|
|
|
|
index[3] = i + 1;
|
|
|
|
index[4] = i + 2;
|
|
|
|
index[5] = i + 3;
|
2013-05-27 16:53:38 +00:00
|
|
|
}
|
|
|
|
|
2013-08-14 10:18:38 +00:00
|
|
|
m_vertex.head = m_vertex.tail = m_vertex.next = count * 2;
|
|
|
|
m_index.tail = count * 3;
|
2013-05-27 16:53:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-31 07:22:35 +00:00
|
|
|
void GSRendererOGL::SetupIA(const float& sx, const float& sy)
|
2012-01-15 17:25:49 +00:00
|
|
|
{
|
2016-05-05 15:42:22 +00:00
|
|
|
GL_PUSH("IA");
|
|
|
|
|
2012-02-11 10:22:02 +00:00
|
|
|
GSDeviceOGL* dev = (GSDeviceOGL*)m_dev;
|
2012-01-15 17:25:49 +00:00
|
|
|
|
2016-05-31 18:18:40 +00:00
|
|
|
|
|
|
|
if (UserHacks_WildHack && !isPackedUV_HackFlag && PRIM->TME && PRIM->FST) {
|
|
|
|
for(unsigned int i = 0; i < m_vertex.next; i++)
|
|
|
|
m_vertex.buff[i].UV &= 0x3FEF3FEF;
|
|
|
|
}
|
|
|
|
|
2013-06-28 10:43:50 +00:00
|
|
|
GLenum t = 0;
|
2016-08-31 07:22:35 +00:00
|
|
|
bool unscale_hack = UserHacks_unscale_pt_ln & (GetUpscaleMultiplier() > 1) & GLLoader::found_geometry_shader;
|
2012-02-11 10:22:02 +00:00
|
|
|
|
|
|
|
switch(m_vt.m_primclass)
|
2012-01-15 17:25:49 +00:00
|
|
|
{
|
2016-08-31 07:22:35 +00:00
|
|
|
case GS_POINT_CLASS:
|
|
|
|
if (unscale_hack) {
|
|
|
|
m_gs_sel.point = 1;
|
|
|
|
vs_cb.PointSize = GSVector2(16.0f * sx, 16.0f * sy);
|
|
|
|
}
|
|
|
|
|
|
|
|
t = GL_POINTS;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GS_LINE_CLASS:
|
|
|
|
if (unscale_hack) {
|
|
|
|
m_gs_sel.line = 1;
|
|
|
|
vs_cb.PointSize = GSVector2(16.0f * sx, 16.0f * sy);
|
|
|
|
}
|
|
|
|
|
2013-05-27 16:53:38 +00:00
|
|
|
t = GL_LINES;
|
2016-08-31 07:22:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GS_SPRITE_CLASS:
|
2016-09-18 14:58:02 +00:00
|
|
|
// Heuristics: trade-off
|
|
|
|
// CPU conversion => ofc, more CPU ;) more bandwidth (72 bytes / sprite)
|
|
|
|
// GPU conversion => ofc, more GPU. And also more CPU due to extra shader validation stage.
|
|
|
|
//
|
|
|
|
// Note: severals openGL operation does draw call under the wood like texture upload. So even if
|
|
|
|
// you do 10 consecutive draw with the geometry shader, you will still pay extra validation if new
|
|
|
|
// texture are uploaded. (game Shadow Hearts)
|
|
|
|
//
|
|
|
|
// Note2: Due to MultiThreaded driver, Nvidia suffers less of the previous issue. Still it isn't free
|
|
|
|
// Shadow Heart is 90 fps (gs) vs 113 fps (no gs)
|
|
|
|
|
|
|
|
// If the draw calls contains few primitives. Geometry Shader gain with be rather small versus
|
|
|
|
// the extra validation cost of the extra stage.
|
|
|
|
//
|
|
|
|
// Note: keep Geometry Shader in the replayer to ease debug.
|
2017-03-10 23:24:38 +00:00
|
|
|
if (GLLoader::found_geometry_shader && !m_vt.m_accurate_stq && (m_vertex.next > 32 || GLLoader::in_replayer)) { // <=> 16 sprites (based on Shadow Hearts)
|
2016-08-31 07:22:35 +00:00
|
|
|
m_gs_sel.sprite = 1;
|
|
|
|
|
|
|
|
t = GL_LINES;
|
|
|
|
} else {
|
|
|
|
Lines2Sprites();
|
|
|
|
|
|
|
|
t = GL_TRIANGLES;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GS_TRIANGLE_CLASS:
|
2013-05-27 16:53:38 +00:00
|
|
|
t = GL_TRIANGLES;
|
2016-08-31 07:22:35 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
__assume(0);
|
2012-01-15 17:25:49 +00:00
|
|
|
}
|
|
|
|
|
2016-08-31 07:22:35 +00:00
|
|
|
dev->IASetVertexBuffer(m_vertex.buff, m_vertex.next);
|
|
|
|
dev->IASetIndexBuffer(m_index.buff, m_index.tail);
|
2012-02-11 10:22:02 +00:00
|
|
|
dev->IASetPrimitiveTopology(t);
|
|
|
|
}
|
|
|
|
|
2016-06-10 19:16:39 +00:00
|
|
|
void GSRendererOGL::EmulateAtst(const int pass, const GSTextureCache::Source* tex)
|
|
|
|
{
|
2016-06-10 23:08:50 +00:00
|
|
|
static const uint32 inverted_atst[] = {ATST_ALWAYS, ATST_NEVER, ATST_GEQUAL, ATST_GREATER, ATST_NOTEQUAL, ATST_LESS, ATST_LEQUAL, ATST_EQUAL};
|
|
|
|
int atst = (pass == 2) ? inverted_atst[m_context->TEST.ATST] : m_context->TEST.ATST;
|
2016-06-10 19:16:39 +00:00
|
|
|
|
2016-10-05 07:41:28 +00:00
|
|
|
if (!m_context->TEST.ATE) return;
|
2016-06-10 19:16:39 +00:00
|
|
|
|
2016-06-10 23:08:50 +00:00
|
|
|
switch (atst) {
|
|
|
|
case ATST_LESS:
|
|
|
|
if (tex && tex->m_spritehack_t) {
|
|
|
|
m_ps_sel.atst = 0;
|
|
|
|
} else {
|
|
|
|
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;
|
2016-06-10 19:16:39 +00:00
|
|
|
m_ps_sel.atst = 1;
|
2016-06-10 23:08:50 +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-06-10 19:16:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-11 19:14:58 +00:00
|
|
|
void GSRendererOGL::EmulateZbuffer()
|
|
|
|
{
|
|
|
|
if (m_context->TEST.ZTE) {
|
|
|
|
m_om_dssel.ztst = m_context->TEST.ZTST;
|
|
|
|
m_om_dssel.zwe = !m_context->ZBUF.ZMSK;
|
|
|
|
} else {
|
|
|
|
m_om_dssel.ztst = ZTST_ALWAYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32 max_z;
|
|
|
|
if (m_context->ZBUF.PSM == PSM_PSMZ32) {
|
|
|
|
max_z = 0xFFFFFFFF;
|
|
|
|
} else if (m_context->ZBUF.PSM == PSM_PSMZ24) {
|
|
|
|
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-10-03 16:32:54 +00:00
|
|
|
vs_cb.DepthMask = GSVector2i(0xFFFFFFFF, 0xFFFFFFFF);
|
2016-08-11 19:14:58 +00:00
|
|
|
|
|
|
|
if (m_om_dssel.ztst >= ZTST_ALWAYS && m_om_dssel.zwe && (m_context->ZBUF.PSM != PSM_PSMZ32)) {
|
|
|
|
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) {
|
2016-11-24 21:21:18 +00:00
|
|
|
GL_DBG("Bad Z size (%f %f) on %s buffers", m_vt.m_min.p.z, m_vt.m_max.p.z, psm_str(m_context->ZBUF.PSM));
|
2016-10-03 16:32:54 +00:00
|
|
|
vs_cb.DepthMask = GSVector2i(max_z, max_z);
|
2016-08-11 19:14:58 +00:00
|
|
|
m_om_dssel.ztst = ZTST_ALWAYS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-16 05:30:52 +00:00
|
|
|
GSVertex* v = &m_vertex.buff[0];
|
2016-08-11 19:14:58 +00:00
|
|
|
// Minor optimization of a corner case (it allow to better emulate some alpha test effects)
|
2016-09-18 15:24:33 +00:00
|
|
|
if (m_om_dssel.ztst == ZTST_GEQUAL && m_vt.m_eq.z && v[0].XYZ.Z == max_z) {
|
2016-10-14 18:24:52 +00:00
|
|
|
GL_DBG("Optimize Z test GEQUAL to ALWAYS (%s)", psm_str(m_context->ZBUF.PSM));
|
2016-08-11 19:14:58 +00:00
|
|
|
m_om_dssel.ztst = ZTST_ALWAYS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-07 17:08:54 +00:00
|
|
|
void GSRendererOGL::EmulateTextureShuffleAndFbmask()
|
2015-04-24 18:53:59 +00:00
|
|
|
{
|
2016-09-03 10:17:59 +00:00
|
|
|
size_t count = m_vertex.next;
|
|
|
|
GSVertex* v = &m_vertex.buff[0];
|
|
|
|
|
2016-09-09 19:51:23 +00:00
|
|
|
// Shadow_of_memories_Shadow_Flickering (Okami mustn't call this code)
|
|
|
|
if (m_texture_shuffle && count < 3 && PRIM->FST && (m_context->FRAME.FBMSK == 0)) {
|
2016-09-03 10:17:59 +00:00
|
|
|
// Avious dubious call to m_texture_shuffle on 16 bits games
|
|
|
|
// The pattern is severals column of 8 pixels. A single sprite
|
|
|
|
// smell fishy but a big sprite is wrong.
|
|
|
|
m_texture_shuffle = ((v[1].U - v[0].U) < 256);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-17 18:02:03 +00:00
|
|
|
if (m_texture_shuffle) {
|
2016-06-07 17:08:54 +00:00
|
|
|
m_ps_sel.shuffle = 1;
|
|
|
|
m_ps_sel.dfmt = 0;
|
2015-06-06 11:56:08 +00:00
|
|
|
|
|
|
|
const GIFRegXYOFFSET& o = m_context->XYOFFSET;
|
|
|
|
|
|
|
|
// vertex position is 8 to 16 pixels, therefore it is the 16-31 bits of the colors
|
|
|
|
int pos = (v[0].XYZ.X - o.OFX) & 0xFF;
|
|
|
|
bool write_ba = (pos > 112 && pos < 136);
|
|
|
|
// Read texture is 8 to 16 pixels (same as above)
|
2015-07-19 07:58:56 +00:00
|
|
|
float tw = (float)(1u << m_context->TEX0.TW);
|
2016-04-14 10:00:58 +00:00
|
|
|
int tex_pos = (PRIM->FST) ? v[0].U : (int)(tw * v[0].ST.S);
|
2015-06-29 19:41:36 +00:00
|
|
|
tex_pos &= 0xFF;
|
2016-06-07 17:08:54 +00:00
|
|
|
m_ps_sel.read_ba = (tex_pos > 112 && tex_pos < 144);
|
2015-06-06 11:56:08 +00:00
|
|
|
|
|
|
|
// Convert the vertex info to a 32 bits color format equivalent
|
2015-06-29 19:41:36 +00:00
|
|
|
if (PRIM->FST) {
|
|
|
|
GL_INS("First vertex is P: %d => %d T: %d => %d", v[0].XYZ.X, v[1].XYZ.X, v[0].U, v[1].U);
|
|
|
|
|
|
|
|
for(size_t i = 0; i < count; i += 2) {
|
|
|
|
if (write_ba)
|
|
|
|
v[i].XYZ.X -= 128u;
|
|
|
|
else
|
|
|
|
v[i+1].XYZ.X += 128u;
|
|
|
|
|
2016-06-07 17:08:54 +00:00
|
|
|
if (m_ps_sel.read_ba)
|
2015-06-29 19:41:36 +00:00
|
|
|
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);
|
|
|
|
tmp = GSVector4i(tmp - offset).srl32(1) + offset;
|
|
|
|
|
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-29 19:41:36 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
const float offset_8pix = 8.0f / tw;
|
|
|
|
GL_INS("First vertex is P: %d => %d T: %f => %f (offset %f)", v[0].XYZ.X, v[1].XYZ.X, v[0].ST.S, v[1].ST.S, offset_8pix);
|
|
|
|
|
|
|
|
for(size_t i = 0; i < count; i += 2) {
|
|
|
|
if (write_ba)
|
|
|
|
v[i].XYZ.X -= 128u;
|
|
|
|
else
|
|
|
|
v[i+1].XYZ.X += 128u;
|
|
|
|
|
2016-06-07 17:08:54 +00:00
|
|
|
if (m_ps_sel.read_ba)
|
2015-06-29 19:41:36 +00:00
|
|
|
v[i].ST.S -= offset_8pix;
|
|
|
|
else
|
|
|
|
v[i+1].ST.S += offset_8pix;
|
|
|
|
|
|
|
|
// Height is too big (2x).
|
|
|
|
GSVector4i offset(o.OFY, o.OFY);
|
|
|
|
|
|
|
|
GSVector4i tmp(v[i].XYZ.Y, v[i+1].XYZ.Y);
|
|
|
|
tmp = GSVector4i(tmp - offset).srl32(1) + offset;
|
|
|
|
|
|
|
|
//fprintf(stderr, "Before %d, After %d\n", v[i+1].XYZ.Y, tmp.y);
|
2016-04-14 10:00:58 +00:00
|
|
|
v[i].XYZ.Y = (uint16)tmp.x;
|
2015-06-29 19:41:36 +00:00
|
|
|
v[i].ST.T /= 2.0f;
|
2016-04-14 10:00:58 +00:00
|
|
|
v[i+1].XYZ.Y = (uint16)tmp.y;
|
2015-06-29 19:41:36 +00:00
|
|
|
v[i+1].ST.T /= 2.0f;
|
|
|
|
}
|
2015-06-06 11:56:08 +00:00
|
|
|
}
|
|
|
|
|
2015-08-04 18:08:33 +00:00
|
|
|
// If date is enabled you need to test the green channel instead of the
|
|
|
|
// alpha channel. Only enable this code in DATE mode to reduce the number
|
|
|
|
// of shader.
|
2016-06-07 17:08:54 +00:00
|
|
|
m_ps_sel.write_rg = !write_ba && m_context->TEST.DATE;
|
2015-08-04 18:08:33 +00:00
|
|
|
|
2015-06-06 11:56:08 +00:00
|
|
|
// Please bang my head against the wall!
|
|
|
|
// 1/ Reduce the frame mask to a 16 bit format
|
2015-07-19 07:58:56 +00:00
|
|
|
const uint32& m = m_context->FRAME.FBMSK;
|
2015-08-16 12:06:10 +00:00
|
|
|
uint32 fbmask = ((m >> 3) & 0x1F) | ((m >> 6) & 0x3E0) | ((m >> 9) & 0x7C00) | ((m >> 16) & 0x8000);
|
2015-06-21 06:47:45 +00:00
|
|
|
// FIXME GSVector will be nice here
|
|
|
|
uint8 rg_mask = fbmask & 0xFF;
|
|
|
|
uint8 ba_mask = (fbmask >> 8) & 0xFF;
|
2016-06-07 17:08:54 +00:00
|
|
|
m_om_csel.wrgba = 0;
|
2015-06-06 11:56:08 +00:00
|
|
|
|
|
|
|
// 2 Select the new mask (Please someone put SSE here)
|
2015-06-21 06:47:45 +00:00
|
|
|
if (rg_mask != 0xFF) {
|
2015-06-06 11:56:08 +00:00
|
|
|
if (write_ba) {
|
2016-06-07 17:08:54 +00:00
|
|
|
GL_INS("Color shuffle %s => B", m_ps_sel.read_ba ? "B" : "R");
|
|
|
|
m_om_csel.wb = 1;
|
2015-06-06 11:56:08 +00:00
|
|
|
} else {
|
2016-06-07 17:08:54 +00:00
|
|
|
GL_INS("Color shuffle %s => R", m_ps_sel.read_ba ? "B" : "R");
|
|
|
|
m_om_csel.wr = 1;
|
2015-06-06 11:56:08 +00:00
|
|
|
}
|
2015-06-21 06:47:45 +00:00
|
|
|
if (rg_mask)
|
2016-06-07 17:08:54 +00:00
|
|
|
m_ps_sel.fbmask = 1;
|
2015-06-06 11:56:08 +00:00
|
|
|
}
|
|
|
|
|
2015-06-21 06:47:45 +00:00
|
|
|
if (ba_mask != 0xFF) {
|
2015-06-06 11:56:08 +00:00
|
|
|
if (write_ba) {
|
2016-06-07 17:08:54 +00:00
|
|
|
GL_INS("Color shuffle %s => A", m_ps_sel.read_ba ? "A" : "G");
|
|
|
|
m_om_csel.wa = 1;
|
2015-06-06 11:56:08 +00:00
|
|
|
} else {
|
2016-06-07 17:08:54 +00:00
|
|
|
GL_INS("Color shuffle %s => G", m_ps_sel.read_ba ? "A" : "G");
|
|
|
|
m_om_csel.wg = 1;
|
2015-06-06 11:56:08 +00:00
|
|
|
}
|
2015-06-21 06:47:45 +00:00
|
|
|
if (ba_mask)
|
2016-06-07 17:08:54 +00:00
|
|
|
m_ps_sel.fbmask = 1;
|
2015-06-21 06:47:45 +00:00
|
|
|
}
|
|
|
|
|
2016-06-07 17:08:54 +00:00
|
|
|
if (m_ps_sel.fbmask && m_sw_blending) {
|
2015-06-21 06:47:45 +00:00
|
|
|
GL_INS("FBMASK SW emulated fb_mask:%x on tex shuffle", fbmask);
|
|
|
|
ps_cb.FbMask.r = rg_mask;
|
|
|
|
ps_cb.FbMask.g = rg_mask;
|
|
|
|
ps_cb.FbMask.b = ba_mask;
|
|
|
|
ps_cb.FbMask.a = ba_mask;
|
2016-06-07 16:42:58 +00:00
|
|
|
m_require_full_barrier = true;
|
2015-07-31 17:43:06 +00:00
|
|
|
} else {
|
2016-06-07 17:08:54 +00:00
|
|
|
m_ps_sel.fbmask = 0;
|
2015-06-06 11:56:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2016-06-07 17:08:54 +00:00
|
|
|
m_ps_sel.dfmt = GSLocalMemory::m_psm[m_context->FRAME.PSM].fmt;
|
2015-06-06 11:56:08 +00:00
|
|
|
|
2015-08-05 20:12:54 +00:00
|
|
|
GSVector4i fbmask_v = GSVector4i::load((int)m_context->FRAME.FBMSK);
|
|
|
|
int ff_fbmask = fbmask_v.eq8(GSVector4i::xffffffff()).mask();
|
|
|
|
int zero_fbmask = fbmask_v.eq8(GSVector4i::zero()).mask();
|
2015-06-06 11:56:08 +00:00
|
|
|
|
2016-06-07 17:08:54 +00:00
|
|
|
m_om_csel.wrgba = ~ff_fbmask; // Enable channel if at least 1 bit is 0
|
2015-06-21 06:47:45 +00:00
|
|
|
|
2016-06-07 17:08:54 +00:00
|
|
|
m_ps_sel.fbmask = m_sw_blending && (~ff_fbmask & ~zero_fbmask & 0xF);
|
2015-08-05 20:12:54 +00:00
|
|
|
|
2016-06-07 17:08:54 +00:00
|
|
|
if (m_ps_sel.fbmask) {
|
2015-08-05 20:12:54 +00:00
|
|
|
ps_cb.FbMask = fbmask_v.u8to32();
|
2015-12-31 22:58:03 +00:00
|
|
|
// Only alpha is special here, I think we can take a very unsafe shortcut
|
|
|
|
// Alpha isn't blended on the GS but directly copyied into the RT.
|
|
|
|
//
|
|
|
|
// Behavior is clearly undefined however there is a high probability that
|
|
|
|
// it will work. Masked bit will be constant and normally the same everywhere
|
|
|
|
// RT/FS output/Cached value.
|
|
|
|
//
|
|
|
|
// Just to be sure let's add a new safe hack for unsafe access :)
|
|
|
|
//
|
|
|
|
// Here the GL spec quote to emphasize the unexpected behavior.
|
|
|
|
/*
|
|
|
|
- If a texel has been written, then in order to safely read the result
|
|
|
|
a texel fetch must be in a subsequent Draw separated by the command
|
|
|
|
|
|
|
|
void TextureBarrier(void);
|
|
|
|
|
|
|
|
TextureBarrier() will guarantee that writes have completed and caches
|
|
|
|
have been invalidated before subsequent Draws are executed.
|
|
|
|
*/
|
2016-09-23 17:06:53 +00:00
|
|
|
// Safe option was removed. Likely nobody never use it. Keep the code commented if it becomes useful one day
|
|
|
|
if (!(~ff_fbmask & ~zero_fbmask & 0x7) /*&& !UserHacks_safe_fbmask*/) {
|
2015-12-31 22:58:03 +00:00
|
|
|
GL_INS("FBMASK Unsafe SW emulated fb_mask:%x on %d bits format", m_context->FRAME.FBMSK,
|
|
|
|
(GSLocalMemory::m_psm[m_context->FRAME.PSM].fmt == 2) ? 16 : 32);
|
2016-06-07 16:42:58 +00:00
|
|
|
m_require_one_barrier = true;
|
2015-12-31 22:58:03 +00:00
|
|
|
} else {
|
|
|
|
// The safe and accurate path (but slow)
|
|
|
|
GL_INS("FBMASK SW emulated fb_mask:%x on %d bits format", m_context->FRAME.FBMSK,
|
|
|
|
(GSLocalMemory::m_psm[m_context->FRAME.PSM].fmt == 2) ? 16 : 32);
|
2016-06-07 16:42:58 +00:00
|
|
|
m_require_full_barrier = true;;
|
2015-12-31 22:58:03 +00:00
|
|
|
}
|
2015-06-06 11:56:08 +00:00
|
|
|
}
|
|
|
|
}
|
2015-07-19 07:58:56 +00:00
|
|
|
}
|
2015-05-26 12:59:07 +00:00
|
|
|
|
2016-06-07 17:08:54 +00:00
|
|
|
void GSRendererOGL::EmulateChannelShuffle(GSTexture** rt, const GSTextureCache::Source* tex)
|
2016-05-31 18:02:55 +00:00
|
|
|
{
|
|
|
|
GSDeviceOGL* dev = (GSDeviceOGL*)m_dev;
|
|
|
|
|
|
|
|
// Uncomment to disable HLE emulation (allow to trace the draw call)
|
|
|
|
// m_channel_shuffle = false;
|
|
|
|
|
|
|
|
// First let's check we really have a channel shuffle effect
|
|
|
|
if (m_channel_shuffle) {
|
|
|
|
if (m_game.title == CRC::GT4 || m_game.title == CRC::GT3 || m_game.title == CRC::GTConcept || m_game.title == CRC::TouristTrophy) {
|
|
|
|
GL_INS("Gran Turismo RGB Channel");
|
2016-06-07 17:08:54 +00:00
|
|
|
m_ps_sel.channel = 7;
|
2016-05-31 18:02:55 +00:00
|
|
|
m_context->TEX0.TFX = TFX_DECAL;
|
|
|
|
*rt = tex->m_from_target;
|
|
|
|
} else if (m_game.title == CRC::Tekken5) {
|
2016-10-16 09:34:06 +00:00
|
|
|
if (m_context->FRAME.FBW == 1) {
|
|
|
|
GL_INS("Tekken5 RGB Channel");
|
|
|
|
m_ps_sel.channel = 7;
|
|
|
|
m_context->FRAME.FBMSK = 0xFF000000;
|
|
|
|
// 12 pages: 2 calls by channel, 3 channels, 1 blit
|
|
|
|
// Minus current draw call
|
|
|
|
m_skip = 12 * (3 + 3 + 1) - 1;
|
|
|
|
*rt = tex->m_from_target;
|
|
|
|
} else {
|
|
|
|
// Could skip model drawing if wrongly detected
|
|
|
|
m_channel_shuffle = false;
|
|
|
|
}
|
2016-05-31 18:02:55 +00:00
|
|
|
} else if ((tex->m_texture->GetType() == GSTexture::DepthStencil) && !(tex->m_32_bits_fmt)) {
|
|
|
|
// So far 2 games hit this code path. Urban Chaos and Tales of Abyss
|
|
|
|
// UC: will copy depth to green channel
|
|
|
|
// ToA: will copy depth to alpha channel
|
|
|
|
if ((m_context->FRAME.FBMSK & 0xFF0000) == 0xFF0000) {
|
|
|
|
// Green channel is masked
|
|
|
|
GL_INS("Tales Of Abyss Crazyness (MSB 16b depth to Alpha)");
|
2016-06-07 17:08:54 +00:00
|
|
|
m_ps_sel.tales_of_abyss_hle = 1;
|
2016-05-31 18:02:55 +00:00
|
|
|
} else {
|
|
|
|
GL_INS("Urban Chaos Crazyness (Green extraction)");
|
2016-06-07 17:08:54 +00:00
|
|
|
m_ps_sel.urban_chaos_hle = 1;
|
2016-05-31 18:02:55 +00:00
|
|
|
}
|
|
|
|
} else if (m_index.tail <= 64 && m_context->CLAMP.WMT == 3) {
|
|
|
|
// Blood will tell. I think it is channel effect too but again
|
|
|
|
// implemented in a different way. I don't want to add more CRC stuff. So
|
|
|
|
// let's disable channel when the signature is different
|
|
|
|
//
|
|
|
|
// Note: Tales Of Abyss and Tekken5 could hit this path too. Those games are
|
|
|
|
// handled above.
|
|
|
|
GL_INS("maybe not a channel!");
|
|
|
|
m_channel_shuffle = false;
|
|
|
|
} else if (m_context->CLAMP.WMS == 3 && ((m_context->CLAMP.MAXU & 0x8) == 8)) {
|
|
|
|
// Read either blue or Alpha. Let's go for Blue ;)
|
|
|
|
// MGS3/Kill Zone
|
|
|
|
GL_INS("Blue channel");
|
2016-06-07 17:08:54 +00:00
|
|
|
m_ps_sel.channel = 3;
|
2016-05-31 18:02:55 +00:00
|
|
|
} else if (m_context->CLAMP.WMS == 3 && ((m_context->CLAMP.MINU & 0x8) == 0)) {
|
|
|
|
// Read either Red or Green. Let's check the V coordinate. 0-1 is likely top so
|
|
|
|
// red. 2-3 is likely bottom so green (actually depends on texture base pointer offset)
|
|
|
|
bool green = PRIM->FST && (m_vertex.buff[0].V & 32);
|
|
|
|
if (green && (m_context->FRAME.FBMSK & 0x00FFFFFF) == 0x00FFFFFF) {
|
|
|
|
// Typically used in Terminator 3
|
|
|
|
int blue_mask = m_context->FRAME.FBMSK >> 24;
|
|
|
|
int green_mask = ~blue_mask & 0xFF;
|
|
|
|
int blue_shift = -1;
|
|
|
|
|
|
|
|
// Note: potentially we could also check the value of the clut
|
|
|
|
switch (m_context->FRAME.FBMSK >> 24) {
|
|
|
|
case 0xFF: ASSERT(0); break;
|
|
|
|
case 0xFE: blue_shift = 1; break;
|
|
|
|
case 0xFC: blue_shift = 2; break;
|
|
|
|
case 0xF8: blue_shift = 3; break;
|
|
|
|
case 0xF0: blue_shift = 4; break;
|
|
|
|
case 0xE0: blue_shift = 5; break;
|
|
|
|
case 0xC0: blue_shift = 6; break;
|
|
|
|
case 0x80: blue_shift = 7; break;
|
|
|
|
default: ASSERT(0); break;
|
|
|
|
}
|
|
|
|
|
|
|
|
int green_shift = 8 - blue_shift;
|
|
|
|
dev->SetupCBMisc(GSVector4i(blue_mask, blue_shift, green_mask, green_shift));
|
|
|
|
|
|
|
|
if (blue_shift >= 0) {
|
|
|
|
GL_INS("Green/Blue channel (%d, %d)", blue_shift, green_shift);
|
2016-06-07 17:08:54 +00:00
|
|
|
m_ps_sel.channel = 6;
|
2016-05-31 18:02:55 +00:00
|
|
|
m_context->FRAME.FBMSK = 0x00FFFFFF;
|
|
|
|
} else {
|
|
|
|
GL_INS("Green channel (wrong mask) (fbmask %x)", m_context->FRAME.FBMSK >> 24);
|
2016-06-07 17:08:54 +00:00
|
|
|
m_ps_sel.channel = 2;
|
2016-05-31 18:02:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} else if (green) {
|
|
|
|
GL_INS("Green channel");
|
2016-06-07 17:08:54 +00:00
|
|
|
m_ps_sel.channel = 2;
|
2016-05-31 18:02:55 +00:00
|
|
|
} else {
|
|
|
|
// Pop
|
|
|
|
GL_INS("Red channel");
|
2016-06-07 17:08:54 +00:00
|
|
|
m_ps_sel.channel = 1;
|
2016-05-31 18:02:55 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
GL_INS("channel not supported");
|
|
|
|
m_channel_shuffle = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Effect is really a channel shuffle effect so let's cheat a little
|
|
|
|
if (m_channel_shuffle) {
|
|
|
|
dev->PSSetShaderResource(4, tex->m_from_target);
|
2016-06-07 16:42:58 +00:00
|
|
|
m_require_one_barrier = true;
|
2016-05-31 18:02:55 +00:00
|
|
|
|
|
|
|
// Replace current draw with a fullscreen sprite
|
|
|
|
//
|
|
|
|
// Performance GPU note: it could be wise to reduce the size to
|
|
|
|
// the rendered size of the framebuffer
|
|
|
|
|
|
|
|
GSVertex* s = &m_vertex.buff[0];
|
|
|
|
s[0].XYZ.X = (uint16)(m_context->XYOFFSET.OFX + 0);
|
|
|
|
s[1].XYZ.X = (uint16)(m_context->XYOFFSET.OFX + 16384);
|
|
|
|
s[0].XYZ.Y = (uint16)(m_context->XYOFFSET.OFY + 0);
|
|
|
|
s[1].XYZ.Y = (uint16)(m_context->XYOFFSET.OFY + 16384);
|
|
|
|
|
|
|
|
m_vertex.head = m_vertex.tail = m_vertex.next = 2;
|
|
|
|
m_index.tail = 2;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
#ifdef ENABLE_OGL_DEBUG
|
|
|
|
dev->PSSetShaderResource(4, NULL);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-07 17:08:54 +00:00
|
|
|
void GSRendererOGL::EmulateBlending(bool DATE_GL42)
|
2015-07-25 15:57:42 +00:00
|
|
|
{
|
2015-08-07 10:06:45 +00:00
|
|
|
GSDeviceOGL* dev = (GSDeviceOGL*)m_dev;
|
2015-07-25 15:57:42 +00:00
|
|
|
const GIFRegALPHA& ALPHA = m_context->ALPHA;
|
2015-08-07 10:06:45 +00:00
|
|
|
bool sw_blending = false;
|
2015-07-25 15:57:42 +00:00
|
|
|
|
2015-08-07 10:06:45 +00:00
|
|
|
// No blending so early exit
|
|
|
|
if (!(PRIM->ABE || PRIM->AA1 && m_vt.m_primclass == GS_LINE_CLASS)) {
|
|
|
|
#ifdef ENABLE_OGL_DEBUG
|
|
|
|
if (m_env.PABE.PABE) {
|
|
|
|
GL_INS("!!! ENV PABE without ABE !!!");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
dev->OMSetBlendState();
|
2016-06-07 16:42:58 +00:00
|
|
|
return;
|
2015-08-07 10:06:45 +00:00
|
|
|
}
|
2015-07-25 15:57:42 +00:00
|
|
|
|
|
|
|
if (m_env.PABE.PABE)
|
|
|
|
{
|
|
|
|
GL_INS("!!! ENV PABE not supported !!!");
|
2015-08-07 10:06:45 +00:00
|
|
|
if (m_sw_blending >= ACC_BLEND_CCLIP_DALPHA) {
|
2016-06-07 17:08:54 +00:00
|
|
|
m_ps_sel.pabe = 1;
|
2016-06-07 16:42:58 +00:00
|
|
|
m_require_full_barrier |= (ALPHA.C == 1);
|
2015-08-07 10:06:45 +00:00
|
|
|
sw_blending = true;
|
2015-07-25 15:57:42 +00:00
|
|
|
}
|
2015-08-07 10:06:45 +00:00
|
|
|
//Breath of Fire Dragon Quarter triggers this in battles. Graphics are fine though.
|
|
|
|
//ASSERT(0);
|
2015-07-31 18:28:54 +00:00
|
|
|
}
|
2015-07-25 15:57:42 +00:00
|
|
|
|
|
|
|
// Compute the blending equation to detect special case
|
2016-04-14 10:00:58 +00:00
|
|
|
uint8 blend_index = uint8(((ALPHA.A * 3 + ALPHA.B) * 3 + ALPHA.C) * 3 + ALPHA.D);
|
2015-08-07 17:43:42 +00:00
|
|
|
int blend_flag = GSDeviceOGL::m_blendMapOGL[blend_index].bogus;
|
2015-08-07 10:06:45 +00:00
|
|
|
|
2015-07-25 15:57:42 +00:00
|
|
|
// SW Blend is (nearly) free. Let's use it.
|
2016-06-07 16:42:58 +00:00
|
|
|
bool impossible_or_free_blend = (blend_flag & (BLEND_NO_BAR|BLEND_A_MAX|BLEND_ACCU)) // Blend doesn't requires the costly barrier
|
|
|
|
|| (m_prim_overlap == PRIM_OVERLAP_NO) // Blend can be done in a single draw
|
|
|
|
|| (m_require_full_barrier); // Another effect (for example fbmask) already requires a full barrier
|
2015-08-07 10:06:45 +00:00
|
|
|
|
2015-07-25 15:57:42 +00:00
|
|
|
// Do the multiplication in shader for blending accumulation: Cs*As + Cd or Cs*Af + Cd
|
2016-04-14 10:00:58 +00:00
|
|
|
bool accumulation_blend = !!(blend_flag & BLEND_ACCU);
|
2015-07-25 15:57:42 +00:00
|
|
|
|
2015-08-07 10:06:45 +00:00
|
|
|
// Warning no break on purpose
|
|
|
|
switch (m_sw_blending) {
|
|
|
|
case ACC_BLEND_ULTRA: sw_blending |= true;
|
2015-08-08 06:57:06 +00:00
|
|
|
case ACC_BLEND_FULL: if (!m_vt.m_alpha.valid && (ALPHA.C == 0)) GetAlphaMinMax();
|
|
|
|
sw_blending |= (ALPHA.A != ALPHA.B) &&
|
2015-08-20 19:39:30 +00:00
|
|
|
((ALPHA.C == 0 && m_vt.m_alpha.max > 128) || (ALPHA.C == 2 && ALPHA.FIX > 128u));
|
2015-08-07 10:06:45 +00:00
|
|
|
case ACC_BLEND_CCLIP_DALPHA: sw_blending |= (ALPHA.C == 1) || (m_env.COLCLAMP.CLAMP == 0);
|
2016-01-22 08:07:35 +00:00
|
|
|
// Initial idea was to enable accurate blending for sprite rendering to handle
|
|
|
|
// correctly post-processing effect. Some games (ZoE) use tons of sprites as particles.
|
|
|
|
// In order to keep it fast, let's limit it to smaller draw call.
|
|
|
|
case ACC_BLEND_SPRITE: sw_blending |= m_vt.m_primclass == GS_SPRITE_CLASS && m_drawlist.size() < 100;
|
2016-06-07 16:42:58 +00:00
|
|
|
case ACC_BLEND_FREE: sw_blending |= impossible_or_free_blend;
|
2016-06-11 11:03:19 +00:00
|
|
|
default: /*sw_blending |= accumulation_blend*/;
|
2015-08-07 10:06:45 +00:00
|
|
|
}
|
|
|
|
// SW Blending
|
|
|
|
// GL42 interact very badly with sw blending. GL42 uses the primitiveID to find the primitive
|
|
|
|
// that write the bad alpha value. Sw blending will force the draw to run primitive by primitive
|
|
|
|
// (therefore primitiveID will be constant to 1)
|
|
|
|
sw_blending &= !DATE_GL42;
|
2015-07-25 15:57:42 +00:00
|
|
|
|
|
|
|
// Color clip
|
|
|
|
if (m_env.COLCLAMP.CLAMP == 0) {
|
2015-08-16 16:12:34 +00:00
|
|
|
if (m_prim_overlap == PRIM_OVERLAP_NO) {
|
|
|
|
// The fastest algo that requires a single pass
|
|
|
|
GL_INS("COLCLIP Free mode ENABLED");
|
2016-06-07 17:08:54 +00:00
|
|
|
m_ps_sel.colclip = 1;
|
2016-07-02 15:19:41 +00:00
|
|
|
//ASSERT(sw_blending);
|
|
|
|
sw_blending = true;
|
2015-10-16 20:06:34 +00:00
|
|
|
accumulation_blend = false; // disable the HDR algo
|
2015-08-16 16:12:34 +00:00
|
|
|
} else if (accumulation_blend) {
|
|
|
|
// A fast algo that requires 2 passes
|
2015-07-30 20:05:08 +00:00
|
|
|
GL_INS("COLCLIP Fast HDR mode ENABLED");
|
2016-06-07 17:08:54 +00:00
|
|
|
m_ps_sel.hdr = 1;
|
2016-06-11 11:03:19 +00:00
|
|
|
sw_blending = true; // Enable sw blending for the HDR algo
|
2015-08-07 10:06:45 +00:00
|
|
|
} else if (sw_blending) {
|
2015-08-16 16:12:34 +00:00
|
|
|
// A slow algo that could requires several passes (barely used)
|
2015-07-25 15:57:42 +00:00
|
|
|
GL_INS("COLCLIP SW ENABLED (blending is %d/%d/%d/%d)", ALPHA.A, ALPHA.B, ALPHA.C, ALPHA.D);
|
2016-06-07 17:08:54 +00:00
|
|
|
m_ps_sel.colclip = 1;
|
2015-07-30 20:05:08 +00:00
|
|
|
} else {
|
2015-08-16 16:12:34 +00:00
|
|
|
// Speed hack skip previous slow algo
|
2015-08-04 18:47:02 +00:00
|
|
|
GL_INS("Sorry colclip isn't supported");
|
2015-07-25 15:57:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-30 20:05:08 +00:00
|
|
|
// Seriously don't expect me to support this kind of crazyness.
|
|
|
|
// No mix of COLCLIP + accumulation_blend + DATE GL42
|
2015-07-25 16:20:00 +00:00
|
|
|
// Neither fbmask and GL42
|
2016-06-07 17:08:54 +00:00
|
|
|
ASSERT(!(m_ps_sel.hdr && DATE_GL42));
|
|
|
|
ASSERT(!(m_ps_sel.fbmask && DATE_GL42));
|
2015-07-25 15:57:42 +00:00
|
|
|
|
|
|
|
// For stat to optimize accurate option
|
|
|
|
#if 0
|
2016-05-01 20:54:18 +00:00
|
|
|
GL_INS("BLEND_INFO: %d/%d/%d/%d. Clamp:%d. Prim:%d number %d (drawlist %d) (sw %d)",
|
|
|
|
ALPHA.A, ALPHA.B, ALPHA.C, ALPHA.D, m_env.COLCLAMP.CLAMP, m_vt.m_primclass, m_vertex.next, m_drawlist.size(), sw_blending);
|
2015-07-25 15:57:42 +00:00
|
|
|
#endif
|
|
|
|
if (sw_blending) {
|
2016-06-07 17:08:54 +00:00
|
|
|
m_ps_sel.blend_a = ALPHA.A;
|
|
|
|
m_ps_sel.blend_b = ALPHA.B;
|
|
|
|
m_ps_sel.blend_c = ALPHA.C;
|
|
|
|
m_ps_sel.blend_d = ALPHA.D;
|
2015-07-25 15:57:42 +00:00
|
|
|
|
2015-07-30 20:05:08 +00:00
|
|
|
if (accumulation_blend) {
|
2015-08-16 16:12:34 +00:00
|
|
|
// Keep HW blending to do the addition/subtraction
|
2016-07-28 13:28:06 +00:00
|
|
|
dev->OMSetBlendState(blend_index, 0, false, true);
|
2015-08-18 07:14:11 +00:00
|
|
|
if (ALPHA.A == 2) {
|
|
|
|
// The blend unit does a reverse subtraction so it means
|
|
|
|
// the shader must output a positive value.
|
|
|
|
// Replace 0 - Cs by Cs - 0
|
2016-06-07 17:08:54 +00:00
|
|
|
m_ps_sel.blend_a = ALPHA.B;
|
|
|
|
m_ps_sel.blend_b = 2;
|
2015-08-18 07:14:11 +00:00
|
|
|
}
|
2015-08-16 16:12:34 +00:00
|
|
|
// Remove the addition/substraction from the SW blending
|
2016-06-07 17:08:54 +00:00
|
|
|
m_ps_sel.blend_d = 2;
|
2016-06-07 16:42:58 +00:00
|
|
|
|
|
|
|
// Note accumulation_blend doesn't require a barrier
|
|
|
|
|
2015-07-30 20:05:08 +00:00
|
|
|
} else {
|
|
|
|
// Disable HW blending
|
2015-07-31 18:28:54 +00:00
|
|
|
dev->OMSetBlendState();
|
2016-06-07 16:42:58 +00:00
|
|
|
|
|
|
|
m_require_full_barrier |= !(blend_flag & BLEND_NO_BAR);
|
2015-07-30 20:05:08 +00:00
|
|
|
}
|
|
|
|
|
2015-07-25 15:57:42 +00:00
|
|
|
// Require the fix alpha vlaue
|
|
|
|
if (ALPHA.C == 2) {
|
2016-03-06 19:45:51 +00:00
|
|
|
ps_cb.TA_Af.a = (float)ALPHA.FIX / 128.0f;
|
2015-07-25 15:57:42 +00:00
|
|
|
}
|
|
|
|
} else {
|
2016-06-07 17:08:54 +00:00
|
|
|
m_ps_sel.clr1 = !!(blend_flag & BLEND_C_CLR);
|
|
|
|
if (m_ps_sel.dfmt == 1 && ALPHA.C == 1) {
|
2015-07-25 15:57:42 +00:00
|
|
|
// 24 bits doesn't have an alpha channel so use 1.0f fix factor as equivalent
|
2016-04-14 10:00:58 +00:00
|
|
|
uint8 hacked_blend_index = blend_index + 3; // +3 <=> +1 on C
|
2015-08-07 10:13:50 +00:00
|
|
|
dev->OMSetBlendState(hacked_blend_index, 128, true);
|
2015-07-31 18:28:54 +00:00
|
|
|
} else {
|
2015-08-07 10:13:50 +00:00
|
|
|
dev->OMSetBlendState(blend_index, ALPHA.FIX, (ALPHA.C == 2));
|
2015-07-25 15:57:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 07:51:47 +00:00
|
|
|
void GSRendererOGL::RealignTargetTextureCoordinate(const GSTextureCache::Source* tex)
|
|
|
|
{
|
2017-02-26 15:09:55 +00:00
|
|
|
if (UserHacks_HPO <= 1 || GetUpscaleMultiplier() == 1) return;
|
2016-06-21 07:51:47 +00:00
|
|
|
|
|
|
|
GSVertex* v = &m_vertex.buff[0];
|
|
|
|
const GSVector2& scale = tex->m_texture->GetScale();
|
2017-02-24 16:55:39 +00:00
|
|
|
bool linear = m_vt.IsRealLinear();
|
2016-06-21 07:51:47 +00:00
|
|
|
int t_position = v[0].U;
|
|
|
|
GSVector4 half_offset(0.0f);
|
|
|
|
|
|
|
|
// FIXME Let's start with something wrong same mess on X and Y
|
|
|
|
// FIXME Maybe it will be enough to check linear
|
|
|
|
|
|
|
|
if (PRIM->FST) {
|
|
|
|
|
2017-02-26 15:09:55 +00:00
|
|
|
if (UserHacks_HPO == 3) {
|
2016-06-21 07:51:47 +00:00
|
|
|
if (!linear && t_position == 8) {
|
|
|
|
half_offset.x = 8;
|
|
|
|
half_offset.y = 8;
|
|
|
|
} else if (linear && t_position == 16) {
|
|
|
|
half_offset.x = 16;
|
|
|
|
half_offset.y = 16;
|
2016-08-09 13:14:13 +00:00
|
|
|
} else if (m_vt.m_min.p.x == -0.5f) {
|
|
|
|
half_offset.x = 8;
|
|
|
|
half_offset.y = 8;
|
2016-06-21 07:51:47 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!linear && t_position == 8) {
|
|
|
|
half_offset.x = 8 - 8 / scale.x;
|
|
|
|
half_offset.y = 8 - 8 / scale.y;
|
|
|
|
} else if (linear && t_position == 16) {
|
|
|
|
half_offset.x = 16 - 16 / scale.x;
|
|
|
|
half_offset.y = 16 - 16 / scale.y;
|
2016-08-09 13:14:13 +00:00
|
|
|
} else if (m_vt.m_min.p.x == -0.5f) {
|
|
|
|
half_offset.x = 8;
|
|
|
|
half_offset.y = 8;
|
2016-06-21 07:51:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GL_INS("offset detected %f,%f t_pos %d (linear %d, scale %f)",
|
|
|
|
half_offset.x, half_offset.y, t_position, linear, scale.x);
|
|
|
|
|
|
|
|
} else if (m_vt.m_eq.q) {
|
|
|
|
float tw = (float)(1 << m_context->TEX0.TW);
|
|
|
|
float th = (float)(1 << m_context->TEX0.TH);
|
|
|
|
float q = v[0].RGBAQ.Q;
|
|
|
|
|
|
|
|
// Tales of Abyss
|
|
|
|
half_offset.x = 0.5f * q / tw;
|
|
|
|
half_offset.y = 0.5f * q / th;
|
|
|
|
|
|
|
|
GL_INS("ST offset detected %f,%f (linear %d, scale %f)",
|
|
|
|
half_offset.x, half_offset.y, linear, scale.x);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
vs_cb.TextureOffset = GSVector4(half_offset);
|
|
|
|
}
|
|
|
|
|
2016-06-07 17:08:54 +00:00
|
|
|
void GSRendererOGL::EmulateTextureSampler(const GSTextureCache::Source* tex)
|
2016-06-07 16:12:57 +00:00
|
|
|
{
|
|
|
|
GSDeviceOGL* dev = (GSDeviceOGL*)m_dev;
|
|
|
|
|
|
|
|
// Warning fetch the texture PSM format rather than the context format. The latter could have been corrected in the texture cache for depth.
|
|
|
|
//const GSLocalMemory::psm_t &psm = GSLocalMemory::m_psm[m_context->TEX0.PSM];
|
|
|
|
const GSLocalMemory::psm_t &psm = GSLocalMemory::m_psm[tex->m_TEX0.PSM];
|
|
|
|
const GSLocalMemory::psm_t &cpsm = psm.pal > 0 ? GSLocalMemory::m_psm[m_context->TEX0.CPSM] : psm;
|
2016-06-09 17:35:18 +00:00
|
|
|
|
|
|
|
const uint8 wms = m_context->CLAMP.WMS;
|
|
|
|
const uint8 wmt = m_context->CLAMP.WMT;
|
2016-06-29 17:42:05 +00:00
|
|
|
bool complex_wms_wmt = !!((wms | wmt) & 2);
|
2016-06-09 17:35:18 +00:00
|
|
|
|
2016-10-02 08:51:29 +00:00
|
|
|
bool need_mipmap = IsMipMapDraw();
|
2016-10-01 11:58:29 +00:00
|
|
|
bool shader_emulated_sampler = tex->m_palette || cpsm.fmt != 0 || complex_wms_wmt || psm.depth;
|
2016-10-02 08:51:29 +00:00
|
|
|
bool trilinear_manual = need_mipmap && m_mipmap == 2;
|
|
|
|
|
2017-02-24 16:55:39 +00:00
|
|
|
bool bilinear = m_vt.IsLinear();
|
2016-10-02 08:51:29 +00:00
|
|
|
int trilinear = 0;
|
|
|
|
bool trilinear_auto = false;
|
2017-02-24 16:55:39 +00:00
|
|
|
switch (UserHacks_tri_filter)
|
2016-10-14 13:30:17 +00:00
|
|
|
{
|
2017-02-24 16:55:39 +00:00
|
|
|
case TriFiltering::Forced:
|
2016-10-02 08:51:29 +00:00
|
|
|
trilinear = static_cast<uint8>(GS_MIN_FILTER::Linear_Mipmap_Linear);
|
|
|
|
trilinear_auto = m_mipmap != 2;
|
|
|
|
break;
|
2016-10-14 13:30:17 +00:00
|
|
|
|
2017-02-24 16:55:39 +00:00
|
|
|
case TriFiltering::PS2:
|
2016-10-02 08:51:29 +00:00
|
|
|
if (need_mipmap && m_mipmap != 2) {
|
|
|
|
trilinear = m_context->TEX1.MMIN;
|
|
|
|
trilinear_auto = true;
|
|
|
|
}
|
|
|
|
break;
|
2016-10-14 13:30:17 +00:00
|
|
|
|
2017-02-24 16:55:39 +00:00
|
|
|
case TriFiltering::None:
|
2016-10-02 08:51:29 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-06-09 17:35:18 +00:00
|
|
|
// 1 and 0 are equivalent
|
|
|
|
m_ps_sel.wms = (wms & 2) ? wms : 0;
|
|
|
|
m_ps_sel.wmt = (wmt & 2) ? wmt : 0;
|
2016-06-07 16:12:57 +00:00
|
|
|
|
|
|
|
// Depth + bilinear filtering isn't done yet (And I'm not sure we need it anyway but a game will prove me wrong)
|
|
|
|
// So of course, GTA set the linear mode, but sampling is done at texel center so it is equivalent to nearest sampling
|
|
|
|
ASSERT(!(psm.depth && m_vt.IsLinear()));
|
|
|
|
|
|
|
|
// 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)
|
2016-06-07 17:08:54 +00:00
|
|
|
if (m_ps_sel.shuffle) {
|
2016-06-07 16:12:57 +00:00
|
|
|
// Force a 32 bits access (normally shuffle is done on 16 bits)
|
2016-06-07 17:08:54 +00:00
|
|
|
// m_ps_sel.tex_fmt = 0; // removed as an optimization
|
|
|
|
m_ps_sel.aem = m_env.TEXA.AEM;
|
2016-06-07 16:12:57 +00:00
|
|
|
ASSERT(tex->m_target);
|
|
|
|
|
|
|
|
// Require a float conversion if the texure is a depth otherwise uses Integral scaling
|
|
|
|
if (psm.depth) {
|
2016-06-07 17:08:54 +00:00
|
|
|
m_ps_sel.depth_fmt = (tex->m_texture->GetType() != GSTexture::DepthStencil) ? 3 : 1;
|
2016-06-07 16:12:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Shuffle is a 16 bits format, so aem is always required
|
|
|
|
GSVector4 ta(m_env.TEXA & GSVector4i::x000000ff());
|
|
|
|
ta /= 255.0f;
|
|
|
|
// FIXME rely on compiler for the optimization
|
|
|
|
ps_cb.TA_Af.x = ta.x;
|
|
|
|
ps_cb.TA_Af.y = ta.y;
|
|
|
|
|
|
|
|
// The purpose of texture shuffle is to move color channel. Extra interpolation is likely a bad idea.
|
|
|
|
bilinear &= m_vt.IsLinear();
|
|
|
|
|
2016-06-21 07:51:47 +00:00
|
|
|
RealignTargetTextureCoordinate(tex);
|
|
|
|
|
2016-06-07 16:12:57 +00:00
|
|
|
} else if (tex->m_target) {
|
|
|
|
// 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)
|
2016-06-07 17:08:54 +00:00
|
|
|
m_ps_sel.tex_fmt = cpsm.fmt;
|
|
|
|
m_ps_sel.aem = m_env.TEXA.AEM;
|
2016-06-07 16:12:57 +00:00
|
|
|
|
|
|
|
// Don't upload AEM if format is 32 bits
|
|
|
|
if (cpsm.fmt) {
|
|
|
|
GSVector4 ta(m_env.TEXA & GSVector4i::x000000ff());
|
|
|
|
ta /= 255.0f;
|
|
|
|
// FIXME rely on compiler for the optimization
|
|
|
|
ps_cb.TA_Af.x = ta.x;
|
|
|
|
ps_cb.TA_Af.y = ta.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Select the index format
|
|
|
|
if (tex->m_palette) {
|
|
|
|
// FIXME Potentially improve fmt field in GSLocalMemory
|
|
|
|
if (m_context->TEX0.PSM == PSM_PSMT4HL)
|
2016-06-07 17:08:54 +00:00
|
|
|
m_ps_sel.tex_fmt |= 1 << 2;
|
2016-06-07 16:12:57 +00:00
|
|
|
else if (m_context->TEX0.PSM == PSM_PSMT4HH)
|
2016-06-07 17:08:54 +00:00
|
|
|
m_ps_sel.tex_fmt |= 2 << 2;
|
2016-06-07 16:12:57 +00:00
|
|
|
else
|
2016-06-07 17:08:54 +00:00
|
|
|
m_ps_sel.tex_fmt |= 3 << 2;
|
2016-06-07 16:12:57 +00:00
|
|
|
|
|
|
|
// 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();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Depth format
|
|
|
|
if (tex->m_texture->GetType() == GSTexture::DepthStencil) {
|
|
|
|
// Require a float conversion if the texure is a depth format
|
2016-06-07 17:08:54 +00:00
|
|
|
m_ps_sel.depth_fmt = (psm.bpp == 16) ? 2 : 1;
|
2016-06-07 16:12:57 +00:00
|
|
|
|
|
|
|
// Don't force interpolation on depth format
|
|
|
|
bilinear &= m_vt.IsLinear();
|
|
|
|
} else if (psm.depth) {
|
|
|
|
// Use Integral scaling
|
2016-10-03 16:52:02 +00:00
|
|
|
m_ps_sel.depth_fmt = 3;
|
2016-06-07 16:12:57 +00:00
|
|
|
|
2016-10-03 16:52:02 +00:00
|
|
|
// Don't force interpolation on depth format
|
|
|
|
bilinear &= m_vt.IsLinear();
|
2016-06-07 16:12:57 +00:00
|
|
|
}
|
|
|
|
|
2016-06-21 07:51:47 +00:00
|
|
|
RealignTargetTextureCoordinate(tex);
|
|
|
|
|
2016-06-07 16:12:57 +00:00
|
|
|
} else if (tex->m_palette) {
|
|
|
|
// Use a standard 8 bits texture. AEM is already done on the CLUT
|
|
|
|
// Therefore you only need to set the index
|
2016-06-07 17:08:54 +00:00
|
|
|
// m_ps_sel.aem = 0; // removed as an optimization
|
2016-06-07 16:12:57 +00:00
|
|
|
|
|
|
|
// Note 4 bits indexes are converted to 8 bits
|
2016-06-07 17:08:54 +00:00
|
|
|
m_ps_sel.tex_fmt = 3 << 2;
|
2016-06-07 16:12:57 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
// Standard texture. Both index and AEM expansion were already done by the CPU.
|
2016-06-07 17:08:54 +00:00
|
|
|
// m_ps_sel.tex_fmt = 0; // removed as an optimization
|
|
|
|
// m_ps_sel.aem = 0; // removed as an optimization
|
2016-06-07 16:12:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (m_context->TEX0.TFX == TFX_MODULATE && m_vt.m_eq.rgba == 0xFFFF && m_vt.m_min.c.eq(GSVector4i(128))) {
|
|
|
|
// Micro optimization that reduces GPU load (removes 5 instructions on the FS program)
|
2016-06-07 17:08:54 +00:00
|
|
|
m_ps_sel.tfx = TFX_DECAL;
|
2016-06-07 16:12:57 +00:00
|
|
|
} else {
|
2016-06-07 17:08:54 +00:00
|
|
|
m_ps_sel.tfx = m_context->TEX0.TFX;
|
2016-06-07 16:12:57 +00:00
|
|
|
}
|
|
|
|
|
2016-06-07 17:08:54 +00:00
|
|
|
m_ps_sel.tcc = m_context->TEX0.TCC;
|
2016-06-07 16:12:57 +00:00
|
|
|
|
2016-10-01 11:58:29 +00:00
|
|
|
m_ps_sel.ltf = bilinear && shader_emulated_sampler;
|
2016-06-07 16:12:57 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2016-06-07 17:08:54 +00:00
|
|
|
m_ps_sel.fst = !!PRIM->FST;
|
2016-06-07 16:12:57 +00:00
|
|
|
|
|
|
|
ps_cb.WH = WH;
|
|
|
|
ps_cb.HalfTexel = GSVector4(-0.5f, 0.5f).xxyy() / WH.zwzw();
|
2016-06-09 17:35:18 +00:00
|
|
|
if (complex_wms_wmt) {
|
2016-06-07 16:12:57 +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();
|
2016-10-02 08:51:29 +00:00
|
|
|
} else if (trilinear_manual) {
|
2016-10-01 15:35:02 +00:00
|
|
|
// Reuse MinMax for mipmap parameter to avoid an extension of the UBO
|
|
|
|
ps_cb.MinMax.x = (float)m_context->TEX1.K / 16.0f;
|
|
|
|
ps_cb.MinMax.y = float(1 << m_context->TEX1.L);
|
|
|
|
ps_cb.MinMax.z = float(m_lod.x); // Offset because first layer is m_lod, dunno if we can do better
|
|
|
|
ps_cb.MinMax.w = float(m_lod.y);
|
2016-10-02 08:51:29 +00:00
|
|
|
} else if (trilinear_auto) {
|
|
|
|
tex->m_texture->GenerateMipmap();
|
2016-06-07 16:12:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TC Offset Hack
|
2016-06-07 17:08:54 +00:00
|
|
|
m_ps_sel.tcoffsethack = !!UserHacks_TCOffset;
|
2016-06-07 16:12:57 +00:00
|
|
|
ps_cb.TC_OH_TS = GSVector4(1/16.0f, 1/16.0f, UserHacks_TCO_x, UserHacks_TCO_y) / WH.xyxy();
|
|
|
|
|
|
|
|
|
|
|
|
// Only enable clamping in CLAMP mode. REGION_CLAMP will be done manually in the shader
|
2016-06-09 17:35:18 +00:00
|
|
|
m_ps_ssel.tau = (wms != CLAMP_CLAMP);
|
|
|
|
m_ps_ssel.tav = (wmt != CLAMP_CLAMP);
|
2016-10-01 15:33:36 +00:00
|
|
|
if (shader_emulated_sampler) {
|
|
|
|
m_ps_ssel.biln = 0;
|
|
|
|
m_ps_ssel.aniso = 0;
|
|
|
|
m_ps_ssel.triln = 0;
|
|
|
|
} else {
|
|
|
|
m_ps_ssel.biln = bilinear;
|
|
|
|
m_ps_ssel.aniso = 1;
|
2016-10-02 08:51:29 +00:00
|
|
|
m_ps_ssel.triln = trilinear;
|
|
|
|
if (trilinear_manual) {
|
2016-10-01 15:35:02 +00:00
|
|
|
m_ps_sel.manual_lod = 1;
|
2016-10-02 08:51:29 +00:00
|
|
|
} else if (trilinear_auto) {
|
|
|
|
m_ps_sel.automatic_lod = 1;
|
2016-10-01 15:35:02 +00:00
|
|
|
}
|
2016-10-01 15:33:36 +00:00
|
|
|
}
|
2016-06-07 16:12:57 +00:00
|
|
|
|
|
|
|
// Setup Texture ressources
|
2016-06-07 17:08:54 +00:00
|
|
|
dev->SetupSampler(m_ps_ssel);
|
2016-06-07 16:12:57 +00:00
|
|
|
dev->PSSetShaderResources(tex->m_texture, tex->m_palette);
|
|
|
|
}
|
|
|
|
|
2015-07-19 07:58:56 +00:00
|
|
|
GSRendererOGL::PRIM_OVERLAP GSRendererOGL::PrimitiveOverlap()
|
|
|
|
{
|
|
|
|
// Either 1 triangle or 1 line or 3 POINTs
|
|
|
|
// It is bad for the POINTs but low probability that they overlap
|
|
|
|
if (m_vertex.next < 4)
|
|
|
|
return PRIM_OVERLAP_NO;
|
|
|
|
|
2015-08-05 15:59:55 +00:00
|
|
|
if (m_vt.m_primclass != GS_SPRITE_CLASS)
|
2015-07-19 07:58:56 +00:00
|
|
|
return PRIM_OVERLAP_UNKNOW; // maybe, maybe not
|
|
|
|
|
|
|
|
// Check intersection of sprite primitive only
|
|
|
|
size_t count = m_vertex.next;
|
2016-01-11 17:44:17 +00:00
|
|
|
PRIM_OVERLAP overlap = PRIM_OVERLAP_NO;
|
|
|
|
GSVertex* v = m_vertex.buff;
|
|
|
|
|
2016-01-11 17:56:08 +00:00
|
|
|
m_drawlist.clear();
|
2016-01-11 17:44:17 +00:00
|
|
|
size_t i = 0;
|
|
|
|
while (i < count) {
|
|
|
|
// In order to speed up comparison a bounding-box is accumulated. It removes a
|
|
|
|
// loop so code is much faster (check game virtua fighter). Besides it allow to check
|
|
|
|
// properly the Y order.
|
2016-01-13 21:43:57 +00:00
|
|
|
|
|
|
|
// .x = min(v[i].XYZ.X, v[i+1].XYZ.X)
|
|
|
|
// .y = min(v[i].XYZ.Y, v[i+1].XYZ.Y)
|
|
|
|
// .z = max(v[i].XYZ.X, v[i+1].XYZ.X)
|
|
|
|
// .w = max(v[i].XYZ.Y, v[i+1].XYZ.Y)
|
|
|
|
GSVector4i all = GSVector4i(v[i].m[1]).upl16(GSVector4i(v[i+1].m[1])).upl16().xzyw();
|
|
|
|
all = all.xyxy().blend(all.zwzw(), all > all.zwxy());
|
2015-10-21 22:46:31 +00:00
|
|
|
|
2016-01-11 17:44:17 +00:00
|
|
|
size_t j = i + 2;
|
|
|
|
while (j < count) {
|
2016-01-13 21:43:57 +00:00
|
|
|
GSVector4i sprite = GSVector4i(v[j].m[1]).upl16(GSVector4i(v[j+1].m[1])).upl16().xzyw();
|
|
|
|
sprite = sprite.xyxy().blend(sprite.zwzw(), sprite > sprite.zwxy());
|
2016-01-11 17:44:17 +00:00
|
|
|
|
|
|
|
// Be sure to get vertex in good order, otherwise .r* function doesn't
|
|
|
|
// work as expected.
|
|
|
|
ASSERT(sprite.x <= sprite.z);
|
|
|
|
ASSERT(sprite.y <= sprite.w);
|
|
|
|
ASSERT(all.x <= all.z);
|
|
|
|
ASSERT(all.y <= all.w);
|
2015-10-21 22:46:31 +00:00
|
|
|
|
2016-01-11 17:44:17 +00:00
|
|
|
if (all.rintersect(sprite).rempty()) {
|
2016-01-13 21:43:57 +00:00
|
|
|
all = all.runion_ordered(sprite);
|
2016-01-11 17:44:17 +00:00
|
|
|
} else {
|
|
|
|
overlap = PRIM_OVERLAP_YES;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
j += 2;
|
2015-08-05 15:59:55 +00:00
|
|
|
}
|
2016-01-11 17:56:08 +00:00
|
|
|
m_drawlist.push_back((j - i) >> 1); // Sprite count
|
2016-01-11 17:44:17 +00:00
|
|
|
i = j;
|
2015-08-05 15:59:55 +00:00
|
|
|
}
|
2016-01-11 17:44:17 +00:00
|
|
|
|
2015-08-05 15:59:55 +00:00
|
|
|
#if 0
|
|
|
|
// Old algo: less constraint but O(n^2) instead of O(n) as above
|
|
|
|
|
2015-07-31 23:27:22 +00:00
|
|
|
// You have no guarantee on the sprite order, first vertex can be either top-left or bottom-left
|
|
|
|
// There is a high probability that the draw call will uses same ordering for all vertices.
|
|
|
|
// In order to keep a small performance impact only the first sprite will be checked
|
|
|
|
//
|
|
|
|
// Some safe-guard will be added in the outer-loop to avoid corruption with a limited perf impact
|
|
|
|
if (v[1].XYZ.Y < v[0].XYZ.Y) {
|
|
|
|
// First vertex is Top-Left
|
|
|
|
for(size_t i = 0; i < count; i += 2) {
|
|
|
|
if (v[i+1].XYZ.Y > v[i].XYZ.Y) {
|
|
|
|
return PRIM_OVERLAP_UNKNOW;
|
|
|
|
}
|
|
|
|
GSVector4i vi(v[i].XYZ.X, v[i+1].XYZ.Y, v[i+1].XYZ.X, v[i].XYZ.Y);
|
|
|
|
for (size_t j = i+2; j < count; j += 2) {
|
|
|
|
GSVector4i vj(v[j].XYZ.X, v[j+1].XYZ.Y, v[j+1].XYZ.X, v[j].XYZ.Y);
|
|
|
|
GSVector4i inter = vi.rintersect(vj);
|
|
|
|
if (!inter.rempty()) {
|
|
|
|
return PRIM_OVERLAP_YES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// First vertex is Bottom-Left
|
|
|
|
for(size_t i = 0; i < count; i += 2) {
|
|
|
|
if (v[i+1].XYZ.Y < v[i].XYZ.Y) {
|
|
|
|
return PRIM_OVERLAP_UNKNOW;
|
|
|
|
}
|
|
|
|
GSVector4i vi(v[i].XYZ.X, v[i].XYZ.Y, v[i+1].XYZ.X, v[i+1].XYZ.Y);
|
|
|
|
for (size_t j = i+2; j < count; j += 2) {
|
|
|
|
GSVector4i vj(v[j].XYZ.X, v[j].XYZ.Y, v[j+1].XYZ.X, v[j+1].XYZ.Y);
|
|
|
|
GSVector4i inter = vi.rintersect(vj);
|
|
|
|
if (!inter.rempty()) {
|
|
|
|
return PRIM_OVERLAP_YES;
|
|
|
|
}
|
2015-07-19 07:58:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-08-05 15:59:55 +00:00
|
|
|
#endif
|
2015-07-19 07:58:56 +00:00
|
|
|
|
2015-07-31 23:27:22 +00:00
|
|
|
//fprintf(stderr, "%d: Yes, code can be optimized (draw of %d vertices)\n", s_n, count);
|
2016-01-11 17:44:17 +00:00
|
|
|
return overlap;
|
2015-07-19 07:58:56 +00:00
|
|
|
}
|
|
|
|
|
2015-07-24 20:06:35 +00:00
|
|
|
GSVector4i GSRendererOGL::ComputeBoundingBox(const GSVector2& rtscale, const GSVector2i& rtsize)
|
|
|
|
{
|
|
|
|
GSVector4 scale = GSVector4(rtscale.x, rtscale.y);
|
|
|
|
GSVector4 offset = GSVector4(-1.0f, 1.0f); // Round value
|
|
|
|
GSVector4 box = m_vt.m_min.p.xyxy(m_vt.m_max.p) + offset.xxyy();
|
|
|
|
return GSVector4i(box * scale.xyxy()).rintersect(GSVector4i(0, 0, rtsize.x, rtsize.y));
|
|
|
|
}
|
|
|
|
|
2016-06-07 16:42:58 +00:00
|
|
|
void GSRendererOGL::SendDraw()
|
2015-07-19 07:58:56 +00:00
|
|
|
{
|
|
|
|
GSDeviceOGL* dev = (GSDeviceOGL*)m_dev;
|
|
|
|
|
2016-06-07 16:42:58 +00:00
|
|
|
if (!m_require_full_barrier && m_require_one_barrier) {
|
|
|
|
// Need only a single barrier
|
2015-12-31 22:58:03 +00:00
|
|
|
glTextureBarrier();
|
|
|
|
dev->DrawIndexedPrimitive();
|
2016-06-07 16:42:58 +00:00
|
|
|
} else if (!m_require_full_barrier) {
|
|
|
|
// Don't need any barrier
|
2015-07-25 15:10:45 +00:00
|
|
|
dev->DrawIndexedPrimitive();
|
|
|
|
} else if (m_prim_overlap == PRIM_OVERLAP_NO) {
|
2016-06-07 16:42:58 +00:00
|
|
|
// Need full barrier but a single barrier will be enough
|
2015-10-17 15:05:15 +00:00
|
|
|
glTextureBarrier();
|
2015-07-19 07:58:56 +00:00
|
|
|
dev->DrawIndexedPrimitive();
|
2016-01-11 17:56:08 +00:00
|
|
|
} else if (m_vt.m_primclass == GS_SPRITE_CLASS) {
|
2016-09-20 07:30:24 +00:00
|
|
|
size_t nb_vertex = (m_gs_sel.sprite == 1) ? 2 : 6;
|
2016-01-11 23:52:45 +00:00
|
|
|
|
|
|
|
GL_PUSH("Split the draw (SPRITE)");
|
|
|
|
|
|
|
|
#if defined(_DEBUG)
|
|
|
|
// Check how draw call is split.
|
|
|
|
map<size_t, size_t> frequency;
|
|
|
|
for (const auto& it: m_drawlist)
|
|
|
|
++frequency[it];
|
|
|
|
|
|
|
|
string message;
|
|
|
|
for (const auto& it: frequency)
|
|
|
|
message += " " + to_string(it.first) + "(" + to_string(it.second) + ")";
|
|
|
|
|
|
|
|
GL_PERF("Split single draw (%d sprites) into %zu draws: consecutive draws(frequency):%s",
|
|
|
|
m_index.tail / nb_vertex, m_drawlist.size(), message.c_str());
|
|
|
|
#endif
|
|
|
|
|
2016-01-11 17:56:08 +00:00
|
|
|
for (size_t count, p = 0, n = 0; n < m_drawlist.size(); p += count, ++n) {
|
|
|
|
count = m_drawlist[n] * nb_vertex;
|
|
|
|
glTextureBarrier();
|
|
|
|
dev->DrawIndexedPrimitive(p, count);
|
|
|
|
}
|
2015-07-19 07:58:56 +00:00
|
|
|
} else {
|
|
|
|
// FIXME: Investigate: a dynamic check to pack as many primitives as possibles
|
|
|
|
// I'm nearly sure GSdx already have this kind of code (maybe we can adapt GSDirtyRect)
|
2016-04-26 17:29:04 +00:00
|
|
|
size_t nb_vertex = GSUtil::GetClassVertexCount(m_vt.m_primclass);
|
2015-07-19 07:58:56 +00:00
|
|
|
|
|
|
|
GL_PUSH("Split the draw");
|
|
|
|
|
|
|
|
GL_PERF("Split single draw in %d draw", m_index.tail/nb_vertex);
|
|
|
|
|
|
|
|
for (size_t p = 0; p < m_index.tail; p += nb_vertex) {
|
2015-10-17 15:05:15 +00:00
|
|
|
glTextureBarrier();
|
2015-07-19 07:58:56 +00:00
|
|
|
dev->DrawIndexedPrimitive(p, nb_vertex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-07 17:08:54 +00:00
|
|
|
void GSRendererOGL::ResetStates()
|
2015-07-19 07:58:56 +00:00
|
|
|
{
|
2016-06-07 17:08:54 +00:00
|
|
|
m_require_one_barrier = false;
|
|
|
|
m_require_full_barrier = false;
|
2015-08-22 10:21:37 +00:00
|
|
|
|
2016-06-07 17:08:54 +00:00
|
|
|
m_vs_sel.key = 0;
|
|
|
|
m_gs_sel.key = 0;
|
|
|
|
m_ps_sel.key = 0;
|
2015-08-22 10:21:37 +00:00
|
|
|
|
2016-06-07 17:08:54 +00:00
|
|
|
m_ps_ssel.key = 0;
|
|
|
|
m_om_csel.key = 0;
|
|
|
|
m_om_dssel.key = 0;
|
|
|
|
}
|
2015-08-22 10:21:37 +00:00
|
|
|
|
2016-06-07 17:08:54 +00:00
|
|
|
void GSRendererOGL::DrawPrims(GSTexture* rt, GSTexture* ds, GSTextureCache::Source* tex)
|
|
|
|
{
|
2016-07-31 11:13:01 +00:00
|
|
|
#ifdef ENABLE_OGL_DEBUG
|
|
|
|
GSVector4i area_out = GSVector4i(m_vt.m_min.p.xyxy(m_vt.m_max.p)).rintersect(GSVector4i(m_context->scissor.in));
|
|
|
|
GSVector4i area_in = GSVector4i(m_vt.m_min.t.xyxy(m_vt.m_max.t));
|
|
|
|
|
|
|
|
GL_PUSH("GL Draw from %d (area %d,%d => %d,%d) in %d (Depth %d) (area %d,%d => %d,%d)",
|
|
|
|
tex && tex->m_texture ? tex->m_texture->GetID() : -1,
|
|
|
|
area_in.x, area_in.y, area_in.z, area_in.w,
|
|
|
|
rt ? rt->GetID() : -1, ds ? ds->GetID() : -1,
|
|
|
|
area_out.x, area_out.y, area_out.z, area_out.w
|
|
|
|
);
|
|
|
|
#endif
|
2015-07-19 07:58:56 +00:00
|
|
|
|
2015-07-24 20:06:35 +00:00
|
|
|
GSTexture* hdr_rt = NULL;
|
2015-07-19 07:58:56 +00:00
|
|
|
|
2015-08-04 17:26:17 +00:00
|
|
|
const GSVector2i& rtsize = ds ? ds->GetSize() : rt->GetSize();
|
|
|
|
const GSVector2& rtscale = ds ? ds->GetScale() : rt->GetScale();
|
2015-07-19 07:58:56 +00:00
|
|
|
|
2015-07-25 14:26:53 +00:00
|
|
|
bool DATE = m_context->TEST.DATE && m_context->FRAME.PSM != PSM_PSMCT24;
|
2015-07-19 07:58:56 +00:00
|
|
|
bool DATE_GL42 = false;
|
|
|
|
bool DATE_GL45 = false;
|
2016-05-15 15:44:40 +00:00
|
|
|
bool DATE_one = false;
|
2015-07-19 07:58:56 +00:00
|
|
|
|
2016-08-11 19:15:17 +00:00
|
|
|
bool ate_first_pass = m_context->TEST.DoFirstPass();
|
|
|
|
bool ate_second_pass = m_context->TEST.DoSecondPass();
|
|
|
|
|
2016-06-07 17:08:54 +00:00
|
|
|
ResetStates();
|
2016-06-21 07:51:47 +00:00
|
|
|
vs_cb.TextureOffset = GSVector4(0.0f);
|
2015-07-19 07:58:56 +00:00
|
|
|
|
|
|
|
ASSERT(m_dev != NULL);
|
|
|
|
GSDeviceOGL* dev = (GSDeviceOGL*)m_dev;
|
|
|
|
|
2016-05-02 17:48:11 +00:00
|
|
|
// HLE implementation of the channel selection effect
|
|
|
|
//
|
|
|
|
// Warning it must be done at the begining because it will change the
|
|
|
|
// vertex list (it will interact with PrimitiveOverlap and accurate
|
|
|
|
// blending)
|
2016-06-07 17:08:54 +00:00
|
|
|
EmulateChannelShuffle(&rt, tex);
|
2016-05-02 17:48:11 +00:00
|
|
|
|
2016-05-14 10:17:59 +00:00
|
|
|
// Upscaling hack to avoid various line/grid issues
|
2016-05-13 16:27:39 +00:00
|
|
|
if (UserHacks_merge_sprite && tex && tex->m_target && (m_vt.m_primclass == GS_SPRITE_CLASS)) {
|
|
|
|
if (PRIM->FST && GSLocalMemory::m_psm[tex->m_TEX0.PSM].fmt < 2 && ((m_vt.m_eq.value & 0xCFFFF) == 0xCFFFF)) {
|
2016-05-10 06:12:07 +00:00
|
|
|
|
2016-05-14 10:17:59 +00:00
|
|
|
// Ideally the hack ought to be enabled in a true paving mode only. I don't know how to do it accurately
|
|
|
|
// neither in a fast way. So instead let's just take the hypothesis that all sprites must have the same
|
|
|
|
// size.
|
|
|
|
// Tested on Tekken 5.
|
|
|
|
GSVertex* v = &m_vertex.buff[0];
|
|
|
|
bool is_paving = true;
|
|
|
|
// SSE optimization: shuffle m[1] to have (4*32 bits) X, Y, U, V
|
|
|
|
int first_dpX = v[1].XYZ.X - v[0].XYZ.X;
|
|
|
|
int first_dpU = v[1].U - v[0].U;
|
2016-05-15 11:10:46 +00:00
|
|
|
for (size_t i = 0; i < m_vertex.next; i += 2) {
|
2016-05-14 10:17:59 +00:00
|
|
|
int dpX = v[i+1].XYZ.X - v[i].XYZ.X;
|
|
|
|
int dpU = v[i+1].U - v[i].U;
|
|
|
|
if (dpX != first_dpX || dpU != first_dpU) {
|
|
|
|
is_paving = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-05-10 06:12:07 +00:00
|
|
|
|
2016-05-14 10:17:59 +00:00
|
|
|
#if 0
|
|
|
|
GSVector4 delta_p = m_vt.m_max.p - m_vt.m_min.p;
|
|
|
|
GSVector4 delta_t = m_vt.m_max.t - m_vt.m_min.t;
|
|
|
|
bool is_blit = PrimitiveOverlap() == PRIM_OVERLAP_NO;
|
|
|
|
GL_INS("PP SAMPLER: Dp %f %f Dt %f %f. Is blit %d, is paving %d, count %d", delta_p.x, delta_p.y, delta_t.x, delta_t.y, is_blit, is_paving, m_vertex.tail);
|
|
|
|
#endif
|
2016-05-10 06:12:07 +00:00
|
|
|
|
2016-05-14 10:17:59 +00:00
|
|
|
if (is_paving) {
|
|
|
|
// Replace all sprite with a single fullscreen sprite.
|
|
|
|
GSVertex* s = &m_vertex.buff[0];
|
2016-05-10 06:12:07 +00:00
|
|
|
|
2016-06-29 17:42:05 +00:00
|
|
|
s[0].XYZ.X = static_cast<uint16>((16.0f * m_vt.m_min.p.x) + m_context->XYOFFSET.OFX);
|
|
|
|
s[1].XYZ.X = static_cast<uint16>((16.0f * m_vt.m_max.p.x) + m_context->XYOFFSET.OFX);
|
|
|
|
s[0].XYZ.Y = static_cast<uint16>((16.0f * m_vt.m_min.p.y) + m_context->XYOFFSET.OFY);
|
|
|
|
s[1].XYZ.Y = static_cast<uint16>((16.0f * m_vt.m_max.p.y) + m_context->XYOFFSET.OFY);
|
2016-05-10 06:12:07 +00:00
|
|
|
|
2016-06-29 17:42:05 +00:00
|
|
|
s[0].U = static_cast<uint16>(16.0f * m_vt.m_min.t.x);
|
|
|
|
s[0].V = static_cast<uint16>(16.0f * m_vt.m_min.t.y);
|
|
|
|
s[1].U = static_cast<uint16>(16.0f * m_vt.m_max.t.x);
|
|
|
|
s[1].V = static_cast<uint16>(16.0f * m_vt.m_max.t.y);
|
2016-05-10 06:12:07 +00:00
|
|
|
|
2016-05-14 10:17:59 +00:00
|
|
|
m_vertex.head = m_vertex.tail = m_vertex.next = 2;
|
|
|
|
m_index.tail = 2;
|
|
|
|
}
|
2016-05-10 06:12:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-15 13:00:52 +00:00
|
|
|
// Always check if primitive overlap. The function will return PRIM_OVERLAP_UNKNOW for non sprite primitive
|
|
|
|
m_prim_overlap = PrimitiveOverlap();
|
2016-09-08 21:26:38 +00:00
|
|
|
if ((m_context->FRAME.Block() == m_context->TEX0.TBP0) && PRIM->TME && m_sw_blending && (m_prim_overlap != PRIM_OVERLAP_NO) && (m_vertex.next > 2)) {
|
2016-09-25 08:05:44 +00:00
|
|
|
if (m_context->FRAME.FBMSK == 0x00FFFFFF) {
|
|
|
|
// Ratchet & Clank / Jak uses this pattern to compute the shadows. Alpha (multiplication) tfx is mostly equivalent to -1/+1 stencil operation
|
2016-10-14 18:24:52 +00:00
|
|
|
GL_DBG("ERROR: Source and Target are the same! Let's sample the framebuffer");
|
2016-09-08 21:26:38 +00:00
|
|
|
m_ps_sel.tex_is_fb = 1;
|
|
|
|
m_require_full_barrier = true;
|
|
|
|
} else {
|
|
|
|
GL_INS("ERROR: Source and Target are the same!");
|
|
|
|
}
|
2015-08-15 16:50:17 +00:00
|
|
|
}
|
2015-07-19 07:58:56 +00:00
|
|
|
|
2016-06-07 17:08:54 +00:00
|
|
|
EmulateTextureShuffleAndFbmask();
|
2015-05-26 13:36:48 +00:00
|
|
|
|
2015-07-21 17:07:24 +00:00
|
|
|
// DATE: selection of the algorithm. Must be done before blending because GL42 is not compatible with blending
|
|
|
|
|
2016-04-07 19:51:37 +00:00
|
|
|
if (DATE) {
|
2015-08-04 18:08:33 +00:00
|
|
|
if (m_prim_overlap == PRIM_OVERLAP_NO || m_texture_shuffle) {
|
|
|
|
// It is way too complex to emulate texture shuffle with DATE. So just use
|
|
|
|
// the slow but accurate algo
|
2016-06-07 16:42:58 +00:00
|
|
|
m_require_full_barrier = true;
|
2015-07-21 17:07:24 +00:00
|
|
|
DATE_GL45 = true;
|
|
|
|
DATE = false;
|
2016-10-05 07:41:28 +00:00
|
|
|
} else if (m_om_csel.wa && !m_context->TEST.ATE) {
|
2016-05-15 15:22:58 +00:00
|
|
|
// Performance note: check alpha range with GetAlphaMinMax()
|
|
|
|
// Note: all my dump are already above 120fps, but it seems to reduce GPU load
|
|
|
|
// with big upscaling
|
|
|
|
GetAlphaMinMax();
|
|
|
|
if (m_context->TEST.DATM && m_vt.m_alpha.max < 128) {
|
|
|
|
// Only first pixel (write 0) will pass (alpha is 1)
|
|
|
|
GL_PERF("Fast DATE with alpha %d-%d", m_vt.m_alpha.min, m_vt.m_alpha.max);
|
2016-05-15 15:44:40 +00:00
|
|
|
DATE_one = true;
|
2016-05-15 15:22:58 +00:00
|
|
|
} else if (!m_context->TEST.DATM && m_vt.m_alpha.min >= 128) {
|
|
|
|
// Only first pixel (write 1) will pass (alpha is 0)
|
|
|
|
GL_PERF("Fast DATE with alpha %d-%d", m_vt.m_alpha.min, m_vt.m_alpha.max);
|
2016-05-15 15:44:40 +00:00
|
|
|
DATE_one = true;
|
2016-05-15 15:22:58 +00:00
|
|
|
} else if ((m_vt.m_primclass == GS_SPRITE_CLASS && m_drawlist.size() < 50) || (m_index.tail < 100)) {
|
|
|
|
// texture barrier will split the draw call into n draw call. It is very efficient for
|
|
|
|
// few primitive draws. Otherwise it sucks.
|
|
|
|
GL_PERF("Slower DATE with alpha %d-%d", m_vt.m_alpha.min, m_vt.m_alpha.max);
|
2016-06-07 16:42:58 +00:00
|
|
|
m_require_full_barrier = true;
|
2015-07-21 17:07:24 +00:00
|
|
|
DATE_GL45 = true;
|
|
|
|
DATE = false;
|
2016-05-19 07:58:13 +00:00
|
|
|
} else if (m_accurate_date) {
|
2016-05-15 15:22:58 +00:00
|
|
|
GL_PERF("Slow DATE with alpha %d-%d", m_vt.m_alpha.min, m_vt.m_alpha.max);
|
|
|
|
|
2017-02-03 17:30:27 +00:00
|
|
|
if (GLLoader::found_GL_ARB_shader_image_load_store && GLLoader::found_GL_ARB_clear_texture) {
|
2016-05-15 14:29:29 +00:00
|
|
|
DATE_GL42 = true;
|
|
|
|
} else {
|
2016-06-07 16:42:58 +00:00
|
|
|
m_require_full_barrier = true;
|
2016-05-15 14:29:29 +00:00
|
|
|
DATE_GL45 = true;
|
|
|
|
DATE = false;
|
|
|
|
}
|
2015-07-21 17:07:24 +00:00
|
|
|
}
|
2016-10-05 07:41:28 +00:00
|
|
|
} else if (!m_om_csel.wa && !m_context->TEST.ATE) {
|
2016-05-23 17:23:04 +00:00
|
|
|
// TODO: is it legal ? Likely but it need to be tested carefully
|
|
|
|
// DATE_GL45 = true;
|
2016-06-07 16:42:58 +00:00
|
|
|
// m_require_one_barrier = true; << replace it with a cheap barrier
|
2016-05-23 17:23:04 +00:00
|
|
|
|
2015-07-21 17:07:24 +00:00
|
|
|
}
|
2016-05-23 17:23:04 +00:00
|
|
|
|
2016-05-15 15:44:40 +00:00
|
|
|
// Will save my life !
|
|
|
|
ASSERT(!(DATE_GL45 && DATE_one));
|
|
|
|
ASSERT(!(DATE_GL42 && DATE_one));
|
|
|
|
ASSERT(!(DATE_GL42 && DATE_GL45));
|
2015-07-21 17:07:24 +00:00
|
|
|
}
|
|
|
|
|
2015-04-19 16:22:20 +00:00
|
|
|
// Blend
|
2014-02-08 11:05:26 +00:00
|
|
|
|
2015-07-25 15:57:42 +00:00
|
|
|
if (!IsOpaque() && rt) {
|
2016-06-07 17:08:54 +00:00
|
|
|
EmulateBlending(DATE_GL42);
|
2015-07-31 18:28:54 +00:00
|
|
|
} else {
|
|
|
|
dev->OMSetBlendState(); // No blending please
|
2015-07-21 17:07:24 +00:00
|
|
|
}
|
2015-07-18 17:55:32 +00:00
|
|
|
|
2016-06-07 17:08:54 +00:00
|
|
|
if (m_ps_sel.dfmt == 1) {
|
2015-05-26 14:16:36 +00:00
|
|
|
// Disable writing of the alpha channel
|
2016-06-07 17:08:54 +00:00
|
|
|
m_om_csel.wa = 0;
|
2015-05-26 14:16:36 +00:00
|
|
|
}
|
2014-02-08 11:05:26 +00:00
|
|
|
|
2015-07-21 17:07:24 +00:00
|
|
|
// DATE (setup part)
|
2014-02-08 11:05:26 +00:00
|
|
|
|
2015-07-25 15:13:37 +00:00
|
|
|
if (DATE) {
|
2015-07-24 20:06:35 +00:00
|
|
|
GSVector4i dRect = ComputeBoundingBox(rtscale, rtsize);
|
2015-04-24 16:32:08 +00:00
|
|
|
|
|
|
|
// Reduce the quantity of clean function
|
2015-07-24 20:06:35 +00:00
|
|
|
glScissor( dRect.x, dRect.y, dRect.width(), dRect.height() );
|
|
|
|
GLState::scissor = dRect;
|
2015-04-24 16:32:08 +00:00
|
|
|
|
2015-04-24 18:13:38 +00:00
|
|
|
// Must be done here to avoid any GL state pertubation (clear function...)
|
|
|
|
// Create an r32ui image that will containt primitive ID
|
2015-04-24 18:53:59 +00:00
|
|
|
if (DATE_GL42) {
|
2016-05-15 13:54:29 +00:00
|
|
|
dev->InitPrimDateTexture(rt, dRect);
|
2016-05-15 15:44:40 +00:00
|
|
|
} else if (DATE_one) {
|
|
|
|
dev->ClearStencil(ds, 1);
|
2015-04-24 18:13:38 +00:00
|
|
|
} else {
|
2015-07-24 20:06:35 +00:00
|
|
|
GSVector4 src = GSVector4(dRect) / GSVector4(rtsize.x, rtsize.y).xyxy();
|
|
|
|
GSVector4 dst = src * 2.0f - 1.0f;
|
2012-01-15 17:25:49 +00:00
|
|
|
|
2014-10-01 19:46:20 +00:00
|
|
|
GSVertexPT1 vertices[] =
|
2012-01-15 17:25:49 +00:00
|
|
|
{
|
2014-10-01 19:46:20 +00:00
|
|
|
{GSVector4(dst.x, dst.y, 0.0f, 0.0f), GSVector2(src.x, src.y)},
|
|
|
|
{GSVector4(dst.z, dst.y, 0.0f, 0.0f), GSVector2(src.z, src.y)},
|
|
|
|
{GSVector4(dst.x, dst.w, 0.0f, 0.0f), GSVector2(src.x, src.w)},
|
|
|
|
{GSVector4(dst.z, dst.w, 0.0f, 0.0f), GSVector2(src.z, src.w)},
|
2012-01-15 17:25:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
dev->SetupDATE(rt, ds, vertices, m_context->TEST.DATM);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
dev->BeginScene();
|
|
|
|
|
|
|
|
// om
|
|
|
|
|
2016-08-11 19:14:58 +00:00
|
|
|
EmulateZbuffer(); // will update VS depth mask
|
2012-01-15 17:25:49 +00:00
|
|
|
|
2015-04-19 16:22:20 +00:00
|
|
|
// vs
|
2012-01-15 17:25:49 +00:00
|
|
|
|
|
|
|
// FIXME Opengl support half pixel center (as dx10). Code could be easier!!!
|
|
|
|
float sx = 2.0f * rtscale.x / (rtsize.x << 4);
|
|
|
|
float sy = 2.0f * rtscale.y / (rtsize.y << 4);
|
2015-07-25 14:26:53 +00:00
|
|
|
float ox = (float)(int)m_context->XYOFFSET.OFX;
|
|
|
|
float oy = (float)(int)m_context->XYOFFSET.OFY;
|
2013-06-26 20:09:07 +00:00
|
|
|
float ox2 = -1.0f / rtsize.x;
|
|
|
|
float oy2 = -1.0f / rtsize.y;
|
2012-01-15 17:25:49 +00:00
|
|
|
|
|
|
|
//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.
|
|
|
|
|
2017-02-26 15:09:55 +00:00
|
|
|
if (rt && rt->LikelyOffset && UserHacks_HPO == 1)
|
2012-01-15 17:25:49 +00:00
|
|
|
{
|
|
|
|
ox2 *= rt->OffsetHack_modx;
|
|
|
|
oy2 *= rt->OffsetHack_mody;
|
|
|
|
}
|
|
|
|
|
2013-06-26 20:09:07 +00:00
|
|
|
// Note: DX does y *= -1.0
|
|
|
|
vs_cb.Vertex_Scale_Offset = GSVector4(sx, sy, ox * sx + ox2 + 1, oy * sy + oy2 + 1);
|
2012-01-15 17:25:49 +00:00
|
|
|
// END of FIXME
|
|
|
|
|
2013-08-14 10:18:38 +00:00
|
|
|
// GS_SPRITE_CLASS are already flat (either by CPU or the GS)
|
2016-06-07 17:08:54 +00:00
|
|
|
m_ps_sel.iip = (m_vt.m_primclass == GS_SPRITE_CLASS) ? 1 : PRIM->IIP;
|
2013-08-14 10:18:38 +00:00
|
|
|
|
2015-04-24 18:53:59 +00:00
|
|
|
if (DATE_GL45) {
|
2016-06-07 17:08:54 +00:00
|
|
|
m_ps_sel.date = 5 + m_context->TEST.DATM;
|
2016-05-15 15:44:40 +00:00
|
|
|
} else if (DATE_one) {
|
2016-06-07 16:42:58 +00:00
|
|
|
m_require_one_barrier = true;
|
2016-06-07 17:08:54 +00:00
|
|
|
m_ps_sel.date = 5 + m_context->TEST.DATM;
|
|
|
|
m_om_dssel.date = 1;
|
|
|
|
m_om_dssel.date_one = 1;
|
2015-05-19 22:51:37 +00:00
|
|
|
} else if (DATE) {
|
2015-04-24 18:53:59 +00:00
|
|
|
if (DATE_GL42)
|
2016-06-07 17:08:54 +00:00
|
|
|
m_ps_sel.date = 1 + m_context->TEST.DATM;
|
2015-04-21 22:36:34 +00:00
|
|
|
else
|
2016-06-07 17:08:54 +00:00
|
|
|
m_om_dssel.date = 1;
|
2012-01-15 17:25:49 +00:00
|
|
|
}
|
|
|
|
|
2016-06-07 17:08:54 +00:00
|
|
|
m_ps_sel.fba = m_context->FBA.FBA;
|
2015-07-03 19:21:56 +00:00
|
|
|
|
2015-05-19 22:51:37 +00:00
|
|
|
if (PRIM->FGE)
|
2012-01-15 17:25:49 +00:00
|
|
|
{
|
2016-06-07 17:08:54 +00:00
|
|
|
m_ps_sel.fog = 1;
|
2012-01-15 17:25:49 +00:00
|
|
|
|
2015-08-14 21:53:01 +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);
|
|
|
|
#else
|
|
|
|
ps_cb.FogColor_AREF = fc;
|
|
|
|
#endif
|
2012-01-15 17:25:49 +00:00
|
|
|
}
|
|
|
|
|
2016-08-11 19:15:17 +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-27 12:46:10 +00:00
|
|
|
bool ate_RGBA_then_Z = false;
|
|
|
|
bool ate_RGB_then_ZA = false;
|
|
|
|
if (ate_first_pass & ate_second_pass) {
|
2016-10-14 18:24:52 +00:00
|
|
|
GL_DBG("Complex Alpha Test");
|
2016-09-18 15:24:33 +00:00
|
|
|
bool commutative_depth = (m_om_dssel.ztst == ZTST_GEQUAL && m_vt.m_eq.z) || (m_om_dssel.ztst == ZTST_ALWAYS);
|
2016-08-27 12:46:10 +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;
|
|
|
|
}
|
2016-08-15 09:20:38 +00:00
|
|
|
|
2016-09-19 06:48:32 +00:00
|
|
|
if (ate_RGBA_then_Z) {
|
2016-10-14 18:24:52 +00:00
|
|
|
GL_DBG("Alternate ATE handling: ate_RGBA_then_Z");
|
2016-08-11 19:15:17 +00:00
|
|
|
// Render all color but don't update depth
|
|
|
|
// ATE is disabled here
|
|
|
|
m_om_dssel.zwe = false;
|
2016-08-27 12:46:10 +00:00
|
|
|
} else if (ate_RGB_then_ZA) {
|
2016-10-14 18:24:52 +00:00
|
|
|
GL_DBG("Alternate ATE handling: ate_RGB_then_ZA");
|
2016-08-27 12:46:10 +00:00
|
|
|
// Render RGB color but don't update depth/alpha
|
|
|
|
// ATE is disabled here
|
|
|
|
m_om_dssel.zwe = false;
|
|
|
|
m_om_csel.wa = false;
|
2016-08-11 19:15:17 +00:00
|
|
|
} else {
|
|
|
|
EmulateAtst(1, tex);
|
|
|
|
}
|
2013-08-10 19:43:59 +00:00
|
|
|
|
2016-06-07 16:12:57 +00:00
|
|
|
if (tex) {
|
2016-06-07 17:08:54 +00:00
|
|
|
EmulateTextureSampler(tex);
|
2016-06-10 19:16:39 +00:00
|
|
|
} else {
|
|
|
|
m_ps_sel.tfx = 4;
|
2013-08-10 19:43:59 +00:00
|
|
|
}
|
2016-06-10 19:16:39 +00:00
|
|
|
|
2015-07-25 15:01:00 +00:00
|
|
|
// Always bind the RT. This way special effect can use it.
|
|
|
|
dev->PSSetShaderResource(3, rt);
|
|
|
|
|
2017-03-12 16:26:20 +00:00
|
|
|
if (m_game.title == CRC::ICO) {
|
|
|
|
GSVertex* v = &m_vertex.buff[0];
|
|
|
|
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 && // at display resolution 512x448
|
|
|
|
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
|
|
|
|
|
|
|
|
// Depth buffer was moved so GSdx will invalide it which means a
|
|
|
|
// downscale. ICO uses the MSB depth bits as the texture alpha
|
|
|
|
// channel. However this depth of field effect requires
|
|
|
|
// texel:pixel mapping accuraccy.
|
|
|
|
//
|
|
|
|
// Use an HLE shader to sample depth directly as the alpha channel
|
|
|
|
GL_INS("ICO sample depth as alpha");
|
|
|
|
m_require_full_barrier = true;
|
|
|
|
// Extract the depth as palette index
|
|
|
|
m_ps_sel.depth_fmt = 1;
|
|
|
|
m_ps_sel.channel = 3;
|
|
|
|
dev->PSSetShaderResource(4, ds);
|
|
|
|
|
|
|
|
// We need the palette to convert the depth to the correct alpha value.
|
|
|
|
if (!tex->m_palette) {
|
|
|
|
tex->m_palette = m_dev->CreateTexture(256, 1);
|
|
|
|
|
|
|
|
const uint32* clut = m_mem.m_clut;
|
|
|
|
int pal = GSLocalMemory::m_psm[tex->m_TEX0.PSM].pal;
|
|
|
|
tex->m_palette->Update(GSVector4i(0, 0, pal, 1), clut, pal * sizeof(clut[0]));
|
|
|
|
tex->m_initpalette = false;
|
|
|
|
|
|
|
|
dev->PSSetShaderResource(1, tex->m_palette);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-15 17:25:49 +00:00
|
|
|
// rs
|
2016-04-28 20:52:22 +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-15 17:25:49 +00:00
|
|
|
|
2016-08-31 07:22:35 +00:00
|
|
|
SetupIA(sx, sy);
|
2012-02-11 10:22:02 +00:00
|
|
|
|
2016-06-07 17:08:54 +00:00
|
|
|
dev->OMSetColorMaskState(m_om_csel);
|
|
|
|
dev->SetupOM(m_om_dssel);
|
2015-05-09 13:02:13 +00:00
|
|
|
|
2015-05-06 06:44:27 +00:00
|
|
|
dev->SetupCB(&vs_cb, &ps_cb);
|
2012-01-15 17:25:49 +00:00
|
|
|
|
2016-08-31 07:22:35 +00:00
|
|
|
dev->SetupPipeline(m_vs_sel, m_gs_sel, m_ps_sel);
|
|
|
|
|
2015-04-24 18:53:59 +00:00
|
|
|
if (DATE_GL42) {
|
2015-05-06 16:52:51 +00:00
|
|
|
GL_PUSH("Date GL42");
|
2015-05-06 06:34:45 +00:00
|
|
|
// It could be good idea to use stencil in the same time.
|
|
|
|
// Early stencil test will reduce the number of atomic-load operation
|
|
|
|
|
2013-08-28 08:44:16 +00:00
|
|
|
// Create an r32i image that will contain primitive ID
|
|
|
|
// Note: do it at the beginning because the clean will dirty the FBO state
|
2013-07-28 14:40:43 +00:00
|
|
|
//dev->InitPrimDateTexture(rtsize.x, rtsize.y);
|
|
|
|
|
2015-04-24 18:13:38 +00:00
|
|
|
// I don't know how much is it legal to mount rt as Texture/RT. No write is done.
|
|
|
|
// In doubt let's detach RT.
|
|
|
|
dev->OMSetRenderTargets(NULL, ds, &scissor);
|
|
|
|
|
2013-07-28 14:40:43 +00:00
|
|
|
// Don't write anything on the color buffer
|
2015-07-02 19:06:40 +00:00
|
|
|
// Neither in the depth buffer
|
|
|
|
glDepthMask(false);
|
2016-06-07 16:42:58 +00:00
|
|
|
// Compute primitiveID max that pass the date test (Draw without barrier)
|
|
|
|
dev->DrawIndexedPrimitive();
|
2013-07-28 14:40:43 +00:00
|
|
|
|
|
|
|
// Ask PS to discard shader above the primitiveID max
|
2015-07-02 19:06:40 +00:00
|
|
|
glDepthMask(GLState::depth_mask);
|
2013-07-28 14:40:43 +00:00
|
|
|
|
2016-06-07 17:08:54 +00:00
|
|
|
m_ps_sel.date = 3;
|
|
|
|
dev->SetupPipeline(m_vs_sel, m_gs_sel, m_ps_sel);
|
2013-07-28 14:40:43 +00:00
|
|
|
|
|
|
|
// Be sure that first pass is finished !
|
2015-06-16 07:57:45 +00:00
|
|
|
dev->Barrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);
|
2013-07-28 14:40:43 +00:00
|
|
|
}
|
2012-01-15 17:25:49 +00:00
|
|
|
|
2016-06-07 17:08:54 +00:00
|
|
|
if (m_ps_sel.hdr) {
|
2015-08-03 16:58:38 +00:00
|
|
|
hdr_rt = dev->CreateTexture(rtsize.x, rtsize.y, GL_RGBA32F);
|
2012-01-15 17:25:49 +00:00
|
|
|
|
2015-07-24 20:06:35 +00:00
|
|
|
dev->CopyRectConv(rt, hdr_rt, ComputeBoundingBox(rtscale, rtsize), false);
|
2012-01-15 17:25:49 +00:00
|
|
|
|
2015-07-24 20:06:35 +00:00
|
|
|
dev->OMSetRenderTargets(hdr_rt, ds, &scissor);
|
|
|
|
} else {
|
|
|
|
dev->OMSetRenderTargets(rt, ds, &scissor);
|
|
|
|
}
|
2012-01-15 17:25:49 +00:00
|
|
|
|
2016-08-11 19:15:17 +00:00
|
|
|
if (ate_first_pass)
|
2012-01-15 17:25:49 +00:00
|
|
|
{
|
2016-06-07 16:42:58 +00:00
|
|
|
SendDraw();
|
2012-01-15 17:25:49 +00:00
|
|
|
}
|
|
|
|
|
2016-08-11 19:15:17 +00:00
|
|
|
if (ate_second_pass)
|
2012-01-15 17:25:49 +00:00
|
|
|
{
|
2015-07-25 14:26:53 +00:00
|
|
|
ASSERT(!m_env.PABE.PABE);
|
2012-01-15 17:25:49 +00:00
|
|
|
|
2016-08-27 12:46:10 +00:00
|
|
|
if (ate_RGBA_then_Z | ate_RGB_then_ZA) {
|
2016-08-11 19:15:17 +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-15 17:25:49 +00:00
|
|
|
|
2016-06-10 23:08:50 +00:00
|
|
|
// Potentially AREF was updated (hope perf impact will be limited)
|
|
|
|
dev->SetupCB(&vs_cb, &ps_cb);
|
|
|
|
|
2016-06-07 17:08:54 +00:00
|
|
|
dev->SetupPipeline(m_vs_sel, m_gs_sel, m_ps_sel);
|
2012-01-15 17:25:49 +00:00
|
|
|
|
2016-06-07 17:08:54 +00:00
|
|
|
bool z = m_om_dssel.zwe;
|
|
|
|
bool r = m_om_csel.wr;
|
|
|
|
bool g = m_om_csel.wg;
|
|
|
|
bool b = m_om_csel.wb;
|
|
|
|
bool a = m_om_csel.wa;
|
2012-01-15 17:25:49 +00:00
|
|
|
|
2015-07-25 14:26:53 +00:00
|
|
|
switch(m_context->TEST.AFAIL)
|
2012-01-15 17:25:49 +00:00
|
|
|
{
|
2013-08-10 19:43:59 +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
|
|
|
|
default: __assume(0);
|
2012-01-15 17:25:49 +00:00
|
|
|
}
|
|
|
|
|
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-27 12:46:10 +00:00
|
|
|
if (ate_RGBA_then_Z) {
|
2016-09-19 06:56:49 +00:00
|
|
|
z = !m_context->ZBUF.ZMSK;
|
2016-08-11 19:15:17 +00:00
|
|
|
r = g = b = a = false;
|
2016-08-27 12:46:10 +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-27 12:46:10 +00:00
|
|
|
r = g = b = false;
|
2016-08-11 19:15:17 +00:00
|
|
|
}
|
|
|
|
|
2015-05-19 22:51:37 +00:00
|
|
|
if (z || r || g || b || a)
|
2012-01-15 17:25:49 +00:00
|
|
|
{
|
2016-06-07 17:08:54 +00:00
|
|
|
m_om_dssel.zwe = z;
|
|
|
|
m_om_csel.wr = r;
|
|
|
|
m_om_csel.wg = g;
|
|
|
|
m_om_csel.wb = b;
|
|
|
|
m_om_csel.wa = a;
|
|
|
|
|
|
|
|
dev->OMSetColorMaskState(m_om_csel);
|
|
|
|
dev->SetupOM(m_om_dssel);
|
2012-01-15 17:25:49 +00:00
|
|
|
|
2016-06-07 16:42:58 +00:00
|
|
|
SendDraw();
|
2012-01-15 17:25:49 +00:00
|
|
|
}
|
|
|
|
}
|
2015-07-24 20:06:35 +00:00
|
|
|
|
|
|
|
if (DATE_GL42) {
|
2013-07-28 14:40:43 +00:00
|
|
|
dev->RecycleDateTexture();
|
2015-07-24 20:06:35 +00:00
|
|
|
}
|
2012-01-15 17:25:49 +00:00
|
|
|
|
|
|
|
dev->EndScene();
|
|
|
|
|
2015-07-24 20:06:35 +00:00
|
|
|
// Warning: EndScene must be called before StretchRect otherwise
|
|
|
|
// vertices will be overwritten. Trust me you don't want to do that.
|
|
|
|
if (hdr_rt) {
|
|
|
|
GSVector4 dRect(ComputeBoundingBox(rtscale, rtsize));
|
|
|
|
GSVector4 sRect = dRect / GSVector4(rtsize.x, rtsize.y).xyxy();
|
2015-09-08 14:36:23 +00:00
|
|
|
dev->StretchRect(hdr_rt, sRect, rt, dRect, ShaderConvert_MOD_256, false);
|
2015-07-24 20:06:35 +00:00
|
|
|
|
|
|
|
dev->Recycle(hdr_rt);
|
|
|
|
}
|
2012-01-15 17:25:49 +00:00
|
|
|
}
|