2010-04-25 00:31:27 +00:00
|
|
|
/*
|
2009-02-09 21:15:56 +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
|
|
|
*
|
2009-02-09 21:15:56 +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
|
|
|
*
|
2009-02-09 21:15:56 +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.
|
2009-02-09 21:15:56 +00:00
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "GSRenderer.h"
|
2011-03-08 01:48:15 +00:00
|
|
|
#include "GSDirtyRect.h"
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-22 01:22:52 +00:00
|
|
|
class GSTextureCache
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
public:
|
2009-06-27 03:32:33 +00:00
|
|
|
enum {RenderTarget, DepthStencil};
|
|
|
|
|
2011-02-07 01:59:05 +00:00
|
|
|
class Surface : public GSAlignedClass<32>
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
protected:
|
2009-05-22 01:22:52 +00:00
|
|
|
GSRenderer* m_renderer;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
public:
|
2009-05-22 01:22:52 +00:00
|
|
|
GSTexture* m_texture;
|
2009-02-09 21:15:56 +00:00
|
|
|
GIFRegTEX0 m_TEX0;
|
2009-06-17 11:24:42 +00:00
|
|
|
GIFRegTEXA m_TEXA;
|
2009-06-27 03:32:33 +00:00
|
|
|
int m_age;
|
2011-02-20 23:53:00 +00:00
|
|
|
uint8* m_temp;
|
2015-06-17 18:02:03 +00:00
|
|
|
bool m_32_bits_fmt; // Allow to detect the casting of 32 bits as 16 bits texture
|
2016-04-21 17:08:41 +00:00
|
|
|
bool m_shared_texture;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-06-27 03:32:33 +00:00
|
|
|
public:
|
2011-02-20 23:53:00 +00:00
|
|
|
Surface(GSRenderer* r, uint8* temp);
|
2009-06-27 03:32:33 +00:00
|
|
|
virtual ~Surface();
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-22 01:22:52 +00:00
|
|
|
virtual void Update();
|
2009-02-09 21:15:56 +00:00
|
|
|
};
|
|
|
|
|
2009-06-27 03:32:33 +00:00
|
|
|
class Source : public Surface
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-06-28 02:02:14 +00:00
|
|
|
struct {GSVector4i* rect; uint32 count;} m_write;
|
|
|
|
|
|
|
|
void Write(const GSVector4i& r);
|
|
|
|
void Flush(uint32 count);
|
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
public:
|
2009-06-27 03:32:33 +00:00
|
|
|
GSTexture* m_palette;
|
|
|
|
bool m_initpalette;
|
2009-07-01 21:14:12 +00:00
|
|
|
uint32 m_valid[MAX_PAGES]; // each uint32 bits map to the 32 blocks of that page
|
2009-06-27 03:32:33 +00:00
|
|
|
uint32* m_clut;
|
|
|
|
bool m_target;
|
2009-07-01 21:14:12 +00:00
|
|
|
bool m_complete;
|
2011-04-25 18:18:21 +00:00
|
|
|
bool m_repeating;
|
2012-06-19 01:12:01 +00:00
|
|
|
bool m_spritehack_t;
|
2011-12-31 15:41:07 +00:00
|
|
|
vector<GSVector2i>* m_p2t;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-06-27 03:32:33 +00:00
|
|
|
public:
|
2011-04-25 18:18:21 +00:00
|
|
|
Source(GSRenderer* r, const GIFRegTEX0& TEX0, const GIFRegTEXA& TEXA, uint8* temp);
|
2009-06-27 03:32:33 +00:00
|
|
|
virtual ~Source();
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-04-25 18:18:21 +00:00
|
|
|
virtual void Update(const GSVector4i& rect);
|
2009-02-09 21:15:56 +00:00
|
|
|
};
|
|
|
|
|
2009-06-27 03:32:33 +00:00
|
|
|
class Target : public Surface
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
public:
|
2009-06-27 03:32:33 +00:00
|
|
|
int m_type;
|
2009-02-09 21:15:56 +00:00
|
|
|
bool m_used;
|
2009-06-27 03:32:33 +00:00
|
|
|
GSDirtyRectList m_dirty;
|
2009-07-12 13:46:05 +00:00
|
|
|
GSVector4i m_valid;
|
2015-06-10 08:07:40 +00:00
|
|
|
bool m_depth_supported;
|
2015-06-25 17:09:26 +00:00
|
|
|
bool m_dirty_alpha;
|
2016-03-06 13:24:20 +00:00
|
|
|
uint32 m_end_block; // Hint of the target area
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
public:
|
2015-06-10 08:07:40 +00:00
|
|
|
Target(GSRenderer* r, const GIFRegTEX0& TEX0, uint8* temp, bool depth_supported);
|
2009-05-14 16:41:52 +00:00
|
|
|
|
2016-03-06 13:25:14 +00:00
|
|
|
void UpdateValidity(const GSVector4i& rect);
|
|
|
|
bool Inside(uint32 bp, uint32 psm, const GSVector4i& rect);
|
2016-03-06 13:24:20 +00:00
|
|
|
|
2009-06-27 03:32:33 +00:00
|
|
|
virtual void Update();
|
2009-02-09 21:15:56 +00:00
|
|
|
};
|
|
|
|
|
2011-02-19 03:36:30 +00:00
|
|
|
class SourceMap
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2011-02-19 03:36:30 +00:00
|
|
|
public:
|
2009-07-16 21:36:07 +00:00
|
|
|
hash_set<Source*> m_surfaces;
|
2009-07-12 13:46:05 +00:00
|
|
|
list<Source*> m_map[MAX_PAGES];
|
2014-10-24 18:49:30 +00:00
|
|
|
uint32 m_pages[16]; // bitmap of all pages
|
2009-06-27 03:32:33 +00:00
|
|
|
bool m_used;
|
|
|
|
|
2009-07-01 21:14:12 +00:00
|
|
|
SourceMap() : m_used(false) {memset(m_pages, 0, sizeof(m_pages));}
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2015-05-15 18:40:09 +00:00
|
|
|
void Add(Source* s, const GIFRegTEX0& TEX0, const GSOffset* off);
|
2009-06-27 03:32:33 +00:00
|
|
|
void RemoveAll();
|
2015-05-13 18:00:25 +00:00
|
|
|
void RemovePartial();
|
2009-06-27 03:32:33 +00:00
|
|
|
void RemoveAt(Source* s);
|
2011-02-19 03:36:30 +00:00
|
|
|
};
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-02-19 03:36:30 +00:00
|
|
|
protected:
|
|
|
|
GSRenderer* m_renderer;
|
|
|
|
SourceMap m_src;
|
2009-06-27 03:32:33 +00:00
|
|
|
list<Target*> m_dst[2];
|
2011-02-19 03:36:30 +00:00
|
|
|
bool m_paltex;
|
2012-06-19 01:12:01 +00:00
|
|
|
int m_spritehack;
|
2015-06-26 07:25:50 +00:00
|
|
|
bool m_preload_frame;
|
2011-02-19 03:36:30 +00:00
|
|
|
uint8* m_temp;
|
2015-06-07 16:42:30 +00:00
|
|
|
bool m_can_convert_depth;
|
2015-07-01 07:28:32 +00:00
|
|
|
int m_crc_hack_level;
|
2016-03-20 17:05:36 +00:00
|
|
|
static bool m_disable_partial_invalidation;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2015-05-13 18:03:04 +00:00
|
|
|
virtual Source* CreateSource(const GIFRegTEX0& TEX0, const GIFRegTEXA& TEXA, Target* t = NULL, bool half_right = false);
|
2009-07-31 23:59:06 +00:00
|
|
|
virtual Target* CreateTarget(const GIFRegTEX0& TEX0, int w, int h, int type);
|
|
|
|
|
|
|
|
virtual int Get8bitFormat() = 0;
|
|
|
|
|
|
|
|
// TODO: virtual void Write(Source* s, const GSVector4i& r) = 0;
|
|
|
|
// TODO: virtual void Write(Target* t, const GSVector4i& r) = 0;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2015-06-07 16:42:30 +00:00
|
|
|
virtual bool CanConvertDepth() { return m_can_convert_depth; }
|
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
public:
|
2009-05-22 01:22:52 +00:00
|
|
|
GSTextureCache(GSRenderer* r);
|
|
|
|
virtual ~GSTextureCache();
|
2011-05-09 01:36:57 +00:00
|
|
|
virtual void Read(Target* t, const GSVector4i& r) = 0;
|
2016-03-19 10:28:15 +00:00
|
|
|
virtual void Read(Source* t, const GSVector4i& r) = 0;
|
2009-05-22 01:22:52 +00:00
|
|
|
void RemoveAll();
|
2015-05-13 18:00:25 +00:00
|
|
|
void RemovePartial();
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-06-27 03:32:33 +00:00
|
|
|
Source* LookupSource(const GIFRegTEX0& TEX0, const GIFRegTEXA& TEXA, const GSVector4i& r);
|
2016-04-21 17:13:47 +00:00
|
|
|
Source* LookupDepthSource(const GIFRegTEX0& TEX0, const GIFRegTEXA& TEXA, const GSVector4i& r);
|
|
|
|
|
2009-07-31 23:59:06 +00:00
|
|
|
Target* LookupTarget(const GIFRegTEX0& TEX0, int w, int h, int type, bool used);
|
2015-06-26 07:25:50 +00:00
|
|
|
Target* LookupTarget(const GIFRegTEX0& TEX0, int w, int h, int real_h);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2015-06-05 21:37:06 +00:00
|
|
|
void InvalidateVideoMemType(int type, uint32 bp);
|
2016-03-19 10:39:56 +00:00
|
|
|
void InvalidateVideoMemSubTarget(GSTextureCache::Target* rt);
|
2015-05-15 18:40:09 +00:00
|
|
|
void InvalidateVideoMem(GSOffset* off, const GSVector4i& r, bool target = true);
|
|
|
|
void InvalidateLocalMem(GSOffset* off, const GSVector4i& r);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-22 01:22:52 +00:00
|
|
|
void IncAge();
|
2010-03-14 19:35:10 +00:00
|
|
|
bool UserHacks_HalfPixelOffset;
|
2015-06-13 06:32:11 +00:00
|
|
|
|
|
|
|
const char* to_string(int type) {
|
|
|
|
return (type == DepthStencil) ? "Depth" : "Color";
|
|
|
|
}
|
2015-07-10 19:11:14 +00:00
|
|
|
|
|
|
|
void PrintMemoryUsage();
|
2009-02-09 21:15:56 +00:00
|
|
|
};
|