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
|
|
|
{
|
2015-05-08 08:40:43 +00:00
|
|
|
m_accurate_date = theApp.GetConfig("accurate_date", 0);
|
2015-07-19 07:34:32 +00:00
|
|
|
|
|
|
|
m_sw_blending = theApp.GetConfig("accurate_blending_unit", 1);
|
2015-05-08 08:40:43 +00:00
|
|
|
|
|
|
|
UserHacks_TCOffset = theApp.GetConfig("UserHacks_TCOffset", 0);
|
|
|
|
UserHacks_TCO_x = (UserHacks_TCOffset & 0xFFFF) / -1000.0f;
|
|
|
|
UserHacks_TCO_y = ((UserHacks_TCOffset >> 16) & 0xFFFF) / -1000.0f;
|
|
|
|
|
2015-09-11 10:19:49 +00:00
|
|
|
m_prim_overlap = PRIM_OVERLAP_UNKNOW;
|
|
|
|
|
2015-05-08 08:40:43 +00:00
|
|
|
if (!theApp.GetConfig("UserHacks", 0)) {
|
|
|
|
UserHacks_TCOffset = 0;
|
|
|
|
UserHacks_TCO_x = 0;
|
|
|
|
UserHacks_TCO_y = 0;
|
|
|
|
}
|
2011-11-16 22:17:37 +00:00
|
|
|
}
|
|
|
|
|
2011-12-19 21:03:23 +00:00
|
|
|
bool GSRendererOGL::CreateDevice(GSDevice* dev)
|
|
|
|
{
|
2015-05-19 22:51:37 +00:00
|
|
|
if (!GSRenderer::CreateDevice(dev))
|
2011-12-19 21:03:23 +00:00
|
|
|
return false;
|
2011-11-16 22:17:37 +00:00
|
|
|
|
2015-08-22 10:21:37 +00:00
|
|
|
// No sw blending if not supported (Intel GPU)
|
|
|
|
if (!GLLoader::found_GL_ARB_texture_barrier) {
|
|
|
|
fprintf(stderr, "Error GL_ARB_texture_barrier is not supported by your driver. You can't emulate correctly the GS blending unit! Sorry!\n");
|
|
|
|
m_accurate_date = false;
|
|
|
|
m_sw_blending = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-19 21:03:23 +00:00
|
|
|
return true;
|
|
|
|
}
|
2011-11-16 22:17:37 +00:00
|
|
|
|
2013-05-27 16:53:38 +00:00
|
|
|
void GSRendererOGL::EmulateGS()
|
|
|
|
{
|
2013-08-14 10:18:38 +00:00
|
|
|
if (m_vt.m_primclass != GS_SPRITE_CLASS) return;
|
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
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-11 10:22:02 +00:00
|
|
|
void GSRendererOGL::SetupIA()
|
2012-01-15 17:25:49 +00:00
|
|
|
{
|
2012-02-11 10:22:02 +00:00
|
|
|
GSDeviceOGL* dev = (GSDeviceOGL*)m_dev;
|
2012-01-15 17:25:49 +00:00
|
|
|
|
2013-05-27 16:53:38 +00:00
|
|
|
if (!GLLoader::found_geometry_shader)
|
|
|
|
EmulateGS();
|
|
|
|
|
2015-04-13 16:34:43 +00:00
|
|
|
dev->IASetVertexBuffer(m_vertex.buff, m_vertex.next);
|
2012-02-11 10:22:02 +00:00
|
|
|
dev->IASetIndexBuffer(m_index.buff, m_index.tail);
|
2012-01-15 17:25:49 +00:00
|
|
|
|
2013-06-28 10:43:50 +00:00
|
|
|
GLenum t = 0;
|
2012-02-11 10:22:02 +00:00
|
|
|
|
|
|
|
switch(m_vt.m_primclass)
|
2012-01-15 17:25:49 +00:00
|
|
|
{
|
|
|
|
case GS_POINT_CLASS:
|
2012-02-11 10:22:02 +00:00
|
|
|
t = GL_POINTS;
|
2012-01-15 17:25:49 +00:00
|
|
|
break;
|
|
|
|
case GS_LINE_CLASS:
|
2012-02-11 10:22:02 +00:00
|
|
|
t = GL_LINES;
|
2012-01-15 17:25:49 +00:00
|
|
|
break;
|
2013-05-27 16:53:38 +00:00
|
|
|
case GS_SPRITE_CLASS:
|
|
|
|
if (GLLoader::found_geometry_shader)
|
|
|
|
t = GL_LINES;
|
|
|
|
else
|
|
|
|
t = GL_TRIANGLES;
|
|
|
|
break;
|
2012-01-15 17:25:49 +00:00
|
|
|
case GS_TRIANGLE_CLASS:
|
2012-02-11 10:22:02 +00:00
|
|
|
t = GL_TRIANGLES;
|
2012-01-15 17:25:49 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
__assume(0);
|
|
|
|
}
|
|
|
|
|
2012-02-11 10:22:02 +00:00
|
|
|
dev->IASetPrimitiveTopology(t);
|
|
|
|
}
|
|
|
|
|
2015-08-07 07:44:42 +00:00
|
|
|
bool GSRendererOGL::EmulateTextureShuffleAndFbmask(GSDeviceOGL::PSSelector& ps_sel, GSDeviceOGL::OMColorMaskSelector& om_csel)
|
2015-04-24 18:53:59 +00:00
|
|
|
{
|
2015-07-19 07:58:56 +00:00
|
|
|
bool require_barrier = false;
|
2015-07-11 11:48:50 +00:00
|
|
|
|
2015-06-17 18:02:03 +00:00
|
|
|
if (m_texture_shuffle) {
|
2015-06-06 11:56:08 +00:00
|
|
|
ps_sel.shuffle = 1;
|
|
|
|
ps_sel.dfmt = 0;
|
|
|
|
|
|
|
|
const GIFRegXYOFFSET& o = m_context->XYOFFSET;
|
|
|
|
GSVertex* v = &m_vertex.buff[0];
|
|
|
|
size_t count = m_vertex.next;
|
|
|
|
|
|
|
|
// vertex position is 8 to 16 pixels, therefore it is the 16-31 bits of the colors
|
|
|
|
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);
|
2015-06-29 19:41:36 +00:00
|
|
|
int tex_pos = (PRIM->FST) ? v[0].U : tw * v[0].ST.S;
|
|
|
|
tex_pos &= 0xFF;
|
2015-06-06 11:56:08 +00:00
|
|
|
ps_sel.read_ba = (tex_pos > 112 && tex_pos < 144);
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
if (ps_sel.read_ba)
|
|
|
|
v[i].U -= 128u;
|
|
|
|
else
|
|
|
|
v[i+1].U += 128u;
|
|
|
|
|
|
|
|
// Height is too big (2x).
|
|
|
|
int tex_offset = v[i].V & 0xF;
|
|
|
|
GSVector4i offset(o.OFY, tex_offset, o.OFY, tex_offset);
|
|
|
|
|
|
|
|
GSVector4i tmp(v[i].XYZ.Y, v[i].V, v[i+1].XYZ.Y, v[i+1].V);
|
|
|
|
tmp = GSVector4i(tmp - offset).srl32(1) + offset;
|
|
|
|
|
|
|
|
v[i].XYZ.Y = tmp.x;
|
|
|
|
v[i].V = tmp.y;
|
|
|
|
v[i+1].XYZ.Y = tmp.z;
|
|
|
|
v[i+1].V = tmp.w;
|
|
|
|
}
|
|
|
|
} 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;
|
|
|
|
|
|
|
|
if (ps_sel.read_ba)
|
|
|
|
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);
|
|
|
|
v[i].XYZ.Y = tmp.x;
|
|
|
|
v[i].ST.T /= 2.0f;
|
|
|
|
v[i+1].XYZ.Y = tmp.y;
|
|
|
|
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.
|
|
|
|
ps_sel.write_rg = !write_ba && m_context->TEST.DATE;
|
|
|
|
|
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;
|
2015-06-06 11:56:08 +00:00
|
|
|
om_csel.wrgba = 0;
|
|
|
|
|
|
|
|
// 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) {
|
|
|
|
GL_INS("Color shuffle %s => B", ps_sel.read_ba ? "B" : "R");
|
|
|
|
om_csel.wb = 1;
|
|
|
|
} else {
|
|
|
|
GL_INS("Color shuffle %s => R", ps_sel.read_ba ? "B" : "R");
|
|
|
|
om_csel.wr = 1;
|
|
|
|
}
|
2015-06-21 06:47:45 +00:00
|
|
|
if (rg_mask)
|
|
|
|
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) {
|
|
|
|
GL_INS("Color shuffle %s => A", ps_sel.read_ba ? "A" : "G");
|
|
|
|
om_csel.wa = 1;
|
|
|
|
} else {
|
|
|
|
GL_INS("Color shuffle %s => G", ps_sel.read_ba ? "A" : "G");
|
|
|
|
om_csel.wg = 1;
|
|
|
|
}
|
2015-06-21 06:47:45 +00:00
|
|
|
if (ba_mask)
|
|
|
|
ps_sel.fbmask = 1;
|
|
|
|
}
|
|
|
|
|
2015-07-31 17:43:06 +00:00
|
|
|
if (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;
|
|
|
|
require_barrier = true;
|
2015-07-31 17:43:06 +00:00
|
|
|
} else {
|
|
|
|
ps_sel.fbmask = 0;
|
2015-06-06 11:56:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2015-07-19 07:58:56 +00:00
|
|
|
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
|
|
|
|
2015-08-05 20:12:54 +00:00
|
|
|
om_csel.wrgba = ~ff_fbmask; // Enable channel if at least 1 bit is 0
|
2015-06-21 06:47:45 +00:00
|
|
|
|
2015-08-05 20:12:54 +00:00
|
|
|
ps_sel.fbmask = m_sw_blending && (~ff_fbmask & ~zero_fbmask & 0xF);
|
|
|
|
|
|
|
|
if (ps_sel.fbmask) {
|
|
|
|
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);
|
|
|
|
ps_cb.FbMask = fbmask_v.u8to32();
|
|
|
|
require_barrier = true;
|
2015-06-06 11:56:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-19 07:58:56 +00:00
|
|
|
return require_barrier;
|
|
|
|
}
|
2015-05-26 12:59:07 +00:00
|
|
|
|
2015-08-07 07:44:42 +00:00
|
|
|
bool GSRendererOGL::EmulateBlending(GSDeviceOGL::PSSelector& ps_sel, 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-07-31 18:28:54 +00:00
|
|
|
bool require_barrier = false;
|
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();
|
|
|
|
return false;
|
|
|
|
}
|
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) {
|
|
|
|
ps_sel.pabe = 1;
|
|
|
|
require_barrier |= (ALPHA.C == 1);
|
|
|
|
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
|
2015-08-07 17:43:42 +00:00
|
|
|
uint8 blend_index = ((ALPHA.A * 3 + ALPHA.B) * 3 + ALPHA.C) * 3 + ALPHA.D;
|
|
|
|
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.
|
2015-08-07 10:06:45 +00:00
|
|
|
bool impossible_or_free_blend = (blend_flag & (BLEND_NO_BAR|BLEND_A_MAX|BLEND_ACCU))
|
|
|
|
|| (m_prim_overlap == PRIM_OVERLAP_NO);
|
|
|
|
|
2015-07-25 15:57:42 +00:00
|
|
|
// Do the multiplication in shader for blending accumulation: Cs*As + Cd or Cs*Af + Cd
|
2015-07-30 20:05:08 +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);
|
|
|
|
case ACC_BLEND_SPRITE: sw_blending |= m_vt.m_primclass == GS_SPRITE_CLASS;
|
|
|
|
case ACC_BLEND_FREE: sw_blending |= ps_sel.fbmask || impossible_or_free_blend;
|
|
|
|
default: sw_blending |= accumulation_blend;
|
|
|
|
}
|
|
|
|
// 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");
|
|
|
|
ps_sel.colclip = 1;
|
2015-10-16 20:06:34 +00:00
|
|
|
ASSERT(sw_blending);
|
|
|
|
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");
|
2015-08-16 16:12:34 +00:00
|
|
|
ps_sel.hdr = 1;
|
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);
|
2015-08-16 16:12:34 +00:00
|
|
|
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
|
2015-07-30 20:05:08 +00:00
|
|
|
ASSERT(!(ps_sel.hdr && DATE_GL42));
|
2015-07-25 16:20:00 +00:00
|
|
|
ASSERT(!(ps_sel.fbmask && DATE_GL42));
|
2015-07-25 15:57:42 +00:00
|
|
|
|
|
|
|
// For stat to optimize accurate option
|
|
|
|
#if 0
|
|
|
|
GL_INS("BLEND_INFO: %d/%d/%d/%d. Clamp:%d. Prim:%d number %d (sw %d)",
|
2015-08-07 10:06:45 +00:00
|
|
|
ALPHA.A, ALPHA.B, ALPHA.C, ALPHA.D, m_env.COLCLAMP.CLAMP, m_vt.m_primclass, m_vertex.next, sw_blending);
|
2015-07-25 15:57:42 +00:00
|
|
|
#endif
|
|
|
|
if (sw_blending) {
|
2015-08-07 10:06:45 +00:00
|
|
|
ps_sel.blend_a = ALPHA.A;
|
|
|
|
ps_sel.blend_b = ALPHA.B;
|
|
|
|
ps_sel.blend_c = ALPHA.C;
|
|
|
|
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
|
2015-08-07 10:06:45 +00:00
|
|
|
dev->OMSetBlendState(blend_index);
|
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
|
|
|
|
ps_sel.blend_a = ALPHA.B;
|
|
|
|
ps_sel.blend_b = 2;
|
|
|
|
}
|
2015-08-16 16:12:34 +00:00
|
|
|
// Remove the addition/substraction from the SW blending
|
2015-07-30 20:05:08 +00:00
|
|
|
ps_sel.blend_d = 2;
|
|
|
|
} else {
|
|
|
|
// Disable HW blending
|
2015-07-31 18:28:54 +00:00
|
|
|
dev->OMSetBlendState();
|
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) {
|
2015-08-07 10:13:50 +00:00
|
|
|
ps_cb.AlphaCoeff.a = (float)ALPHA.FIX / 128.0f;
|
2015-07-25 15:57:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// No need to flush for every primitive
|
2015-07-31 07:09:44 +00:00
|
|
|
require_barrier |= !(blend_flag & BLEND_NO_BAR) && !accumulation_blend;
|
2015-07-25 15:57:42 +00:00
|
|
|
} else {
|
2015-08-15 18:05:09 +00:00
|
|
|
ps_sel.clr1 = !!(blend_flag & BLEND_C_CLR);
|
2015-07-25 15:57:42 +00:00
|
|
|
if (ps_sel.dfmt == 1 && ALPHA.C == 1) {
|
|
|
|
// 24 bits doesn't have an alpha channel so use 1.0f fix factor as equivalent
|
2015-08-07 10:06:45 +00:00
|
|
|
int 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return require_barrier;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
GSVertex* v = &m_vertex.buff[0];
|
|
|
|
|
2015-08-05 15:59:55 +00:00
|
|
|
// In order to speed up comparaison a boundind-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.
|
2015-10-21 22:46:31 +00:00
|
|
|
GSVector4i all;
|
|
|
|
//FIXME better vector operation
|
|
|
|
if (v[1].XYZ.Y < v[0].XYZ.Y) {
|
|
|
|
all.y = v[1].XYZ.Y;
|
|
|
|
all.w = v[0].XYZ.Y;
|
|
|
|
} else {
|
|
|
|
all.y = v[0].XYZ.Y;
|
|
|
|
all.w = v[1].XYZ.Y;
|
|
|
|
}
|
|
|
|
if (v[1].XYZ.X < v[0].XYZ.X) {
|
|
|
|
all.x = v[1].XYZ.X;
|
|
|
|
all.z = v[0].XYZ.X;
|
|
|
|
} else {
|
|
|
|
all.x = v[0].XYZ.X;
|
|
|
|
all.z = v[1].XYZ.X;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(size_t i = 2; i < count; i += 2) {
|
2015-08-05 15:59:55 +00:00
|
|
|
GSVector4i sprite;
|
2015-10-21 22:46:31 +00:00
|
|
|
//FIXME better vector operation
|
|
|
|
if (v[i+1].XYZ.Y < v[i+0].XYZ.Y) {
|
|
|
|
sprite.y = v[i+1].XYZ.Y;
|
|
|
|
sprite.w = v[i+0].XYZ.Y;
|
2015-08-05 15:59:55 +00:00
|
|
|
} else {
|
2015-10-21 22:46:31 +00:00
|
|
|
sprite.y = v[i+0].XYZ.Y;
|
|
|
|
sprite.w = v[i+1].XYZ.Y;
|
2015-08-05 15:59:55 +00:00
|
|
|
}
|
2015-10-21 22:46:31 +00:00
|
|
|
if (v[i+1].XYZ.X < v[i+0].XYZ.X) {
|
|
|
|
sprite.x = v[i+1].XYZ.X;
|
|
|
|
sprite.z = v[i+0].XYZ.X;
|
|
|
|
} else {
|
|
|
|
sprite.x = v[i+0].XYZ.X;
|
|
|
|
sprite.z = v[i+1].XYZ.X;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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-08-05 15:59:55 +00:00
|
|
|
if (all.rintersect(sprite).rempty()) {
|
|
|
|
all = all.runion(sprite);
|
|
|
|
} else {
|
|
|
|
return PRIM_OVERLAP_YES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#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);
|
2015-07-19 07:58:56 +00:00
|
|
|
return PRIM_OVERLAP_NO;
|
|
|
|
}
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2015-07-19 07:58:56 +00:00
|
|
|
void GSRendererOGL::SendDraw(bool require_barrier)
|
|
|
|
{
|
|
|
|
GSDeviceOGL* dev = (GSDeviceOGL*)m_dev;
|
|
|
|
|
2015-07-25 15:10:45 +00:00
|
|
|
if (!require_barrier) {
|
|
|
|
dev->DrawIndexedPrimitive();
|
|
|
|
} else if (m_prim_overlap == PRIM_OVERLAP_NO) {
|
|
|
|
ASSERT(GLLoader::found_GL_ARB_texture_barrier);
|
2015-10-17 15:05:15 +00:00
|
|
|
glTextureBarrier();
|
2015-07-19 07:58:56 +00:00
|
|
|
dev->DrawIndexedPrimitive();
|
|
|
|
} 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)
|
2015-07-19 16:22:00 +00:00
|
|
|
size_t nb_vertex;
|
|
|
|
switch (m_vt.m_primclass) {
|
|
|
|
case GS_TRIANGLE_CLASS: nb_vertex = 3; break;
|
2015-08-01 11:26:15 +00:00
|
|
|
case GS_POINT_CLASS: nb_vertex = 1; break;
|
|
|
|
case GS_SPRITE_CLASS: nb_vertex = (GLLoader::found_geometry_shader) ? 2 : 6; break;
|
2015-07-19 16:22:00 +00:00
|
|
|
default: nb_vertex = 2; break;
|
|
|
|
}
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
GL_POP();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GSRendererOGL::DrawPrims(GSTexture* rt, GSTexture* ds, GSTextureCache::Source* tex)
|
|
|
|
{
|
2015-08-22 10:21:37 +00:00
|
|
|
GSDeviceOGL::VSSelector vs_sel;
|
|
|
|
GSDeviceOGL::GSSelector gs_sel;
|
|
|
|
|
|
|
|
GSDeviceOGL::PSSelector ps_sel;
|
|
|
|
GSDeviceOGL::PSSamplerSelector ps_ssel;
|
|
|
|
|
|
|
|
GSDeviceOGL::OMColorMaskSelector om_csel;
|
|
|
|
GSDeviceOGL::OMDepthStencilSelector om_dssel;
|
|
|
|
|
2015-07-19 07:58:56 +00:00
|
|
|
GL_PUSH("GL Draw from %d in %d (Depth %d)",
|
|
|
|
tex && tex->m_texture ? tex->m_texture->GetID() : 0,
|
2015-08-04 17:26:17 +00:00
|
|
|
rt ? rt->GetID() : -1, ds ? ds->GetID() : -1);
|
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;
|
|
|
|
|
|
|
|
bool require_barrier = false; // For accurate option
|
|
|
|
|
|
|
|
ASSERT(m_dev != NULL);
|
|
|
|
|
|
|
|
GSDeviceOGL* dev = (GSDeviceOGL*)m_dev;
|
|
|
|
dev->s_n = s_n;
|
|
|
|
|
2015-08-05 15:59:55 +00:00
|
|
|
if ((DATE || m_sw_blending) && GLLoader::found_GL_ARB_texture_barrier && (m_vt.m_primclass == GS_SPRITE_CLASS)) {
|
2015-07-19 07:58:56 +00:00
|
|
|
// Except 2D games, sprites are often use for special post-processing effect
|
|
|
|
m_prim_overlap = PrimitiveOverlap();
|
|
|
|
} else {
|
|
|
|
m_prim_overlap = PRIM_OVERLAP_UNKNOW;
|
|
|
|
}
|
2015-08-15 16:50:17 +00:00
|
|
|
#ifdef ENABLE_OGL_DEBUG
|
|
|
|
if (m_sw_blending && (m_prim_overlap != PRIM_OVERLAP_NO) && (m_context->FRAME.Block() == m_context->TEX0.TBP0) && (m_vertex.next > 2)) {
|
|
|
|
GL_INS("ERROR: Source and Target are the same!");
|
|
|
|
}
|
|
|
|
#endif
|
2015-07-19 07:58:56 +00:00
|
|
|
|
2015-08-07 07:44:42 +00:00
|
|
|
require_barrier |= EmulateTextureShuffleAndFbmask(ps_sel, om_csel);
|
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
|
|
|
|
|
2015-07-25 15:13:37 +00:00
|
|
|
if (DATE && GLLoader::found_GL_ARB_texture_barrier) {
|
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
|
2015-07-25 15:13:37 +00:00
|
|
|
require_barrier = true;
|
2015-07-21 17:07:24 +00:00
|
|
|
DATE_GL45 = true;
|
|
|
|
DATE = false;
|
2015-08-22 10:21:37 +00:00
|
|
|
} else if (m_accurate_date && om_csel.wa /* FIXME Check the msb bit of the mask instead + the dfmt*/
|
2015-07-25 14:26:53 +00:00
|
|
|
&& (!m_context->TEST.ATE || m_context->TEST.ATST == ATST_ALWAYS)) {
|
2015-07-21 17:07:24 +00:00
|
|
|
// texture barrier will split the draw call into n draw call. It is very efficient for
|
|
|
|
// few primitive draws. Otherwise it sucks.
|
2015-07-25 15:13:37 +00:00
|
|
|
if (m_index.tail < 100) {
|
2015-07-21 17:07:24 +00:00
|
|
|
require_barrier = true;
|
|
|
|
DATE_GL45 = true;
|
|
|
|
DATE = false;
|
|
|
|
} else {
|
|
|
|
DATE_GL42 = GLLoader::found_GL_ARB_shader_image_load_store;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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) {
|
2015-08-07 07:44:42 +00:00
|
|
|
require_barrier |= EmulateBlending(ps_sel, 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
|
|
|
|
2015-05-26 14:16:36 +00:00
|
|
|
if (ps_sel.dfmt == 1) {
|
|
|
|
// Disable writing of the alpha channel
|
|
|
|
om_csel.wa = 0;
|
|
|
|
}
|
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) {
|
2015-04-24 18:13:38 +00:00
|
|
|
dev->InitPrimDateTexture(rt);
|
|
|
|
} 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
|
|
|
|
|
2015-07-25 14:26:53 +00:00
|
|
|
if (m_context->TEST.ZTE)
|
2012-01-15 17:25:49 +00:00
|
|
|
{
|
2015-07-25 14:26:53 +00:00
|
|
|
om_dssel.ztst = m_context->TEST.ZTST;
|
|
|
|
om_dssel.zwe = !m_context->ZBUF.ZMSK;
|
2012-01-15 17:25:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
om_dssel.ztst = ZTST_ALWAYS;
|
|
|
|
}
|
|
|
|
|
2015-04-19 16:22:20 +00:00
|
|
|
// vs
|
2012-01-15 17:25:49 +00:00
|
|
|
|
|
|
|
vs_sel.tme = PRIM->TME;
|
|
|
|
vs_sel.fst = PRIM->FST;
|
2015-04-13 16:34:43 +00:00
|
|
|
vs_sel.wildhack = (UserHacks_WildHack && !isPackedUV_HackFlag) ? 1 : 0;
|
2012-01-15 17:25:49 +00:00
|
|
|
|
|
|
|
// 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.
|
|
|
|
|
2015-05-19 22:51:37 +00:00
|
|
|
if (om_dssel.ztst >= ZTST_ALWAYS && om_dssel.zwe)
|
2012-01-15 17:25:49 +00:00
|
|
|
{
|
2015-07-25 14:26:53 +00:00
|
|
|
if (m_context->ZBUF.PSM == PSM_PSMZ24)
|
2012-01-15 17:25:49 +00:00
|
|
|
{
|
2015-05-19 22:51:37 +00:00
|
|
|
if (m_vt.m_max.p.z > 0xffffff)
|
2012-01-15 17:25:49 +00:00
|
|
|
{
|
2012-02-11 10:22:02 +00:00
|
|
|
ASSERT(m_vt.m_min.p.z > 0xffffff);
|
2012-01-15 17:25:49 +00:00
|
|
|
// Fixme :Following conditional fixes some dialog frame in Wild Arms 3, but may not be what was intended.
|
2012-02-11 10:22:02 +00:00
|
|
|
if (m_vt.m_min.p.z > 0xffffff)
|
2012-01-15 17:25:49 +00:00
|
|
|
{
|
2015-05-07 22:16:31 +00:00
|
|
|
GL_INS("Bad Z size on 24 bits buffers")
|
2012-01-15 17:25:49 +00:00
|
|
|
vs_sel.bppz = 1;
|
|
|
|
om_dssel.ztst = ZTST_ALWAYS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-07-25 14:26:53 +00:00
|
|
|
else if (m_context->ZBUF.PSM == PSM_PSMZ16 || m_context->ZBUF.PSM == PSM_PSMZ16S)
|
2012-01-15 17:25:49 +00:00
|
|
|
{
|
2015-05-19 22:51:37 +00:00
|
|
|
if (m_vt.m_max.p.z > 0xffff)
|
2012-01-15 17:25:49 +00:00
|
|
|
{
|
2012-02-11 10:22:02 +00:00
|
|
|
ASSERT(m_vt.m_min.p.z > 0xffff); // sfex capcom logo
|
2012-01-15 17:25:49 +00:00
|
|
|
// Fixme : Same as above, I guess.
|
2012-02-11 10:22:02 +00:00
|
|
|
if (m_vt.m_min.p.z > 0xffff)
|
2012-01-15 17:25:49 +00:00
|
|
|
{
|
2015-05-07 22:16:31 +00:00
|
|
|
GL_INS("Bad Z size on 16 bits buffers")
|
2012-01-15 17:25:49 +00:00
|
|
|
vs_sel.bppz = 2;
|
|
|
|
om_dssel.ztst = ZTST_ALWAYS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
|
2015-06-05 20:37:34 +00:00
|
|
|
if (rt && rt->LikelyOffset)
|
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)
|
|
|
|
ps_sel.iip = (m_vt.m_primclass == GS_SPRITE_CLASS) ? 1 : PRIM->IIP;
|
|
|
|
|
2015-04-24 18:53:59 +00:00
|
|
|
if (DATE_GL45) {
|
2015-07-25 14:26:53 +00:00
|
|
|
ps_sel.date = 5 + m_context->TEST.DATM;
|
2015-05-19 22:51:37 +00:00
|
|
|
} else if (DATE) {
|
2015-04-24 18:53:59 +00:00
|
|
|
if (DATE_GL42)
|
2015-07-25 14:26:53 +00:00
|
|
|
ps_sel.date = 1 + m_context->TEST.DATM;
|
2015-04-21 22:36:34 +00:00
|
|
|
else
|
|
|
|
om_dssel.date = 1;
|
2012-01-15 17:25:49 +00:00
|
|
|
}
|
|
|
|
|
2015-07-25 14:26:53 +00:00
|
|
|
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
|
|
|
{
|
|
|
|
ps_sel.fog = 1;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-07-25 14:26:53 +00:00
|
|
|
if (m_context->TEST.ATE)
|
|
|
|
ps_sel.atst = m_context->TEST.ATST;
|
2012-08-15 10:14:13 +00:00
|
|
|
else
|
|
|
|
ps_sel.atst = ATST_ALWAYS;
|
|
|
|
|
2015-07-25 14:26:53 +00:00
|
|
|
if (m_context->TEST.ATE && m_context->TEST.ATST > 1)
|
|
|
|
ps_cb.FogColor_AREF.a = (float)m_context->TEST.AREF;
|
2012-01-15 17:25:49 +00:00
|
|
|
|
2013-08-10 19:43:59 +00:00
|
|
|
// By default don't use texture
|
|
|
|
ps_sel.tfx = 4;
|
2015-05-08 08:57:21 +00:00
|
|
|
bool spritehack = false;
|
|
|
|
int atst = ps_sel.atst;
|
2013-08-10 19:43:59 +00:00
|
|
|
|
2015-05-19 22:51:37 +00:00
|
|
|
if (tex)
|
2012-01-15 17:25:49 +00:00
|
|
|
{
|
2015-07-25 14:26:53 +00:00
|
|
|
const GSLocalMemory::psm_t &psm = GSLocalMemory::m_psm[m_context->TEX0.PSM];
|
|
|
|
const GSLocalMemory::psm_t &cpsm = psm.pal > 0 ? GSLocalMemory::m_psm[m_context->TEX0.CPSM] : psm;
|
2012-08-15 10:14:13 +00:00
|
|
|
bool bilinear = m_filter == 2 ? m_vt.IsLinear() : m_filter != 0;
|
2015-08-14 18:57:45 +00:00
|
|
|
bool simple_sample = !tex->m_palette && cpsm.fmt == 0 && m_context->CLAMP.WMS < 2 && m_context->CLAMP.WMT < 2;
|
2015-04-03 18:09:02 +00:00
|
|
|
// Don't force extra filtering on sprite (it creates various upscaling issue)
|
2015-04-15 07:26:01 +00:00
|
|
|
bilinear &= !((m_vt.m_primclass == GS_SPRITE_CLASS) && m_userhacks_round_sprite_offset && !m_vt.IsLinear());
|
2012-06-13 10:43:04 +00:00
|
|
|
|
2015-07-25 14:26:53 +00:00
|
|
|
ps_sel.wms = m_context->CLAMP.WMS;
|
|
|
|
ps_sel.wmt = m_context->CLAMP.WMT;
|
2015-06-06 11:56:08 +00:00
|
|
|
|
2015-08-08 11:34:55 +00:00
|
|
|
// 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)
|
2015-06-06 11:56:08 +00:00
|
|
|
if (ps_sel.shuffle) {
|
2015-08-08 11:34:55 +00:00
|
|
|
// Force a 32 bits access (normally shuffle is done on 16 bits)
|
|
|
|
// ps_sel.tex_fmt = 0; // removed as an optimization
|
|
|
|
ps_sel.aem = m_env.TEXA.AEM;
|
|
|
|
ASSERT(tex->m_target);
|
|
|
|
|
|
|
|
GSVector4 ta(m_env.TEXA & GSVector4i::x000000ff());
|
|
|
|
ps_cb.MinF_TA = ta.xyxy() / 255.0f;
|
|
|
|
|
|
|
|
// FIXME: it is likely a bad idea to do the bilinear interpolation here
|
|
|
|
// bilinear &= m_vt.IsLinear();
|
|
|
|
|
|
|
|
} 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)
|
|
|
|
ps_sel.tex_fmt = cpsm.fmt;
|
|
|
|
ps_sel.aem = m_env.TEXA.AEM;
|
|
|
|
|
|
|
|
GSVector4 ta(m_env.TEXA & GSVector4i::x000000ff());
|
|
|
|
ps_cb.MinF_TA = ta.xyxy() / 255.0f;
|
|
|
|
|
|
|
|
// Select the index format
|
|
|
|
if (tex->m_palette) {
|
|
|
|
// FIXME Potentially improve fmt field in GSLocalMemory
|
|
|
|
if (m_context->TEX0.PSM == PSM_PSMT4HL)
|
|
|
|
ps_sel.tex_fmt |= 1 << 2;
|
|
|
|
else if (m_context->TEX0.PSM == PSM_PSMT4HH)
|
|
|
|
ps_sel.tex_fmt |= 2 << 2;
|
|
|
|
else
|
|
|
|
ps_sel.tex_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.
|
2015-06-14 08:02:30 +00:00
|
|
|
bilinear &= m_vt.IsLinear();
|
2015-08-08 11:34:55 +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
|
|
|
|
// ps_sel.aem = 0; // removed as an optimization
|
|
|
|
|
|
|
|
// Note 4 bits indexes are converted to 8 bits
|
|
|
|
ps_sel.tex_fmt = 3 << 2;
|
2015-06-08 19:00:00 +00:00
|
|
|
|
2015-05-24 14:50:01 +00:00
|
|
|
} else {
|
2015-08-08 11:34:55 +00:00
|
|
|
// Standard texture. Both index and AEM expansion were already done by the CPU.
|
|
|
|
// ps_sel.tex_fmt = 0; // removed as an optimization
|
|
|
|
// ps_sel.aem = 0; // removed as an optimization
|
2015-05-24 14:50:01 +00:00
|
|
|
}
|
2015-07-20 17:35:30 +00:00
|
|
|
|
2015-07-25 14:26:53 +00:00
|
|
|
if (m_context->TEX0.TFX == TFX_MODULATE && m_vt.m_eq.rgba == 0xFFFF && m_vt.m_min.c.eq(GSVector4i(128))) {
|
2015-07-20 17:35:30 +00:00
|
|
|
// Micro optimization that reduces GPU load (removes 5 instructions on the FS program)
|
|
|
|
ps_sel.tfx = TFX_DECAL;
|
|
|
|
} else {
|
2015-07-25 14:26:53 +00:00
|
|
|
ps_sel.tfx = m_context->TEX0.TFX;
|
2015-07-20 17:35:30 +00:00
|
|
|
}
|
|
|
|
|
2015-07-25 14:26:53 +00:00
|
|
|
ps_sel.tcc = m_context->TEX0.TCC;
|
2015-07-20 17:35:30 +00:00
|
|
|
|
2012-08-15 10:14:13 +00:00
|
|
|
ps_sel.ltf = bilinear && !simple_sample;
|
2015-05-08 08:57:21 +00:00
|
|
|
spritehack = tex->m_spritehack_t;
|
2012-01-15 17:25:49 +00:00
|
|
|
|
|
|
|
int w = tex->m_texture->GetWidth();
|
|
|
|
int h = tex->m_texture->GetHeight();
|
|
|
|
|
2015-07-25 14:26:53 +00:00
|
|
|
int tw = (int)(1 << m_context->TEX0.TW);
|
|
|
|
int th = (int)(1 << m_context->TEX0.TH);
|
2012-01-15 17:25:49 +00:00
|
|
|
|
|
|
|
GSVector4 WH(tw, th, w, h);
|
|
|
|
|
2015-08-20 19:39:30 +00:00
|
|
|
ps_sel.fst = !!PRIM->FST;
|
2012-01-15 17:25:49 +00:00
|
|
|
|
|
|
|
ps_cb.WH = WH;
|
|
|
|
ps_cb.HalfTexel = GSVector4(-0.5f, 0.5f).xxyy() / WH.zwzw();
|
2015-08-14 21:53:01 +00:00
|
|
|
if ((m_context->CLAMP.WMS | m_context->CLAMP.WMT) > 1) {
|
|
|
|
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();
|
|
|
|
}
|
2012-01-15 17:25:49 +00:00
|
|
|
|
2013-02-23 15:35:56 +00:00
|
|
|
// TC Offset Hack
|
|
|
|
ps_sel.tcoffsethack = !!UserHacks_TCOffset;
|
2015-09-11 12:47:33 +00:00
|
|
|
ps_cb.TC_OH_TS = GSVector4(1/16.0f, 1/16.0f, UserHacks_TCO_x, UserHacks_TCO_y) / WH.xyxy();
|
2013-02-23 15:35:56 +00:00
|
|
|
|
2012-01-15 17:25:49 +00:00
|
|
|
|
2015-08-14 21:53:01 +00:00
|
|
|
// Only enable clamping in CLAMP mode. REGION_CLAMP will be done manually in the shader
|
2015-10-17 12:39:26 +00:00
|
|
|
ps_ssel.tau = (m_context->CLAMP.WMS != CLAMP_CLAMP);
|
|
|
|
ps_ssel.tav = (m_context->CLAMP.WMT != CLAMP_CLAMP);
|
|
|
|
ps_ssel.ltf = bilinear && simple_sample;
|
|
|
|
ps_ssel.aniso = simple_sample;
|
2013-08-17 08:57:52 +00:00
|
|
|
|
|
|
|
// Setup Texture ressources
|
2015-08-07 12:46:57 +00:00
|
|
|
dev->SetupSampler(ps_ssel);
|
|
|
|
dev->PSSetShaderResources(tex->m_texture, tex->m_palette);
|
2015-05-08 08:57:21 +00:00
|
|
|
|
|
|
|
if (spritehack && (ps_sel.atst == 2)) {
|
|
|
|
ps_sel.atst = 1;
|
|
|
|
}
|
2015-05-23 10:23:05 +00:00
|
|
|
} else {
|
|
|
|
#ifdef ENABLE_OGL_DEBUG
|
|
|
|
// Unattach texture to avoid noise in debugger
|
2015-08-07 12:46:57 +00:00
|
|
|
dev->PSSetShaderResources(NULL, NULL);
|
2015-05-23 10:23:05 +00:00
|
|
|
#endif
|
2013-08-10 19:43:59 +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);
|
|
|
|
|
2013-08-10 19:43:59 +00:00
|
|
|
|
2015-07-10 21:59:14 +00:00
|
|
|
// GS
|
|
|
|
|
2015-07-11 07:32:27 +00:00
|
|
|
#if 0
|
|
|
|
if (m_vt.m_primclass == GS_POINT_CLASS) {
|
|
|
|
// Upscaling point will create aliasing because point has a size of 0 pixels.
|
|
|
|
// This code tries to replace point with sprite. So a point in 4x will be replaced by
|
|
|
|
// a 4x4 sprite.
|
|
|
|
gs_sel.point = 1;
|
|
|
|
// FIXME this formula is potentially wrong
|
|
|
|
GSVector4 point_size = GSVector4(rtscale.x / rtsize.x, rtscale.y / rtsize.y) * 2.0f;
|
|
|
|
vs_cb.TextureScale = vs_cb.TextureScale.xyxy(point_size);
|
|
|
|
}
|
|
|
|
#endif
|
2015-07-10 21:59:14 +00:00
|
|
|
gs_sel.sprite = m_vt.m_primclass == GS_SPRITE_CLASS;
|
|
|
|
|
2013-08-10 19:43:59 +00:00
|
|
|
dev->SetupVS(vs_sel);
|
2015-07-10 21:59:14 +00:00
|
|
|
dev->SetupGS(gs_sel);
|
2013-08-10 19:43:59 +00:00
|
|
|
dev->SetupPS(ps_sel);
|
2013-07-19 19:25:50 +00:00
|
|
|
|
2012-01-15 17:25:49 +00:00
|
|
|
// rs
|
|
|
|
|
2015-07-25 14:26:53 +00:00
|
|
|
GSVector4i scissor = GSVector4i(GSVector4(rtscale).xyxy() * m_context->scissor.in).rintersect(GSVector4i(rtsize).zwxy());
|
2012-01-15 17:25:49 +00:00
|
|
|
|
2015-05-06 16:52:51 +00:00
|
|
|
GL_PUSH("IA");
|
2012-02-11 10:22:02 +00:00
|
|
|
SetupIA();
|
2015-05-06 16:52:51 +00:00
|
|
|
GL_POP();
|
2012-02-11 10:22:02 +00:00
|
|
|
|
2015-05-05 08:26:01 +00:00
|
|
|
dev->OMSetColorMaskState(om_csel);
|
2015-07-31 18:28:54 +00:00
|
|
|
dev->SetupOM(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
|
|
|
|
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);
|
2013-07-28 14:40:43 +00:00
|
|
|
// Compute primitiveID max that pass the date test
|
2015-05-09 13:01:39 +00:00
|
|
|
SendDraw(false);
|
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
|
|
|
|
|
|
|
ps_sel.date = 3;
|
2013-08-10 19:43:59 +00:00
|
|
|
dev->SetupPS(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);
|
2015-05-06 16:52:51 +00:00
|
|
|
|
|
|
|
GL_POP();
|
2013-07-28 14:40:43 +00:00
|
|
|
}
|
2012-01-15 17:25:49 +00:00
|
|
|
|
2015-07-30 20:05:08 +00:00
|
|
|
if (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
|
|
|
|
2015-07-25 14:26:53 +00:00
|
|
|
if (m_context->TEST.DoFirstPass())
|
2012-01-15 17:25:49 +00:00
|
|
|
{
|
2015-05-09 13:01:39 +00:00
|
|
|
SendDraw(require_barrier);
|
2012-01-15 17:25:49 +00:00
|
|
|
}
|
|
|
|
|
2015-07-25 14:26:53 +00:00
|
|
|
if (m_context->TEST.DoSecondPass())
|
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
|
|
|
|
|
|
|
static const uint32 iatst[] = {1, 0, 5, 6, 7, 2, 3, 4};
|
|
|
|
|
2015-05-08 08:57:21 +00:00
|
|
|
ps_sel.atst = iatst[atst];
|
|
|
|
if (spritehack && (ps_sel.atst == 2)) {
|
|
|
|
ps_sel.atst = 1;
|
|
|
|
}
|
2012-01-15 17:25:49 +00:00
|
|
|
|
2013-08-10 19:43:59 +00:00
|
|
|
dev->SetupPS(ps_sel);
|
2012-01-15 17:25:49 +00:00
|
|
|
|
|
|
|
bool z = om_dssel.zwe;
|
2015-05-05 08:26:01 +00:00
|
|
|
bool r = om_csel.wr;
|
|
|
|
bool g = om_csel.wg;
|
|
|
|
bool b = om_csel.wb;
|
|
|
|
bool a = 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
|
|
|
}
|
|
|
|
|
2015-05-19 22:51:37 +00:00
|
|
|
if (z || r || g || b || a)
|
2012-01-15 17:25:49 +00:00
|
|
|
{
|
|
|
|
om_dssel.zwe = z;
|
2015-05-05 08:26:01 +00:00
|
|
|
om_csel.wr = r;
|
|
|
|
om_csel.wg = g;
|
|
|
|
om_csel.wb = b;
|
|
|
|
om_csel.wa = a;
|
2012-01-15 17:25:49 +00:00
|
|
|
|
2015-05-05 08:26:01 +00:00
|
|
|
dev->OMSetColorMaskState(om_csel);
|
2015-07-31 18:28:54 +00:00
|
|
|
dev->SetupOM(om_dssel);
|
2012-01-15 17:25:49 +00:00
|
|
|
|
2015-05-09 13:01:39 +00:00
|
|
|
SendDraw(require_barrier);
|
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);
|
|
|
|
}
|
|
|
|
|
2015-05-06 16:52:51 +00:00
|
|
|
GL_POP();
|
2012-01-15 17:25:49 +00:00
|
|
|
}
|