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 "GS.h"
# include "GSLocalMemory.h"
# include "GSDrawingContext.h"
# include "GSDrawingEnvironment.h"
# include "GSVertex.h"
2012-01-05 02:40:24 +00:00
# include "GSVertexTrace.h"
2009-02-09 21:15:56 +00:00
# include "GSUtil.h"
# include "GSPerfMon.h"
# include "GSVector.h"
# include "GSDevice.h"
# include "GSCrc.h"
# include "GSAlignedClass.h"
# include "GSDump.h"
2016-05-05 14:03:48 +00:00
struct GSFrameInfo
{
uint32 FBP ;
uint32 FPSM ;
uint32 FBMSK ;
uint32 TBP0 ;
uint32 TPSM ;
uint32 TZTST ;
bool TME ;
} ;
typedef bool ( * GetSkipCount ) ( const GSFrameInfo & fi , int & skip ) ;
2011-02-07 01:59:05 +00:00
class GSState : public GSAlignedClass < 32 >
2009-02-09 21:15:56 +00:00
{
2011-12-20 14:33:28 +00:00
// RESTRICT prevents multiple loads of the same part of the register when accessing its bitfields (the compiler is happy to know that memory writes in-between will not go there)
typedef void ( GSState : : * GIFPackedRegHandler ) ( const GIFPackedReg * RESTRICT r ) ;
2011-02-18 01:56:05 +00:00
2009-02-09 21:15:56 +00:00
GIFPackedRegHandler m_fpGIFPackedRegHandlers [ 16 ] ;
2012-01-08 17:10:00 +00:00
GIFPackedRegHandler m_fpGIFPackedRegHandlerXYZ [ 8 ] [ 4 ] ;
2009-02-09 21:15:56 +00:00
2011-12-20 14:33:28 +00:00
void GIFPackedRegHandlerNull ( const GIFPackedReg * RESTRICT r ) ;
void GIFPackedRegHandlerRGBA ( const GIFPackedReg * RESTRICT r ) ;
void GIFPackedRegHandlerSTQ ( const GIFPackedReg * RESTRICT r ) ;
void GIFPackedRegHandlerUV ( const GIFPackedReg * RESTRICT r ) ;
GSdx:
- changed the KH2 fix in GetTextureMinMax to my taste, should give the same results, when the used texture rect is to the left/above the clamped area, it returns [min, min+1], and [max-1, max] for right/below
- m_mem.m_clut.Read32 was returned to its original place from GetAlphaMinMax
- UserHacks_WildHack was moved up to GSState, special UV handlers are only used when this setting is active
- updated xbyak to the latest available (avx2 seems incomplete, the 256-bit promoted old instructions are missing)
- changed vtune's include path to the 2013 edition
Some other not yet commited changes from a year ago:
- WriteImageX overflow crash-fix
- moved colclamp after dithering (sw mode), it makes more sense, no visible changes noticed
- Gif_Tag::analyzeTag(), there was a conditional I didn't like, split the loop into two parts
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@5649 96395faa-99c1-11dd-bbfe-3dabce05a288
2013-06-06 11:36:01 +00:00
void GIFPackedRegHandlerUV_Hack ( const GIFPackedReg * RESTRICT r ) ;
2016-09-08 15:25:59 +00:00
template < uint32 prim , uint32 adc , bool auto_flush > void GIFPackedRegHandlerXYZF2 ( const GIFPackedReg * RESTRICT r ) ;
template < uint32 prim , uint32 adc , bool auto_flush > void GIFPackedRegHandlerXYZ2 ( const GIFPackedReg * RESTRICT r ) ;
2011-12-20 14:33:28 +00:00
void GIFPackedRegHandlerFOG ( const GIFPackedReg * RESTRICT r ) ;
void GIFPackedRegHandlerA_D ( const GIFPackedReg * RESTRICT r ) ;
void GIFPackedRegHandlerNOP ( const GIFPackedReg * RESTRICT r ) ;
2010-07-19 15:49:30 +00:00
2011-12-20 14:33:28 +00:00
typedef void ( GSState : : * GIFRegHandler ) ( const GIFReg * RESTRICT r ) ;
2009-02-09 21:15:56 +00:00
GIFRegHandler m_fpGIFRegHandlers [ 256 ] ;
2012-01-08 17:10:00 +00:00
GIFRegHandler m_fpGIFRegHandlerXYZ [ 8 ] [ 4 ] ;
2009-02-09 21:15:56 +00:00
2012-01-18 11:47:31 +00:00
typedef void ( GSState : : * GIFPackedRegHandlerC ) ( const GIFPackedReg * RESTRICT r , uint32 size ) ;
2012-01-21 12:34:36 +00:00
GIFPackedRegHandlerC m_fpGIFPackedRegHandlersC [ 2 ] ;
2012-01-18 11:47:31 +00:00
GIFPackedRegHandlerC m_fpGIFPackedRegHandlerSTQRGBAXYZF2 [ 8 ] ;
2012-01-21 12:34:36 +00:00
GIFPackedRegHandlerC m_fpGIFPackedRegHandlerSTQRGBAXYZ2 [ 8 ] ;
2012-01-18 11:47:31 +00:00
2016-09-08 15:25:59 +00:00
template < uint32 prim , bool auto_flush > void GIFPackedRegHandlerSTQRGBAXYZF2 ( const GIFPackedReg * RESTRICT r , uint32 size ) ;
template < uint32 prim , bool auto_flush > void GIFPackedRegHandlerSTQRGBAXYZ2 ( const GIFPackedReg * RESTRICT r , uint32 size ) ;
2012-01-21 04:44:04 +00:00
void GIFPackedRegHandlerNOP ( const GIFPackedReg * RESTRICT r , uint32 size ) ;
2012-01-18 11:47:31 +00:00
2012-01-08 17:10:00 +00:00
template < int i > void ApplyTEX0 ( GIFRegTEX0 & TEX0 ) ;
2012-01-27 11:56:49 +00:00
void ApplyPRIM ( uint32 prim ) ;
2010-07-19 15:49:30 +00:00
2011-12-20 14:33:28 +00:00
void GIFRegHandlerNull ( const GIFReg * RESTRICT r ) ;
void GIFRegHandlerPRIM ( const GIFReg * RESTRICT r ) ;
void GIFRegHandlerRGBAQ ( const GIFReg * RESTRICT r ) ;
void GIFRegHandlerST ( const GIFReg * RESTRICT r ) ;
void GIFRegHandlerUV ( const GIFReg * RESTRICT r ) ;
GSdx:
- changed the KH2 fix in GetTextureMinMax to my taste, should give the same results, when the used texture rect is to the left/above the clamped area, it returns [min, min+1], and [max-1, max] for right/below
- m_mem.m_clut.Read32 was returned to its original place from GetAlphaMinMax
- UserHacks_WildHack was moved up to GSState, special UV handlers are only used when this setting is active
- updated xbyak to the latest available (avx2 seems incomplete, the 256-bit promoted old instructions are missing)
- changed vtune's include path to the 2013 edition
Some other not yet commited changes from a year ago:
- WriteImageX overflow crash-fix
- moved colclamp after dithering (sw mode), it makes more sense, no visible changes noticed
- Gif_Tag::analyzeTag(), there was a conditional I didn't like, split the loop into two parts
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@5649 96395faa-99c1-11dd-bbfe-3dabce05a288
2013-06-06 11:36:01 +00:00
void GIFRegHandlerUV_Hack ( const GIFReg * RESTRICT r ) ;
2016-09-08 15:25:59 +00:00
template < uint32 prim , uint32 adc , bool auto_flush > void GIFRegHandlerXYZF2 ( const GIFReg * RESTRICT r ) ;
template < uint32 prim , uint32 adc , bool auto_flush > void GIFRegHandlerXYZ2 ( const GIFReg * RESTRICT r ) ;
2011-12-20 14:33:28 +00:00
template < int i > void GIFRegHandlerTEX0 ( const GIFReg * RESTRICT r ) ;
template < int i > void GIFRegHandlerCLAMP ( const GIFReg * RESTRICT r ) ;
void GIFRegHandlerFOG ( const GIFReg * RESTRICT r ) ;
void GIFRegHandlerNOP ( const GIFReg * RESTRICT r ) ;
template < int i > void GIFRegHandlerTEX1 ( const GIFReg * RESTRICT r ) ;
template < int i > void GIFRegHandlerTEX2 ( const GIFReg * RESTRICT r ) ;
template < int i > void GIFRegHandlerXYOFFSET ( const GIFReg * RESTRICT r ) ;
void GIFRegHandlerPRMODECONT ( const GIFReg * RESTRICT r ) ;
void GIFRegHandlerPRMODE ( const GIFReg * RESTRICT r ) ;
void GIFRegHandlerTEXCLUT ( const GIFReg * RESTRICT r ) ;
void GIFRegHandlerSCANMSK ( const GIFReg * RESTRICT r ) ;
template < int i > void GIFRegHandlerMIPTBP1 ( const GIFReg * RESTRICT r ) ;
template < int i > void GIFRegHandlerMIPTBP2 ( const GIFReg * RESTRICT r ) ;
void GIFRegHandlerTEXA ( const GIFReg * RESTRICT r ) ;
void GIFRegHandlerFOGCOL ( const GIFReg * RESTRICT r ) ;
void GIFRegHandlerTEXFLUSH ( const GIFReg * RESTRICT r ) ;
template < int i > void GIFRegHandlerSCISSOR ( const GIFReg * RESTRICT r ) ;
template < int i > void GIFRegHandlerALPHA ( const GIFReg * RESTRICT r ) ;
void GIFRegHandlerDIMX ( const GIFReg * RESTRICT r ) ;
void GIFRegHandlerDTHE ( const GIFReg * RESTRICT r ) ;
void GIFRegHandlerCOLCLAMP ( const GIFReg * RESTRICT r ) ;
template < int i > void GIFRegHandlerTEST ( const GIFReg * RESTRICT r ) ;
void GIFRegHandlerPABE ( const GIFReg * RESTRICT r ) ;
template < int i > void GIFRegHandlerFBA ( const GIFReg * RESTRICT r ) ;
template < int i > void GIFRegHandlerFRAME ( const GIFReg * RESTRICT r ) ;
template < int i > void GIFRegHandlerZBUF ( const GIFReg * RESTRICT r ) ;
void GIFRegHandlerBITBLTBUF ( const GIFReg * RESTRICT r ) ;
void GIFRegHandlerTRXPOS ( const GIFReg * RESTRICT r ) ;
void GIFRegHandlerTRXREG ( const GIFReg * RESTRICT r ) ;
void GIFRegHandlerTRXDIR ( const GIFReg * RESTRICT r ) ;
void GIFRegHandlerHWREG ( const GIFReg * RESTRICT r ) ;
void GIFRegHandlerSIGNAL ( const GIFReg * RESTRICT r ) ;
void GIFRegHandlerFINISH ( const GIFReg * RESTRICT r ) ;
void GIFRegHandlerLABEL ( const GIFReg * RESTRICT r ) ;
2009-02-09 21:15:56 +00:00
int m_version ;
int m_sssize ;
bool m_mt ;
void ( * m_irq ) ( ) ;
bool m_path3hack ;
2014-05-02 21:03:02 +00:00
bool m_init_read_fifo_supported ;
2009-02-09 21:15:56 +00:00
2009-04-18 09:34:25 +00:00
struct GSTransferBuffer
{
2010-04-25 00:31:27 +00:00
int x , y ;
int start , end , total ;
2009-04-18 09:34:25 +00:00
bool overflow ;
2009-05-14 16:41:52 +00:00
uint8 * buff ;
2016-08-29 21:56:15 +00:00
GIFRegBITBLTBUF m_blit ;
2009-04-18 09:34:25 +00:00
GSTransferBuffer ( ) ;
virtual ~ GSTransferBuffer ( ) ;
2016-08-29 21:56:15 +00:00
void Init ( int tx , int ty , const GIFRegBITBLTBUF & blit ) ;
2009-04-18 09:34:25 +00:00
bool Update ( int tw , int th , int bpp , int & len ) ;
} m_tr ;
2009-02-09 21:15:56 +00:00
protected :
2016-05-05 14:22:14 +00:00
bool IsBadFrame ( ) ;
2016-05-05 14:03:48 +00:00
void SetupCrcHack ( ) ;
GSdx:
- changed the KH2 fix in GetTextureMinMax to my taste, should give the same results, when the used texture rect is to the left/above the clamped area, it returns [min, min+1], and [max-1, max] for right/below
- m_mem.m_clut.Read32 was returned to its original place from GetAlphaMinMax
- UserHacks_WildHack was moved up to GSState, special UV handlers are only used when this setting is active
- updated xbyak to the latest available (avx2 seems incomplete, the 256-bit promoted old instructions are missing)
- changed vtune's include path to the 2013 edition
Some other not yet commited changes from a year ago:
- WriteImageX overflow crash-fix
- moved colclamp after dithering (sw mode), it makes more sense, no visible changes noticed
- Gif_Tag::analyzeTag(), there was a conditional I didn't like, split the loop into two parts
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@5649 96395faa-99c1-11dd-bbfe-3dabce05a288
2013-06-06 11:36:01 +00:00
int UserHacks_WildHack ;
2015-06-04 16:52:58 +00:00
bool isPackedUV_HackFlag ;
int m_crc_hack_level ;
2016-05-05 14:03:48 +00:00
GetSkipCount m_gsc ;
2016-05-05 14:22:14 +00:00
int m_skip ;
int m_userhacks_skipdraw ;
2016-09-08 15:25:59 +00:00
bool m_userhacks_auto_flush ;
2009-02-09 21:15:56 +00:00
2012-01-05 02:40:24 +00:00
GSVertex m_v ;
2012-01-23 04:11:24 +00:00
float m_q ;
2013-06-17 04:11:10 +00:00
GSVector4i m_scissor ;
GSVector4i m_ofxy ;
2012-02-08 16:57:14 +00:00
bool m_texflush ;
2016-05-05 14:03:48 +00:00
struct
2012-01-08 17:10:00 +00:00
{
2012-01-19 04:53:36 +00:00
GSVertex * buff ;
2012-01-08 17:10:00 +00:00
size_t head , tail , next , maxcount ; // head: first vertex, tail: last vertex + 1, next: last indexed + 1
size_t xy_tail ;
2013-06-17 04:11:10 +00:00
uint64 xy [ 4 ] ;
2012-01-08 17:10:00 +00:00
} m_vertex ;
2016-05-05 14:03:48 +00:00
struct
2012-01-08 17:10:00 +00:00
{
uint32 * buff ;
size_t tail ;
} m_index ;
2009-02-09 21:15:56 +00:00
2012-01-09 08:41:33 +00:00
void UpdateContext ( ) ;
void UpdateScissor ( ) ;
2016-09-28 07:45:22 +00:00
void UpdateVertexKick ( ) ;
2009-02-09 21:15:56 +00:00
2012-01-05 02:40:24 +00:00
void GrowVertexBuffer ( ) ;
2010-08-17 04:38:49 +00:00
2016-09-08 15:25:59 +00:00
template < uint32 prim , bool auto_flush >
2012-01-06 00:17:52 +00:00
void VertexKick ( uint32 skip ) ;
2012-01-05 02:40:24 +00:00
// following functions need m_vt to be initialized
2012-01-19 04:53:36 +00:00
GSVertexTrace m_vt ;
2012-01-05 02:40:24 +00:00
void GetTextureMinMax ( GSVector4i & r , const GIFRegTEX0 & TEX0 , const GIFRegCLAMP & CLAMP , bool linear ) ;
void GetAlphaMinMax ( ) ;
bool TryAlphaTest ( uint32 & fm , uint32 & zm ) ;
bool IsOpaque ( ) ;
2015-08-04 11:27:08 +00:00
bool IsMipMapActive ( ) ;
2016-09-25 09:51:48 +00:00
GIFRegTEX0 GetTex0Layer ( int lod ) ;
2009-02-09 21:15:56 +00:00
public :
2010-07-11 04:38:33 +00:00
GIFPath m_path [ 4 ] ;
2009-03-31 03:19:21 +00:00
GIFRegPRIM * PRIM ;
GSPrivRegSet * m_regs ;
2009-02-09 21:15:56 +00:00
GSLocalMemory m_mem ;
GSDrawingEnvironment m_env ;
GSDrawingContext * m_context ;
GSPerfMon m_perfmon ;
2009-05-14 16:41:52 +00:00
uint32 m_crc ;
2016-04-06 04:51:17 +00:00
CRC : : Game m_game ;
GSDump m_dump ;
2009-02-09 21:15:56 +00:00
int m_options ;
int m_frameskip ;
2009-07-16 21:36:07 +00:00
bool m_framelimit ;
2016-04-06 04:51:17 +00:00
bool m_NTSC_Saturation ;
2012-01-08 17:10:00 +00:00
bool m_nativeres ;
2015-08-04 11:27:08 +00:00
bool m_mipmap ;
2009-02-09 21:15:56 +00:00
2012-01-29 10:12:20 +00:00
int s_n ;
bool s_dump ;
bool s_save ;
2015-05-01 11:35:21 +00:00
bool s_savet ;
2012-01-29 10:12:20 +00:00
bool s_savez ;
2015-05-31 15:38:52 +00:00
bool s_savef ;
2012-01-29 10:12:20 +00:00
int s_saven ;
2015-05-03 14:46:48 +00:00
int s_savel ;
2016-07-14 17:41:21 +00:00
string m_dump_root ;
2012-01-29 10:12:20 +00:00
2009-02-09 21:15:56 +00:00
public :
2012-01-19 04:53:36 +00:00
GSState ( ) ;
2009-02-09 21:15:56 +00:00
virtual ~ GSState ( ) ;
void ResetHandlers ( ) ;
2009-05-14 16:41:52 +00:00
GSVector4i GetDisplayRect ( int i = - 1 ) ;
GSVector4i GetFrameRect ( int i = - 1 ) ;
2016-05-19 08:32:50 +00:00
GSVideoMode GetVideoMode ( ) ;
2009-05-14 16:41:52 +00:00
2009-02-09 21:15:56 +00:00
bool IsEnabled ( int i ) ;
2016-05-19 08:32:50 +00:00
bool isinterlaced ( ) ;
2009-05-14 16:41:52 +00:00
2015-09-18 01:07:58 +00:00
float GetTvRefreshRate ( ) ;
2009-02-09 21:15:56 +00:00
virtual void Reset ( ) ;
2016-09-28 07:45:22 +00:00
void Flush ( ) ;
void FlushPrim ( ) ;
void FlushWrite ( ) ;
2012-01-05 02:40:24 +00:00
virtual void Draw ( ) = 0 ;
2016-05-05 14:43:02 +00:00
virtual void PurgePool ( ) = 0 ;
2009-05-14 16:41:52 +00:00
virtual void InvalidateVideoMem ( const GIFRegBITBLTBUF & BITBLTBUF , const GSVector4i & r ) { }
2011-12-20 14:33:28 +00:00
virtual void InvalidateLocalMem ( const GIFRegBITBLTBUF & BITBLTBUF , const GSVector4i & r , bool clut = false ) { }
2009-02-09 21:15:56 +00:00
void Move ( ) ;
2010-07-19 15:49:30 +00:00
void Write ( const uint8 * mem , int len ) ;
2009-05-14 16:41:52 +00:00
void Read ( uint8 * mem , int len ) ;
2014-05-02 21:03:02 +00:00
void InitReadFIFO ( uint8 * mem , int len ) ;
2009-02-09 21:15:56 +00:00
2009-05-14 16:41:52 +00:00
void SoftReset ( uint32 mask ) ;
void WriteCSR ( uint32 csr ) { m_regs - > CSR . u32 [ 1 ] = csr ; }
void ReadFIFO ( uint8 * mem , int size ) ;
2010-07-19 15:49:30 +00:00
template < int index > void Transfer ( const uint8 * mem , uint32 size ) ;
2009-02-09 21:15:56 +00:00
int Freeze ( GSFreezeData * fd , bool sizeonly ) ;
int Defrost ( const GSFreezeData * fd ) ;
2009-05-14 16:41:52 +00:00
void GetLastTag ( uint32 * tag ) { * tag = m_path3hack ; m_path3hack = 0 ; }
virtual void SetGameCRC ( uint32 crc , int options ) ;
2009-07-16 21:36:07 +00:00
void SetFrameSkip ( int skip ) ;
2009-09-18 23:48:12 +00:00
void SetRegsMem ( uint8 * basemem ) ;
2009-09-18 19:54:56 +00:00
void SetIrqCallback ( void ( * irq ) ( ) ) ;
2011-02-07 01:59:05 +00:00
void SetMultithreaded ( bool mt = true ) ;
2009-02-09 21:15:56 +00:00
} ;