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
*
*/
# include "stdafx.h"
2010-04-25 00:31:27 +00:00
# include "GSRendererHW.h"
2012-01-05 02:40:24 +00:00
2012-01-19 04:53:36 +00:00
GSRendererHW : : GSRendererHW ( GSTextureCache * tc )
2015-06-07 15:57:55 +00:00
: m_width ( 1280 )
, m_height ( 1024 )
2012-01-05 02:40:24 +00:00
, m_skip ( 0 )
, m_reset ( false )
, m_upscale_multiplier ( 1 )
2013-06-28 17:32:37 +00:00
, m_tc ( tc )
2012-01-05 02:40:24 +00:00
{
m_upscale_multiplier = theApp . GetConfig ( " upscale_multiplier " , 1 ) ;
2012-03-06 20:01:27 +00:00
m_userhacks_skipdraw = ! ! theApp . GetConfig ( " UserHacks " , 0 ) ? theApp . GetConfig ( " UserHacks_SkipDraw " , 0 ) : 0 ;
2015-04-05 22:15:53 +00:00
m_userhacks_align_sprite_X = ! ! theApp . GetConfig ( " UserHacks_align_sprite_X " , 0 ) & & ! ! theApp . GetConfig ( " UserHacks " , 0 ) ;
2015-04-09 17:51:50 +00:00
m_userhacks_round_sprite_offset = ! ! theApp . GetConfig ( " UserHacks " , 0 ) ? theApp . GetConfig ( " UserHacks_round_sprite_offset " , 0 ) : 0 ;
2015-06-07 15:57:55 +00:00
2015-06-22 16:23:47 +00:00
if ( m_upscale_multiplier = = 1 & & ! m_nativeres ) { //Custom
2015-06-07 15:57:55 +00:00
m_width = theApp . GetConfig ( " resx " , m_width ) ;
m_height = theApp . GetConfig ( " resy " , m_height ) ;
}
if ( m_upscale_multiplier = = 1 ) {
m_userhacks_round_sprite_offset = 0 ;
m_userhacks_align_sprite_X = 0 ;
}
2015-05-13 18:00:25 +00:00
}
2015-06-04 20:15:52 +00:00
void GSRendererHW : : SetScaling ( ) {
2015-05-13 18:00:25 +00:00
2015-06-07 02:50:19 +00:00
m_buffer_size = max ( m_context - > FRAME . FBW * 64 , m_regs - > DISP [ m_regs - > PMODE . EN1 = = 1 ? 0 : 1 ] . DISPFB . FBW * 64 ) ;
2015-06-04 23:12:15 +00:00
2015-06-01 18:04:39 +00:00
//Only increase the buffer size, don't make it smaller, it breaks games (GH3)
2015-06-07 15:57:55 +00:00
if ( ! m_nativeres & & m_width < ( m_buffer_size * m_upscale_multiplier ) ) {
2015-05-13 18:00:25 +00:00
m_tc - > RemovePartial ( ) ;
}
else {
return ;
}
2012-01-05 02:40:24 +00:00
2015-06-07 17:31:51 +00:00
m_height = m_buffer_size < 1024 ? 512 : 1024 ;
2015-06-07 15:57:55 +00:00
m_upscale_multiplier = theApp . GetConfig ( " upscale_multiplier " , m_upscale_multiplier ) ;
2015-06-04 23:12:15 +00:00
2015-06-23 18:43:04 +00:00
if ( m_upscale_multiplier = = 1 & & ! m_nativeres ) { //Custom
2015-06-07 15:57:55 +00:00
m_width = theApp . GetConfig ( " resx " , m_width ) ;
m_height = theApp . GetConfig ( " resy " , m_height ) ;
}
if ( m_upscale_multiplier > 1 )
{
2015-05-13 18:00:25 +00:00
if ( m_upscale_multiplier > 6 )
2012-01-05 02:40:24 +00:00
{
m_upscale_multiplier = 1 ; // use the normal upscale math
}
2015-04-13 16:31:48 +00:00
2015-06-07 15:57:55 +00:00
m_width = m_buffer_size * m_upscale_multiplier ;
m_height * = m_upscale_multiplier ;
2015-04-13 16:31:48 +00:00
}
2015-06-07 15:57:55 +00:00
2015-06-04 23:12:15 +00:00
printf ( " Frame buffer size set to %dx%d (%dx%d) \n " , ( m_width / m_upscale_multiplier ) , ( m_height / m_upscale_multiplier ) , m_width , m_height ) ;
2012-01-05 02:40:24 +00:00
}
GSRendererHW : : ~ GSRendererHW ( )
{
delete m_tc ;
}
void GSRendererHW : : SetGameCRC ( uint32 crc , int options )
{
GSRenderer : : SetGameCRC ( crc , options ) ;
m_hacks . SetGameCRC ( m_game ) ;
}
bool GSRendererHW : : CanUpscale ( )
{
2015-06-14 08:19:15 +00:00
if ( m_hacks . m_cu & & ! ( this - > * m_hacks . m_cu ) ( ) )
2012-01-05 02:40:24 +00:00
{
return false ;
}
return ! m_nativeres & & m_regs - > PMODE . EN ! = 0 ; // upscale ratio depends on the display size, with no output it may not be set correctly (ps2 logo to game transition)
}
int GSRendererHW : : GetUpscaleMultiplier ( )
{
return m_upscale_multiplier ;
}
void GSRendererHW : : Reset ( )
{
// TODO: GSreset can come from the main thread too => crash
// m_tc->RemoveAll();
m_reset = true ;
GSRenderer : : Reset ( ) ;
}
void GSRendererHW : : VSync ( int field )
{
2015-05-13 18:00:25 +00:00
//Check if the frame buffer width or display width has changed
SetScaling ( ) ;
2012-01-05 02:40:24 +00:00
if ( m_reset )
{
m_tc - > RemoveAll ( ) ;
m_reset = false ;
}
2012-01-18 11:47:31 +00:00
GSRenderer : : VSync ( field ) ;
m_tc - > IncAge ( ) ;
m_skip = 0 ;
2012-01-05 02:40:24 +00:00
}
void GSRendererHW : : ResetDevice ( )
{
m_tc - > RemoveAll ( ) ;
GSRenderer : : ResetDevice ( ) ;
}
GSTexture * GSRendererHW : : GetOutput ( int i )
{
const GSRegDISPFB & DISPFB = m_regs - > DISP [ i ] . DISPFB ;
GIFRegTEX0 TEX0 ;
TEX0 . TBP0 = DISPFB . Block ( ) ;
TEX0 . TBW = DISPFB . FBW ;
TEX0 . PSM = DISPFB . PSM ;
// TRACE(_T("[%d] GetOutput %d %05x (%d)\n"), (int)m_perfmon.GetFrame(), i, (int)TEX0.TBP0, (int)TEX0.PSM);
GSTexture * t = NULL ;
2015-06-26 07:25:50 +00:00
if ( GSTextureCache : : Target * rt = m_tc - > LookupTarget ( TEX0 , m_width , m_height , GetFrameRect ( i ) . bottom ) )
2012-01-05 02:40:24 +00:00
{
t = rt - > m_texture ;
if ( s_dump )
{
2015-05-31 15:38:52 +00:00
if ( s_savef & & s_n > = s_saven )
2012-01-05 02:40:24 +00:00
{
2015-02-21 12:51:06 +00:00
t - > Save ( root_hw + format ( " %05d_f%lld_fr%d_%05x_%d.bmp " , s_n , m_perfmon . GetFrame ( ) , i , ( int ) TEX0 . TBP0 , ( int ) TEX0 . PSM ) ) ;
2012-01-05 02:40:24 +00:00
}
}
2015-05-15 20:43:34 +00:00
s_n + + ; // Alaways increment it
2012-01-05 02:40:24 +00:00
}
return t ;
}
void GSRendererHW : : InvalidateVideoMem ( const GIFRegBITBLTBUF & BITBLTBUF , const GSVector4i & r )
{
// printf("[%d] InvalidateVideoMem %d,%d - %d,%d %05x (%d)\n", (int)m_perfmon.GetFrame(), r.left, r.top, r.right, r.bottom, (int)BITBLTBUF.DBP, (int)BITBLTBUF.DPSM);
m_tc - > InvalidateVideoMem ( m_mem . GetOffset ( BITBLTBUF . DBP , BITBLTBUF . DBW , BITBLTBUF . DPSM ) , r ) ;
}
void GSRendererHW : : InvalidateLocalMem ( const GIFRegBITBLTBUF & BITBLTBUF , const GSVector4i & r , bool clut )
{
// printf("[%d] InvalidateLocalMem %d,%d - %d,%d %05x (%d)\n", (int)m_perfmon.GetFrame(), r.left, r.top, r.right, r.bottom, (int)BITBLTBUF.SBP, (int)BITBLTBUF.SPSM);
if ( clut ) return ; // FIXME
m_tc - > InvalidateLocalMem ( m_mem . GetOffset ( BITBLTBUF . SBP , BITBLTBUF . SBW , BITBLTBUF . SPSM ) , r ) ;
}
2015-04-09 17:51:50 +00:00
int GSRendererHW : : Interpolate_UV ( float alpha , int t0 , int t1 )
{
float t = ( 1.0f - alpha ) * t0 + alpha * t1 ;
return ( int ) t & ~ 0xF ; // cheap rounding
}
2015-04-12 15:10:45 +00:00
float GSRendererHW : : alpha0 ( int L , int X0 , int X1 )
2015-04-09 17:51:50 +00:00
{
2015-04-12 15:10:45 +00:00
float x = ( X0 + 15 ) & ~ 0xF ; // Round up
return ( x - X0 ) / ( float ) L ;
2015-04-09 17:51:50 +00:00
}
2015-04-12 15:10:45 +00:00
float GSRendererHW : : alpha1 ( int L , int X0 , int X1 )
2015-04-09 17:51:50 +00:00
{
float x = ( X1 - 1 ) & ~ 0xF ; // Round down. Note -1 because right pixel isn't included in primitive so 0x100 must return 0.
2015-04-12 15:10:45 +00:00
return ( x - X0 ) / ( float ) L ;
2015-04-09 17:51:50 +00:00
}
2015-04-12 10:24:07 +00:00
template < bool linear >
void GSRendererHW : : RoundSpriteOffset ( )
{
//#define DEBUG_U
//#define DEBUG_V
2015-04-16 16:27:27 +00:00
# if defined(DEBUG_V) || defined(DEBUG_U)
2015-04-12 10:24:07 +00:00
bool debug = linear ;
2015-04-16 16:27:27 +00:00
# endif
2015-04-12 10:24:07 +00:00
size_t count = m_vertex . next ;
GSVertex * v = & m_vertex . buff [ 0 ] ;
for ( size_t i = 0 ; i < count ; i + = 2 ) {
2015-04-12 15:10:45 +00:00
// Performance note: if it had any impact on perf, someone would port it to SSE (AKA GSVector)
2015-04-12 10:24:07 +00:00
// Compute the coordinate of first and last texels (in native with a linear filtering)
2015-04-12 15:10:45 +00:00
int ox = m_context - > XYOFFSET . OFX ;
int X0 = v [ i ] . XYZ . X - ox ;
int X1 = v [ i + 1 ] . XYZ . X - ox ;
int Lx = ( v [ i + 1 ] . XYZ . X - v [ i ] . XYZ . X ) ;
float ax0 = alpha0 ( Lx , X0 , X1 ) ;
float ax1 = alpha1 ( Lx , X0 , X1 ) ;
2015-04-12 10:24:07 +00:00
int tx0 = Interpolate_UV ( ax0 , v [ i ] . U , v [ i + 1 ] . U ) ;
int tx1 = Interpolate_UV ( ax1 , v [ i ] . U , v [ i + 1 ] . U ) ;
# ifdef DEBUG_U
if ( debug ) {
fprintf ( stderr , " u0:%d and u1:%d \n " , v [ i ] . U , v [ i + 1 ] . U ) ;
fprintf ( stderr , " a0:%f and a1:%f \n " , ax0 , ax1 ) ;
fprintf ( stderr , " t0:%d and t1:%d \n " , tx0 , tx1 ) ;
}
# endif
2015-04-12 15:10:45 +00:00
int oy = m_context - > XYOFFSET . OFY ;
int Y0 = v [ i ] . XYZ . Y - oy ;
int Y1 = v [ i + 1 ] . XYZ . Y - oy ;
int Ly = ( v [ i + 1 ] . XYZ . Y - v [ i ] . XYZ . Y ) ;
float ay0 = alpha0 ( Ly , Y0 , Y1 ) ;
float ay1 = alpha1 ( Ly , Y0 , Y1 ) ;
2015-04-12 10:24:07 +00:00
int ty0 = Interpolate_UV ( ay0 , v [ i ] . V , v [ i + 1 ] . V ) ;
int ty1 = Interpolate_UV ( ay1 , v [ i ] . V , v [ i + 1 ] . V ) ;
# ifdef DEBUG_V
if ( debug ) {
fprintf ( stderr , " v0:%d and v1:%d \n " , v [ i ] . V , v [ i + 1 ] . V ) ;
fprintf ( stderr , " a0:%f and a1:%f \n " , ay0 , ay1 ) ;
fprintf ( stderr , " t0:%d and t1:%d \n " , ty0 , ty1 ) ;
}
# endif
# ifdef DEBUG_U
if ( debug )
fprintf ( stderr , " GREP_BEFORE %d => %d \n " , v [ i ] . U , v [ i + 1 ] . U ) ;
# endif
# ifdef DEBUG_V
if ( debug )
fprintf ( stderr , " GREP_BEFORE %d => %d \n " , v [ i ] . V , v [ i + 1 ] . V ) ;
# endif
# if 1
// Use rounded value of the newly computed texture coordinate. It ensures
// that sampling will remains inside texture boundary
//
2015-04-16 16:27:27 +00:00
// Note for bilinear: by definition it will never work correctly! A sligh modification
// of interpolation migth trigger a discard (with alpha testing)
// Let's use something simple that correct really bad case (for a couple of 2D games).
// I hope it won't create too much glitches.
2015-04-12 15:57:37 +00:00
if ( linear ) {
2015-04-16 16:27:27 +00:00
int Lu = v [ i + 1 ] . U - v [ i ] . U ;
// Note 32 is based on taisho-mononoke
if ( ( Lu > 0 ) & & ( Lu < = ( Lx + 32 ) ) ) {
v [ i + 1 ] . U - = 8 ;
2015-04-12 15:57:37 +00:00
}
2015-04-12 10:24:07 +00:00
} else {
2015-04-12 15:57:37 +00:00
if ( tx0 < = tx1 ) {
v [ i ] . U = tx0 ;
v [ i + 1 ] . U = tx1 + 16 ;
} else {
v [ i ] . U = tx0 + 15 ;
2015-04-14 16:39:26 +00:00
v [ i + 1 ] . U = tx1 ;
2015-04-12 15:57:37 +00:00
}
2015-04-12 10:24:07 +00:00
}
# endif
# if 1
2015-04-12 15:57:37 +00:00
if ( linear ) {
2015-04-16 16:27:27 +00:00
int Lv = v [ i + 1 ] . V - v [ i ] . V ;
if ( ( Lv > 0 ) & & ( Lv < = ( Ly + 32 ) ) ) {
v [ i + 1 ] . V - = 8 ;
2015-04-12 15:57:37 +00:00
}
2015-04-12 10:24:07 +00:00
} else {
2015-04-12 15:57:37 +00:00
if ( ty0 < = ty1 ) {
v [ i ] . V = ty0 ;
v [ i + 1 ] . V = ty1 + 16 ;
} else {
v [ i ] . V = ty0 + 15 ;
2015-04-14 16:39:26 +00:00
v [ i + 1 ] . V = ty1 ;
2015-04-12 15:57:37 +00:00
}
2015-04-12 10:24:07 +00:00
}
# endif
# ifdef DEBUG_U
if ( debug )
fprintf ( stderr , " GREP_AFTER %d => %d \n \n " , v [ i ] . U , v [ i + 1 ] . U ) ;
# endif
# ifdef DEBUG_V
if ( debug )
fprintf ( stderr , " GREP_AFTER %d => %d \n \n " , v [ i ] . V , v [ i + 1 ] . V ) ;
# endif
}
}
2012-01-05 02:40:24 +00:00
void GSRendererHW : : Draw ( )
{
2015-05-05 15:48:11 +00:00
if ( m_dev - > IsLost ( ) | | GSRenderer : : IsBadFrame ( m_skip , m_userhacks_skipdraw ) ) {
2015-05-24 10:53:23 +00:00
GL_INS ( " Warning skipping a draw call (%d) " , s_n ) ;
2015-05-06 16:52:51 +00:00
s_n + = 3 ; // Keep it sync with SW renderer
2015-05-05 15:48:11 +00:00
return ;
}
2015-05-16 17:28:22 +00:00
GL_PUSH ( " HW Draw %d " , s_n ) ;
2012-01-05 02:40:24 +00:00
GSDrawingEnvironment & env = m_env ;
GSDrawingContext * context = m_context ;
2015-06-05 20:37:34 +00:00
// It is allowed to use the depth and rt at the same location. However at least 1 must
2015-07-04 08:52:43 +00:00
// be disabled.
// 1/ GoW uses a Cd blending on a 24 bits buffer (no alpha)
// 2/ SuperMan really draw the same value in both buffer...
const bool no_rt = ( context - > ALPHA . IsCd ( ) & & PRIM - > ABE & & ( context - > FRAME . PSM = = 1 ) ) | |
( context - > FRAME . FBP = = context - > ZBUF . ZBP & & ! PRIM - > TME & & ! context - > ZBUF . ZMSK & & ! context - > FRAME . FBMSK ) ;
2015-06-05 20:37:34 +00:00
2012-01-05 02:40:24 +00:00
GIFRegTEX0 TEX0 ;
TEX0 . TBP0 = context - > FRAME . Block ( ) ;
TEX0 . TBW = context - > FRAME . FBW ;
TEX0 . PSM = context - > FRAME . PSM ;
2015-06-05 20:37:34 +00:00
GSTextureCache : : Target * rt = no_rt ? NULL : m_tc - > LookupTarget ( TEX0 , m_width , m_height , GSTextureCache : : RenderTarget , true ) ;
2015-06-14 17:42:11 +00:00
GSTexture * rt_tex = rt ? rt - > m_texture : NULL ;
2012-01-05 02:40:24 +00:00
TEX0 . TBP0 = context - > ZBUF . Block ( ) ;
TEX0 . TBW = context - > FRAME . FBW ;
TEX0 . PSM = context - > ZBUF . PSM ;
GSTextureCache : : Target * ds = m_tc - > LookupTarget ( TEX0 , m_width , m_height , GSTextureCache : : DepthStencil , context - > DepthWrite ( ) ) ;
2015-06-05 20:37:34 +00:00
if ( ( ! rt & & ! no_rt ) | | ! ds )
2012-01-05 02:40:24 +00:00
{
2015-06-07 07:42:12 +00:00
GL_POP ( ) ;
2012-01-05 02:40:24 +00:00
ASSERT ( 0 ) ;
return ;
}
GSTextureCache : : Source * tex = NULL ;
2015-06-17 18:02:03 +00:00
m_texture_shuffle = false ;
2012-01-05 02:40:24 +00:00
if ( PRIM - > TME )
{
2015-06-12 06:58:08 +00:00
# ifdef ENABLE_OGL_DEBUG
if ( ( context - > FRAME . Block ( ) = = context - > TEX0 . TBP0 ) & & ( m_vertex . next > 2 ) ) {
GL_INS ( " ERROR: Source and Target are the same! " ) ;
}
# endif
2013-07-01 21:28:58 +00:00
/*
// m_tc->LookupSource will mess with the palette, should not, but we do this after, until it is sorted out
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
if ( GSLocalMemory : : m_psm [ context - > TEX0 . PSM ] . pal > 0 )
{
m_mem . m_clut . Read32 ( context - > TEX0 , env . TEXA ) ;
}
2013-07-01 21:28:58 +00:00
*/
2012-01-05 02:40:24 +00:00
GSVector4i r ;
2012-01-19 04:53:36 +00:00
GetTextureMinMax ( r , context - > TEX0 , context - > CLAMP , m_vt . IsLinear ( ) ) ;
2012-01-05 02:40:24 +00:00
tex = m_tc - > LookupSource ( context - > TEX0 , env . TEXA , r ) ;
2015-06-07 07:42:12 +00:00
if ( ! tex ) {
GL_POP ( ) ;
return ;
}
2013-07-01 21:28:58 +00:00
if ( GSLocalMemory : : m_psm [ context - > TEX0 . PSM ] . pal > 0 )
{
m_mem . m_clut . Read32 ( context - > TEX0 , env . TEXA ) ;
}
2015-06-17 18:02:03 +00:00
if ( rt ) {
rt - > m_32_bits_fmt | = tex - > m_32_bits_fmt ;
}
// Both input and output are 16 bits but texture was initially 32 bits!
m_texture_shuffle = ( ( context - > FRAME . PSM & 0x2 ) & & ( ( context - > TEX0 . PSM & 3 ) = = 2 ) & & ( m_vt . m_primclass = = GS_SPRITE_CLASS ) & & tex - > m_32_bits_fmt ) ;
2015-06-25 07:49:11 +00:00
ASSERT ( ! m_texture_shuffle | | ( context - > CLAMP . WMS < 3 & & context - > CLAMP . WMT < 3 ) ) ;
2012-01-05 02:40:24 +00:00
}
if ( s_dump )
{
uint64 frame = m_perfmon . GetFrame ( ) ;
string s ;
2015-05-23 10:23:05 +00:00
if ( s_n > = s_saven ) {
// Dump Register state
s = format ( " %05d_context.txt " , s_n ) ;
m_env . Dump ( root_hw + s ) ;
m_context - > Dump ( root_hw + s ) ;
}
2015-05-01 11:35:21 +00:00
if ( s_savet & & s_n > = s_saven & & tex )
2012-01-05 02:40:24 +00:00
{
2015-02-21 12:51:06 +00:00
s = format ( " %05d_f%lld_tex_%05x_%d_%d%d_%02x_%02x_%02x_%02x.dds " ,
2012-01-05 02:40:24 +00:00
s_n , frame , ( int ) context - > TEX0 . TBP0 , ( int ) context - > TEX0 . PSM ,
( int ) context - > CLAMP . WMS , ( int ) context - > CLAMP . WMT ,
( int ) context - > CLAMP . MINU , ( int ) context - > CLAMP . MAXU ,
( int ) context - > CLAMP . MINV , ( int ) context - > CLAMP . MAXV ) ;
2015-02-21 12:51:06 +00:00
tex - > m_texture - > Save ( root_hw + s , true ) ;
2012-01-05 02:40:24 +00:00
if ( tex - > m_palette )
{
2015-02-21 12:51:06 +00:00
s = format ( " %05d_f%lld_tpx_%05x_%d.dds " , s_n , frame , context - > TEX0 . CBP , context - > TEX0 . CPSM ) ;
2012-01-05 02:40:24 +00:00
2015-02-21 12:51:06 +00:00
tex - > m_palette - > Save ( root_hw + s , true ) ;
2012-01-05 02:40:24 +00:00
}
}
s_n + + ;
if ( s_save & & s_n > = s_saven )
{
2015-02-21 12:51:06 +00:00
s = format ( " %05d_f%lld_rt0_%05x_%d.bmp " , s_n , frame , context - > FRAME . Block ( ) , context - > FRAME . PSM ) ;
2012-01-05 02:40:24 +00:00
2015-06-05 20:37:34 +00:00
if ( rt )
rt - > m_texture - > Save ( root_hw + s ) ;
2012-01-05 02:40:24 +00:00
}
if ( s_savez & & s_n > = s_saven )
{
2015-02-21 12:51:06 +00:00
s = format ( " %05d_f%lld_rz0_%05x_%d.bmp " , s_n , frame , context - > ZBUF . Block ( ) , context - > ZBUF . PSM ) ;
2012-01-05 02:40:24 +00:00
2015-02-21 12:51:06 +00:00
ds - > m_texture - > Save ( root_hw + s ) ;
2012-01-05 02:40:24 +00:00
}
s_n + + ;
2015-05-03 14:46:48 +00:00
2015-05-06 16:52:51 +00:00
# ifdef ENABLE_OGL_DEBUG
} else {
s_n + = 2 ;
# endif
2012-01-05 02:40:24 +00:00
}
2015-06-14 17:42:11 +00:00
if ( m_hacks . m_oi & & ! ( this - > * m_hacks . m_oi ) ( rt_tex , ds - > m_texture , tex ) )
2012-01-05 02:40:24 +00:00
{
2015-06-07 07:42:12 +00:00
s_n + = 1 ; // keep counter sync
GL_POP ( ) ;
2012-01-05 02:40:24 +00:00
return ;
}
// skip alpha test if possible
GIFRegTEST TEST = context - > TEST ;
GIFRegFRAME FRAME = context - > FRAME ;
GIFRegZBUF ZBUF = context - > ZBUF ;
uint32 fm = context - > FRAME . FBMSK ;
uint32 zm = context - > ZBUF . ZMSK | | context - > TEST . ZTE = = 0 ? 0xffffffff : 0 ;
if ( context - > TEST . ATE & & context - > TEST . ATST ! = ATST_ALWAYS )
{
if ( GSRenderer : : TryAlphaTest ( fm , zm ) )
{
context - > TEST . ATST = ATST_ALWAYS ;
}
}
context - > FRAME . FBMSK = fm ;
context - > ZBUF . ZMSK = zm ! = 0 ;
2015-05-16 17:28:22 +00:00
// A couple of hack to avoid upscaling issue. So far it seems to impacts mostly sprite
2015-04-15 07:40:06 +00:00
if ( ( m_upscale_multiplier > 1 ) & & ( m_vt . m_primclass = = GS_SPRITE_CLASS ) ) {
2015-04-07 17:18:24 +00:00
size_t count = m_vertex . next ;
GSVertex * v = & m_vertex . buff [ 0 ] ;
2015-04-03 23:21:46 +00:00
// Hack to avoid vertical black line in various games (ace combat/tekken)
if ( m_userhacks_align_sprite_X ) {
// Note for performance reason I do the check only once on the first
// primitive
int win_position = v [ 1 ] . XYZ . X - context - > XYOFFSET . OFX ;
const bool unaligned_position = ( ( win_position & 0xF ) = = 8 ) ;
2015-04-16 16:08:32 +00:00
const bool unaligned_texture = ( ( v [ 1 ] . U & 0xF ) = = 0 ) & & PRIM - > FST ; // I'm not sure this check is useful
const bool hole_in_vertex = ( count < 4 ) | | ( v [ 1 ] . XYZ . X ! = v [ 2 ] . XYZ . X ) ;
if ( hole_in_vertex & & unaligned_position & & ( unaligned_texture | | ! PRIM - > FST ) ) {
2015-04-03 23:21:46 +00:00
// Normaly vertex are aligned on full pixels and texture in half
// pixels. Let's extend the coverage of an half-pixel to avoid
// hole after upscaling
for ( size_t i = 0 ; i < count ; i + = 2 ) {
v [ i + 1 ] . XYZ . X + = 8 ;
2015-04-16 16:08:32 +00:00
// I really don't know if it is a good idea. Neither what to do for !PRIM->FST
if ( unaligned_texture )
2015-04-03 23:21:46 +00:00
v [ i + 1 ] . U + = 8 ;
}
2015-04-03 19:02:25 +00:00
}
}
2015-04-15 07:40:06 +00:00
if ( PRIM - > FST ) {
if ( ( m_userhacks_round_sprite_offset > 1 ) | | ( m_userhacks_round_sprite_offset = = 1 & & ! m_vt . IsLinear ( ) ) ) {
if ( m_vt . IsLinear ( ) )
RoundSpriteOffset < true > ( ) ;
else
RoundSpriteOffset < false > ( ) ;
}
} else {
; // vertical line in Yakuza (note check m_userhacks_align_sprite_X behavior)
2015-04-09 17:51:50 +00:00
}
2015-04-03 16:11:47 +00:00
}
2012-01-05 02:40:24 +00:00
//
2015-06-14 17:42:11 +00:00
DrawPrims ( rt_tex , ds - > m_texture , tex ) ;
2012-01-05 02:40:24 +00:00
//
context - > TEST = TEST ;
context - > FRAME = FRAME ;
context - > ZBUF = ZBUF ;
//
2012-01-19 04:53:36 +00:00
GSVector4i r = GSVector4i ( m_vt . m_min . p . xyxy ( m_vt . m_max . p ) ) . rintersect ( GSVector4i ( context - > scissor . in ) ) ;
2012-01-05 02:40:24 +00:00
2015-06-05 20:37:34 +00:00
if ( fm ! = 0xffffffff & & rt )
2012-01-05 02:40:24 +00:00
{
rt - > m_valid = rt - > m_valid . runion ( r ) ;
m_tc - > InvalidateVideoMem ( context - > offset . fb , r , false ) ;
2015-06-05 21:37:06 +00:00
m_tc - > InvalidateVideoMemType ( GSTextureCache : : DepthStencil , context - > FRAME . Block ( ) ) ;
2012-01-05 02:40:24 +00:00
}
if ( zm ! = 0xffffffff )
{
ds - > m_valid = ds - > m_valid . runion ( r ) ;
m_tc - > InvalidateVideoMem ( context - > offset . zb , r , false ) ;
2015-06-05 21:37:06 +00:00
m_tc - > InvalidateVideoMemType ( GSTextureCache : : RenderTarget , context - > ZBUF . Block ( ) ) ;
2012-01-05 02:40:24 +00:00
}
//
2015-06-14 08:19:15 +00:00
if ( m_hacks . m_oo )
2012-01-05 02:40:24 +00:00
{
( this - > * m_hacks . m_oo ) ( ) ;
}
if ( s_dump )
{
uint64 frame = m_perfmon . GetFrame ( ) ;
string s ;
if ( s_save & & s_n > = s_saven )
{
2015-02-21 12:51:06 +00:00
s = format ( " %05d_f%lld_rt1_%05x_%d.bmp " , s_n , frame , context - > FRAME . Block ( ) , context - > FRAME . PSM ) ;
2012-01-05 02:40:24 +00:00
2015-06-05 20:37:34 +00:00
if ( rt )
rt - > m_texture - > Save ( root_hw + s ) ;
2012-01-05 02:40:24 +00:00
}
if ( s_savez & & s_n > = s_saven )
{
2015-02-21 12:51:06 +00:00
s = format ( " %05d_f%lld_rz1_%05x_%d.bmp " , s_n , frame , context - > ZBUF . Block ( ) , context - > ZBUF . PSM ) ;
2012-01-05 02:40:24 +00:00
2015-02-21 12:51:06 +00:00
ds - > m_texture - > Save ( root_hw + s ) ;
2012-01-05 02:40:24 +00:00
}
s_n + + ;
2015-05-05 15:48:11 +00:00
if ( ( s_n - s_saven ) > s_savel ) {
s_dump = 0 ;
}
2015-05-06 16:52:51 +00:00
# ifdef ENABLE_OGL_DEBUG
} else {
s_n + = 1 ;
# endif
2012-01-05 02:40:24 +00:00
}
# ifdef DISABLE_HW_TEXTURE_CACHE
2015-06-05 20:37:34 +00:00
if ( rt )
m_tc - > Read ( rt , r ) ;
2012-01-05 02:40:24 +00:00
# endif
2015-05-08 13:51:46 +00:00
GL_POP ( ) ;
2012-01-05 02:40:24 +00:00
}
// hacks
GSRendererHW : : Hacks : : Hacks ( )
: m_oi_map ( m_oi_list )
, m_oo_map ( m_oo_list )
, m_cu_map ( m_cu_list )
, m_oi ( NULL )
, m_oo ( NULL )
, m_cu ( NULL )
{
m_oi_list . push_back ( HackEntry < OI_Ptr > ( CRC : : FFXII , CRC : : EU , & GSRendererHW : : OI_FFXII ) ) ;
m_oi_list . push_back ( HackEntry < OI_Ptr > ( CRC : : FFX , CRC : : RegionCount , & GSRendererHW : : OI_FFX ) ) ;
m_oi_list . push_back ( HackEntry < OI_Ptr > ( CRC : : MetalSlug6 , CRC : : RegionCount , & GSRendererHW : : OI_MetalSlug6 ) ) ;
m_oi_list . push_back ( HackEntry < OI_Ptr > ( CRC : : GodOfWar2 , CRC : : RegionCount , & GSRendererHW : : OI_GodOfWar2 ) ) ;
m_oi_list . push_back ( HackEntry < OI_Ptr > ( CRC : : SimpsonsGame , CRC : : RegionCount , & GSRendererHW : : OI_SimpsonsGame ) ) ;
m_oi_list . push_back ( HackEntry < OI_Ptr > ( CRC : : RozenMaidenGebetGarden , CRC : : RegionCount , & GSRendererHW : : OI_RozenMaidenGebetGarden ) ) ;
m_oi_list . push_back ( HackEntry < OI_Ptr > ( CRC : : SpidermanWoS , CRC : : RegionCount , & GSRendererHW : : OI_SpidermanWoS ) ) ;
m_oi_list . push_back ( HackEntry < OI_Ptr > ( CRC : : TyTasmanianTiger , CRC : : RegionCount , & GSRendererHW : : OI_TyTasmanianTiger ) ) ;
m_oi_list . push_back ( HackEntry < OI_Ptr > ( CRC : : TyTasmanianTiger2 , CRC : : RegionCount , & GSRendererHW : : OI_TyTasmanianTiger ) ) ;
m_oi_list . push_back ( HackEntry < OI_Ptr > ( CRC : : DigimonRumbleArena2 , CRC : : RegionCount , & GSRendererHW : : OI_DigimonRumbleArena2 ) ) ;
m_oi_list . push_back ( HackEntry < OI_Ptr > ( CRC : : StarWarsForceUnleashed , CRC : : RegionCount , & GSRendererHW : : OI_StarWarsForceUnleashed ) ) ;
m_oi_list . push_back ( HackEntry < OI_Ptr > ( CRC : : BlackHawkDown , CRC : : RegionCount , & GSRendererHW : : OI_BlackHawkDown ) ) ;
m_oi_list . push_back ( HackEntry < OI_Ptr > ( CRC : : XmenOriginsWolverine , CRC : : RegionCount , & GSRendererHW : : OI_XmenOriginsWolverine ) ) ;
m_oi_list . push_back ( HackEntry < OI_Ptr > ( CRC : : CallofDutyFinalFronts , CRC : : RegionCount , & GSRendererHW : : OI_CallofDutyFinalFronts ) ) ;
m_oi_list . push_back ( HackEntry < OI_Ptr > ( CRC : : SpyroNewBeginning , CRC : : RegionCount , & GSRendererHW : : OI_SpyroNewBeginning ) ) ;
m_oi_list . push_back ( HackEntry < OI_Ptr > ( CRC : : SpyroEternalNight , CRC : : RegionCount , & GSRendererHW : : OI_SpyroEternalNight ) ) ;
m_oi_list . push_back ( HackEntry < OI_Ptr > ( CRC : : TalesOfLegendia , CRC : : RegionCount , & GSRendererHW : : OI_TalesOfLegendia ) ) ;
2014-01-21 15:27:05 +00:00
m_oi_list . push_back ( HackEntry < OI_Ptr > ( CRC : : SMTNocturne , CRC : : RegionCount , & GSRendererHW : : OI_SMTNocturne ) ) ;
2015-07-05 15:32:57 +00:00
m_oi_list . push_back ( HackEntry < OI_Ptr > ( CRC : : SuperManReturns , CRC : : RegionCount , & GSRendererHW : : OI_SuperManReturns ) ) ;
2012-01-05 02:40:24 +00:00
m_oo_list . push_back ( HackEntry < OO_Ptr > ( CRC : : DBZBT2 , CRC : : RegionCount , & GSRendererHW : : OO_DBZBT2 ) ) ;
m_oo_list . push_back ( HackEntry < OO_Ptr > ( CRC : : MajokkoALaMode2 , CRC : : RegionCount , & GSRendererHW : : OO_MajokkoALaMode2 ) ) ;
m_cu_list . push_back ( HackEntry < CU_Ptr > ( CRC : : DBZBT2 , CRC : : RegionCount , & GSRendererHW : : CU_DBZBT2 ) ) ;
m_cu_list . push_back ( HackEntry < CU_Ptr > ( CRC : : MajokkoALaMode2 , CRC : : RegionCount , & GSRendererHW : : CU_MajokkoALaMode2 ) ) ;
m_cu_list . push_back ( HackEntry < CU_Ptr > ( CRC : : TalesOfAbyss , CRC : : RegionCount , & GSRendererHW : : CU_TalesOfAbyss ) ) ;
}
void GSRendererHW : : Hacks : : SetGameCRC ( const CRC : : Game & game )
{
uint32 hash = ( uint32 ) ( ( game . region < < 24 ) | game . title ) ;
m_oi = m_oi_map [ hash ] ;
m_oo = m_oo_map [ hash ] ;
m_cu = m_cu_map [ hash ] ;
2015-06-14 17:42:11 +00:00
if ( game . flags & CRC : : PointListPalette ) {
2012-01-05 02:40:24 +00:00
ASSERT ( m_oi = = NULL ) ;
m_oi = & GSRendererHW : : OI_PointListPalette ;
}
2015-07-03 20:13:35 +00:00
bool hack = theApp . GetConfig ( " UserHacks_ColorDepthClearOverlap " , 0 ) & & theApp . GetConfig ( " UserHacks " , 0 ) ;
if ( hack & & ! m_oi ) {
// FIXME: Enable this code in the future. I think it could replace
// most of the "old" OI hack. So far code was tested on GoW2 & SimpsonsGame with
// success
2015-06-14 17:42:11 +00:00
m_oi = & GSRendererHW : : OI_DoubleHalfClear ;
}
}
bool GSRendererHW : : OI_DoubleHalfClear ( GSTexture * rt , GSTexture * ds , GSTextureCache : : Source * t )
{
2015-07-05 12:13:24 +00:00
if ( ( m_vt . m_primclass = = GS_SPRITE_CLASS ) & & ! PRIM - > TME & & ! m_context - > ZBUF . ZMSK & & ( m_context - > FRAME . FBW > = 7 ) & & rt ) {
2015-06-14 17:42:11 +00:00
GSVertex * v = & m_vertex . buff [ 0 ] ;
//GL_INS("OI_DoubleHalfClear: psm:%x. Z:%d R:%d G:%d B:%d A:%d", m_context->FRAME.PSM,
// v[1].XYZ.Z, v[1].RGBAQ.R, v[1].RGBAQ.G, v[1].RGBAQ.B, v[1].RGBAQ.A);
// Check it is a clear on the first primitive only
if ( v [ 1 ] . XYZ . Z | | v [ 1 ] . RGBAQ . R | | v [ 1 ] . RGBAQ . G | | v [ 1 ] . RGBAQ . B | | v [ 1 ] . RGBAQ . A ) {
return true ;
}
// Only 32 bits format is supported otherwise it is complicated
if ( m_context - > FRAME . PSM & 2 )
return true ;
// FIXME might need some rounding
// In 32 bits pages are 64x32 pixels. In theory, it must be somethings
// like FBW * 64 pixels * ratio / 32 pixels / 2 = FBW * ratio
// It is hard to predict the ratio, so I round it to 1. And I use
// <= comparison below.
uint32 h_pages = m_context - > FRAME . FBW ;
uint32 base ;
uint32 half ;
if ( m_context - > FRAME . FBP > m_context - > ZBUF . ZBP ) {
base = m_context - > ZBUF . ZBP ;
half = m_context - > FRAME . FBP ;
} else {
base = m_context - > FRAME . FBP ;
half = m_context - > ZBUF . ZBP ;
}
if ( half < = ( base + h_pages * m_context - > FRAME . FBW ) ) {
//GL_INS("OI_DoubleHalfClear: base %x half %x. h_pages %d fbw %d", base, half, h_pages, m_context->FRAME.FBW);
if ( m_context - > FRAME . FBP > m_context - > ZBUF . ZBP ) {
m_dev - > ClearDepth ( ds , 0 ) ;
} else {
m_dev - > ClearRenderTarget ( rt , 0 ) ;
}
// Don't return false, it will break the rendering. I guess that it misses texture
// invalidation
//return false;
}
}
return true ;
2012-01-05 02:40:24 +00:00
}
2015-06-04 16:52:58 +00:00
// OI (others input?/implementation?) hacks replace current draw call
2012-01-05 02:40:24 +00:00
bool GSRendererHW : : OI_FFXII ( GSTexture * rt , GSTexture * ds , GSTextureCache : : Source * t )
{
static uint32 * video = NULL ;
static size_t lines = 0 ;
if ( lines = = 0 )
{
2012-01-19 04:53:36 +00:00
if ( m_vt . m_primclass = = GS_LINE_CLASS & & ( m_vertex . next = = 448 * 2 | | m_vertex . next = = 512 * 2 ) )
2012-01-05 02:40:24 +00:00
{
2012-01-06 00:17:52 +00:00
lines = m_vertex . next / 2 ;
2012-01-05 02:40:24 +00:00
}
}
else
{
2012-01-19 04:53:36 +00:00
if ( m_vt . m_primclass = = GS_POINT_CLASS )
2012-01-05 02:40:24 +00:00
{
2012-01-06 00:17:52 +00:00
if ( m_vertex . next > = 16 * 512 )
2012-01-05 02:40:24 +00:00
{
// incoming pixels are stored in columns, one column is 16x512, total res 448x512 or 448x454
if ( ! video ) video = new uint32 [ 512 * 512 ] ;
2012-03-23 21:00:22 +00:00
int ox = m_context - > XYOFFSET . OFX - 8 ;
int oy = m_context - > XYOFFSET . OFY - 8 ;
2012-01-05 02:40:24 +00:00
2012-01-19 04:53:36 +00:00
const GSVertex * RESTRICT v = m_vertex . buff ;
2012-01-05 02:40:24 +00:00
2012-03-23 21:00:22 +00:00
for ( int i = ( int ) m_vertex . next ; i > 0 ; i - - , v + + )
2012-01-05 02:40:24 +00:00
{
2012-01-19 04:53:36 +00:00
int x = ( v - > XYZ . X - ox ) > > 4 ;
int y = ( v - > XYZ . Y - oy ) > > 4 ;
2012-03-17 12:55:02 +00:00
2012-03-23 21:00:22 +00:00
if ( x < 0 | | x > = 448 | | y < 0 | | y > = ( int ) lines ) return false ; // le sigh
2012-03-17 12:55:02 +00:00
2012-01-19 04:53:36 +00:00
video [ ( y < < 8 ) + ( y < < 7 ) + ( y < < 6 ) + x ] = v - > RGBAQ . u32 [ 0 ] ;
2012-01-05 02:40:24 +00:00
}
return false ;
}
else
{
lines = 0 ;
}
}
2012-01-19 04:53:36 +00:00
else if ( m_vt . m_primclass = = GS_LINE_CLASS )
2012-01-05 02:40:24 +00:00
{
2012-01-06 00:17:52 +00:00
if ( m_vertex . next = = lines * 2 )
2012-01-05 02:40:24 +00:00
{
// normally, this step would copy the video onto screen with 512 texture mapped horizontal lines,
// but we use the stored video data to create a new texture, and replace the lines with two triangles
m_dev - > Recycle ( t - > m_texture ) ;
t - > m_texture = m_dev - > CreateTexture ( 512 , 512 ) ;
t - > m_texture - > Update ( GSVector4i ( 0 , 0 , 448 , lines ) , video , 448 * 4 ) ;
2012-01-19 04:53:36 +00:00
m_vertex . buff [ 2 ] = m_vertex . buff [ m_vertex . next - 2 ] ;
m_vertex . buff [ 3 ] = m_vertex . buff [ m_vertex . next - 1 ] ;
2012-01-05 02:40:24 +00:00
m_index . buff [ 0 ] = 0 ;
m_index . buff [ 1 ] = 1 ;
m_index . buff [ 2 ] = 2 ;
m_index . buff [ 3 ] = 1 ;
m_index . buff [ 4 ] = 2 ;
m_index . buff [ 5 ] = 3 ;
2012-01-06 00:17:52 +00:00
m_vertex . head = m_vertex . tail = m_vertex . next = 4 ;
2012-01-05 02:40:24 +00:00
m_index . tail = 6 ;
2012-01-19 04:53:36 +00:00
m_vt . Update ( m_vertex . buff , m_index . buff , m_index . tail , GS_TRIANGLE_CLASS ) ;
2012-01-05 02:40:24 +00:00
}
else
{
lines = 0 ;
}
}
}
return true ;
}
bool GSRendererHW : : OI_FFX ( GSTexture * rt , GSTexture * ds , GSTextureCache : : Source * t )
{
uint32 FBP = m_context - > FRAME . Block ( ) ;
uint32 ZBP = m_context - > ZBUF . Block ( ) ;
uint32 TBP = m_context - > TEX0 . TBP0 ;
if ( ( FBP = = 0x00d00 | | FBP = = 0x00000 ) & & ZBP = = 0x02100 & & PRIM - > TME & & TBP = = 0x01a00 & & m_context - > TEX0 . PSM = = PSM_PSMCT16S )
{
// random battle transition (z buffer written directly, clear it now)
m_dev - > ClearDepth ( ds , 0 ) ;
}
return true ;
}
bool GSRendererHW : : OI_MetalSlug6 ( GSTexture * rt , GSTexture * ds , GSTextureCache : : Source * t )
{
// missing red channel fix (looks alright in pcsx2 r5000+)
2012-01-19 04:53:36 +00:00
GSVertex * RESTRICT v = m_vertex . buff ;
2012-01-05 02:40:24 +00:00
2012-03-23 21:00:22 +00:00
for ( int i = ( int ) m_vertex . next ; i > 0 ; i - - , v + + )
2012-01-05 02:40:24 +00:00
{
2012-01-19 04:53:36 +00:00
uint32 c = v - > RGBAQ . u32 [ 0 ] ;
2012-01-05 02:40:24 +00:00
uint32 r = ( c > > 0 ) & 0xff ;
uint32 g = ( c > > 8 ) & 0xff ;
uint32 b = ( c > > 16 ) & 0xff ;
if ( r = = 0 & & g ! = 0 & & b ! = 0 )
{
2012-01-19 04:53:36 +00:00
v - > RGBAQ . u32 [ 0 ] = ( c & 0xffffff00 ) | ( ( g + b + 1 ) > > 1 ) ;
2012-01-05 02:40:24 +00:00
}
}
2012-01-19 04:53:36 +00:00
m_vt . Update ( m_vertex . buff , m_index . buff , m_index . tail , m_vt . m_primclass ) ;
2012-01-05 02:40:24 +00:00
return true ;
}
bool GSRendererHW : : OI_GodOfWar2 ( GSTexture * rt , GSTexture * ds , GSTextureCache : : Source * t )
{
uint32 FBP = m_context - > FRAME . Block ( ) ;
uint32 FBW = m_context - > FRAME . FBW ;
uint32 FPSM = m_context - > FRAME . PSM ;
if ( ( FBP = = 0x00f00 | | FBP = = 0x00100 | | FBP = = 0x01280 ) & & FPSM = = PSM_PSMZ24 ) // ntsc 0xf00, pal 0x100, ntsc "HD" 0x1280
{
// z buffer clear
GIFRegTEX0 TEX0 ;
TEX0 . TBP0 = FBP ;
TEX0 . TBW = FBW ;
TEX0 . PSM = FPSM ;
if ( GSTextureCache : : Target * ds = m_tc - > LookupTarget ( TEX0 , m_width , m_height , GSTextureCache : : DepthStencil , true ) )
{
m_dev - > ClearDepth ( ds - > m_texture , 0 ) ;
}
return false ;
}
return true ;
}
bool GSRendererHW : : OI_SimpsonsGame ( GSTexture * rt , GSTexture * ds , GSTextureCache : : Source * t )
{
uint32 FBP = m_context - > FRAME . Block ( ) ;
uint32 FPSM = m_context - > FRAME . PSM ;
if ( ( FBP = = 0x01500 | | FBP = = 0x01800 ) & & FPSM = = PSM_PSMZ24 ) //0x1800 pal, 0x1500 ntsc
{
// instead of just simply drawing a full height 512x512 sprite to clear the z buffer,
// it uses a 512x256 sprite only, yet it is still able to fill the whole surface with zeros,
// how? by using a render target that overlaps with the lower half of the z buffer...
// TODO: tony hawk pro skater 4 same problem, the empty half is not visible though, painted over fully
m_dev - > ClearDepth ( ds , 0 ) ;
return false ;
}
return true ;
}
bool GSRendererHW : : OI_RozenMaidenGebetGarden ( GSTexture * rt , GSTexture * ds , GSTextureCache : : Source * t )
{
if ( ! PRIM - > TME )
{
uint32 FBP = m_context - > FRAME . Block ( ) ;
uint32 ZBP = m_context - > ZBUF . Block ( ) ;
if ( FBP = = 0x008c0 & & ZBP = = 0x01a40 )
{
// frame buffer clear, atst = fail, afail = write z only, z buffer points to frame buffer
GIFRegTEX0 TEX0 ;
TEX0 . TBP0 = ZBP ;
TEX0 . TBW = m_context - > FRAME . FBW ;
TEX0 . PSM = m_context - > FRAME . PSM ;
if ( GSTextureCache : : Target * rt = m_tc - > LookupTarget ( TEX0 , m_width , m_height , GSTextureCache : : RenderTarget , true ) )
{
m_dev - > ClearRenderTarget ( rt - > m_texture , 0 ) ;
}
return false ;
}
else if ( FBP = = 0x00000 & & m_context - > ZBUF . Block ( ) = = 0x01180 )
{
// z buffer clear, frame buffer now points to the z buffer (how can they be so clever?)
GIFRegTEX0 TEX0 ;
TEX0 . TBP0 = FBP ;
TEX0 . TBW = m_context - > FRAME . FBW ;
TEX0 . PSM = m_context - > ZBUF . PSM ;
if ( GSTextureCache : : Target * ds = m_tc - > LookupTarget ( TEX0 , m_width , m_height , GSTextureCache : : DepthStencil , true ) )
{
m_dev - > ClearDepth ( ds - > m_texture , 0 ) ;
}
return false ;
}
}
return true ;
}
bool GSRendererHW : : OI_SpidermanWoS ( GSTexture * rt , GSTexture * ds , GSTextureCache : : Source * t )
{
uint32 FBP = m_context - > FRAME . Block ( ) ;
uint32 FPSM = m_context - > FRAME . PSM ;
if ( ( FBP = = 0x025a0 | | FBP = = 0x02800 ) & & FPSM = = PSM_PSMCT32 ) //0x2800 pal, 0x25a0 ntsc
{
//only top half of the screen clears
m_dev - > ClearDepth ( ds , 0 ) ;
}
return true ;
}
bool GSRendererHW : : OI_TyTasmanianTiger ( GSTexture * rt , GSTexture * ds , GSTextureCache : : Source * t )
{
uint32 FBP = m_context - > FRAME . Block ( ) ;
uint32 FPSM = m_context - > FRAME . PSM ;
if ( ( FBP = = 0x02800 | | FBP = = 0x02BC0 ) & & FPSM = = PSM_PSMCT24 ) //0x2800 pal, 0x2bc0 ntsc
{
//half height buffer clear
m_dev - > ClearDepth ( ds , 0 ) ;
return false ;
}
return true ;
}
bool GSRendererHW : : OI_DigimonRumbleArena2 ( GSTexture * rt , GSTexture * ds , GSTextureCache : : Source * t )
{
uint32 FBP = m_context - > FRAME . Block ( ) ;
uint32 FPSM = m_context - > FRAME . PSM ;
if ( ! PRIM - > TME )
{
if ( ( FBP = = 0x02300 | | FBP = = 0x03fc0 ) & & FPSM = = PSM_PSMCT32 )
{
//half height buffer clear
m_dev - > ClearDepth ( ds , 0 ) ;
}
}
return true ;
}
bool GSRendererHW : : OI_BlackHawkDown ( GSTexture * rt , GSTexture * ds , GSTextureCache : : Source * t )
{
uint32 FBP = m_context - > FRAME . Block ( ) ;
uint32 FPSM = m_context - > FRAME . PSM ;
if ( FBP = = 0x02000 & & FPSM = = PSM_PSMZ24 )
{
//half height buffer clear
m_dev - > ClearDepth ( ds , 0 ) ;
return false ;
}
return true ;
}
bool GSRendererHW : : OI_StarWarsForceUnleashed ( GSTexture * rt , GSTexture * ds , GSTextureCache : : Source * t )
{
uint32 FBP = m_context - > FRAME . Block ( ) ;
uint32 FPSM = m_context - > FRAME . PSM ;
if ( ! PRIM - > TME )
{
if ( FPSM = = PSM_PSMCT24 & & FBP = = 0x2bc0 )
{
m_dev - > ClearDepth ( ds , 0 ) ;
return false ;
}
}
else if ( PRIM - > TME )
{
2012-01-19 04:53:36 +00:00
if ( ( FBP = = 0x0 | | FBP = = 0x01180 ) & & FPSM = = PSM_PSMCT32 & & ( m_vt . m_eq . z & & m_vt . m_max . p . z = = 0 ) )
2012-01-05 02:40:24 +00:00
{
m_dev - > ClearDepth ( ds , 0 ) ;
}
}
return true ;
}
bool GSRendererHW : : OI_XmenOriginsWolverine ( GSTexture * rt , GSTexture * ds , GSTextureCache : : Source * t )
{
uint32 FBP = m_context - > FRAME . Block ( ) ;
uint32 FPSM = m_context - > FRAME . PSM ;
if ( FBP = = 0x0 & & FPSM = = PSM_PSMCT16 )
{
//half height buffer clear
m_dev - > ClearDepth ( ds , 0 ) ;
}
return true ;
}
bool GSRendererHW : : OI_CallofDutyFinalFronts ( GSTexture * rt , GSTexture * ds , GSTextureCache : : Source * t )
{
uint32 FBP = m_context - > FRAME . Block ( ) ;
uint32 FPSM = m_context - > FRAME . PSM ;
if ( FBP = = 0x02300 & & FPSM = = PSM_PSMZ24 )
{
//half height buffer clear
m_dev - > ClearDepth ( ds , 0 ) ;
return false ;
}
return true ;
}
bool GSRendererHW : : OI_SpyroNewBeginning ( GSTexture * rt , GSTexture * ds , GSTextureCache : : Source * t )
{
uint32 FBP = m_context - > FRAME . Block ( ) ;
uint32 FPSM = m_context - > FRAME . PSM ;
if ( ! PRIM - > TME )
{
if ( FPSM = = PSM_PSMCT24 & & ( FBP = = 0x02800 | | FBP = = 0x02bc0 ) ) //0x2800 pal, 0x2bc0 ntsc
{
//half height buffer clear
m_dev - > ClearDepth ( ds , 0 ) ;
return false ;
}
}
else if ( PRIM - > TME )
{
2012-01-19 04:53:36 +00:00
if ( ( FBP = = 0x0 | | FBP = = 0x01180 ) & & FPSM = = PSM_PSMCT32 & & ( m_vt . m_eq . z & & m_vt . m_min . p . z = = 0 ) )
2012-01-05 02:40:24 +00:00
{
m_dev - > ClearDepth ( ds , 0 ) ;
}
}
return true ;
}
bool GSRendererHW : : OI_SpyroEternalNight ( GSTexture * rt , GSTexture * ds , GSTextureCache : : Source * t )
{
uint32 FBP = m_context - > FRAME . Block ( ) ;
uint32 FPSM = m_context - > FRAME . PSM ;
if ( ! PRIM - > TME )
{
if ( FPSM = = PSM_PSMCT24 & & FBP = = 0x2bc0 )
{
//half height buffer clear
m_dev - > ClearDepth ( ds , 0 ) ;
return false ;
}
}
else if ( PRIM - > TME )
{
2012-01-19 04:53:36 +00:00
if ( ( FBP = = 0x0 | | FBP = = 0x01180 ) & & FPSM = = PSM_PSMCT32 & & ( m_vt . m_eq . z & & m_vt . m_min . p . z = = 0 ) )
2012-01-05 02:40:24 +00:00
{
m_dev - > ClearDepth ( ds , 0 ) ;
}
}
return true ;
}
bool GSRendererHW : : OI_TalesOfLegendia ( GSTexture * rt , GSTexture * ds , GSTextureCache : : Source * t )
{
uint32 FBP = m_context - > FRAME . Block ( ) ;
uint32 FPSM = m_context - > FRAME . PSM ;
2012-01-19 04:53:36 +00:00
if ( FPSM = = PSM_PSMCT32 & & FBP = = 0x01c00 & & ! m_context - > TEST . ATE & & m_vt . m_eq . z )
2012-01-05 02:40:24 +00:00
{
m_context - > TEST . ZTST = ZTST_ALWAYS ;
//m_dev->ClearDepth(ds, 0);
}
return true ;
}
2014-01-21 15:27:05 +00:00
bool GSRendererHW : : OI_SMTNocturne ( GSTexture * rt , GSTexture * ds , GSTextureCache : : Source * t )
{
uint32 FBMSK = m_context - > FRAME . FBMSK ;
uint32 FBP = m_context - > FRAME . Block ( ) ;
uint32 FBW = m_context - > FRAME . FBW ;
uint32 FPSM = m_context - > FRAME . PSM ;
if ( FBMSK = = 16777215 & & m_vertex . head ! = 2 & & m_vertex . tail ! = 4 & & m_vertex . next ! = 4 )
{
GIFRegTEX0 TEX0 ;
TEX0 . TBP0 = FBP ;
TEX0 . TBW = FBW ;
TEX0 . PSM = FPSM ;
if ( GSTextureCache : : Target * ds = m_tc - > LookupTarget ( TEX0 , m_width , m_height , GSTextureCache : : DepthStencil , true ) )
{
m_dev - > ClearDepth ( ds - > m_texture , 0 ) ;
}
return false ;
}
return true ;
}
2012-01-05 02:40:24 +00:00
bool GSRendererHW : : OI_PointListPalette ( GSTexture * rt , GSTexture * ds , GSTextureCache : : Source * t )
{
2012-01-19 04:53:36 +00:00
if ( m_vt . m_primclass = = GS_POINT_CLASS & & ! PRIM - > TME )
2012-01-05 02:40:24 +00:00
{
uint32 FBP = m_context - > FRAME . Block ( ) ;
uint32 FBW = m_context - > FRAME . FBW ;
if ( FBP > = 0x03f40 & & ( FBP & 0x1f ) = = 0 )
{
2012-01-06 00:17:52 +00:00
if ( m_vertex . next = = 16 )
2012-01-05 02:40:24 +00:00
{
2012-01-19 04:53:36 +00:00
GSVertex * RESTRICT v = m_vertex . buff ;
2012-01-05 02:40:24 +00:00
2012-01-19 04:53:36 +00:00
for ( int i = 0 ; i < 16 ; i + + , v + + )
2012-01-05 02:40:24 +00:00
{
2012-01-19 04:53:36 +00:00
uint32 c = v - > RGBAQ . u32 [ 0 ] ;
2012-01-05 02:40:24 +00:00
uint32 a = c > > 24 ;
c = ( a > = 0x80 ? 0xff000000 : ( a < < 25 ) ) | ( c & 0x00ffffff ) ;
2012-01-19 04:53:36 +00:00
v - > RGBAQ . u32 [ 0 ] = c ;
2012-01-05 02:40:24 +00:00
m_mem . WritePixel32 ( i & 7 , i > > 3 , c , FBP , FBW ) ;
}
m_mem . m_clut . Invalidate ( ) ;
return false ;
}
2012-01-06 00:17:52 +00:00
else if ( m_vertex . next = = 256 )
2012-01-05 02:40:24 +00:00
{
2012-01-19 04:53:36 +00:00
GSVertex * RESTRICT v = m_vertex . buff ;
2012-01-05 02:40:24 +00:00
2012-01-19 04:53:36 +00:00
for ( int i = 0 ; i < 256 ; i + + , v + + )
2012-01-05 02:40:24 +00:00
{
2012-01-19 04:53:36 +00:00
uint32 c = v - > RGBAQ . u32 [ 0 ] ;
2012-01-05 02:40:24 +00:00
uint32 a = c > > 24 ;
c = ( a > = 0x80 ? 0xff000000 : ( a < < 25 ) ) | ( c & 0x00ffffff ) ;
2012-01-19 04:53:36 +00:00
v - > RGBAQ . u32 [ 0 ] = c ;
2012-01-05 02:40:24 +00:00
m_mem . WritePixel32 ( i & 15 , i > > 4 , c , FBP , FBW ) ;
}
m_mem . m_clut . Invalidate ( ) ;
return false ;
}
else
{
ASSERT ( 0 ) ;
}
}
}
return true ;
}
2015-07-04 08:52:43 +00:00
bool GSRendererHW : : OI_SuperMan ( GSTexture * rt , GSTexture * ds , GSTextureCache : : Source * t )
{
// Instead to use a fullscreen rectangle they use a 32 pixels, 4096 pixels with a FBW of 1.
// Technically the FB wrap/overlap on itself...
GSDrawingContext * ctx = m_context ;
GSVertex * v = & m_vertex . buff [ 0 ] ;
if ( ! ( ctx - > FRAME . FBP = = ctx - > ZBUF . ZBP & & ! PRIM - > TME & & ! ctx - > ZBUF . ZMSK & & ! ctx - > FRAME . FBMSK ) )
return true ;
// Please kill those crazy devs!
ASSERT ( m_vertex . next = = 2 ) ;
ASSERT ( m_vt . m_primclass = = GS_SPRITE_CLASS ) ;
ASSERT ( ( v - > RGBAQ . A < < 24 | v - > RGBAQ . B < < 16 | v - > RGBAQ . G < < 8 | v - > RGBAQ . R ) = = ( int ) v - > XYZ . Z ) ;
// Do a direct write
double depth = ( double ) v - > XYZ . Z * exp2 ( - 32.0f ) ;
m_dev - > ClearDepth ( ds , ( float ) depth ) ;
m_tc - > InvalidateVideoMemType ( GSTextureCache : : RenderTarget , ctx - > ZBUF . Block ( ) ) ;
return false ;
}
2015-06-04 16:52:58 +00:00
// OO (others output?) hacks: invalidate extra local memory after the draw call
2012-01-05 02:40:24 +00:00
void GSRendererHW : : OO_DBZBT2 ( )
{
// palette readback (cannot detect yet, when fetching the texture later)
uint32 FBP = m_context - > FRAME . Block ( ) ;
uint32 TBP0 = m_context - > TEX0 . TBP0 ;
if ( PRIM - > TME & & ( FBP = = 0x03c00 & & TBP0 = = 0x03c80 | | FBP = = 0x03ac0 & & TBP0 = = 0x03b40 ) )
{
GIFRegBITBLTBUF BITBLTBUF ;
BITBLTBUF . SBP = FBP ;
BITBLTBUF . SBW = 1 ;
BITBLTBUF . SPSM = PSM_PSMCT32 ;
InvalidateLocalMem ( BITBLTBUF , GSVector4i ( 0 , 0 , 64 , 64 ) ) ;
}
}
void GSRendererHW : : OO_MajokkoALaMode2 ( )
{
// palette readback
uint32 FBP = m_context - > FRAME . Block ( ) ;
if ( ! PRIM - > TME & & FBP = = 0x03f40 )
{
GIFRegBITBLTBUF BITBLTBUF ;
BITBLTBUF . SBP = FBP ;
BITBLTBUF . SBW = 1 ;
BITBLTBUF . SPSM = PSM_PSMCT32 ;
InvalidateLocalMem ( BITBLTBUF , GSVector4i ( 0 , 0 , 16 , 16 ) ) ;
}
}
2015-06-04 16:52:58 +00:00
// Can Upscale hacks: disable upscaling for some draw calls
2012-01-05 02:40:24 +00:00
bool GSRendererHW : : CU_DBZBT2 ( )
{
// palette should stay 64 x 64
uint32 FBP = m_context - > FRAME . Block ( ) ;
return FBP ! = 0x03c00 & & FBP ! = 0x03ac0 ;
}
bool GSRendererHW : : CU_MajokkoALaMode2 ( )
{
// palette should stay 16 x 16
uint32 FBP = m_context - > FRAME . Block ( ) ;
return FBP ! = 0x03f40 ;
}
bool GSRendererHW : : CU_TalesOfAbyss ( )
{
// full image blur and brightening
uint32 FBP = m_context - > FRAME . Block ( ) ;
return FBP ! = 0x036e0 & & FBP ! = 0x03560 & & FBP ! = 0x038e0 ;
}