2010-04-25 00:31:27 +00:00
|
|
|
/*
|
2010-04-24 21:37:39 +00:00
|
|
|
* Copyright (C) 2007-2009 Gabest
|
|
|
|
* http://www.gabest.org
|
|
|
|
*
|
|
|
|
* This Program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
2010-04-25 00:31:27 +00:00
|
|
|
*
|
2010-04-24 21:37:39 +00:00
|
|
|
* This Program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2010-04-25 00:31:27 +00:00
|
|
|
*
|
2010-04-24 21:37:39 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with GNU Make; see the file COPYING. If not, write to
|
2012-09-09 18:16:11 +00:00
|
|
|
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA USA.
|
2010-04-24 21:37:39 +00:00
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "StdAfx.h"
|
|
|
|
#include "GSTextureCache11.h"
|
|
|
|
|
|
|
|
// GSTextureCache11
|
|
|
|
|
|
|
|
GSTextureCache11::GSTextureCache11(GSRenderer* r)
|
|
|
|
: GSTextureCache(r)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void GSTextureCache11::Read(Target* t, const GSVector4i& r)
|
|
|
|
{
|
2018-12-03 17:01:47 +00:00
|
|
|
if (!t->m_dirty.empty() || r.width() == 0 || r.height() == 0)
|
2010-04-24 21:37:39 +00:00
|
|
|
{
|
2010-04-25 00:31:27 +00:00
|
|
|
return;
|
2010-04-24 21:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const GIFRegTEX0& TEX0 = t->m_TEX0;
|
|
|
|
|
2018-12-03 17:01:47 +00:00
|
|
|
DXGI_FORMAT format;
|
|
|
|
int ps_shader;
|
|
|
|
switch (TEX0.PSM)
|
2010-04-24 21:37:39 +00:00
|
|
|
{
|
2018-12-03 17:01:47 +00:00
|
|
|
case PSM_PSMCT32:
|
|
|
|
case PSM_PSMCT24:
|
|
|
|
format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
|
|
|
ps_shader = ShaderConvert_COPY;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PSM_PSMCT16:
|
|
|
|
case PSM_PSMCT16S:
|
|
|
|
format = DXGI_FORMAT_R16_UINT;
|
|
|
|
ps_shader = ShaderConvert_RGBA8_TO_16_BITS;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PSM_PSMZ32:
|
|
|
|
case PSM_PSMZ24:
|
|
|
|
format = DXGI_FORMAT_R32_UINT;
|
|
|
|
ps_shader = ShaderConvert_FLOAT32_TO_32_BITS;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PSM_PSMZ16:
|
|
|
|
case PSM_PSMZ16S:
|
|
|
|
format = DXGI_FORMAT_R16_UINT;
|
|
|
|
ps_shader = ShaderConvert_FLOAT32_TO_32_BITS;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return;
|
2010-04-24 21:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// printf("GSRenderTarget::Read %d,%d - %d,%d (%08x)\n", r.left, r.top, r.right, r.bottom, TEX0.TBP0);
|
|
|
|
|
|
|
|
int w = r.width();
|
|
|
|
int h = r.height();
|
|
|
|
|
|
|
|
GSVector4 src = GSVector4(r) * GSVector4(t->m_texture->GetScale()).xyxy() / GSVector4(t->m_texture->GetSize()).xyxy();
|
|
|
|
|
2018-12-03 17:01:47 +00:00
|
|
|
if (GSTexture* offscreen = m_renderer->m_dev->CopyOffscreen(t->m_texture, src, w, h, format, ps_shader))
|
2010-04-24 21:37:39 +00:00
|
|
|
{
|
|
|
|
GSTexture::GSMap m;
|
|
|
|
|
2018-12-03 17:01:47 +00:00
|
|
|
if (offscreen->Map(m))
|
2010-04-24 21:37:39 +00:00
|
|
|
{
|
|
|
|
// TODO: block level write
|
|
|
|
|
2015-05-15 18:40:09 +00:00
|
|
|
GSOffset* off = m_renderer->m_mem.GetOffset(TEX0.TBP0, TEX0.TBW, TEX0.PSM);
|
2010-04-24 21:37:39 +00:00
|
|
|
|
2018-12-03 17:01:47 +00:00
|
|
|
switch (TEX0.PSM)
|
2010-04-24 21:37:39 +00:00
|
|
|
{
|
2018-12-03 17:01:47 +00:00
|
|
|
case PSM_PSMCT32:
|
|
|
|
case PSM_PSMZ32:
|
|
|
|
m_renderer->m_mem.WritePixel32(m.bits, m.pitch, off, r);
|
|
|
|
break;
|
|
|
|
case PSM_PSMCT24:
|
|
|
|
case PSM_PSMZ24:
|
|
|
|
m_renderer->m_mem.WritePixel24(m.bits, m.pitch, off, r);
|
|
|
|
break;
|
|
|
|
case PSM_PSMCT16:
|
|
|
|
case PSM_PSMCT16S:
|
|
|
|
case PSM_PSMZ16:
|
|
|
|
case PSM_PSMZ16S:
|
|
|
|
m_renderer->m_mem.WritePixel16(m.bits, m.pitch, off, r);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ASSERT(0);
|
2010-04-24 21:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
offscreen->Unmap();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_renderer->m_dev->Recycle(offscreen);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-19 10:28:15 +00:00
|
|
|
void GSTextureCache11::Read(Source* t, const GSVector4i& r)
|
|
|
|
{
|
|
|
|
// FIXME: copy was copyied from openGL. It is unlikely to work.
|
|
|
|
|
|
|
|
const GIFRegTEX0& TEX0 = t->m_TEX0;
|
|
|
|
|
|
|
|
if (GSTexture* offscreen = m_renderer->m_dev->CreateOffscreen(r.width(), r.height())) {
|
|
|
|
m_renderer->m_dev->CopyRect(t->m_texture, offscreen, r);
|
|
|
|
|
|
|
|
GSTexture::GSMap m;
|
|
|
|
GSVector4i r_offscreen(0, 0, r.width(), r.height());
|
|
|
|
|
|
|
|
if (offscreen->Map(m, &r_offscreen)) {
|
|
|
|
GSOffset* off = m_renderer->m_mem.GetOffset(TEX0.TBP0, TEX0.TBW, TEX0.PSM);
|
|
|
|
|
|
|
|
m_renderer->m_mem.WritePixel32(m.bits, m.pitch, off, r);
|
|
|
|
|
|
|
|
offscreen->Unmap();
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME invalidate data
|
|
|
|
m_renderer->m_dev->Recycle(offscreen);
|
|
|
|
}
|
|
|
|
}
|